Skip to content

Commit

Permalink
feat: support application.mainClass instead of mainClassName deprecat…
Browse files Browse the repository at this point in the history
…ed convention and lazy plugin loading to get source main sets
  • Loading branch information
samypr100 committed Sep 24, 2023
1 parent dcae14d commit f15beb1
Showing 1 changed file with 27 additions and 10 deletions.
37 changes: 27 additions & 10 deletions src/main/java/com/gluonhq/gradle/tasks/ConfigBuild.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,18 @@
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Collections;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.stream.Collectors;

import org.gradle.api.GradleException;
import org.gradle.api.Project;
import org.gradle.api.artifacts.DependencySet;
import org.gradle.api.plugins.ApplicationPlugin;
import org.gradle.api.plugins.JavaApplication;
import org.gradle.api.plugins.JavaPlugin;
import org.gradle.api.provider.Property;
import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.SourceSetContainer;

Expand Down Expand Up @@ -84,7 +88,7 @@ public void build() {

Path buildRootPath = project.getLayout().getBuildDirectory().dir(Constants.GLUONFX_PATH).get().getAsFile().toPath();
project.getLogger().debug("BuildRoot: " + buildRootPath);

SubstrateDispatcher dispatcher = new SubstrateDispatcher(buildRootPath, clientConfig);
result = dispatcher.nativeCompile();
} catch (Exception e) {
Expand All @@ -97,7 +101,19 @@ public void build() {
}

private ProjectConfiguration createSubstrateConfiguration() {
ProjectConfiguration clientConfig = new ProjectConfiguration((String) project.getProperties().get("mainClassName"), getClassPath());
// Use Application Plugin First to get mainClass
Property<String> mainClass = project.getObjects().property(String.class);
project.getPlugins().withType(ApplicationPlugin.class, applicationPlugin -> {
JavaApplication javaApp = project.getExtensions().getByType(JavaApplication.class);
mainClass.set(javaApp.getMainClass().getOrNull());
});
// Fallback to deprecated mainClassName
if (!mainClass.isPresent()){
mainClass.set((String) project.getProperties().get("mainClassName"));
}

// Init Client Config
ProjectConfiguration clientConfig = new ProjectConfiguration(mainClass.getOrNull(), getClassPath());
clientConfig.setJavaStaticSdkVersion(clientExtension.getJavaStaticSdkVersion());
clientConfig.setJavafxStaticSdkVersion(clientExtension.getJavafxStaticSdkVersion());

Expand Down Expand Up @@ -159,14 +175,15 @@ private String getClassPath() {
}

private List<Path> getClassPathFromSourceSets() {
List<Path> classPath = Collections.emptyList();
SourceSetContainer sourceSetContainer = (SourceSetContainer) project.getProperties().get("sourceSets");
SourceSet mainSourceSet = sourceSetContainer.findByName("main");
if (mainSourceSet != null) {
classPath = mainSourceSet.getRuntimeClasspath().getFiles().stream()
final List<Path> classPath = new ArrayList<>();
project.getPlugins().withType(JavaPlugin.class, javaPlugin -> {
SourceSetContainer sourceSetContainer = project.getExtensions().getByType(SourceSetContainer.class);
SourceSet mainSourceSet = sourceSetContainer.getByName(SourceSet.MAIN_SOURCE_SET_NAME);
mainSourceSet.getRuntimeClasspath().getFiles().stream()
.filter(File::exists)
.map(File::toPath).collect(Collectors.toList());
}
.map(File::toPath)
.forEachOrdered(classPath::add);
});
return classPath;
}

Expand Down

0 comments on commit f15beb1

Please sign in to comment.