You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by tr...@apache.org on 2006/01/11 09:43:00 UTC
svn commit: r367972 - in
/maven/plugins/trunk/maven-war-plugin/src/main/java/org/apache/maven/plugin/war:
AbstractWarMojo.java WarMojo.java
Author: trygvis
Date: Wed Jan 11 00:42:42 2006
New Revision: 367972
URL: http://svn.apache.org/viewcvs?rev=367972&view=rev
Log:
o Adding support for attached WARs.
Modified:
maven/plugins/trunk/maven-war-plugin/src/main/java/org/apache/maven/plugin/war/AbstractWarMojo.java
maven/plugins/trunk/maven-war-plugin/src/main/java/org/apache/maven/plugin/war/WarMojo.java
Modified: maven/plugins/trunk/maven-war-plugin/src/main/java/org/apache/maven/plugin/war/AbstractWarMojo.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-war-plugin/src/main/java/org/apache/maven/plugin/war/AbstractWarMojo.java?rev=367972&r1=367971&r2=367972&view=diff
==============================================================================
--- maven/plugins/trunk/maven-war-plugin/src/main/java/org/apache/maven/plugin/war/AbstractWarMojo.java (original)
+++ maven/plugins/trunk/maven-war-plugin/src/main/java/org/apache/maven/plugin/war/AbstractWarMojo.java Wed Jan 11 00:42:42 2006
@@ -80,7 +80,7 @@
* @parameter expression="${maven.war.webxml}"
*/
private String webXml;
-
+
/**
* Directory to unpack dependent WARs into if needed
*
@@ -88,7 +88,7 @@
* @required
*/
private File workDirectory;
-
+
/**
* To look up Archiver/UnArchiver implementations
*
@@ -96,7 +96,6 @@
* @required
*/
protected ArchiverManager archiverManager;
-
public static final String WEB_INF = "WEB-INF";
@@ -114,20 +113,20 @@
* @parameter alias="excludes"
*/
private String warSourceExcludes;
-
+
/**
* The comma separated list of tokens to include when doing
* a war overlay.
* Default is '**'
- *
+ *
* @parameter
*/
private String dependentWarIncludes = "**";
-
+
/**
* The comma separated list of tokens to exclude when doing
* a way overlay.
- *
+ *
* @parameter
*/
private String dependentWarExcludes;
@@ -220,11 +219,11 @@
{
return StringUtils.split( StringUtils.defaultString( warSourceIncludes ), "," );
}
-
+
/**
* Returns a string array of the excludes to be used
* when adding dependent wars as an overlay onto this war.
- *
+ *
* @return an array of tokens to exclude
*/
protected String[] getDependentWarExcludes() {
@@ -235,11 +234,11 @@
return (String[]) EMPTY_STRING_ARRAY.clone();
}
-
+
/**
* Returns a string array of the includes to be used
* when adding dependent wars as an overlay onto this war.
- *
+ *
* @return an array of tokens to include
*/
protected String[] getDependentWarIncludes() {
@@ -334,7 +333,7 @@
}
Set artifacts = project.getArtifacts();
-
+
List dependentWarDirectories = new ArrayList();
for ( Iterator iter = artifacts.iterator(); iter.hasNext(); )
@@ -364,7 +363,7 @@
}
}
}
-
+
if ( dependentWarDirectories.size() > 0 )
{
getLog().info( "Overlaying " + dependentWarDirectories.size() + " war(s)." );
@@ -376,11 +375,11 @@
}
}
}
-
+
/**
* Unpacks war artifacts into a temporary directory inside <tt>workDirectory</tt>
* named with the name of the war.
- *
+ *
* @param artifact War artifact to unpack.
* @return Directory containing the unpacked war.
* @throws MojoExecutionException
@@ -417,7 +416,7 @@
return tempLocation;
}
-
+
/**
* Unpacks the archive file.
*
@@ -446,16 +445,16 @@
throw new MojoExecutionException( "Error unpacking file: " + file + "to: " + location, e );
}
}
-
+
/**
* Recursively copies contents of <tt>srcDir</tt> into <tt>targetDir</tt>.
* This will not overwrite any existing files.
- *
+ *
* @param srcDir Directory containing unpacked dependent war contents
* @param targetDir Directory to overlay srcDir into
*/
private void copyDependentWarContents( File srcDir, File targetDir )
- throws IOException, MojoExecutionException
+ throws MojoExecutionException
{
DirectoryScanner scanner = new DirectoryScanner();
scanner.setBasedir( srcDir );
@@ -477,7 +476,7 @@
for ( int j = 0; j < files.length; j++ )
{
File targetFile = new File( targetDir, files[j] );
-
+
// Do not overwrite existing files.
if (!targetFile.exists())
{
Modified: maven/plugins/trunk/maven-war-plugin/src/main/java/org/apache/maven/plugin/war/WarMojo.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-war-plugin/src/main/java/org/apache/maven/plugin/war/WarMojo.java?rev=367972&r1=367971&r2=367972&view=diff
==============================================================================
--- maven/plugins/trunk/maven-war-plugin/src/main/java/org/apache/maven/plugin/war/WarMojo.java (original)
+++ maven/plugins/trunk/maven-war-plugin/src/main/java/org/apache/maven/plugin/war/WarMojo.java Wed Jan 11 00:42:42 2006
@@ -20,6 +20,7 @@
import org.apache.maven.archiver.MavenArchiver;
import org.apache.maven.artifact.DependencyResolutionRequiredException;
import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.project.MavenProjectHelper;
import org.codehaus.plexus.archiver.ArchiverException;
import org.codehaus.plexus.archiver.jar.ManifestException;
import org.codehaus.plexus.archiver.war.WarArchiver;
@@ -27,7 +28,6 @@
import java.io.File;
import java.io.IOException;
-
/**
* Build a war/webapp.
*
@@ -57,6 +57,13 @@
private String warName;
/**
+ * Classifier to add to the artifact generated. If given, the artifact will be an attachment instead.
+ *
+ * @parameter
+ */
+ private String classifier;
+
+ /**
* The Jar archiver.
*
* @parameter expression="${component.org.codehaus.plexus.archiver.Archiver#war}"
@@ -72,6 +79,37 @@
private MavenArchiveConfiguration archive = new MavenArchiveConfiguration();
/**
+ * @component
+ */
+ private MavenProjectHelper projectHelper;
+
+ // ----------------------------------------------------------------------
+ // Implementation
+ // ----------------------------------------------------------------------
+
+ /**
+ * Overload this to produce a test-war, for example.
+ */
+ protected String getClassifier()
+ {
+ return classifier;
+ }
+
+ protected static File getWarFile( File basedir, String finalName, String classifier )
+ {
+ if ( classifier == null )
+ {
+ classifier = "";
+ }
+ else if ( classifier.trim().length() > 0 && !classifier.startsWith( "-" ) )
+ {
+ classifier = "-" + classifier;
+ }
+
+ return new File( basedir, finalName + classifier + ".war" );
+ }
+
+ /**
* Executes the WarMojo on the current project.
*
* @throws MojoExecutionException if an error occured while building the webapp
@@ -79,7 +117,7 @@
public void execute()
throws MojoExecutionException
{
- File warFile = new File( outputDirectory, warName + ".war" );
+ File warFile = getWarFile( new File( outputDirectory ), warName, getClassifier() );
try
{
@@ -123,6 +161,14 @@
// create archive
archiver.createArchive( getProject(), archive );
- getProject().getArtifact().setFile( warFile );
+ String classifier = getClassifier();
+ if ( classifier != null )
+ {
+ projectHelper.attachArtifact( getProject(), "war", classifier, warFile );
+ }
+ else
+ {
+ getProject().getArtifact().setFile( warFile );
+ }
}
}