diff --git a/plugins/alfresco-maven-plugin/pom.xml b/plugins/alfresco-maven-plugin/pom.xml
index 7b1b486c..28cfacf7 100644
--- a/plugins/alfresco-maven-plugin/pom.xml
+++ b/plugins/alfresco-maven-plugin/pom.xml
@@ -84,7 +84,7 @@
org.apache.maven.plugins
maven-plugin-plugin
- 3.1
+ 3.0
diff --git a/plugins/alfresco-maven-plugin/src/main/java/org/alfresco/maven/plugin/AmpMojo.java b/plugins/alfresco-maven-plugin/src/main/java/org/alfresco/maven/plugin/AmpMojo.java
index f4d2f994..57f3d030 100644
--- a/plugins/alfresco-maven-plugin/src/main/java/org/alfresco/maven/plugin/AmpMojo.java
+++ b/plugins/alfresco-maven-plugin/src/main/java/org/alfresco/maven/plugin/AmpMojo.java
@@ -23,14 +23,12 @@ import org.apache.maven.project.MavenProjectHelper;
import org.codehaus.plexus.archiver.jar.JarArchiver;
/**
- * Builds an AMP archive of the current project's contents. By default,
- * the location of the AMP root contents is ${project.build.directory}/${project.build.finalName}
- * but it can be customised using plugin's configuration.
- * Java resources (in src/main/java and src/main/resources) are packages in a separate JAR file
- * that is automatically bundled in the /lib folder of the AMP archive and it treated as build artifact
+ * Builds an AMP archive of the current project's contents.
+ * The location of the AMP contents is ${project.build.directory}/${project.build.finalName}.
+ * Java resources (in src/main/java and src/main/resources) are packaged in a standard JAR file
+ * that is automatically bundled in the /lib folder of the AMP archive and it's treated as build artifact
* (i.e. distributed on Maven repositories during deploy).
- * Optionally you can include Maven dependencies into the /lib folder of the AMP archive
- * and customise the classifier of both AMP and JAR archives being created
+ * Maven transitive dependencies are by default added into the /lib folder of the AMP archive
*
* @author Gabriele Columbro, Maurizio Pillitu
* @version $Id:$
@@ -39,24 +37,25 @@ import org.codehaus.plexus.archiver.jar.JarArchiver;
* @requiresProject
* @threadSafe
* @requiresDependencyResolution runtime
+ * @description Packages an Alfresco AMP file in ${project.build.directory} using the content found in ${project.build.directory}/${project.build.finalName}
*/
public class AmpMojo extends AbstractMojo {
/**
* Name of the generated AMP and JAR artifacts
*
- * @parameter expression="${ampFinalName}" default-value="${project.build.finalName}"
+ * @parameter property="maven.alfresco.ampFinalName" default-value="${project.build.finalName}"
* @required
* @readonly
*/
protected String ampFinalName;
/**
- * Root folder that is packaged into the AMP
+ * Target folder used to aggregate content then packaged into the AMP
*
- * @parameter default-value="${project.build.directory}/${project.build.finalName}"
+ * @parameter property="maven.alfresco.ampBuildDirectory" default-value="${project.build.directory}/${project.build.finalName}"
* @required
- * @
+ *
*/
protected File ampBuildDirectory;
@@ -65,21 +64,21 @@ public class AmpMojo extends AbstractMojo {
* If this is not given,it will merely be written to the output directory
* according to the finalName.
*
- * @parameter
+ * @parameter property="maven.alfresco.classifier"
*/
protected String classifier;
/**
* Whether (runtime scoped) JAR dependencies (including transitive) should be added or not to the generated AMP /lib folder.
- * By default it's true so all direct and transitive dependencies will be added
+ * By default it's true so all direct and transitive (runtime) dependencies will be added
*
- * @parameter default-value="true"
+ * @parameter property="maven.alfresco.includeDependencies" default-value="true"
* @required
*/
protected boolean includeDependencies;
/**
- * ${project.basedir}/target directory
+ * Directory the build produces the AMP file in
*
* @parameter default-value="${project.build.directory}"
* @required
diff --git a/plugins/alfresco-maven-plugin/src/main/java/org/alfresco/maven/plugin/InstallMojo.java b/plugins/alfresco-maven-plugin/src/main/java/org/alfresco/maven/plugin/InstallMojo.java
index 0e1aa9de..dde14a3d 100644
--- a/plugins/alfresco-maven-plugin/src/main/java/org/alfresco/maven/plugin/InstallMojo.java
+++ b/plugins/alfresco-maven-plugin/src/main/java/org/alfresco/maven/plugin/InstallMojo.java
@@ -1,150 +1,118 @@
package org.alfresco.maven.plugin;
-import org.alfresco.repo.module.tool.ModuleManagementTool;
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.plugin.AbstractMojo;
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.MojoFailureException;
-import org.apache.maven.project.MavenProject;
-import org.codehaus.plexus.util.FileUtils;
-
import java.io.File;
import java.io.IOException;
+import org.alfresco.repo.module.tool.ModuleManagementTool;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+
/**
- * Performs a AMP to WAR overlay invoking the Alfresco Repository POJO
- * ModuleManagementTool.installModules() and therefore emulating the same
- * WAR overlay performed by Alfresco Repository during bootstrap.
+ * Performs a AMP to WAR overlay invoking the Alfresco Repository ModuleManagementTool.
+ * It therefore wraps and emulates the same WAR overlay performed by Alfresco MMT.
*
- * The AMP files overlaid are all AMP runtime dependencies defined in the
- * current project's build.
- *
- * Additionally (and optionally) you can define the full path of a single AMP file that needs to
- * be overlaid, using the configuration element.
- *
+ * This goal will install the AMP file(s) found in ${ampLocation} onto the WAR (or exploded WAR) found in ${warLocation}
+ *
* @version $Id:$
* @requiresDependencyResolution
* @goal install
+ * @description Installs one or more AMPs onto an Alfresco / Share WAR (or
+ * exploded WAR folder)
*/
public class InstallMojo extends AbstractMojo {
- private static final String AMP_OVERLAY_FOLDER_NAME = "ampoverlays_temp";
+ private static final String WEBAPP_MANIFEST_PATH = "META-INF" + File.separator + "MANIFEST.MF";
+ private static final String WEBAPP_DESCRIPTOR_PATH = "WEB-INF" + File.separator + "web.xml";
/**
- * Name of the generated AMP and JAR artifacts
- *
- * @parameter expression="${ampFinalName}" default-value="${project.build.finalName}"
- * @required
- * @readonly
+ * The location of the AMP file(s) to be installed. If this location is a
+ * folder all AMPs contained in the folder are installed, if it's a file it
+ * get direclty installed on the ${warLocation}
+ *
+ * @parameter property="maven.alfresco.ampLocation" default-value="${project.build.directory}/${project.build.finalName}.amp"
*/
- protected String ampFinalName;
-
+ private File ampLocation;
+
/**
- * The WAR file or exploded dir to install the AMPs in. If specified
- * Defaults to outputDirectory/${ampFinalName}-war
- *
- * @parameter expression="${warLocation}" default-value="${project.build.directory}/${project.build.finalName}-war"
+ * The WAR file or exploded dir to install the AMPs in. If specified
+ * Defaults to "${project.build.directory}/${project.build.finalName}-war
+ *
+ * @parameter property="maven.alfresco.warLocation" default-value="${project.build.directory}/${project.build.finalName}-war"
*/
private File warLocation;
-
+
/**
- * One single amp file that, if exists, gets included into the list
- * of modules to install within the Alfresco WAR, along with other AMP
- * defined as (runtime) Maven dependencies
- *
- * @parameter expression="${singleAmp}" default-value="${project.build.directory}/${project.build.finalName}.amp"
+ * Whether Alfresco MMT should be executed in verbose mode
+ *
+ * @parameter property="maven.alfresco.verbose" default-value="false"
*/
- private File singleAmp;
-
+ private boolean verbose;
+
/**
- * [Read Only] The target/ directory.
- *
- * @parameter expression="${project.build.directory}"
- * @readonly
- * @required
+ * Whether Alfresco MMT should be force installation of AMPs
+ *
+ * @parameter property="maven.alfresco.force" default-value="true"
*/
- private String outputDirectory;
-
+ private boolean force;
+
/**
- * The maven project.
- *
- * @parameter expression="${project}"
- * @required
- * @readonly
+ * Whether Alfresco MMT should produce backups while installing. Defaults to false to speed up development, set to true for Production AMP installations
+ *
+ * @parameter property="maven.alfresco.backup" default-value="false"
*/
- private MavenProject project;
+ private boolean backup;
public InstallMojo() {
}
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
- File overlayTempDir = new File(this.outputDirectory, AMP_OVERLAY_FOLDER_NAME);
- getLog().debug("Setting AMP Destination dir to " + overlayTempDir.getAbsolutePath());
-
+ // Checks appropriate input params are in place
+ checkParams();
+ ModuleManagementTool mmt = new ModuleManagementTool();
+ mmt.setVerbose(verbose);
/**
- * Collect all AMP runtime dependencies and copy all files
- * in one single build folder, *ampDirectoryDir*
+ * Invoke the ModuleManagementTool to install AMP modules on the WAR
+ * file; if ampLocation is a folder all contained AMPs are installed otherwise
+ * a single AMP install is attempted with the ampLocation
*/
- try {
- for (Object artifactObj : project.getRuntimeArtifacts()) {
- if (artifactObj instanceof Artifact) {
- Artifact artifact = (Artifact) artifactObj;
- if ("amp".equals(artifact.getType())) {
- File artifactFile = artifact.getFile();
- FileUtils.copyFileToDirectory(artifactFile, overlayTempDir);
- getLog().debug(String.format("Copied %s into %s", artifactFile, overlayTempDir));
- }
- }
- }
- if (this.singleAmp != null && this.singleAmp.exists()) {
- if (!overlayTempDir.exists()) {
- overlayTempDir.mkdirs();
- }
-
- FileUtils.copyFileToDirectory(this.singleAmp, overlayTempDir);
- getLog().debug(String.format("Copied %s into %s", this.singleAmp, overlayTempDir));
- }
- } catch (IOException e) {
- getLog().error(
- String.format(
- "Cannot copy AMP module to folder %s",
- overlayTempDir));
- }
-
- // Locate the WAR file to overlay - the one produced by the current project
-// if (warLocation == null) {
-// String warLocation = this.outputDirectory + File.separator + this.ampFinalName + "-war" + File.separator;
-// this.warLocation = new File(warLocation);
-// }
- if (!warLocation.exists()) {
- getLog().info(
- "No WAR file found in " + warLocation.getAbsolutePath() + " - skipping overlay.");
- } else if (overlayTempDir == null ||
- !overlayTempDir.exists()) {
- getLog().info(
- "No ampoverlay folder found in " + overlayTempDir + " - skipping overlay.");
- } else if (overlayTempDir.listFiles().length == 0) {
- getLog().info(
- "No runtime AMP dependencies found for this build - skipping overlay.");
- } else {
- /**
- * Invoke the ModuleManagementTool to install AMP modules on the WAR file;
- * so far, no backup or force flags are enabled
- */
- ModuleManagementTool mmt = new ModuleManagementTool();
- mmt.setVerbose(true);
+ if(ampLocation.isDirectory())
+ {
try {
- mmt.installModules(
- overlayTempDir.getAbsolutePath(),
- warLocation.getAbsolutePath(),
- false, //preview
- true, //force install
- false); //backup
+ mmt.installModules(ampLocation.getAbsolutePath(),
+ warLocation.getAbsolutePath(), false, // preview
+ force, // force install
+ backup); // backup
} catch (IOException e) {
- throw new MojoExecutionException("Problems while installing " +
- overlayTempDir.getAbsolutePath() + " onto " + warLocation.getAbsolutePath(), e);
- }
+ throw new MojoExecutionException("ampLocation " + ampLocation.getAbsolutePath() + " did not contain AMP files - AMP installation cannot proceed");
+ } // backup
+ } else if(ampLocation.isFile())
+ {
+ mmt.installModule(ampLocation.getAbsolutePath(),
+ warLocation.getAbsolutePath(), false, // preview
+ force, // force install
+ backup); // backup
+ } else
+ {
+ throw new MojoFailureException("ampLocation " + ampLocation.getAbsolutePath() + " was neither an AMP file or a folder containing AMP files - AMP installation cannot proceed");
}
}
+
+ private void checkParams() throws MojoExecutionException {
+ if (this.ampLocation == null || !this.ampLocation.exists()) {
+ throw new MojoExecutionException("No AMP file(s) found in " + ampLocation.getAbsolutePath() + " - AMP installation cannot proceed");
+ }
+ if (this.warLocation == null || !this.warLocation.exists()) {
+ throw new MojoExecutionException("No WAR file found in " + warLocation.getAbsolutePath() + " - AMP installation cannot proceed");
+ }
+
+ File descriptor = new File(warLocation.getPath() + File.separator + WEBAPP_DESCRIPTOR_PATH);
+ if(!descriptor.exists())
+ throw new MojoExecutionException("No webapp found in " + descriptor.getAbsolutePath() + ". AMP installation cannot proceed. Are you binding amp:install to the right phase?");
+
+ File manifest = new File(warLocation.getPath() + File.separator + WEBAPP_MANIFEST_PATH);
+ if(!manifest.exists())
+ throw new MojoExecutionException("No MANIFEST.MF found in " + manifest.getAbsolutePath() + ". AMP installation cannot proceed. Are you binding amp:install to the right phase?");
+ }
}
\ No newline at end of file
diff --git a/plugins/alfresco-maven-plugin/src/main/java/org/alfresco/maven/plugin/VersionMojo.java b/plugins/alfresco-maven-plugin/src/main/java/org/alfresco/maven/plugin/VersionMojo.java
index 21b7c9b7..b2002c20 100644
--- a/plugins/alfresco-maven-plugin/src/main/java/org/alfresco/maven/plugin/VersionMojo.java
+++ b/plugins/alfresco-maven-plugin/src/main/java/org/alfresco/maven/plugin/VersionMojo.java
@@ -21,6 +21,7 @@ import org.apache.maven.project.MavenProject;
* @phase initialize
* @requiresProject
* @threadSafe
+ * @description Parses Maven version and removes literals as not allowed in AMP versions, making a noSnapshotVersion property available for POM filtering
*/
public class VersionMojo extends AbstractMojo {
@@ -30,7 +31,7 @@ public class VersionMojo extends AbstractMojo {
* The snapshotSuffix used to identify and strip the -SNAPSHOT version suffix
* See issue https://issues.alfresco.com/jira/browse/ENH-1232
*
- * @parameter expression="${snapshotSuffix}" default-value="-SNAPSHOT"
+ * @parameter property="maven.alfresco.snapshotSuffix" default-value="-SNAPSHOT"
* @required
*/
protected String snapshotSuffix;
@@ -40,7 +41,7 @@ public class VersionMojo extends AbstractMojo {
* of the artifact creation
* See issue https://issues.alfresco.com/jira/browse/ENH-1232
*
- * @parameter expression="${snapshotToTimestamp}" default-value="false"
+ * @parameter property="maven.alfresco.snapshotToTimestamp" default-value="false"
* @required
*/
protected boolean snapshotToTimestamp;
@@ -51,14 +52,14 @@ public class VersionMojo extends AbstractMojo {
* ${buildnumber} in the plugin
* configuration.
*
- * @parameter expression="${customVersionSuffix}"
+ * @parameter property="maven.alfresco.customVersionSuffix"
*/
protected String customVersionSuffix;
/**
* The Maven project property the stripped version is pushed into
*
- * @parameter expression="${propertyName}" default-value="noSnapshotVersion"
+ * @parameter property="maven.alfresco.propertyName" default-value="noSnapshotVersion"
* @required
*/
private String propertyName;
@@ -75,7 +76,7 @@ public class VersionMojo extends AbstractMojo {
/**
* [Read Only] Current version of the project
*
- * @parameter expression="${project.version}"
+ * @parameter default-value="${project.version}"
* @required
* @readonly
*/
diff --git a/plugins/alfresco-maven-plugin/src/main/java/org/alfresco/maven/plugin/archiver/AmpUnArchiver.java b/plugins/alfresco-maven-plugin/src/main/java/org/alfresco/maven/plugin/archiver/AmpUnArchiver.java
index 848923b4..f4cb91c1 100644
--- a/plugins/alfresco-maven-plugin/src/main/java/org/alfresco/maven/plugin/archiver/AmpUnArchiver.java
+++ b/plugins/alfresco-maven-plugin/src/main/java/org/alfresco/maven/plugin/archiver/AmpUnArchiver.java
@@ -10,7 +10,12 @@ import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.archiver.ArchiverException;
import org.codehaus.plexus.archiver.zip.AbstractZipUnArchiver;
import org.codehaus.plexus.component.annotations.Requirement;
-
+/**
+ * This class provides AMP unpacking support for projects depending on AMPs
+ * This allows for example AMPs to be specified as in the maven-war-plugin
+ * @author mindthegab
+ *
+ */
public class AmpUnArchiver extends AbstractZipUnArchiver {
public AmpUnArchiver()
@@ -20,6 +25,9 @@ public class AmpUnArchiver extends AbstractZipUnArchiver {
private LegacySupport legacySupport;
@Override
+ /**
+ * By default the AMPs are unpacked in ${project.directory}/${project.build.finalName}
+ */
public File getDestDirectory() {
MavenSession session = legacySupport.getSession();
MavenProject project = session.getCurrentProject();
@@ -34,7 +42,7 @@ public class AmpUnArchiver extends AbstractZipUnArchiver {
* so far, no backup or force flags are enabled
*/
ModuleManagementTool mmt = new ModuleManagementTool();
- mmt.setVerbose(true);
+ mmt.setVerbose(false);
getLogger().info("getDestFile ():" + getDestFile());
getLogger().info("getDestFile ():" + getDestFile());
getLogger().info("getDestDirectory ():" + getDestDirectory());
diff --git a/plugins/alfresco-maven-plugin/src/site/site.xml b/plugins/alfresco-maven-plugin/src/site/site.xml
index 52968a5f..4d3c2ed9 100644
--- a/plugins/alfresco-maven-plugin/src/site/site.xml
+++ b/plugins/alfresco-maven-plugin/src/site/site.xml
@@ -40,7 +40,7 @@