fixed issue #297, now webappDirectory is honored if present

This commit is contained in:
mindthegab 2015-06-01 18:13:36 +01:00
parent 41dd5ff1ea
commit a39a11ffe7

View File

@ -1,15 +1,25 @@
package org.alfresco.maven.plugin.archiver; package org.alfresco.maven.plugin.archiver;
import java.io.File; import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import org.alfresco.repo.module.tool.ModuleManagementTool; import org.alfresco.repo.module.tool.ModuleManagementTool;
import org.apache.maven.execution.MavenSession; import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.ConfigurationContainer;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.PluginConfiguration;
import org.apache.maven.plugin.ContextEnabled;
import org.apache.maven.plugin.LegacySupport; import org.apache.maven.plugin.LegacySupport;
import org.apache.maven.plugin.MojoExecution;
import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.project.MavenProject; 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;
import org.codehaus.plexus.util.xml.Xpp3Dom;
/** /**
* This class provides AMP unpacking support for projects depending on AMPs * 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 * This allows for example AMPs to be specified as <overlay> in the maven-war-plugin
@ -24,14 +34,44 @@ public class AmpUnArchiver extends AbstractZipUnArchiver {
@Requirement @Requirement
private LegacySupport legacySupport; private LegacySupport legacySupport;
private Map pluginContext = new HashMap();
/**
* @parameter default-value="${mojoExecution}"
* @readonly
*/
private MojoExecution mojoExecution;
@Override @Override
/** /**
* By default the AMPs are unpacked in ${project.directory}/${project.build.finalName} * 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();
return new File(project.getBuild().getDirectory() + File.separator + project.getBuild().getFinalName()); // By default we use build finalName
File location = new File(project.getBuild().getDirectory() + File.separator + project.getBuild().getFinalName());
// If the war plugin configures a custom webappDirectory instead, we pick it up
Plugin warPlugin = project.getPlugin("org.apache.maven.plugins:maven-war-plugin");
if(warPlugin != null)
{
Xpp3Dom warPluginConfig = (Xpp3Dom) warPlugin.getConfiguration();
if(warPluginConfig != null)
{
Xpp3Dom warConfigElement = warPluginConfig.getChild("webappDirectory");
if(warConfigElement != null)
{
String webappDir = warConfigElement.getValue();
if(webappDir != null && !webappDir.isEmpty())
{
location = new File(webappDir);
}
}
}
}
return location;
} }
@Override @Override
@ -41,6 +81,7 @@ public class AmpUnArchiver extends AbstractZipUnArchiver {
* Invoke the ModuleManagementTool to install AMP modules on the WAR file; * Invoke the ModuleManagementTool to install AMP modules on the WAR file;
* so far, no backup or force flags are enabled * so far, no backup or force flags are enabled
*/ */
File destDirectory = getDestDirectory();
ModuleManagementTool mmt = new ModuleManagementTool(); ModuleManagementTool mmt = new ModuleManagementTool();
mmt.setVerbose(false); mmt.setVerbose(false);
@ -48,9 +89,9 @@ public class AmpUnArchiver extends AbstractZipUnArchiver {
getLogger().info("Installing into destination file: " + getDestFile()); getLogger().info("Installing into destination file: " + getDestFile());
if(getDestDirectory()!= null) if(getDestDirectory()!= null)
getLogger().info("Installing into destination folder: " + getDestDirectory()); getLogger().info("Installing into destination folder: " + destDirectory);
File destLocation = (getDestFile() == null || !getDestFile().exists() ) ? getDestDirectory() : getDestFile(); File destLocation = (getDestFile() == null || !getDestFile().exists() ) ? destDirectory : getDestFile();
getLogger().info("Installing " + getSourceFile() + " into " + destLocation); getLogger().info("Installing " + getSourceFile() + " into " + destLocation);
try { try {
@ -73,4 +114,5 @@ public class AmpUnArchiver extends AbstractZipUnArchiver {
} }
} }
} }