brett 2005/03/22 05:25:58
Modified: maven-archiver/src/main/java/org/apache/maven/archiver
MavenArchiver.java
maven-plugins/maven-war-plugin/src/main/java/org/apache/maven/plugin/war
WarMojo.java
maven-plugins/maven-jar-plugin/src/main/java/org/apache/maven/plugin/jar
JarMojo.java
maven-plugins/maven-ejb-plugin/src/main/java/org/apache/maven/plugin/ejb
EjbMojo.java
Removed:
maven-plugins/maven-jar-plugin/src/main/java/org/apache/maven/plugin/jar
JarDeployMojo.java JarInstallMojo.java
Log:
convert archive mojos to new execute(). More work is required to reuse the
common fields.
Revision Changes Path
1.5 +34 -55
maven-components/maven-archiver/src/main/java/org/apache/maven/archiver/MavenArchiver.java
Index: MavenArchiver.java
===================================================================
RCS file:
/home/cvs/maven-components/maven-archiver/src/main/java/org/apache/maven/archiver/MavenArchiver.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- MavenArchiver.java 10 Mar 2005 09:44:49 -0000 1.4
+++ MavenArchiver.java 22 Mar 2005 13:25:58 -0000 1.5
@@ -1,62 +1,53 @@
package org.apache.maven.archiver;
-/* ====================================================================
- * Copyright 2001-2005 The Apache Software Foundation.
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ====================================================================
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
import org.apache.maven.artifact.Artifact;
-import org.apache.maven.model.Dependency;
-import org.apache.maven.plugin.PluginExecutionRequest;
import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.archiver.ArchiverException;
import org.codehaus.plexus.archiver.jar.JarArchiver;
import org.codehaus.plexus.archiver.jar.Manifest;
+import org.codehaus.plexus.archiver.jar.ManifestException;
import java.io.File;
+import java.io.IOException;
import java.util.Iterator;
-import java.util.List;
import java.util.Set;
/**
+ * @todo improve the use of this now that plugin fields are used instead of
a request object - add an <archive> element to configuration?
* @author <a href="[EMAIL PROTECTED]">Emmanuel Venisse</a>
* @version $Revision$ $Date$
*/
public class MavenArchiver
{
- JarArchiver archiver = new JarArchiver();
+ private JarArchiver archiver = new JarArchiver();
- File archiveFile;
+ private File archiveFile;
/**
* Return a pre-configured manifest
*
* @todo Add user attributes list and user groups list
*/
- public Manifest getManifest( PluginExecutionRequest request )
- throws Exception
+ public Manifest getManifest( MavenProject project, String mainClass,
String packageName, boolean addClasspath,
+ boolean addExtensions )
+ throws ManifestException
{
- MavenProject project = (MavenProject) request.getParameter(
"project" );
-
- String mainClass = (String) request.getParameter( "mainClass" );
-
- String packageName = (String) request.getParameter( "package" );
-
- boolean addClasspath = new Boolean( (String) request.getParameter(
"addClasspath" ) ).booleanValue();
-
- boolean addExtensions = new Boolean( (String) request.getParameter(
"addExtensions" ) ).booleanValue();
-
// Added basic entries
Manifest m = new Manifest();
Manifest.Attribute buildAttr = new Manifest.Attribute( "Built-By",
System.getProperty( "user.name" ) );
@@ -88,7 +79,7 @@
classpath.append( " " );
}
- classpath.append( artifact.getArtifactId() + "-" +
artifact.getVersion() + ".jar");
+ classpath.append( artifact.getArtifactId() + "-" +
artifact.getVersion() + ".jar" );
}
}
@@ -168,13 +159,13 @@
"-Extension-Name",
artifact.getArtifactId() );
m.addConfiguredAttribute( archExtNameAttr );
- Manifest.Attribute archImplVersionAttr = new
Manifest.Attribute( artifact.getArtifactId() +
-
"-Implementation-Version",
-
artifact.getVersion() );
+ String name = artifact.getArtifactId() +
"-Implementation-Version";
+ Manifest.Attribute archImplVersionAttr = new
Manifest.Attribute( name, artifact.getVersion() );
m.addConfiguredAttribute( archImplVersionAttr );
- Manifest.Attribute archImplUrlAttr = new
Manifest.Attribute( artifact.getArtifactId() +
-
"-Implementation-URL", "http://www.ibiblio.org/maven/" +
-
artifact.toString() );
+ // TODO: make repo configurable
+ name = artifact.getArtifactId() + "-Implementation-URL";
+ String url = "http://www.ibiblio.org/maven/" +
artifact.toString();
+ Manifest.Attribute archImplUrlAttr = new
Manifest.Attribute( name, url );
m.addConfiguredAttribute( archImplUrlAttr );
}
}
@@ -198,35 +189,23 @@
archiveFile = outputFile;
}
- public void createArchive( PluginExecutionRequest request )
- throws Exception
+ public void createArchive( MavenProject project, String manifestFile,
boolean compress, boolean index,
+ Manifest manifest )
+ throws ArchiverException, ManifestException, IOException
{
//
----------------------------------------------------------------------
//
//
----------------------------------------------------------------------
- MavenProject project = (MavenProject) request.getParameter(
"project" );
-
- String manifest = (String) request.getParameter( "manifest" );
-
- boolean compress = new Boolean( (String) request.getParameter(
"compress" ) ).booleanValue();
-
- boolean index = new Boolean( (String) request.getParameter( "index"
) ).booleanValue();
-
- //
----------------------------------------------------------------------
- //
- //
----------------------------------------------------------------------
-
archiver.addFile( project.getFile(), "META-INF/maven/pom.xml" );
- if ( manifest != null && !"".equals( manifest ) )
+ if ( manifestFile != null && !"".equals( manifestFile ) )
{
- File manifestFile = new File( manifest );
- archiver.setManifest( manifestFile );
+ archiver.setManifest( new File( manifestFile ) );
}
// Configure the jar
- archiver.addConfiguredManifest( getManifest( request ) );
+ archiver.addConfiguredManifest( manifest );
archiver.setCompress( compress );
archiver.setIndex( index );
1.11 +81 -48
maven-components/maven-plugins/maven-war-plugin/src/main/java/org/apache/maven/plugin/war/WarMojo.java
Index: WarMojo.java
===================================================================
RCS file:
/home/cvs/maven-components/maven-plugins/maven-war-plugin/src/main/java/org/apache/maven/plugin/war/WarMojo.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- WarMojo.java 21 Mar 2005 00:07:39 -0000 1.10
+++ WarMojo.java 22 Mar 2005 13:25:58 -0000 1.11
@@ -19,9 +19,11 @@
import org.apache.maven.archiver.MavenArchiver;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.AbstractPlugin;
-import org.apache.maven.plugin.PluginExecutionRequest;
-import org.apache.maven.plugin.PluginExecutionResponse;
+import org.apache.maven.plugin.PluginExecutionException;
import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.archiver.ArchiverException;
+import org.codehaus.plexus.archiver.jar.Manifest;
+import org.codehaus.plexus.archiver.jar.ManifestException;
import org.codehaus.plexus.archiver.war.WarArchiver;
import org.codehaus.plexus.util.FileUtils;
@@ -56,7 +58,7 @@
* expression="#maven.jar.index"
* default="false"
* description=""
- * @parameter name="package"
+ * @parameter name="packageName"
* type="String"
* required="false"
* validator=""
@@ -144,21 +146,34 @@
public class WarMojo
extends AbstractPlugin
{
- public static final String WEB_INF = "WEB-INF";
+ private static final String[] DEFAULT_INCLUDES = new String[]{"**/**"};
+
+ private static final String[] DEFAULT_EXCLUDES = new
String[]{"**/WEB-INF/web.xml"};
- private PluginExecutionRequest request;
+ public static final String WEB_INF = "WEB-INF";
private String mode;
private MavenProject project;
- private File classesDirectory;
+ private String basedir;
+
+ /**
+ * @todo File
+ */
+ private String classesDirectory;
private String outputDirectory;
- private File webappDirectory;
+ /**
+ * @todo File
+ */
+ private String webappDirectory;
- private File warSourceDirectory;
+ /**
+ * @todo File
+ */
+ private String warSourceDirectory;
private String warSourceIncludes;
@@ -166,7 +181,33 @@
private String webXml;
- private File warFile;
+ private String warName;
+
+ private String mainClass;
+
+ private String packageName;
+
+ private String manifest;
+
+ /**
+ * @todo boolean instead
+ */
+ private String addClasspath;
+
+ /**
+ * @todo boolean instead
+ */
+ private String addExtensions;
+
+ /**
+ * @todo boolean instead
+ */
+ private String index;
+
+ /**
+ * @todo boolean instead
+ */
+ private String compress;
public void copyResources( File sourceDirectory, File webappDirectory,
String includes, String excludes,
String webXml )
@@ -176,7 +217,7 @@
{
getLog().info( "Copy webapp resources to " +
webappDirectory.getAbsolutePath() );
- if ( warSourceDirectory.exists() )
+ if ( new File( warSourceDirectory ).exists() )
{
//TODO : Use includes and excludes
FileUtils.copyDirectoryStructure( sourceDirectory,
webappDirectory );
@@ -195,7 +236,7 @@
public void buildWebapp( MavenProject project )
throws IOException
{
- getLog().info( "Assembling webapp " + project.getArtifactId() + " in
" + webappDirectory.getAbsolutePath() );
+ getLog().info( "Assembling webapp " + project.getArtifactId() + " in
" + webappDirectory );
File libDirectory = new File( webappDirectory, WEB_INF + "/lib" );
@@ -203,6 +244,7 @@
File webappClassesDirectory = new File( webappDirectory, WEB_INF +
"/classes" );
+ File classesDirectory = new File( this.classesDirectory );
if ( classesDirectory.exists() )
{
FileUtils.copyDirectoryStructure( classesDirectory,
webappClassesDirectory );
@@ -228,13 +270,14 @@
public void generateExplodedWebapp()
throws IOException
{
+ File webappDirectory = new File( this.webappDirectory );
webappDirectory.mkdirs();
File webinfDir = new File( webappDirectory, WEB_INF );
webinfDir.mkdirs();
- copyResources( warSourceDirectory, webappDirectory,
warSourceIncludes, warSourceExcludes, webXml );
+ copyResources( new File( warSourceDirectory ), webappDirectory,
warSourceIncludes, warSourceExcludes, webXml );
buildWebapp( project );
}
@@ -247,19 +290,25 @@
generateExplodedWebapp();
}
- public void execute( PluginExecutionRequest request,
PluginExecutionResponse response )
- throws Exception
+ public void execute()
+ throws PluginExecutionException
{
- //
----------------------------------------------------------------------
- //
- //
----------------------------------------------------------------------
-
- parseRequest( request );
-
- //
----------------------------------------------------------------------
- //
- //
----------------------------------------------------------------------
+ File warFile = new File( outputDirectory, warName + ".war" );
+ try
+ {
+ performPackaging( warFile );
+ }
+ catch ( Exception e )
+ {
+ // TODO: improve error handling
+ throw new PluginExecutionException( "Error assembling EJB", e );
+ }
+ }
+
+ private void performPackaging( File warFile )
+ throws IOException, ArchiverException, ManifestException
+ {
if ( "inplace".equals( mode ) )
{
generateInPlaceWebapp();
@@ -281,38 +330,22 @@
archiver.setOutputFile( warFile );
- warArchiver.addDirectory( webappDirectory, new
String[]{"**/**"}, new String[]{"**/WEB-INF/web.xml"} );
+ warArchiver.addDirectory( new File( webappDirectory ),
DEFAULT_INCLUDES, DEFAULT_EXCLUDES );
warArchiver.setWebxml( new File( webappDirectory,
"WEB-INF/web.xml" ) );
// create archive
- archiver.createArchive( request );
+ Manifest configuredManifest = archiver.getManifest( project,
mainClass, packageName,
+
convertBoolean( addClasspath ),
+
convertBoolean( addExtensions ) );
+ archiver.createArchive( project, manifest, convertBoolean(
compress ), convertBoolean( index ),
+ configuredManifest );
}
}
}
- public void parseRequest( PluginExecutionRequest request )
+ private static boolean convertBoolean( String s )
{
- this.request = request;
-
- project = (MavenProject) request.getParameter( "project" );
-
- classesDirectory = new File( (String) request.getParameter(
"classesDirectory" ) );
-
- outputDirectory = (String) request.getParameter( "outputDirectory" );
-
- webappDirectory = new File( (String) request.getParameter(
"webappDirectory" ) );
-
- warSourceDirectory = new File( (String) request.getParameter(
"warSourceDirectory" ) );
-
- warSourceIncludes = (String) request.getParameter(
"warSourceIncludes" );
-
- warSourceExcludes = (String) request.getParameter(
"warSourceExcludes" );
-
- webXml = (String) request.getParameter( "webXml" );
-
- mode = (String) request.getParameter( "mode" );
-
- warFile = new File( outputDirectory, (String) request.getParameter(
"warName" ) + ".war" );
+ return Boolean.valueOf( s ).booleanValue();
}
}
1.18 +65 -21
maven-components/maven-plugins/maven-jar-plugin/src/main/java/org/apache/maven/plugin/jar/JarMojo.java
Index: JarMojo.java
===================================================================
RCS file:
/home/cvs/maven-components/maven-plugins/maven-jar-plugin/src/main/java/org/apache/maven/plugin/jar/JarMojo.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- JarMojo.java 10 Mar 2005 09:36:44 -0000 1.17
+++ JarMojo.java 22 Mar 2005 13:25:58 -0000 1.18
@@ -18,8 +18,9 @@
import org.apache.maven.archiver.MavenArchiver;
import org.apache.maven.plugin.AbstractPlugin;
-import org.apache.maven.plugin.PluginExecutionRequest;
-import org.apache.maven.plugin.PluginExecutionResponse;
+import org.apache.maven.plugin.PluginExecutionException;
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.archiver.jar.Manifest;
import java.io.File;
@@ -49,7 +50,7 @@
* expression="#maven.jar.index"
* default="false"
* description=""
- * @parameter name="package"
+ * @parameter name="packageName"
* type="String"
* required="false"
* validator=""
@@ -104,35 +105,78 @@
extends AbstractPlugin
{
/**
- * @todo Add license files in META-INF directory.
+ * @todo File
*/
- public void execute( PluginExecutionRequest request,
PluginExecutionResponse response )
- throws Exception
- {
- //
----------------------------------------------------------------------
- //
- //
----------------------------------------------------------------------
+ private String basedir;
+
+ private String jarName;
+
+ private String outputDirectory;
+
+ private static final String[] DEFAULT_EXCLUDES = new
String[]{"**/package.html"};
+
+ private static final String[] DEFAULT_INCLUDES = new String[]{"**/**"};
- File basedir = new File( (String) request.getParameter( "basedir" )
);
+ private MavenProject project;
+
+ private String manifest;
+
+ private String mainClass;
+
+ private String packageName;
+
+ /**
+ * @todo boolean instead
+ */
+ private String addClasspath;
- String outputDirectory = (String) request.getParameter(
"outputDirectory" );
+ /**
+ * @todo boolean instead
+ */
+ private String addExtensions;
- String jarName = (String) request.getParameter( "jarName" );
+ /**
+ * @todo boolean instead
+ */
+ private String index;
- //
----------------------------------------------------------------------
- //
- //
----------------------------------------------------------------------
+ /**
+ * @todo boolean instead
+ */
+ private String compress;
+ /**
+ * @todo Add license files in META-INF directory.
+ */
+ public void execute()
+ throws PluginExecutionException
+ {
File jarFile = new File( basedir, jarName + ".jar" );
MavenArchiver archiver = new MavenArchiver();
archiver.setOutputFile( jarFile );
- archiver.getArchiver().addDirectory( new File( outputDirectory ),
new String[]{"**/**"},
- new String[]{"**/package.html"}
);
+ try
+ {
+ archiver.getArchiver().addDirectory( new File( outputDirectory
), DEFAULT_INCLUDES, DEFAULT_EXCLUDES );
+
+ // create archive
+ Manifest configuredManifest = archiver.getManifest( project,
mainClass, packageName,
+
convertBoolean( addClasspath ),
+
convertBoolean( addExtensions ) );
+ archiver.createArchive( project, manifest, convertBoolean(
compress ), convertBoolean( index ),
+ configuredManifest );
+ }
+ catch ( Exception e )
+ {
+ // TODO: improve error handling
+ throw new PluginExecutionException( "Error assembling EJB", e );
+ }
+ }
- // create archive
- archiver.createArchive( request );
+ private static boolean convertBoolean( String s )
+ {
+ return Boolean.valueOf( s ).booleanValue();
}
}
1.4 +91 -42
maven-components/maven-plugins/maven-ejb-plugin/src/main/java/org/apache/maven/plugin/ejb/EjbMojo.java
Index: EjbMojo.java
===================================================================
RCS file:
/home/cvs/maven-components/maven-plugins/maven-ejb-plugin/src/main/java/org/apache/maven/plugin/ejb/EjbMojo.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- EjbMojo.java 21 Mar 2005 08:18:33 -0000 1.3
+++ EjbMojo.java 22 Mar 2005 13:25:58 -0000 1.4
@@ -18,8 +18,9 @@
import org.apache.maven.archiver.MavenArchiver;
import org.apache.maven.plugin.AbstractPlugin;
-import org.apache.maven.plugin.PluginExecutionRequest;
-import org.apache.maven.plugin.PluginExecutionResponse;
+import org.apache.maven.plugin.PluginExecutionException;
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.archiver.jar.Manifest;
import java.io.File;
@@ -49,7 +50,7 @@
* expression="#maven.ejb.index"
* default="false"
* description=""
- * @parameter name="package"
+ * @parameter name="packageName"
* type="String"
* required="false"
* validator=""
@@ -110,66 +111,114 @@
public class EjbMojo
extends AbstractPlugin
{
+ // TODO: will null work instead?
+ private static final String[] DEFAULT_INCLUDES = new String[]{"**/**"};
+
+ private static final String[] DEFAULT_EXCLUDES = new
String[]{"**/*Bean.class", "**/*CMP.class",
+
"**/*Session.class", "**/package.html"};
+
/**
- * @todo Add license files in META-INF directory.
+ * @todo File instead
*/
- public void execute( PluginExecutionRequest request,
PluginExecutionResponse response ) throws Exception
- {
- //
----------------------------------------------------------------------
- //
- //
----------------------------------------------------------------------
+ private String basedir;
- File basedir = new File( (String) request.getParameter( "basedir" )
);
+ private String outputDirectory;
- String outputDirectory = (String) request.getParameter(
"outputDirectory" );
+ private String jarName;
- String jarName = (String) request.getParameter( "jarName" );
+ /**
+ * @todo boolean instead
+ */
+ private String generateClient;
- boolean generateClient = new Boolean( (String) request.getParameter(
"generateClient" ) ).booleanValue();
+ private MavenProject project;
- //
----------------------------------------------------------------------
- //
- //
----------------------------------------------------------------------
+ private String mainClass;
- getLog().info( "Building ejb " + jarName );
+ private String packageName;
- File jarFile = new File( basedir, jarName + ".jar" );
+ private String manifest;
- MavenArchiver archiver = new MavenArchiver();
+ /**
+ * @todo boolean instead
+ */
+ private String addClasspath;
- archiver.setOutputFile( jarFile );
+ /**
+ * @todo boolean instead
+ */
+ private String addExtensions;
- String ejbJarXmlFile = "META-INF/ejb-jar.xml";
+ /**
+ * @todo boolean instead
+ */
+ private String index;
- archiver.getArchiver().addDirectory( new File( outputDirectory ),
new String[] { "**/**" },
- new String[] { ejbJarXmlFile,
"**/package.html" } );
+ /**
+ * @todo boolean instead
+ */
+ private String compress;
- archiver.getArchiver().addFile( new File( outputDirectory,
ejbJarXmlFile ), ejbJarXmlFile );
+ /**
+ * @todo Add license files in META-INF directory.
+ */
+ public void execute()
+ throws PluginExecutionException
+ {
+ getLog().info( "Building ejb " + jarName );
- // create archive
- archiver.createArchive( request );
+ File jarFile = new File( basedir, jarName + ".jar" );
- if ( generateClient )
- {
- getLog().info( "Building ejb client " + jarName + "-client" );
+ MavenArchiver archiver = new MavenArchiver();
- File clientJarFile = new File( basedir, jarName + "-client.jar"
);
+ archiver.setOutputFile( jarFile );
- MavenArchiver clientArchiver = new MavenArchiver();
+ String ejbJarXmlFile = "META-INF/ejb-jar.xml";
- clientArchiver.setOutputFile( jarFile );
+ try
+ {
+ archiver.getArchiver().addDirectory( new File( outputDirectory
), DEFAULT_INCLUDES,
+ new String[]{ejbJarXmlFile,
"**/package.html"} );
- clientArchiver.getArchiver().addDirectory(
- new File(
outputDirectory ),
- new String[] {
"**/**" },
- new String[] {
- "**/*Bean.class",
- "**/*CMP.class",
-
"**/*Session.class",
- "**/package.html"
} );
+ archiver.getArchiver().addFile( new File( outputDirectory,
ejbJarXmlFile ), ejbJarXmlFile );
// create archive
- clientArchiver.createArchive( request );
+ Manifest configuredManifest = archiver.getManifest( project,
mainClass, packageName,
+
convertBoolean( addClasspath ),
+
convertBoolean( addExtensions ) );
+ archiver.createArchive( project, manifest, convertBoolean(
compress ), convertBoolean( index ),
+ configuredManifest );
+
+ if ( convertBoolean( generateClient ) )
+ {
+ getLog().info( "Building ejb client " + jarName + "-client"
);
+
+ File clientJarFile = new File( basedir, jarName +
"-client.jar" );
+
+ MavenArchiver clientArchiver = new MavenArchiver();
+
+ clientArchiver.setOutputFile( clientJarFile );
+
+ clientArchiver.getArchiver().addDirectory( new File(
outputDirectory ), DEFAULT_INCLUDES,
+ DEFAULT_EXCLUDES
);
+
+ // create archive
+ configuredManifest =
+ clientArchiver.getManifest( project, mainClass,
packageName, convertBoolean( addClasspath ),
+ convertBoolean(
addExtensions ) );
+ clientArchiver.createArchive( project, manifest,
convertBoolean( compress ), convertBoolean( index ),
+ configuredManifest );
+ }
+ }
+ catch ( Exception e )
+ {
+ // TODO: improve error handling
+ throw new PluginExecutionException( "Error assembling EJB", e );
}
}
+
+ private static boolean convertBoolean( String s )
+ {
+ return new Boolean( s ).booleanValue();
+ }
}
\ No newline at end of file