diff --git a/src/it/upload-app/pom.xml b/src/it/upload-app/pom.xml
new file mode 100644
index 0000000..b64bb4c
--- /dev/null
+++ b/src/it/upload-app/pom.xml
@@ -0,0 +1,70 @@
+
+
+
+ 4.0.0
+
+ com.inteligr8.alfresco
+ aps-model-maven-plugin-upload-app
+ @pom.version@
+ pom
+
+ Upload App Plugin Tests
+
+
+
+
+ ${project.groupId}
+ aps-model-maven-plugin
+ @pom.version@
+
+
+ download-unpack-app
+ generate-sources
+
+ download-app
+ unpack-app
+
+
+ true
+ true
+
+
+
+ translate-app
+ compile
+
+ translate-app
+
+
+ ${project.build.directory}/aps-dev
+
+
+
+ pack-app
+ package
+
+ pack-app
+
+
+ ${project.build.directory}/aps-dev
+ ${project.build.directory}/aps-test
+
+
+
+ upload-app
+ package
+
+ upload-app
+
+
+ ${project.build.directory}/aps-test
+
+
+
+
+
+
+
+
diff --git a/src/main/java/com/inteligr8/maven/aps/modeling/goal/ApsAppAccessibleGoal.java b/src/main/java/com/inteligr8/maven/aps/modeling/goal/ApsAppAccessibleGoal.java
index 489852a..2f0692e 100644
--- a/src/main/java/com/inteligr8/maven/aps/modeling/goal/ApsAppAccessibleGoal.java
+++ b/src/main/java/com/inteligr8/maven/aps/modeling/goal/ApsAppAccessibleGoal.java
@@ -42,15 +42,15 @@ public abstract class ApsAppAccessibleGoal extends ApsAddressibleGoal {
return apps;
}
- protected Long findAppId() throws MojoExecutionException {
- return this.findAppIdByName(this.apsAppName);
+ protected Long findAppId(boolean failOnNotFound) throws MojoExecutionException {
+ return this.findAppIdByName(this.apsAppName, failOnNotFound);
}
- protected Long findAppIdByName(String appName) throws MojoExecutionException {
+ protected Long findAppIdByName(String appName, boolean failOnNotFound) throws MojoExecutionException {
Map apps = this.findAppNameIds();
Long appId = apps.get(this.apsAppName);
- if (appId == null)
- throw new MojoExecutionException("The APS App '' could not be found; valid apps: " + apps.keySet());
+ if (failOnNotFound && appId == null)
+ throw new MojoExecutionException("The APS App '" + this.apsAppName + "' could not be found; valid apps: " + apps.keySet());
return appId;
}
diff --git a/src/main/java/com/inteligr8/maven/aps/modeling/goal/DownloadAppGoal.java b/src/main/java/com/inteligr8/maven/aps/modeling/goal/DownloadAppGoal.java
index 3b7001b..579efc6 100644
--- a/src/main/java/com/inteligr8/maven/aps/modeling/goal/DownloadAppGoal.java
+++ b/src/main/java/com/inteligr8/maven/aps/modeling/goal/DownloadAppGoal.java
@@ -23,7 +23,7 @@ public class DownloadAppGoal extends ApsAppAccessibleGoal {
public void executeEnabled() throws MojoExecutionException, MojoFailureException {
this.validateTargetDirectory();
- Long appId = this.findAppId();
+ Long appId = this.findAppId(true);
File appZip = this.downloadApp(appId);
File toAppZip = new File(this.zipDirectory, this.apsAppName + ".zip");
diff --git a/src/main/java/com/inteligr8/maven/aps/modeling/goal/UploadAppGoal.java b/src/main/java/com/inteligr8/maven/aps/modeling/goal/UploadAppGoal.java
new file mode 100644
index 0000000..3d0b1db
--- /dev/null
+++ b/src/main/java/com/inteligr8/maven/aps/modeling/goal/UploadAppGoal.java
@@ -0,0 +1,98 @@
+package com.inteligr8.maven.aps.modeling.goal;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.text.ParseException;
+
+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.Parameter;
+import org.codehaus.plexus.component.annotations.Component;
+
+import com.inteligr8.alfresco.activiti.ApsPublicRestApiJerseyImpl;
+import com.inteligr8.alfresco.activiti.model.AppDefinitionUpdateResultRepresentation;
+import com.inteligr8.alfresco.activiti.model.FileMultipartJersey;
+
+@Mojo( name = "upload-app", threadSafe = true )
+@Component( role = org.apache.maven.plugin.Mojo.class )
+public class UploadAppGoal extends ApsAppAccessibleGoal {
+
+ @Parameter( property = "aps-model.upload.directory", required = true, defaultValue = "${project.build.directory}/aps" )
+ protected File zipDirectory;
+
+ @Parameter( property = "publish", required = true, defaultValue = "false" )
+ protected boolean publish = false;
+
+ protected final int bufferSize = 128 * 1024;
+
+ @Override
+ public void executeEnabled() throws MojoExecutionException, MojoFailureException {
+ File sourceFile = this.validateSourceDirectory();
+
+ Long appId = this.findAppId(false);
+
+ try {
+ this.uploadApp(appId, sourceFile);
+ } catch (IOException ie) {
+ throw new MojoExecutionException("The APS App could not be uploaded", ie);
+ }
+ }
+
+ protected File validateSourceDirectory() {
+ if (!this.zipDirectory.exists()) {
+ throw new IllegalStateException("The 'zipDirectory' does not exist: " + this.zipDirectory);
+ } else if (!this.zipDirectory.isDirectory()) {
+ throw new IllegalStateException("The 'zipDirectory' is not a directory: " + this.zipDirectory);
+ }
+
+ File sourceFile = new File(this.zipDirectory, this.apsAppName + ".zip");
+
+ if (!sourceFile.exists()) {
+ throw new IllegalStateException("The App file does not exists in the 'zipDirectory': " + sourceFile);
+ } else if (!sourceFile.isFile()) {
+ throw new IllegalStateException("The App file is not a file: " + sourceFile);
+ }
+
+ return sourceFile;
+ }
+
+ private void uploadApp(Long appId, File appZip) throws IOException, MojoExecutionException {
+ ApsPublicRestApiJerseyImpl api = this.getApsApi();
+
+ FileInputStream fistream = new FileInputStream(appZip);
+ BufferedInputStream bistream = new BufferedInputStream(fistream, this.bufferSize);
+ try {
+ FileMultipartJersey multipart = FileMultipartJersey.from(appZip.getName(), bistream);
+
+ if (appId == null) {
+ if (this.publish) {
+ this.getLog().info("Uploading & publishing new APS App: " + this.apsAppName);
+ AppDefinitionUpdateResultRepresentation appDefUpdate = api.getAppDefinitionsJerseyApi().publishApp(multipart);
+ if (Boolean.TRUE.equals(appDefUpdate.getError()))
+ throw new MojoExecutionException(appDefUpdate.getErrorDescription());
+ } else {
+ this.getLog().info("Uploading new APS App: " + this.apsAppName);
+ api.getAppDefinitionsJerseyApi().importApp(multipart, true);
+ }
+ } else {
+ if (this.publish) {
+ this.getLog().info("Uploading, versioning, & publishing APS App: " + this.apsAppName + " (" + appId + ")");
+ AppDefinitionUpdateResultRepresentation appDefUpdate = api.getAppDefinitionsJerseyApi().publishApp(appId, multipart);
+ if (Boolean.TRUE.equals(appDefUpdate.getError()))
+ throw new MojoExecutionException(appDefUpdate.getErrorDescription());
+ } else {
+ this.getLog().info("Uploading & versioning APS App: " + this.apsAppName + " (" + appId + ")");
+ api.getAppDefinitionsJerseyApi().importApp(appId, multipart, true);
+ }
+ }
+ } catch (ParseException pe) {
+ throw new MojoExecutionException("The app ZIP could not be wrapped in a multipart", pe);
+ } finally {
+ bistream.close();
+ }
+ }
+
+}