-- fixed install plugin. Right now dependencies unpacking is handled from the unArchiver via standard <overlay> mechanism

-- modified semantics of install
   - by default not bound to any phase
   - accepts a parameter called ampLocation (a single AMP or a folder) and installs to a WAR (or exploded WAR)
   - warLocation can also be specified
   - mostly a utility plugin / MMT wrap to be embedded in Alfresco related builds
   - singleAmp does not exist anymore. either put your AMP in ${project.build.directory}/${project.build.finalName}.amp or configure 'ampLocation'
- updated site

git-svn-id: http://maven-alfresco-archetypes.googlecode.com/svn/trunk@629 04253f4f-3451-0410-a141-5562f1e59037
This commit is contained in:
mindthegab 2012-11-03 20:15:10 +00:00
parent 56475bb755
commit a869e55b25
6 changed files with 112 additions and 136 deletions

View File

@ -84,7 +84,7 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId> <artifactId>maven-plugin-plugin</artifactId>
<version>3.1</version> <version>3.0</version>
</plugin> </plugin>
</plugins> </plugins>
</reporting> </reporting>

View File

@ -23,14 +23,12 @@ import org.apache.maven.project.MavenProjectHelper;
import org.codehaus.plexus.archiver.jar.JarArchiver; import org.codehaus.plexus.archiver.jar.JarArchiver;
/** /**
* Builds an AMP archive of the current project's contents. By default, * Builds an AMP archive of the current project's contents.
* the location of the AMP root contents is ${project.build.directory}/${project.build.finalName} * The location of the AMP contents is ${project.build.directory}/${project.build.finalName}.
* but it can be customised using <ampBuildDirectory> plugin's configuration. * Java resources (in src/main/java and src/main/resources) are packaged in a standard JAR file
* 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's treated as build artifact
* that is automatically bundled in the /lib folder of the AMP archive and it treated as build artifact
* (i.e. distributed on Maven repositories during deploy). * (i.e. distributed on Maven repositories during deploy).
* Optionally you can include Maven dependencies into the /lib folder of the AMP archive * Maven transitive dependencies are by default added into the /lib folder of the AMP archive
* and customise the classifier of both AMP and JAR archives being created
* *
* @author Gabriele Columbro, Maurizio Pillitu * @author Gabriele Columbro, Maurizio Pillitu
* @version $Id:$ * @version $Id:$
@ -39,24 +37,25 @@ import org.codehaus.plexus.archiver.jar.JarArchiver;
* @requiresProject * @requiresProject
* @threadSafe * @threadSafe
* @requiresDependencyResolution runtime * @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 { public class AmpMojo extends AbstractMojo {
/** /**
* Name of the generated AMP and JAR artifacts * 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 * @required
* @readonly * @readonly
*/ */
protected String ampFinalName; 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 * @required
* @ *
*/ */
protected File ampBuildDirectory; 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 * If this is not given,it will merely be written to the output directory
* according to the finalName. * according to the finalName.
* *
* @parameter * @parameter property="maven.alfresco.classifier"
*/ */
protected String classifier; protected String classifier;
/** /**
* Whether (runtime scoped) JAR dependencies (including transitive) should be added or not to the generated AMP /lib folder. * 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 * @required
*/ */
protected boolean includeDependencies; protected boolean includeDependencies;
/** /**
* ${project.basedir}/target directory * Directory the build produces the AMP file in
* *
* @parameter default-value="${project.build.directory}" * @parameter default-value="${project.build.directory}"
* @required * @required

View File

@ -1,150 +1,118 @@
package org.alfresco.maven.plugin; 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.File;
import java.io.IOException; 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 * Performs a AMP to WAR overlay invoking the Alfresco Repository ModuleManagementTool.
* ModuleManagementTool.installModules() and therefore emulating the same * It therefore wraps and emulates the same WAR overlay performed by Alfresco MMT.
* WAR overlay performed by Alfresco Repository during bootstrap.
* <p/> * <p/>
* The AMP files overlaid are all AMP runtime dependencies defined in the * This goal will install the AMP file(s) found in ${ampLocation} onto the WAR (or exploded WAR) found in ${warLocation}
* current project's build.
* <p/>
* Additionally (and optionally) you can define the full path of a single AMP file that needs to
* be overlaid, using the <simpleAmp> configuration element.
* *
* @version $Id:$ * @version $Id:$
* @requiresDependencyResolution * @requiresDependencyResolution
* @goal install * @goal install
* @description Installs one or more AMPs onto an Alfresco / Share WAR (or
* exploded WAR folder)
*/ */
public class InstallMojo extends AbstractMojo { 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 * 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 expression="${ampFinalName}" default-value="${project.build.finalName}" * @parameter property="maven.alfresco.ampLocation" default-value="${project.build.directory}/${project.build.finalName}.amp"
* @required
* @readonly
*/ */
protected String ampFinalName; private File ampLocation;
/** /**
* The WAR file or exploded dir to install the AMPs in. If specified * The WAR file or exploded dir to install the AMPs in. If specified
* Defaults to <code>outputDirectory/${ampFinalName}-war</code> * Defaults to <code>"${project.build.directory}/${project.build.finalName}-war</code>
* *
* @parameter expression="${warLocation}" default-value="${project.build.directory}/${project.build.finalName}-war" * @parameter property="maven.alfresco.warLocation" default-value="${project.build.directory}/${project.build.finalName}-war"
*/ */
private File warLocation; private File warLocation;
/** /**
* One single amp file that, if exists, gets included into the list * Whether Alfresco MMT should be executed in verbose mode
* 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" * @parameter property="maven.alfresco.verbose" default-value="false"
*/ */
private File singleAmp; private boolean verbose;
/** /**
* [Read Only] The target/ directory. * Whether Alfresco MMT should be force installation of AMPs
* *
* @parameter expression="${project.build.directory}" * @parameter property="maven.alfresco.force" default-value="true"
* @readonly
* @required
*/ */
private String outputDirectory; private boolean force;
/** /**
* The maven project. * Whether Alfresco MMT should produce backups while installing. Defaults to false to speed up development, set to true for Production AMP installations
* *
* @parameter expression="${project}" * @parameter property="maven.alfresco.backup" default-value="false"
* @required
* @readonly
*/ */
private MavenProject project; private boolean backup;
public InstallMojo() { public InstallMojo() {
} }
@Override @Override
public void execute() throws MojoExecutionException, MojoFailureException { public void execute() throws MojoExecutionException, MojoFailureException {
File overlayTempDir = new File(this.outputDirectory, AMP_OVERLAY_FOLDER_NAME); // Checks appropriate input params are in place
getLog().debug("Setting AMP Destination dir to " + overlayTempDir.getAbsolutePath()); checkParams();
ModuleManagementTool mmt = new ModuleManagementTool();
mmt.setVerbose(verbose);
/** /**
* Collect all AMP runtime dependencies and copy all files * Invoke the ModuleManagementTool to install AMP modules on the WAR
* in one single build folder, *ampDirectoryDir* * file; if ampLocation is a folder all contained AMPs are installed otherwise
* a single AMP install is attempted with the ampLocation
*/ */
try { if(ampLocation.isDirectory())
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);
try { try {
mmt.installModules( mmt.installModules(ampLocation.getAbsolutePath(),
overlayTempDir.getAbsolutePath(), warLocation.getAbsolutePath(), false, // preview
warLocation.getAbsolutePath(), force, // force install
false, //preview backup); // backup
true, //force install
false); //backup
} catch (IOException e) { } catch (IOException e) {
throw new MojoExecutionException("Problems while installing " + throw new MojoExecutionException("ampLocation " + ampLocation.getAbsolutePath() + " did not contain AMP files - AMP installation cannot proceed");
overlayTempDir.getAbsolutePath() + " onto " + warLocation.getAbsolutePath(), e); } // 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?");
}
} }

View File

@ -21,6 +21,7 @@ import org.apache.maven.project.MavenProject;
* @phase initialize * @phase initialize
* @requiresProject * @requiresProject
* @threadSafe * @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 { 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 * The snapshotSuffix used to identify and strip the -SNAPSHOT version suffix
* See issue https://issues.alfresco.com/jira/browse/ENH-1232 * 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 * @required
*/ */
protected String snapshotSuffix; protected String snapshotSuffix;
@ -40,7 +41,7 @@ public class VersionMojo extends AbstractMojo {
* of the artifact creation * of the artifact creation
* See issue https://issues.alfresco.com/jira/browse/ENH-1232 * 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 * @required
*/ */
protected boolean snapshotToTimestamp; protected boolean snapshotToTimestamp;
@ -51,14 +52,14 @@ public class VersionMojo extends AbstractMojo {
* <customVersionSuffix>${buildnumber}</customVersionSuffix> in the plugin * <customVersionSuffix>${buildnumber}</customVersionSuffix> in the plugin
* configuration. * configuration.
* *
* @parameter expression="${customVersionSuffix}" * @parameter property="maven.alfresco.customVersionSuffix"
*/ */
protected String customVersionSuffix; protected String customVersionSuffix;
/** /**
* The Maven project property the stripped version is pushed into * 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 * @required
*/ */
private String propertyName; private String propertyName;
@ -75,7 +76,7 @@ public class VersionMojo extends AbstractMojo {
/** /**
* [Read Only] Current version of the project * [Read Only] Current version of the project
* *
* @parameter expression="${project.version}" * @parameter default-value="${project.version}"
* @required * @required
* @readonly * @readonly
*/ */

View File

@ -10,7 +10,12 @@ import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.archiver.ArchiverException; import org.codehaus.plexus.archiver.ArchiverException;
import org.codehaus.plexus.archiver.zip.AbstractZipUnArchiver; import org.codehaus.plexus.archiver.zip.AbstractZipUnArchiver;
import org.codehaus.plexus.component.annotations.Requirement; 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 <overlay> in the maven-war-plugin
* @author mindthegab
*
*/
public class AmpUnArchiver extends AbstractZipUnArchiver { public class AmpUnArchiver extends AbstractZipUnArchiver {
public AmpUnArchiver() public AmpUnArchiver()
@ -20,6 +25,9 @@ public class AmpUnArchiver extends AbstractZipUnArchiver {
private LegacySupport legacySupport; private LegacySupport legacySupport;
@Override @Override
/**
* By default the AMPs are unpacked in ${project.directory}/${project.build.finalName}
*/
public File getDestDirectory() { public File getDestDirectory() {
MavenSession session = legacySupport.getSession(); MavenSession session = legacySupport.getSession();
MavenProject project = session.getCurrentProject(); MavenProject project = session.getCurrentProject();
@ -34,7 +42,7 @@ public class AmpUnArchiver extends AbstractZipUnArchiver {
* so far, no backup or force flags are enabled * so far, no backup or force flags are enabled
*/ */
ModuleManagementTool mmt = new ModuleManagementTool(); ModuleManagementTool mmt = new ModuleManagementTool();
mmt.setVerbose(true); mmt.setVerbose(false);
getLogger().info("getDestFile ():" + getDestFile()); getLogger().info("getDestFile ():" + getDestFile());
getLogger().info("getDestFile ():" + getDestFile()); getLogger().info("getDestFile ():" + getDestFile());
getLogger().info("getDestDirectory ():" + getDestDirectory()); getLogger().info("getDestDirectory ():" + getDestDirectory());

View File

@ -40,7 +40,7 @@
<menu name="Plugin info"> <menu name="Plugin info">
<item name="Goals" href="plugin-info.html"/> <item name="Goals" href="plugin-info.html"/>
<item name="Usage" href="upage.html"/> <item name="Usage" href="usage.html"/>
<item name="Advanced Usage" href="components.html"/> <item name="Advanced Usage" href="components.html"/>
</menu> </menu>