flesh out assemble mojo

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163603 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-03-17 23:59:07 +00:00
parent a436d8a8b6
commit 99b5fe6d9f
3 changed files with 94 additions and 73 deletions

View File

@ -65,28 +65,25 @@ public class MBoot
// ----------------------------------------------------------------------
String[] modelloDeps = new String[]{"classworlds/jars/classworlds-1.1-alpha-1.jar",
//"plexus/jars/plexus-container-api-1.0-alpha-1-SNAPSHOT.jar",
"plexus/jars/plexus-container-default-1.0-alpha-2-SNAPSHOT.jar",
//"plexus/jars/plexus-utils-1.0-alpha-1-SNAPSHOT.jar",
"modello/jars/modello-core-1.0-SNAPSHOT.jar",
"modello/jars/modello-xdoc-plugin-1.0-SNAPSHOT.jar",
"modello/jars/modello-xml-plugin-1.0-SNAPSHOT.jar",
"modello/jars/modello-xpp3-plugin-1.0-SNAPSHOT.jar"};
String[] builds = new String[]{"maven-model", "maven-settings", "maven-monitor", "maven-plugin",
"maven-artifact", "maven-script/maven-script-marmalade", "maven-core",
"maven-archiver", "maven-plugin-tools/maven-plugin-tools-api",
String[] builds = new String[]{"maven-model", "maven-settings", "maven-monitor", "maven-plugin", "maven-artifact",
"maven-script/maven-script-marmalade", "maven-core", "maven-archiver",
"maven-plugin-tools/maven-plugin-tools-api",
"maven-plugin-tools/maven-plugin-tools-java",
"maven-plugin-tools/maven-plugin-tools-pluggy",
"maven-plugin-tools/maven-plugin-tools-marmalade",
"maven-core-it-verifier"};
"maven-plugin-tools/maven-plugin-tools-marmalade", "maven-core-it-verifier"};
String[] pluginBuilds = new String[]{"maven-plugins/maven-clean-plugin", "maven-plugins/maven-compiler-plugin",
"maven-plugins/maven-deploy-plugin", "maven-plugins/maven-ejb-plugin",
"maven-plugins/maven-install-plugin", "maven-plugins/maven-jar-plugin",
"maven-plugins/maven-plugin-plugin", "maven-plugins/maven-pom-plugin",
"maven-plugins/maven-resources-plugin", "maven-plugins/maven-surefire-plugin",
"maven-plugins/maven-war-plugin"};
String[] pluginBuilds = new String[]{"maven-plugins/maven-assemble-plugin", "maven-plugins/maven-clean-plugin",
"maven-plugins/maven-compiler-plugin", "maven-plugins/maven-deploy-plugin",
"maven-plugins/maven-ejb-plugin", "maven-plugins/maven-install-plugin",
"maven-plugins/maven-jar-plugin", "maven-plugins/maven-plugin-plugin",
"maven-plugins/maven-pom-plugin", "maven-plugins/maven-resources-plugin",
"maven-plugins/maven-surefire-plugin", "maven-plugins/maven-war-plugin"};
private static final Map MODELLO_TARGET_VERSIONS;
@ -97,12 +94,14 @@ public class MBoot
Map targetVersions = new TreeMap();
targetVersions.put( "maven-model", "4.0.0" );
targetVersions.put( "maven-settings", "1.0.0" );
targetVersions.put( "maven-plugins/maven-assemble-plugin", "1.0.0" );
MODELLO_TARGET_VERSIONS = Collections.unmodifiableMap( targetVersions );
Map modelFiles = new TreeMap();
modelFiles.put( "maven-model", "maven.mdo" );
modelFiles.put( "maven-settings", "settings.mdo" );
modelFiles.put( "maven-plugins/maven-assemble-plugin", "src/main/mdo/descriptor.mdo" );
MODELLO_MODEL_FILES = Collections.unmodifiableMap( modelFiles );
}
@ -222,13 +221,18 @@ public class MBoot
mavenRepoLocal = repoDir.getAbsolutePath();
System.out.println( "You SHOULD have a ~/.m2/settings.xml file and must contain at least the following information:\n" );
System.out.println(
"You SHOULD have a ~/.m2/settings.xml file and must contain at least the following information:" );
System.out.println();
System.out.println( "<settings>\n" + " <profiles>\n" + " <profile>\n"
+ " <active>true</active>\n"
+ " <localRepository>/path/to/your/repository</localRepository>\n"
+ " </profile>\n" + " </profiles>\n"
+ "</settings>\n" );
System.out.println( "<settings>" );
System.out.println( " <profiles>" );
System.out.println( " <profile>" );
System.out.println( " <active>true</active>" );
System.out.println( " <localRepository>/path/to/your/repository</localRepository>" );
System.out.println( " </profile>" );
System.out.println( " </profiles>" );
System.out.println( "</settings>" );
System.out.println();
@ -236,8 +240,8 @@ public class MBoot
System.out.println();
System.out.println( "HOWEVER, since you did not specify a repository path, maven will use: "
+ repoDir.getAbsolutePath() + " to store artifacts locally." );
System.out.println( "HOWEVER, since you did not specify a repository path, maven will use: " +
repoDir.getAbsolutePath() + " to store artifacts locally." );
}
String mavenHome = null;
@ -680,10 +684,9 @@ public class MBoot
File f = new File( repoLocal, dependency );
if ( !f.exists() )
{
throw new FileNotFoundException( "Missing dependency: " + dependency +
( !online
? "; run again online"
: "; there was a problem downloading it earlier" ) );
throw new FileNotFoundException(
"Missing dependency: " + dependency +
( !online ? "; run again online" : "; there was a problem downloading it earlier" ) );
}
cl.addURL( f.toURL() );
@ -700,10 +703,9 @@ public class MBoot
File f = new File( repoLocal, dependency );
if ( !f.exists() )
{
throw new FileNotFoundException( "Missing dependency: " + dependency +
( !online
? "; run again online"
: "; there was a problem downloading it earlier" ) );
throw new FileNotFoundException(
"Missing dependency: " + dependency +
( !online ? "; run again online" : "; there was a problem downloading it earlier" ) );
}
cl.addURL( f.toURL() );
@ -735,10 +737,9 @@ public class MBoot
File f = new File( repoLocal, dependency );
if ( !f.exists() )
{
throw new FileNotFoundException( "Missing dependency: " + dependency +
( !online
? "; run again online"
: "; there was a problem downloading it earlier" ) );
throw new FileNotFoundException(
"Missing dependency: " + dependency +
( !online ? "; run again online" : "; there was a problem downloading it earlier" ) );
}
modelloClassLoader.addURL( f.toURL() );
@ -879,7 +880,7 @@ public class MBoot
excludes.add( "**/*Abstract*.java" );
String reportsDir = new File(basedir, "target/test-reports").getAbsolutePath();
String reportsDir = new File( basedir, "target/test-reports" ).getAbsolutePath();
boolean success = testRunner.execute( repoLocal, basedir, classes, testClasses, includes, excludes,
classpath( reader.getDependencies(), null ), reportsDir );
@ -1387,7 +1388,7 @@ public class MBoot
{
if ( "active".equals( rawName ) )
{
currentProfile.setActive( Boolean.valueOf(currentBody.toString().trim()).booleanValue() );
currentProfile.setActive( Boolean.valueOf( currentBody.toString().trim() ).booleanValue() );
}
else if ( "localRepository".equals( rawName ) )
{
@ -1407,15 +1408,14 @@ public class MBoot
}
else
{
throw new SAXException( "Invalid proxy entry. Missing one or more " +
"fields: {host, port}." );
throw new SAXException( "Invalid proxy entry. Missing one or more " + "fields: {host, port}." );
}
}
else if ( currentProxy != null )
{
if ( "active".equals( rawName ) )
{
currentProxy.setActive( Boolean.valueOf(currentBody.toString().trim()).booleanValue() );
currentProxy.setActive( Boolean.valueOf( currentBody.toString().trim() ).booleanValue() );
}
else if ( "host".equals( rawName ) )
{
@ -1446,16 +1446,16 @@ public class MBoot
}
else if ( "settings".equals( rawName ) )
{
if( profiles.size() == 1 )
if ( profiles.size() == 1 )
{
activeProfile = (Profile) profiles.get(0);
activeProfile = (Profile) profiles.get( 0 );
}
else
{
for ( Iterator it = profiles.iterator(); it.hasNext(); )
{
Profile profile = (Profile) it.next();
if( profile.isActive() )
if ( profile.isActive() )
{
activeProfile = profile;
}
@ -1466,7 +1466,7 @@ public class MBoot
for ( Iterator it = proxies.iterator(); it.hasNext(); )
{
Proxy proxy = (Proxy) it.next();
if( proxy.isActive() )
if ( proxy.isActive() )
{
activeProxy = proxy;
}

View File

@ -1,4 +1,4 @@
<model>
<project>
<parent>
<artifactId>maven-plugin-parent</artifactId>
<groupId>maven</groupId>
@ -15,15 +15,16 @@
<groupId>maven</groupId>
<artifactId>maven-core</artifactId>
<version>2.0-SNAPSHOT</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>maven</groupId>
<artifactId>maven-model</artifactId>
<version>2.0-SNAPSHOT</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>plexus</groupId>
<artifactId>plexus-archiver</artifactId>
<version>1.0-alpha-1-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
@ -49,4 +50,4 @@
</plugin>
</plugins>
</build>
</model>
</project>

View File

@ -22,25 +22,18 @@ import org.apache.maven.plugin.PluginExecutionResponse;
import org.apache.maven.plugins.assemble.model.Assembly;
import org.apache.maven.plugins.assemble.model.FileSet;
import org.apache.maven.plugins.assemble.model.io.xpp3.AssemblyXpp3Reader;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.archiver.Archiver;
import org.codehaus.plexus.archiver.tar.TarArchiver;
import java.io.File;
import java.io.FileReader;
import java.util.Iterator;
import java.util.List;
/**
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
* @version $Id$
* @goal assemble
* @description assemble an application bundle or distribution
* @parameter name="buildDirectory"
* type="String"
* required="true"
* validator=""
* expression="#project.build.directory/assembly"
* description=""
* @parameter name="outputDirectory" type="String" required="true" validator="" expression="#project.build.directory" description=""
* @parameter name="descriptor" type="String" required="true" validator="" expression="#maven.assemble.descriptor" description=""
* @parameter name="finalName" type="String" required="true" validator="" expression="#project.build.finalName" description=""
@ -48,29 +41,54 @@ import java.util.List;
public class AssembleMojo
extends AbstractPlugin
{
private static final String[] EMPTY_STRING_ARRAY = {};
public void execute( PluginExecutionRequest request, PluginExecutionResponse response )
throws Exception
{
// TODO: align all to basedir
String outputDirectory = (String) request.getParameter( "outputDirectory" );
String buildDirectory = (String) request.getParameter( "buildDirectory" );
String descriptor = (String) request.getParameter( "descriptor" );
String finalName = (String) request.getParameter( "finalName" );
AssemblyXpp3Reader reader = new AssemblyXpp3Reader();
Assembly assembly = reader.read( new FileReader( new File( descriptor ) ) );
// TODO: include in bootstrap
// TODO: include dependencies marked for distribution under certain formats
// TODO: have a default set of descriptors that can be used instead of the file
String fullName = finalName + "-" + assembly.getId();
File outputBase = new File( buildDirectory, fullName );
outputBase.mkdirs();
for ( Iterator i = assembly.getFilesets().iterator(); i.hasNext(); )
for ( Iterator i = assembly.getFormats().iterator(); i.hasNext(); )
{
FileSet fileset = (FileSet) i.next();
String format = (String) i.next();
String filename = fullName + "." + format;
// TODO: use component roles? Can we do that in a mojo?
Archiver archiver;
if ( format.startsWith( "tar" ) )
{
TarArchiver tarArchiver = new TarArchiver();
archiver = tarArchiver;
int index = format.indexOf( '.' );
if ( index >= 0 )
{
// TODO: this needs a cleanup in plexus archiver - use a real typesafe enum
TarArchiver.TarCompressionMethod tarCompressionMethod = new TarArchiver.TarCompressionMethod();
tarCompressionMethod.setValue( format.substring( index + 1 ) );
tarArchiver.setCompression( tarCompressionMethod );
}
}
else
{
// TODO: better handling
throw new IllegalArgumentException( "Unknown format: " + format );
}
for ( Iterator j = assembly.getFilesets().iterator(); j.hasNext(); )
{
FileSet fileset = (FileSet) j.next();
String directory = fileset.getDirectory();
String output = fileset.getOutputDirectory();
if ( output == null )
@ -78,11 +96,13 @@ public class AssembleMojo
output = directory;
}
// TODO: includes/excludes
FileUtils.copyDirectoryStructure( new File( directory ), new File( outputBase, output ));
String[] includes = (String[]) fileset.getIncludes().toArray( EMPTY_STRING_ARRAY );
String[] excludes = (String[]) fileset.getExcludes().toArray( EMPTY_STRING_ARRAY );
archiver.addDirectory( new File( directory ), output, includes, excludes );
}
// TODO: package it up
archiver.setDestFile( new File( outputDirectory, filename ) );
archiver.createArchive();
}
}
}