Skip to content

Commit

Permalink
feat: support application.mainClass (#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
samypr100 authored Jul 14, 2024
1 parent ec726cb commit d3e0397
Showing 1 changed file with 28 additions and 11 deletions.
39 changes: 28 additions & 11 deletions src/main/java/com/gluonhq/gradle/tasks/ConfigBuild.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2022, Gluon
* Copyright (c) 2019, 2024, Gluon
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down 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 d3e0397

Please sign in to comment.