You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sn...@apache.org on 2007/07/18 04:54:50 UTC
svn commit: r557123 - in
/maven/plugins/branches/MWAR-97-2/src/main/java/org/apache/maven/plugin/war/packaging:
AbstractWarPackagingTask.java ArtifactsPackagingTask.java
ClassesPackagingTask.java WarPackagingContext.java
WarProjectPackagingTask.java
Author: snicoll
Date: Tue Jul 17 19:54:49 2007
New Revision: 557123
URL: http://svn.apache.org/viewvc?view=rev&rev=557123
Log:
War overlays refactoring: added classes packaging task.
Added:
maven/plugins/branches/MWAR-97-2/src/main/java/org/apache/maven/plugin/war/packaging/ClassesPackagingTask.java
Modified:
maven/plugins/branches/MWAR-97-2/src/main/java/org/apache/maven/plugin/war/packaging/AbstractWarPackagingTask.java
maven/plugins/branches/MWAR-97-2/src/main/java/org/apache/maven/plugin/war/packaging/ArtifactsPackagingTask.java
maven/plugins/branches/MWAR-97-2/src/main/java/org/apache/maven/plugin/war/packaging/WarPackagingContext.java
maven/plugins/branches/MWAR-97-2/src/main/java/org/apache/maven/plugin/war/packaging/WarProjectPackagingTask.java
Modified: maven/plugins/branches/MWAR-97-2/src/main/java/org/apache/maven/plugin/war/packaging/AbstractWarPackagingTask.java
URL: http://svn.apache.org/viewvc/maven/plugins/branches/MWAR-97-2/src/main/java/org/apache/maven/plugin/war/packaging/AbstractWarPackagingTask.java?view=diff&rev=557123&r1=557122&r2=557123
==============================================================================
--- maven/plugins/branches/MWAR-97-2/src/main/java/org/apache/maven/plugin/war/packaging/AbstractWarPackagingTask.java (original)
+++ maven/plugins/branches/MWAR-97-2/src/main/java/org/apache/maven/plugin/war/packaging/AbstractWarPackagingTask.java Tue Jul 17 19:54:49 2007
@@ -50,6 +50,10 @@
{
public static final String[] DEFAULT_INCLUDES = {"**/**"};
+ public static final String CLASSES_PATH = "WEB-INF/classes";
+
+ public static final String LIB_PATH = "WEB-INF/lib";
+
/**
* Copies the files if possible.
* <p/>
Modified: maven/plugins/branches/MWAR-97-2/src/main/java/org/apache/maven/plugin/war/packaging/ArtifactsPackagingTask.java
URL: http://svn.apache.org/viewvc/maven/plugins/branches/MWAR-97-2/src/main/java/org/apache/maven/plugin/war/packaging/ArtifactsPackagingTask.java?view=diff&rev=557123&r1=557122&r2=557123
==============================================================================
--- maven/plugins/branches/MWAR-97-2/src/main/java/org/apache/maven/plugin/war/packaging/ArtifactsPackagingTask.java (original)
+++ maven/plugins/branches/MWAR-97-2/src/main/java/org/apache/maven/plugin/war/packaging/ArtifactsPackagingTask.java Tue Jul 17 19:54:49 2007
@@ -19,8 +19,6 @@
extends AbstractWarPackagingTask
{
- public static final String LIB_PATH = "WEB-INF/lib";
-
public static final String TLD_PATH = "WEB-INF/tld";
public static final String SERVICES_PATH = "WEB-INF/services";
Added: maven/plugins/branches/MWAR-97-2/src/main/java/org/apache/maven/plugin/war/packaging/ClassesPackagingTask.java
URL: http://svn.apache.org/viewvc/maven/plugins/branches/MWAR-97-2/src/main/java/org/apache/maven/plugin/war/packaging/ClassesPackagingTask.java?view=auto&rev=557123
==============================================================================
--- maven/plugins/branches/MWAR-97-2/src/main/java/org/apache/maven/plugin/war/packaging/ClassesPackagingTask.java (added)
+++ maven/plugins/branches/MWAR-97-2/src/main/java/org/apache/maven/plugin/war/packaging/ClassesPackagingTask.java Tue Jul 17 19:54:49 2007
@@ -0,0 +1,98 @@
+package org.apache.maven.plugin.war.packaging;
+
+import org.apache.maven.archiver.MavenArchiver;
+import org.apache.maven.artifact.DependencyResolutionRequiredException;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.war.util.PathSet;
+import org.codehaus.plexus.archiver.ArchiverException;
+import org.codehaus.plexus.archiver.jar.ManifestException;
+
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * Handles the classes directory that needs to be packaged in the web application.
+ * <p/>
+ * Based on the {@link WarPackagingContext#archiveClasses()} flag the resources
+ * either copied into to <tt>WEB-INF/classes</tt> directory or archived in a jar
+ * within the <tt>WEB-INF/lib</tt> directory.
+ *
+ * @author Stephane Nicoll
+ */
+public class ClassesPackagingTask
+ extends AbstractWarPackagingTask
+{
+
+ public void performPackaging( WarPackagingContext context )
+ throws MojoExecutionException
+ {
+ final File webappClassesDirectory = new File( context.getWebAppDirectory(), CLASSES_PATH );
+
+ if ( context.getClassesDirectory().exists() && !context.getClassesDirectory().equals( webappClassesDirectory ) )
+ {
+ if ( context.archiveClasses() )
+ {
+ generateJarArchive( context );
+ }
+ else
+ {
+ final PathSet sources = getFilesToIncludes( context.getClassesDirectory(), null, null );
+ try
+ {
+ copyFiles( context, webappClassesDirectory, sources );
+ }
+ catch ( IOException e )
+ {
+ throw new MojoExecutionException(
+ "Could not copy webapp classes[" + context.getClassesDirectory().getAbsolutePath() + "]", e );
+ }
+ }
+ }
+ }
+
+ protected void generateJarArchive( WarPackagingContext context )
+ throws MojoExecutionException
+ {
+ //TODO use ArtifactFactory and resolve the final name the usual way instead
+ final String archiveName = context.getProject().getBuild().getFinalName() + ".jar";
+ final String targetFilename = LIB_PATH + File.separator + archiveName;
+
+ // TODO: this is bit hackish here ; check if the specified path is registered
+ if ( context.getProtectedFiles().contains( targetFilename ) )
+ {
+ context.getLogger().warn(
+ "Could not generate archive classes file[" + targetFilename + "] has already been copied." );
+ }
+ else
+ {
+ final File libDirectory = new File( context.getWebAppDirectory(), LIB_PATH );
+ final File jarFile = new File( libDirectory, archiveName );
+
+ try
+ {
+ final MavenArchiver archiver = new MavenArchiver();
+ archiver.setArchiver( context.getJarArchiver() );
+ archiver.setOutputFile( jarFile );
+ archiver.getArchiver().addDirectory( context.getClassesDirectory(), context.getWebAppSourceIncludes(),
+ context.getWebAppSourceExcludes() );
+ archiver.createArchive( context.getProject(), context.getArchive() );
+ }
+ catch ( ArchiverException e )
+ {
+ throw new MojoExecutionException( "Could not create classes archive", e );
+ }
+ catch ( ManifestException e )
+ {
+ throw new MojoExecutionException( "Could not create classes archive", e );
+ }
+ catch ( IOException e )
+ {
+ throw new MojoExecutionException( "Could not create classes archive", e );
+ }
+ catch ( DependencyResolutionRequiredException e )
+ {
+ throw new MojoExecutionException( "Could not create classes archive", e );
+ }
+ }
+ }
+}
Modified: maven/plugins/branches/MWAR-97-2/src/main/java/org/apache/maven/plugin/war/packaging/WarPackagingContext.java
URL: http://svn.apache.org/viewvc/maven/plugins/branches/MWAR-97-2/src/main/java/org/apache/maven/plugin/war/packaging/WarPackagingContext.java?view=diff&rev=557123&r1=557122&r2=557123
==============================================================================
--- maven/plugins/branches/MWAR-97-2/src/main/java/org/apache/maven/plugin/war/packaging/WarPackagingContext.java (original)
+++ maven/plugins/branches/MWAR-97-2/src/main/java/org/apache/maven/plugin/war/packaging/WarPackagingContext.java Tue Jul 17 19:54:49 2007
@@ -19,9 +19,11 @@
* under the License.
*/
+import org.apache.maven.archiver.MavenArchiveConfiguration;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.war.util.PathSet;
import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.archiver.jar.JarArchiver;
import org.codehaus.plexus.archiver.manager.ArchiverManager;
import org.codehaus.plexus.logging.Logger;
@@ -73,6 +75,21 @@
String[] getWebAppSourceExcludes();
/**
+ * Returns the directory holding generated classes.
+ *
+ * @return the classes directory
+ */
+ File getClassesDirectory();
+
+ /**
+ * Specify whether the classes resources should be archived in
+ * the <tt>WEB-INF/lib</tt> of the generated web app.
+ *
+ * @return true if the classes should be archived, false otherwise
+ */
+ boolean archiveClasses();
+
+ /**
* Returns the logger to use to output logging event.
*
* @return the logger
@@ -92,6 +109,21 @@
* @return the archiver manager
*/
ArchiverManager getArchiverManager();
+
+ /**
+ * The maven archive configuration to use.
+ *
+ * @return the maven archive configuration
+ */
+ MavenArchiveConfiguration getArchive();
+
+ /**
+ * Returns the Jar archiver needed for archiving classes directory into
+ * jar file under WEB-INF/lib.
+ *
+ * @return the jar archiver to user
+ */
+ JarArchiver getJarArchiver();
/**
* Returns the list of files that have already been copied during the
Modified: maven/plugins/branches/MWAR-97-2/src/main/java/org/apache/maven/plugin/war/packaging/WarProjectPackagingTask.java
URL: http://svn.apache.org/viewvc/maven/plugins/branches/MWAR-97-2/src/main/java/org/apache/maven/plugin/war/packaging/WarProjectPackagingTask.java?view=diff&rev=557123&r1=557122&r2=557123
==============================================================================
--- maven/plugins/branches/MWAR-97-2/src/main/java/org/apache/maven/plugin/war/packaging/WarProjectPackagingTask.java (original)
+++ maven/plugins/branches/MWAR-97-2/src/main/java/org/apache/maven/plugin/war/packaging/WarProjectPackagingTask.java Tue Jul 17 19:54:49 2007
@@ -13,6 +13,7 @@
* <ul
* <li>The list of web resources, if any</li>
* <li>The content of the webapp directory if it exists</li>
+ * <li>The content of the classes directory if it exists</li>
* <li>The dependencies of the project</li>
* </ul>
*
@@ -44,6 +45,8 @@
handeWebAppSourceDirectory( context );
+ handleClassesDirectory( context );
+
handleArtifacts( context );
}
@@ -114,7 +117,7 @@
* Handles the webapp artifacts.
*
* @param context the packaging context
- * @throws MojoExecutionException if the artifacts could not be copied
+ * @throws MojoExecutionException if the artifacts could not be packaged
*/
protected void handleArtifacts( WarPackagingContext context )
throws MojoExecutionException
@@ -123,6 +126,19 @@
task.performPackaging( context );
}
+ /**
+ * Handles the webapp classes.
+ *
+ * @param context the packaging context
+ * @throws MojoExecutionException if the classes could not be packaged
+ */
+ protected void handleClassesDirectory( WarPackagingContext context )
+ throws MojoExecutionException
+ {
+ ClassesPackagingTask task = new ClassesPackagingTask();
+ task.performPackaging( context );
+ }
+
/**
* Copies webapp webResources from the specified directory.
@@ -137,7 +153,7 @@
{
if ( !context.getWebAppDirectory().exists() )
{
- context.getLogger().warn( "Not copyuing webapp webResources[" + resource.getDirectory() +
+ context.getLogger().warn( "Not copying webapp webResources[" + resource.getDirectory() +
"]: webapp directory[" + context.getWebAppDirectory().getAbsolutePath() + "] does not exist!" );
}