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 ConfigurationCache #170

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
10 changes: 3 additions & 7 deletions src/main/java/org/openjfx/gradle/JavaFXModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@

import org.gradle.api.GradleException;

import java.util.List;
import java.util.Locale;
import java.util.Optional;
import java.util.Set;
import java.util.*;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;
Expand Down Expand Up @@ -81,16 +78,15 @@ public boolean compareJarFileName(JavaFXPlatform platform, String jarFileName) {
return p.matcher(jarFileName).matches();
}

public static Set<JavaFXModule> getJavaFXModules(List<String> moduleNames) {
public static Set<JavaFXModule> getJavaFXModules(Collection<String> moduleNames) {
validateModules(moduleNames);

return moduleNames.stream()
.map(JavaFXModule::fromModuleName)
.flatMap(Optional::stream)
.collect(Collectors.toSet());
}

public static void validateModules(List<String> moduleNames) {
public static void validateModules(Collection<String> moduleNames) {
var invalidModules = moduleNames.stream()
.filter(module -> JavaFXModule.fromModuleName(module).isEmpty())
.collect(Collectors.toList());
Expand Down
33 changes: 23 additions & 10 deletions src/main/java/org/openjfx/gradle/JavaFXOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@
import org.gradle.api.artifacts.dsl.RepositoryHandler;
import org.gradle.api.artifacts.repositories.FlatDirectoryArtifactRepository;
import org.gradle.api.model.ObjectFactory;
import org.gradle.api.provider.Property;
import org.gradle.api.provider.SetProperty;
import org.gradle.api.tasks.SourceSetContainer;
import org.gradle.nativeplatform.MachineArchitecture;
import org.gradle.nativeplatform.OperatingSystemFamily;

import javax.inject.Inject;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
Expand All @@ -54,13 +55,13 @@ abstract public class JavaFXOptions {

static final String MAVEN_JAVAFX_ARTIFACT_GROUP_ID = "org.openjfx";
private static final String JAVAFX_SDK_LIB_FOLDER = "lib";
private final SetProperty<String> modules;
private final Property<JavaFXPlatform> platform;

private JavaFXPlatform platform;

private String version = "17";
private String sdk;
private String[] configurations = new String[] { "implementation" };
private List<String> modules = new ArrayList<>();
private FlatDirectoryArtifactRepository customSDKArtifactRepository;

private final SourceSetContainer sourceSets;
Expand All @@ -80,11 +81,18 @@ abstract public class JavaFXOptions {

public JavaFXOptions(SourceSetContainer sourceSets, OsDetector osDetector) {
this.sourceSets = sourceSets;
platform = JavaFXPlatform.detect(osDetector);
platform = getObjects().property(JavaFXPlatform.class);
getFxPlatform().convention(JavaFXPlatform.detect(osDetector));
setClasspathAttributesForAllSourceSets();
modules = getObjects().setProperty(String.class);
}


public JavaFXPlatform getPlatform() {
return getFxPlatform().get();
}

public Property<JavaFXPlatform> getFxPlatform(){
return platform;
}

Expand All @@ -94,7 +102,7 @@ public JavaFXPlatform getPlatform() {
* Supported classifiers are linux, linux-aarch64, win/windows, osx/mac/macos or osx-aarch64/mac-aarch64/macos-aarch64.
*/
public void setPlatform(String platform) {
this.platform = JavaFXPlatform.fromString(platform);
this.getFxPlatform().set(JavaFXPlatform.fromString(platform));
setClasspathAttributesForAllSourceSets();
}

Expand All @@ -108,10 +116,10 @@ private void setClasspathAttributesForAllSourceSets() {
private void setClasspathAttributes(Configuration classpath) {
classpath.getAttributes().attribute(
OperatingSystemFamily.OPERATING_SYSTEM_ATTRIBUTE,
getObjects().named(OperatingSystemFamily.class, platform.getOsFamily()));
getObjects().named(OperatingSystemFamily.class, platform.get().getOsFamily()));
classpath.getAttributes().attribute(
MachineArchitecture.ARCHITECTURE_ATTRIBUTE,
getObjects().named(MachineArchitecture.class, platform.getArch()));
getObjects().named(MachineArchitecture.class, platform.get().getArch()));
}

public String getVersion() {
Expand Down Expand Up @@ -168,12 +176,17 @@ public String[] getConfigurations() {
return configurations;
}

public List<String> getModules() {
public SetProperty<String> getFxModules() {
return modules;
}

public Set<String> getModules() {
return modules.get();
}

public void setModules(List<String> modules) {
this.modules = modules;
this.modules.set(modules);

}

public void modules(String...moduleNames) {
Expand All @@ -190,7 +203,7 @@ private void declareFXDependencies(String conf) {
return;
}

var javaFXModules = JavaFXModule.getJavaFXModules(this.modules);
var javaFXModules = JavaFXModule.getJavaFXModules(getModules());
if (customSDKArtifactRepository == null) {
javaFXModules.stream()
.sorted()
Expand Down
24 changes: 14 additions & 10 deletions src/main/java/org/openjfx/gradle/JavaFXPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
import org.gradle.api.file.FileCollection;
import org.gradle.api.plugins.ApplicationPlugin;
import org.gradle.api.plugins.JavaBasePlugin;
import org.gradle.api.provider.Property;
import org.gradle.api.provider.SetProperty;
import org.gradle.api.tasks.JavaExec;
import org.gradle.api.tasks.SourceSetContainer;
import org.gradle.util.GradleVersion;
Expand All @@ -57,7 +59,6 @@ public void apply(Project project) {
if (GradleVersion.current().compareTo(GradleVersion.version("6.1")) < 0) {
throw new GradleException("This plugin requires Gradle 6.1+");
}

// Make sure 'java-base' is applied first, which makes the 'SourceSetContainer' available.
// More concrete Java plugins that build on top of 'java-base' – like 'java-library' or 'application' –
// will be applied by the user.
Expand Down Expand Up @@ -91,12 +92,15 @@ public void apply(Project project) {
return; // a module, as determined by Gradle core
}

execTask.doFirst(a -> {
if (execTask.getExtensions().findByName("moduleOptions") != null) {
return; // a module, as determined by modularity plugin
}

putJavaFXJarsOnModulePathForClasspathApplication(execTask, javaFXOptions);
final var fxPlatform = javaFXOptions.getFxPlatform();
final var fxModules = javaFXOptions.getFxModules();
if (execTask.getExtensions().findByName("moduleOptions") != null) {
return;
}

execTask.doFirst(a -> {
putJavaFXJarsOnModulePathForClasspathApplication(execTask, fxPlatform, fxModules);
});
});
});
Expand All @@ -107,15 +111,15 @@ public void apply(Project project) {
* the classpath. Hence, this patches the setup of Gradle's standard ':run' task to move all JavaFX Jars
* from '-classpath' to '-module-path'. This functionality is only relevant for NON-MODULAR apps.
*/
private static void putJavaFXJarsOnModulePathForClasspathApplication(JavaExec execTask, JavaFXOptions javaFXOptions) {
private static void putJavaFXJarsOnModulePathForClasspathApplication(JavaExec execTask, final Property<JavaFXPlatform> platform, final SetProperty<String> stringSetProperty) {
FileCollection classpath = execTask.getClasspath();

execTask.setClasspath(classpath.filter(jar -> !isJavaFXJar(jar, javaFXOptions.getPlatform())));
var modulePath = classpath.filter(jar -> isJavaFXJar(jar, javaFXOptions.getPlatform()));
execTask.setClasspath(classpath.filter(jar -> !isJavaFXJar(jar, platform.get())));
var modulePath = classpath.filter(jar -> isJavaFXJar(jar, platform.get()));

execTask.getJvmArgumentProviders().add(() -> List.of(
"--module-path", modulePath.getAsPath(),
"--add-modules", String.join(",", javaFXOptions.getModules())
"--add-modules", String.join(",", stringSetProperty.get())
));
}

Expand Down