From 72c1ac089f0d1ec73e8bafcf5f589ea971df4734 Mon Sep 17 00:00:00 2001 From: Abhinay Agarwal Date: Tue, 5 Oct 2021 07:36:50 +0530 Subject: [PATCH] Revert "Overload javafx:run goal to work with JavaFX 17 (#136)" (#140) This reverts commit 88781ed9148d6fd46d5ab745dba0deba2cc82719. --- pom.xml | 5 - .../java/org/openjfx/JavaFXRunFixMojo.java | 157 ------------------ src/main/java/org/openjfx/JavaFXRunMojo.java | 8 +- .../org/openjfx/model/JavaFXDependency.java | 63 ------- .../java/org/openjfx/model/JavaFXModule.java | 93 ----------- .../org/openjfx/JavaFXRunMojoTestCase.java | 2 +- 6 files changed, 2 insertions(+), 326 deletions(-) delete mode 100644 src/main/java/org/openjfx/JavaFXRunFixMojo.java delete mode 100644 src/main/java/org/openjfx/model/JavaFXDependency.java delete mode 100644 src/main/java/org/openjfx/model/JavaFXModule.java diff --git a/pom.xml b/pom.xml index d7bb34e..cbe84e9 100644 --- a/pom.xml +++ b/pom.xml @@ -63,11 +63,6 @@ commons-exec 1.3 - - org.apache.maven.shared - maven-invoker - 2.2 - diff --git a/src/main/java/org/openjfx/JavaFXRunFixMojo.java b/src/main/java/org/openjfx/JavaFXRunFixMojo.java deleted file mode 100644 index ebdf1de..0000000 --- a/src/main/java/org/openjfx/JavaFXRunFixMojo.java +++ /dev/null @@ -1,157 +0,0 @@ -/* - * 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.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; - -/** - * 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 { - - @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; - - @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(runpom).exists() ? runpom : 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.getTransitiveMavenDependencies(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 modified pom", e); - } - - invocationRequest.setPomFile(modifiedPomFile); - invocationRequest.setGoals(Collections.singletonList("javafx:dorun")); - invocationRequest.setUserSettingsFile(session.getRequest().getUserSettingsFile()); - - final Invoker invoker = new DefaultInvoker(); - 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/JavaFXRunMojo.java b/src/main/java/org/openjfx/JavaFXRunMojo.java index d84f6c4..a0c8d14 100644 --- a/src/main/java/org/openjfx/JavaFXRunMojo.java +++ b/src/main/java/org/openjfx/JavaFXRunMojo.java @@ -44,13 +44,7 @@ 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 'dorun' is temporary. It will be reverted - * once JavaFX 17.x empty jars are available with Automatic-Module-Name. - */ -@Mojo(name = "dorun", requiresDependencyResolution = ResolutionScope.RUNTIME) +@Mojo(name = "run", requiresDependencyResolution = ResolutionScope.RUNTIME) @Execute(phase = LifecyclePhase.PROCESS_CLASSES) public class JavaFXRunMojo extends JavaFXBaseMojo { diff --git a/src/main/java/org/openjfx/model/JavaFXDependency.java b/src/main/java/org/openjfx/model/JavaFXDependency.java deleted file mode 100644 index 337bd0f..0000000 --- a/src/main/java/org/openjfx/model/JavaFXDependency.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * 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; -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 deleted file mode 100644 index d3b418f..0000000 --- a/src/main/java/org/openjfx/model/JavaFXModule.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * 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 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 getTransitiveMavenDependencies(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; - } -} diff --git a/src/test/java/org/openjfx/JavaFXRunMojoTestCase.java b/src/test/java/org/openjfx/JavaFXRunMojoTestCase.java index be215ed..e643fce 100644 --- a/src/test/java/org/openjfx/JavaFXRunMojoTestCase.java +++ b/src/test/java/org/openjfx/JavaFXRunMojoTestCase.java @@ -140,7 +140,7 @@ public void testClasspathNoLauncherRun() throws Exception { } protected JavaFXRunMojo getJavaFXRunMojo(File testPom) throws Exception { - JavaFXRunMojo mojo = (JavaFXRunMojo) lookupMojo("dorun", testPom); + JavaFXRunMojo mojo = (JavaFXRunMojo) lookupMojo("run", testPom); assertNotNull(mojo); setUpProject(testPom, mojo);