diff --git a/pom.xml b/pom.xml
index 0088d9a..ce55cfa 100644
--- a/pom.xml
+++ b/pom.xml
@@ -184,6 +184,7 @@
jar
public
+ true
@@ -212,6 +213,13 @@
run
+
+ ${aps-model.baseUrl}
+ ${aps-model.authType}
+ ${aps-model.basicAuth.username}
+ ${aps-model.basicAuth.password}
+ ${aps-model.appName}
+
${run-it}/pom.xml
@@ -223,6 +231,14 @@
+
+
+
+ inteligr8-releases
+ Inteligr8 Releases
+ https://repos.inteligr8.com/nexus/repository/inteligr8-public
+
+
diff --git a/src/it/download-app/pom.xml b/src/it/download-app/pom.xml
index 6f4c9dd..e3d8f43 100644
--- a/src/it/download-app/pom.xml
+++ b/src/it/download-app/pom.xml
@@ -12,10 +12,6 @@
Download App Plugin Tests
-
- FORMS Core
-
-
@@ -29,9 +25,6 @@
download-app
-
- ${aps.app}
-
download-app-other
@@ -40,8 +33,7 @@
download-app
- ${aps.app}
- ${basedir}/src/main/app
+ ${basedir}/src/main/aps
@@ -57,8 +49,8 @@
- ${project.build.directory}/app/${aps.app}.zip
- ${basedir}/src/main/app/${aps.app}.zip
+ ${project.build.directory}/aps/${aps-model.appName}.zip
+ ${basedir}/src/main/aps/${aps-model.appName}.zip
diff --git a/src/it/translate-app/pom.xml b/src/it/translate-app/pom.xml
index 0d70c2a..0c0bc72 100644
--- a/src/it/translate-app/pom.xml
+++ b/src/it/translate-app/pom.xml
@@ -12,10 +12,6 @@
Translate App Plugin Tests
-
- FORMS Core
-
-
@@ -31,7 +27,7 @@
unpack-app
- ${aps.app}
+ true
@@ -41,8 +37,7 @@
translate-app
- ${aps.app}
- ${basedir}/src/main/app
+ ${basedir}/src/main/aps/app
@@ -58,7 +53,7 @@
- ${basedir}/src/main/app/${aps.app}/${aps.app}.json
+ ${basedir}/src/main/aps/app/${aps-model.appName}/${aps-model.appName}.json
diff --git a/src/it/unpack-app/pom.xml b/src/it/unpack-app/pom.xml
index 085b737..df47b5b 100644
--- a/src/it/unpack-app/pom.xml
+++ b/src/it/unpack-app/pom.xml
@@ -12,10 +12,6 @@
Unpack App Plugin Tests
-
- FORMS Core
-
-
@@ -30,9 +26,6 @@
download-app
unpack-app
-
- ${aps.app}
-
unpack-app
@@ -41,8 +34,7 @@
unpack-app
- ${aps.app}
- ${basedir}/src/main/app
+ ${basedir}/src/main/aps/app
@@ -58,8 +50,8 @@
- ${project.build.directory}/app/${aps.app}/${aps.app}.json
- ${basedir}/src/main/app/${aps.app}/${aps.app}.json
+ ${project.build.directory}/aps/app/${aps-model.appName}/${aps-model.appName}.json
+ ${basedir}/src/main/aps/app/${aps-model.appName}/${aps-model.appName}.json
diff --git a/src/main/java/com/inteligr8/maven/aps/modeling/ApsAppAccessibleGoal.java b/src/main/java/com/inteligr8/maven/aps/modeling/ApsAppAccessibleGoal.java
deleted file mode 100644
index d59ff31..0000000
--- a/src/main/java/com/inteligr8/maven/aps/modeling/ApsAppAccessibleGoal.java
+++ /dev/null
@@ -1,38 +0,0 @@
-package com.inteligr8.maven.aps.modeling;
-
-import java.util.List;
-
-import com.inteligr8.alfresco.activiti.ApsPublicRestApiJerseyImpl;
-import com.inteligr8.alfresco.activiti.api.ModelsApi.ModelType;
-import com.inteligr8.alfresco.activiti.model.Datum;
-import com.inteligr8.alfresco.activiti.model.ResultListDataRepresentation;
-import com.inteligr8.alfresco.activiti.model.Tenant;
-
-public abstract class ApsAppAccessibleGoal extends ApsAddressibleGoal {
-
- protected Long findTenantId() {
- List tenants = this.getApsApi().getAdminApi().getTenants();
- if (tenants == null || tenants.isEmpty())
- return null;
- return tenants.iterator().next().getId();
- }
-
- protected Long findAppByName(String appName) {
- ApsPublicRestApiJerseyImpl api = this.getApsApi();
-
- this.getLog().debug("Searching for APS App with name: " + appName);
- ResultListDataRepresentation results = api.getModelsApi().get(null, null, ModelType.App.getId(), null);
- this.getLog().debug("Found " + results.getTotal() + " APS Apps");
- for (Datum datum : results.getData()) {
- String name = (String)datum.getAdditionalProperties().get("name");
- if (name.equals(appName)) {
- Number id = (Number)datum.getAdditionalProperties().get("id");
- this.getLog().info("Found APS App ID: " + id);
- return id == null ? null : id.longValue();
- }
- }
-
- return null;
- }
-
-}
diff --git a/src/main/java/com/inteligr8/maven/aps/modeling/UnpackAppGoal.java b/src/main/java/com/inteligr8/maven/aps/modeling/UnpackAppGoal.java
deleted file mode 100644
index ed755e0..0000000
--- a/src/main/java/com/inteligr8/maven/aps/modeling/UnpackAppGoal.java
+++ /dev/null
@@ -1,186 +0,0 @@
-package com.inteligr8.maven.aps.modeling;
-
-import java.io.BufferedInputStream;
-import java.io.BufferedOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipInputStream;
-
-import javax.xml.transform.TransformerException;
-
-import org.apache.commons.io.IOUtils;
-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.Parameter;
-import org.codehaus.plexus.component.annotations.Component;
-import org.xml.sax.SAXException;
-
-@Mojo( name = "unpack-app", threadSafe = true )
-@Component( role = org.apache.maven.plugin.Mojo.class )
-public class UnpackAppGoal extends AbstractMojo {
-
- @Parameter( property = "apsAppName", required = true )
- protected String apsAppName;
-
- @Parameter( property = "sourceDirectory", required = true, defaultValue = "${project.build.directory}/app" )
- protected File sourceDirectory;
-
- @Parameter( property = "targetDirectory", required = true, defaultValue = "${project.build.directory}/app" )
- protected File targetDirectory;
-
- @Parameter( property = "charset", required = true, defaultValue = "utf-8" )
- protected String charsetName = "utf-8";
-
- @Parameter( property = "skip", required = true, defaultValue = "false" )
- protected boolean skip = false;
-
- private final int bufferSize = 128 * 1024;
-
- @Override
- public void execute() throws MojoExecutionException, MojoFailureException {
- File sourceFile = this.validateSourceDirectory();
-
- this.validateTargetDirectory();
- File appDirectory = this.validateAppDirectory();
- this.getLog().debug("Clearing directory: " + appDirectory);
- this.clearDirectory(appDirectory);
-
- try {
- this.unpack(sourceFile, appDirectory);
- } catch (IOException ie) {
- throw new MojoExecutionException("The downloaded APS App could not be unpacked", ie);
- }
-
- this.normalizeFiles(appDirectory);
- }
-
- protected File validateSourceDirectory() {
- if (!this.sourceDirectory.exists()) {
- throw new IllegalStateException("The 'sourceDirectory' does not exist: " + this.sourceDirectory);
- } else if (!this.sourceDirectory.isDirectory()) {
- throw new IllegalStateException("The 'sourceDirectory' is not a directory: " + this.sourceDirectory);
- }
-
- File sourceFile = new File(this.sourceDirectory, this.apsAppName + ".zip");
-
- if (!sourceFile.exists()) {
- throw new IllegalStateException("The App file does not exists in the 'sourceDirectory': " + sourceFile);
- } else if (!sourceFile.isFile()) {
- throw new IllegalStateException("The App file is not a file: " + sourceFile);
- }
-
- return sourceFile;
- }
-
- protected void validateTargetDirectory() {
- if (!this.targetDirectory.exists()) {
- this.getLog().debug("Creating APS Apps directory: " + this.targetDirectory);
- this.targetDirectory.mkdirs();
- } else if (!this.targetDirectory.isDirectory()) {
- throw new IllegalStateException("The 'apsAppsDirectory' refers to a file and not a directory: " + this.targetDirectory);
- }
- }
-
- protected File validateAppDirectory() {
- File appDirectory = new File(this.targetDirectory, this.apsAppName);
- if (!appDirectory.exists()) {
- this.getLog().debug("Creating APS App directory: " + appDirectory);
- appDirectory.mkdirs();
- } else if (!appDirectory.isDirectory()) {
- throw new IllegalStateException("The 'apsAppsDirectory' has a file where nothing or a directory is expected: " + appDirectory);
- }
-
- return appDirectory;
- }
-
- private void unpack(File appZip, File targetDirectory) throws IOException {
- FileInputStream fistream = new FileInputStream(appZip);
- BufferedInputStream bistream = new BufferedInputStream(fistream, this.bufferSize);
- try {
- ZipInputStream zistream = new ZipInputStream(bistream);
- try {
- for (ZipEntry zentry = zistream.getNextEntry(); zentry != null; zentry = zistream.getNextEntry()) {
- try {
- String path = zentry.getName();
- if (!zentry.isDirectory()) {
- this.getLog().debug("Unzipping path: " + zentry.getName());
- this.unzipToPath(zistream, Paths.get(path), targetDirectory);
- }
- } finally {
- zistream.closeEntry();
- }
- }
- } finally {
- zistream.close();
- }
- } finally {
- bistream.close();
- }
- }
-
- private void unzipToPath(InputStream istream, Path relativePath, File targetDirectory) throws IOException {
- Path path = targetDirectory.toPath().resolve(relativePath);
- Path folderPath = path.getParent();
- Files.createDirectories(folderPath);
-
- FileOutputStream fostream = new FileOutputStream(path.toFile());
- BufferedOutputStream bostream = new BufferedOutputStream(fostream);
- try {
- IOUtils.copy(istream, bostream);
- } finally {
- bostream.close();
- }
- }
-
- private void clearDirectory(File directory) {
- for (File file : directory.listFiles()) {
- if (file.isDirectory())
- this.clearDirectory(file);
- file.delete();
- }
- }
-
- private void normalizeFiles(File directory) throws MojoFailureException {
- for (File file : directory.listFiles()) {
- if (file.isDirectory()) {
- this.normalizeFiles(file);
- } else {
- String ext = this.getFileExtension(file);
-
- try {
- switch (ext) {
- case "json":
- ModelUtil.getInstance().json(file);
- break;
- case "xml":
- case "bpmn":
- ModelUtil.getInstance().xml(file);
- break;
- default:
- file.delete();
- }
- } catch (TransformerException | SAXException | IOException e) {
- throw new MojoFailureException("The following file faild to be reformatted: " + file, e);
- }
- }
- }
- }
-
- private String getFileExtension(File file) {
- int lastdot = file.getName().lastIndexOf('.');
- if (lastdot < 0)
- return null;
-
- return file.getName().substring(lastdot+1).toLowerCase();
- }
-
-}
diff --git a/src/main/java/com/inteligr8/maven/aps/modeling/ApsAddressibleGoal.java b/src/main/java/com/inteligr8/maven/aps/modeling/goal/ApsAddressibleGoal.java
similarity index 65%
rename from src/main/java/com/inteligr8/maven/aps/modeling/ApsAddressibleGoal.java
rename to src/main/java/com/inteligr8/maven/aps/modeling/goal/ApsAddressibleGoal.java
index 5da59ff..5141963 100644
--- a/src/main/java/com/inteligr8/maven/aps/modeling/ApsAddressibleGoal.java
+++ b/src/main/java/com/inteligr8/maven/aps/modeling/goal/ApsAddressibleGoal.java
@@ -1,47 +1,47 @@
-package com.inteligr8.maven.aps.modeling;
+package com.inteligr8.maven.aps.modeling.goal;
-import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugins.annotations.Parameter;
import com.inteligr8.alfresco.activiti.ApsClientConfiguration;
import com.inteligr8.alfresco.activiti.ApsClientJerseyImpl;
import com.inteligr8.alfresco.activiti.ApsPublicRestApiJerseyImpl;
-public abstract class ApsAddressibleGoal extends AbstractMojo {
+public abstract class ApsAddressibleGoal extends DisablableGoal {
- @Parameter( property = "activitiAppBaseUrl", required = true, defaultValue = "http://localhost:8080/activiti-app" )
+ @Parameter( property = "aps-model.baseUrl", required = true, defaultValue = "http://localhost:8080/activiti-app" )
protected String activitiAppBaseUrl;
- @Parameter( property = "activitiAppAuth", required = true, defaultValue = "BASIC" )
+ @Parameter( property = "aps-model.authType", required = true, defaultValue = "BASIC" )
protected String activitiAppAuthType;
- @Parameter( property = "activitiAppBasicUsername", required = false, defaultValue = "admin" )
+ @Parameter( property = "aps-model.basicAuth.username", required = false, defaultValue = "admin@app.activiti.com" )
protected String activitiAppAuthBasicUsername;
- @Parameter( property = "activitiAppBasicPassword", required = false, defaultValue = "admin" )
+ @Parameter( property = "aps-model.basicAuth.password", required = false, defaultValue = "admin" )
protected String activitiAppAuthBasicPassword;
- @Parameter( property = "oAuthCode", required = false )
+ @Parameter( property = "aps-model.oauth.code", required = false )
protected String oauthCode;
- @Parameter( property = "oAuthClientId", required = false )
+ @Parameter( property = "aps-model.oauth.clientId", required = false )
protected String oauthClientId;
- @Parameter( property = "oAuthClientSecret", required = false )
+ @Parameter( property = "aps-model.oauth.clientSecret", required = false )
protected String oauthClientSecret;
- @Parameter( property = "oAuthUsername", required = false )
+ @Parameter( property = "aps-model.oauth.username", required = false )
protected String oauthUsername;
- @Parameter( property = "oAuthPassword", required = false )
+ @Parameter( property = "aps-model.oauth.password", required = false )
protected String oauthPassword;
- @Parameter( property = "oAuthTokenUrl", required = false )
+ @Parameter( property = "aps-model.oauth.tokenUrl", required = false )
protected String oauthTokenUrl;
private ApsPublicRestApiJerseyImpl api;
public ApsClientConfiguration getApsClientConfiguration() {
+ this.getLog().debug("Configuring APS to URL: " + this.activitiAppBaseUrl);
ApsClientConfiguration config = new ApsClientConfiguration();
config.setBaseUrl(this.activitiAppBaseUrl);
switch (this.activitiAppAuthType.toUpperCase()) {
@@ -64,7 +64,7 @@ public abstract class ApsAddressibleGoal extends AbstractMojo {
config.setOAuthPassword(this.oauthPassword);
break;
default:
- throw new IllegalArgumentException("The 'activitiAppAuth' configuration must be either 'Basic' or 'OAuth'");
+ throw new IllegalArgumentException("The 'activitiAppAuthType' configuration must be either 'Basic' or 'OAuth'");
}
return config;
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
new file mode 100644
index 0000000..489852a
--- /dev/null
+++ b/src/main/java/com/inteligr8/maven/aps/modeling/goal/ApsAppAccessibleGoal.java
@@ -0,0 +1,57 @@
+package com.inteligr8.maven.aps.modeling.goal;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugins.annotations.Parameter;
+
+import com.inteligr8.alfresco.activiti.ApsPublicRestApiJerseyImpl;
+import com.inteligr8.alfresco.activiti.api.ModelsApi.ModelType;
+import com.inteligr8.alfresco.activiti.model.Datum;
+import com.inteligr8.alfresco.activiti.model.ResultListDataRepresentation;
+import com.inteligr8.alfresco.activiti.model.Tenant;
+
+public abstract class ApsAppAccessibleGoal extends ApsAddressibleGoal {
+
+ @Parameter( property = "aps-model.appName", required = true )
+ protected String apsAppName;
+
+ protected Long findTenantId() {
+ List tenants = this.getApsApi().getAdminApi().getTenants();
+ if (tenants == null || tenants.isEmpty())
+ return null;
+ return tenants.iterator().next().getId();
+ }
+
+ protected Map findAppNameIds() {
+ ApsPublicRestApiJerseyImpl api = this.getApsApi();
+
+ Map apps = new HashMap<>(16);
+
+ this.getLog().debug("Searching for all APS Apps");
+ ResultListDataRepresentation results = api.getModelsApi().get("everyone", null, ModelType.App.getId(), null);
+ this.getLog().debug("Found " + results.getTotal() + " APS Apps");
+ for (Datum datum : results.getData()) {
+ String name = (String)datum.getAdditionalProperties().get("name");
+ Number id = (Number)datum.getAdditionalProperties().get("id");
+ apps.put(name, id.longValue());
+ }
+
+ return apps;
+ }
+
+ protected Long findAppId() throws MojoExecutionException {
+ return this.findAppIdByName(this.apsAppName);
+ }
+
+ protected Long findAppIdByName(String appName) 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());
+ return appId;
+ }
+
+}
diff --git a/src/main/java/com/inteligr8/maven/aps/modeling/goal/ApsAppGoal.java b/src/main/java/com/inteligr8/maven/aps/modeling/goal/ApsAppGoal.java
new file mode 100644
index 0000000..e60b081
--- /dev/null
+++ b/src/main/java/com/inteligr8/maven/aps/modeling/goal/ApsAppGoal.java
@@ -0,0 +1,10 @@
+package com.inteligr8.maven.aps.modeling.goal;
+
+import org.apache.maven.plugins.annotations.Parameter;
+
+public abstract class ApsAppGoal extends DisablableGoal {
+
+ @Parameter( property = "aps-model.appName", required = true )
+ protected String apsAppName;
+
+}
diff --git a/src/main/java/com/inteligr8/maven/aps/modeling/ApsInfoGoal.java b/src/main/java/com/inteligr8/maven/aps/modeling/goal/ApsInfoGoal.java
similarity index 85%
rename from src/main/java/com/inteligr8/maven/aps/modeling/ApsInfoGoal.java
rename to src/main/java/com/inteligr8/maven/aps/modeling/goal/ApsInfoGoal.java
index 07b8d01..d3764d5 100644
--- a/src/main/java/com/inteligr8/maven/aps/modeling/ApsInfoGoal.java
+++ b/src/main/java/com/inteligr8/maven/aps/modeling/goal/ApsInfoGoal.java
@@ -1,4 +1,4 @@
-package com.inteligr8.maven.aps.modeling;
+package com.inteligr8.maven.aps.modeling.goal;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
@@ -12,7 +12,7 @@ import com.inteligr8.alfresco.activiti.model.AppVersion;
public class ApsInfoGoal extends ApsAddressibleGoal {
@Override
- public void execute() throws MojoExecutionException, MojoFailureException {
+ public void executeEnabled() throws MojoExecutionException, MojoFailureException {
AppVersion version = this.getApsApi()
.getAppVersionApi()
.get();
diff --git a/src/main/java/com/inteligr8/maven/aps/modeling/DeployAppGoal.java b/src/main/java/com/inteligr8/maven/aps/modeling/goal/DeployAppGoal.java
similarity index 89%
rename from src/main/java/com/inteligr8/maven/aps/modeling/DeployAppGoal.java
rename to src/main/java/com/inteligr8/maven/aps/modeling/goal/DeployAppGoal.java
index 07eee07..1a7d87e 100644
--- a/src/main/java/com/inteligr8/maven/aps/modeling/DeployAppGoal.java
+++ b/src/main/java/com/inteligr8/maven/aps/modeling/goal/DeployAppGoal.java
@@ -1,4 +1,4 @@
-package com.inteligr8.maven.aps.modeling;
+package com.inteligr8.maven.aps.modeling.goal;
import java.io.BufferedInputStream;
import java.io.File;
@@ -19,26 +19,21 @@ import com.inteligr8.alfresco.activiti.model.AppDefinitionUpdateResultRepresenta
@Component( role = org.apache.maven.plugin.Mojo.class )
public class DeployAppGoal extends ApsAppAccessibleGoal {
- @Parameter( property = "apsAppName", required = true )
- protected String apsAppName;
-
- @Parameter( property = "sourceDirectory", required = true, defaultValue = "${project.build.directory}/app" )
+ @Parameter( property = "sourceDirectory", required = true, defaultValue = "${project.build.directory}/aps/app" )
protected File sourceDirectory;
@Parameter( property = "publish", required = true, defaultValue = "false" )
protected boolean publish = false;
- @Parameter( property = "skip", required = true, defaultValue = "false" )
- protected boolean skip = false;
-
protected final int bufferSize = 128 * 1024;
@Override
- public void execute() throws MojoExecutionException, MojoFailureException {
+ public void executeEnabled() throws MojoExecutionException, MojoFailureException {
File sourceFile = this.validateSourceDirectory();
+ Long appId = this.findAppId();
+
try {
- Long appId = this.findAppByName(this.apsAppName);
this.uploadApp(appId, sourceFile);
} catch (IOException ie) {
throw new MojoExecutionException("The downloaded APS App could not be unpacked", ie);
diff --git a/src/main/java/com/inteligr8/maven/aps/modeling/goal/DisablableGoal.java b/src/main/java/com/inteligr8/maven/aps/modeling/goal/DisablableGoal.java
new file mode 100644
index 0000000..ba1c368
--- /dev/null
+++ b/src/main/java/com/inteligr8/maven/aps/modeling/goal/DisablableGoal.java
@@ -0,0 +1,29 @@
+package com.inteligr8.maven.aps.modeling.goal;
+
+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;
+
+public abstract class DisablableGoal extends AbstractMojo {
+
+ @Parameter( property = "aps-model.skip", required = true, defaultValue = "false" )
+ protected boolean skip = false;
+
+ protected boolean isEnabled() {
+ return !this.skip;
+ }
+
+ protected boolean isDisabled() {
+ return this.skip;
+ }
+
+ @Override
+ public final void execute() throws MojoExecutionException, MojoFailureException {
+ if (this.isEnabled())
+ this.executeEnabled();
+ }
+
+ public abstract void executeEnabled() throws MojoExecutionException, MojoFailureException;
+
+}
diff --git a/src/main/java/com/inteligr8/maven/aps/modeling/DownloadAppGoal.java b/src/main/java/com/inteligr8/maven/aps/modeling/goal/DownloadAppGoal.java
similarity index 61%
rename from src/main/java/com/inteligr8/maven/aps/modeling/DownloadAppGoal.java
rename to src/main/java/com/inteligr8/maven/aps/modeling/goal/DownloadAppGoal.java
index ce95e70..3b7001b 100644
--- a/src/main/java/com/inteligr8/maven/aps/modeling/DownloadAppGoal.java
+++ b/src/main/java/com/inteligr8/maven/aps/modeling/goal/DownloadAppGoal.java
@@ -1,4 +1,4 @@
-package com.inteligr8.maven.aps.modeling;
+package com.inteligr8.maven.aps.modeling.goal;
import java.io.File;
import java.io.IOException;
@@ -16,23 +16,17 @@ import com.inteligr8.alfresco.activiti.ApsPublicRestApiJerseyImpl;
@Component( role = org.apache.maven.plugin.Mojo.class )
public class DownloadAppGoal extends ApsAppAccessibleGoal {
- @Parameter( property = "apsAppName", required = true )
- protected String apsAppName;
-
- @Parameter( property = "targetDirectory", required = true, defaultValue = "${project.build.directory}/app" )
- protected File targetDirectory;
-
- @Parameter( property = "skip", required = true, defaultValue = "false" )
- protected boolean skip = false;
+ @Parameter( property = "aps-model.download.directory", required = true, defaultValue = "${project.build.directory}/aps" )
+ protected File zipDirectory;
@Override
- public void execute() throws MojoExecutionException, MojoFailureException {
+ public void executeEnabled() throws MojoExecutionException, MojoFailureException {
this.validateTargetDirectory();
- long appId = this.findAppByName(this.apsAppName);
+ Long appId = this.findAppId();
File appZip = this.downloadApp(appId);
- File toAppZip = new File(this.targetDirectory, this.apsAppName + ".zip");
+ File toAppZip = new File(this.zipDirectory, this.apsAppName + ".zip");
if (toAppZip.exists())
toAppZip.delete();
@@ -44,10 +38,10 @@ public class DownloadAppGoal extends ApsAppAccessibleGoal {
}
protected void validateTargetDirectory() {
- if (!this.targetDirectory.exists()) {
- this.getLog().debug("Creating APS Apps directory: " + this.targetDirectory);
- this.targetDirectory.mkdirs();
- } else if (!this.targetDirectory.isDirectory()) {
+ if (!this.zipDirectory.exists()) {
+ this.getLog().debug("Creating APS Apps directory: " + this.zipDirectory);
+ this.zipDirectory.mkdirs();
+ } else if (!this.zipDirectory.isDirectory()) {
throw new IllegalStateException("The 'targetDirectory' refers to a file and not a directory");
}
}
diff --git a/src/main/java/com/inteligr8/maven/aps/modeling/PackAppGoal.java b/src/main/java/com/inteligr8/maven/aps/modeling/goal/PackAppGoal.java
similarity index 89%
rename from src/main/java/com/inteligr8/maven/aps/modeling/PackAppGoal.java
rename to src/main/java/com/inteligr8/maven/aps/modeling/goal/PackAppGoal.java
index fb24f77..2db4965 100644
--- a/src/main/java/com/inteligr8/maven/aps/modeling/PackAppGoal.java
+++ b/src/main/java/com/inteligr8/maven/aps/modeling/goal/PackAppGoal.java
@@ -1,4 +1,4 @@
-package com.inteligr8.maven.aps.modeling;
+package com.inteligr8.maven.aps.modeling.goal;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
@@ -12,7 +12,6 @@ import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import org.apache.commons.io.IOUtils;
-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;
@@ -21,24 +20,18 @@ import org.codehaus.plexus.component.annotations.Component;
@Mojo( name = "pack-app", threadSafe = true )
@Component( role = org.apache.maven.plugin.Mojo.class )
-public class PackAppGoal extends AbstractMojo {
+public class PackAppGoal extends ApsAppGoal {
- @Parameter( property = "apsAppName", required = true )
- protected String apsAppName;
-
- @Parameter( property = "sourceDirectory", required = true, defaultValue = "${project.build.directory}/app" )
+ @Parameter( property = "sourceDirectory", required = true, defaultValue = "${project.build.directory}/aps/app" )
protected File sourceDirectory;
- @Parameter( property = "targetDirectory", required = true, defaultValue = "${project.build.directory}/app" )
+ @Parameter( property = "targetDirectory", required = true, defaultValue = "${project.build.directory}/aps/app" )
protected File targetDirectory;
- @Parameter( property = "skip", required = true, defaultValue = "false" )
- protected boolean skip = false;
-
protected final int bufferSize = 128 * 1024;
@Override
- public void execute() throws MojoExecutionException, MojoFailureException {
+ public void executeEnabled() throws MojoExecutionException, MojoFailureException {
this.validateSourceDirectory();
File appDirectory = this.validateAppDirectory();
diff --git a/src/main/java/com/inteligr8/maven/aps/modeling/TranslateAppGoal.java b/src/main/java/com/inteligr8/maven/aps/modeling/goal/TranslateAppGoal.java
similarity index 59%
rename from src/main/java/com/inteligr8/maven/aps/modeling/TranslateAppGoal.java
rename to src/main/java/com/inteligr8/maven/aps/modeling/goal/TranslateAppGoal.java
index faa79ba..5f8a178 100644
--- a/src/main/java/com/inteligr8/maven/aps/modeling/TranslateAppGoal.java
+++ b/src/main/java/com/inteligr8/maven/aps/modeling/goal/TranslateAppGoal.java
@@ -1,4 +1,4 @@
-package com.inteligr8.maven.aps.modeling;
+package com.inteligr8.maven.aps.modeling.goal;
import java.io.File;
import java.io.IOException;
@@ -12,6 +12,8 @@ import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.component.annotations.Component;
+import com.inteligr8.maven.aps.modeling.translator.ApsAppTranslator;
+
@Mojo( name = "translate-app", threadSafe = true )
@Component( role = org.apache.maven.plugin.Mojo.class )
public class TranslateAppGoal extends ApsAppAccessibleGoal {
@@ -22,26 +24,20 @@ public class TranslateAppGoal extends ApsAppAccessibleGoal {
@Parameter( defaultValue = "${session}", readonly = true )
protected MavenSession session;
- @Parameter( property = "apsAppName", required = true )
- protected String apsAppName;
-
- @Parameter( property = "sourceDirectory", required = true, defaultValue = "${project.build.directory}/app" )
- protected File sourceDirectory;
+ @Parameter( property = "aps-model.app.directory", required = true, defaultValue = "${project.build.directory}/aps/app" )
+ protected File unzipDirectory;
- @Parameter( property = "targetDirectory", required = false, defaultValue = "${project.build.directory}/app" )
- protected File targetDirectory;
+ @Parameter( property = "aps-model.translatedApp.directory", required = false, defaultValue = "${project.build.directory}/aps/app" )
+ protected File finalDirectory;
- @Parameter( property = "overwrite", required = true, defaultValue = "true" )
+ @Parameter( property = "aps-model.translate.overwrite", required = true, defaultValue = "true" )
protected boolean overwrite = true;
- @Parameter( property = "charset", required = true, defaultValue = "utf-8" )
+ @Parameter( property = "aps-model.translate.charset", required = true, defaultValue = "utf-8" )
protected String charsetName = "utf-8";
- @Parameter( property = "skip", required = true, defaultValue = "false" )
- protected boolean skip = false;
-
@Override
- public void execute() throws MojoExecutionException, MojoFailureException {
+ public void executeEnabled() throws MojoExecutionException, MojoFailureException {
File apsAppDirectory = this.validateApsAppDirectory();
File newApsAppDirectory = this.validateTargetDirectory();
@@ -63,34 +59,34 @@ public class TranslateAppGoal extends ApsAppAccessibleGoal {
}
protected File validateApsAppDirectory() throws MojoExecutionException {
- if (!this.sourceDirectory.exists())
- throw new MojoExecutionException("The 'sourceDirectory' does not exist: " + this.sourceDirectory);
- if (!this.sourceDirectory.isDirectory())
- throw new MojoExecutionException("The 'sourceDirectory' is not a directory: " + this.sourceDirectory);
+ if (!this.unzipDirectory.exists())
+ throw new MojoExecutionException("The 'unzipDirectory' does not exist: " + this.unzipDirectory);
+ if (!this.unzipDirectory.isDirectory())
+ throw new MojoExecutionException("The 'unzipDirectory' is not a directory: " + this.unzipDirectory);
- File appDirectory = new File(this.sourceDirectory, this.apsAppName);
+ File appDirectory = new File(this.unzipDirectory, this.apsAppName);
if (!appDirectory.exists())
- throw new MojoExecutionException("The 'apsAppName' does not exist in the 'apsAppsDirectory': " + appDirectory);
+ throw new MojoExecutionException("The 'apsAppName' does not exist in the 'unzipDirectory': " + appDirectory);
if (!appDirectory.isDirectory())
- throw new MojoExecutionException("The 'apsAppName' is not a directory in the 'apsAppsDirectory': " + appDirectory);
+ throw new MojoExecutionException("The 'apsAppName' is not a directory in the 'unzipDirectory': " + appDirectory);
return appDirectory;
}
protected File validateTargetDirectory() throws MojoExecutionException {
- if (!this.targetDirectory.exists()) {
- this.targetDirectory.mkdirs();
- } else if (!this.targetDirectory.isDirectory()) {
- throw new MojoExecutionException("The 'targetDirectory' is not a directory: " + this.targetDirectory);
+ if (!this.finalDirectory.exists()) {
+ this.finalDirectory.mkdirs();
+ } else if (!this.finalDirectory.isDirectory()) {
+ throw new MojoExecutionException("The 'finalDirectory' is not a directory: " + this.finalDirectory);
}
- File appDirectory = new File(this.targetDirectory, this.apsAppName);
+ File appDirectory = new File(this.finalDirectory, this.apsAppName);
if (!appDirectory.exists()) {
appDirectory.mkdirs();
} else if (!appDirectory.isDirectory()) {
- throw new MojoExecutionException("The 'apsAppName' is not a directory in the 'targetDirectory': " + appDirectory);
+ throw new MojoExecutionException("The 'apsAppName' is not a directory in the 'finalDirectory': " + appDirectory);
}
return appDirectory;
diff --git a/src/main/java/com/inteligr8/maven/aps/modeling/goal/UnpackAppGoal.java b/src/main/java/com/inteligr8/maven/aps/modeling/goal/UnpackAppGoal.java
new file mode 100644
index 0000000..d597d4e
--- /dev/null
+++ b/src/main/java/com/inteligr8/maven/aps/modeling/goal/UnpackAppGoal.java
@@ -0,0 +1,302 @@
+package com.inteligr8.maven.aps.modeling.goal;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.List;
+import java.util.Map;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+
+import javax.xml.transform.TransformerException;
+
+import org.apache.commons.io.IOUtils;
+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 org.w3c.dom.Document;
+import org.xml.sax.SAXException;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.inteligr8.maven.aps.modeling.util.ApsModelArrayNodeSorter;
+import com.inteligr8.maven.aps.modeling.util.ApsModelListMapSorter;
+import com.inteligr8.maven.aps.modeling.util.ModelUtil;
+
+@Mojo( name = "unpack-app", threadSafe = true )
+@Component( role = org.apache.maven.plugin.Mojo.class )
+public class UnpackAppGoal extends ApsAppGoal {
+
+ @Parameter( property = "aps-model.download.directory", required = true, defaultValue = "${project.build.directory}/aps" )
+ protected File zipDirectory;
+
+ @Parameter( property = "aps-model.app.directory", required = true, defaultValue = "${project.build.directory}/aps/app" )
+ protected File unzipDirectory;
+
+ @Parameter( property = "aps-model.reformat", required = true, defaultValue = "true" )
+ protected boolean reformat = true;
+
+ @Parameter( property = "aps-model.normalize", required = true, defaultValue = "false" )
+ protected boolean normalize;
+
+ @Parameter( property = "aps-model.charset", required = true, defaultValue = "utf-8" )
+ protected String charsetName = "utf-8";
+
+ private final int bufferSize = 128 * 1024;
+
+ @Override
+ public void executeEnabled() throws MojoExecutionException, MojoFailureException {
+ this.validate();
+
+ File sourceFile = this.validateSourceDirectory();
+
+ this.validateTargetDirectory();
+ File appDirectory = this.validateAppDirectory();
+ this.getLog().debug("Clearing directory: " + appDirectory);
+ this.clearDirectory(appDirectory);
+
+ try {
+ this.unpack(sourceFile, appDirectory);
+ } catch (IOException ie) {
+ throw new MojoExecutionException("The downloaded APS App could not be unpacked", ie);
+ }
+
+ if (this.reformat)
+ this.reformatFiles(appDirectory);
+ }
+
+ protected void validate() {
+ if (this.normalize && !this.reformat) {
+ this.getLog().warn("The reformat option is disabled, but normalization is enabled; enabling reformat anyway");
+ this.reformat = true;
+ }
+ }
+
+ 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;
+ }
+
+ protected void validateTargetDirectory() {
+ if (!this.unzipDirectory.exists()) {
+ this.getLog().debug("Creating unzip directory: " + this.unzipDirectory);
+ this.unzipDirectory.mkdirs();
+ } else if (!this.unzipDirectory.isDirectory()) {
+ throw new IllegalStateException("The 'unzipDirectory' refers to a file and not a directory: " + this.unzipDirectory);
+ }
+ }
+
+ protected File validateAppDirectory() {
+ File appDirectory = new File(this.unzipDirectory, this.apsAppName);
+ if (!appDirectory.exists()) {
+ this.getLog().debug("Creating APS App directory: " + appDirectory);
+ appDirectory.mkdirs();
+ } else if (!appDirectory.isDirectory()) {
+ throw new IllegalStateException("The 'apsAppsDirectory' has a file where nothing or a directory is expected: " + appDirectory);
+ }
+
+ return appDirectory;
+ }
+
+ private void unpack(File appZip, File targetDirectory) throws IOException {
+ FileInputStream fistream = new FileInputStream(appZip);
+ BufferedInputStream bistream = new BufferedInputStream(fistream, this.bufferSize);
+ try {
+ ZipInputStream zistream = new ZipInputStream(bistream);
+ try {
+ for (ZipEntry zentry = zistream.getNextEntry(); zentry != null; zentry = zistream.getNextEntry()) {
+ try {
+ String path = zentry.getName();
+ if (!zentry.isDirectory()) {
+ this.getLog().debug("Unzipping path: " + zentry.getName());
+ this.unzipToPath(zistream, Paths.get(path), targetDirectory);
+ }
+ } finally {
+ zistream.closeEntry();
+ }
+ }
+ } finally {
+ zistream.close();
+ }
+ } finally {
+ bistream.close();
+ }
+ }
+
+ private void unzipToPath(InputStream istream, Path relativePath, File targetDirectory) throws IOException {
+ Path path = targetDirectory.toPath().resolve(relativePath);
+ Path folderPath = path.getParent();
+ Files.createDirectories(folderPath);
+
+ FileOutputStream fostream = new FileOutputStream(path.toFile());
+ BufferedOutputStream bostream = new BufferedOutputStream(fostream);
+ try {
+ IOUtils.copy(istream, bostream);
+ } finally {
+ bostream.close();
+ }
+ }
+
+ private void clearDirectory(File directory) {
+ for (File file : directory.listFiles()) {
+ if (file.isDirectory())
+ this.clearDirectory(file);
+ file.delete();
+ }
+ }
+
+ private void reformatFiles(File directory) throws MojoFailureException {
+ for (File file : directory.listFiles()) {
+ if (file.isDirectory()) {
+ this.reformatFiles(file);
+ } else {
+ String ext = this.getFileExtension(file);
+
+ try {
+ switch (ext) {
+ case "json":
+ this.getLog().debug("Reformatting file: " + file);
+ Map json = ModelUtil.getInstance().readJsonAsMap(file);
+ if (this.normalize)
+ this.normalizeJson(json);
+ ModelUtil.getInstance().writeJson(json, file);
+ break;
+ case "xml":
+ case "bpmn":
+ this.getLog().debug("Reformatting file: " + file);
+ Document xml = ModelUtil.getInstance().readXml(file);
+ if (this.normalize)
+ this.normalizeXml(xml);
+ ModelUtil.getInstance().writeXml(xml, file);
+ break;
+ default:
+ file.delete();
+ }
+ } catch (TransformerException | SAXException | IOException e) {
+ throw new MojoFailureException("The following file faild to be reformatted: " + file, e);
+ }
+ }
+ }
+ }
+
+ private boolean normalizeJson(Map jsonMap) {
+ boolean changed = false;
+
+ try {
+ List