You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@taverna.apache.org by st...@apache.org on 2015/02/17 12:50:20 UTC

[02/50] [abbrv] incubator-taverna-osgi git commit: Added plugin-deploy-file goal

Added plugin-deploy-file goal

git-svn-id: http://taverna.googlecode.com/svn/taverna/dev/maven-plugin/trunk/taverna-maven-plugin@16464 bf327186-88b3-11dd-a302-d386e5130c1c


Project: http://git-wip-us.apache.org/repos/asf/incubator-taverna-osgi/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-taverna-osgi/commit/3a7b9ed4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-taverna-osgi/tree/3a7b9ed4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-taverna-osgi/diff/3a7b9ed4

Branch: refs/heads/master
Commit: 3a7b9ed4d476799ea2b2d4d33faffed1979b97e7
Parents: d377e30
Author: david@mygrid.org.uk <da...@bf327186-88b3-11dd-a302-d386e5130c1c>
Authored: Fri Dec 13 16:43:50 2013 +0000
Committer: david@mygrid.org.uk <da...@bf327186-88b3-11dd-a302-d386e5130c1c>
Committed: Fri Dec 13 16:43:50 2013 +0000

----------------------------------------------------------------------
 pom.xml                                         |  15 --
 .../t2/maven/plugins/AbstractDeployMojo.java    |  32 +--
 .../t2/maven/plugins/AbstractWagonMojo.java     |  60 +++++
 .../plugins/TavernaPluginDeployFileMojo.java    | 235 +++++++++++++++++++
 .../maven/plugins/TavernaPluginDeployMojo.java  |   4 +-
 5 files changed, 299 insertions(+), 47 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-taverna-osgi/blob/3a7b9ed4/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 7e7d6dc..aab045b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -35,14 +35,6 @@
 					</execution>
 				</executions>
 			</plugin>
-			<!-- <plugin> <groupId>org.jvnet.jaxb2.maven2</groupId> <artifactId>maven-jaxb2-plugin</artifactId>
-				<version>0.8.3</version> <configuration> <forceRegenerate>true</forceRegenerate>
-				<schemas> <schema> Use real url when deployed <url>http://ns.taverna.org.uk/2013/application/profile/ApplicationProfile.xsd</url>
-				<url>http://localhost/2013/application/profile/ApplicationProfile.xsd</url>
-				</schema> <schema> Use real url when deployed <url>http://ns.taverna.org.uk/2013/application/plugin/ApplicationPlugin.xsd</url>
-				<url>http://localhost/2013/application/plugin/ApplicationPlugin.xsd</url>
-				</schema> </schemas> </configuration> <executions> <execution> <goals> <goal>generate</goal>
-				</goals> </execution> </executions> </plugin> -->
 		</plugins>
 	</build>
 	<dependencies>
@@ -72,18 +64,11 @@
 			<artifactId>maven-osgi</artifactId>
 			<version>0.2.0</version>
 		</dependency>
-		<!-- <dependency>
-			<groupId>org.apache.maven.wagon</groupId>
-			<artifactId>wagon-file</artifactId>
-			<version>2.4</version>
-		</dependency> -->
 		<dependency>
 			<groupId>uk.org.taverna.commons</groupId>
 			<artifactId>taverna-xml-schemas</artifactId>
 			<version>0.1.0-SNAPSHOT</version>
 		</dependency>
-		<!-- <dependency> <groupId>org.apache.felix</groupId> <artifactId>maven-bundle-plugin</artifactId>
-			<version>2.3.7</version> </dependency> -->
 
 		<dependency>
 			<groupId>biz.aQute</groupId>

http://git-wip-us.apache.org/repos/asf/incubator-taverna-osgi/blob/3a7b9ed4/src/main/java/net/sf/taverna/t2/maven/plugins/AbstractDeployMojo.java
----------------------------------------------------------------------
diff --git a/src/main/java/net/sf/taverna/t2/maven/plugins/AbstractDeployMojo.java b/src/main/java/net/sf/taverna/t2/maven/plugins/AbstractDeployMojo.java
index e19e2f6..d3e98cf 100644
--- a/src/main/java/net/sf/taverna/t2/maven/plugins/AbstractDeployMojo.java
+++ b/src/main/java/net/sf/taverna/t2/maven/plugins/AbstractDeployMojo.java
@@ -23,22 +23,17 @@ package net.sf.taverna.t2.maven.plugins;
 import java.io.File;
 
 import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.manager.WagonManager;
 import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugins.annotations.Component;
 import org.apache.maven.plugins.annotations.Parameter;
 import org.apache.maven.project.MavenProject;
-import org.apache.maven.wagon.ConnectionException;
-import org.apache.maven.wagon.Wagon;
-import org.apache.maven.wagon.observers.Debug;
 
 /**
- *
+ * Abstract Mojo for deploying artifacts.
  *
  * @author David Withers
  */
-public abstract class AbstractDeployMojo extends AbstractMojo {
+public abstract class AbstractDeployMojo extends AbstractWagonMojo {
 
 	@Component
 	protected MavenProject project;
@@ -58,27 +53,4 @@ public abstract class AbstractDeployMojo extends AbstractMojo {
 	@Parameter(defaultValue = "${project.distributionManagementArtifactRepository}", required = true, readonly = true)
 	protected ArtifactRepository deploymentRepository;
 
-	@Component
-	protected WagonManager wagonManager;
-
-	/**
-	 * Disconnect the wagon.
-	 *
-	 * @param wagon
-	 *            the wagon to disconnect
-	 * @param debug
-	 */
-	protected void disconnectWagon(Wagon wagon, Debug debug) {
-		if (getLog().isDebugEnabled()) {
-			wagon.removeTransferListener(debug);
-			wagon.removeSessionListener(debug);
-		}
-		try {
-			wagon.disconnect();
-		} catch (ConnectionException e) {
-			getLog().error("Error disconnecting wagon - ignored", e);
-		}
-	}
-
-
 }

http://git-wip-us.apache.org/repos/asf/incubator-taverna-osgi/blob/3a7b9ed4/src/main/java/net/sf/taverna/t2/maven/plugins/AbstractWagonMojo.java
----------------------------------------------------------------------
diff --git a/src/main/java/net/sf/taverna/t2/maven/plugins/AbstractWagonMojo.java b/src/main/java/net/sf/taverna/t2/maven/plugins/AbstractWagonMojo.java
new file mode 100644
index 0000000..a74166a
--- /dev/null
+++ b/src/main/java/net/sf/taverna/t2/maven/plugins/AbstractWagonMojo.java
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * Copyright (C) 2013 The University of Manchester
+ *
+ *  Modifications to the initial code base are copyright of their
+ *  respective authors, or their employers as appropriate.
+ *
+ *  This program 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 program 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 program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package net.sf.taverna.t2.maven.plugins;
+
+import org.apache.maven.artifact.manager.WagonManager;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugins.annotations.Component;
+import org.apache.maven.wagon.ConnectionException;
+import org.apache.maven.wagon.Wagon;
+import org.apache.maven.wagon.observers.Debug;
+
+/**
+ * Abstract Mojo for using the wagon.
+ *
+ * @author David Withers
+ */
+public abstract class AbstractWagonMojo extends AbstractMojo {
+
+	@Component
+	protected WagonManager wagonManager;
+
+	/**
+	 * Disconnect the wagon.
+	 *
+	 * @param wagon
+	 *            the wagon to disconnect
+	 * @param debug
+	 */
+	protected void disconnectWagon(Wagon wagon, Debug debug) {
+		if (getLog().isDebugEnabled()) {
+			wagon.removeTransferListener(debug);
+			wagon.removeSessionListener(debug);
+		}
+		try {
+			wagon.disconnect();
+		} catch (ConnectionException e) {
+			getLog().error("Error disconnecting wagon - ignored", e);
+		}
+	}
+
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-taverna-osgi/blob/3a7b9ed4/src/main/java/net/sf/taverna/t2/maven/plugins/TavernaPluginDeployFileMojo.java
----------------------------------------------------------------------
diff --git a/src/main/java/net/sf/taverna/t2/maven/plugins/TavernaPluginDeployFileMojo.java b/src/main/java/net/sf/taverna/t2/maven/plugins/TavernaPluginDeployFileMojo.java
new file mode 100644
index 0000000..cf2034b
--- /dev/null
+++ b/src/main/java/net/sf/taverna/t2/maven/plugins/TavernaPluginDeployFileMojo.java
@@ -0,0 +1,235 @@
+/*******************************************************************************
+ * Copyright (C) 2009 The University of Manchester
+ *
+ *  Modifications to the initial code base are copyright of their
+ *  respective authors, or their employers as appropriate.
+ *
+ *  This program 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 program 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 program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package net.sf.taverna.t2.maven.plugins;
+
+import static net.sf.taverna.t2.maven.plugins.TavernaPluginGenerateMojo.META_INF_TAVERNA;
+import static net.sf.taverna.t2.maven.plugins.TavernaPluginGenerateMojo.PLUGIN_FILE;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.jar.JarFile;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipException;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Marshaller;
+import javax.xml.bind.Unmarshaller;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.maven.plugins.annotations.Parameter;
+import org.apache.maven.wagon.ConnectionException;
+import org.apache.maven.wagon.ResourceDoesNotExistException;
+import org.apache.maven.wagon.UnsupportedProtocolException;
+import org.apache.maven.wagon.Wagon;
+import org.apache.maven.wagon.authentication.AuthenticationException;
+import org.apache.maven.wagon.observers.Debug;
+import org.apache.maven.wagon.repository.Repository;
+
+import uk.org.taverna.commons.plugin.xml.jaxb.PluginInfo;
+import uk.org.taverna.commons.plugin.xml.jaxb.PluginVersions;
+import uk.org.taverna.commons.plugin.xml.jaxb.Plugins;
+import uk.org.taverna.commons.versions.xml.jaxb.Version;
+
+/**
+ * Deploys the Taverna plugin using <code>scp</code> or <code>file</code> protocol to the site URL
+ * specified.
+ *
+ * @author David Withers
+ */
+@Mojo(name = "plugin-deploy-file", requiresProject=false, requiresDirectInvocation = true)
+public class TavernaPluginDeployFileMojo extends AbstractWagonMojo {
+
+	private static final String PLUGIN_FILE_ENTRY = META_INF_TAVERNA + "/" + PLUGIN_FILE;
+
+	private static final String PLUGINS_FILE = "plugins.xml";
+
+	@Parameter(defaultValue = "http://updates.taverna.org.uk/workbench/3.0/dev/", required = true)
+	protected String site;
+
+	@Parameter(property = "file", required = true)
+	protected File file;
+
+	@Parameter(property = "url", required = true)
+	protected String url;
+
+	@Parameter(property = "serverId", required = true)
+	protected String serverId;
+
+	public void execute() throws MojoExecutionException {
+		if (!file.exists()) {
+			throw new MojoExecutionException("The Taverna Plugin file " + file
+					+ " does not exist");
+		}
+
+		JarFile pluginJarFile;
+		try {
+			pluginJarFile = new JarFile(file);
+		} catch (ZipException e) {
+			throw new MojoExecutionException(file + " is not a valid Taverna Plugin file", e);
+		} catch (IOException e) {
+			throw new MojoExecutionException("Error opening Taverna Plugin file: " + file, e);
+		}
+
+		ZipEntry pluginFileEntry = pluginJarFile.getJarEntry(PLUGIN_FILE_ENTRY);
+		if (pluginFileEntry == null) {
+			throw new MojoExecutionException(file
+					+ " is not a valid Taverna Plugin file, missing " + PLUGIN_FILE_ENTRY);
+		}
+
+		JAXBContext jaxbContext;
+		try {
+			jaxbContext = JAXBContext.newInstance(PluginInfo.class, Plugins.class);
+		} catch (JAXBException e) {
+			throw new MojoExecutionException("Error setting up JAXB context ", e);
+		}
+
+		PluginInfo plugin;
+		try {
+			InputStream inputStream = pluginJarFile.getInputStream(pluginFileEntry);
+			Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
+			plugin = (PluginInfo) unmarshaller.unmarshal(inputStream);
+			inputStream.close();
+		} catch (IOException e) {
+			throw new MojoExecutionException("Error reading " + file, e);
+		} catch (JAXBException e) {
+			throw new MojoExecutionException("Error reading " + file, e);
+		}
+
+		getLog().debug("The Taverna plugin will be deployed to '" + url + "'");
+
+		Repository repository = new Repository(serverId, url);
+
+		// create the wagon
+		Wagon wagon;
+		try {
+			wagon = wagonManager.getWagon(repository.getProtocol());
+		} catch (UnsupportedProtocolException e) {
+			throw new MojoExecutionException("Unsupported protocol: '" + repository.getProtocol()
+					+ "'", e);
+		}
+
+		Debug debug = new Debug();
+		if (getLog().isDebugEnabled()) {
+			wagon.addSessionListener(debug);
+			wagon.addTransferListener(debug);
+		}
+
+		// connect to the plugin site
+		try {
+			wagon.connect(repository, wagonManager.getAuthenticationInfo(serverId),
+					wagonManager.getProxy(repository.getProtocol()));
+		} catch (ConnectionException e) {
+			throw new MojoExecutionException("Error connecting to plugin site at " + url, e);
+		} catch (AuthenticationException e) {
+			throw new MojoExecutionException("Authentication error connecting to plugin site at "
+					+ url, e);
+		}
+
+		try {
+			File pluginsFile = File.createTempFile("taverna", null);
+
+			// fetch the plugins file
+			Plugins plugins;
+			try {
+				Utils.downloadFile(PLUGINS_FILE, pluginsFile, wagon, getLog());
+				try {
+					Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
+					plugins = (Plugins) unmarshaller.unmarshal(pluginsFile);
+				} catch (JAXBException e) {
+					throw new MojoExecutionException("Error reading " + pluginsFile, e);
+				}
+			} catch (ResourceDoesNotExistException e) {
+				getLog().info("Creating new plugins file");
+				plugins = new Plugins();
+			}
+
+			String deployedPluginFile = plugin.getId() + "-" + plugin.getVersion() + ".jar";
+
+			if (addPlugin(plugins, plugin, deployedPluginFile)) {
+				// write the new plugin site file
+				try {
+					Marshaller marshaller = jaxbContext.createMarshaller();
+					marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
+					marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION,
+							TavernaPluginGenerateMojo.SCHEMA_LOCATION);
+					marshaller.marshal(plugins, pluginsFile);
+				} catch (JAXBException e) {
+					throw new MojoExecutionException("Error writing " + PLUGINS_FILE, e);
+				}
+
+				// upload the plugin to the update site
+				Utils.uploadFile(file, deployedPluginFile, wagon, getLog());
+				// upload the plugin site file
+				Utils.uploadFile(pluginsFile, PLUGINS_FILE, wagon, getLog());
+			}
+		} catch (IOException e) {
+			throw new MojoExecutionException("Error writing " + PLUGINS_FILE, e);
+		} finally {
+			disconnectWagon(wagon, debug);
+		}
+	}
+
+	private boolean addPlugin(Plugins plugins, PluginInfo pluginInfo, String pluginURL) {
+		PluginVersions plugin = getPlugin(plugins, pluginInfo);
+		Version latestVersion = plugin.getLatestVersion();
+		if (latestVersion != null && latestVersion.getVersion().equals(pluginInfo.getVersion())) {
+			getLog().error(
+					String.format("%1$s version %2$s has already been deployed",
+							pluginInfo.getName(), pluginInfo.getVersion()));
+			return false;
+		}
+		Version newPluginVersion = new Version();
+		newPluginVersion.setVersion(pluginInfo.getVersion());
+		newPluginVersion.setFile(pluginURL);
+
+		getLog().info(
+				String.format("Adding %1$s version %2$s", pluginInfo.getName(),
+						pluginInfo.getVersion()));
+		if (plugin.getLatestVersion() != null) {
+			plugin.getPreviousVersion().add(plugin.getLatestVersion());
+		}
+		plugin.setLatestVersion(newPluginVersion);
+		return true;
+	}
+
+	private PluginVersions getPlugin(Plugins plugins, PluginInfo pluginInfo) {
+		PluginVersions pluginVersions = null;
+		for (PluginVersions existingPlugin : plugins.getPlugin()) {
+			if (existingPlugin.getId().equals(pluginInfo.getId())) {
+				pluginVersions = existingPlugin;
+				break;
+			}
+		}
+		if (pluginVersions == null) {
+			pluginVersions = new PluginVersions();
+			pluginVersions.setId(pluginInfo.getId());
+			plugins.getPlugin().add(pluginVersions);
+		}
+		pluginVersions.setName(pluginInfo.getName());
+		pluginVersions.setDescription(pluginInfo.getDescription());
+		pluginVersions.setOrganization(pluginInfo.getOrganization());
+		return pluginVersions;
+	}
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-taverna-osgi/blob/3a7b9ed4/src/main/java/net/sf/taverna/t2/maven/plugins/TavernaPluginDeployMojo.java
----------------------------------------------------------------------
diff --git a/src/main/java/net/sf/taverna/t2/maven/plugins/TavernaPluginDeployMojo.java b/src/main/java/net/sf/taverna/t2/maven/plugins/TavernaPluginDeployMojo.java
index e4d56a4..8ba1f3d 100644
--- a/src/main/java/net/sf/taverna/t2/maven/plugins/TavernaPluginDeployMojo.java
+++ b/src/main/java/net/sf/taverna/t2/maven/plugins/TavernaPluginDeployMojo.java
@@ -135,10 +135,8 @@ public class TavernaPluginDeployMojo extends AbstractDeployMojo {
 		}
 
 		try {
-			// upload the plugin to the update site
 			String deployedPluginFile = project.getGroupId() + "." + project.getArtifactId() + "-"
 					+ plugin.getVersion() + ".jar";
-			Utils.uploadFile(artifactFile, deployedPluginFile, wagon, getLog());
 
 			// fetch the plugins file
 			Plugins plugins;
@@ -168,6 +166,8 @@ public class TavernaPluginDeployMojo extends AbstractDeployMojo {
 					throw new MojoExecutionException("Error writing " + PLUGINS_FILE, e);
 				}
 
+				// upload the plugin to the update site
+				Utils.uploadFile(artifactFile, deployedPluginFile, wagon, getLog());
 				// upload the plugin site file
 				Utils.uploadFile(pluginsFile, PLUGINS_FILE, wagon, getLog());
 			}