Fix so JAR project files are not duplicated in WAR, #391

This commit is contained in:
Martin Bergljung
2016-09-05 15:23:53 +01:00
parent 558d4b422c
commit 05b2cfbb1e
2 changed files with 17 additions and 39 deletions

View File

@@ -134,6 +134,13 @@
<artifactId>mojo-executor</artifactId> <artifactId>mojo-executor</artifactId>
<version>2.2.0</version> <version>2.2.0</version>
</dependency> </dependency>
<!-- ZIP directories in an easy way -->
<dependency>
<groupId>org.zeroturnaround</groupId>
<artifactId>zt-zip</artifactId>
<version>1.9</version>
<type>jar</type>
</dependency>
</dependencies> </dependencies>
<reporting> <reporting>

View File

@@ -17,7 +17,6 @@
*/ */
package org.alfresco.maven.plugin; package org.alfresco.maven.plugin;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.maven.execution.MavenSession; import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Dependency; import org.apache.maven.model.Dependency;
@@ -31,9 +30,9 @@ import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.ResolutionScope; import org.apache.maven.plugins.annotations.ResolutionScope;
import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProject;
import org.zeroturnaround.zip.ZipUtil;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.util.*; import java.util.*;
import static org.twdata.maven.mojoexecutor.MojoExecutor.*; import static org.twdata.maven.mojoexecutor.MojoExecutor.*;
@@ -52,7 +51,6 @@ import static org.twdata.maven.mojoexecutor.MojoExecutor.*;
requiresDependencyResolution = ResolutionScope.TEST) requiresDependencyResolution = ResolutionScope.TEST)
public class RunMojo extends AbstractMojo { public class RunMojo extends AbstractMojo {
public static final String MAVEN_DEPENDENCY_PLUGIN_VERSION = "2.10"; public static final String MAVEN_DEPENDENCY_PLUGIN_VERSION = "2.10";
public static final String MAVEN_WAR_PLUGIN_VERSION = "2.6";
public static final String MAVEN_INSTALL_PLUGIN_VERSION = "2.5.2"; public static final String MAVEN_INSTALL_PLUGIN_VERSION = "2.5.2";
public static final String MAVEN_REPLACER_PLUGIN_VERSION = "1.5.3"; public static final String MAVEN_REPLACER_PLUGIN_VERSION = "1.5.3";
public static final String MAVEN_RESOURCE_PLUGIN_VERSION = "2.7"; public static final String MAVEN_RESOURCE_PLUGIN_VERSION = "2.7";
@@ -626,8 +624,8 @@ public class RunMojo extends AbstractMojo {
// Then apply all these amps to the unpacked war // Then apply all these amps to the unpacked war
// Call the Alfresco Maven Plugin Install Mojo directly, so we don't have to keep SDK version info here // Call the Alfresco Maven Plugin Install Mojo directly, so we don't have to keep SDK version info here
String ampsLocation = project.getBasedir() + "/target/" + ampsModuleDir; String ampsLocation = project.getBuild().getDirectory() + "/" + ampsModuleDir;
String warLocation = project.getBasedir() + "/target/" + getWarName(warName); String warLocation = project.getBuild().getDirectory() + "/" + getWarName(warName);
InstallMojo installMojo = new InstallMojo(); InstallMojo installMojo = new InstallMojo();
installMojo.setAmpLocation(new File(ampsLocation)); installMojo.setAmpLocation(new File(ampsLocation));
installMojo.setWarLocation(new File(warLocation)); installMojo.setWarLocation(new File(warLocation));
@@ -669,39 +667,12 @@ public class RunMojo extends AbstractMojo {
final String warSourceDir = getWarOutputDir(warName); final String warSourceDir = getWarOutputDir(warName);
// Package the customized war file // Package the customized war file
executeMojo( // Note. don't use the maven-war-plugin here as it will package the module files twice, once from the
plugin( // target/classes dir and once via the JAR
groupId("org.apache.maven.plugins"), String warPath = project.getBuild().getDirectory() + "/" + warName + ".war";
artifactId("maven-war-plugin"), ZipUtil.pack(new File(warSourceDir), new File(warPath));
version(MAVEN_WAR_PLUGIN_VERSION)
),
goal("war"),
configuration(
element(name("warName"), warName),
element(name("warSourceDirectory"), warSourceDir),
// Specifically tell the archiver where the manifest file is,
// so a new manifest is not generated.
// We are picking the manifest from the original war.
// If we don't do this, then customized share.war will not start properly.
element(name("archive"),
element(name("manifestFile"), warSourceDir + "/META-INF/MANIFEST.MF")
)
)
, execEnv
);
// Delete temporary webapp assembly dir, so it is not added to next webapp that is assembled... // Install the customized war file in the local maven repo
// (otherwise share.war will contain alfresco.war stuff)
String tempAssemblyDir = project.getBasedir() + "/target/" + project.getArtifactId() + "-" + project.getVersion();
getLog().info("Deleting temp webapp assembly dir: " + tempAssemblyDir);
File tempWebAppAssemblyDir = new File(tempAssemblyDir);
try {
FileUtils.deleteDirectory(tempWebAppAssemblyDir);
} catch (IOException e) {
e.printStackTrace();
}
// Install the customized war file in local maven repo
executeMojo( executeMojo(
plugin( plugin(
groupId("org.apache.maven.plugins"), groupId("org.apache.maven.plugins"),
@@ -710,7 +681,7 @@ public class RunMojo extends AbstractMojo {
), ),
goal("install-file"), goal("install-file"),
configuration( configuration(
element(name("file"), "${project.build.directory}/" + warName + ".war"), element(name("file"), warPath),
element(name("groupId"), "${project.groupId}"), element(name("groupId"), "${project.groupId}"),
element(name("artifactId"), warArtifactId), element(name("artifactId"), warArtifactId),
element(name("version"), "${project.version}"), element(name("version"), "${project.version}"),
@@ -1093,7 +1064,7 @@ public class RunMojo extends AbstractMojo {
* @return a directory such as: .../aio/target/platform-war * @return a directory such as: .../aio/target/platform-war
*/ */
private String getWarOutputDir(String baseWarName) { private String getWarOutputDir(String baseWarName) {
return "${project.build.directory}/" + getWarName(baseWarName); return project.getBuild().getDirectory() + "/" + getWarName(baseWarName);
} }
/** /**