From a86ec00a6fa3dc4e079974655b078767d9d57b5e Mon Sep 17 00:00:00 2001 From: Steve Hannah Date: Sun, 31 Dec 2023 08:12:54 -0800 Subject: [PATCH] added maven goals to build for specific targets without having to provide any profiles or properties This will make it easier to inspect the build targets that are available via the Maven side-bar. Goals include: build-android build-android-gradle-project build-jar build-ios build-ios-release build-ios-xcode-project build-javascript build-mac-desktop build-windows-desktop build-windows-uwp This also includes a goal to install the intelliJ run profiles into the project, in case they were lost. --- .../AbstractBuildWrapperMojo.java | 70 ++ .../BuildAndroidGradleProjectMojo.java | 19 + .../maven/buildWrappers/BuildAndroidMojo.java | 19 + .../buildWrappers/BuildExecutableJarMojo.java | 24 + .../maven/buildWrappers/BuildIosMojo.java | 19 + .../buildWrappers/BuildIosReleaseMojo.java | 19 + .../BuildIosXcodeProjectMojo.java | 19 + .../buildWrappers/BuildJavascriptMojo.java | 19 + .../buildWrappers/BuildMacDesktopMojo.java | 19 + .../BuildWindowsDesktopMojo.java | 19 + .../buildWrappers/BuildWindowsDeviceMojo.java | 19 + .../InstallIntelliJRunProfilesMojo.java | 37 + .../codename1/maven/intellij/workspace.xml | 849 ++++++++++++++++++ 13 files changed, 1151 insertions(+) create mode 100644 maven/codenameone-maven-plugin/src/main/java/com/codename1/maven/buildWrappers/AbstractBuildWrapperMojo.java create mode 100644 maven/codenameone-maven-plugin/src/main/java/com/codename1/maven/buildWrappers/BuildAndroidGradleProjectMojo.java create mode 100644 maven/codenameone-maven-plugin/src/main/java/com/codename1/maven/buildWrappers/BuildAndroidMojo.java create mode 100644 maven/codenameone-maven-plugin/src/main/java/com/codename1/maven/buildWrappers/BuildExecutableJarMojo.java create mode 100644 maven/codenameone-maven-plugin/src/main/java/com/codename1/maven/buildWrappers/BuildIosMojo.java create mode 100644 maven/codenameone-maven-plugin/src/main/java/com/codename1/maven/buildWrappers/BuildIosReleaseMojo.java create mode 100644 maven/codenameone-maven-plugin/src/main/java/com/codename1/maven/buildWrappers/BuildIosXcodeProjectMojo.java create mode 100644 maven/codenameone-maven-plugin/src/main/java/com/codename1/maven/buildWrappers/BuildJavascriptMojo.java create mode 100644 maven/codenameone-maven-plugin/src/main/java/com/codename1/maven/buildWrappers/BuildMacDesktopMojo.java create mode 100644 maven/codenameone-maven-plugin/src/main/java/com/codename1/maven/buildWrappers/BuildWindowsDesktopMojo.java create mode 100644 maven/codenameone-maven-plugin/src/main/java/com/codename1/maven/buildWrappers/BuildWindowsDeviceMojo.java create mode 100644 maven/codenameone-maven-plugin/src/main/java/com/codename1/maven/intellij/InstallIntelliJRunProfilesMojo.java create mode 100644 maven/codenameone-maven-plugin/src/main/resources/com/codename1/maven/intellij/workspace.xml diff --git a/maven/codenameone-maven-plugin/src/main/java/com/codename1/maven/buildWrappers/AbstractBuildWrapperMojo.java b/maven/codenameone-maven-plugin/src/main/java/com/codename1/maven/buildWrappers/AbstractBuildWrapperMojo.java new file mode 100644 index 0000000000..8b9407718b --- /dev/null +++ b/maven/codenameone-maven-plugin/src/main/java/com/codename1/maven/buildWrappers/AbstractBuildWrapperMojo.java @@ -0,0 +1,70 @@ +package com.codename1.maven.buildWrappers; + +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.project.MavenProject; +import org.apache.maven.shared.invoker.*; + +import java.io.File; +import java.util.Collections; +import java.util.Properties; + +/** + * Base class for build wrapper Mojos. + * + * Wrapper mojos were created to make it easier to build Codename One targets + * directly in IDEs like IntelliJ without having to provide any properties or profiles. + * + * The user will see "buildAndroid", "buildIos" and "buildIosXcodeProject" goals, etc.. + * listed in the Maven sidebar, and they can just double-click them to invoke them + * directly. + */ +public abstract class AbstractBuildWrapperMojo extends AbstractMojo { + + @Parameter(defaultValue = "${project}", readonly = true) + private MavenProject project; + + @Override + public void execute() throws MojoExecutionException, MojoFailureException { + if (!project.isExecutionRoot()) { + getLog().info("Skipping execution for non-root project"); + return; + } + InvocationRequest request = new DefaultInvocationRequest(); + request.setPomFile(new File("pom.xml")); + request.setGoals(Collections.singletonList("package")); + + Properties properties = new Properties(); + properties.setProperty("skipTests", "true"); + properties.setProperty("codename1.platform", getPlatform()); + if (getBuildTarget() != null) { + properties.setProperty("codename1.buildTarget", getBuildTarget()); + } + request.setProperties(properties); + + if (buildExecutableJar()) { + request.setProfiles(Collections.singletonList("executable-jar")); + } + + Invoker invoker = new DefaultInvoker(); + + try { + InvocationResult result = invoker.execute(request); + if (result.getExitCode() != 0) { + throw new MojoFailureException("Failed to build project with exit code " + result.getExitCode()); + } + } catch (MavenInvocationException e) { + throw new MojoExecutionException("Failed to invoke Maven", e); + } + } + + protected abstract String getPlatform(); + protected abstract String getBuildTarget(); + + protected boolean buildExecutableJar() { + return false; + } + +} diff --git a/maven/codenameone-maven-plugin/src/main/java/com/codename1/maven/buildWrappers/BuildAndroidGradleProjectMojo.java b/maven/codenameone-maven-plugin/src/main/java/com/codename1/maven/buildWrappers/BuildAndroidGradleProjectMojo.java new file mode 100644 index 0000000000..d10bc115c4 --- /dev/null +++ b/maven/codenameone-maven-plugin/src/main/java/com/codename1/maven/buildWrappers/BuildAndroidGradleProjectMojo.java @@ -0,0 +1,19 @@ +package com.codename1.maven.buildWrappers; + + +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.ResolutionScope; + +@Mojo(name="buildAndroidGradleProject", requiresDependencyResolution = ResolutionScope.NONE, + requiresDependencyCollection = ResolutionScope.NONE) +public class BuildAndroidGradleProjectMojo extends AbstractBuildWrapperMojo { + @Override + protected String getPlatform() { + return "android"; + } + + @Override + protected String getBuildTarget() { + return "android-source"; + } +} diff --git a/maven/codenameone-maven-plugin/src/main/java/com/codename1/maven/buildWrappers/BuildAndroidMojo.java b/maven/codenameone-maven-plugin/src/main/java/com/codename1/maven/buildWrappers/BuildAndroidMojo.java new file mode 100644 index 0000000000..ad37e16c33 --- /dev/null +++ b/maven/codenameone-maven-plugin/src/main/java/com/codename1/maven/buildWrappers/BuildAndroidMojo.java @@ -0,0 +1,19 @@ +package com.codename1.maven.buildWrappers; + + +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.ResolutionScope; + +@Mojo(name="buildAndroid", requiresDependencyResolution = ResolutionScope.NONE, + requiresDependencyCollection = ResolutionScope.NONE) +public class BuildAndroidMojo extends AbstractBuildWrapperMojo { + @Override + protected String getPlatform() { + return "android"; + } + + @Override + protected String getBuildTarget() { + return "android-device"; + } +} diff --git a/maven/codenameone-maven-plugin/src/main/java/com/codename1/maven/buildWrappers/BuildExecutableJarMojo.java b/maven/codenameone-maven-plugin/src/main/java/com/codename1/maven/buildWrappers/BuildExecutableJarMojo.java new file mode 100644 index 0000000000..bfd3917711 --- /dev/null +++ b/maven/codenameone-maven-plugin/src/main/java/com/codename1/maven/buildWrappers/BuildExecutableJarMojo.java @@ -0,0 +1,24 @@ +package com.codename1.maven.buildWrappers; + + +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.ResolutionScope; + +@Mojo(name="buildExecutableJar", requiresDependencyResolution = ResolutionScope.NONE, + requiresDependencyCollection = ResolutionScope.NONE) +public class BuildExecutableJarMojo extends AbstractBuildWrapperMojo { + @Override + protected String getPlatform() { + return "javase"; + } + + @Override + protected String getBuildTarget() { + return null; + } + + @Override + protected boolean buildExecutableJar() { + return true; + } +} diff --git a/maven/codenameone-maven-plugin/src/main/java/com/codename1/maven/buildWrappers/BuildIosMojo.java b/maven/codenameone-maven-plugin/src/main/java/com/codename1/maven/buildWrappers/BuildIosMojo.java new file mode 100644 index 0000000000..23f19e1791 --- /dev/null +++ b/maven/codenameone-maven-plugin/src/main/java/com/codename1/maven/buildWrappers/BuildIosMojo.java @@ -0,0 +1,19 @@ +package com.codename1.maven.buildWrappers; + + +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.ResolutionScope; + +@Mojo(name="buildIos", requiresDependencyResolution = ResolutionScope.NONE, + requiresDependencyCollection = ResolutionScope.NONE) +public class BuildIosMojo extends AbstractBuildWrapperMojo { + @Override + protected String getPlatform() { + return "ios"; + } + + @Override + protected String getBuildTarget() { + return "ios-device"; + } +} diff --git a/maven/codenameone-maven-plugin/src/main/java/com/codename1/maven/buildWrappers/BuildIosReleaseMojo.java b/maven/codenameone-maven-plugin/src/main/java/com/codename1/maven/buildWrappers/BuildIosReleaseMojo.java new file mode 100644 index 0000000000..ed9603353a --- /dev/null +++ b/maven/codenameone-maven-plugin/src/main/java/com/codename1/maven/buildWrappers/BuildIosReleaseMojo.java @@ -0,0 +1,19 @@ +package com.codename1.maven.buildWrappers; + + +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.ResolutionScope; + +@Mojo(name="buildIosRelease", requiresDependencyResolution = ResolutionScope.NONE, + requiresDependencyCollection = ResolutionScope.NONE) +public class BuildIosReleaseMojo extends AbstractBuildWrapperMojo { + @Override + protected String getPlatform() { + return "ios"; + } + + @Override + protected String getBuildTarget() { + return "ios-device-release"; + } +} diff --git a/maven/codenameone-maven-plugin/src/main/java/com/codename1/maven/buildWrappers/BuildIosXcodeProjectMojo.java b/maven/codenameone-maven-plugin/src/main/java/com/codename1/maven/buildWrappers/BuildIosXcodeProjectMojo.java new file mode 100644 index 0000000000..f40d60cbfc --- /dev/null +++ b/maven/codenameone-maven-plugin/src/main/java/com/codename1/maven/buildWrappers/BuildIosXcodeProjectMojo.java @@ -0,0 +1,19 @@ +package com.codename1.maven.buildWrappers; + + +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.ResolutionScope; + +@Mojo(name="buildIosXcodeProject", requiresDependencyResolution = ResolutionScope.NONE, + requiresDependencyCollection = ResolutionScope.NONE) +public class BuildIosXcodeProjectMojo extends AbstractBuildWrapperMojo { + @Override + protected String getPlatform() { + return "ios"; + } + + @Override + protected String getBuildTarget() { + return "ios-source"; + } +} diff --git a/maven/codenameone-maven-plugin/src/main/java/com/codename1/maven/buildWrappers/BuildJavascriptMojo.java b/maven/codenameone-maven-plugin/src/main/java/com/codename1/maven/buildWrappers/BuildJavascriptMojo.java new file mode 100644 index 0000000000..ef7958b580 --- /dev/null +++ b/maven/codenameone-maven-plugin/src/main/java/com/codename1/maven/buildWrappers/BuildJavascriptMojo.java @@ -0,0 +1,19 @@ +package com.codename1.maven.buildWrappers; + + +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.ResolutionScope; + +@Mojo(name="buildJavascript", requiresDependencyResolution = ResolutionScope.NONE, + requiresDependencyCollection = ResolutionScope.NONE) +public class BuildJavascriptMojo extends AbstractBuildWrapperMojo { + @Override + protected String getPlatform() { + return "javascript"; + } + + @Override + protected String getBuildTarget() { + return "javascript"; + } +} diff --git a/maven/codenameone-maven-plugin/src/main/java/com/codename1/maven/buildWrappers/BuildMacDesktopMojo.java b/maven/codenameone-maven-plugin/src/main/java/com/codename1/maven/buildWrappers/BuildMacDesktopMojo.java new file mode 100644 index 0000000000..9858caa0d0 --- /dev/null +++ b/maven/codenameone-maven-plugin/src/main/java/com/codename1/maven/buildWrappers/BuildMacDesktopMojo.java @@ -0,0 +1,19 @@ +package com.codename1.maven.buildWrappers; + + +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.ResolutionScope; + +@Mojo(name="buildMacDesktop", requiresDependencyResolution = ResolutionScope.NONE, + requiresDependencyCollection = ResolutionScope.NONE) +public class BuildMacDesktopMojo extends AbstractBuildWrapperMojo { + @Override + protected String getPlatform() { + return "javase"; + } + + @Override + protected String getBuildTarget() { + return "mac-os-x-desktop"; + } +} diff --git a/maven/codenameone-maven-plugin/src/main/java/com/codename1/maven/buildWrappers/BuildWindowsDesktopMojo.java b/maven/codenameone-maven-plugin/src/main/java/com/codename1/maven/buildWrappers/BuildWindowsDesktopMojo.java new file mode 100644 index 0000000000..2813ff33fc --- /dev/null +++ b/maven/codenameone-maven-plugin/src/main/java/com/codename1/maven/buildWrappers/BuildWindowsDesktopMojo.java @@ -0,0 +1,19 @@ +package com.codename1.maven.buildWrappers; + + +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.ResolutionScope; + +@Mojo(name="buildWindowsDesktop", requiresDependencyResolution = ResolutionScope.NONE, + requiresDependencyCollection = ResolutionScope.NONE) +public class BuildWindowsDesktopMojo extends AbstractBuildWrapperMojo { + @Override + protected String getPlatform() { + return "javase"; + } + + @Override + protected String getBuildTarget() { + return "windows-desktop"; + } +} diff --git a/maven/codenameone-maven-plugin/src/main/java/com/codename1/maven/buildWrappers/BuildWindowsDeviceMojo.java b/maven/codenameone-maven-plugin/src/main/java/com/codename1/maven/buildWrappers/BuildWindowsDeviceMojo.java new file mode 100644 index 0000000000..4de6fe6e03 --- /dev/null +++ b/maven/codenameone-maven-plugin/src/main/java/com/codename1/maven/buildWrappers/BuildWindowsDeviceMojo.java @@ -0,0 +1,19 @@ +package com.codename1.maven.buildWrappers; + + +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.ResolutionScope; + +@Mojo(name="buildWindowsUWP", requiresDependencyResolution = ResolutionScope.NONE, + requiresDependencyCollection = ResolutionScope.NONE) +public class BuildWindowsDeviceMojo extends AbstractBuildWrapperMojo { + @Override + protected String getPlatform() { + return "win"; + } + + @Override + protected String getBuildTarget() { + return "windows-device"; + } +} diff --git a/maven/codenameone-maven-plugin/src/main/java/com/codename1/maven/intellij/InstallIntelliJRunProfilesMojo.java b/maven/codenameone-maven-plugin/src/main/java/com/codename1/maven/intellij/InstallIntelliJRunProfilesMojo.java new file mode 100644 index 0000000000..b766774fac --- /dev/null +++ b/maven/codenameone-maven-plugin/src/main/java/com/codename1/maven/intellij/InstallIntelliJRunProfilesMojo.java @@ -0,0 +1,37 @@ +package com.codename1.maven.intellij; + +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.ResolutionScope; +import org.codehaus.plexus.util.FileUtils; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; + +/** + * Goal to install the IntelliJ run profiles for the project. + */ +@Mojo(name="configure-intellij", requiresDependencyResolution = ResolutionScope.NONE, + requiresDependencyCollection = ResolutionScope.NONE) +public class InstallIntelliJRunProfilesMojo extends AbstractMojo { + @Override + public void execute() throws MojoExecutionException, MojoFailureException { + File workspaceFile = new File(".idea/workspace.xml"); + if (!workspaceFile.exists()) { + throw new MojoFailureException("No workspace.xml file found. Please run this goal from the root of your IntelliJ project."); + } + + InputStream in = getClass().getResourceAsStream("workspace.xml"); + if (in == null) { + throw new MojoFailureException("Failed to find workspace.xml template in resources"); + } + try { + FileUtils.copyURLToFile(getClass().getResource("workspace.xml"), workspaceFile); + } catch (IOException ex) { + throw new MojoFailureException("Failed to copy workspace.xml template to " + workspaceFile.getAbsolutePath(), ex); + } + } +} diff --git a/maven/codenameone-maven-plugin/src/main/resources/com/codename1/maven/intellij/workspace.xml b/maven/codenameone-maven-plugin/src/main/resources/com/codename1/maven/intellij/workspace.xml new file mode 100644 index 0000000000..6a3d1984d4 --- /dev/null +++ b/maven/codenameone-maven-plugin/src/main/resources/com/codename1/maven/intellij/workspace.xml @@ -0,0 +1,849 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1613589489573 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file