[jboss-svn-commits] JBL Code SVN: r19757 - labs/jbosslabs/labs-3.0-build/maven-labs-plugin/src/main/java/org/jboss/labs/plugin.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue Apr 29 08:48:01 EDT 2008


Author: unibrew
Date: 2008-04-29 08:48:01 -0400 (Tue, 29 Apr 2008)
New Revision: 19757

Added:
   labs/jbosslabs/labs-3.0-build/maven-labs-plugin/src/main/java/org/jboss/labs/plugin/LabsClearspaceDeployPlugin.java
   labs/jbosslabs/labs-3.0-build/maven-labs-plugin/src/main/java/org/jboss/labs/plugin/LabsClearspaceMojo.java
   labs/jbosslabs/labs-3.0-build/maven-labs-plugin/src/main/java/org/jboss/labs/plugin/LabsClearspaceSetupPlugin.java
Modified:
   labs/jbosslabs/labs-3.0-build/maven-labs-plugin/src/main/java/org/jboss/labs/plugin/LabsMojo.java
   labs/jbosslabs/labs-3.0-build/maven-labs-plugin/src/main/java/org/jboss/labs/plugin/LabsSetupMojo.java
Log:
[JBLAB-948] Maven plugin for CS build.

Added: labs/jbosslabs/labs-3.0-build/maven-labs-plugin/src/main/java/org/jboss/labs/plugin/LabsClearspaceDeployPlugin.java
===================================================================
--- labs/jbosslabs/labs-3.0-build/maven-labs-plugin/src/main/java/org/jboss/labs/plugin/LabsClearspaceDeployPlugin.java	                        (rev 0)
+++ labs/jbosslabs/labs-3.0-build/maven-labs-plugin/src/main/java/org/jboss/labs/plugin/LabsClearspaceDeployPlugin.java	2008-04-29 12:48:01 UTC (rev 19757)
@@ -0,0 +1,133 @@
+/*
+ * JBoss Labs. http://labs.jboss.com/jbosslabs
+ * 
+ * Copyright � 2008  Red Hat Middleware, LLC. All rights reserved.
+ * 
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT A 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, v.2.1 along with this distribution; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ * 
+ * Red Hat Author(s): Bob McWhirter, Przemyslaw Dej, Ryszard Kozmik, 
+ *      Tomasz Szymanski, Adam Warski, Pawel Wrzeszcz
+ */
+package org.jboss.labs.plugin;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+
+/**
+ * 
+ * @author <a href="ryszard.kozmik at jboss.com">Ryszard Kozmik</a>
+ * @goal cs-deploy
+ * @phase install
+ *
+ */
+public class LabsClearspaceDeployPlugin extends LabsClearspaceMojo
+{
+
+    /**
+     * File to deploy
+     * 
+     * @parameter expression="${project.build.directory}/${project.build.finalName}.${project.packaging}"
+     * @required
+     */
+    private File fileToDeploy;
+
+    /**
+     * Name of the file on server. If not set, original name will be used.
+     * 
+     * @parameter
+     */
+    private String fileFinalName;
+
+    /**
+     * Can be set to false, to switch off a specified project from deployment
+     * (such as ear components).
+     * 
+     * @parameter default-value="false"
+     * @required
+     */
+    private boolean csDeploy;
+
+    /**
+     * Property used to determine if we're inside allowed packaging - if yes, it
+     * will be ignored.
+     * 
+     * @parameter expression="${project.packaging}"
+     * @required
+     */
+    private String packaging;
+
+    /**
+     * Coma-separated list of allowed packagings in build
+     * 
+     * @parameter default-value="jar,ear,ejb,war,sar,rar"
+     * @required
+     */
+    private String allowedPackagings;
+
+    @Override
+    protected void executeLabs() throws MojoExecutionException,
+                    MojoFailureException {
+            String[] packs = allowedPackagings.split(",");
+
+            if (checkPackaging(packs) && csDeploy) {
+                    if (!fileToDeploy.exists() || fileToDeploy.isDirectory()) {
+                            throw new MojoExecutionException("File "
+                                            + fileToDeploy.getAbsolutePath()
+                                            + " doesn't exist or points to a directory.");
+                    }
+
+                    File finalFile = new File(clearspaceHome.getAbsoluteFile()
+                                    + "/"
+                                    + "webapps"
+                                    + "/"
+                                    + (fileFinalName == null ? fileToDeploy.getName()
+                                                    : fileFinalName));
+
+                    if (!finalFile.exists()) {
+                            try {
+                                    finalFile.createNewFile();
+                            } catch (IOException e) {
+                                    throw new MojoExecutionException("Unable to create file: "
+                                                    + finalFile.getAbsolutePath(), e);
+                            }
+                    }
+
+                    getLog().info(
+                                    "Deploying " + fileToDeploy.getAbsolutePath() + " to "
+                                                    + finalFile.getAbsolutePath());
+
+                    // finally copy the file
+                    copyFile(fileToDeploy, finalFile);
+
+            }
+
+    }
+
+    private boolean checkPackaging(String[] packs) {
+            for (String s : packs) {
+                    if (s.equals(packaging)) {
+                            return true;
+                    }
+            }
+
+            getLog().info(packaging + " is not allowed packaging for deployment");
+
+            return false;
+    }
+
+}

Added: labs/jbosslabs/labs-3.0-build/maven-labs-plugin/src/main/java/org/jboss/labs/plugin/LabsClearspaceMojo.java
===================================================================
--- labs/jbosslabs/labs-3.0-build/maven-labs-plugin/src/main/java/org/jboss/labs/plugin/LabsClearspaceMojo.java	                        (rev 0)
+++ labs/jbosslabs/labs-3.0-build/maven-labs-plugin/src/main/java/org/jboss/labs/plugin/LabsClearspaceMojo.java	2008-04-29 12:48:01 UTC (rev 19757)
@@ -0,0 +1,71 @@
+/*
+ * JBoss Labs. http://labs.jboss.com/jbosslabs
+ * 
+ * Copyright � 2008  Red Hat Middleware, LLC. All rights reserved.
+ * 
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT A 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, v.2.1 along with this distribution; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ * 
+ * Red Hat Author(s): Bob McWhirter, Przemyslaw Dej, Ryszard Kozmik, 
+ *      Tomasz Szymanski, Adam Warski, Pawel Wrzeszcz
+ */
+package org.jboss.labs.plugin;
+
+import java.io.File;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+
+/**
+ * 
+ * @author <a href="ryszard.kozmik at jboss.com">Ryszard Kozmik</a>
+ *
+ */
+public abstract class LabsClearspaceMojo extends LabsMojo
+{
+    
+    private static final String CLEARSPACE_HOME="CLEARSPACE_HOME";
+    
+    protected File clearspaceHome;
+
+    public void execute() throws MojoExecutionException,
+            MojoFailureException
+    {
+
+        // load properties
+        loadProperties(project);
+        
+        // Check parameters
+
+        if (clearspaceHome == null)
+        {
+
+            if (System.getProperty(CLEARSPACE_HOME) != null)
+            {
+                clearspaceHome = new File(System.getProperty(CLEARSPACE_HOME));
+            } else if (System.getenv(CLEARSPACE_HOME) != null)
+            {
+                clearspaceHome = new File(System.getenv(CLEARSPACE_HOME));
+            } else
+            {
+                throw new MojoExecutionException(
+                        "jbossDirectory property is not set. Please set either $CLEARSPACE_HOME or the property");
+            }
+        }
+
+        // execute plugin
+        executeLabs();
+    }
+
+}

Added: labs/jbosslabs/labs-3.0-build/maven-labs-plugin/src/main/java/org/jboss/labs/plugin/LabsClearspaceSetupPlugin.java
===================================================================
--- labs/jbosslabs/labs-3.0-build/maven-labs-plugin/src/main/java/org/jboss/labs/plugin/LabsClearspaceSetupPlugin.java	                        (rev 0)
+++ labs/jbosslabs/labs-3.0-build/maven-labs-plugin/src/main/java/org/jboss/labs/plugin/LabsClearspaceSetupPlugin.java	2008-04-29 12:48:01 UTC (rev 19757)
@@ -0,0 +1,127 @@
+/*
+ * JBoss Labs. http://labs.jboss.com/jbosslabs
+ * 
+ * Copyright � 2008  Red Hat Middleware, LLC. All rights reserved.
+ * 
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT A 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, v.2.1 along with this distribution; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ * 
+ * Red Hat Author(s): Bob McWhirter, Przemyslaw Dej, Ryszard Kozmik, 
+ *      Tomasz Szymanski, Adam Warski, Pawel Wrzeszcz
+ */
+package org.jboss.labs.plugin;
+
+import java.io.File;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+
+/**
+ * 
+ * @author <a href="ryszard.kozmik at jboss.com">Ryszard Kozmik</a>
+ * @goal cs-setup
+ * @phase process-resources
+ *
+ */
+public class LabsClearspaceSetupPlugin extends LabsClearspaceMojo
+{
+
+    private static final String HOME = "HOME";
+
+    private static final String DEPLOY = "DEPLOY";
+
+    private static final String CONF = "CONF";
+
+    /**
+     * Set to true if you want to use this project in your setup phase
+     * 
+     * @parameter default-value="false"
+     * @required
+     */
+    private boolean csSetupable;
+
+    /**
+     * Folder with resources to be copied
+     * 
+     * @parameter expression="${project.basedir}/resources"
+     * @required
+     */
+    private File resourcesFolder;
+
+    /**
+     * Target folder where resources will be copied. Use HOME for clearspaceHome,
+     * DEPLOY for ${clearspaceHome}/webapps, CONF for
+     * ${clearspaceHome}/conf or anything else to copy to
+     * ${clearspaceHome}/${toFolder}
+     * 
+     * @parameter default-value="DEPLOY"
+     * @required
+     */
+    private String destinationFolder;
+
+    /**
+     * Regular expression that describes list of files to include. Please note
+     * that includes has a higher priority then excludes.
+     * 
+     * @parameter
+     */
+    private String includes;
+
+    /**
+     * Regular expression that describes list of files to exclude. Please note
+     * that includes has a higher priority then excludes.
+     * 
+     * @parameter
+     */
+    private String excludes;
+
+    protected void executeLabs() throws MojoExecutionException,
+                    MojoFailureException {
+            if (csSetupable) {
+                    String copyTo;
+
+                    if (destinationFolder.startsWith(HOME)) {
+                            copyTo = clearspaceHome.getAbsolutePath()
+                                            + destinationFolder.substring(HOME.length());
+                    } else if (destinationFolder.startsWith(DEPLOY)) {
+                            copyTo = clearspaceHome.getAbsolutePath() + "/webapps"
+                                            + destinationFolder.substring(DEPLOY.length());
+                    } else if (destinationFolder.startsWith(CONF)) {
+                            copyTo = clearspaceHome.getAbsolutePath() + destinationFolder.substring(CONF.length());
+                    } else {
+                            copyTo = clearspaceHome.getAbsolutePath() + "/" + destinationFolder;
+                    }
+
+                    File copyToDir = new File(copyTo);
+
+                    // check if it exists and is a directory
+                    if (copyToDir.exists() && !copyToDir.isDirectory()) {
+                            throw new MojoExecutionException(copyTo + " is not a directory");
+                    }
+                    // if it doesn't exist - try to create dirs
+                    else if (!copyToDir.exists() && !copyToDir.mkdirs()) {
+                            throw new MojoExecutionException(
+                                            "Unable to create directory structure for " + copyTo);
+                    }
+
+                    getLog().info(
+                                    "Seting Up " + resourcesFolder.getAbsolutePath() + " to "
+                                                    + copyTo);
+
+                    copyDir(resourcesFolder, copyToDir, new LabsFilenameFilter(includes,
+                                    excludes));
+            }
+    }
+
+}

Modified: labs/jbosslabs/labs-3.0-build/maven-labs-plugin/src/main/java/org/jboss/labs/plugin/LabsMojo.java
===================================================================
--- labs/jbosslabs/labs-3.0-build/maven-labs-plugin/src/main/java/org/jboss/labs/plugin/LabsMojo.java	2008-04-29 12:15:48 UTC (rev 19756)
+++ labs/jbosslabs/labs-3.0-build/maven-labs-plugin/src/main/java/org/jboss/labs/plugin/LabsMojo.java	2008-04-29 12:48:01 UTC (rev 19757)
@@ -1,7 +1,7 @@
 /*
  * JBoss Labs. http://labs.jboss.com/jbosslabs
  * 
- * Copyright © 2008  Red Hat Middleware, LLC. All rights reserved.
+ * Copyright � 2008  Red Hat Middleware, LLC. All rights reserved.
  * 
  * This copyrighted material is made available to anyone wishing to use,
  * modify, copy, or redistribute it subject to the terms and conditions
@@ -64,9 +64,9 @@
 	 * 
 	 * @parameter expression="${project}"
 	 */
-	private MavenProject project;
+	protected MavenProject project;
 
-	public final void execute() throws MojoExecutionException,
+	public void execute() throws MojoExecutionException,
 			MojoFailureException {
 
 		// load properties
@@ -90,7 +90,7 @@
 		executeLabs();
 	}
 
-	private void loadProperties(MavenProject project) {
+	protected void loadProperties(MavenProject project) {
 		if (project.getParent() != null) {
 			loadProperties(project.getParent());
 		}

Modified: labs/jbosslabs/labs-3.0-build/maven-labs-plugin/src/main/java/org/jboss/labs/plugin/LabsSetupMojo.java
===================================================================
--- labs/jbosslabs/labs-3.0-build/maven-labs-plugin/src/main/java/org/jboss/labs/plugin/LabsSetupMojo.java	2008-04-29 12:15:48 UTC (rev 19756)
+++ labs/jbosslabs/labs-3.0-build/maven-labs-plugin/src/main/java/org/jboss/labs/plugin/LabsSetupMojo.java	2008-04-29 12:48:01 UTC (rev 19757)
@@ -1,7 +1,7 @@
 /*
  * JBoss Labs. http://labs.jboss.com/jbosslabs
  * 
- * Copyright © 2008  Red Hat Middleware, LLC. All rights reserved.
+ * Copyright � 2008  Red Hat Middleware, LLC. All rights reserved.
  * 
  * This copyrighted material is made available to anyone wishing to use,
  * modify, copy, or redistribute it subject to the terms and conditions




More information about the jboss-svn-commits mailing list