diff --git a/maven-archiver/src/main/java/org/apache/maven/archiver/MavenArchiver.java b/maven-archiver/src/main/java/org/apache/maven/archiver/MavenArchiver.java index 0eac629125..7e583bd246 100644 --- a/maven-archiver/src/main/java/org/apache/maven/archiver/MavenArchiver.java +++ b/maven-archiver/src/main/java/org/apache/maven/archiver/MavenArchiver.java @@ -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 element to configuration? * @author Emmanuel Venisse * @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 @@ public class MavenArchiver classpath.append( " " ); } - classpath.append( artifact.getArtifactId() + "-" + artifact.getVersion() + ".jar"); + classpath.append( artifact.getArtifactId() + "-" + artifact.getVersion() + ".jar" ); } } @@ -168,13 +159,13 @@ public class MavenArchiver "-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 @@ public class MavenArchiver 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 ); diff --git a/maven-plugins/maven-ejb-plugin/src/main/java/org/apache/maven/plugin/ejb/EjbMojo.java b/maven-plugins/maven-ejb-plugin/src/main/java/org/apache/maven/plugin/ejb/EjbMojo.java index 8304c62add..89e249474f 100644 --- a/maven-plugins/maven-ejb-plugin/src/main/java/org/apache/maven/plugin/ejb/EjbMojo.java +++ b/maven-plugins/maven-ejb-plugin/src/main/java/org/apache/maven/plugin/ejb/EjbMojo.java @@ -18,8 +18,9 @@ package org.apache.maven.plugin.ejb; 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 @@ import java.io.File; * expression="#maven.ejb.index" * default="false" * description="" - * @parameter name="package" + * @parameter name="packageName" * type="String" * required="false" * validator="" @@ -110,27 +111,60 @@ import java.io.File; 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 File instead + */ + private String basedir; + + private String outputDirectory; + + private String jarName; + + /** + * @todo boolean instead + */ + private String generateClient; + + private MavenProject project; + + 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; + /** * @todo Add license files in META-INF directory. */ - public void execute( PluginExecutionRequest request, PluginExecutionResponse response ) throws Exception + public void execute() + throws PluginExecutionException { - // ---------------------------------------------------------------------- - // - // ---------------------------------------------------------------------- - - File basedir = new File( (String) request.getParameter( "basedir" ) ); - - String outputDirectory = (String) request.getParameter( "outputDirectory" ); - - String jarName = (String) request.getParameter( "jarName" ); - - boolean generateClient = new Boolean( (String) request.getParameter( "generateClient" ) ).booleanValue(); - - // ---------------------------------------------------------------------- - // - // ---------------------------------------------------------------------- - getLog().info( "Building ejb " + jarName ); File jarFile = new File( basedir, jarName + ".jar" ); @@ -141,35 +175,50 @@ public class EjbMojo String ejbJarXmlFile = "META-INF/ejb-jar.xml"; - archiver.getArchiver().addDirectory( new File( outputDirectory ), new String[] { "**/**" }, - new String[] { ejbJarXmlFile, "**/package.html" } ); - - archiver.getArchiver().addFile( new File( outputDirectory, ejbJarXmlFile ), ejbJarXmlFile ); - - // create archive - archiver.createArchive( request ); - - if ( generateClient ) + try { - getLog().info( "Building ejb client " + jarName + "-client" ); + archiver.getArchiver().addDirectory( new File( outputDirectory ), DEFAULT_INCLUDES, + new String[]{ejbJarXmlFile, "**/package.html"} ); - File clientJarFile = new File( basedir, jarName + "-client.jar" ); - - MavenArchiver clientArchiver = new MavenArchiver(); - - clientArchiver.setOutputFile( jarFile ); - - 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 diff --git a/maven-plugins/maven-jar-plugin/src/main/java/org/apache/maven/plugin/jar/JarDeployMojo.java b/maven-plugins/maven-jar-plugin/src/main/java/org/apache/maven/plugin/jar/JarDeployMojo.java deleted file mode 100644 index 28b0eab2a6..0000000000 --- a/maven-plugins/maven-jar-plugin/src/main/java/org/apache/maven/plugin/jar/JarDeployMojo.java +++ /dev/null @@ -1,83 +0,0 @@ -package org.apache.maven.plugin.jar; - -/* - * Copyright 2001-2004 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 - * - * 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. - */ - -import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.DefaultArtifact; -import org.apache.maven.artifact.deployer.ArtifactDeployer; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.model.DistributionManagement; -import org.apache.maven.model.Repository; -import org.apache.maven.plugin.AbstractPlugin; -import org.apache.maven.plugin.PluginExecutionRequest; -import org.apache.maven.plugin.PluginExecutionResponse; -import org.apache.maven.project.MavenProject; - -/** - * @goal deploy - * @description deploys a JAR to remote repository - * @parameter name="project" - * type="org.apache.maven.project.MavenProject" - * required="true" - * validator="" - * expression="#project" - * description="" - * @parameter name="deployer" - * type="org.apache.maven.artifact.deployer.ArtifactDeployer" - * required="true" validator="" - * expression="#component.org.apache.maven.artifact.deployer.ArtifactDeployer" - * description="" - * @parameter - * name="deploymentRepository" - * type="org.apache.maven.artifact.repository.ArtifactRepository" - * required="true" - * validator="" - * expression="#project.distributionManagementArtifactRepository" - * description="" - * - */ -public class JarDeployMojo - extends AbstractPlugin -{ - public void execute( PluginExecutionRequest request, PluginExecutionResponse response ) throws Exception - { - MavenProject project = (MavenProject) request.getParameter( "project" ); - - ArtifactDeployer artifactDeployer = (ArtifactDeployer) request.getParameter( "deployer" ); - - ArtifactRepository deploymentRepository = (ArtifactRepository) request.getParameter( "deploymentRepository" ); - - if ( deploymentRepository == null ) - { - String msg = "Deployment failed: repository element" + " was not specified in the pom inside" - + " distributionManagement element"; - throw new Exception( msg ); - } - - if ( deploymentRepository.getAuthenticationInfo() == null ) - { - getLog().warn( - "Deployment repository {id: \'" + deploymentRepository.getId() - + "\'} has no associated authentication info!" ); - } - - Artifact artifact = new DefaultArtifact( project.getGroupId(), project.getArtifactId(), project.getVersion(), - project.getPackaging() ); - - artifactDeployer.deploy( project.getBuild().getDirectory(), artifact, deploymentRepository ); - } -} \ No newline at end of file diff --git a/maven-plugins/maven-jar-plugin/src/main/java/org/apache/maven/plugin/jar/JarInstallMojo.java b/maven-plugins/maven-jar-plugin/src/main/java/org/apache/maven/plugin/jar/JarInstallMojo.java deleted file mode 100644 index a134f6d359..0000000000 --- a/maven-plugins/maven-jar-plugin/src/main/java/org/apache/maven/plugin/jar/JarInstallMojo.java +++ /dev/null @@ -1,78 +0,0 @@ -package org.apache.maven.plugin.jar; - -/* - * Copyright 2001-2004 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 - * - * 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. - */ - -import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.DefaultArtifact; -import org.apache.maven.artifact.installer.ArtifactInstaller; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.plugin.AbstractPlugin; -import org.apache.maven.plugin.PluginExecutionRequest; -import org.apache.maven.plugin.PluginExecutionResponse; -import org.apache.maven.project.MavenProject; - -/** - * @goal install - * @description installs project's main artifact in local repository - * @parameter name="project" - * type="org.apache.maven.project.MavenProject" - * required="true" - * validator="" - * expression="#project" - * description="" - * @parameter name="installer" - * type="org.apache.maven.artifact.installer.ArtifactInstaller" - * required="true" - * validator="" - * expression="#component.org.apache.maven.artifact.installer.ArtifactInstaller" - * description="" - * @parameter name="localRepository" - * type="org.apache.maven.artifact.repository.ArtifactRepository" - * required="true" - * validator="" - * expression="#localRepository" - * description="" - */ -public class JarInstallMojo - extends AbstractPlugin -{ - public void execute( PluginExecutionRequest request, PluginExecutionResponse response ) - throws Exception - { - MavenProject project = (MavenProject) request.getParameter( "project" ); - - ArtifactInstaller artifactInstaller = (ArtifactInstaller) request.getParameter( "installer" ); - - ArtifactRepository localRepository = (ArtifactRepository) request.getParameter( "localRepository" ); - - Artifact artifact = new DefaultArtifact( project.getGroupId(), project.getArtifactId(), project.getVersion(), - project.getPackaging() ); - - artifactInstaller.install( project.getBuild().getDirectory(), artifact, localRepository ); - - // ---------------------------------------------------------------------- - // This is not the way to do this, but in order to get the integration - // tests working this is what I'm doing. jvz. - // ---------------------------------------------------------------------- - - Artifact pomArtifact = new DefaultArtifact( project.getGroupId(), project.getArtifactId(), - project.getVersion(), "pom" ); - - artifactInstaller.install( project.getFile(), pomArtifact, localRepository ); - - } -} diff --git a/maven-plugins/maven-jar-plugin/src/main/java/org/apache/maven/plugin/jar/JarMojo.java b/maven-plugins/maven-jar-plugin/src/main/java/org/apache/maven/plugin/jar/JarMojo.java index fd63a721cf..0a17337294 100644 --- a/maven-plugins/maven-jar-plugin/src/main/java/org/apache/maven/plugin/jar/JarMojo.java +++ b/maven-plugins/maven-jar-plugin/src/main/java/org/apache/maven/plugin/jar/JarMojo.java @@ -18,8 +18,9 @@ package org.apache.maven.plugin.jar; 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 @@ import java.io.File; * expression="#maven.jar.index" * default="false" * description="" - * @parameter name="package" + * @parameter name="packageName" * type="String" * required="false" * validator="" @@ -103,36 +104,79 @@ import java.io.File; public class JarMojo extends AbstractPlugin { + /** + * @todo File + */ + 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[]{"**/**"}; + + private MavenProject project; + + private String manifest; + + private String mainClass; + + private String packageName; + + /** + * @todo boolean instead + */ + private String addClasspath; + + /** + * @todo boolean instead + */ + private String addExtensions; + + /** + * @todo boolean instead + */ + private String index; + + /** + * @todo boolean instead + */ + private String compress; + /** * @todo Add license files in META-INF directory. */ - public void execute( PluginExecutionRequest request, PluginExecutionResponse response ) - throws Exception + public void execute() + throws PluginExecutionException { - // ---------------------------------------------------------------------- - // - // ---------------------------------------------------------------------- - - File basedir = new File( (String) request.getParameter( "basedir" ) ); - - String outputDirectory = (String) request.getParameter( "outputDirectory" ); - - String jarName = (String) request.getParameter( "jarName" ); - - // ---------------------------------------------------------------------- - // - // ---------------------------------------------------------------------- - 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 - archiver.createArchive( request ); + // 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 ); + } + } + + private static boolean convertBoolean( String s ) + { + return Boolean.valueOf( s ).booleanValue(); } } diff --git a/maven-plugins/maven-war-plugin/src/main/java/org/apache/maven/plugin/war/WarMojo.java b/maven-plugins/maven-war-plugin/src/main/java/org/apache/maven/plugin/war/WarMojo.java index 975a5fbe5b..6a7589ba26 100644 --- a/maven-plugins/maven-war-plugin/src/main/java/org/apache/maven/plugin/war/WarMojo.java +++ b/maven-plugins/maven-war-plugin/src/main/java/org/apache/maven/plugin/war/WarMojo.java @@ -19,9 +19,11 @@ package org.apache.maven.plugin.war; 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 @@ import java.util.Set; * expression="#maven.jar.index" * default="false" * description="" - * @parameter name="package" + * @parameter name="packageName" * type="String" * required="false" * validator="" @@ -144,21 +146,34 @@ import java.util.Set; public class WarMojo extends AbstractPlugin { - public static final String WEB_INF = "WEB-INF"; + private static final String[] DEFAULT_INCLUDES = new String[]{"**/**"}; - private PluginExecutionRequest request; + private static final String[] DEFAULT_EXCLUDES = new String[]{"**/WEB-INF/web.xml"}; + + 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 @@ public class WarMojo 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 @@ public class WarMojo { 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 class WarMojo 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 @@ public class WarMojo 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 class WarMojo 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 @@ public class WarMojo generateExplodedWebapp(); } - public void execute( PluginExecutionRequest request, PluginExecutionResponse response ) - throws Exception + public void execute() + throws PluginExecutionException { - // ---------------------------------------------------------------------- - // - // ---------------------------------------------------------------------- + File warFile = new File( outputDirectory, warName + ".war" ); - parseRequest( request ); - - // ---------------------------------------------------------------------- - // - // ---------------------------------------------------------------------- + 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 @@ public class WarMojo 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(); } }