maven-m2-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eveni...@apache.org
Subject cvs commit: maven-components/maven-archiver/src/main/java/org/apache/maven/archiver MavenArchiver.java
Date Sat, 05 Mar 2005 14:52:12 GMT
evenisse    2005/03/05 06:52:12

  Modified:    maven-mboot2/src/main/java MBoot.java
               maven-plugins/maven-jar-plugin pom.xml
               maven-plugins/maven-jar-plugin/src/main/java/org/apache/maven/plugin/jar
                        JarMojo.java
               maven-plugins/maven-war-plugin pom.xml
               maven-plugins/maven-war-plugin/src/main/java/org/apache/maven/plugin/war
                        WarMojo.java
               maven-plugins pom.xml
  Added:       maven-archiver .cvsignore pom.xml
               maven-archiver/src/main/java/org/apache/maven/archiver
                        MavenArchiver.java
  Log:
  - Externalize archiver methods
  - Update JarMojo
  - Implements WarMojo (Not tested yet)
  
  Revision  Changes    Path
  1.56      +2 -1      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.55
  retrieving revision 1.56
  diff -u -r1.55 -r1.56
  --- MBoot.java	4 Mar 2005 09:04:14 -0000	1.55
  +++ MBoot.java	5 Mar 2005 14:52:11 -0000	1.56
  @@ -40,7 +40,7 @@
           "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",
  -        "plexus/jars/plexus-utils-1.0-alpha-1-SNAPSHOT.jar",
  +        "plexus/jars/plexus-utils-1.0-alpha-2-SNAPSHOT.jar",
           "surefire/jars/surefire-booter-1.2-SNAPSHOT.jar",
           "surefire/jars/surefire-1.2-SNAPSHOT.jar",
           "qdox/jars/qdox-1.2.jar" };
  @@ -83,6 +83,7 @@
           "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",
  
  
  
  1.10      +5 -0      maven-components/maven-plugins/maven-jar-plugin/pom.xml
  
  Index: pom.xml
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-plugins/maven-jar-plugin/pom.xml,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- pom.xml	27 Feb 2005 17:45:41 -0000	1.9
  +++ pom.xml	5 Mar 2005 14:52:11 -0000	1.10
  @@ -26,6 +26,11 @@
       </dependency>
       <dependency>
         <groupId>maven</groupId>
  +      <artifactId>maven-archiver</artifactId>
  +      <version>1.0-SNAPSHOT</version>
  +    </dependency>
  +    <dependency>
  +      <groupId>maven</groupId>
         <artifactId>maven-artifact</artifactId>
         <version>2.0-SNAPSHOT</version>
       </dependency>
  
  
  
  1.15      +8 -28     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.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- JarMojo.java	27 Feb 2005 23:58:41 -0000	1.14
  +++ JarMojo.java	5 Mar 2005 14:52:11 -0000	1.15
  @@ -16,10 +16,10 @@
    * limitations under the License.
    */
   
  +import org.apache.maven.archiver.MavenArchiver;
   import org.apache.maven.plugin.PluginExecutionRequest;
   import org.apache.maven.plugin.PluginExecutionResponse;
   import org.apache.maven.project.MavenProject;
  -import org.codehaus.plexus.archiver.jar.JarArchiver;
   
   import java.io.File;
   
  @@ -120,45 +120,25 @@
           //
           // ----------------------------------------------------------------------
   
  -        MavenProject project = (MavenProject)request.getParameter("project");
  -
  -        String manifest = (String) request.getParameter( "manifest" );
  -
           File basedir = new File( (String) request.getParameter( "basedir" ) );
   
           String outputDirectory = (String) request.getParameter( "outputDirectory" );
   
           String jarName = (String) request.getParameter( "jarName" );
   
  -        boolean compress = new Boolean( (String) request.getParameter( "compress" ) ).booleanValue();
  -
  -        boolean index = new Boolean( (String) request.getParameter( "index" ) ).booleanValue();
  -
           // ----------------------------------------------------------------------
           //
           // ----------------------------------------------------------------------
   
  -
           File jarFile = new File( basedir, jarName + ".jar" );
   
  -        JarArchiver archiver = new JarArchiver();
  -        archiver.addDirectory( new File( outputDirectory ), new String[] { "**/**" }, new
String[] { "**/package.html" } );
  -        archiver.addFile( project.getFile(), "META-INF/maven/pom.xml" );
  -
  -        if (manifest != null && ! "".equals( manifest ) )
  -        {
  -            File manifestFile = new File( manifest );
  -            archiver.setManifest( manifestFile );
  -        }
  -
  -        // Configure the jar
  -        archiver.addConfiguredManifest( getManifest( request ) );
  -
  -        archiver.setCompress( compress );
  -        archiver.setIndex( index );
  -        archiver.setDestFile( jarFile );
  +        MavenArchiver archiver = new MavenArchiver();
  +
  +        archiver.setOutputFile( jarFile );
  +
  +        archiver.getArchiver().addDirectory( new File( outputDirectory ), new String[]
{ "**/**" }, new String[] { "**/package.html" } );
   
           // create archive
  -        archiver.createArchive();
  +        archiver.createArchive( request );
       }
   }
  
  
  
  1.3       +10 -6     maven-components/maven-plugins/maven-war-plugin/pom.xml
  
  Index: pom.xml
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-plugins/maven-war-plugin/pom.xml,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- pom.xml	4 Mar 2005 09:04:26 -0000	1.2
  +++ pom.xml	5 Mar 2005 14:52:11 -0000	1.3
  @@ -20,12 +20,6 @@
         <version>2.0-SNAPSHOT</version>
       </dependency>
       <dependency>
  -      <groupId>maven</groupId>
  -      <artifactId>maven-jar-plugin</artifactId>
  -      <version>1.0-SNAPSHOT</version>
  -      <type>plugin</type>
  -    </dependency>
  -    <dependency>
         <groupId>plexus</groupId>
         <artifactId>plexus-container-default</artifactId>
         <version>1.0-alpha-2-SNAPSHOT</version>
  @@ -37,6 +31,11 @@
       </dependency>
       <dependency>
         <groupId>maven</groupId>
  +      <artifactId>maven-archiver</artifactId>
  +      <version>1.0-SNAPSHOT</version>
  +    </dependency>
  +    <dependency>
  +      <groupId>maven</groupId>
         <artifactId>maven-artifact</artifactId>
         <version>2.0-SNAPSHOT</version>
       </dependency>
  @@ -50,5 +49,10 @@
         <artifactId>maven-model</artifactId>
         <version>2.0-SNAPSHOT</version>
       </dependency>
  +    <dependency>
  +      <groupId>maven</groupId>
  +      <artifactId>wagon-api</artifactId>
  +      <version>1.0-alpha-1-SNAPSHOT</version>
  +    </dependency>
     </dependencies>
   </project>
  
  
  
  1.3       +213 -13   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.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- WarMojo.java	4 Mar 2005 09:04:14 -0000	1.2
  +++ WarMojo.java	5 Mar 2005 14:52:11 -0000	1.3
  @@ -16,19 +16,30 @@
    * limitations under the License.
    */
   
  +import java.io.IOException;
  +import java.io.File;
  +import java.util.Iterator;
  +import java.util.Set;
  +
  +import org.apache.maven.archiver.MavenArchiver;
  +import org.apache.maven.artifact.Artifact;
  +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;
   
  +import org.codehaus.plexus.archiver.war.WarArchiver;
  +import org.codehaus.plexus.util.FileUtils;
  +
   /**
    * @goal war
    * @phase package
    *
  - * @description build a jar
  + * @description build a war/webapp
    *
    * @parameter
  - *  name="jarName"
  + *  name="warName"
    *  type="String"
    *  required="true"
    *  validator=""
  @@ -58,34 +69,66 @@
    *  expression="#maven.jar.manifest"
    *  description=""
    * @parameter
  - *  name="mainClass"
  + *  name="addExtensions"
    *  type="String"
    *  required="false"
    *  validator=""
  - *  expression="#maven.jar.mainClass"
  + *  expression="#maven.jar.addExtensions"
  + *  default="false"
  + *  description=""
  + * @parameter
  + *  name="warSourceDirectory"
  + *  type="String"
  + *  required="true"
  + *  validator=""
  + *  expression="#maven.war.src"
  + *  default="#basedir/src/webapp"
    *  description=""
    * @parameter
  - *  name="addClasspath"
  + *  name="warSourceIncludes"
    *  type="String"
    *  required="false"
    *  validator=""
  - *  expression="#maven.jar.addClasspath"
  - *  default="false"
  + *  expression="#maven.war.src.includes"
  + *  default="**"
    *  description=""
    * @parameter
  - *  name="addExtensions"
  + *  name="warSourceIncludes"
    *  type="String"
    *  required="false"
    *  validator=""
  - *  expression="#maven.jar.addExtensions"
  - *  default="false"
  + *  expression="#maven.war.src.excludes"
  + *  description=""
  + * @parameter
  + *  name="webXml"
  + *  type="String"
  + *  required="false"
  + *  validator=""
  + *  expression="#maven.war.webxml"
  + *  description=""
  + * @parameter
  + *  name="webappDirectory"
  + *  type="String"
  + *  required="true"
  + *  validator=""
  + *  expression="#maven.war.webapp.dir"
  + *  default="#project.build.output/#project.build.finalName"
  + *  description=""
  + * @parameter
  + *  name="mode"
  + *  type="String"
  + *  required="true"
  + *  validator=""
  + *  expression="#maven.war.mode"
  + *  default="war"
    *  description=""
    * @parameter
    *  name="outputDirectory"
    *  type="String"
    *  required="true"
    *  validator=""
  - *  expression="#project.build.output"
  + *  expression="#maven.war.build.dir"
  + *  default="#project.build.output"
    *  description=""
    * @parameter
    *  name="basedir"
  @@ -94,6 +137,12 @@
    *  validator=""
    *  expression="#project.build.directory"
    *  description=""
  + * @parameter name="localRepository"
  + *  type="org.apache.maven.artifact.repository.ArtifactRepository"
  + *  required="true"
  + *  validator=""
  + *  expression="#localRepository"
  + *  description=""
    * @parameter
    *  name="project"
    *  type="org.apache.maven.project.MavenProject"
  @@ -108,13 +157,164 @@
   public class WarMojo
       extends AbstractPlugin
   {
  +    public static final String WEB_INF = "WEB_INF";
  +
  +    private PluginExecutionRequest request;
  +
  +    private String mode;
  +
  +    private MavenProject project;
  +
  +    private ArtifactRepository localRepository;
  +
  +    private String outputDirectory;
  +
  +    private File webappDirectory;
  +
  +    private File warSourceDirectory;
  +
  +    private String warSourceIncludes;
  +
  +    private String warSourceExcludes;
  +
  +    private String webXml;
  +
  +    private File warFile;
  +
  +    public void copyResources( File sourceDirectory, File webappDirectory, String includes,
String excludes, String webXml )
  +        throws IOException
  +    {
  +        if ( sourceDirectory != webappDirectory )
  +        {
  +            request.getLog().info( "Copy webapp resources to " + webappDirectory.getAbsolutePath()
);
  +
  +            if ( warSourceDirectory.exists() )
  +            {
  +                FileUtils.copyDirectory( sourceDirectory, webappDirectory, includes, excludes
);
  +            }
  +
  +            if ( webXml != null && ! "".equals( webXml ) )
  +            {
  +                FileUtils.copyFileToDirectory( new File( webXml ), new File( webappDirectory,
WEB_INF ) );
  +            }
  +        }
  +    }
  +
  +    /**
  +     * @todo properties 'war.bundle' and 'war.target.path'
  +     * @todo copy classes to classes webapp directory
  +     */
  +    public void buildWebapp( MavenProject project )
  +        throws IOException
  +    {
  +        request.getLog().info( "Assembling webapp " + project.getArtifactId() );
  +
  +        File libDirectory = new File( webappDirectory, WEB_INF + "/lib" );
  +
  +        File tldDirectory = new File( webappDirectory, WEB_INF + "/tld" );
  +
  +        File classesDirectory = new File( webappDirectory, WEB_INF + "/classes" );
  +
  +        Set artifacts = project.getArtifacts();
  +
  +        for ( Iterator iter = artifacts.iterator(); iter.hasNext(); )
  +        {
  +            Artifact artifact = (Artifact) iter.next();
  +            if ( "jar".equals( artifact.getType() ) )
  +            {
  +                FileUtils.copyFileToDirectory( new File( localRepository.getBasedir(),
artifact.toString() ) , libDirectory );
  +            }
  +            if ( "tld".equals( artifact.getType() ) )
  +            {
  +                FileUtils.copyFileToDirectory( new File( localRepository.getBasedir(),
artifact.toString() ) , tldDirectory );
  +            }
  +        }
  +    }
  +
  +    public void generateExplodedWebapp()
  +        throws IOException
  +    {
  +        webappDirectory.mkdirs();
  +
  +        File webinfDir = new File( webappDirectory, WEB_INF );
  +
  +        webinfDir.mkdirs();
  +
  +        copyResources( warSourceDirectory, webappDirectory, warSourceIncludes, warSourceExcludes,
webXml );
  +
  +        //buildWebapp( project );
  +    }
  +
  +    public void generateInPlaceWebapp()
  +        throws IOException
  +    {
  +        webappDirectory = warSourceDirectory;
  +
  +        generateExplodedWebapp();
  +    }
  +
       public void execute( PluginExecutionRequest request, PluginExecutionResponse response
)
           throws Exception
       {
           // ----------------------------------------------------------------------
           //
           // ----------------------------------------------------------------------
  -        request.getLog().info("war");
   
  +        parseRequest( request );
  +
  +        // ----------------------------------------------------------------------
  +        //
  +        // ----------------------------------------------------------------------
  +
  +        if ( "inplace".equals( mode ) )
  +        {
  +            generateInPlaceWebapp();
  +        }
  +        else
  +        {
  +            generateExplodedWebapp();
  +
  +            if ( ! "exploded".equals( mode ) )
  +            {
  +                //generate war file
  +                request.getLog().info( "Generating war " + warFile.getAbsolutePath() );
  +
  +                MavenArchiver archiver = new MavenArchiver();
  +
  +                //archiver.setArchiver( new WarArchiver() );
  +
  +                archiver.setOutputFile( warFile );
  +
  +                archiver.getArchiver().addDirectory( webappDirectory, new String[] { "**/**"
}, null );
  +
  +                // create archive
  +                archiver.createArchive( request );
  +            }
  +        }
  +    }
  +
  +    public void parseRequest( PluginExecutionRequest request )
  +    {
  +        this.request = request;
  +
  +        project = (MavenProject) request.getParameter( "project" );
  +
  +        localRepository = (ArtifactRepository) request.getParameter( "localRepository"
);
  +
  +        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" );
       }
   }
  
  
  
  1.15      +1 -1      maven-components/maven-plugins/pom.xml
  
  Index: pom.xml
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-plugins/pom.xml,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- pom.xml	4 Mar 2005 09:04:20 -0000	1.14
  +++ pom.xml	5 Mar 2005 14:52:11 -0000	1.15
  @@ -58,7 +58,7 @@
       <dependency>
         <groupId>plexus</groupId>
         <artifactId>plexus-utils</artifactId>
  -      <version>1.0-alpha-1-SNAPSHOT</version>
  +      <version>1.0-alpha-2-SNAPSHOT</version>
       </dependency>    
     </dependencies>
   </project>
  
  
  
  1.1                  maven-components/maven-archiver/.cvsignore
  
  Index: .cvsignore
  ===================================================================
  *~
  *.log
  target
  dist
  *.ipr
  *.iws
  *.iml
  dist
  target
  .classpath
  .project
  build.xml
  
  
  
  1.1                  maven-components/maven-archiver/pom.xml
  
  Index: pom.xml
  ===================================================================
  <project>
    <modelVersion>4.0.0</modelVersion>
    <parent>
      <groupId>maven</groupId>
      <artifactId>maven-component</artifactId>
      <version>2.0-SNAPSHOT</version>
    </parent>
    <groupId>maven</groupId>
    <artifactId>maven-archiver</artifactId>
    <version>1.0-SNAPSHOT</version>
    <dependencies>
      <dependency>
        <groupId>maven</groupId>
        <artifactId>maven-monitor</artifactId>
        <version>2.0-SNAPSHOT</version>
      </dependency>
      <dependency>
        <groupId>plexus</groupId>
        <artifactId>plexus-container-default</artifactId>
        <version>1.0-alpha-2-SNAPSHOT</version>
      </dependency>
      <dependency>
        <groupId>plexus</groupId>
        <artifactId>plexus-archiver</artifactId>
        <version>1.0-alpha-1-SNAPSHOT</version>
      </dependency>
      <dependency>
        <groupId>maven</groupId>
        <artifactId>maven-artifact</artifactId>
        <version>2.0-SNAPSHOT</version>
      </dependency>
      <dependency>
        <groupId>maven</groupId>
        <artifactId>maven-core</artifactId>
        <version>2.0-SNAPSHOT</version>
      </dependency>
      <dependency>
        <groupId>maven</groupId>
        <artifactId>maven-model</artifactId>
        <version>2.0-SNAPSHOT</version>
      </dependency>
      <dependency>
        <groupId>maven</groupId>
        <artifactId>maven-plugin</artifactId>
        <version>2.0-SNAPSHOT</version>
      </dependency>
    </dependencies>
  </project>
  
  
  1.1                  maven-components/maven-archiver/src/main/java/org/apache/maven/archiver/MavenArchiver.java
  
  Index: MavenArchiver.java
  ===================================================================
  package org.apache.maven.archiver;
  
  /* ====================================================================
   *   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
   *
   *       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.model.Dependency;
  import org.apache.maven.plugin.PluginExecutionRequest;
  import org.apache.maven.project.MavenProject;
  
  import org.codehaus.plexus.archiver.jar.JarArchiver;
  import org.codehaus.plexus.archiver.jar.Manifest;
  
  import java.io.File;
  import java.util.Iterator;
  import java.util.List;
  import java.util.Properties;
  import java.util.Set;
  
  /**
   * @author <a href="evenisse@apache.org">Emmanuel Venisse</a>
   * @version $Revision: 1.1 $ $Date: 2005/03/05 14:52:12 $
   */
  public class MavenArchiver
  {
      JarArchiver archiver = new JarArchiver();
  
      File archiveFile;
  
      /**
       * Return a pre-configured manifest
       * @todo Add user attributes list and user groups list
       */
      public Manifest getManifest( PluginExecutionRequest request )
          throws Exception
      {
          MavenProject project = (MavenProject)request.getParameter("project");
  
          String mainClass = (String) request.getParameter( "mainClass" );
  
          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" ) );
          m.addConfiguredAttribute( buildAttr );
          Manifest.Attribute createdAttr = new Manifest.Attribute( "Created-By", "Apache Maven"
);
          m.addConfiguredAttribute( createdAttr );
          Manifest.Attribute packageAttr = new Manifest.Attribute( "Package", project.getPackage()
);
          m.addConfiguredAttribute( packageAttr );
          Manifest.Attribute buildJdkAttr = new Manifest.Attribute( "Build-Jdk", System.getProperty(
"java.version" ) );
          m.addConfiguredAttribute( buildJdkAttr );
  
          if ( addClasspath )
          {
              StringBuffer classpath = new StringBuffer();
              List dependencies = project.getDependencies();
  
              for ( Iterator iter = dependencies.iterator(); iter.hasNext(); )
              {
                  Dependency dependency = (Dependency) iter.next();
                  Properties properties = dependency.getProperties();
                  if ( Boolean.valueOf(properties.getProperty("manifest.classpath")).booleanValue())
                  {
                      if (classpath.length() > 0 )
                      {
                          classpath.append( " " );
                      }
  
                      // TODO replace dependency by artifact
                      classpath.append( dependency.getArtifactId() + "-" + dependency.getVersion()
+ ".jar");
                  }
              }
              
              Manifest.Attribute classpathAttr = new Manifest.Attribute( "Class-Path", classpath.toString()
);
              m.addConfiguredAttribute( classpathAttr );
          }
  
          // Added supplementary entries
          Manifest.Attribute extensionNameAttr = new Manifest.Attribute( "Extension-Name",
project.getArtifactId() );
          m.addConfiguredAttribute( extensionNameAttr );
          
          if ( project.getShortDescription() != null )
          {
              Manifest.Attribute specificationTitleAttr = new Manifest.Attribute( "Specification-Title",
project.getShortDescription() );
              m.addConfiguredAttribute( specificationTitleAttr );
          }
  
          if ( project.getOrganization() != null )
          {
              Manifest.Attribute specificationVendor = new Manifest.Attribute( "Specification-Vendor",
project.getOrganization().getName() );
              m.addConfiguredAttribute( specificationVendor );
              Manifest.Attribute implementationVendorAttr = new Manifest.Attribute( "Implementation-Vendor",
project.getOrganization().getName() );
              m.addConfiguredAttribute( implementationVendorAttr );
          }
  
          Manifest.Attribute implementationTitleAttr = new Manifest.Attribute( "Implementation-Title",
project.getArtifactId() );
          m.addConfiguredAttribute( implementationTitleAttr );
          Manifest.Attribute implementationVersionAttr = new Manifest.Attribute( "Implementation-Version",
project.getVersion() );
          m.addConfiguredAttribute( implementationVersionAttr );
  
          if ( mainClass != null && ! "".equals( mainClass ) )
          {
              Manifest.Attribute mainClassAttr = new Manifest.Attribute( "Main-Class", mainClass
);
              m.addConfiguredAttribute( mainClassAttr );
          }
  
          // Added extensions
          if ( addExtensions )
          {
              StringBuffer extensionsList = new StringBuffer();
              Set artifacts = project.getArtifacts();
  
              for ( Iterator iter = artifacts.iterator(); iter.hasNext(); )
              {
                  Artifact artifact = (Artifact) iter.next();
                  if ( "jar".equals( artifact.getType() ) )
                  {
                      if (extensionsList.length() > 0 )
                      {
                          extensionsList.append( " " );
                      }
                      extensionsList.append( artifact.getArtifactId() );
                  }
              }
  
              if (extensionsList.length() > 0 )
              {
                  Manifest.Attribute extensionsListAttr = new Manifest.Attribute( "Extension-List",
extensionsList.toString() );
                  m.addConfiguredAttribute( extensionsListAttr );
              }
  
              for ( Iterator iter = artifacts.iterator(); iter.hasNext(); )
              {
                  Artifact artifact = (Artifact) iter.next();
                  if ( "jar".equals( artifact.getType() ) )
                  {
                      Manifest.Attribute archExtNameAttr = new Manifest.Attribute( artifact.getArtifactId()
                          + "-Extension-Name", artifact.getArtifactId() );
                      m.addConfiguredAttribute( archExtNameAttr );
                      Manifest.Attribute archImplVersionAttr = new Manifest.Attribute( artifact.getArtifactId()
                          + "-Implementation-Version", artifact.getVersion() );
                      m.addConfiguredAttribute( archImplVersionAttr );
                      Manifest.Attribute archImplUrlAttr = new Manifest.Attribute( artifact.getArtifactId()
                          + "-Implementation-URL", "http://www.ibiblio.org/maven/" + artifact.toString()
);
                      m.addConfiguredAttribute( archImplUrlAttr );
                  }
              }
          }
  
          return m;
      }
  
      public JarArchiver getArchiver()
      {
          return archiver;
      }
  
      public void setArchiver( JarArchiver archiver )
      {
          this.archiver = archiver;
      }
  
      public void setOutputFile( File outputFile )
      {
          archiveFile = outputFile;
      }
  
      public void createArchive( PluginExecutionRequest request )
          throws Exception
      {
          // ----------------------------------------------------------------------
          //
          // ----------------------------------------------------------------------
  
          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 ) )
          {
              File manifestFile = new File( manifest );
              archiver.setManifest( manifestFile );
          }
  
          // Configure the jar
          archiver.addConfiguredManifest( getManifest( request ) );
  
          archiver.setCompress( compress );
          archiver.setIndex( index );
          archiver.setDestFile( archiveFile );
  
          // create archive
          archiver.createArchive();
      }
  }
  
  
  

Mime
View raw message