Skip to content
Open
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 @@ -90,6 +90,8 @@ public final void apply(Project project) {
BaselineModuleJvmArgsExtension extension =
project.getExtensions().create(EXTENSION_NAME, BaselineModuleJvmArgsExtension.class, project);

Provider<String> projectPath = project.provider(project::getPath);

// javac isn't provided `--add-exports` args for the time being due to
// https://github.com/gradle/gradle/issues/18824
// However, we set sourceCompatibility in BaselineJavaVersion to opt out of the '--release' flag.
Expand All @@ -111,6 +113,11 @@ public final void apply(Project project) {
setTaskInputsFromExtension(javaCompile, extension);
});

Provider<ImmutableList<JarManifestModuleInfo>> classpathInfo =
project.provider(() -> collectClasspathInfoForSourceSet(sourceSet));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than wrapping this in a provider can we just make collectClasspathInfoForSourceSet return a provider - something like this should work I think:

        return classpath.getElements().map(fileSystemLocations -> fileSystemLocations.stream()
                .map(FileSystemLocation::getAsFile)
                .map(file -> { ... }))

Provider<Boolean> hasBaselineJavaVersion =
project.provider(() -> project.getPlugins().hasPlugin(BaselineJavaVersion.class));

TaskProvider<Task> javadocTaskProvider = null;
try {
javadocTaskProvider = project.getTasks().named(sourceSet.getJavadocTaskName());
Expand All @@ -123,27 +130,25 @@ public final void apply(Project project) {
@Override
public void execute(Task task) {
// The '--release' flag is set when BaselineJavaVersion is not used.
if (!project.getPlugins().hasPlugin(BaselineJavaVersion.class)) {
if (!hasBaselineJavaVersion.get()) {
log.debug(
"BaselineModuleJvmArgs not applying args to compilation task {} on {} "
+ "due to lack of BaselineJavaVersion",
task.getName(),
project.getPath());
projectPath.get());
return;
}

Javadoc javadoc = (Javadoc) task;

MinimalJavadocOptions options = javadoc.getOptions();
if (options instanceof CoreJavadocOptions coreOptions) {
ImmutableList<JarManifestModuleInfo> info =
collectClasspathInfoForSourceSet(sourceSet);
List<String> exportValues = Stream.concat(
// Compilation only supports exports, so we union with opens.
Stream.concat(
extension.exports().get().stream(),
extension.opens().get().stream()),
info.stream()
classpathInfo.get().stream()
.flatMap(item -> Stream.concat(
item.exports().stream(), item.opens().stream())))
.distinct()
Expand All @@ -153,7 +158,7 @@ public void execute(Task task) {
log.debug(
"BaselineModuleJvmArgs building {} on {} with exports: {}",
javadoc.getName(),
project.getPath(),
projectPath.get(),
exportValues);
if (!exportValues.isEmpty()) {
coreOptions
Expand Down Expand Up @@ -196,18 +201,17 @@ public void execute(Task task) {
project.getPlugins().withType(BaselineJavaVersion.class, _unused -> {
BaselineJavaVersionExtension javaVersionsExtension =
project.getExtensions().getByType(BaselineJavaVersionExtension.class);
extension.setEnablePreview(javaVersionsExtension.runtime().map(chosenJavaVersion -> {
return chosenJavaVersion.enablePreview()
? Optional.of(chosenJavaVersion.javaLanguageVersion())
: Optional.empty();
}));
extension.setEnablePreview(javaVersionsExtension
.runtime()
.map(chosenJavaVersion -> chosenJavaVersion.enablePreview()
? Optional.of(chosenJavaVersion.javaLanguageVersion())
: Optional.empty()));
});

project.getTasks().withType(Jar.class).configureEach(new Action<Jar>() {
@Override
public void execute(Jar jar) {
String jarName = jar.getName();
String projectPath = jar.getProject().getPath();

jar.doFirst(new Action<Task>() {
@Override
Expand All @@ -216,12 +220,20 @@ public void execute(Task task) {
@Override
public void execute(Manifest manifest) {
addManifestAttribute(
jarName, projectPath, manifest, ADD_EXPORTS_ATTRIBUTE, extension.exports());
jarName,
projectPath.get(),
manifest,
ADD_EXPORTS_ATTRIBUTE,
extension.exports());
addManifestAttribute(
jarName, projectPath, manifest, ADD_OPENS_ATTRIBUTE, extension.opens());
jarName,
projectPath.get(),
manifest,
ADD_OPENS_ATTRIBUTE,
extension.opens());
addManifestAttribute(
jarName,
projectPath,
projectPath.get(),
manifest,
ENABLE_PREVIEW_ATTRIBUTE,
extension.getEnablePreview().map(maybeVersion -> maybeVersion.stream()
Expand Down