Skip to content

proper toolchain support #118

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

Merged
merged 3 commits into from
Apr 9, 2021
Merged
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ is required to run a JavaFX application. Also, if a module-info descriptor is pr

Values: MODULEPATH or CLASSPATH.

This plugin supports Maven toolchains using the "jdk" tool.

### Example

The following configuration adds some VM options, and a command line argument:
Expand Down
89 changes: 44 additions & 45 deletions src/main/java/org/openjfx/JavaFXBaseMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,32 @@

package org.openjfx;

import static org.openjfx.model.RuntimePathOption.CLASSPATH;
import static org.openjfx.model.RuntimePathOption.MODULEPATH;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Properties;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.apache.commons.exec.CommandLine;
import org.apache.commons.exec.ExecuteException;
import org.apache.commons.exec.ExecuteResultHandler;
Expand All @@ -33,6 +59,8 @@
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.apache.maven.toolchain.Toolchain;
import org.apache.maven.toolchain.ToolchainManager;
import org.codehaus.plexus.languages.java.jpms.JavaModuleDescriptor;
import org.codehaus.plexus.languages.java.jpms.LocationManager;
import org.codehaus.plexus.languages.java.jpms.ModuleNameSource;
Expand All @@ -42,32 +70,6 @@
import org.codehaus.plexus.util.cli.CommandLineUtils;
import org.openjfx.model.RuntimePathOption;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Properties;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static org.openjfx.model.RuntimePathOption.CLASSPATH;
import static org.openjfx.model.RuntimePathOption.MODULEPATH;

abstract class JavaFXBaseMojo extends AbstractMojo {

private static final String JAVAFX_APPLICATION_CLASS_NAME = "javafx.application.Application";
Expand Down Expand Up @@ -147,31 +149,19 @@ abstract class JavaFXBaseMojo extends AbstractMojo {
@Parameter(property = "javafx.args")
String commandlineArgs;

/**
* <p>The -source argument for the Java compiler.</p>
*/
@Parameter(property = "javafx.source", defaultValue = "11")
private String source;

/**
* <p>The -target argument for the Java compiler.</p>
*/
@Parameter(property = "javafx.target", defaultValue = "11")
private String target;

/**
* The -release argument for the Java compiler
*/
@Parameter(property = "javafx.release", defaultValue = "11")
private String release;

/**
* If set to true, it will include the dependencies that
* generate path exceptions in the classpath. Default is false.
*/
@Parameter(property = "javafx.includePathExceptionsInClasspath", defaultValue = "false")
private boolean includePathExceptionsInClasspath;

/**
*
*/
@Component
private ToolchainManager toolchainManager;

List<String> classpathElements;
List<String> modulepathElements;
Map<String, JavaModuleDescriptor> pathElements;
Expand Down Expand Up @@ -378,10 +368,19 @@ CommandLine getExecutablePath(String executable, Map<String, String> enviro, Fil
File execFile = new File(executable);
String exec = null;
if (execFile.isFile()) {
getLog().debug("Toolchains are ignored, 'executable' parameter is set to " + executable);
getLog().debug("'executable' parameter is set to " + executable);
exec = execFile.getAbsolutePath();
}

if (exec == null && toolchainManager != null) {
Toolchain toolchain = toolchainManager.getToolchainFromBuildContext("jdk", session);
getLog().info("Toolchain in javafx-maven-plugin " + toolchain);
if (toolchain != null) {
exec = toolchain.findTool("java");
getLog().debug("Tool in toolchain in javafx-maven-plugin " + exec);
}
}

if (exec == null) {
String javaHomeFromEnv = getJavaHomeEnv(enviro);
if (javaHomeFromEnv != null && ! javaHomeFromEnv.isEmpty()) {
Expand Down