Commit a869e55b authored by mindthegab's avatar mindthegab
Browse files

-- fixed install plugin. Right now dependencies unpacking is handled from the...

-- 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
parent 56475bb7
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -84,7 +84,7 @@
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-plugin-plugin</artifactId>
        <version>3.1</version>
        <version>3.0</version>
      </plugin>
    </plugins>
  </reporting>
+14 −15
Original line number Diff line number Diff line
@@ -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 <ampBuildDirectory> 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
+78 −110
Original line number Diff line number Diff line
package org.alfresco.maven.plugin;

import java.io.File;
import java.io.IOException;

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;

/**
 * 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.
 * <p/>
 * The AMP files overlaid are all AMP runtime dependencies defined in the
 * 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.
 * 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
     * 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}"
     * @required
     * @readonly
     * @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 <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;
    
    /**
     * 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
     * Whether Alfresco MMT should be executed in verbose mode
     * 
     * @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}"
     * @readonly
     * @required
     * @parameter property="maven.alfresco.force" default-value="true"
     */
    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}"
     * @required
     * @readonly
     * @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
         */
        if(ampLocation.isDirectory())
        {
            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));
                    }
                }
                mmt.installModules(ampLocation.getAbsolutePath(),
                        warLocation.getAbsolutePath(), false, // preview
                        force, // force install
                        backup); // backup
            } catch (IOException 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");
        }
            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));
    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");
        }
        } catch (IOException e) {
            getLog().error(
                    String.format(
                            "Cannot copy AMP module to folder %s",
                            overlayTempDir));
        if (this.warLocation == null || !this.warLocation.exists()) {
            throw new MojoExecutionException("No WAR file found in " + warLocation.getAbsolutePath() + " - AMP installation cannot proceed");
        }
        
        // 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 {
                mmt.installModules(
                        overlayTempDir.getAbsolutePath(),
                        warLocation.getAbsolutePath(),
                        false,  //preview
                        true,   //force install
                        false); //backup
            } catch (IOException e) {
                throw new MojoExecutionException("Problems while installing " + 
            overlayTempDir.getAbsolutePath() + " onto " + warLocation.getAbsolutePath(), e);
            }
        }
        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
+6 −5
Original line number Diff line number Diff line
@@ -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 {
     * <customVersionSuffix>${buildnumber}</customVersionSuffix> 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
     */
+10 −2
Original line number Diff line number Diff line
@@ -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 <overlay> 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());
Loading