maven-m2-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject cvs commit: maven-components/maven-mboot2/src/main/java MBoot.java
Date Thu, 17 Mar 2005 23:59:07 GMT
brett       2005/03/17 15:59:07

  Modified:    maven-plugins/maven-assemble-plugin/src/main/java/org/apache/maven/plugin/assemble
                        AssembleMojo.java
               maven-plugins/maven-assemble-plugin pom.xml
               maven-mboot2/src/main/java MBoot.java
  Log:
  flesh out assemble mojo
  
  Revision  Changes    Path
  1.2       +44 -24    maven-components/maven-plugins/maven-assemble-plugin/src/main/java/org/apache/maven/plugin/assemble/AssembleMojo.java
  
  Index: AssembleMojo.java
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-plugins/maven-assemble-plugin/src/main/java/org/apache/maven/plugin/assemble/AssembleMojo.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AssembleMojo.java	13 Mar 2005 01:37:59 -0000	1.1
  +++ AssembleMojo.java	17 Mar 2005 23:59:06 -0000	1.2
  @@ -22,25 +22,18 @@
   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,41 +41,68 @@
   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 directory = fileset.getDirectory();
  -            String output = fileset.getOutputDirectory();
  -            if ( output == null )
  +            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
               {
  -                output = directory;
  +                // TODO: better handling
  +                throw new IllegalArgumentException( "Unknown format: " + format );
               }
   
  -            // TODO: includes/excludes
  +            for ( Iterator j = assembly.getFilesets().iterator(); j.hasNext(); )
  +            {
  +                FileSet fileset = (FileSet) j.next();
  +                String directory = fileset.getDirectory();
  +                String output = fileset.getOutputDirectory();
  +                if ( output == null )
  +                {
  +                    output = directory;
  +                }
  +
  +                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
);
  +            }
   
  -            FileUtils.copyDirectoryStructure( new File( directory ), new File( outputBase,
output ));
  +            archiver.setDestFile( new File( outputDirectory, filename ) );
  +            archiver.createArchive();
           }
  -
  -        // TODO: package it up
       }
   }
  
  
  
  1.4       +7 -6      maven-components/maven-plugins/maven-assemble-plugin/pom.xml
  
  Index: pom.xml
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-plugins/maven-assemble-plugin/pom.xml,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- pom.xml	15 Mar 2005 22:31:54 -0000	1.3
  +++ pom.xml	17 Mar 2005 23:59:06 -0000	1.4
  @@ -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>
  
  
  
  1.71      +44 -44    maven-components/maven-mboot2/src/main/java/MBoot.java
  
  Index: MBoot.java
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-mboot2/src/main/java/MBoot.java,v
  retrieving revision 1.70
  retrieving revision 1.71
  diff -u -r1.70 -r1.71
  --- MBoot.java	17 Mar 2005 20:20:49 -0000	1.70
  +++ MBoot.java	17 Mar 2005 23:59:07 -0000	1.71
  @@ -65,28 +65,25 @@
       // ----------------------------------------------------------------------
   
       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 @@
           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 @@
   
               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 @@
   
               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 @@
               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 @@
               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 @@
               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() );
  @@ -878,9 +879,9 @@
           excludes = new ArrayList();
   
           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 @@
               {
                   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 @@
                   }
                   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 @@
               }
               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 @@
                       for ( Iterator it = proxies.iterator(); it.hasNext(); )
                       {
                           Proxy proxy = (Proxy) it.next();
  -                        if( proxy.isActive() )
  +                        if ( proxy.isActive() )
                           {
                               activeProxy = proxy;
                           }
  
  
  

Mime
View raw message