mirror of
https://github.com/Alfresco/alfresco-sdk.git
synced 2025-08-07 17:49:34 +00:00
Experimental / trunk switch: final folder fixes
git-svn-id: http://maven-alfresco-archetypes.googlecode.com/svn/trunk@625 04253f4f-3451-0410-a141-5562f1e59037
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
package org.alfresco.maven.plugin;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Class holding all common well know constants for the AMP packaging/extraction process
|
||||
* @author columbro
|
||||
*
|
||||
*/
|
||||
public class AmpModel {
|
||||
|
||||
public static final String AMP_FOLDER_LIB = "lib";
|
||||
|
||||
public static final List<String> EXTENSION_LIST = Arrays.asList(new String[] {"jar","ejb","ejb-client","test-jar"});
|
||||
}
|
@@ -0,0 +1,243 @@
|
||||
package org.alfresco.maven.plugin;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.maven.plugin.archiver.AmpArchiver;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.maven.archiver.MavenArchiveConfiguration;
|
||||
import org.apache.maven.archiver.MavenArchiver;
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
|
||||
import org.apache.maven.execution.MavenSession;
|
||||
import org.apache.maven.plugin.AbstractMojo;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
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
|
||||
* (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
|
||||
*
|
||||
* @author Gabriele Columbro, Maurizio Pillitu
|
||||
* @version $Id:$
|
||||
* @goal amp
|
||||
* @phase package
|
||||
* @requiresProject
|
||||
* @threadSafe
|
||||
* @requiresDependencyResolution runtime
|
||||
*/
|
||||
public class AmpMojo extends AbstractMojo {
|
||||
|
||||
/**
|
||||
* Name of the generated AMP and JAR artifacts
|
||||
*
|
||||
* @parameter expression="${ampFinalName}" default-value="${project.build.finalName}"
|
||||
* @required
|
||||
* @readonly
|
||||
*/
|
||||
protected String ampFinalName;
|
||||
|
||||
/**
|
||||
* Root folder that is packaged into the AMP
|
||||
*
|
||||
* @parameter default-value="${project.build.directory}/${project.build.finalName}"
|
||||
* @required
|
||||
* @
|
||||
*/
|
||||
protected File ampBuildDirectory;
|
||||
|
||||
/**
|
||||
* Classifier to add to the artifact generated. If given, the artifact will be attached.
|
||||
* If this is not given,it will merely be written to the output directory
|
||||
* according to the finalName.
|
||||
*
|
||||
* @parameter
|
||||
*/
|
||||
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
|
||||
*
|
||||
* @parameter default-value="true"
|
||||
* @required
|
||||
*/
|
||||
protected boolean includeDependencies;
|
||||
|
||||
/**
|
||||
* ${project.basedir}/target directory
|
||||
*
|
||||
* @parameter default-value="${project.build.directory}"
|
||||
* @required
|
||||
* @readonly
|
||||
*/
|
||||
protected File outputDirectory;
|
||||
|
||||
/**
|
||||
* (Read Only) Directory containing the classes and resource files that should be packaged into the JAR.
|
||||
*
|
||||
* @parameter default-value="${project.build.outputDirectory}"
|
||||
* @required
|
||||
* @readonly
|
||||
*/
|
||||
protected File classesDirectory;
|
||||
|
||||
/**
|
||||
* (Read Only) The Maven project.
|
||||
*
|
||||
* @parameter default-value="${project}"
|
||||
* @required
|
||||
* @readonly
|
||||
*/
|
||||
protected MavenProject project;
|
||||
|
||||
/**
|
||||
* (Read Only) The Maven session
|
||||
*
|
||||
* @parameter default-value="${session}"
|
||||
* @readonly
|
||||
* @required
|
||||
*/
|
||||
protected MavenSession session;
|
||||
|
||||
/**
|
||||
* The archive configuration to use.
|
||||
* See <a href="http://maven.apache.org/shared/maven-archiver/index.html">Maven Archiver Reference</a>.
|
||||
*
|
||||
* @parameter
|
||||
*/
|
||||
protected MavenArchiveConfiguration archive = new MavenArchiveConfiguration();
|
||||
|
||||
/**
|
||||
* @component
|
||||
*/
|
||||
protected MavenProjectHelper projectHelper;
|
||||
|
||||
public void execute()
|
||||
throws MojoExecutionException {
|
||||
|
||||
if(includeDependencies) {
|
||||
gatherDependencies();
|
||||
}
|
||||
|
||||
File ampFile = createArchive();
|
||||
if (this.classifier != null) {
|
||||
this.projectHelper.attachArtifact(this.project, "amp", this.classifier, ampFile);
|
||||
} else {
|
||||
this.project.getArtifact().setFile(ampFile);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns the AMP archive, invoking the AmpArchiver
|
||||
*
|
||||
* @return a File pointing to an existing AMP package, contained
|
||||
* in ${project.build.outputDirectory}
|
||||
*/
|
||||
protected File createArchive()
|
||||
throws MojoExecutionException {
|
||||
File jarFile = getFile(
|
||||
new File(this.ampBuildDirectory, AmpModel.AMP_FOLDER_LIB),
|
||||
this.ampFinalName,
|
||||
this.classifier,
|
||||
"jar");
|
||||
|
||||
File ampFile = getFile(
|
||||
this.outputDirectory,
|
||||
this.ampFinalName,
|
||||
this.classifier,
|
||||
"amp"
|
||||
);
|
||||
|
||||
MavenArchiver jarArchiver = new MavenArchiver();
|
||||
jarArchiver.setArchiver(new JarArchiver());
|
||||
jarArchiver.setOutputFile(jarFile);
|
||||
|
||||
MavenArchiver ampArchiver = new MavenArchiver();
|
||||
ampArchiver.setArchiver(new AmpArchiver());
|
||||
ampArchiver.setOutputFile(ampFile);
|
||||
|
||||
if (!this.ampBuildDirectory.exists()) {
|
||||
getLog().warn("ampBuildDirectory does not exist - AMP will be empty");
|
||||
} else {
|
||||
try {
|
||||
jarArchiver.getArchiver().addDirectory(this.classesDirectory, new String[]{}, new String[]{});
|
||||
jarArchiver.createArchive(this.session, this.project, this.archive);
|
||||
} catch (Exception e) {
|
||||
throw new MojoExecutionException("Error creating JAR", e);
|
||||
}
|
||||
try {
|
||||
ampArchiver.getArchiver().addDirectory(this.ampBuildDirectory, new String[]{"**"}, new String[]{});
|
||||
ampArchiver.createArchive(this.session, this.project, this.archive);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new MojoExecutionException("Error creating AMP", e);
|
||||
}
|
||||
}
|
||||
return ampFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a File object pointing to the target AMP package; the pointer to the File is created taking into
|
||||
* account the (optional) artifact classifier defined
|
||||
*
|
||||
* @param basedir the Base Directory of the currently built project
|
||||
* @param finalName the Final Name of the artifact being built
|
||||
* @param classifier the optional classifier of the artifact being built
|
||||
* @return a File object pointing to the target AMP package
|
||||
*/
|
||||
protected static File getFile(File basedir, String finalName, String classifier, String extension) {
|
||||
if (classifier == null) {
|
||||
classifier = "";
|
||||
} else if (classifier.trim().length() > 0 && !classifier.startsWith("-")) {
|
||||
classifier = "-" + classifier;
|
||||
}
|
||||
return new File(basedir, finalName + classifier + "." + extension);
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all runtime dependencies to AMP lib. By default transitive runtime dependencies are retrieved.
|
||||
* This behavior can be configured via the transitive parameter
|
||||
* @throws MojoExecutionException
|
||||
*/
|
||||
protected void gatherDependencies() throws MojoExecutionException
|
||||
{
|
||||
Set<Artifact> dependencies = null;
|
||||
// Whether transitive deps should be gathered or not
|
||||
dependencies = project.getArtifacts();
|
||||
|
||||
ScopeArtifactFilter filter = new ScopeArtifactFilter( Artifact.SCOPE_RUNTIME );
|
||||
|
||||
for (Artifact artifact : dependencies) {
|
||||
if ( !artifact.isOptional() && filter.include( artifact ) )
|
||||
{
|
||||
String type = artifact.getType();
|
||||
|
||||
if (AmpModel.EXTENSION_LIST.contains(type))
|
||||
{
|
||||
File targetFile = new File(ampBuildDirectory + File.separator + AmpModel.AMP_FOLDER_LIB + File.separator + artifact.getFile().getName());
|
||||
String targetFilePath = targetFile.getPath();
|
||||
try {
|
||||
FileUtils.copyFile(artifact.getFile(), targetFile);
|
||||
} catch (IOException e) {
|
||||
throw new MojoExecutionException("Error copying transitive dependency " + artifact.getId() + " to file: " + targetFilePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,150 @@
|
||||
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;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* <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.
|
||||
*
|
||||
* @version $Id:$
|
||||
* @requiresDependencyResolution
|
||||
* @goal install
|
||||
*/
|
||||
public class InstallMojo extends AbstractMojo {
|
||||
|
||||
private static final String AMP_OVERLAY_FOLDER_NAME = "ampoverlays_temp";
|
||||
|
||||
/**
|
||||
* Name of the generated AMP and JAR artifacts
|
||||
*
|
||||
* @parameter expression="${ampFinalName}" default-value="${project.build.finalName}"
|
||||
* @required
|
||||
* @readonly
|
||||
*/
|
||||
protected String ampFinalName;
|
||||
|
||||
/**
|
||||
* The WAR file or exploded dir to install the AMPs in. If specified
|
||||
* Defaults to <code>outputDirectory/${ampFinalName}-war</code>
|
||||
*
|
||||
* @parameter expression="${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"
|
||||
*/
|
||||
private File singleAmp;
|
||||
|
||||
/**
|
||||
* [Read Only] The target/ directory.
|
||||
*
|
||||
* @parameter expression="${project.build.directory}"
|
||||
* @readonly
|
||||
* @required
|
||||
*/
|
||||
private String outputDirectory;
|
||||
|
||||
/**
|
||||
* The maven project.
|
||||
*
|
||||
* @parameter expression="${project}"
|
||||
* @required
|
||||
* @readonly
|
||||
*/
|
||||
private MavenProject project;
|
||||
|
||||
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());
|
||||
|
||||
/**
|
||||
* Collect all AMP runtime dependencies and copy all files
|
||||
* in one single build folder, *ampDirectoryDir*
|
||||
*/
|
||||
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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,113 @@
|
||||
package org.alfresco.maven.plugin;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import org.apache.maven.plugin.AbstractMojo;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.plugin.MojoFailureException;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
|
||||
/**
|
||||
* Removes -SNAPSHOT suffix from the version number (if present), optionally replacing it with a timestamp.
|
||||
* The result is provided in the Maven property ${noSnapshotVersion} (name can be changed using
|
||||
* <propertyName>myCustomVersion</>).
|
||||
* This feature is mostly needed to avoid Alfresco failing when installing AMP modules with non-numeric
|
||||
* versions.
|
||||
*
|
||||
* @version $Id:$
|
||||
* @goal set-version
|
||||
* @phase initialize
|
||||
* @requiresProject
|
||||
* @threadSafe
|
||||
*/
|
||||
public class VersionMojo extends AbstractMojo {
|
||||
|
||||
private static final DateFormat TIMESTAMP_FORMATTER = new SimpleDateFormat("yyMMddHHmm");
|
||||
|
||||
/**
|
||||
* 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"
|
||||
* @required
|
||||
*/
|
||||
protected String snapshotSuffix;
|
||||
|
||||
/**
|
||||
* Enable this option in order to replace -SNAPSHOT with the currentTimestamp
|
||||
* of the artifact creation
|
||||
* See issue https://issues.alfresco.com/jira/browse/ENH-1232
|
||||
*
|
||||
* @parameter expression="${snapshotToTimestamp}" default-value="false"
|
||||
* @required
|
||||
*/
|
||||
protected boolean snapshotToTimestamp;
|
||||
|
||||
/**
|
||||
* Allows to append a custom (numeric) value to the current artifact's version,
|
||||
* i.e. appending the SCM build number can be accomplished defining
|
||||
* <customVersionSuffix>${buildnumber}</customVersionSuffix> in the plugin
|
||||
* configuration.
|
||||
*
|
||||
* @parameter expression="${customVersionSuffix}"
|
||||
*/
|
||||
protected String customVersionSuffix;
|
||||
|
||||
/**
|
||||
* The Maven project property the stripped version is pushed into
|
||||
*
|
||||
* @parameter expression="${propertyName}" default-value="noSnapshotVersion"
|
||||
* @required
|
||||
*/
|
||||
private String propertyName;
|
||||
|
||||
/**
|
||||
* [Read Only] The Maven project.
|
||||
*
|
||||
* @parameter default-value="${project}"
|
||||
* @required
|
||||
* @readonly
|
||||
*/
|
||||
protected MavenProject project;
|
||||
|
||||
/**
|
||||
* [Read Only] Current version of the project
|
||||
*
|
||||
* @parameter expression="${project.version}"
|
||||
* @required
|
||||
* @readonly
|
||||
*/
|
||||
protected String version;
|
||||
|
||||
/**
|
||||
* Normalizes the project's version following 2 patterns
|
||||
* - Remove the -SNAPSHOT suffix, if present
|
||||
* - (Optionally) append the timestamp to the version, if -SNAPSHOT is present
|
||||
* - (Optionally) append the build number to the version
|
||||
*
|
||||
* @return the current project's version normalized
|
||||
*/
|
||||
protected String getNormalizedVersion() {
|
||||
int separatorIndex = version.indexOf(snapshotSuffix);
|
||||
String normalizedVersion = version;
|
||||
if (separatorIndex > -1) {
|
||||
normalizedVersion = version.substring(0, separatorIndex);
|
||||
getLog().info("Removed -SNAPSHOT suffix from version - " + normalizedVersion);
|
||||
}
|
||||
if (this.customVersionSuffix != null && this.customVersionSuffix.length() > 0) {
|
||||
normalizedVersion += "." + this.customVersionSuffix;
|
||||
getLog().info("Added custom suffix to version - " + normalizedVersion);
|
||||
} else if (this.snapshotToTimestamp) {
|
||||
normalizedVersion += "." + TIMESTAMP_FORMATTER.format(new Date());
|
||||
getLog().info("Added timestamp to version - " + normalizedVersion);
|
||||
}
|
||||
return normalizedVersion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() throws MojoExecutionException, MojoFailureException {
|
||||
project.getProperties().put(propertyName, getNormalizedVersion());
|
||||
}
|
||||
}
|
@@ -0,0 +1,47 @@
|
||||
package org.alfresco.maven.plugin.archiver;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import org.codehaus.plexus.archiver.jar.JarArchiver;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
|
||||
/**
|
||||
* Emulates the JarArchiver only changing the extension name from .jar to .amp
|
||||
* It also adds a logging statement that can help debugging the build
|
||||
*
|
||||
* @author Gabriele Columbro, Maurizio Pillitu
|
||||
*/
|
||||
public class AmpArchiver extends JarArchiver {
|
||||
|
||||
public AmpArchiver() {
|
||||
super.archiveType = "amp";
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.codehaus.plexus.archiver.AbstractArchiver#addDirectory(java.io.File, String, String[], String[])
|
||||
*/
|
||||
public void addDirectory(final File directory, final String prefix, final String[] includes,
|
||||
final String[] excludes) {
|
||||
getLogger().info("Adding directory to AMP package [ '" + directory + "' '" + prefix + "']");
|
||||
super.addDirectory(directory, prefix, includes, excludes);
|
||||
}
|
||||
}
|
@@ -0,0 +1,65 @@
|
||||
package org.alfresco.maven.plugin.archiver;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.alfresco.repo.module.tool.ModuleManagementTool;
|
||||
import org.apache.maven.execution.MavenSession;
|
||||
import org.apache.maven.plugin.LegacySupport;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
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;
|
||||
|
||||
public class AmpUnArchiver extends AbstractZipUnArchiver {
|
||||
|
||||
public AmpUnArchiver()
|
||||
{
|
||||
}
|
||||
@Requirement
|
||||
private LegacySupport legacySupport;
|
||||
|
||||
@Override
|
||||
public File getDestDirectory() {
|
||||
MavenSession session = legacySupport.getSession();
|
||||
MavenProject project = session.getCurrentProject();
|
||||
return new File(project.getBuild().getDirectory() + File.separator + project.getBuild().getFinalName());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void execute() throws ArchiverException {
|
||||
try {
|
||||
/**
|
||||
* 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);
|
||||
getLogger().info("getDestFile ():" + getDestFile());
|
||||
getLogger().info("getDestFile ():" + getDestFile());
|
||||
getLogger().info("getDestDirectory ():" + getDestDirectory());
|
||||
|
||||
File destLocation = (getDestFile() == null || !getDestFile().exists() ) ? getDestDirectory() : getDestFile();
|
||||
|
||||
getLogger().info("Installing " + getSourceFile() + " into " + destLocation);
|
||||
try {
|
||||
mmt.installModule(
|
||||
getSourceFile().getAbsolutePath(),
|
||||
destLocation.getAbsolutePath(),
|
||||
false, //preview
|
||||
true, //force install
|
||||
false); //backup
|
||||
} catch (Exception e) {
|
||||
throw new MojoExecutionException("Problems while installing " +
|
||||
getSourceFile().getAbsolutePath() + " onto " + destLocation.getAbsolutePath(), e);
|
||||
}
|
||||
getLogger().debug("MMT invocation for " + getSourceFile().getAbsolutePath() + "complete");
|
||||
} catch (Exception e) {
|
||||
throw new ArchiverException("Error while expanding "
|
||||
+ getSourceFile().getAbsolutePath(), e);
|
||||
} finally {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,27 @@
|
||||
<lifecycles>
|
||||
<lifecycle>
|
||||
<id>amp</id>
|
||||
<phases>
|
||||
<phase>
|
||||
<id>initialize</id>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>set-version</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</phase>
|
||||
<phase>
|
||||
<id>package</id>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>amp</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</phase>
|
||||
</phases>
|
||||
</lifecycle>
|
||||
</lifecycles>
|
@@ -0,0 +1,61 @@
|
||||
<component-set>
|
||||
<components>
|
||||
<component>
|
||||
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
|
||||
<role-hint>amp</role-hint>
|
||||
<implementation>org.apache.maven.artifact.handler.DefaultArtifactHandler</implementation>
|
||||
<configuration>
|
||||
<extension>amp</extension>
|
||||
<type>amp</type>
|
||||
<packaging>amp</packaging>
|
||||
<language>java</language>
|
||||
<addedToClasspath>true</addedToClasspath>
|
||||
<includesDependencies>true</includesDependencies>
|
||||
</configuration>
|
||||
</component>
|
||||
|
||||
<component>
|
||||
<role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role>
|
||||
<role-hint>amp</role-hint>
|
||||
<implementation>org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping</implementation>
|
||||
<configuration>
|
||||
<phases>
|
||||
<initialize>org.alfresco.maven.plugin:alfresco-maven-plugin:set-version</initialize>
|
||||
<process-resources>org.apache.maven.plugins:maven-resources-plugin:resources</process-resources>
|
||||
<compile>org.apache.maven.plugins:maven-compiler-plugin:compile</compile>
|
||||
<process-test-resources>org.apache.maven.plugins:maven-resources-plugin:testResources</process-test-resources>
|
||||
<test-compile>org.apache.maven.plugins:maven-compiler-plugin:testCompile</test-compile>
|
||||
<test>org.apache.maven.plugins:maven-surefire-plugin:test</test>
|
||||
<package>org.alfresco.maven.plugin:alfresco-maven-plugin:amp</package>
|
||||
<install>org.apache.maven.plugins:maven-install-plugin:install</install>
|
||||
<deploy>org.apache.maven.plugins:maven-deploy-plugin:deploy</deploy>
|
||||
</phases>
|
||||
</configuration>
|
||||
</component>
|
||||
|
||||
<component>
|
||||
<role>org.codehaus.plexus.archiver.Archiver</role>
|
||||
<role-hint>amp</role-hint>
|
||||
<implementation>org.alfresco.maven.plugin.archiver.AmpArchiver</implementation>
|
||||
<instantiation-strategy>per-lookup</instantiation-strategy>
|
||||
</component>
|
||||
|
||||
|
||||
<!-- An AMP requires an MMT like behaviour when unpacked in a war.
|
||||
In the maven-war-plugin the default assumption is made on the choice of the unarchiver
|
||||
role-hint = file-extension
|
||||
so we use role-hint=amp here to seamlessly integrate with it
|
||||
-->
|
||||
<component>
|
||||
<role>org.codehaus.plexus.archiver.UnArchiver</role>
|
||||
<role-hint>amp</role-hint>
|
||||
<implementation>org.alfresco.maven.plugin.archiver.AmpUnArchiver</implementation>
|
||||
<requirements>
|
||||
<requirement>
|
||||
<role>org.apache.maven.plugin.LegacySupport</role>
|
||||
</requirement>
|
||||
</requirements>
|
||||
</component>
|
||||
|
||||
</components>
|
||||
</component-set>
|
36
plugins/alfresco-maven-plugin/src/site/apt/usage.apt.vm
Normal file
36
plugins/alfresco-maven-plugin/src/site/apt/usage.apt.vm
Normal file
@@ -0,0 +1,36 @@
|
||||
-----
|
||||
Maven AMP Plugin Plexus Components
|
||||
-----
|
||||
|
||||
|
||||
|
||||
AMP Lifecycle Mapping
|
||||
|
||||
This plugin provides support for <packaging>amp</packaging> type of projects. \
|
||||
Lifecycle of an Alfresco modules is mapped in the file:
|
||||
|
||||
{{ ${site_tags_url}/${site_pom_artifactId}-${site_pom_version}/src/main/resources/META-INF/plexus/components.xml }}
|
||||
|
||||
This build produces an Alfresco compatible AMP as main build product. It supports (being derived from maven-war-plugin)
|
||||
overlay of modules and transitive AMP dependency packing.
|
||||
|
||||
An AMP depending on one ore more AMP will package those AMP in the final product of the build:
|
||||
overlays can be configured same as in {{ http://maven.apache.org/plugins/maven-war-plugin/overlays.html }}.
|
||||
A plain zip UnArchiver is used for this overlay.
|
||||
|
||||
|
||||
|
||||
AMP -> WAR Unarchiver
|
||||
|
||||
The default UnArchiver (role-hint="amp") used by the default maven infrastructure for .amp files is a custom UnArchiver
|
||||
which behaves as the MMT, unarchiving AMPs in the proper places as dictated by {{{http://wiki.alfresco.com/wiki/AMP_Files} Alfresco AMP convention}} .
|
||||
This little component allows any plugin to manage .amp dependencies in case the maven-amp-plugin is declared with <extensions>true</extensions> in
|
||||
the current POM, basically supporting AMPs in Maven with no need for custom external tools like MMT.
|
||||
|
||||
See {{ ${site_tags_url}/${site_pom_artifactId}-${site_pom_version}/src/main/resources/META-INF/plexus/components.xml }}
|
||||
|
||||
|
||||
AMP Artifact Handler
|
||||
|
||||
Instructs maven which type of Archive is the AMP, providing info about its inclusion in the classpath or the fact that already contains
|
||||
its dependencies.
|
59
plugins/alfresco-maven-plugin/src/site/site.xml
Normal file
59
plugins/alfresco-maven-plugin/src/site/site.xml
Normal file
@@ -0,0 +1,59 @@
|
||||
<project>
|
||||
<skin>
|
||||
<groupId>org.apache.maven.skins</groupId>
|
||||
<artifactId>maven-fluido-skin</artifactId>
|
||||
<version>1.2.1</version>
|
||||
</skin>
|
||||
<custom>
|
||||
<fluidoSkin>
|
||||
<topBarEnabled>true</topBarEnabled>
|
||||
<sideBarEnabled>true</sideBarEnabled>
|
||||
<topBarIcon>
|
||||
<name>Maven Alfresco Lifecycle</name>
|
||||
<alt>Maven Alfresco Lifecycle</alt>
|
||||
<src>/img/Alfresco-logo-transparent.gif</src>
|
||||
<href>/index.html</href>
|
||||
</topBarIcon>
|
||||
<twitter>
|
||||
<user>mindthegabz</user>
|
||||
<showUser>true</showUser>
|
||||
<showFollowers>true</showFollowers>
|
||||
</twitter>
|
||||
<facebookLike />
|
||||
<googlePlusOne />
|
||||
</fluidoSkin>
|
||||
</custom>
|
||||
<poweredBy>
|
||||
<logo name="Maven" href="http://maven.apache.org" img="http://maven.apache.org/images/logos/maven-feather.png"/>
|
||||
<logo name="Alfresco - Open source ECM" img="http://alfresco.com/assets/images/icons/powered_by_alfresco.gif" href="http://www.alfresco.com" />
|
||||
</poweredBy>
|
||||
<publishDate position="navigation-bottom" format="MM-dd-yy"/>
|
||||
<bannerLeft>
|
||||
<name>Alfresco Maven Plugin - v. ${project.version}</name>
|
||||
<href>${site_site_url}</href>
|
||||
</bannerLeft>
|
||||
<body>
|
||||
<links>
|
||||
<item name="Maven" href="http://maven.apache.org/"/>
|
||||
<item name="Apache" href="http://www.apache.org/"/>
|
||||
</links>
|
||||
|
||||
<menu name="Plugin info">
|
||||
<item name="Goals" href="plugin-info.html"/>
|
||||
<item name="Usage" href="upage.html"/>
|
||||
<item name="Advanced Usage" href="components.html"/>
|
||||
</menu>
|
||||
|
||||
<menu name="Used by">
|
||||
<!-- @TODO update href -->
|
||||
<item name="Maven Alfresco AMP Archetype" href="https://artifacts.alfresco.com/nexus/content/repositories/alfresco-docs/maven-alfresco-lifecycle/maven-alfresco-archetypes/maven-alfresco-amp-archetype/index.html"/>
|
||||
<item name="Maven Alfresco All In One Archetype" href="https://artifacts.alfresco.com/nexus/content/repositories/alfresco-docs/maven-alfresco-lifecycle/maven-alfresco-archetypes/maven-alfresco-amp-archetype/index.html"/>
|
||||
</menu>
|
||||
|
||||
<!--<menu name="See also">-->
|
||||
<!--</menu>-->
|
||||
|
||||
<!--<menu ref="reports"/>-->
|
||||
|
||||
</body>
|
||||
</project>
|
Reference in New Issue
Block a user