[jboss-svn-commits] JBL Code SVN: r9706 - in labs/jbossbuild/trunk/projects/maven-plugins/jboss-deploy-maven-plugin: src and 13 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Feb 22 12:38:24 EST 2007


Author: pgier
Date: 2007-02-22 12:38:23 -0500 (Thu, 22 Feb 2007)
New Revision: 9706

Added:
   labs/jbossbuild/trunk/projects/maven-plugins/jboss-deploy-maven-plugin/pom.xml
   labs/jbossbuild/trunk/projects/maven-plugins/jboss-deploy-maven-plugin/src/
   labs/jbossbuild/trunk/projects/maven-plugins/jboss-deploy-maven-plugin/src/main/
   labs/jbossbuild/trunk/projects/maven-plugins/jboss-deploy-maven-plugin/src/main/java/
   labs/jbossbuild/trunk/projects/maven-plugins/jboss-deploy-maven-plugin/src/main/java/org/
   labs/jbossbuild/trunk/projects/maven-plugins/jboss-deploy-maven-plugin/src/main/java/org/jboss/
   labs/jbossbuild/trunk/projects/maven-plugins/jboss-deploy-maven-plugin/src/main/java/org/jboss/maven/
   labs/jbossbuild/trunk/projects/maven-plugins/jboss-deploy-maven-plugin/src/main/java/org/jboss/maven/plugins/
   labs/jbossbuild/trunk/projects/maven-plugins/jboss-deploy-maven-plugin/src/main/java/org/jboss/maven/plugins/deploy/
   labs/jbossbuild/trunk/projects/maven-plugins/jboss-deploy-maven-plugin/src/main/java/org/jboss/maven/plugins/deploy/JBossDeployMojo.java
   labs/jbossbuild/trunk/projects/maven-plugins/jboss-deploy-maven-plugin/src/main/resources/
   labs/jbossbuild/trunk/projects/maven-plugins/jboss-deploy-maven-plugin/src/main/resources/org/
   labs/jbossbuild/trunk/projects/maven-plugins/jboss-deploy-maven-plugin/src/main/resources/org/jboss/
   labs/jbossbuild/trunk/projects/maven-plugins/jboss-deploy-maven-plugin/src/main/resources/org/jboss/maven/
   labs/jbossbuild/trunk/projects/maven-plugins/jboss-deploy-maven-plugin/src/main/resources/org/jboss/maven/plugins/
   labs/jbossbuild/trunk/projects/maven-plugins/jboss-deploy-maven-plugin/src/main/resources/org/jboss/maven/plugins/deploy/
   labs/jbossbuild/trunk/projects/maven-plugins/jboss-deploy-maven-plugin/src/main/resources/org/jboss/maven/plugins/deploy/component-info-template.xml
Log:
JBBUILD-340; Adding jboss-deploy-maven-plugin for deploying to jboss repository.

Added: labs/jbossbuild/trunk/projects/maven-plugins/jboss-deploy-maven-plugin/pom.xml
===================================================================
--- labs/jbossbuild/trunk/projects/maven-plugins/jboss-deploy-maven-plugin/pom.xml	                        (rev 0)
+++ labs/jbossbuild/trunk/projects/maven-plugins/jboss-deploy-maven-plugin/pom.xml	2007-02-22 17:38:23 UTC (rev 9706)
@@ -0,0 +1,58 @@
+<?xml version="1.0"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <parent>
+    <groupId>jboss</groupId>
+    <artifactId>jboss-parent</artifactId>
+    <version>1</version>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+  <artifactId>jboss-deploy-maven-plugin</artifactId>
+  <packaging>maven-plugin</packaging>
+  <name>JBoss Deploy Maven Plugin</name>
+  <version>1.0-SNAPSHOT</version>
+  <description>Plugin for deploying artifacts to JBoss non-maven repository.</description>
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <version>2.0</version>
+        <configuration>
+          <optimize>true</optimize>
+          <source>1.5</source>
+          <target>1.5</target>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+  <repositories>
+    <repository>
+      <snapshots />
+      <id>jboss</id>
+      <name>JBoss Repository</name>
+      <url>http://repository.jboss.com/maven2/</url>
+    </repository>
+  </repositories>
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-core</artifactId>
+      <version>2.0.4</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-plugin-api</artifactId>
+      <version>2.0</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-project</artifactId>
+      <version>2.0.4</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-artifact</artifactId>
+      <version>2.0.4</version>
+    </dependency>
+  </dependencies>
+</project>


Property changes on: labs/jbossbuild/trunk/projects/maven-plugins/jboss-deploy-maven-plugin/pom.xml
___________________________________________________________________
Name: svn:executable
   + *

Added: labs/jbossbuild/trunk/projects/maven-plugins/jboss-deploy-maven-plugin/src/main/java/org/jboss/maven/plugins/deploy/JBossDeployMojo.java
===================================================================
--- labs/jbossbuild/trunk/projects/maven-plugins/jboss-deploy-maven-plugin/src/main/java/org/jboss/maven/plugins/deploy/JBossDeployMojo.java	                        (rev 0)
+++ labs/jbossbuild/trunk/projects/maven-plugins/jboss-deploy-maven-plugin/src/main/java/org/jboss/maven/plugins/deploy/JBossDeployMojo.java	2007-02-22 17:38:23 UTC (rev 9706)
@@ -0,0 +1,272 @@
+package org.jboss.maven.plugins.deploy;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.nio.channels.FileChannel;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.Properties;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.MavenProjectHelper;
+
+/**
+ * Maven plugin for deploying to jboss repository.  By default
+ * it will bind to the deploy phase.
+ * 
+ * @phase deploy
+ * @goal jboss-deploy
+ * 
+ */
+public class JBossDeployMojo extends AbstractMojo
+{
+
+   private static String fileSep = System.getProperty("file.separator");
+
+   /**
+    * The Maven Project Object
+    *
+    * @parameter expression="${project}"
+    * @required
+    * @readonly
+    */
+   protected MavenProject project;
+
+   /**
+    * The Maven Plugin Object
+    *
+    * @parameter expression="${plugin.components}"
+    * @required
+    * @readonly
+    */
+   protected List pluginComponents;
+
+   /**
+    * Maven project properties.
+    *
+    * @parameter expression="${project.properties}"
+    * @required
+    * @readonly
+    */
+   protected Properties projectProperties;
+
+   /**
+    * The maven project helper.
+    *
+    * @parameter expression="${component.org.apache.maven.project.MavenProjectHelper}"
+    * @required
+    * @readonly
+    */
+   private MavenProjectHelper projectHelper;
+
+   /**
+    * The source directories containing the sources to be compiled.
+    *
+    * @parameter expression="${project.compileSourceRoots}"
+    * @required
+    * @readonly
+    */
+   private List compileSourceRoots;
+
+   /**
+    * The plugin dependencies.
+    *
+    * @parameter expression="${plugin.artifacts}"
+    * @required
+    * @readonly
+    */
+   private List pluginArtifacts;
+
+   /**
+    * @parameter expression="${project.pluginArtifacts}"
+    * @required
+    * @readonly
+    */
+   //private HashSet pluginArtifacts;
+   /**
+    * The directory for compiled classes.
+    *
+    * @parameter expression="${project.build.outputDirectory}"
+    * @required
+    * @readonly
+    */
+   private File targetClassesDirectory;
+
+   /**
+    * The directory for compiled classes.
+    *
+    * @parameter expression="${project.build.directory}"
+    * @required
+    * @readonly
+    */
+   private File targetDirectory;
+
+   /**
+    * Project artifacts.
+    *
+    * @parameter expression="${project.artifact}"
+    * @required
+    * @readonly
+    * @todo this is an export variable, really
+    */
+   private Artifact projectArtifact;
+
+   /**
+    * This is the location that the jboss repository (non-maven) files will be copied to.
+    * @parameter
+    * @required
+    */
+   private String jbossDeployRoot;
+
+   /**
+    * Main execution path of the plugin.
+    */
+   public void execute() throws MojoExecutionException
+   {
+      this.getLog().debug("Executing JBoss deploy plugin");
+
+      // Initialize local variables
+      String artifactFileName = project.getArtifactId() + "." + project.getPackaging();
+      String artifactFilePath = targetDirectory.toString() + fileSep + artifactFileName;
+      String artifactSourcesFilePath = targetDirectory.toString() + fileSep + project.getArtifactId() + "-sources" + "." + project.getPackaging();
+      String artifactJavadocFilePath = targetDirectory.toString() + fileSep + project.getArtifactId() + "-javadoc" + "." + project.getPackaging();
+      String artifactTestsFilePath = targetDirectory.toString() + fileSep + project.getArtifactId() + "-tests" + "." + project.getPackaging();
+      String deployToPath = jbossDeployRoot + fileSep + project.getGroupId() + fileSep + project.getArtifactId()
+            + fileSep + project.getVersion() + fileSep;
+      //String deployToArtifact = deployToPath + "lib" + fileSep + artifactFileName;
+
+      // Load template file
+      InputStream templateInputStream = this.getClass().getResourceAsStream("component-info-template.xml");
+
+      if (templateInputStream == null)
+      {
+         this.getLog().error("Unable to load template file");
+         return;
+      }
+      StringBuffer compInfoTemplate = new StringBuffer(1000);
+      try
+      {
+         BufferedReader reader = new BufferedReader(new InputStreamReader(templateInputStream));
+         char[] buf = new char[1000];
+         int numRead = 0;
+         while ((numRead = reader.read(buf)) != -1)
+         {
+            compInfoTemplate.append(String.valueOf(buf, 0, numRead));
+         }
+         reader.close();
+      }
+      catch (IOException ioe)
+      {
+         this.getLog().error("Unable to load component info template.");
+         this.getLog().error(ioe.toString());
+         throw new MojoExecutionException(ioe.getMessage());
+      }
+
+      // Evaluate the place holders in the template
+      String componentId = project.getGroupId() + "/" + project.getArtifactId();
+      evaluateVariable(compInfoTemplate, "project.name", componentId + "-component-info");
+      evaluateVariable(compInfoTemplate, "component.id", componentId);
+      evaluateVariable(compInfoTemplate, "project.version", project.getVersion());
+      evaluateVariable(compInfoTemplate, "project.license", "lgpl");
+      if (project.getDescription() == null || project.getDescription().equals(""))
+      {
+         project.setDescription(project.getId());
+      }
+      evaluateVariable(compInfoTemplate, "project.description", project.getDescription());
+
+      // Write the component info file
+      try
+      {
+         File deployToDir = new File(deployToPath);
+         if (!deployToDir.exists()) {
+            deployToDir.mkdirs();
+         }
+         File compInfoFile = new File(deployToPath + "component-info.xml");
+         FileWriter fw = new FileWriter(compInfoFile);
+         fw.write(compInfoTemplate.toString());
+         fw.close();
+      }
+      catch (IOException ioe)
+      {
+         ioe.printStackTrace();
+      }
+
+      Enumeration keys = projectProperties.keys();
+      while (keys.hasMoreElements())
+      {
+         String key = (String) keys.nextElement();
+         getLog().info(key + ": " + projectProperties.getProperty(key));
+      }
+      getLog().info(projectProperties.size() + "");
+
+      // Deploy lib directory.
+      getLog().debug("Copying from: " + artifactFilePath);
+      getLog().info("Deploying to: " + deployToPath);
+      String deployToPathLib = deployToPath + "lib" + fileSep;
+      try {
+         copyFileToDir(artifactFilePath, deployToPathLib);
+         copyFileToDir(artifactTestsFilePath, deployToPathLib);
+         copyFileToDir(artifactSourcesFilePath, deployToPathLib);
+         copyFileToDir(artifactJavadocFilePath, deployToPathLib);
+      } catch (IOException ioe) {
+         throw new MojoExecutionException("Problem copying artifacts: " + ioe.getMessage());
+      }
+   }
+
+   /**
+    * Copy a file from the source path to the destination.
+    * 
+    * @param src The file to copy.  If the source file does not exist, the method does nothing.
+    * @param dest The directory to copy the file.  If the dest path does not exist,
+    *     any necessary folders will be created.
+    */
+   public void copyFileToDir(String src, String dest) throws IOException
+   {
+      File srcFile = new File(src);
+      if (!srcFile.exists()) {
+         return;
+      }
+      File destDir = new File(dest);
+      if (!destDir.exists())
+      {
+         destDir.mkdirs();
+      }
+      File destFile = new File(destDir.getCanonicalPath() + fileSep + srcFile.getName());
+      FileChannel srcChannel = new FileInputStream(srcFile).getChannel();
+      FileChannel dstChannel = new FileOutputStream(destFile).getChannel();
+      dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
+      srcChannel.close();
+      dstChannel.close();
+      this.getLog().debug("Copied to file: " + destFile.getCanonicalPath());
+   }
+
+   /**
+    * Replace all instances of var with value in the given buffer.
+    * For example if var is project.name, this method will search
+    * the buffer for "${project.name}" and replace it with the value
+    * provided.
+    * 
+    * @param buffer The buffer to be modified
+    * @param var The name of the variable to be evaluated.
+    * @param value The replacement string.
+    */
+   public void evaluateVariable(StringBuffer buffer, String var, String value)
+   {
+      int start = 0;
+      while ((start = buffer.indexOf("${" + var + "}")) != -1)
+      {
+         int end = start + ("${" + var + "}").length();
+         buffer.replace(start, end, value);
+      }
+   }
+
+}


Property changes on: labs/jbossbuild/trunk/projects/maven-plugins/jboss-deploy-maven-plugin/src/main/java/org/jboss/maven/plugins/deploy/JBossDeployMojo.java
___________________________________________________________________
Name: svn:executable
   + *

Added: labs/jbossbuild/trunk/projects/maven-plugins/jboss-deploy-maven-plugin/src/main/resources/org/jboss/maven/plugins/deploy/component-info-template.xml
===================================================================
--- labs/jbossbuild/trunk/projects/maven-plugins/jboss-deploy-maven-plugin/src/main/resources/org/jboss/maven/plugins/deploy/component-info-template.xml	                        (rev 0)
+++ labs/jbossbuild/trunk/projects/maven-plugins/jboss-deploy-maven-plugin/src/main/resources/org/jboss/maven/plugins/deploy/component-info-template.xml	2007-02-22 17:38:23 UTC (rev 9706)
@@ -0,0 +1,17 @@
+
+<project name="${project.name}">
+  <component id="${component.id}"
+             licenseType="${project.license}"
+             version="${project.version}"
+             description="${project.description}"
+             >
+  
+    <artifact id="jboss-common-core.jar"/>
+    <artifact id="jboss-common-core-sources.jar"/>
+
+    <export>
+      <include input="jboss-common-core.jar"/>
+    </export>
+
+  </component>
+</project>
\ No newline at end of file




More information about the jboss-svn-commits mailing list