- Added attachClasses configuration which will attach a JAR with as separate 'classes' artifact

- Added attachConfig configuration which attaches a 'config' classifier JAR with the contents of the config dir of the AMP, useful as a test dependency

Fixes issue 147

git-svn-id: http://maven-alfresco-archetypes.googlecode.com/svn/trunk@706 04253f4f-3451-0410-a141-5562f1e59037
This commit is contained in:
rgauss
2013-10-29 19:49:11 +00:00
parent 427944a051
commit 1e1430fb5f

View File

@@ -73,6 +73,20 @@ public class AmpMojo extends AbstractMojo {
*/ */
protected boolean includeDependencies; protected boolean includeDependencies;
/**
* Whether the JAR produced should be attached as a separate 'classes' artifact.
*
* @parameter property="maven.alfresco.attachClasses" default-value="false"
*/
protected boolean attachClasses;
/**
* Whether a config artifact should be produced should be attached as a separate 'config' artifact.
*
* @parameter property="maven.alfresco.attachConfig" default-value="false"
*/
protected boolean attachConfig;
/** /**
* Directory of the final generated AMP * Directory of the final generated AMP
* *
@@ -128,12 +142,50 @@ public class AmpMojo extends AbstractMojo {
gatherDependencies(); gatherDependencies();
} }
File jarFile = createJarArchive();
if (this.attachClasses) {
this.projectHelper.attachArtifact(this.project, "jar", "classes", jarFile);
}
File ampFile = createArchive(); File ampFile = createArchive();
if (this.classifier != null) { if (this.classifier != null) {
this.projectHelper.attachArtifact(this.project, "amp", this.classifier, ampFile); this.projectHelper.attachArtifact(this.project, "amp", this.classifier, ampFile);
} else { } else {
this.project.getArtifact().setFile(ampFile); this.project.getArtifact().setFile(ampFile);
} }
if (attachConfig) {
File configFile = createConfigArchive();
this.projectHelper.attachArtifact(this.project, "jar", "config", configFile);
}
}
/**
* Creates and returns the JAR archive, invoking the MavenArchiver
*
* @return a File pointing to the JAR, contained
* in ${project.build.outputDirectory}
*/
protected File createJarArchive()
throws MojoExecutionException {
File jarFile = getFile(
new File(this.ampBuildDirectory, AmpModel.AMP_FOLDER_LIB),
this.ampFinalName,
this.classifier,
"jar");
MavenArchiver jarArchiver = new MavenArchiver();
jarArchiver.setArchiver(new JarArchiver());
jarArchiver.setOutputFile(jarFile);
try {
jarArchiver.getArchiver().addDirectory(this.classesDirectory, new String[] {}, new String[] {});
jarArchiver.createArchive(this.session, this.project, this.archive);
return jarFile;
}
catch (Exception e) {
throw new MojoExecutionException("Error creating JAR", e);
}
} }
/** /**
@@ -144,11 +196,6 @@ public class AmpMojo extends AbstractMojo {
*/ */
protected File createArchive() protected File createArchive()
throws MojoExecutionException { throws MojoExecutionException {
File jarFile = getFile(
new File(this.ampBuildDirectory, AmpModel.AMP_FOLDER_LIB),
this.ampFinalName,
this.classifier,
"jar");
File ampFile = getFile( File ampFile = getFile(
this.ampFinalDir, this.ampFinalDir,
@@ -157,10 +204,6 @@ public class AmpMojo extends AbstractMojo {
"amp" "amp"
); );
MavenArchiver jarArchiver = new MavenArchiver();
jarArchiver.setArchiver(new JarArchiver());
jarArchiver.setOutputFile(jarFile);
MavenArchiver ampArchiver = new MavenArchiver(); MavenArchiver ampArchiver = new MavenArchiver();
ampArchiver.setArchiver(new AmpArchiver()); ampArchiver.setArchiver(new AmpArchiver());
ampArchiver.setOutputFile(ampFile); ampArchiver.setOutputFile(ampFile);
@@ -172,12 +215,6 @@ public class AmpMojo extends AbstractMojo {
if (!this.ampBuildDirectory.exists()) { if (!this.ampBuildDirectory.exists()) {
getLog().warn("ampBuildDirectory does not exist - AMP will be empty"); getLog().warn("ampBuildDirectory does not exist - AMP will be empty");
} else { } 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 { try {
ampArchiver.getArchiver().addDirectory(this.ampBuildDirectory, new String[]{"**"}, new String[]{}); ampArchiver.getArchiver().addDirectory(this.ampBuildDirectory, new String[]{"**"}, new String[]{});
ampArchiver.createArchive(this.session, this.project, this.archive); ampArchiver.createArchive(this.session, this.project, this.archive);
@@ -189,6 +226,37 @@ public class AmpMojo extends AbstractMojo {
return ampFile; return ampFile;
} }
/**
* Creates and returns the config archive, invoking the MavenArchiver
*
* @return a File pointing to the JAR, contained
* in ${project.build.outputDirectory}
*/
protected File createConfigArchive()
throws MojoExecutionException {
File configFile = getFile(
new File(this.project.getBuild().getDirectory()),
this.ampFinalName,
this.classifier,
"jar");
MavenArchiver configArchiver = new MavenArchiver();
configArchiver.setArchiver(new JarArchiver());
configArchiver.setOutputFile(configFile);
try {
configArchiver.getArchiver().addDirectory(
new File(this.ampBuildDirectory, "config"),
new String[] { },
new String[] { "**/*.class" });
configArchiver.createArchive(this.session, this.project, this.archive);
return configFile;
}
catch (Exception e) {
throw new MojoExecutionException("Error creating config artifact", e);
}
}
/** /**
* Builds a File object pointing to the target AMP package; the pointer to the File is created taking into * 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 * account the (optional) artifact classifier defined