|
20 | 20 | import groovy.lang.GroovyCodeSource;
|
21 | 21 | import groovy.util.DelegatingScript;
|
22 | 22 |
|
| 23 | +import java.lang.reflect.Field; |
| 24 | +import java.lang.reflect.Modifier; |
23 | 25 | import java.net.URL;
|
24 | 26 | import java.nio.charset.StandardCharsets;
|
25 | 27 | import java.security.AccessController;
|
26 | 28 | import java.security.PrivilegedAction;
|
| 29 | +import java.util.ArrayList; |
| 30 | +import java.util.Collections; |
| 31 | +import java.util.List; |
27 | 32 |
|
28 | 33 | import org.codehaus.groovy.control.CompilerConfiguration;
|
29 | 34 | import org.codehaus.groovy.control.customizers.ImportCustomizer;
|
@@ -61,6 +66,12 @@ public class ForbiddenApisPlugin implements Plugin<Project> {
|
61 | 66 | /** Minimum Gradle version this plugin requires to run (v3.2). */
|
62 | 67 | public static final GradleVersion MIN_GRADLE_VERSION = GradleVersion.version("3.2");
|
63 | 68 |
|
| 69 | + /** True, if this version of Gradle supports task avoidance API (>=v4.9). */ |
| 70 | + public static final boolean TASK_AVOIDANCE_AVAILABLE = GradleVersion.current().compareTo(GradleVersion.version("4.9")) >= 0; |
| 71 | + |
| 72 | + /** All properties that our ForbiddenApisExtension provides. Used by plugin init script to create convention mapping. */ |
| 73 | + public static final List<String> FORBIDDEN_APIS_EXTENSION_PROPS = determineExtensionProps(); |
| 74 | + |
64 | 75 | /** Java Package that contains the Gradle Daemon (needed to detect it on startup). */
|
65 | 76 | private static final String GRADLE_DAEMON_PACKAGE = "org.gradle.launcher.daemon.";
|
66 | 77 |
|
@@ -97,6 +108,17 @@ public Class<? extends DelegatingScript> run() {
|
97 | 108 | });
|
98 | 109 | }
|
99 | 110 |
|
| 111 | + private static List<String> determineExtensionProps() { |
| 112 | + final List<String> props = new ArrayList<>(); |
| 113 | + for (final Field f : CheckForbiddenApisExtension.class.getDeclaredFields()) { |
| 114 | + final int mods = f.getModifiers(); |
| 115 | + if (Modifier.isPublic(mods) && !f.isSynthetic() && !Modifier.isStatic(mods)) { |
| 116 | + props.add(f.getName()); |
| 117 | + } |
| 118 | + } |
| 119 | + return Collections.unmodifiableList(props); |
| 120 | + } |
| 121 | + |
100 | 122 | private static boolean isGradleDaemon() {
|
101 | 123 | // see: http://stackoverflow.com/questions/23265217/how-to-know-whether-you-are-running-inside-a-gradle-daemon
|
102 | 124 | if (System.getProperty("sun.java.command", "").startsWith(GRADLE_DAEMON_PACKAGE)) {
|
|
0 commit comments