[jboss-cvs] JBossAS SVN: r72321 - in projects/maven/plugins/deployer/trunk: src/main/java/org/jboss/maven/plugin/deployer and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Apr 16 18:42:40 EDT 2008


Author: thomas.diesler at jboss.com
Date: 2008-04-16 18:42:40 -0400 (Wed, 16 Apr 2008)
New Revision: 72321

Added:
   projects/maven/plugins/deployer/trunk/src/main/java/org/jboss/maven/plugin/deployer/AbstractDeployerMojo.java
   projects/maven/plugins/deployer/trunk/src/main/java/org/jboss/maven/plugin/deployer/DependenciesHandler.java
   projects/maven/plugins/deployer/trunk/src/main/java/org/jboss/maven/plugin/deployer/DeploymentsHandler.java
   projects/maven/plugins/deployer/trunk/src/main/java/org/jboss/maven/plugin/deployer/UndeploymentsHandler.java
Modified:
   projects/maven/plugins/deployer/trunk/
   projects/maven/plugins/deployer/trunk/.classpath
   projects/maven/plugins/deployer/trunk/pom.xml
   projects/maven/plugins/deployer/trunk/src/main/java/org/jboss/maven/plugin/deployer/DeployerMojo.java
   projects/maven/plugins/deployer/trunk/src/main/java/org/jboss/maven/plugin/deployer/Deployment.java
Log:
wip


Property changes on: projects/maven/plugins/deployer/trunk
___________________________________________________________________
Name: svn:ignore
   + target


Modified: projects/maven/plugins/deployer/trunk/.classpath
===================================================================
--- projects/maven/plugins/deployer/trunk/.classpath	2008-04-16 22:32:45 UTC (rev 72320)
+++ projects/maven/plugins/deployer/trunk/.classpath	2008-04-16 22:42:40 UTC (rev 72321)
@@ -2,6 +2,24 @@
 <classpath>
 	<classpathentry kind="src" path="src/main/java"/>
 	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
-	<classpathentry kind="var" path="M2_REPO/org/apache/maven/maven-plugin-api/2.0.9/maven-plugin-api-2.0.9.jar" sourcepath="/M2_REPO/org/apache/maven/maven-plugin-api/2.0.9/maven-plugin-api-2.0.9-sources.jar"/>
+	<classpathentry kind="var" path="M2_REPO/org/apache/maven/maven-plugin-api/2.0.9/maven-plugin-api-2.0.9.jar" sourcepath="/M2_REPO/org/apache/maven/maven-plugin-api/2.0.9/maven-plugin-api-2.0.9-sources.jar">
+		<attributes>
+			<attribute name="javadoc_location" value="jar:file:/home/tdiesler/.m2/repository/org/apache/maven/maven-plugin-api/2.0.9/maven-plugin-api-2.0.9-javadoc.jar!/"/>
+		</attributes>
+	</classpathentry>
+	<classpathentry kind="var" path="M2_REPO/org/apache/maven/plugins/maven-dependency-plugin/2.0/maven-dependency-plugin-2.0.jar" sourcepath="/M2_REPO/org/apache/maven/plugins/maven-dependency-plugin/2.0/maven-dependency-plugin-2.0-sources.jar">
+		<attributes>
+			<attribute name="javadoc_location" value="jar:file:/home/tdiesler/.m2/repository/org/apache/maven/plugins/maven-dependency-plugin/2.0/maven-dependency-plugin-2.0-javadoc.jar!/"/>
+		</attributes>
+	</classpathentry>
+	<classpathentry kind="var" path="M2_REPO/org/apache/maven/plugins/maven-assembly-plugin/2.1/maven-assembly-plugin-2.1.jar" sourcepath="/M2_REPO/org/apache/maven/plugins/maven-assembly-plugin/2.1/maven-assembly-plugin-2.1-sources.jar">
+		<attributes>
+			<attribute name="javadoc_location" value="jar:file:/home/tdiesler/.m2/repository/org/apache/maven/plugins/maven-assembly-plugin/2.1/maven-assembly-plugin-2.1-javadoc.jar!/"/>
+		</attributes>
+	</classpathentry>
+	<classpathentry kind="var" path="M2_REPO/org/codehaus/plexus/plexus-utils/1.4.6/plexus-utils-1.4.6.jar"/>
+	<classpathentry kind="var" path="M2_REPO/org/apache/maven/maven-project/2.0.9/maven-project-2.0.9.jar"/>
+	<classpathentry kind="var" path="M2_REPO/org/apache/maven/shared/maven-common-artifact-filters/1.0/maven-common-artifact-filters-1.0.jar"/>
+	<classpathentry kind="var" path="M2_REPO/org/apache/maven/maven-artifact/2.0.9/maven-artifact-2.0.9.jar"/>
 	<classpathentry kind="output" path="target/eclipse"/>
 </classpath>

Modified: projects/maven/plugins/deployer/trunk/pom.xml
===================================================================
--- projects/maven/plugins/deployer/trunk/pom.xml	2008-04-16 22:32:45 UTC (rev 72320)
+++ projects/maven/plugins/deployer/trunk/pom.xml	2008-04-16 22:42:40 UTC (rev 72321)
@@ -9,25 +9,106 @@
   <url>http://maven.apache.org</url>
   
   <version>1.0-SNAPSHOT</version>
-  
+	
+  <properties>
+    <maven.artifact>2.0.9</maven.artifact>
+    <maven.assembly.plugin>2.1</maven.assembly.plugin>
+    <maven.dependency.plugin>2.0</maven.dependency.plugin>
+    <maven.plugin.api>2.0.9</maven.plugin.api>
+    <maven.project>2.0.9</maven.project>
+  </properties>
+	
   <dependencies>
+    <!-- maven-artifact -->
     <dependency>
       <groupId>org.apache.maven</groupId>
+      <artifactId>maven-artifact</artifactId>
+      <version>${maven.artifact}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-artifact</artifactId>
+      <version>${maven.artifact}</version>
+      <classifier>sources</classifier>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-artifact</artifactId>
+      <version>${maven.artifact}</version>
+      <classifier>javadoc</classifier>
+    </dependency>
+    <!-- maven-plugin-api -->
+    <dependency>
+      <groupId>org.apache.maven</groupId>
       <artifactId>maven-plugin-api</artifactId>
-      <version>2.0.9</version>
+      <version>${maven.plugin.api}</version>
     </dependency>
     <dependency>
       <groupId>org.apache.maven</groupId>
       <artifactId>maven-plugin-api</artifactId>
-      <version>2.0.9</version>
+      <version>${maven.plugin.api}</version>
       <classifier>sources</classifier>
     </dependency>
     <dependency>
-      <groupId>junit</groupId>
-      <artifactId>junit</artifactId>
-      <version>3.8.1</version>
-      <scope>test</scope>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-plugin-api</artifactId>
+      <version>${maven.plugin.api}</version>
+      <classifier>javadoc</classifier>
     </dependency>
+    <!-- maven-project -->
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-project</artifactId>
+      <version>${maven.project}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-project</artifactId>
+      <version>${maven.project}</version>
+      <classifier>sources</classifier>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-project</artifactId>
+      <version>${maven.project}</version>
+      <classifier>javadoc</classifier>
+    </dependency>
+    <!-- maven-assembly-plugin -->
+    <dependency>
+      <groupId>org.apache.maven.plugins</groupId>
+      <artifactId>maven-assembly-plugin</artifactId>
+      <version>${maven.assembly.plugin}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven.plugins</groupId>
+      <artifactId>maven-assembly-plugin</artifactId>
+      <version>${maven.assembly.plugin}</version>
+      <classifier>sources</classifier>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven.plugins</groupId>
+      <artifactId>maven-assembly-plugin</artifactId>
+      <version>${maven.assembly.plugin}</version>
+      <classifier>javadoc</classifier>
+    </dependency>
+    <!-- maven-dependency-plugin -->
+    <dependency>
+      <groupId>org.apache.maven.plugins</groupId>
+      <artifactId>maven-dependency-plugin</artifactId>
+      <version>${maven.dependency.plugin}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven.plugins</groupId>
+      <artifactId>maven-dependency-plugin</artifactId>
+      <version>${maven.dependency.plugin}</version>
+      <classifier>sources</classifier>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven.plugins</groupId>
+      <artifactId>maven-dependency-plugin</artifactId>
+      <version>${maven.dependency.plugin}</version>
+      <classifier>javadoc</classifier>
+    </dependency>
   </dependencies>
   
   <build>
@@ -45,12 +126,32 @@
         <artifactId>maven-deployer-plugin</artifactId>
         <version>${version}</version>
         <configuration>
-          <jbossHome>/home/tdiesler/svn/jbossas/tags/JBoss_5_0_0_Beta4/build/output/jboss-5.0.0.Beta4</jbossHome>
+          <!--jbossHome>/home/tdiesler/svn/jbossas/tags/JBoss_5_0_0_Beta4/build/output/jboss-5.0.0.Beta4</jbossHome-->
+          <jbossHome>target</jbossHome>
+          <deployStructure>target/deploy-structure</deployStructure>
+          <keepDeployStructure>true</keepDeployStructure>
+          <undeployments>
+            <include>./classes/META-INF/maven/plugin.xml</include>
+            <include>./classes/bogus</include>
+            <include>./classes</include>
+          </undeployments>
           <deployments>
             <deployment>
-              <sourceDir></sourceDir>
+              <targetDir>bin</targetDir>
+              <sourceDir>src/main/java</sourceDir>
+              <includes>
+                <include>**/*.java</include>
+              </includes>
             </deployment>
           </deployments>
+          <dependencies>
+            <deployment>
+              <targetDir>libs</targetDir>
+              <includes>
+                <include>**/*.java</include>
+              </includes>
+            </deployment>
+          </dependencies>
         </configuration>
       </plugin>
     </plugins>

Added: projects/maven/plugins/deployer/trunk/src/main/java/org/jboss/maven/plugin/deployer/AbstractDeployerMojo.java
===================================================================
--- projects/maven/plugins/deployer/trunk/src/main/java/org/jboss/maven/plugin/deployer/AbstractDeployerMojo.java	                        (rev 0)
+++ projects/maven/plugins/deployer/trunk/src/main/java/org/jboss/maven/plugin/deployer/AbstractDeployerMojo.java	2008-04-16 22:42:40 UTC (rev 72321)
@@ -0,0 +1,164 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.maven.plugin.deployer;
+
+// $Id$
+
+import java.util.List;
+
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.project.MavenProject;
+
+/**
+ * 
+ *
+ * @author Thomas.Diesler at jboss.com
+ * @since 16-Apr-2008
+ */
+public abstract class AbstractDeployerMojo extends AbstractMojo
+{
+   /**
+    * Used to look up Artifacts in the remote repository.
+    * 
+    * @parameter expression="${component.org.apache.maven.artifact.factory.ArtifactFactory}"
+    * @required
+    * @readonly
+    */
+   private org.apache.maven.artifact.factory.ArtifactFactory factory;
+
+   /**
+    * Used to look up Artifacts in the remote repository.
+    * 
+    * @parameter expression="${component.org.apache.maven.artifact.resolver.ArtifactResolver}"
+    * @required
+    * @readonly
+    */
+   private org.apache.maven.artifact.resolver.ArtifactResolver resolver;
+
+   /**
+    * Artifact collector, needed to resolve dependencies.
+    * 
+    * @component role="org.apache.maven.artifact.resolver.ArtifactCollector"
+    * @required
+    * @readonly
+    */
+   private org.apache.maven.artifact.resolver.ArtifactCollector artifactCollector;
+
+   /**
+    * @component role="org.apache.maven.artifact.metadata.ArtifactMetadataSource"
+    *            hint="maven"
+    * @required
+    * @readonly
+    */
+   private org.apache.maven.artifact.metadata.ArtifactMetadataSource artifactMetadataSource;
+
+   /**
+    * Location of the local repository.
+    * 
+    * @parameter expression="${localRepository}"
+    * @readonly
+    * @required
+    */
+   private org.apache.maven.artifact.repository.ArtifactRepository local;
+
+   /**
+    * List of Remote Repositories used by the resolver
+    * 
+    * @parameter expression="${project.remoteArtifactRepositories}"
+    * @readonly
+    * @required
+    */
+   private java.util.List remoteRepos;
+
+   /**
+    * To look up Archiver/UnArchiver implementations
+    * 
+    * @parameter expression="${component.org.codehaus.plexus.archiver.manager.ArchiverManager}"
+    * @required
+    * @readonly
+    */
+   private org.codehaus.plexus.archiver.manager.ArchiverManager archiverManager;
+
+   /**
+    * POM
+    * 
+    * @parameter expression="${project}"
+    * @readonly
+    * @required
+    */
+   private MavenProject project;
+
+   /**
+    * Contains the full list of projects in the reactor.
+    * 
+    * @parameter expression="${reactorProjects}"
+    * @required
+    * @readonly
+    */
+   private List reactorProjects;
+
+   public org.codehaus.plexus.archiver.manager.ArchiverManager getArchiverManager()
+   {
+      return archiverManager;
+   }
+
+   public org.apache.maven.artifact.resolver.ArtifactCollector getArtifactCollector()
+   {
+      return artifactCollector;
+   }
+
+   public org.apache.maven.artifact.metadata.ArtifactMetadataSource getArtifactMetadataSource()
+   {
+      return artifactMetadataSource;
+   }
+
+   public org.apache.maven.artifact.factory.ArtifactFactory getFactory()
+   {
+      return factory;
+   }
+
+   public org.apache.maven.artifact.repository.ArtifactRepository getLocal()
+   {
+      return local;
+   }
+
+   public MavenProject getProject()
+   {
+      return project;
+   }
+
+   public List getReactorProjects()
+   {
+      return reactorProjects;
+   }
+
+   public java.util.List getRemoteRepos()
+   {
+      return remoteRepos;
+   }
+
+   public org.apache.maven.artifact.resolver.ArtifactResolver getResolver()
+   {
+      return resolver;
+   }
+
+}


Property changes on: projects/maven/plugins/deployer/trunk/src/main/java/org/jboss/maven/plugin/deployer/AbstractDeployerMojo.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Added: projects/maven/plugins/deployer/trunk/src/main/java/org/jboss/maven/plugin/deployer/DependenciesHandler.java
===================================================================
--- projects/maven/plugins/deployer/trunk/src/main/java/org/jboss/maven/plugin/deployer/DependenciesHandler.java	                        (rev 0)
+++ projects/maven/plugins/deployer/trunk/src/main/java/org/jboss/maven/plugin/deployer/DependenciesHandler.java	2008-04-16 22:42:40 UTC (rev 72321)
@@ -0,0 +1,88 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.maven.plugin.deployer;
+
+//$Id$
+
+import java.io.File;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.dependency.utils.DependencyStatusSets;
+
+public class DependenciesHandler
+{
+   private DeployerMojo mojo;
+
+   private DependenciesHandler(DeployerMojo mojo)
+   {
+      this.mojo = mojo;
+   }
+
+   public static void process(DeployerMojo mojo) throws MojoExecutionException
+   {
+      new DependenciesHandler(mojo).process();
+   }
+
+   private void process() throws MojoExecutionException
+   {
+      List<Deployment> dependencies = mojo.getDependencies();
+      if (dependencies != null)
+      {
+         mojo.getLog().info("Dependencies");
+         for (Deployment dep : dependencies)
+         {
+            dep.validateConfiguration(mojo, false);
+            processDeployment(dep);
+         }
+      }
+   }
+
+   private void processDeployment(Deployment dep) throws MojoExecutionException
+   {
+      /*
+      boolean stripVersion = true;
+      
+      File outputDirectory = new File(mojo.getDeployStructure() + "/" + dep.getTargetDir());
+      mojo.setOutputDirectory(outputDirectory);
+      mojo.setStripVersion(stripVersion);
+
+      DependencyStatusSets dss = mojo.getDependencySets(true);
+      Set artifacts = dss.getResolvedDependencies();
+
+      for (Iterator i = artifacts.iterator(); i.hasNext();)
+      {
+         mojo.copyArtifact((Artifact)i.next(), stripVersion);
+      }
+
+      artifacts = dss.getSkippedDependencies();
+      for (Iterator i = artifacts.iterator(); i.hasNext();)
+      {
+         Artifact artifact = (Artifact)i.next();
+         mojo.getLog().info(artifact.getFile().getName() + " already exists in destination.");
+      }
+      */
+   }
+}


Property changes on: projects/maven/plugins/deployer/trunk/src/main/java/org/jboss/maven/plugin/deployer/DependenciesHandler.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Modified: projects/maven/plugins/deployer/trunk/src/main/java/org/jboss/maven/plugin/deployer/DeployerMojo.java
===================================================================
--- projects/maven/plugins/deployer/trunk/src/main/java/org/jboss/maven/plugin/deployer/DeployerMojo.java	2008-04-16 22:32:45 UTC (rev 72320)
+++ projects/maven/plugins/deployer/trunk/src/main/java/org/jboss/maven/plugin/deployer/DeployerMojo.java	2008-04-16 22:42:40 UTC (rev 72321)
@@ -24,14 +24,14 @@
 // $Id$
 
 import java.io.File;
+import java.io.IOException;
 import java.util.List;
-import java.util.Map;
 
-import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
+import org.codehaus.plexus.util.FileUtils;
 
 /**
- * Goal which touches a timestamp file.
+ * Goal which copies files and dependencies to jboss
  *
  * @goal deploy-jboss
  * @phase package
@@ -39,42 +39,128 @@
  * @author Thomas.Diesler at jboss.com
  * @since 16-Apr-2008
  */
-public class DeployerMojo extends AbstractMojo
+public class DeployerMojo extends AbstractDeployerMojo
 {
    /** 
+    * The required jboss home location.
+    * i.e. ~/svn/jbossas/tags/JBoss_5_0_0_Beta4/build/output/jboss-5.0.0.Beta4
+    * 
     * @required
     * @parameter 
     */
    private File jbossHome;
-   
+
    /** 
-    * @required
+    * The optional temporary deploy structure
     * @parameter 
     */
+   private File deployStructure;
+
+   /** 
+    * An optional falg to temporary deploy structure
+    * @parameter default-value="false" 
+    */
+   private boolean keepDeployStructure;
+
+   /** 
+    * The optional list of deployments
+    * @parameter 
+    */
    private List<Deployment> deployments;
-   
+
+   /** 
+    * The optional list of dependencies
+    * @parameter 
+    */
+   private List<Deployment> dependencies;
+
+   /** 
+    * An optional list of files to undeploy
+    * @parameter  
+    */
+   private List<String> undeployments;
+
    public void execute() throws MojoExecutionException
    {
-      getPluginContext().put("artifactId", "maven-deployer-plugin");
-      
-      validateConfiguration();
-      
-      getLog().info("jbossHome: " + jbossHome);
-      for (Deployment dep : deployments)
+      try
       {
-         dep.validateConfiguration(this);
-         processDeployment(dep);
+         validateConfiguration();
+
+         getLog().info("project: " + project);
+         getLog().info("jbossHome: " + jbossHome);
+
+         // recreate deploy structure
+         FileUtils.deleteDirectory(deployStructure);
+         deployStructure.mkdirs();
+
+         UndeploymentsHandler.process(this);
+         DeploymentsHandler.process(this);
+         //DependenciesHandler.process(this);
       }
+      catch (IOException ex)
+      {
+         throw new MojoExecutionException("Cannot process goal 'deploy-jboss'", ex);
+      }
+      finally
+      {
+         if (keepDeployStructure == false && deployStructure != null)
+            deployStructure.delete();
+      }
    }
 
-   private void processDeployment(Deployment dep)
+   /*
+    // public access to protected method
+    public DependencyStatusSets getDependencySets(boolean stopOnFailure) throws MojoExecutionException
+    {
+    return super.getDependencySets(stopOnFailure);
+    }
+
+    // public access to protected method
+    public void copyArtifact(Artifact artifact, boolean stripVersion) throws MojoExecutionException
+    {
+    super.copyArtifact(artifact, stripVersion);
+    }
+    */
+
+   public List<Deployment> getDependencies()
    {
-      getLog().info(" +- " + dep.getTargetDir());
+      return dependencies;
    }
 
-   private void validateConfiguration() throws MojoExecutionException
+   public List<Deployment> getDeployments()
    {
+      return deployments;
+   }
+
+   public File getDeployStructure()
+   {
+      return deployStructure;
+   }
+
+   public File getJbossHome()
+   {
+      return jbossHome;
+   }
+
+   public boolean isKeepDeployStructure()
+   {
+      return keepDeployStructure;
+   }
+
+   public List<String> getUndeployments()
+   {
+      return undeployments;
+   }
+
+   private void validateConfiguration() throws MojoExecutionException, IOException
+   {
       if (jbossHome.exists() == false)
          throw new MojoExecutionException("jbossHome does not exist: " + jbossHome);
+
+      if (deployStructure == null)
+      {
+         deployStructure = File.createTempFile("maven-deploy", ".tmp").getParentFile();
+         getLog().debug("deployStructure: " + deployStructure);
+      }
    }
 }

Modified: projects/maven/plugins/deployer/trunk/src/main/java/org/jboss/maven/plugin/deployer/Deployment.java
===================================================================
--- projects/maven/plugins/deployer/trunk/src/main/java/org/jboss/maven/plugin/deployer/Deployment.java	2008-04-16 22:32:45 UTC (rev 72320)
+++ projects/maven/plugins/deployer/trunk/src/main/java/org/jboss/maven/plugin/deployer/Deployment.java	2008-04-16 22:42:40 UTC (rev 72321)
@@ -21,24 +21,49 @@
  */
 package org.jboss.maven.plugin.deployer;
 
+//$Id$
+
+import java.io.File;
+import java.util.List;
+
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 
-// $Id$
-
+/**
+ * A deployment config structure
+ *
+ * @author Thomas.Diesler at jboss.com
+ * @since 16-Apr-2008
+ */
 public class Deployment
 {
-   /** 
+   /**
+    * The target directory relative to 'jbossHome'
+    *  
     * @required
     * @parameter 
     */
    private String targetDir;
-   /** 
+   
+   /**
+    * The source directory
     * @parameter 
     */
-   private String sourceDir;
+   private File sourceDir;
+   
+   /**
+    * The optional list of includes
+    * @parameter 
+    */
+   private List<String> includes;
 
-   public String getSourceDir()
+   /**
+    * The optional list of excludes
+    * @parameter 
+    */
+   private List<String> excludes;
+
+   public File getSourceDir()
    {
       return sourceDir;
    }
@@ -48,19 +73,36 @@
       return targetDir;
    }
 
-   public void validateConfiguration(AbstractMojo mojo) throws MojoExecutionException
+   public List<String> getIncludes()
    {
+      return includes;
+   }
+
+   public List<String> getExcludes()
+   {
+      return excludes;
+   }
+
+   public void validateConfiguration(DeployerMojo mojo, boolean sourceRequired) throws MojoExecutionException
+   {
+      String artifactId = mojo.getProject().getArtifactId();
+      
       if (targetDir == null)
       {
-         mojo.getLog().info("<deployments>");
-         mojo.getLog().info("  <deployment>");
-         mojo.getLog().info("    <targetDir>VALUE</targetDir>");
-         mojo.getLog().info("    ...");
-         mojo.getLog().info("  </deployment>");
-         mojo.getLog().info("</deployments>");
-
-         String artifactId = (String)mojo.getPluginContext().get("artifactId");
+         mojo.getLog().info("<deployment>");
+         mojo.getLog().info("  <targetDir>VALUE</targetDir>");
+         mojo.getLog().info("  ...");
+         mojo.getLog().info("</deployment>");
          throw new MojoExecutionException("Inside the definition for plugin '" + artifactId + "' specify the following");
       }
+      
+      if (sourceRequired == true && sourceDir == null)
+      {
+         mojo.getLog().info("<deployment>");
+         mojo.getLog().info("  <sourceDir>VALUE</sourceDir>");
+         mojo.getLog().info("  ...");
+         mojo.getLog().info("</deployment>");
+         throw new MojoExecutionException("Inside the definition for plugin '" + artifactId + "' specify the following");
+      }
    }
 }

Added: projects/maven/plugins/deployer/trunk/src/main/java/org/jboss/maven/plugin/deployer/DeploymentsHandler.java
===================================================================
--- projects/maven/plugins/deployer/trunk/src/main/java/org/jboss/maven/plugin/deployer/DeploymentsHandler.java	                        (rev 0)
+++ projects/maven/plugins/deployer/trunk/src/main/java/org/jboss/maven/plugin/deployer/DeploymentsHandler.java	2008-04-16 22:42:40 UTC (rev 72321)
@@ -0,0 +1,141 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.maven.plugin.deployer;
+
+// $Id$
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.codehaus.plexus.util.FileUtils;
+
+/**
+ * Handles deployment of artifacts.
+ *
+ * @author Thomas.Diesler at jboss.com
+ * @since 16-Apr-2008
+ */
+public class DeploymentsHandler
+{
+   private DeployerMojo mojo;
+
+   private DeploymentsHandler(DeployerMojo mojo)
+   {
+      this.mojo = mojo;
+   }
+
+   public static void process(DeployerMojo mojo) throws MojoExecutionException, IOException
+   {
+      new DeploymentsHandler(mojo).process();
+   }
+
+   private void process() throws MojoExecutionException, IOException
+   {
+      List<Deployment> deployments = mojo.getDeployments();
+      if (deployments != null)
+      {
+         mojo.getLog().info("Deploy");
+         for (Deployment dep : deployments)
+         {
+            dep.validateConfiguration(mojo, true);
+            processDeployment(dep);
+         }
+      }
+   }
+
+   private void processDeployment(Deployment dep) throws MojoExecutionException, IOException
+   {
+      String targetDir = dep.getTargetDir();
+      File sourceDir = dep.getSourceDir();
+
+      mojo.getLog().info(" +- " + targetDir);
+
+      List<String> includes = dep.getIncludes();
+      int offset = sourceDir.getCanonicalPath().length() + 1;
+
+      List<File> effectiveFiles = new ArrayList<File>();
+
+      // includes
+      if (includes != null)
+      {
+         for (String include : includes)
+         {
+            List<File> files = FileUtils.getFiles(sourceDir, include, null);
+            for (File file : files)
+            {
+               mojo.getLog().debug("Include: " + file.getCanonicalPath().substring(offset));
+               effectiveFiles.add(file);
+            }
+         }
+      }
+      else
+      {
+         List<File> files = FileUtils.getFiles(sourceDir, "**", null);
+         for (File file : files)
+         {
+            mojo.getLog().debug("Include: " + file.getCanonicalPath().substring(offset));
+            effectiveFiles.add(file);
+         }
+      }
+
+      // excludes
+      List<String> excludes = dep.getExcludes();
+      if (excludes != null)
+      {
+         for (String exclude : excludes)
+         {
+            List<File> files = FileUtils.getFiles(sourceDir, exclude, null);
+            for (File file : files)
+            {
+               mojo.getLog().debug("Exclude: " + file.getCanonicalPath().substring(offset));
+               effectiveFiles.remove(file);
+            }
+         }
+      }
+
+      File destRoot = new File(mojo.getDeployStructure() + "/" + targetDir);
+      copyFiles(effectiveFiles, sourceDir, destRoot);
+
+      for (File file : effectiveFiles)
+      {
+         mojo.getLog().info("  +- " + file.getCanonicalPath().substring(offset));
+      }
+   }
+
+   private void copyFiles(List<File> files, File sourceDir, File destRoot) throws IOException
+   {
+      int offset = sourceDir.getCanonicalPath().length() + 1;
+      for (File file : files)
+      {
+         if (file.getCanonicalPath().startsWith(sourceDir.getCanonicalPath()) == false)
+            throw new IOException("File is not from sourceDir: " + file);
+
+         String relFile = file.getCanonicalPath().substring(offset);
+         String relPath = new File(relFile).getParent();
+         File destDir = new File(destRoot + "/" + relPath);
+         FileUtils.copyFileToDirectory(file, destDir);
+      }
+   }
+}


Property changes on: projects/maven/plugins/deployer/trunk/src/main/java/org/jboss/maven/plugin/deployer/DeploymentsHandler.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Added: projects/maven/plugins/deployer/trunk/src/main/java/org/jboss/maven/plugin/deployer/UndeploymentsHandler.java
===================================================================
--- projects/maven/plugins/deployer/trunk/src/main/java/org/jboss/maven/plugin/deployer/UndeploymentsHandler.java	                        (rev 0)
+++ projects/maven/plugins/deployer/trunk/src/main/java/org/jboss/maven/plugin/deployer/UndeploymentsHandler.java	2008-04-16 22:42:40 UTC (rev 72321)
@@ -0,0 +1,78 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.maven.plugin.deployer;
+
+// $Id$
+
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+
+import org.codehaus.plexus.util.FileUtils;
+
+/**
+ * Handles undeployment of artifacts.
+ *
+ * @author Thomas.Diesler at jboss.com
+ * @since 16-Apr-2008
+ */
+public class UndeploymentsHandler
+{
+   private DeployerMojo mojo;
+
+   private UndeploymentsHandler(DeployerMojo mojo)
+   {
+      this.mojo = mojo;
+   }
+
+   public static void process(DeployerMojo mojo) throws IOException
+   {
+      new UndeploymentsHandler(mojo).process();
+   }
+
+   private void process() throws IOException
+   {
+      List<String> undeployments = mojo.getUndeployments();
+      if (undeployments != null)
+      {
+         mojo.getLog().info("Undeploy");
+         for (String relFile : undeployments)
+         {
+            File file = new File(mojo.getJbossHome() + "/" + relFile);
+            if (file.isDirectory())
+            {
+               mojo.getLog().info(" +- " + relFile + " (directory)");
+               FileUtils.deleteDirectory(file);
+            }
+            else if (file.exists())
+            {
+               mojo.getLog().info(" +- " + relFile + " (file)");
+               file.delete();
+            }
+            else
+            {
+               mojo.getLog().info(" +- " + relFile + " (not found)");
+            }
+         }
+      }
+   }
+}


Property changes on: projects/maven/plugins/deployer/trunk/src/main/java/org/jboss/maven/plugin/deployer/UndeploymentsHandler.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF




More information about the jboss-cvs-commits mailing list