[Arakhnę-Dev] [307] * Add "atomicdeploy" maven plugin.

[ Thread Index | Date Index | More arakhne.org/dev Archives ]


Revision: 307
Author:   galland
Date:     2011-11-05 11:32:24 +0100 (Sat, 05 Nov 2011)
Log Message:
-----------
* Add "atomicdeploy" maven plugin.

Added Paths:
-----------
    trunk/atomicdeploy/
    trunk/atomicdeploy/lifecycle-mapping-metadata.xml
    trunk/atomicdeploy/pom.xml
    trunk/atomicdeploy/src/
    trunk/atomicdeploy/src/main/
    trunk/atomicdeploy/src/main/java/
    trunk/atomicdeploy/src/main/java/org/
    trunk/atomicdeploy/src/main/java/org/arakhne/
    trunk/atomicdeploy/src/main/java/org/arakhne/maven/
    trunk/atomicdeploy/src/main/java/org/arakhne/maven/plugins/
    trunk/atomicdeploy/src/main/java/org/arakhne/maven/plugins/atomicdeploy/
    trunk/atomicdeploy/src/main/java/org/arakhne/maven/plugins/atomicdeploy/JavadocMojo.java
    trunk/atomicdeploy/src/main/resources/
    trunk/atomicdeploy/src/test/

Added: trunk/atomicdeploy/lifecycle-mapping-metadata.xml
===================================================================
--- trunk/atomicdeploy/lifecycle-mapping-metadata.xml	                        (rev 0)
+++ trunk/atomicdeploy/lifecycle-mapping-metadata.xml	2011-11-05 10:32:24 UTC (rev 307)
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- ########################################################################
+     # See http://wiki.eclipse.org/M2E_compatible_maven_plugins for details #
+     ######################################################################## -->
+<lifecycleMappingMetadata>
+  <pluginExecutions>
+    <pluginExecution>
+      <pluginExecutionFilter>
+        <groupId>org.arakhne.afc</groupId>
+        <artifactId>atomicdeploy</artifactId>
+        <versionRange>[1.0,)</versionRange>
+        <goals>
+          <goal>javadoc</goal>
+        </goals>
+      </pluginExecutionFilter>
+      <action>
+        <ignore />
+      </action>
+    </pluginExecution>
+  </pluginExecutions>
+</lifecycleMappingMetadata>
\ No newline at end of file


Property changes on: trunk/atomicdeploy/lifecycle-mapping-metadata.xml
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Added: trunk/atomicdeploy/pom.xml
===================================================================
--- trunk/atomicdeploy/pom.xml	                        (rev 0)
+++ trunk/atomicdeploy/pom.xml	2011-11-05 10:32:24 UTC (rev 307)
@@ -0,0 +1,62 @@
+<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/xsd/maven-4.0.0.xsd";>
+	<modelVersion>4.0.0</modelVersion>
+	<parent>
+		<artifactId>afc</artifactId>
+		<groupId>org.arakhne.afc</groupId>
+		<version>4.3-SNAPSHOT</version>
+		<relativePath>..</relativePath>
+	</parent>
+	
+	<artifactId>atomicdeploy</artifactId>
+	<version>1.0-SNAPSHOT</version>
+	<name>Atomic Deploy</name>
+	<packaging>maven-plugin</packaging>
+	<url>http://www.arakhne.org</url>
+
+	<properties>
+		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+	</properties>
+
+	<dependencies>
+		<dependency>
+			<groupId>org.arakhne.afc</groupId>
+			<artifactId>maventools</artifactId>
+		</dependency>
+	</dependencies>
+
+	<build>
+		<plugins>
+			<plugin>
+				<artifactId>maven-plugin-plugin</artifactId>
+				<executions>
+					<execution>
+						<id>generated-helpmojo</id>
+						<goals>
+							<goal>helpmojo</goal>
+						</goals>
+					</execution>
+				</executions>
+				<configuration>
+					<goalPrefix>atomicdeploy</goalPrefix>
+				</configuration>
+			</plugin>
+		</plugins>
+		<resources>
+			<resource>
+				<directory>${basedir}/src/main/resources</directory>
+				<includes>
+					<include>**/*</include>
+				</includes>
+			</resource>
+			<resource>
+				<directory>${basedir}</directory>
+				<targetPath>${basedir}/target/classes/META-INF/m2e/</targetPath>
+				<filtering>false</filtering>
+				<includes>
+					<include>lifecycle-mapping-metadata.xml</include>
+				</includes>
+			</resource>
+		</resources>
+	</build>
+</project>
\ No newline at end of file


Property changes on: trunk/atomicdeploy/pom.xml
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Added: trunk/atomicdeploy/src/main/java/org/arakhne/maven/plugins/atomicdeploy/JavadocMojo.java
===================================================================
--- trunk/atomicdeploy/src/main/java/org/arakhne/maven/plugins/atomicdeploy/JavadocMojo.java	                        (rev 0)
+++ trunk/atomicdeploy/src/main/java/org/arakhne/maven/plugins/atomicdeploy/JavadocMojo.java	2011-11-05 10:32:24 UTC (rev 307)
@@ -0,0 +1,268 @@
+/* 
+ * $Id$
+ * 
+ * Copyright (C) 2011 Stephane GALLAND This library 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 library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ * This program is free software; you can redistribute it and/or modify
+ */
+package org.arakhne.maven.plugins.atomicdeploy;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.util.List;
+
+import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.model.DistributionManagement;
+import org.apache.maven.model.Site;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.MavenProjectBuilder;
+import org.arakhne.maven.AbstractArakhneMojo;
+import org.sonatype.aether.RepositorySystem;
+import org.sonatype.aether.RepositorySystemSession;
+import org.sonatype.aether.repository.RemoteRepository;
+
+/**
+ * Deploy the generated javadoc directory into the site deployment location.
+ * 
+ * @author $Author: galland$
+ * @version $FullVersion$
+ * @mavengroupid $GroupId$
+ * @mavenartifactid $ArtifactId$
+ * 
+ * @goal javadoc
+ * @phase deploy
+ * @requireProject true
+ * @threadSafe
+ */
+public class JavadocMojo extends AbstractArakhneMojo {
+
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public synchronized void checkMojoAttributes() {
+		assertNotNull("javadocDirectory", this.javadocDirectory); //$NON-NLS-1$
+		assertNotNull("outputDirectory", this.outputDirectory); //$NON-NLS-1$
+		assertNotNull("artifactHandlerManager", this.artifactHandlerManager); //$NON-NLS-1$
+		assertNotNull("baseDirectory", this.baseDirectory); //$NON-NLS-1$
+		assertNotNull("mavenProjectBuilder", this.mavenProjectBuilder); //$NON-NLS-1$
+		assertNotNull("mavenSession", this.mavenSession); //$NON-NLS-1$
+		assertNotNull("repositorySystem", this.repoSystem); //$NON-NLS-1$
+		assertNotNull("repositorySystemSession", this.repoSession); //$NON-NLS-1$
+		assertNotNull("remoteRepositoryList", this.remoteRepos); //$NON-NLS-1$
+	}
+
+	//-----------------------------------------------------
+	// Inherited behavior attributes
+
+	/**
+	 * @component
+	 */
+	private ArtifactHandlerManager artifactHandlerManager;
+
+	/**
+	 * @parameter expression="${project.basedir}"
+	 */
+	private File baseDirectory;
+
+	/**
+	 * @parameter expression="${project.build.directory}"
+	 */
+	private File outputDirectory;
+
+	/**
+	 * @component role="org.apache.maven.project.MavenProjectBuilder"
+	 * @required
+	 * @readonly
+	 */
+	private MavenProjectBuilder mavenProjectBuilder;
+
+	/**
+	 * Reference to the current session.
+	 * 
+	 * @parameter expression="${session}"
+	 * @required
+	 */
+	private MavenSession mavenSession;
+
+	/**
+	 * The entry point to Aether, i.e. the component doing all the work.
+	 * 
+	 * @component
+	 */
+	private RepositorySystem repoSystem;
+
+	/**
+	 * The current repository/network configuration of Maven.
+	 * 
+	 * @parameter default-value="${repositorySystemSession}"
+	 * @readonly
+	 */
+	private RepositorySystemSession repoSession;
+
+	/**
+	 * The project's remote repositories to use for the resolution of plugins and their dependencies.
+	 * 
+	 * @parameter default-value="${project.remoteProjectRepositories}"
+	 * @readonly
+	 */
+	private List<RemoteRepository> remoteRepos;
+
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public File getOutputDirectory() {
+		return this.outputDirectory;
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public File getBaseDirectory() {
+		return this.baseDirectory;
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public ArtifactHandlerManager getArtifactHandlerManager() {
+		return this.artifactHandlerManager;
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public MavenSession getMavenSession() {
+		return this.mavenSession;
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public RepositorySystemSession getRepositorySystemSession() {
+		return this.repoSession;
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public List<RemoteRepository> getRemoteRepositoryList() {
+		return this.remoteRepos;
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public RepositorySystem getRepositorySystem() {
+		return this.repoSystem;
+	}
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public MavenProjectBuilder getMavenProjectBuilder() {
+		return this.mavenProjectBuilder;
+	}
+
+	//-----------------------------------------------------
+	// Mojo dedicated attributes
+	
+	private static URL getSiteDeploymentURL(MavenProject project) {
+		DistributionManagement distManagement = project.getDistributionManagement();
+		if (distManagement!=null) {
+			Site site = distManagement.getSite();
+			if (site!=null) {
+				String url = site.getUrl();
+				if (url!=null && url.length()>0) {
+					try {
+						return new URL(url);
+					}
+					catch(Throwable e) {
+						//
+					}
+				}
+			}
+		}
+		return null;
+	}
+
+	private static URL getInheritedSiteDeploymentURL(MavenProject project) {
+		URL deployementURL = null;
+		MavenProject p = project; 
+		while(deployementURL==null && p!=null) {
+			deployementURL = getSiteDeploymentURL(p);
+			p = p.getParent();
+		}
+		return deployementURL;
+	}
+
+	/**
+	 * Directory of the javadoc.
+	 * 
+	 * @parameter expression="${project.build.directory}/site/javadoc"
+	 */
+	private String javadocDirectory;
+
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public synchronized void executeMojo() throws MojoExecutionException {
+		File javadocDir = new File(this.javadocDirectory);
+		if (javadocDir.isDirectory()) {
+			MavenProject project = this.mavenSession.getCurrentProject();
+			URL deployementURL = getInheritedSiteDeploymentURL(project);
+			if (deployementURL!=null) {
+				if ("file".equalsIgnoreCase(deployementURL.getProtocol())) { //$NON-NLS-1$
+					File output = new File(deployementURL.getPath());
+					try {
+						dirRemove(output);
+						dirCopy(javadocDir, output);
+					}
+					catch (IOException e) {
+						error(e);
+						throw new MojoExecutionException(e.getMessage(), e);
+					}
+				}
+				else {
+					String message = "Unsupported transport protocol: "+deployementURL.getProtocol(); //$NON-NLS-1$
+					error(message);
+					throw new MojoExecutionException(message);
+				}
+			}
+			else {
+				String message = "No site deployement URL found"; //$NON-NLS-1$
+				error(message);
+				throw new MojoExecutionException(message);
+			}
+		}
+		else {
+			String message = "Javadoc directory not found: "+this.javadocDirectory; //$NON-NLS-1$
+			error(message);
+			throw new MojoExecutionException(message);
+		}
+	}
+
+}


Property changes on: trunk/atomicdeploy/src/main/java/org/arakhne/maven/plugins/atomicdeploy/JavadocMojo.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/