Skip to content

Commit

Permalink
Fix Signatures URLs added to any task are actually applied to all tas…
Browse files Browse the repository at this point in the history
…ks. This closes #203 (#209)
  • Loading branch information
uschindler authored Oct 3, 2022
1 parent a497d62 commit 7518dd3
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ public class CheckForbiddenApis extends DefaultTask implements PatternFilterable
private FileCollection classpath;
private String targetCompatibility;

/** Gives access to internal data of plugin to plugin-init.groovy */
CheckForbiddenApisExtension internalTaskData() {
return data;
}

/**
* Directories with the class files to check.
* Defaults to current sourseSet's output directory (Gradle 3) or output directories (Gradle 4.0+).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public Class<? extends DelegatingScript> run() {
loader.parseClass(csrc, false).asSubclass(DelegatingScript.class);
return clazz;
} catch (Exception e) {
throw new RuntimeException("Cannot compile Groovy script: " + PLUGIN_INIT_SCRIPT);
throw new RuntimeException("Cannot compile Groovy script: " + PLUGIN_INIT_SCRIPT, e);
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
/** Initializes the plugin and binds it to project lifecycle. */

import org.gradle.api.plugins.JavaBasePlugin;
import org.gradle.api.file.ConfigurableFileCollection;

project.plugins.apply(JavaBasePlugin.class);

Expand All @@ -43,12 +44,24 @@ project.sourceSets.all{ sourceSet ->
description = "Runs forbidden-apis checks on '${sourceSet.name}' classes.";
dependsOn(sourceSet.output);
outputs.upToDateWhen { true }
def taskData = internalTaskData()
conventionMapping.with{
FORBIDDEN_APIS_EXTENSION_PROPS.each{ key ->
map(key, { extension[key] });
map(key, {
def item = taskData[key]
if (item instanceof ConfigurableFileCollection) {
return item.from(extension[key])
} else if (item instanceof Collection) {
item.addAll(extension[key])
return item
}
return extension[key]
})
}
classesDirs = { sourceSet.output.hasProperty('classesDirs') ? sourceSet.output.classesDirs : project.files(sourceSet.output.classesDir) }
classpath = { sourceSet.compileClasspath }
ConfigurableFileCollection templateClassesDirs = project.files();
classesDirs = { templateClassesDirs.from(sourceSet.output.hasProperty('classesDirs') ? sourceSet.output.classesDirs : sourceSet.output.classesDir) }
ConfigurableFileCollection templateClasspath = project.files();
classpath = { templateClasspath.from(sourceSet.compileClasspath) }
targetCompatibility = targetCompatibilityGetter
}
}
Expand Down
10 changes: 10 additions & 0 deletions src/test/gradle/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ sourceSets {
srcDirs = [new File(forbiddenRootDir, 'src/main/java')]
}
}
main2 {
compileClasspath = files(forbiddenClasspath.tokenize(File.pathSeparator))
java {
srcDirs = [new File(forbiddenRootDir, 'src/main/java')]
}
}
test {
compileClasspath = files(forbiddenTestClasspath.tokenize(File.pathSeparator))
java {
Expand All @@ -53,6 +59,10 @@ forbiddenApis {
}

forbiddenApisMain {
bundledSignatures.add('jdk-internal')
}

forbiddenApisMain2 {
bundledSignatures += 'jdk-system-out'
}

Expand Down

0 comments on commit 7518dd3

Please sign in to comment.