Skip to content

Commit 7518dd3

Browse files
authored
Fix Signatures URLs added to any task are actually applied to all tasks. This closes #203 (#209)
1 parent a497d62 commit 7518dd3

File tree

4 files changed

+32
-4
lines changed

4 files changed

+32
-4
lines changed

src/main/java/de/thetaphi/forbiddenapis/gradle/CheckForbiddenApis.java

+5
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ public class CheckForbiddenApis extends DefaultTask implements PatternFilterable
121121
private FileCollection classpath;
122122
private String targetCompatibility;
123123

124+
/** Gives access to internal data of plugin to plugin-init.groovy */
125+
CheckForbiddenApisExtension internalTaskData() {
126+
return data;
127+
}
128+
124129
/**
125130
* Directories with the class files to check.
126131
* Defaults to current sourseSet's output directory (Gradle 3) or output directories (Gradle 4.0+).

src/main/java/de/thetaphi/forbiddenapis/gradle/ForbiddenApisPlugin.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public Class<? extends DelegatingScript> run() {
102102
loader.parseClass(csrc, false).asSubclass(DelegatingScript.class);
103103
return clazz;
104104
} catch (Exception e) {
105-
throw new RuntimeException("Cannot compile Groovy script: " + PLUGIN_INIT_SCRIPT);
105+
throw new RuntimeException("Cannot compile Groovy script: " + PLUGIN_INIT_SCRIPT, e);
106106
}
107107
}
108108
});

src/main/resources/de/thetaphi/forbiddenapis/gradle/plugin-init.groovy

+16-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
/** Initializes the plugin and binds it to project lifecycle. */
1818

1919
import org.gradle.api.plugins.JavaBasePlugin;
20+
import org.gradle.api.file.ConfigurableFileCollection;
2021

2122
project.plugins.apply(JavaBasePlugin.class);
2223

@@ -43,12 +44,24 @@ project.sourceSets.all{ sourceSet ->
4344
description = "Runs forbidden-apis checks on '${sourceSet.name}' classes.";
4445
dependsOn(sourceSet.output);
4546
outputs.upToDateWhen { true }
47+
def taskData = internalTaskData()
4648
conventionMapping.with{
4749
FORBIDDEN_APIS_EXTENSION_PROPS.each{ key ->
48-
map(key, { extension[key] });
50+
map(key, {
51+
def item = taskData[key]
52+
if (item instanceof ConfigurableFileCollection) {
53+
return item.from(extension[key])
54+
} else if (item instanceof Collection) {
55+
item.addAll(extension[key])
56+
return item
57+
}
58+
return extension[key]
59+
})
4960
}
50-
classesDirs = { sourceSet.output.hasProperty('classesDirs') ? sourceSet.output.classesDirs : project.files(sourceSet.output.classesDir) }
51-
classpath = { sourceSet.compileClasspath }
61+
ConfigurableFileCollection templateClassesDirs = project.files();
62+
classesDirs = { templateClassesDirs.from(sourceSet.output.hasProperty('classesDirs') ? sourceSet.output.classesDirs : sourceSet.output.classesDir) }
63+
ConfigurableFileCollection templateClasspath = project.files();
64+
classpath = { templateClasspath.from(sourceSet.compileClasspath) }
5265
targetCompatibility = targetCompatibilityGetter
5366
}
5467
}

src/test/gradle/build.gradle

+10
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ sourceSets {
3838
srcDirs = [new File(forbiddenRootDir, 'src/main/java')]
3939
}
4040
}
41+
main2 {
42+
compileClasspath = files(forbiddenClasspath.tokenize(File.pathSeparator))
43+
java {
44+
srcDirs = [new File(forbiddenRootDir, 'src/main/java')]
45+
}
46+
}
4147
test {
4248
compileClasspath = files(forbiddenTestClasspath.tokenize(File.pathSeparator))
4349
java {
@@ -53,6 +59,10 @@ forbiddenApis {
5359
}
5460

5561
forbiddenApisMain {
62+
bundledSignatures.add('jdk-internal')
63+
}
64+
65+
forbiddenApisMain2 {
5666
bundledSignatures += 'jdk-system-out'
5767
}
5868

0 commit comments

Comments
 (0)