[jboss-cvs] JBossAS SVN: r72360 - in projects/maven/plugins/deployer/trunk/src/test/resources: test-jboss-home and 7 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Apr 17 10:20:35 EDT 2008
Author: thomas.diesler at jboss.com
Date: 2008-04-17 10:20:34 -0400 (Thu, 17 Apr 2008)
New Revision: 72360
Added:
projects/maven/plugins/deployer/trunk/src/test/resources/test-jboss-home/
projects/maven/plugins/deployer/trunk/src/test/resources/test-jboss-home/bin/
projects/maven/plugins/deployer/trunk/src/test/resources/test-jboss-home/bin/org/
projects/maven/plugins/deployer/trunk/src/test/resources/test-jboss-home/bin/org/jboss/
projects/maven/plugins/deployer/trunk/src/test/resources/test-jboss-home/bin/org/jboss/maven/
projects/maven/plugins/deployer/trunk/src/test/resources/test-jboss-home/bin/org/jboss/maven/plugin/
projects/maven/plugins/deployer/trunk/src/test/resources/test-jboss-home/bin/org/jboss/maven/plugin/deployer/
projects/maven/plugins/deployer/trunk/src/test/resources/test-jboss-home/bin/org/jboss/maven/plugin/deployer/AbstractDeployerMojo.java
projects/maven/plugins/deployer/trunk/src/test/resources/test-jboss-home/bin/org/jboss/maven/plugin/deployer/DeployerMojo.java
projects/maven/plugins/deployer/trunk/src/test/resources/test-jboss-home/bin/org/jboss/maven/plugin/deployer/Deployment.java
projects/maven/plugins/deployer/trunk/src/test/resources/test-jboss-home/bin/org/jboss/maven/plugin/deployer/UndeployerMojo.java
projects/maven/plugins/deployer/trunk/src/test/resources/test-jboss-home/bin/org/jboss/maven/plugin/deployer/handlers/
projects/maven/plugins/deployer/trunk/src/test/resources/test-jboss-home/bin/org/jboss/maven/plugin/deployer/handlers/DependenciesHandler.java
projects/maven/plugins/deployer/trunk/src/test/resources/test-jboss-home/bin/org/jboss/maven/plugin/deployer/handlers/DeploymentsHandler.java
projects/maven/plugins/deployer/trunk/src/test/resources/test-jboss-home/bin/org/jboss/maven/plugin/deployer/handlers/UndeploymentsHandler.java
projects/maven/plugins/deployer/trunk/src/test/resources/test-jboss-home/deploy-layout.txt
Log:
deploy/undeploy, ok
Added: projects/maven/plugins/deployer/trunk/src/test/resources/test-jboss-home/bin/org/jboss/maven/plugin/deployer/AbstractDeployerMojo.java
===================================================================
--- projects/maven/plugins/deployer/trunk/src/test/resources/test-jboss-home/bin/org/jboss/maven/plugin/deployer/AbstractDeployerMojo.java (rev 0)
+++ projects/maven/plugins/deployer/trunk/src/test/resources/test-jboss-home/bin/org/jboss/maven/plugin/deployer/AbstractDeployerMojo.java 2008-04-17 14:20:34 UTC (rev 72360)
@@ -0,0 +1,252 @@
+/*
+ * 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.List;
+
+import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.resolver.ArtifactCollector;
+import org.apache.maven.artifact.resolver.ArtifactResolver;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.archiver.manager.ArchiverManager;
+
+/**
+ *
+ *
+ * @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
+ */
+ protected ArtifactFactory factory;
+
+ /**
+ * Used to look up Artifacts in the remote repository.
+ *
+ * @parameter expression="${component.org.apache.maven.artifact.resolver.ArtifactResolver}"
+ * @required
+ * @readonly
+ */
+ protected ArtifactResolver resolver;
+
+ /**
+ * Artifact collector, needed to resolve dependencies.
+ *
+ * @component role="org.apache.maven.artifact.resolver.ArtifactCollector"
+ * @required
+ * @readonly
+ */
+ protected ArtifactCollector artifactCollector;
+
+ /**
+ * @component role="org.apache.maven.artifact.metadata.ArtifactMetadataSource"
+ * hint="maven"
+ * @required
+ * @readonly
+ */
+ protected ArtifactMetadataSource artifactMetadataSource;
+
+ /**
+ * Location of the local repository.
+ *
+ * @parameter expression="${localRepository}"
+ * @readonly
+ * @required
+ */
+ protected ArtifactRepository localRepository;
+
+ /**
+ * List of Remote Repositories used by the resolver
+ *
+ * @parameter expression="${project.remoteArtifactRepositories}"
+ * @readonly
+ * @required
+ */
+ protected List remoteRepos;
+
+ /**
+ * To look up Archiver/UnArchiver implementations
+ *
+ * @parameter expression="${component.org.codehaus.plexus.archiver.manager.ArchiverManager}"
+ * @required
+ * @readonly
+ */
+ protected ArchiverManager archiverManager;
+
+ /**
+ * POM
+ *
+ * @parameter expression="${project}"
+ * @readonly
+ * @required
+ */
+ protected MavenProject project;
+
+ /**
+ * Contains the full list of projects in the reactor.
+ *
+ * @parameter expression="${reactorProjects}"
+ * @required
+ * @readonly
+ */
+ protected List reactorProjects;
+
+ /**
+ * The required jboss home location.
+ * i.e. ~/svn/jbossas/tags/JBoss_5_0_0_Beta4/build/output/jboss-5.0.0.Beta4
+ *
+ * @required
+ * @parameter
+ */
+ protected File jbossHome;
+
+ /**
+ * An optional list of files to undeploy
+ * @parameter
+ */
+ protected List<String> undeploy;
+
+ /**
+ * The optional temporary deployment directory
+ * @parameter
+ */
+ protected File layoutDirectory;
+
+ /**
+ * The optional list of dependencies
+ * @parameter
+ */
+ private List<Deployment> dependencies;
+
+ /**
+ * The optional layout result file
+ * This file can be used by the @see{UndeployerMojo}
+ * @parameter
+ */
+ protected File layoutResult;
+
+ /**
+ * An optional falg to temporary deploy structure
+ * @parameter default-value="false"
+ */
+ protected boolean keepLayout;
+
+ /**
+ * The optional list of deployments
+ * @parameter
+ */
+ private List<Deployment> deployments;
+
+ public ArchiverManager getArchiverManager()
+ {
+ return archiverManager;
+ }
+
+ public ArtifactCollector getArtifactCollector()
+ {
+ return artifactCollector;
+ }
+
+ public ArtifactMetadataSource getArtifactMetadataSource()
+ {
+ return artifactMetadataSource;
+ }
+
+ public ArtifactFactory getFactory()
+ {
+ return factory;
+ }
+
+ public ArtifactRepository getLocal()
+ {
+ return localRepository;
+ }
+
+ public MavenProject getProject()
+ {
+ return project;
+ }
+
+ public List getReactorProjects()
+ {
+ return reactorProjects;
+ }
+
+ public List getRemoteRepos()
+ {
+ return remoteRepos;
+ }
+
+ public ArtifactResolver getResolver()
+ {
+ return resolver;
+ }
+
+ public File getJBossHome()
+ {
+ return jbossHome;
+ }
+
+ public List<String> getUndeploy()
+ {
+ return undeploy;
+ }
+
+ public File getLayoutDirectory()
+ {
+ return layoutDirectory;
+ }
+
+ public List<Deployment> getDependencies()
+ {
+ return dependencies;
+ }
+
+ public List<Deployment> getDeployments()
+ {
+ return deployments;
+ }
+
+ public File getLayoutResult()
+ {
+ return layoutResult;
+ }
+
+ public boolean isKeepLayout()
+ {
+ return keepLayout;
+ }
+
+}
Property changes on: projects/maven/plugins/deployer/trunk/src/test/resources/test-jboss-home/bin/org/jboss/maven/plugin/deployer/AbstractDeployerMojo.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: projects/maven/plugins/deployer/trunk/src/test/resources/test-jboss-home/bin/org/jboss/maven/plugin/deployer/DeployerMojo.java
===================================================================
--- projects/maven/plugins/deployer/trunk/src/test/resources/test-jboss-home/bin/org/jboss/maven/plugin/deployer/DeployerMojo.java (rev 0)
+++ projects/maven/plugins/deployer/trunk/src/test/resources/test-jboss-home/bin/org/jboss/maven/plugin/deployer/DeployerMojo.java 2008-04-17 14:20:34 UTC (rev 72360)
@@ -0,0 +1,143 @@
+/*
+ * 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.FileWriter;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.codehaus.plexus.util.FileUtils;
+import org.jboss.maven.plugin.deployer.handlers.DependenciesHandler;
+import org.jboss.maven.plugin.deployer.handlers.DeploymentsHandler;
+import org.jboss.maven.plugin.deployer.handlers.UndeploymentsHandler;
+
+/**
+ * Goal which copies files and dependencies to jboss
+ *
+ * @goal deploy-jboss
+ * @phase package
+ *
+ * @author Thomas.Diesler at jboss.com
+ * @since 16-Apr-2008
+ */
+public class DeployerMojo extends AbstractDeployerMojo
+{
+ public static final String PLUGIN_GROUPID = "org.jboss.maven.plugin";
+ public static final String PLUGIN_ARTIFACTID = "maven-deployer-plugin";
+ public static final String PLUGIN_ID = PLUGIN_GROUPID + ":" + PLUGIN_ARTIFACTID;
+
+ public void execute() throws MojoExecutionException
+ {
+ try
+ {
+ validateConfiguration();
+
+ getLog().info("jbossHome=" + jbossHome);
+ getLog().info("layoutDirectory=" + layoutDirectory);
+
+ // recreate deploy structure
+ FileUtils.deleteDirectory(layoutDirectory);
+ layoutDirectory.mkdirs();
+
+ UndeploymentsHandler.process(this);
+ DeploymentsHandler.process(this);
+ DependenciesHandler.process(this);
+
+ writeLayoutResult();
+ copyLayout();
+ }
+ catch (IOException ex)
+ {
+ throw new MojoExecutionException("Cannot process goal 'deploy-jboss'", ex);
+ }
+ finally
+ {
+ if (keepLayout == false && layoutDirectory != null)
+ layoutDirectory.delete();
+ }
+ }
+
+ private void writeLayoutResult() throws IOException
+ {
+ if (layoutResult != null)
+ {
+ PrintWriter out = new PrintWriter(new FileWriter(layoutResult));
+ if (project != null)
+ {
+ out.println("# ProjectName: " + project.getName());
+ out.println("# ProjectVersion: " + project.getVersion());
+ out.println("#");
+ Map pluginMap = project.getPluginArtifactMap();
+ Artifact plugin = (Artifact)pluginMap.get(PLUGIN_ID);
+ out.println("# PluginId: " + PLUGIN_ID);
+ out.println("# PluginVersion: " + plugin.getVersion());
+ out.println("#");
+ }
+ SimpleDateFormat dateFormat = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss");
+ out.println("# Date: " + dateFormat.format(new Date()));
+ out.println("# User: " + System.getProperty("user.name"));
+ out.println("#");
+
+ List<File> files = FileUtils.getFiles(layoutDirectory, null, null);
+ String layoutPath = layoutDirectory.getCanonicalPath();
+ for (File file : files)
+ {
+ String filePath = file.getCanonicalPath();
+ out.println(filePath.substring(layoutPath.length() + 1));
+ }
+ out.close();
+ }
+ }
+
+ private void copyLayout() throws IOException
+ {
+ List<File> files = FileUtils.getFiles(layoutDirectory, null, null);
+ DeploymentsHandler.copyFiles(files, layoutDirectory, jbossHome);
+ }
+
+ private void validateConfiguration() throws MojoExecutionException, IOException
+ {
+ if (jbossHome.exists() == false)
+ {
+ jbossHome.mkdirs();
+ getLog().warn("Creating non existant jbossHome: " + jbossHome);
+ }
+
+ if (layoutDirectory == null)
+ {
+ File tmpFile = File.createTempFile(PLUGIN_ARTIFACTID, "");
+ getLog().debug("layoutDirectory: " + tmpFile);
+ tmpFile.delete();
+ tmpFile.mkdirs();
+ layoutDirectory = tmpFile;
+ }
+ }
+}
Property changes on: projects/maven/plugins/deployer/trunk/src/test/resources/test-jboss-home/bin/org/jboss/maven/plugin/deployer/DeployerMojo.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: projects/maven/plugins/deployer/trunk/src/test/resources/test-jboss-home/bin/org/jboss/maven/plugin/deployer/Deployment.java
===================================================================
--- projects/maven/plugins/deployer/trunk/src/test/resources/test-jboss-home/bin/org/jboss/maven/plugin/deployer/Deployment.java (rev 0)
+++ projects/maven/plugins/deployer/trunk/src/test/resources/test-jboss-home/bin/org/jboss/maven/plugin/deployer/Deployment.java 2008-04-17 14:20:34 UTC (rev 72360)
@@ -0,0 +1,107 @@
+/*
+ * 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.List;
+
+import org.apache.maven.plugin.MojoExecutionException;
+
+/**
+ * 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 File sourceDir;
+
+ /**
+ * The optional list of includes
+ * @parameter
+ */
+ private List<String> includes;
+
+ /**
+ * The optional list of excludes
+ * @parameter
+ */
+ private List<String> excludes;
+
+ public File getSourceDir()
+ {
+ return sourceDir;
+ }
+
+ public String getTargetDir()
+ {
+ return targetDir;
+ }
+
+ public List<String> getIncludes()
+ {
+ return includes;
+ }
+
+ public List<String> getExcludes()
+ {
+ return excludes;
+ }
+
+ public void validateConfiguration(AbstractDeployerMojo mojo, boolean sourceRequired) throws MojoExecutionException
+ {
+ String artifactId = DeployerMojo.PLUGIN_ARTIFACTID;
+
+ if (targetDir == null)
+ {
+ 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");
+ }
+ }
+}
Property changes on: projects/maven/plugins/deployer/trunk/src/test/resources/test-jboss-home/bin/org/jboss/maven/plugin/deployer/Deployment.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: projects/maven/plugins/deployer/trunk/src/test/resources/test-jboss-home/bin/org/jboss/maven/plugin/deployer/UndeployerMojo.java
===================================================================
--- projects/maven/plugins/deployer/trunk/src/test/resources/test-jboss-home/bin/org/jboss/maven/plugin/deployer/UndeployerMojo.java (rev 0)
+++ projects/maven/plugins/deployer/trunk/src/test/resources/test-jboss-home/bin/org/jboss/maven/plugin/deployer/UndeployerMojo.java 2008-04-17 14:20:34 UTC (rev 72360)
@@ -0,0 +1,99 @@
+/*
+ * 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.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.codehaus.plexus.util.FileUtils;
+import org.jboss.maven.plugin.deployer.handlers.UndeploymentsHandler;
+
+/**
+ * Goal which deletes files from jboss
+ *
+ * @goal undeploy-jboss
+ *
+ * @author Thomas.Diesler at jboss.com
+ * @since 16-Apr-2008
+ */
+public class UndeployerMojo extends AbstractDeployerMojo
+{
+ public void execute() throws MojoExecutionException
+ {
+ try
+ {
+ validateConfiguration();
+
+ getLog().info("jbossHome: " + jbossHome);
+
+ UndeploymentsHandler.process(this);
+ processLayoutResult();
+ }
+ catch (IOException ex)
+ {
+ throw new MojoExecutionException("Cannot process goal 'deploy-jboss'", ex);
+ }
+ }
+
+ private void processLayoutResult() throws IOException
+ {
+ if (layoutResult != null)
+ {
+ BufferedReader reader = new BufferedReader(new FileReader(layoutResult));
+ String line = reader.readLine();
+ while (line != null)
+ {
+ if (line.startsWith("#") == false)
+ {
+ File file = new File(jbossHome + "/" + line);
+ if (file.isDirectory())
+ {
+ FileUtils.deleteDirectory(file.getCanonicalPath());
+ getLog().info(" +- " + line + " (directory)");
+ }
+ else if (file.exists())
+ {
+ file.delete();
+ getLog().info(" +- " + line + " (file)");
+ }
+ else
+ {
+ getLog().info(" +- " + line + " (not found)");
+ }
+ }
+ line = reader.readLine();
+ }
+ reader.close();
+ }
+ }
+
+ private void validateConfiguration() throws MojoExecutionException, IOException
+ {
+ if (jbossHome.exists() == false)
+ throw new MojoExecutionException("jbossHome does not exist: " + jbossHome);
+ }
+}
Property changes on: projects/maven/plugins/deployer/trunk/src/test/resources/test-jboss-home/bin/org/jboss/maven/plugin/deployer/UndeployerMojo.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: projects/maven/plugins/deployer/trunk/src/test/resources/test-jboss-home/bin/org/jboss/maven/plugin/deployer/handlers/DependenciesHandler.java
===================================================================
--- projects/maven/plugins/deployer/trunk/src/test/resources/test-jboss-home/bin/org/jboss/maven/plugin/deployer/handlers/DependenciesHandler.java (rev 0)
+++ projects/maven/plugins/deployer/trunk/src/test/resources/test-jboss-home/bin/org/jboss/maven/plugin/deployer/handlers/DependenciesHandler.java 2008-04-17 14:20:34 UTC (rev 72360)
@@ -0,0 +1,157 @@
+/*
+ * 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.handlers;
+
+//$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.CopyDependenciesMojo;
+import org.apache.maven.plugin.dependency.utils.DependencyStatusSets;
+import org.apache.maven.project.MavenProject;
+import org.jboss.maven.plugin.deployer.AbstractDeployerMojo;
+import org.jboss.maven.plugin.deployer.Deployment;
+
+public class DependenciesHandler
+{
+ private AbstractDeployerMojo mojo;
+
+ private DependenciesHandler(AbstractDeployerMojo mojo)
+ {
+ this.mojo = mojo;
+ }
+
+ public static void process(AbstractDeployerMojo 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;
+ ExtCopyDependenciesMojo depMojo = new ExtCopyDependenciesMojo();
+ depMojo.setFactory(mojo.getFactory());
+ depMojo.setResolver(mojo.getResolver());
+ depMojo.setArtifactCollector(mojo.getArtifactCollector());
+ depMojo.setArtifactMetadataSource(mojo.getArtifactMetadataSource());
+ depMojo.setLocal(mojo.getLocal());
+ depMojo.setRemoteRepos(mojo.getRemoteRepos());
+ depMojo.setArchiverManager(mojo.getArchiverManager());
+ depMojo.setReactorProjects(mojo.getReactorProjects());
+ depMojo.setProject(mojo.getProject());
+ depMojo.setLog(mojo.getLog());
+ depMojo.setStripVersion(stripVersion);
+ depMojo.setCopyPom(false);
+ depMojo.setSilent(true);
+
+ File outputDirectory = new File(mojo.getLayoutDirectory() + "/" + dep.getTargetDir());
+ mojo.getLog().info(" +- " + dep.getTargetDir());
+
+ depMojo.setOutputDirectory(outputDirectory);
+
+ List<String> includes = dep.getIncludes();
+ if (includes != null)
+ {
+ String includeArtifactIds = includes.toString();
+ includeArtifactIds = includeArtifactIds.substring(1, includeArtifactIds.length() - 1);
+ depMojo.setIncludeArtifactIds(includeArtifactIds);
+ }
+
+ List<String> excludes = dep.getExcludes();
+ if (excludes != null)
+ {
+ String excludeArtifactIds = excludes.toString();
+ excludeArtifactIds = excludeArtifactIds.substring(1, excludeArtifactIds.length() - 1);
+ depMojo.setExcludeArtifactIds(excludeArtifactIds);
+ }
+
+ DependencyStatusSets dss = depMojo.getDependencySets(true);
+ Set artifacts = dss.getResolvedDependencies();
+
+ for (Iterator i = artifacts.iterator(); i.hasNext();)
+ {
+ Artifact artifact = (Artifact)i.next();
+ depMojo.copyArtifact(artifact, stripVersion);
+ mojo.getLog().info(" +- " + artifact);
+ }
+ }
+
+ /** Provides access to protected properties */
+ class ExtCopyDependenciesMojo extends CopyDependenciesMojo
+ {
+ public void setProject(MavenProject project)
+ {
+ super.project = project;
+ }
+
+ public void setReactorProjects(List reactorProjects)
+ {
+ super.reactorProjects = reactorProjects;
+ }
+
+ public void setIncludeArtifactIds(String includeArtifactIds)
+ {
+ super.includeArtifactIds = includeArtifactIds;
+ }
+
+ public void setExcludeArtifactIds(String excludeArtifactIds)
+ {
+ super.excludeArtifactIds = excludeArtifactIds;
+ }
+
+ public void setSilent(boolean silent)
+ {
+ super.silent = silent;
+ }
+
+ @Override
+ public DependencyStatusSets getDependencySets(boolean stopOnFailure) throws MojoExecutionException
+ {
+ return super.getDependencySets(stopOnFailure);
+ }
+
+ @Override
+ public void copyArtifact(Artifact artifact, boolean removeVersion) throws MojoExecutionException
+ {
+ super.copyArtifact(artifact, removeVersion);
+ }
+ }
+}
Property changes on: projects/maven/plugins/deployer/trunk/src/test/resources/test-jboss-home/bin/org/jboss/maven/plugin/deployer/handlers/DependenciesHandler.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: projects/maven/plugins/deployer/trunk/src/test/resources/test-jboss-home/bin/org/jboss/maven/plugin/deployer/handlers/DeploymentsHandler.java
===================================================================
--- projects/maven/plugins/deployer/trunk/src/test/resources/test-jboss-home/bin/org/jboss/maven/plugin/deployer/handlers/DeploymentsHandler.java (rev 0)
+++ projects/maven/plugins/deployer/trunk/src/test/resources/test-jboss-home/bin/org/jboss/maven/plugin/deployer/handlers/DeploymentsHandler.java 2008-04-17 14:20:34 UTC (rev 72360)
@@ -0,0 +1,143 @@
+/*
+ * 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.handlers;
+
+// $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;
+import org.jboss.maven.plugin.deployer.AbstractDeployerMojo;
+import org.jboss.maven.plugin.deployer.Deployment;
+
+/**
+ * Handles deployment of artifacts.
+ *
+ * @author Thomas.Diesler at jboss.com
+ * @since 16-Apr-2008
+ */
+public class DeploymentsHandler
+{
+ private AbstractDeployerMojo mojo;
+
+ private DeploymentsHandler(AbstractDeployerMojo mojo)
+ {
+ this.mojo = mojo;
+ }
+
+ public static void process(AbstractDeployerMojo 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.getLayoutDirectory() + "/" + targetDir);
+ copyFiles(effectiveFiles, sourceDir, destRoot);
+
+ for (File file : effectiveFiles)
+ {
+ mojo.getLog().info(" +- " + file.getCanonicalPath().substring(offset));
+ }
+ }
+
+ public static 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 != null ? "/" + relPath : ""));
+ FileUtils.copyFileToDirectory(file, destDir);
+ }
+ }
+}
Property changes on: projects/maven/plugins/deployer/trunk/src/test/resources/test-jboss-home/bin/org/jboss/maven/plugin/deployer/handlers/DeploymentsHandler.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: projects/maven/plugins/deployer/trunk/src/test/resources/test-jboss-home/bin/org/jboss/maven/plugin/deployer/handlers/UndeploymentsHandler.java
===================================================================
--- projects/maven/plugins/deployer/trunk/src/test/resources/test-jboss-home/bin/org/jboss/maven/plugin/deployer/handlers/UndeploymentsHandler.java (rev 0)
+++ projects/maven/plugins/deployer/trunk/src/test/resources/test-jboss-home/bin/org/jboss/maven/plugin/deployer/handlers/UndeploymentsHandler.java 2008-04-17 14:20:34 UTC (rev 72360)
@@ -0,0 +1,79 @@
+/*
+ * 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.handlers;
+
+// $Id$
+
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+
+import org.codehaus.plexus.util.FileUtils;
+import org.jboss.maven.plugin.deployer.AbstractDeployerMojo;
+
+/**
+ * Handles undeployment of artifacts.
+ *
+ * @author Thomas.Diesler at jboss.com
+ * @since 16-Apr-2008
+ */
+public class UndeploymentsHandler
+{
+ private AbstractDeployerMojo mojo;
+
+ private UndeploymentsHandler(AbstractDeployerMojo mojo)
+ {
+ this.mojo = mojo;
+ }
+
+ public static void process(AbstractDeployerMojo mojo) throws IOException
+ {
+ new UndeploymentsHandler(mojo).process();
+ }
+
+ private void process() throws IOException
+ {
+ List<String> undeployments = mojo.getUndeploy();
+ 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/test/resources/test-jboss-home/bin/org/jboss/maven/plugin/deployer/handlers/UndeploymentsHandler.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: projects/maven/plugins/deployer/trunk/src/test/resources/test-jboss-home/deploy-layout.txt
===================================================================
--- projects/maven/plugins/deployer/trunk/src/test/resources/test-jboss-home/deploy-layout.txt (rev 0)
+++ projects/maven/plugins/deployer/trunk/src/test/resources/test-jboss-home/deploy-layout.txt 2008-04-17 14:20:34 UTC (rev 72360)
@@ -0,0 +1,11 @@
+# Date: Thu, 17 Apr 2008 16:04:40
+# User: tdiesler
+#
+deploy-layout.txt
+bin/org/jboss/maven/plugin/deployer/AbstractDeployerMojo.java
+bin/org/jboss/maven/plugin/deployer/handlers/DeploymentsHandler.java
+bin/org/jboss/maven/plugin/deployer/handlers/DependenciesHandler.java
+bin/org/jboss/maven/plugin/deployer/handlers/UndeploymentsHandler.java
+bin/org/jboss/maven/plugin/deployer/DeployerMojo.java
+bin/org/jboss/maven/plugin/deployer/Deployment.java
+bin/org/jboss/maven/plugin/deployer/UndeployerMojo.java
Property changes on: projects/maven/plugins/deployer/trunk/src/test/resources/test-jboss-home/deploy-layout.txt
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
More information about the jboss-cvs-commits
mailing list