From 141338f0bfcb8631a32fccb6ffdfb6e5f74f0e6b Mon Sep 17 00:00:00 2001 From: Abhinay Agarwal Date: Fri, 10 Sep 2021 22:17:14 +0530 Subject: [PATCH 1/9] Use Maven invoker plugin to create and invoke a new pom.xml --- pom.xml | 9 +- src/main/java/org/openjfx/JavaFXRunMojo.java | 2 +- .../java/org/openjfx/JavaFXRunMojoFix.java | 140 ++++++++++++++++++ .../org/openjfx/model/JavaFXDependency.java | 34 +++++ .../java/org/openjfx/model/JavaFXModule.java | 93 ++++++++++++ 5 files changed, 275 insertions(+), 3 deletions(-) create mode 100644 src/main/java/org/openjfx/JavaFXRunMojoFix.java create mode 100644 src/main/java/org/openjfx/model/JavaFXDependency.java create mode 100644 src/main/java/org/openjfx/model/JavaFXModule.java diff --git a/pom.xml b/pom.xml index 616561f..6b99eff 100644 --- a/pom.xml +++ b/pom.xml @@ -63,6 +63,11 @@ commons-exec 1.3 + + org.apache.maven.shared + maven-invoker + 2.2 + @@ -139,8 +144,8 @@ maven-compiler-plugin 3.8.0 - ${maven.compiler.source} - ${maven.compiler.target} + 9 + 9 diff --git a/src/main/java/org/openjfx/JavaFXRunMojo.java b/src/main/java/org/openjfx/JavaFXRunMojo.java index a0c8d14..4ec66d3 100644 --- a/src/main/java/org/openjfx/JavaFXRunMojo.java +++ b/src/main/java/org/openjfx/JavaFXRunMojo.java @@ -44,7 +44,7 @@ import static org.openjfx.model.RuntimePathOption.CLASSPATH; import static org.openjfx.model.RuntimePathOption.MODULEPATH; -@Mojo(name = "run", requiresDependencyResolution = ResolutionScope.RUNTIME) +@Mojo(name = "runx", requiresDependencyResolution = ResolutionScope.RUNTIME) @Execute(phase = LifecyclePhase.PROCESS_CLASSES) public class JavaFXRunMojo extends JavaFXBaseMojo { diff --git a/src/main/java/org/openjfx/JavaFXRunMojoFix.java b/src/main/java/org/openjfx/JavaFXRunMojoFix.java new file mode 100644 index 0000000..74d0358 --- /dev/null +++ b/src/main/java/org/openjfx/JavaFXRunMojoFix.java @@ -0,0 +1,140 @@ +/* + * Copyright (c) 2021, Gluon + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.openjfx; + +import org.apache.maven.execution.MavenSession; +import org.apache.maven.model.Dependency; +import org.apache.maven.model.Model; +import org.apache.maven.model.Profile; +import org.apache.maven.model.io.xpp3.MavenXpp3Reader; +import org.apache.maven.model.io.xpp3.MavenXpp3Writer; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugins.annotations.*; +import org.apache.maven.shared.invoker.*; +import org.openjfx.model.JavaFXDependency; +import org.openjfx.model.JavaFXModule; + +import java.io.*; +import java.util.*; +import java.util.stream.Collectors; + +@Mojo(name = "run", requiresDependencyResolution = ResolutionScope.COMPILE) +@Execute(phase = LifecyclePhase.PROCESS_RESOURCES) +public class JavaFXRunMojoFix extends JavaFXBaseMojo { + + @Parameter(readonly = true, required = true, defaultValue = "${basedir}/pom.xml") + String pom; + + @Parameter(readonly = true, required = true, defaultValue = "${project.basedir}/modifiedPom.xml") + String modifiedPom; + + @Parameter(defaultValue = "${session}", readonly = true) + MavenSession session; + + @Parameter(defaultValue = "${javafx.platform}", readonly = true) + String javafxPlatform; + + @Override + public void execute() throws MojoExecutionException { + String osName = System.getProperty("os.name").toLowerCase(Locale.ROOT); + String classifier = ""; + if (osName.contains("mac")) { + classifier = "mac"; + } else if (osName.contains("nux")) { + classifier = "linux"; + } else if (osName.contains("windows")) { + classifier = "win"; + } else { + throw new MojoExecutionException("Error, os.name " + osName + " not supported"); + } + + String PLATFORM = javafxPlatform != null ? javafxPlatform : classifier; + + final InvocationRequest invocationRequest = new DefaultInvocationRequest(); + invocationRequest.setProfiles(project.getActiveProfiles().stream() + .map(Profile::getId) + .collect(Collectors.toList())); + invocationRequest.setProperties(session.getRequest().getUserProperties()); + + // 1. Create modified pom + File modifiedPomFile = new File(modifiedPom); + try (InputStream is = new FileInputStream(new File(pom))) { + // 2. Create model from current pom + Model model = new MavenXpp3Reader().read(is); + + Set javaFXDependencies = new HashSet<>(); + List toRemove = new ArrayList<>(); + // 3. Check for dependencies + for (Dependency p : model.getDependencies()) { + if (p.getGroupId().equalsIgnoreCase("org.openjfx")) { + toRemove.add(p); + final Optional javaFXModule = JavaFXModule.fromArtifactName(p.getArtifactId()); + javaFXModule.ifPresent(module -> { + javaFXDependencies.add(module.getMavenDependency(PLATFORM, p.getVersion())); + javaFXDependencies.addAll(module.getMavenDependencies(PLATFORM, p.getVersion())); + }); + } + } + model.getDependencies().removeAll(toRemove); + model.getDependencies().addAll(javaFXDependencies); + + // 4. Serialize new pom + try (OutputStream os = new FileOutputStream(modifiedPomFile)) { + new MavenXpp3Writer().write(os, model); + } + } catch (Exception e) { + if (modifiedPomFile.exists()) { + modifiedPomFile.delete(); + } + throw new MojoExecutionException("Error generating agent pom", e); + } + + invocationRequest.setPomFile(modifiedPomFile); + invocationRequest.setGoals(Collections.singletonList("javafx:runx")); + + final Invoker invoker = new DefaultInvoker(); + // 8. Execute: + try { + final InvocationResult invocationResult = invoker.execute(invocationRequest); + if (invocationResult.getExitCode() != 0) { + throw new MojoExecutionException("Error, javafx:run failed", invocationResult.getExecutionException()); + } + } catch (MavenInvocationException e) { + e.printStackTrace(); + throw new MojoExecutionException("Error", e); + } finally { + if (modifiedPomFile.exists()) { + modifiedPomFile.delete(); + } + } + } +} + diff --git a/src/main/java/org/openjfx/model/JavaFXDependency.java b/src/main/java/org/openjfx/model/JavaFXDependency.java new file mode 100644 index 0000000..2fc8380 --- /dev/null +++ b/src/main/java/org/openjfx/model/JavaFXDependency.java @@ -0,0 +1,34 @@ +package org.openjfx.model; + +import org.apache.maven.model.Dependency; +import org.apache.maven.model.Exclusion; + +import java.util.ArrayList; +import java.util.List; + +public class JavaFXDependency extends Dependency { + + public JavaFXDependency(String artifactId, String version) { + setArtifactId(artifactId); + setVersion(version); + setGroupId("org.openjfx"); + setExclusions(exclusions()); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + JavaFXDependency that = (JavaFXDependency) o; + return this.getArtifactId().equals(that.getArtifactId()); + } + + private List exclusions() { + final Exclusion exclusion = new Exclusion(); + exclusion.setGroupId("org.openjfx"); + exclusion.setArtifactId("*"); + List exclusions = new ArrayList<>(); + exclusions.add(exclusion); + return exclusions; + } +} diff --git a/src/main/java/org/openjfx/model/JavaFXModule.java b/src/main/java/org/openjfx/model/JavaFXModule.java new file mode 100644 index 0000000..68e0404 --- /dev/null +++ b/src/main/java/org/openjfx/model/JavaFXModule.java @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2018, 2020, Gluon + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.openjfx.model; + +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; +import java.util.Optional; +import java.util.stream.Stream; + +public enum JavaFXModule { + + BASE, + 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 List dependentModules; + + JavaFXModule(JavaFXModule...dependentModules) { + this.dependentModules = List.of(dependentModules); + } + + public static Optional fromArtifactName(String artifactName) { + return Stream.of(JavaFXModule.values()) + .filter(javaFXModule -> artifactName.equals(javaFXModule.getArtifactName())) + .findFirst(); + } + + public String getModuleName() { + return PREFIX_MODULE + name().toLowerCase(Locale.ROOT); + } + + public String getModuleJarFileName() { + return getModuleName() + ".jar"; + } + + public String getArtifactName() { + return PREFIX_ARTIFACT + name().toLowerCase(Locale.ROOT); + } + + public List getDependentModules() { + return dependentModules; + } + + public List getMavenDependencies(String platform, String version) { + List mavenDependencies = new ArrayList<>(); + for (JavaFXModule dependentModule : dependentModules) { + mavenDependencies.add(dependentModule.getMavenDependency(platform, version)); + } + return mavenDependencies; + } + + public JavaFXDependency getMavenDependency(String platform, String version) { + final JavaFXDependency dependency = new JavaFXDependency(getArtifactName(), version); + dependency.setVersion(version); + dependency.setClassifier(platform); + return dependency; + } +} From bb9ca30c84e3ee6470c3c4229cfd64dbbddbb5ed Mon Sep 17 00:00:00 2001 From: Abhinay Agarwal Date: Fri, 10 Sep 2021 22:21:06 +0530 Subject: [PATCH 2/9] Ignore failing tests --- src/test/java/org/openjfx/JavaFXRunMojoTestCase.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/java/org/openjfx/JavaFXRunMojoTestCase.java b/src/test/java/org/openjfx/JavaFXRunMojoTestCase.java index e643fce..cd9c705 100644 --- a/src/test/java/org/openjfx/JavaFXRunMojoTestCase.java +++ b/src/test/java/org/openjfx/JavaFXRunMojoTestCase.java @@ -41,6 +41,7 @@ import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory; import org.eclipse.aether.repository.LocalRepository; import org.junit.Assert; +import org.junit.Ignore; import org.junit.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -55,6 +56,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +@Ignore public class JavaFXRunMojoTestCase extends AbstractMojoTestCase { private static final File LOCAL_REPO = new File( "src/test/repository" ); From bd830ae971c51b5690c309d7d2d4058a55f4e642 Mon Sep 17 00:00:00 2001 From: Abhinay Agarwal Date: Mon, 13 Sep 2021 13:33:46 +0530 Subject: [PATCH 3/9] Rename method name --- .../java/org/openjfx/JavaFXRunMojoFix.java | 22 +++++++++++++------ .../java/org/openjfx/model/JavaFXModule.java | 2 +- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/openjfx/JavaFXRunMojoFix.java b/src/main/java/org/openjfx/JavaFXRunMojoFix.java index 74d0358..0696ca0 100644 --- a/src/main/java/org/openjfx/JavaFXRunMojoFix.java +++ b/src/main/java/org/openjfx/JavaFXRunMojoFix.java @@ -27,7 +27,6 @@ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - package org.openjfx; import org.apache.maven.execution.MavenSession; @@ -42,8 +41,18 @@ import org.openjfx.model.JavaFXDependency; import org.openjfx.model.JavaFXModule; -import java.io.*; -import java.util.*; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Locale; +import java.util.Optional; +import java.util.Set; import java.util.stream.Collectors; @Mojo(name = "run", requiresDependencyResolution = ResolutionScope.COMPILE) @@ -86,7 +95,7 @@ public void execute() throws MojoExecutionException { // 1. Create modified pom File modifiedPomFile = new File(modifiedPom); - try (InputStream is = new FileInputStream(new File(pom))) { + try (InputStream is = new FileInputStream(pom)) { // 2. Create model from current pom Model model = new MavenXpp3Reader().read(is); @@ -99,7 +108,7 @@ public void execute() throws MojoExecutionException { final Optional javaFXModule = JavaFXModule.fromArtifactName(p.getArtifactId()); javaFXModule.ifPresent(module -> { javaFXDependencies.add(module.getMavenDependency(PLATFORM, p.getVersion())); - javaFXDependencies.addAll(module.getMavenDependencies(PLATFORM, p.getVersion())); + javaFXDependencies.addAll(module.getTransitiveMavenDependencies(PLATFORM, p.getVersion())); }); } } @@ -114,14 +123,13 @@ public void execute() throws MojoExecutionException { if (modifiedPomFile.exists()) { modifiedPomFile.delete(); } - throw new MojoExecutionException("Error generating agent pom", e); + throw new MojoExecutionException("Error generating modified pom", e); } invocationRequest.setPomFile(modifiedPomFile); invocationRequest.setGoals(Collections.singletonList("javafx:runx")); final Invoker invoker = new DefaultInvoker(); - // 8. Execute: try { final InvocationResult invocationResult = invoker.execute(invocationRequest); if (invocationResult.getExitCode() != 0) { diff --git a/src/main/java/org/openjfx/model/JavaFXModule.java b/src/main/java/org/openjfx/model/JavaFXModule.java index 68e0404..d3c5099 100644 --- a/src/main/java/org/openjfx/model/JavaFXModule.java +++ b/src/main/java/org/openjfx/model/JavaFXModule.java @@ -76,7 +76,7 @@ public List getDependentModules() { return dependentModules; } - public List getMavenDependencies(String platform, String version) { + public List getTransitiveMavenDependencies(String platform, String version) { List mavenDependencies = new ArrayList<>(); for (JavaFXModule dependentModule : dependentModules) { mavenDependencies.add(dependentModule.getMavenDependency(platform, version)); From cfc9e81f492a02b73701db74c1a40866f1f09531 Mon Sep 17 00:00:00 2001 From: Abhinay Agarwal Date: Mon, 13 Sep 2021 13:41:49 +0530 Subject: [PATCH 4/9] Rename Mojo --- .../openjfx/{JavaFXRunMojoFix.java => JavaFXRunFixMojo.java} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename src/main/java/org/openjfx/{JavaFXRunMojoFix.java => JavaFXRunFixMojo.java} (99%) diff --git a/src/main/java/org/openjfx/JavaFXRunMojoFix.java b/src/main/java/org/openjfx/JavaFXRunFixMojo.java similarity index 99% rename from src/main/java/org/openjfx/JavaFXRunMojoFix.java rename to src/main/java/org/openjfx/JavaFXRunFixMojo.java index 0696ca0..151b4ec 100644 --- a/src/main/java/org/openjfx/JavaFXRunMojoFix.java +++ b/src/main/java/org/openjfx/JavaFXRunFixMojo.java @@ -57,7 +57,7 @@ @Mojo(name = "run", requiresDependencyResolution = ResolutionScope.COMPILE) @Execute(phase = LifecyclePhase.PROCESS_RESOURCES) -public class JavaFXRunMojoFix extends JavaFXBaseMojo { +public class JavaFXRunFixMojo extends JavaFXBaseMojo { @Parameter(readonly = true, required = true, defaultValue = "${basedir}/pom.xml") String pom; From eb91454dfdb7ebc0f805a8a7458df82e5b2c86c4 Mon Sep 17 00:00:00 2001 From: Abhinay Agarwal Date: Mon, 13 Sep 2021 14:03:21 +0530 Subject: [PATCH 5/9] Add license header and remove unwanted changes --- pom.xml | 4 +-- .../org/openjfx/model/JavaFXDependency.java | 29 +++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 6b99eff..bb617df 100644 --- a/pom.xml +++ b/pom.xml @@ -144,8 +144,8 @@ maven-compiler-plugin 3.8.0 - 9 - 9 + ${maven.compiler.source} + ${maven.compiler.target} diff --git a/src/main/java/org/openjfx/model/JavaFXDependency.java b/src/main/java/org/openjfx/model/JavaFXDependency.java index 2fc8380..337bd0f 100644 --- a/src/main/java/org/openjfx/model/JavaFXDependency.java +++ b/src/main/java/org/openjfx/model/JavaFXDependency.java @@ -1,3 +1,32 @@ +/* + * Copyright (c) 2021, Gluon + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ package org.openjfx.model; import org.apache.maven.model.Dependency; From 4e3db84586034222dbfc85cf8df168afda2f4d04 Mon Sep 17 00:00:00 2001 From: Abhinay Agarwal Date: Mon, 13 Sep 2021 23:46:29 +0530 Subject: [PATCH 6/9] Add support for gluonfx-maven-plugin --- src/main/java/org/openjfx/JavaFXRunFixMojo.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/openjfx/JavaFXRunFixMojo.java b/src/main/java/org/openjfx/JavaFXRunFixMojo.java index 151b4ec..0e3ae71 100644 --- a/src/main/java/org/openjfx/JavaFXRunFixMojo.java +++ b/src/main/java/org/openjfx/JavaFXRunFixMojo.java @@ -62,6 +62,10 @@ public class JavaFXRunFixMojo extends JavaFXBaseMojo { @Parameter(readonly = true, required = true, defaultValue = "${basedir}/pom.xml") String pom; + // gluonfx-maven-plugin creates `runPom.xml` for gluonfx:runagent goal + @Parameter(readonly = true, required = true, defaultValue = "${basedir}/runPom.xml") + String runpom; + @Parameter(readonly = true, required = true, defaultValue = "${project.basedir}/modifiedPom.xml") String modifiedPom; @@ -95,7 +99,7 @@ public void execute() throws MojoExecutionException { // 1. Create modified pom File modifiedPomFile = new File(modifiedPom); - try (InputStream is = new FileInputStream(pom)) { + try (InputStream is = new FileInputStream(new File(runpom).exists() ? runpom : pom)) { // 2. Create model from current pom Model model = new MavenXpp3Reader().read(is); From 6b8ec4571c426b29c5ff18568421568c9277f704 Mon Sep 17 00:00:00 2001 From: Abhinay Agarwal Date: Tue, 14 Sep 2021 17:33:44 +0530 Subject: [PATCH 7/9] Changes as per review --- src/main/java/org/openjfx/JavaFXRunFixMojo.java | 4 ++++ src/main/java/org/openjfx/JavaFXRunMojo.java | 6 ++++++ src/main/java/org/openjfx/model/JavaFXModule.java | 2 +- src/test/java/org/openjfx/JavaFXRunMojoTestCase.java | 3 +-- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/openjfx/JavaFXRunFixMojo.java b/src/main/java/org/openjfx/JavaFXRunFixMojo.java index 0e3ae71..17063f3 100644 --- a/src/main/java/org/openjfx/JavaFXRunFixMojo.java +++ b/src/main/java/org/openjfx/JavaFXRunFixMojo.java @@ -55,6 +55,10 @@ import java.util.Set; import java.util.stream.Collectors; +/** + * A temporary mojo introduced to run JavaFX applications + * with Java 17 Maven artifacts. + */ @Mojo(name = "run", requiresDependencyResolution = ResolutionScope.COMPILE) @Execute(phase = LifecyclePhase.PROCESS_RESOURCES) public class JavaFXRunFixMojo extends JavaFXBaseMojo { diff --git a/src/main/java/org/openjfx/JavaFXRunMojo.java b/src/main/java/org/openjfx/JavaFXRunMojo.java index 4ec66d3..460f4a9 100644 --- a/src/main/java/org/openjfx/JavaFXRunMojo.java +++ b/src/main/java/org/openjfx/JavaFXRunMojo.java @@ -44,6 +44,12 @@ import static org.openjfx.model.RuntimePathOption.CLASSPATH; import static org.openjfx.model.RuntimePathOption.MODULEPATH; +/** + * Mojo to run a JavaFX application. + * + * Mojo name change from 'run' to 'runx' is temporary. It will be reverted + * once JavaFX 17.x empty jars are available with Automatic-Module-Name. + */ @Mojo(name = "runx", requiresDependencyResolution = ResolutionScope.RUNTIME) @Execute(phase = LifecyclePhase.PROCESS_CLASSES) public class JavaFXRunMojo extends JavaFXBaseMojo { diff --git a/src/main/java/org/openjfx/model/JavaFXModule.java b/src/main/java/org/openjfx/model/JavaFXModule.java index d3c5099..d3b418f 100644 --- a/src/main/java/org/openjfx/model/JavaFXModule.java +++ b/src/main/java/org/openjfx/model/JavaFXModule.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2020, Gluon + * Copyright (c) 2021, Gluon * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/test/java/org/openjfx/JavaFXRunMojoTestCase.java b/src/test/java/org/openjfx/JavaFXRunMojoTestCase.java index cd9c705..9c65e42 100644 --- a/src/test/java/org/openjfx/JavaFXRunMojoTestCase.java +++ b/src/test/java/org/openjfx/JavaFXRunMojoTestCase.java @@ -56,7 +56,6 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -@Ignore public class JavaFXRunMojoTestCase extends AbstractMojoTestCase { private static final File LOCAL_REPO = new File( "src/test/repository" ); @@ -142,7 +141,7 @@ public void testClasspathNoLauncherRun() throws Exception { } protected JavaFXRunMojo getJavaFXRunMojo(File testPom) throws Exception { - JavaFXRunMojo mojo = (JavaFXRunMojo) lookupMojo("run", testPom); + JavaFXRunMojo mojo = (JavaFXRunMojo) lookupMojo("runx", testPom); assertNotNull(mojo); setUpProject(testPom, mojo); From 871b758a6e9ad57c61dbc6d4266cb43e94c5cec7 Mon Sep 17 00:00:00 2001 From: Abhinay Agarwal Date: Tue, 14 Sep 2021 17:34:25 +0530 Subject: [PATCH 8/9] Pass user settings file location to invocation --- src/main/java/org/openjfx/JavaFXRunFixMojo.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/org/openjfx/JavaFXRunFixMojo.java b/src/main/java/org/openjfx/JavaFXRunFixMojo.java index 17063f3..9c62682 100644 --- a/src/main/java/org/openjfx/JavaFXRunFixMojo.java +++ b/src/main/java/org/openjfx/JavaFXRunFixMojo.java @@ -136,6 +136,7 @@ public void execute() throws MojoExecutionException { invocationRequest.setPomFile(modifiedPomFile); invocationRequest.setGoals(Collections.singletonList("javafx:runx")); + invocationRequest.setUserSettingsFile(session.getRequest().getUserSettingsFile()); final Invoker invoker = new DefaultInvoker(); try { From c17ee94a46b1a846256e854df20e07b6af1aeed7 Mon Sep 17 00:00:00 2001 From: Abhinay Agarwal Date: Tue, 14 Sep 2021 20:25:17 +0530 Subject: [PATCH 9/9] Change mojo name to 'dorun' --- src/main/java/org/openjfx/JavaFXRunFixMojo.java | 2 +- src/main/java/org/openjfx/JavaFXRunMojo.java | 4 ++-- src/test/java/org/openjfx/JavaFXRunMojoTestCase.java | 3 +-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/openjfx/JavaFXRunFixMojo.java b/src/main/java/org/openjfx/JavaFXRunFixMojo.java index 9c62682..ebdf1de 100644 --- a/src/main/java/org/openjfx/JavaFXRunFixMojo.java +++ b/src/main/java/org/openjfx/JavaFXRunFixMojo.java @@ -135,7 +135,7 @@ public void execute() throws MojoExecutionException { } invocationRequest.setPomFile(modifiedPomFile); - invocationRequest.setGoals(Collections.singletonList("javafx:runx")); + invocationRequest.setGoals(Collections.singletonList("javafx:dorun")); invocationRequest.setUserSettingsFile(session.getRequest().getUserSettingsFile()); final Invoker invoker = new DefaultInvoker(); diff --git a/src/main/java/org/openjfx/JavaFXRunMojo.java b/src/main/java/org/openjfx/JavaFXRunMojo.java index 460f4a9..d84f6c4 100644 --- a/src/main/java/org/openjfx/JavaFXRunMojo.java +++ b/src/main/java/org/openjfx/JavaFXRunMojo.java @@ -47,10 +47,10 @@ /** * Mojo to run a JavaFX application. * - * Mojo name change from 'run' to 'runx' is temporary. It will be reverted + * Mojo name change from 'run' to 'dorun' is temporary. It will be reverted * once JavaFX 17.x empty jars are available with Automatic-Module-Name. */ -@Mojo(name = "runx", requiresDependencyResolution = ResolutionScope.RUNTIME) +@Mojo(name = "dorun", requiresDependencyResolution = ResolutionScope.RUNTIME) @Execute(phase = LifecyclePhase.PROCESS_CLASSES) public class JavaFXRunMojo extends JavaFXBaseMojo { diff --git a/src/test/java/org/openjfx/JavaFXRunMojoTestCase.java b/src/test/java/org/openjfx/JavaFXRunMojoTestCase.java index 9c65e42..be215ed 100644 --- a/src/test/java/org/openjfx/JavaFXRunMojoTestCase.java +++ b/src/test/java/org/openjfx/JavaFXRunMojoTestCase.java @@ -41,7 +41,6 @@ import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory; import org.eclipse.aether.repository.LocalRepository; import org.junit.Assert; -import org.junit.Ignore; import org.junit.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -141,7 +140,7 @@ public void testClasspathNoLauncherRun() throws Exception { } protected JavaFXRunMojo getJavaFXRunMojo(File testPom) throws Exception { - JavaFXRunMojo mojo = (JavaFXRunMojo) lookupMojo("runx", testPom); + JavaFXRunMojo mojo = (JavaFXRunMojo) lookupMojo("dorun", testPom); assertNotNull(mojo); setUpProject(testPom, mojo);