Author: vmassol
Date: Sun Aug 14 06:19:12 2005
New Revision: 232602

URL: http://svn.apache.org/viewcvs?rev=232602&view=rev
Log:
MNG-150: Create a rar mojo. Applied on behalf of snicoll.

Added:
    maven/components/trunk/sandbox/maven-rar-plugin/
    maven/components/trunk/sandbox/maven-rar-plugin/pom.xml   (with props)
    maven/components/trunk/sandbox/maven-rar-plugin/src/
    maven/components/trunk/sandbox/maven-rar-plugin/src/main/
    maven/components/trunk/sandbox/maven-rar-plugin/src/main/java/
    maven/components/trunk/sandbox/maven-rar-plugin/src/main/java/org/
    maven/components/trunk/sandbox/maven-rar-plugin/src/main/java/org/apache/
    
maven/components/trunk/sandbox/maven-rar-plugin/src/main/java/org/apache/maven/
    
maven/components/trunk/sandbox/maven-rar-plugin/src/main/java/org/apache/maven/plugin/
    
maven/components/trunk/sandbox/maven-rar-plugin/src/main/java/org/apache/maven/plugin/rar/
    
maven/components/trunk/sandbox/maven-rar-plugin/src/main/java/org/apache/maven/plugin/rar/RarMojo.java
   (with props)
Modified:
    
maven/components/trunk/maven-core/src/main/resources/META-INF/plexus/components.xml

Modified: 
maven/components/trunk/maven-core/src/main/resources/META-INF/plexus/components.xml
URL: 
http://svn.apache.org/viewcvs/maven/components/trunk/maven-core/src/main/resources/META-INF/plexus/components.xml?rev=232602&r1=232601&r2=232602&view=diff
==============================================================================
--- 
maven/components/trunk/maven-core/src/main/resources/META-INF/plexus/components.xml
 (original)
+++ 
maven/components/trunk/maven-core/src/main/resources/META-INF/plexus/components.xml
 Sun Aug 14 06:19:12 2005
@@ -308,6 +308,30 @@
     </component>
 
     <component>
+      <role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role>
+      <role-hint>rar</role-hint>
+      
<implementation>org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping</implementation>
+      <configuration>
+        <!-- START SNIPPET: rar-lifecycle -->
+        <phases>
+          
<process-resources>org.apache.maven.plugins:maven-resources-plugin:resources</process-resources>
+          
<compile>org.apache.maven.plugins:maven-compiler-plugin:compile</compile>
+          
<process-test-resources>org.apache.maven.plugins:maven-resources-plugin:testResources</process-test-resources>
+          
<test-compile>org.apache.maven.plugins:maven-compiler-plugin:testCompile</test-compile>
+          <test>org.apache.maven.plugins:maven-surefire-plugin:test</test>
+          <package>
+            org.apache.maven.plugins:maven-jar-plugin:jar,
+            org.apache.maven.plugins:maven-source-plugin:jar,
+            org.apache.maven.plugins:maven-rar-plugin:rar
+          </package>
+          
<install>org.apache.maven.plugins:maven-install-plugin:install</install>
+          <deploy>org.apache.maven.plugins:maven-deploy-plugin:deploy</deploy>
+        </phases>
+        <!-- END SNIPPET: rar-lifecycle -->
+      </configuration>
+    </component>
+
+    <component>
       <role>org.apache.maven.plugin.version.PluginVersionManager</role>
       <role-hint>default</role-hint>
       
<implementation>org.apache.maven.plugin.version.DefaultPluginVersionManager</implementation>

Added: maven/components/trunk/sandbox/maven-rar-plugin/pom.xml
URL: 
http://svn.apache.org/viewcvs/maven/components/trunk/sandbox/maven-rar-plugin/pom.xml?rev=232602&view=auto
==============================================================================
--- maven/components/trunk/sandbox/maven-rar-plugin/pom.xml (added)
+++ maven/components/trunk/sandbox/maven-rar-plugin/pom.xml Sun Aug 14 06:19:12 
2005
@@ -0,0 +1,24 @@
+<model>
+  <parent>
+    <artifactId>maven-plugin-parent</artifactId>
+    <groupId>org.apache.maven.plugins</groupId>
+    <version>2.0-beta-1-SNAPSHOT</version>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+  <artifactId>maven-rar-plugin</artifactId>
+  <packaging>maven-plugin</packaging>
+  <name>Maven Rar plugin</name>
+  <version>2.0-beta-1-SNAPSHOT</version>
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-archiver</artifactId>
+      <version>2.0-beta-1-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-project</artifactId>
+      <version>2.0-beta-1-SNAPSHOT</version>
+    </dependency>    
+  </dependencies>
+</model>

Propchange: maven/components/trunk/sandbox/maven-rar-plugin/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/components/trunk/sandbox/maven-rar-plugin/pom.xml
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: 
maven/components/trunk/sandbox/maven-rar-plugin/src/main/java/org/apache/maven/plugin/rar/RarMojo.java
URL: 
http://svn.apache.org/viewcvs/maven/components/trunk/sandbox/maven-rar-plugin/src/main/java/org/apache/maven/plugin/rar/RarMojo.java?rev=232602&view=auto
==============================================================================
--- 
maven/components/trunk/sandbox/maven-rar-plugin/src/main/java/org/apache/maven/plugin/rar/RarMojo.java
 (added)
+++ 
maven/components/trunk/sandbox/maven-rar-plugin/src/main/java/org/apache/maven/plugin/rar/RarMojo.java
 Sun Aug 14 06:19:12 2005
@@ -0,0 +1,221 @@
+package org.apache.maven.plugin.rar;
+
+/*
+ * 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.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.archiver.MavenArchiver;
+import org.apache.maven.archiver.MavenArchiveConfiguration;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.artifact.Artifact;
+import org.codehaus.plexus.util.FileUtils;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.Set;
+
+/**
+ * Builds J2EE Resource Adapter Archive (RAR) files.
+ *
+ * @author <a href="[EMAIL PROTECTED]">Stephane Nicoll</a>
+ * @version $Id$
+ * @goal rar
+ * @phase package
+ * @requiresDependencyResolution test
+ * @description builds a rar
+ */
+public class RarMojo
+    extends AbstractMojo
+{
+    public static final String RA_XML_URI = "META-INF/ra.xml";
+
+
+    /**
+     * Single directory for extra files to include in the RAR.
+     *
+     * @parameter expression="${basedir}/src/rar"
+     * @required
+     */
+    private String rarSourceDirectory;
+
+    /**
+     * The location of the ra.xml file to be used within the rar file.
+     *
+     * @parameter expression="${basedir}/src/rar/META-INF/ra.xml"
+     */
+    private String raXmlLocation;
+
+    /**
+     * Specify if the generated jar file of this project should be
+     * included in the rar file ; default is true.
+     *
+     * @parameter
+     */
+    private Boolean includeJar = Boolean.TRUE;
+
+    /**
+     * The location of the manifest file to be used within the rar file.
+     *
+     * @parameter expression="${basedir}/src/rar/META-INF/MANIFEST.MF"
+     * @TODO handle this field
+     */
+    private String manifestLocation;
+
+    /**
+     * Directory that resources are copied to during the build.
+     *
+     * @parameter 
expression="${project.build.directory}/${project.build.finalName}"
+     * @required
+     */
+    private String workDirectory;
+
+    /**
+     * The directory for the generated RAR.
+     *
+     * @parameter expression="${project.build.directory}"
+     * @required
+     */
+    private String outputDirectory;
+
+    /**
+     * The name of the RAR file to generate.
+     *
+     * @parameter alias="rarName" expression="${project.build.finalName}"
+     * @required
+     * @readonly
+     */
+    private String finalName;
+
+    /**
+     * The maven project.
+     *
+     * @parameter expression="${project}"
+     * @required
+     * @readonly
+     * @description "the maven project to use"
+     */
+    private MavenProject project;
+
+    /**
+     * The maven archiver to use.
+     *
+     * @parameter
+     */
+    private MavenArchiveConfiguration archive = new 
MavenArchiveConfiguration();
+
+
+    private File buildDir;
+
+
+    public void execute()
+        throws MojoExecutionException
+    {
+        getLog().debug( " ======= RarMojo settings =======" );
+        getLog().debug( "rarSourceDirectory[" + rarSourceDirectory + "]" );
+        getLog().debug( "manifestLocation[" + manifestLocation + "]" );
+        getLog().debug( "raXmlLocation[" + raXmlLocation + "]" );
+        getLog().debug( "workDirectory[" + workDirectory + "]" );
+        getLog().debug( "outputDirectory[" + outputDirectory + "]" );
+        getLog().debug( "finalName[" + finalName + "]" );
+
+        // Check if jar file is there and if requested, copy it
+        try
+        {
+            if (includeJar.booleanValue()) {
+                File generatedJarFile = new File( outputDirectory, finalName + 
".jar" );
+                if (generatedJarFile.exists()) {
+                    getLog().info( "Including generated jar 
file["+generatedJarFile.getName()+"]");
+                    FileUtils.copyFileToDirectory( generatedJarFile, 
getBuildDir());
+                }
+            }
+        }
+        catch ( IOException e )
+        {
+            throw new MojoExecutionException( "Error copying generated Jar 
file", e );
+        }
+
+        // Copy dependencies
+        try
+        {
+            Set artifacts = project.getArtifacts();
+            for ( Iterator iter = artifacts.iterator(); iter.hasNext(); )
+            {
+                Artifact artifact = (Artifact) iter.next();
+                if ( !Artifact.SCOPE_TEST.equals( artifact.getScope() ) &&
+                    !Artifact.SCOPE_PROVIDED.equals( artifact.getScope() ) )
+                {
+                    getLog().info("Copying artifact[" + artifact.getGroupId() 
+ ", " + artifact.getId() + ", " +
+                        artifact.getScope() + "]");
+                    FileUtils.copyFileToDirectory( artifact.getFile(), 
getBuildDir() );
+                }
+            }
+        }
+        catch ( IOException e )
+        {
+            throw new MojoExecutionException( "Error copying RAR 
dependencies", e );
+        }
+
+        // Copy source files
+        try
+        {
+            File rarSourceDir = new File( rarSourceDirectory );
+            if ( rarSourceDir.exists() )
+            {
+                getLog().info( "Copy rar resources to " + 
getBuildDir().getAbsolutePath() );
+                FileUtils.copyDirectoryStructure( rarSourceDir, getBuildDir() 
);
+            }
+        }
+        catch ( IOException e )
+        {
+            throw new MojoExecutionException( "Error copying RAR resources", e 
);
+        }
+
+        // Check if connector deployment descriptor is there
+        File ddFile = new File( getBuildDir(), RA_XML_URI );
+        if ( !ddFile.exists() )
+        {
+            getLog().warn(
+                "Connector deployment descriptor: " + ddFile.getAbsolutePath() 
+ " does not exist." );
+        }
+
+        try
+        {
+            File rarFile = new File( outputDirectory, finalName + ".rar" );
+            MavenArchiver archiver = new MavenArchiver();
+            archiver.setOutputFile( rarFile );
+
+            archiver.getArchiver().addDirectory( getBuildDir() );
+            archiver.createArchive( project, archive );
+        }
+        catch ( Exception e )
+        {
+            throw new MojoExecutionException( "Error assembling RAR", e );
+        }
+
+
+    }
+
+    protected File getBuildDir()
+    {
+        if ( buildDir == null )
+        {
+            buildDir = new File( workDirectory );
+        }
+        return buildDir;
+    }
+}

Propchange: 
maven/components/trunk/sandbox/maven-rar-plugin/src/main/java/org/apache/maven/plugin/rar/RarMojo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/components/trunk/sandbox/maven-rar-plugin/src/main/java/org/apache/maven/plugin/rar/RarMojo.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to