convert archive mojos to new execute(). More work is required to reuse the common fields.

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163659 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-03-22 13:25:58 +00:00
parent f385f562f0
commit 092c2f75cf
6 changed files with 273 additions and 329 deletions

View File

@ -1,6 +1,6 @@
package org.apache.maven.archiver;
/* ====================================================================
/*
* Copyright 2001-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
@ -14,49 +14,40 @@ package org.apache.maven.archiver;
* 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="evenisse@apache.org">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 @@ 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 );

View File

@ -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,15 +175,21 @@ public class EjbMojo
String ejbJarXmlFile = "META-INF/ejb-jar.xml";
archiver.getArchiver().addDirectory( new File( outputDirectory ), new String[] { "**/**" },
new String[] { ejbJarXmlFile, "**/package.html" } );
try
{
archiver.getArchiver().addDirectory( new File( outputDirectory ), DEFAULT_INCLUDES,
new String[]{ejbJarXmlFile, "**/package.html"} );
archiver.getArchiver().addFile( new File( outputDirectory, ejbJarXmlFile ), ejbJarXmlFile );
// 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 );
if ( generateClient )
if ( convertBoolean( generateClient ) )
{
getLog().info( "Building ejb client " + jarName + "-client" );
@ -157,19 +197,28 @@ public class EjbMojo
MavenArchiver clientArchiver = new MavenArchiver();
clientArchiver.setOutputFile( jarFile );
clientArchiver.setOutputFile( clientJarFile );
clientArchiver.getArchiver().addDirectory(
new File( outputDirectory ),
new String[] { "**/**" },
new String[] {
"**/*Bean.class",
"**/*CMP.class",
"**/*Session.class",
"**/package.html" } );
clientArchiver.getArchiver().addDirectory( new File( outputDirectory ), DEFAULT_INCLUDES,
DEFAULT_EXCLUDES );
// create archive
clientArchiver.createArchive( request );
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();
}
}

View File

@ -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 );
}
}

View File

@ -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 );
}
}

View File

@ -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 );
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();
}
}

View File

@ -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();
}
}