Loading src/it/upload-app/pom.xml 0 → 100644 +70 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.inteligr8.alfresco</groupId> <artifactId>aps-model-maven-plugin-upload-app</artifactId> <version>@pom.version@</version> <packaging>pom</packaging> <name>Upload App Plugin Tests</name> <build> <plugins> <plugin> <groupId>${project.groupId}</groupId> <artifactId>aps-model-maven-plugin</artifactId> <version>@pom.version@</version> <executions> <execution> <id>download-unpack-app</id> <phase>generate-sources</phase> <goals> <goal>download-app</goal> <goal>unpack-app</goal> </goals> <configuration> <reformat>true</reformat> <normalize>true</normalize> </configuration> </execution> <execution> <id>translate-app</id> <phase>compile</phase> <goals> <goal>translate-app</goal> </goals> <configuration> <finalDirectory>${project.build.directory}/aps-dev</finalDirectory> </configuration> </execution> <execution> <id>pack-app</id> <phase>package</phase> <goals> <goal>pack-app</goal> </goals> <configuration> <unzipDirectory>${project.build.directory}/aps-dev</unzipDirectory> <zipDirectory>${project.build.directory}/aps-test</zipDirectory> </configuration> </execution> <execution> <id>upload-app</id> <phase>package</phase> <goals> <goal>upload-app</goal> </goals> <configuration> <zipDirectory>${project.build.directory}/aps-test</zipDirectory> </configuration> </execution> </executions> </plugin> </plugins> </build> </project> src/main/java/com/inteligr8/maven/aps/modeling/goal/ApsAppAccessibleGoal.java +5 −5 Original line number Diff line number Diff line Loading @@ -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<String, Long> 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; } Loading src/main/java/com/inteligr8/maven/aps/modeling/goal/DownloadAppGoal.java +1 −1 Original line number Diff line number Diff line Loading @@ -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"); Loading src/main/java/com/inteligr8/maven/aps/modeling/goal/UploadAppGoal.java 0 → 100644 +98 −0 Original line number Diff line number Diff line 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(); } } } Loading
src/it/upload-app/pom.xml 0 → 100644 +70 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.inteligr8.alfresco</groupId> <artifactId>aps-model-maven-plugin-upload-app</artifactId> <version>@pom.version@</version> <packaging>pom</packaging> <name>Upload App Plugin Tests</name> <build> <plugins> <plugin> <groupId>${project.groupId}</groupId> <artifactId>aps-model-maven-plugin</artifactId> <version>@pom.version@</version> <executions> <execution> <id>download-unpack-app</id> <phase>generate-sources</phase> <goals> <goal>download-app</goal> <goal>unpack-app</goal> </goals> <configuration> <reformat>true</reformat> <normalize>true</normalize> </configuration> </execution> <execution> <id>translate-app</id> <phase>compile</phase> <goals> <goal>translate-app</goal> </goals> <configuration> <finalDirectory>${project.build.directory}/aps-dev</finalDirectory> </configuration> </execution> <execution> <id>pack-app</id> <phase>package</phase> <goals> <goal>pack-app</goal> </goals> <configuration> <unzipDirectory>${project.build.directory}/aps-dev</unzipDirectory> <zipDirectory>${project.build.directory}/aps-test</zipDirectory> </configuration> </execution> <execution> <id>upload-app</id> <phase>package</phase> <goals> <goal>upload-app</goal> </goals> <configuration> <zipDirectory>${project.build.directory}/aps-test</zipDirectory> </configuration> </execution> </executions> </plugin> </plugins> </build> </project>
src/main/java/com/inteligr8/maven/aps/modeling/goal/ApsAppAccessibleGoal.java +5 −5 Original line number Diff line number Diff line Loading @@ -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<String, Long> 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; } Loading
src/main/java/com/inteligr8/maven/aps/modeling/goal/DownloadAppGoal.java +1 −1 Original line number Diff line number Diff line Loading @@ -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"); Loading
src/main/java/com/inteligr8/maven/aps/modeling/goal/UploadAppGoal.java 0 → 100644 +98 −0 Original line number Diff line number Diff line 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(); } } }