Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Signatures URLs added to any task are actually applied to all tasks #209

Merged
merged 1 commit into from
Oct 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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