-
Notifications
You must be signed in to change notification settings - Fork 413
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added maven goals to build for specific targets without having to pro…
…vide 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.
- Loading branch information
Showing
13 changed files
with
1,151 additions
and
0 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
...aven-plugin/src/main/java/com/codename1/maven/buildWrappers/AbstractBuildWrapperMojo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
...plugin/src/main/java/com/codename1/maven/buildWrappers/BuildAndroidGradleProjectMojo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...ameone-maven-plugin/src/main/java/com/codename1/maven/buildWrappers/BuildAndroidMojo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...-maven-plugin/src/main/java/com/codename1/maven/buildWrappers/BuildExecutableJarMojo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...odenameone-maven-plugin/src/main/java/com/codename1/maven/buildWrappers/BuildIosMojo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...one-maven-plugin/src/main/java/com/codename1/maven/buildWrappers/BuildIosReleaseMojo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...aven-plugin/src/main/java/com/codename1/maven/buildWrappers/BuildIosXcodeProjectMojo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...one-maven-plugin/src/main/java/com/codename1/maven/buildWrappers/BuildJavascriptMojo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...one-maven-plugin/src/main/java/com/codename1/maven/buildWrappers/BuildMacDesktopMojo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...maven-plugin/src/main/java/com/codename1/maven/buildWrappers/BuildWindowsDesktopMojo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...-maven-plugin/src/main/java/com/codename1/maven/buildWrappers/BuildWindowsDeviceMojo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"; | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...ven-plugin/src/main/java/com/codename1/maven/intellij/InstallIntelliJRunProfilesMojo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} | ||
} |
Oops, something went wrong.