Skip to content

Commit

Permalink
Declare dependencies for dependent modules in case of of local SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
jjohannes committed Aug 29, 2023
1 parent 59f1e8f commit bc3f697
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 25 deletions.
22 changes: 16 additions & 6 deletions src/main/java/org/openjfx/gradle/JavaFXModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,22 @@
public enum JavaFXModule {

BASE,
GRAPHICS,
CONTROLS,
FXML,
MEDIA,
SWING,
WEB;
GRAPHICS(BASE),
CONTROLS(BASE, GRAPHICS),
FXML(BASE, GRAPHICS),
MEDIA(BASE, GRAPHICS),
SWING(BASE, GRAPHICS),
WEB(BASE, CONTROLS, GRAPHICS, MEDIA);

static final String PREFIX_MODULE = "javafx.";
private static final String PREFIX_ARTIFACT = "javafx-";

private final List<JavaFXModule> dependentModules;

JavaFXModule(JavaFXModule...dependentModules) {
this.dependentModules = List.of(dependentModules);
}

public static Optional<JavaFXModule> fromModuleName(String moduleName) {
return Stream.of(JavaFXModule.values())
.filter(javaFXModule -> moduleName.equals(javaFXModule.getModuleName()))
Expand Down Expand Up @@ -93,4 +99,8 @@ public static void validateModules(List<String> moduleNames) {
throw new GradleException("Found one or more invalid JavaFX module names: " + invalidModules);
}
}

public List<JavaFXModule> getDependentModules() {
return dependentModules;
}
}
42 changes: 24 additions & 18 deletions src/main/java/org/openjfx/gradle/JavaFXOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@
import javax.inject.Inject;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Stream;

abstract public class JavaFXOptions {

Expand Down Expand Up @@ -185,23 +185,29 @@ private void declareFXDependencies(String conf) {
// This allows users to make multiple modifications to the 'configurations' list at arbitrary times during
// build configuration.
getConfigurationContainer().getByName(conf).withDependencies(dependencySet -> {
if (!List.of(configurations).contains(conf)) {
// configuration was removed: do nothing
return;
}
JavaFXModule.getJavaFXModules(this.modules).stream()
.sorted()
.forEach(javaFXModule -> {
if (customSDKArtifactRepository != null) {
dependencySet.add(getDependencies().create(Map.of("name", javaFXModule.getModuleName())));
} else {
dependencySet.add(getDependencies().create(
MAVEN_JAVAFX_ARTIFACT_GROUP_ID + ":"
+ javaFXModule.getArtifactName() + ":"
+ getVersion()
));
}
});
if (!List.of(configurations).contains(conf)) {
// configuration was removed: do nothing
return;
}

Set<JavaFXModule> javaFXModules = JavaFXModule.getJavaFXModules(this.modules);
if (customSDKArtifactRepository == null) {
javaFXModules.stream().sorted().forEach(javaFXModule -> dependencySet.add(getDependencies().create(
MAVEN_JAVAFX_ARTIFACT_GROUP_ID + ":" + javaFXModule.getArtifactName() + ":" + getVersion()
)));
} else {
// Use the list of dependencies of each module to also add direct dependencies for those.
// This is needed, because there is no information about transitive dependencies in the metadata
// of the modules (as there is no such metadata in the local sdk).
Stream<JavaFXModule> javaFXModulesWithTransitives = Stream.concat(
javaFXModules.stream(),
javaFXModules.stream().flatMap(m -> m.getDependentModules().stream())
).distinct().sorted();

javaFXModulesWithTransitives.forEach(javaFXModule -> dependencySet.add(getDependencies().create(
Map.of("name", javaFXModule.getModuleName())
)));
}
});
}

Expand Down
2 changes: 1 addition & 1 deletion test-project/local-sdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ application {
}

javafx {
modules = ['javafx.controls', 'javafx.base', 'javafx.graphics']
modules = ['javafx.controls']
sdk = "javafx-sdk-17.0.8"
}

0 comments on commit bc3f697

Please sign in to comment.