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

feat: support application.mainClass #183

Merged
merged 2 commits into from
Jul 14, 2024
Merged
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
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;
jperedadnr marked this conversation as resolved.
Show resolved Hide resolved
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());
jperedadnr marked this conversation as resolved.
Show resolved Hide resolved
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
Loading