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:57 UTC

[39/50] [abbrv] incubator-taverna-osgi git commit: taverna-maven-plugin/

http://git-wip-us.apache.org/repos/asf/incubator-taverna-osgi/blob/37264921/taverna-maven-plugin/src/main/java/net/sf/taverna/t2/maven/plugins/TavernaProfileDeployMojo.java
----------------------------------------------------------------------
diff --git a/taverna-maven-plugin/src/main/java/net/sf/taverna/t2/maven/plugins/TavernaProfileDeployMojo.java b/taverna-maven-plugin/src/main/java/net/sf/taverna/t2/maven/plugins/TavernaProfileDeployMojo.java
new file mode 100644
index 0000000..fce4ded
--- /dev/null
+++ b/taverna-maven-plugin/src/main/java/net/sf/taverna/t2/maven/plugins/TavernaProfileDeployMojo.java
@@ -0,0 +1,275 @@
+/*******************************************************************************
+ * 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 java.io.File;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+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.LifecyclePhase;
+import org.apache.maven.plugins.annotations.Mojo;
+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.profile.xml.jaxb.ApplicationProfile;
+import uk.org.taverna.commons.profile.xml.jaxb.BundleInfo;
+import uk.org.taverna.commons.profile.xml.jaxb.UpdateSite;
+import uk.org.taverna.commons.versions.xml.jaxb.Version;
+import uk.org.taverna.commons.versions.xml.jaxb.Versions;
+
+/**
+ * Deploys the application profile using <code>scp</code> or <code>file</code> protocol to the site
+ * URL specified in the <code>&lt;distributionManagement&gt;</code> section of the POM.
+ *
+ * @author David Withers
+ */
+@Mojo(name = "profile-deploy", defaultPhase = LifecyclePhase.DEPLOY)
+public class TavernaProfileDeployMojo extends AbstractDeployMojo {
+
+	private static final String UPDATES_FILE = "updates.xml";
+
+	private File tempDirectory;
+
+	public void execute() throws MojoExecutionException {
+		tempDirectory = new File(buildDirectory, TavernaProfileGenerateMojo.TAVERNA_TMP);
+		tempDirectory.mkdirs();
+		if (artifact == null) {
+			throw new MojoExecutionException(
+					"The application profile does not exist, please run taverna:profile-generate first");
+		}
+
+		File artifactFile = artifact.getFile();
+		if (artifactFile == null) {
+			throw new MojoExecutionException(
+					"The application profile does not exist, please run taverna:profile-generate first");
+		}
+
+		JAXBContext jaxbContext;
+		try {
+			jaxbContext = JAXBContext.newInstance(ApplicationProfile.class, UpdateSite.class);
+		} catch (JAXBException e) {
+			throw new MojoExecutionException("Error setting up JAXB context ", e);
+		}
+
+		ApplicationProfile applicationProfile;
+		try {
+			Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
+			applicationProfile = (ApplicationProfile) unmarshaller.unmarshal(artifactFile);
+		} catch (JAXBException e) {
+			throw new MojoExecutionException("Error reading " + artifactFile, e);
+		}
+
+		if (deploymentRepository == null) {
+			throw new MojoExecutionException(
+					"Missing repository information in the distribution management element in the project.");
+		}
+
+		String url = deploymentRepository.getUrl();
+		String id = deploymentRepository.getId();
+
+		if (url == null) {
+			throw new MojoExecutionException(
+					"The URL to the update site is missing in the project descriptor.");
+		}
+		getLog().debug("The Taverna application will be deployed to '" + url + "'");
+
+		Repository repository = new Repository(id, 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 update site
+		try {
+			wagon.connect(repository, wagonManager.getAuthenticationInfo(id),
+					wagonManager.getProxy(repository.getProtocol()));
+		} catch (ConnectionException e) {
+			throw new MojoExecutionException("Error connecting to " + url, e);
+		} catch (AuthenticationException e) {
+			throw new MojoExecutionException("Authentication error connecting to " + url, e);
+		}
+
+		try {
+			// upload the application profile to the update site
+			String deployedProfileFile = "ApplicationProfile" + "-" + applicationProfile.getVersion()
+					+ ".xml";
+			Utils.uploadFile(artifactFile, deployedProfileFile, wagon, getLog());
+
+			// fetch the applications file
+			UpdateSite updateSite;
+			File updatesFile = new File(tempDirectory, UPDATES_FILE);
+			try {
+				Utils.downloadFile(UPDATES_FILE, updatesFile, wagon, getLog());
+				try {
+					Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
+					updateSite = (UpdateSite) unmarshaller
+							.unmarshal(updatesFile);
+				} catch (JAXBException e) {
+					throw new MojoExecutionException("Error reading " + updatesFile, e);
+				}
+			} catch(ResourceDoesNotExistException e) {
+				getLog().info("Creating new application versions file");
+				updateSite = new UpdateSite();
+				Versions versions = new Versions();
+				versions.setId(applicationProfile.getId());
+				versions.setName(applicationProfile.getName());
+				updateSite.setVersions(versions);
+			}
+
+			Version latestVersion = updateSite.getVersions().getLatestVersion();
+			if (latestVersion != null) {
+				File latestProfileFile = new File(tempDirectory, "ApplicationProfile-" + latestVersion.getVersion()
+						+ ".xml");
+				try {
+					Utils.downloadFile(latestVersion.getFile(), latestProfileFile, wagon, getLog());
+				} catch (ResourceDoesNotExistException e) {
+					throw new MojoExecutionException(latestVersion.getFile() + " does not exist", e);
+				}
+				ApplicationProfile latestProfile;
+				try {
+					Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
+					latestProfile = (ApplicationProfile) unmarshaller.unmarshal(latestProfileFile);
+				} catch (JAXBException e) {
+					throw new MojoExecutionException("Error reading " + latestProfileFile, e);
+				}
+				Set<BundleInfo> requiredBundles = getRequiredBundles(latestProfile, applicationProfile);
+				if (requiredBundles.isEmpty()) {
+					getLog().warn("No new bundles to upload");
+				} else {
+					// upload new bundles to the update site
+					uploadBundles(requiredBundles, wagon);
+				}
+			}
+
+			if (addApplicationVersion(updateSite.getVersions(), applicationProfile,
+					deployedProfileFile)) {
+				// write the new application versions list
+				try {
+					Marshaller marshaller = jaxbContext.createMarshaller();
+					marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
+					marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, TavernaProfileGenerateMojo.SCHEMA_LOCATION);
+					marshaller.marshal(updateSite, updatesFile);
+				} catch (JAXBException e) {
+					throw new MojoExecutionException("Error writing " + UPDATES_FILE, e);
+				}
+
+				// upload the new application versions list to the update site
+				Utils.uploadFile(updatesFile, UPDATES_FILE, wagon, getLog());
+			}
+		}
+		finally {
+			disconnectWagon(wagon, debug);
+		}
+	}
+
+	/**
+	 * Adds an new application version to the application versions if the version doesn't already
+	 * exist.
+	 *
+	 * @param applicationVersions
+	 *            the ApplicationVersions document
+	 * @param applicationProfile
+	 *            the applicationProfile
+	 * @param profileURL
+	 * @return true if a new version was added to the ApplicationVersions document; false if the
+	 *         version already exits
+	 */
+	private boolean addApplicationVersion(Versions applicationVersions,
+			ApplicationProfile applicationProfile, String profileURL) {
+		Version latestVersion = applicationVersions.getLatestVersion();
+		if (latestVersion != null
+				&& latestVersion.getVersion().equals(applicationProfile.getVersion())) {
+			getLog().error(
+					String.format("%1$s version %2$s has already been deployed",
+							applicationProfile.getName(), applicationProfile.getVersion()));
+			return false;
+		}
+
+		Version newApplicationVersion = new Version();
+		newApplicationVersion.setVersion(applicationProfile.getVersion());
+		newApplicationVersion.setFile(profileURL);
+
+		getLog().info(
+				String.format("Adding %1$s version %2$s", applicationProfile.getName(),
+						applicationProfile.getVersion()));
+		if (applicationVersions.getLatestVersion() != null) {
+			applicationVersions.getPreviousVersion().add(applicationVersions.getLatestVersion());
+		}
+		applicationVersions.setLatestVersion(newApplicationVersion);
+		return true;
+	}
+
+	/**
+	 * @param requiredBundles
+	 * @throws MojoExecutionException
+	 */
+	private void uploadBundles(Set<BundleInfo> requiredBundles, Wagon wagon) throws MojoExecutionException {
+		File libDirectory = new File(tempDirectory, "lib");
+		for (BundleInfo bundle : requiredBundles) {
+			Utils.uploadFile(new File(libDirectory, bundle.getFileName()), "lib/" + bundle.getFileName(), wagon, getLog());
+		}
+	}
+
+	private Set<BundleInfo> getRequiredBundles(ApplicationProfile currentProfile,
+			ApplicationProfile newProfile) {
+		Set<BundleInfo> requiredBundles = new HashSet<BundleInfo>();
+		Map<String, BundleInfo> currentBundles = new HashMap<String, BundleInfo>();
+		for (BundleInfo bundle : currentProfile.getBundle()) {
+			currentBundles.put(bundle.getSymbolicName(), bundle);
+		}
+		for (BundleInfo bundle : newProfile.getBundle()) {
+			if (currentBundles.containsKey(bundle.getSymbolicName())) {
+				BundleInfo currentBundle = currentBundles.get(bundle.getSymbolicName());
+				if (!bundle.getVersion().equals(currentBundle.getVersion())) {
+					requiredBundles.add(bundle);
+				}
+			} else {
+				requiredBundles.add(bundle);
+			}
+		}
+		return requiredBundles;
+	}
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-taverna-osgi/blob/37264921/taverna-maven-plugin/src/main/java/net/sf/taverna/t2/maven/plugins/TavernaProfileGenerateMojo.java
----------------------------------------------------------------------
diff --git a/taverna-maven-plugin/src/main/java/net/sf/taverna/t2/maven/plugins/TavernaProfileGenerateMojo.java b/taverna-maven-plugin/src/main/java/net/sf/taverna/t2/maven/plugins/TavernaProfileGenerateMojo.java
new file mode 100644
index 0000000..1a0e9a0
--- /dev/null
+++ b/taverna-maven-plugin/src/main/java/net/sf/taverna/t2/maven/plugins/TavernaProfileGenerateMojo.java
@@ -0,0 +1,221 @@
+/*******************************************************************************
+ * 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 java.io.File;
+import java.io.IOException;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Marshaller;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugins.annotations.Component;
+import org.apache.maven.plugins.annotations.LifecyclePhase;
+import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.maven.plugins.annotations.Parameter;
+import org.apache.maven.plugins.annotations.ResolutionScope;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.ProjectDependenciesResolver;
+import org.apache.maven.shared.osgi.DefaultMaven2OsgiConverter;
+import org.apache.maven.shared.osgi.Maven2OsgiConverter;
+import org.eclipse.aether.RepositorySystemSession;
+
+import uk.org.taverna.commons.profile.xml.jaxb.ApplicationProfile;
+import uk.org.taverna.commons.profile.xml.jaxb.BundleInfo;
+import uk.org.taverna.commons.profile.xml.jaxb.FrameworkConfiguration;
+import uk.org.taverna.commons.profile.xml.jaxb.Updates;
+
+/**
+ * Generates an application profile file.
+ *
+ * @author David Withers
+ */
+@Mojo(name = "profile-generate", defaultPhase = LifecyclePhase.GENERATE_RESOURCES, requiresDependencyResolution = ResolutionScope.RUNTIME)
+public class TavernaProfileGenerateMojo extends AbstractMojo {
+
+	public static final String SYSTEM_PACKAGES = "org.osgi.framework.system.packages.extra";
+
+	public static final String SCHEMA_LOCATION = "http://ns.taverna.org.uk/2013/application/profile http://localhost/2013/application/profile/ApplicationProfile.xsd";
+
+	public static final String TAVERNA_TMP = "taverna-tmp";
+
+	public static final String APPLICATION_PROFILE_FILE = "ApplicationProfile.xml";
+
+	@Component
+	private MavenProject project;
+
+	@Component
+	private ProjectDependenciesResolver projectDependenciesResolver;
+
+	@Parameter(defaultValue = "${repositorySystemSession}", readonly = true)
+	private RepositorySystemSession repositorySystemSession;
+
+	/**
+	 * The directory where the generated <code>ApplicationProfile.xml</code> file will be put.
+	 */
+	@Parameter(defaultValue = "${project.build.directory}", required = true)
+	protected File outputDirectory;
+
+	@Parameter(defaultValue = "SNAPSHOT")
+	private String buildNumber;
+
+	@Parameter
+	private List<FrameworkConfiguration> frameworkConfigurations;
+
+	@Parameter(required = true)
+	private String updateSite;
+
+	@Parameter(defaultValue = "updates.xml")
+	private String updatesFile;
+
+	@Parameter(defaultValue = "lib")
+	private String libDirectory;
+
+	@Parameter(required = true)
+	private String pluginSite;
+
+	@Parameter(defaultValue = "plugins.xml")
+	private String pluginsFile;
+
+	private Maven2OsgiConverter maven2OsgiConverter = new DefaultMaven2OsgiConverter();
+
+	private MavenOsgiUtils osgiUtils;
+
+	private File tempDirectory;
+
+	public void execute() throws MojoExecutionException, MojoFailureException {
+		try {
+			osgiUtils = new MavenOsgiUtils(project, repositorySystemSession,
+					projectDependenciesResolver, getSystemPackages(), getLog());
+			tempDirectory = new File(outputDirectory, TAVERNA_TMP);
+
+			File profileFile = createApplicationProfile();
+			project.getArtifact().setFile(profileFile);
+
+			copyDependencies();
+
+		} catch (JAXBException e) {
+			throw new MojoExecutionException("Error generating application profile", e);
+		}
+	}
+
+	private void copyDependencies() throws MojoExecutionException {
+		File libDirectory = new File(tempDirectory, "lib");
+		libDirectory.mkdirs();
+
+		try {
+			for (Artifact artifact : project.getArtifacts()) {
+				FileUtils.copyFileToDirectory(artifact.getFile(),
+						new File(libDirectory, artifact.getGroupId()));
+			}
+		} catch (IOException e) {
+			throw new MojoExecutionException("Error copying dependecies to lib directory", e);
+		}
+
+	}
+
+	/**
+	 * Generates the application profile file.
+	 *
+	 * @return the <code>File</code> that the application profile has been written to
+	 * @throws JAXBException
+	 *             if the application profile cannot be created
+	 * @throws MojoExecutionException
+	 */
+	private File createApplicationProfile() throws JAXBException, MojoExecutionException {
+		String groupId = project.getGroupId();
+		String artifactId = project.getArtifactId();
+		String version = maven2OsgiConverter.getVersion(project.getVersion());
+		if (version.endsWith("SNAPSHOT")) {
+			version = version.substring(0, version.indexOf("SNAPSHOT")) + buildNumber;
+		}
+
+		tempDirectory.mkdirs();
+		File applicationProfileFile = new File(tempDirectory, APPLICATION_PROFILE_FILE);
+
+		ApplicationProfile applicationProfile = new ApplicationProfile();
+		applicationProfile.setId(groupId + "." + artifactId);
+		applicationProfile.setName(project.getName());
+		applicationProfile.setVersion(version);
+
+		Updates updates = new Updates();
+		updates.setUpdateSite(updateSite);
+		updates.setUpdatesFile(updatesFile);
+		updates.setLibDirectory(libDirectory);
+		updates.setPluginSite(pluginSite);
+		updates.setPluginsFile(pluginsFile);
+		applicationProfile.setUpdates(updates);
+
+		List<FrameworkConfiguration> frameworkConfiguration = applicationProfile
+				.getFrameworkConfiguration();
+		for (FrameworkConfiguration configuration : frameworkConfigurations) {
+			frameworkConfiguration.add(configuration);
+		}
+
+		Set<BundleArtifact> bundleDependencies = osgiUtils.getBundleDependencies(
+				Artifact.SCOPE_COMPILE, Artifact.SCOPE_RUNTIME);
+		List<BundleInfo> runtimeBundles = osgiUtils.getBundles(bundleDependencies);
+		if (!runtimeBundles.isEmpty()) {
+			List<BundleInfo> bundles = applicationProfile.getBundle();
+			for (BundleInfo bundle : runtimeBundles) {
+				bundles.add(bundle);
+			}
+		}
+
+		JAXBContext jaxbContext = JAXBContext.newInstance(ApplicationProfile.class);
+		Marshaller marshaller = jaxbContext.createMarshaller();
+		marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
+		marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, SCHEMA_LOCATION);
+		marshaller.marshal(applicationProfile, applicationProfileFile);
+
+		return applicationProfileFile;
+	}
+
+	private Set<String> getSystemPackages() {
+		Set<String> systemPackages = new HashSet<String>();
+		if (frameworkConfigurations != null) {
+			for (FrameworkConfiguration configuration : frameworkConfigurations) {
+				if (SYSTEM_PACKAGES.equals(configuration.getName())) {
+					String packagesString = configuration.getValue();
+					if (packagesString != null) {
+						String[] packages = packagesString.split(",");
+						for (String packageString : packages) {
+							String[] packageProperties = packageString.split(";");
+							if (packageProperties.length > 0) {
+								systemPackages.add(packageProperties[0]);
+							}
+						}
+					}
+				}
+			}
+		}
+		return systemPackages;
+	}
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-taverna-osgi/blob/37264921/taverna-maven-plugin/src/main/java/net/sf/taverna/t2/maven/plugins/Utils.java
----------------------------------------------------------------------
diff --git a/taverna-maven-plugin/src/main/java/net/sf/taverna/t2/maven/plugins/Utils.java b/taverna-maven-plugin/src/main/java/net/sf/taverna/t2/maven/plugins/Utils.java
new file mode 100644
index 0000000..82f5fee
--- /dev/null
+++ b/taverna-maven-plugin/src/main/java/net/sf/taverna/t2/maven/plugins/Utils.java
@@ -0,0 +1,171 @@
+/*******************************************************************************
+ * 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 java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.URLEncoder;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.commons.codec.digest.DigestUtils;
+import org.apache.commons.io.FileUtils;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.wagon.ResourceDoesNotExistException;
+import org.apache.maven.wagon.TransferFailedException;
+import org.apache.maven.wagon.Wagon;
+import org.apache.maven.wagon.authorization.AuthorizationException;
+
+/**
+ * @author David Withers
+ */
+public class Utils {
+
+	public static String uploadFile(File file, String resourceName, Wagon wagon, Log log)
+			throws MojoExecutionException {
+		String resourceUrl = getResourceUrl(wagon, resourceName);
+		File digestFile = new File(file.getPath() + ".md5");
+		try {
+			String digestString = DigestUtils.md5Hex(new FileInputStream(file));
+			FileUtils.writeStringToFile(digestFile, digestString);
+		} catch (IOException e) {
+			throw new MojoExecutionException(
+					String.format("Error generating digest for %1$s", file), e);
+		}
+		try {
+			log.info(String.format("Uploading %1$s to %2$s", file, resourceUrl));
+			wagon.put(file, resourceName);
+			wagon.put(digestFile, resourceName + ".md5");
+		} catch (TransferFailedException e) {
+			throw new MojoExecutionException(String.format("Error transferring %1$s to %2$s", file,
+					resourceUrl), e);
+		} catch (ResourceDoesNotExistException e) {
+			throw new MojoExecutionException(String.format("%1$s does not exist", resourceUrl), e);
+		} catch (AuthorizationException e) {
+			throw new MojoExecutionException(String.format(
+					"Authentication error transferring %1$s to %2$s", file, resourceUrl), e);
+		}
+		return resourceUrl;
+	}
+
+	public static void downloadFile(String resourceName, File file, Wagon wagon, Log log)
+			throws MojoExecutionException, ResourceDoesNotExistException {
+		String resourceUrl = getResourceUrl(wagon, resourceName);
+		File digestFile = new File(file.getPath() + ".md5");
+		try {
+			log.info(String.format("Downloading %1$s to %2$s", resourceUrl, file));
+			wagon.get(resourceName, file);
+			wagon.get(resourceName + ".md5", digestFile);
+		} catch (TransferFailedException e) {
+			throw new MojoExecutionException(String.format("Error transferring %1$s to %2$s",
+					resourceUrl, file), e);
+		} catch (AuthorizationException e) {
+			throw new MojoExecutionException(String.format(
+					"Authentication error transferring %1$s to %2$s", resourceUrl, file), e);
+		}
+		try {
+			String digestString1 = DigestUtils.md5Hex(new FileInputStream(file));
+			String digestString2 = FileUtils.readFileToString(digestFile);
+			if (!digestString1.equals(digestString2)) {
+				throw new MojoExecutionException(String.format(
+						"Error downloading file: digsests not equal. (%1$s != %2$s)",
+						digestString1, digestString2));
+			}
+		} catch (IOException e) {
+			throw new MojoExecutionException(String.format("Error checking digest for %1$s", file),
+					e);
+		}
+	}
+
+	public static String getResourceUrl(Wagon wagon, String resourceName) {
+		StringBuilder urlBuilder = new StringBuilder(wagon.getRepository().getUrl());
+		for (String part : resourceName.split("/")) {
+			urlBuilder.append('/');
+			urlBuilder.append(URLEncoder.encode(part));
+		}
+		return urlBuilder.toString();
+	}
+
+	public static String timestamp() {
+		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd'T'HHmm");
+		return dateFormat.format(new Date());
+	}
+
+	public static Set<String> getJavaPackages(Log log) {
+		Set<String> javaPackages = new HashSet<String>();
+		InputStream resource = Utils.class.getClassLoader().getResourceAsStream("java7-packages");
+		if (resource != null) {
+			BufferedReader reader = new BufferedReader(new InputStreamReader(resource));
+			try {
+				String line = reader.readLine();
+				while (line != null) {
+					if (!line.isEmpty()) {
+						javaPackages.add(line.trim());
+					}
+					line = reader.readLine();
+				}
+			} catch (IOException e) {
+				log.warn(
+						"Problem while reading to readinf java package list from resource file java7-packages",
+						e);
+			}
+		} else {
+			log.warn("Unable to read java package list from resource file java7-packages");
+		}
+		return javaPackages;
+	}
+
+	public static <T> List<Set<T>> getSubsets(Set<T> set) {
+		List<Set<T>> subsets = new ArrayList<Set<T>>();
+        List<T> list = new ArrayList<T>(set);
+		int numOfSubsets = 1 << set.size();
+		for (int i = 0; i < numOfSubsets; i++){
+			Set<T> subset = new HashSet<T>();
+		    for (int j = 0; j < numOfSubsets; j++){
+		        if (((i>>j) & 1) == 1) {
+		            subset.add(list.get(j));
+		        }
+		    }
+		    if (!subset.isEmpty()) {
+		    	subsets.add(subset);
+		    }
+		}
+		Collections.sort(subsets, new Comparator<Set<T>>() {
+			@Override
+			public int compare(Set<T> o1, Set<T> o2) {
+				return o1.size() - o2.size();
+			}
+		});
+		return subsets;
+	}
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-taverna-osgi/blob/37264921/taverna-maven-plugin/src/main/resources/META-INF/plexus/components.xml
----------------------------------------------------------------------
diff --git a/taverna-maven-plugin/src/main/resources/META-INF/plexus/components.xml b/taverna-maven-plugin/src/main/resources/META-INF/plexus/components.xml
new file mode 100644
index 0000000..ad375db
--- /dev/null
+++ b/taverna-maven-plugin/src/main/resources/META-INF/plexus/components.xml
@@ -0,0 +1,32 @@
+<component-set>
+	<components>
+		<component>
+			<role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role>
+			<role-hint>taverna-plugin</role-hint>
+			<implementation>org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping
+			</implementation>
+			<configuration>
+				<phases>
+					<generate-resources>net.sf.taverna.t2.maven.plugins:taverna-maven-plugin:plugin-generate</generate-resources>
+					<prepare-package>net.sf.taverna.t2.maven.plugins:taverna-maven-plugin:plugin-prepare-bundles</prepare-package>
+					<package>org.apache.maven.plugins:maven-jar-plugin:jar</package>
+					<deploy>net.sf.taverna.t2.maven.plugins:taverna-maven-plugin:plugin-deploy</deploy>
+				</phases>
+			</configuration>
+		</component>
+		<component>
+			<role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role>
+			<role-hint>taverna-application</role-hint>
+			<implementation>org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping
+			</implementation>
+			<configuration>
+				<phases>
+					<generate-resources>net.sf.taverna.t2.maven.plugins:taverna-maven-plugin:profile-generate
+					</generate-resources>
+					<deploy>net.sf.taverna.t2.maven.plugins:taverna-maven-plugin:profile-deploy
+					</deploy>
+				</phases>
+			</configuration>
+		</component>
+	</components>
+</component-set>

http://git-wip-us.apache.org/repos/asf/incubator-taverna-osgi/blob/37264921/taverna-maven-plugin/src/main/resources/java7-packages
----------------------------------------------------------------------
diff --git a/taverna-maven-plugin/src/main/resources/java7-packages b/taverna-maven-plugin/src/main/resources/java7-packages
new file mode 100644
index 0000000..032c7dd
--- /dev/null
+++ b/taverna-maven-plugin/src/main/resources/java7-packages
@@ -0,0 +1,209 @@
+java.applet
+java.awt
+java.awt.color
+java.awt.datatransfer
+java.awt.dnd
+java.awt.event
+java.awt.font
+java.awt.geom
+java.awt.im
+java.awt.im.spi
+java.awt.image
+java.awt.image.renderable
+java.awt.print
+java.beans
+java.beans.beancontext
+java.io
+java.lang
+java.lang.annotation
+java.lang.instrument
+java.lang.invoke
+java.lang.management
+java.lang.ref
+java.lang.reflect
+java.math
+java.net
+java.nio
+java.nio.channels
+java.nio.channels.spi
+java.nio.charset
+java.nio.charset.spi
+java.nio.file
+java.nio.file.attribute
+java.nio.file.spi
+java.rmi
+java.rmi.activation
+java.rmi.dgc
+java.rmi.registry
+java.rmi.server
+java.security
+java.security.acl
+java.security.cert
+java.security.interfaces
+java.security.spec
+java.sql
+java.text
+java.text.spi
+java.util
+java.util.concurrent
+java.util.concurrent.atomic
+java.util.concurrent.locks
+java.util.jar
+java.util.logging
+java.util.prefs
+java.util.regex
+java.util.spi
+java.util.zip
+javax.accessibility
+javax.activation
+javax.activity
+javax.annotation
+javax.annotation.processing
+javax.crypto
+javax.crypto.interfaces
+javax.crypto.spec
+javax.imageio
+javax.imageio.event
+javax.imageio.metadata
+javax.imageio.plugins.bmp
+javax.imageio.plugins.jpeg
+javax.imageio.spi
+javax.imageio.stream
+javax.jws
+javax.jws.soap
+javax.lang.model
+javax.lang.model.element
+javax.lang.model.type
+javax.lang.model.util
+javax.management
+javax.management.loading
+javax.management.modelmbean
+javax.management.monitor
+javax.management.openmbean
+javax.management.relation
+javax.management.remote
+javax.management.remote.rmi
+javax.management.timer
+javax.naming
+javax.naming.directory
+javax.naming.event
+javax.naming.ldap
+javax.naming.spi
+javax.net
+javax.net.ssl
+javax.print
+javax.print.attribute
+javax.print.attribute.standard
+javax.print.event
+javax.rmi
+javax.rmi.CORBA
+javax.rmi.ssl
+javax.script
+javax.security.auth
+javax.security.auth.callback
+javax.security.auth.kerberos
+javax.security.auth.login
+javax.security.auth.spi
+javax.security.auth.x500
+javax.security.cert
+javax.security.sasl
+javax.sound.midi
+javax.sound.midi.spi
+javax.sound.sampled
+javax.sound.sampled.spi
+javax.sql
+javax.sql.rowset
+javax.sql.rowset.serial
+javax.sql.rowset.spi
+javax.swing
+javax.swing.border
+javax.swing.colorchooser
+javax.swing.event
+javax.swing.filechooser
+javax.swing.plaf
+javax.swing.plaf.basic
+javax.swing.plaf.metal
+javax.swing.plaf.multi
+javax.swing.plaf.nimbus
+javax.swing.plaf.synth
+javax.swing.table
+javax.swing.text
+javax.swing.text.html
+javax.swing.text.html.parser
+javax.swing.text.rtf
+javax.swing.tree
+javax.swing.undo
+javax.tools
+javax.transaction
+javax.transaction.xa
+javax.xml
+javax.xml.bind
+javax.xml.bind.annotation
+javax.xml.bind.annotation.adapters
+javax.xml.bind.attachment
+javax.xml.bind.helpers
+javax.xml.bind.util
+javax.xml.crypto
+javax.xml.crypto.dom
+javax.xml.crypto.dsig
+javax.xml.crypto.dsig.dom
+javax.xml.crypto.dsig.keyinfo
+javax.xml.crypto.dsig.spec
+javax.xml.datatype
+javax.xml.namespace
+javax.xml.parsers
+javax.xml.soap
+javax.xml.stream
+javax.xml.stream.events
+javax.xml.stream.util
+javax.xml.transform
+javax.xml.transform.dom
+javax.xml.transform.sax
+javax.xml.transform.stax
+javax.xml.transform.stream
+javax.xml.validation
+javax.xml.ws
+javax.xml.ws.handler
+javax.xml.ws.handler.soap
+javax.xml.ws.http
+javax.xml.ws.soap
+javax.xml.ws.spi
+javax.xml.ws.spi.http
+javax.xml.ws.wsaddressing
+javax.xml.xpath
+org.ietf.jgss
+org.omg.CORBA
+org.omg.CORBA_2_3
+org.omg.CORBA_2_3.portable
+org.omg.CORBA.DynAnyPackage
+org.omg.CORBA.ORBPackage
+org.omg.CORBA.portable
+org.omg.CORBA.TypeCodePackage
+org.omg.CosNaming
+org.omg.CosNaming.NamingContextExtPackage
+org.omg.CosNaming.NamingContextPackage
+org.omg.Dynamic
+org.omg.DynamicAny
+org.omg.DynamicAny.DynAnyFactoryPackage
+org.omg.DynamicAny.DynAnyPackage
+org.omg.IOP
+org.omg.IOP.CodecFactoryPackage
+org.omg.IOP.CodecPackage
+org.omg.Messaging
+org.omg.PortableInterceptor
+org.omg.PortableInterceptor.ORBInitInfoPackage
+org.omg.PortableServer
+org.omg.PortableServer.CurrentPackage
+org.omg.PortableServer.POAManagerPackage
+org.omg.PortableServer.POAPackage
+org.omg.PortableServer.portable
+org.omg.PortableServer.ServantLocatorPackage
+org.omg.SendingContext
+org.omg.stub.java.rmi
+org.w3c.dom
+org.w3c.dom.bootstrap
+org.w3c.dom.events
+org.w3c.dom.ls
+org.xml.sax
+org.xml.sax.ext
+org.xml.sax.helpers
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-taverna-osgi/blob/37264921/taverna-maven-plugin/src/test/java/net/sf/taverna/t2/maven/plugins/TavernaPluginGenerateMojoTest.java
----------------------------------------------------------------------
diff --git a/taverna-maven-plugin/src/test/java/net/sf/taverna/t2/maven/plugins/TavernaPluginGenerateMojoTest.java b/taverna-maven-plugin/src/test/java/net/sf/taverna/t2/maven/plugins/TavernaPluginGenerateMojoTest.java
new file mode 100644
index 0000000..6f21fb1
--- /dev/null
+++ b/taverna-maven-plugin/src/test/java/net/sf/taverna/t2/maven/plugins/TavernaPluginGenerateMojoTest.java
@@ -0,0 +1,80 @@
+/*******************************************************************************
+ * 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 org.apache.maven.plugin.testing.AbstractMojoTestCase;
+import org.junit.Ignore;
+import org.junit.Test;
+
+/**
+ * Unit tests for TavernaPluginGenerateMojo.
+ *
+ * @author David Withers
+ */
+public class TavernaPluginGenerateMojoTest extends AbstractMojoTestCase {
+
+	private TavernaPluginGenerateMojo tavernaPluginGenerateMojo;
+
+	/**
+	 * @throws java.lang.Exception
+	 */
+	@Ignore
+	public void setUp() throws Exception {
+//		super.setUp();
+//
+//		File pluginXml = new File( getBasedir(), "src/test/resources/unit/plugin-config.xml" );
+//        tavernaPluginGenerateMojo = (TavernaPluginGenerateMojo) lookupMojo( "plugin-generate", pluginXml );
+//
+//		MavenProject mavenProject = (MavenProject) getVariableValueFromObject(tavernaPluginGenerateMojo, "project");
+//
+//		Artifact artifact = new DefaultArtifact("net.sf.taverna.t2", "example-plugin", VersionRange
+//				.createFromVersion("0.1.0"), "compile", "jar", "", null);
+//        artifact.setRepository(new DefaultArtifactRepository("id1",
+//				"http://www.mygrid.org.uk/maven/repository", new DefaultRepositoryLayout()));
+//		mavenProject.setArtifact(artifact);
+//
+//
+//		Artifact dependency = new DefaultArtifact("com.example.test", "test-artifact", VersionRange
+//				.createFromVersion("1.3.5"), "compile", "jar", "", null);
+//		dependency.setGroupId("com.example.test");
+//		dependency.setArtifactId("test-artifact");
+//		dependency.setVersion("1.3.5");
+//		dependency.setRepository(new DefaultArtifactRepository("id2",
+//				"http://www.example.com/maven/repository", new DefaultRepositoryLayout()));
+//		mavenProject.setDependencyArtifacts(Collections.singleton(dependency));
+//
+//		MavenSession session = new MavenSession(getContainer(), (RepositorySystemSession) null, (MavenExecutionRequest) null, (MavenExecutionResult) null);
+//		setVariableValueToObject(tavernaPluginGenerateMojo, "session", session);
+	}
+
+	/**
+	 * Test method for
+	 * {@link net.sf.taverna.t2.maven.plugins.TavernaPluginGenerateMojo#execute()}
+	 *
+	 * @throws Exception
+	 */
+	@Test
+	@Ignore
+	public void testExecute() throws Exception {
+//		tavernaPluginGenerateMojo.execute();
+	}
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-taverna-osgi/blob/37264921/taverna-maven-plugin/src/test/resources/unit/plugin-config.xml
----------------------------------------------------------------------
diff --git a/taverna-maven-plugin/src/test/resources/unit/plugin-config.xml b/taverna-maven-plugin/src/test/resources/unit/plugin-config.xml
new file mode 100644
index 0000000..a8c1723
--- /dev/null
+++ b/taverna-maven-plugin/src/test/resources/unit/plugin-config.xml
@@ -0,0 +1,19 @@
+<project>
+	<build>
+		<plugins>
+			<plugin>
+				<groupId>net.sf.taverna.t2.maven.plugins</groupId>
+				<artifactId>taverna-maven-plugin</artifactId>
+				<configuration>
+					<buildDirectory>${basedir}/target/test/unit</buildDirectory>
+					<project>
+						<groupId>net.sf.taverna.t2</groupId>
+						<artifactId>example-plugin</artifactId>
+						<version>0.1.0</version>
+						<name>Taverna 2 Example Plugin</name>
+					</project>
+				</configuration>
+			</plugin>
+		</plugins>
+	</build>
+</project>
\ No newline at end of file