You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by sp...@apache.org on 2006/03/01 20:34:10 UTC

svn commit: r382131 - in /geronimo/devtools/eclipse-plugin/trunk/maven-plugins: ./ maven-geronimodevtools-plugin/ maven-geronimodevtools-plugin/src/ maven-geronimodevtools-plugin/src/main/ maven-geronimodevtools-plugin/src/main/java/ maven-geronimodevt...

Author: sppatel
Date: Wed Mar  1 11:34:08 2006
New Revision: 382131

URL: http://svn.apache.org/viewcvs?rev=382131&view=rev
Log:
initial drop of m2 plugins

Added:
    geronimo/devtools/eclipse-plugin/trunk/maven-plugins/
    geronimo/devtools/eclipse-plugin/trunk/maven-plugins/maven-geronimodevtools-plugin/
    geronimo/devtools/eclipse-plugin/trunk/maven-plugins/maven-geronimodevtools-plugin/pom.xml   (with props)
    geronimo/devtools/eclipse-plugin/trunk/maven-plugins/maven-geronimodevtools-plugin/src/
    geronimo/devtools/eclipse-plugin/trunk/maven-plugins/maven-geronimodevtools-plugin/src/main/
    geronimo/devtools/eclipse-plugin/trunk/maven-plugins/maven-geronimodevtools-plugin/src/main/java/
    geronimo/devtools/eclipse-plugin/trunk/maven-plugins/maven-geronimodevtools-plugin/src/main/java/org/
    geronimo/devtools/eclipse-plugin/trunk/maven-plugins/maven-geronimodevtools-plugin/src/main/java/org/apache/
    geronimo/devtools/eclipse-plugin/trunk/maven-plugins/maven-geronimodevtools-plugin/src/main/java/org/apache/geronimo/
    geronimo/devtools/eclipse-plugin/trunk/maven-plugins/maven-geronimodevtools-plugin/src/main/java/org/apache/geronimo/eclipse/
    geronimo/devtools/eclipse-plugin/trunk/maven-plugins/maven-geronimodevtools-plugin/src/main/java/org/apache/geronimo/eclipse/devtools/
    geronimo/devtools/eclipse-plugin/trunk/maven-plugins/maven-geronimodevtools-plugin/src/main/java/org/apache/geronimo/eclipse/devtools/DownloadMojo.java   (with props)
    geronimo/devtools/eclipse-plugin/trunk/maven-plugins/maven-geronimodevtools-plugin/src/main/java/org/apache/geronimo/eclipse/devtools/InstallPluginDependenciesMojo.java   (with props)

Added: geronimo/devtools/eclipse-plugin/trunk/maven-plugins/maven-geronimodevtools-plugin/pom.xml
URL: http://svn.apache.org/viewcvs/geronimo/devtools/eclipse-plugin/trunk/maven-plugins/maven-geronimodevtools-plugin/pom.xml?rev=382131&view=auto
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/maven-plugins/maven-geronimodevtools-plugin/pom.xml (added)
+++ geronimo/devtools/eclipse-plugin/trunk/maven-plugins/maven-geronimodevtools-plugin/pom.xml Wed Mar  1 11:34:08 2006
@@ -0,0 +1,31 @@
+<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/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.apache.geronimo.devtools</groupId>
+  <artifactId>maven-geronimodevtools-plugin</artifactId>
+  <packaging>maven-plugin</packaging>
+  <version>1.0-SNAPSHOT</version>
+  <name>Geronimo Devtools Maven Plugin</name>
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-plugin-api</artifactId>
+      <version>2.0.1</version>
+    </dependency>
+    <dependency>
+      <groupId>ant</groupId>
+      <artifactId>ant</artifactId>
+      <version>1.6.5</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-project</artifactId>
+      <version>2.0</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven.plugins</groupId>
+      <artifactId>maven-install-plugin</artifactId>
+      <version>2.1</version>
+    </dependency>
+  </dependencies>
+</project>
\ No newline at end of file

Propchange: geronimo/devtools/eclipse-plugin/trunk/maven-plugins/maven-geronimodevtools-plugin/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/devtools/eclipse-plugin/trunk/maven-plugins/maven-geronimodevtools-plugin/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/devtools/eclipse-plugin/trunk/maven-plugins/maven-geronimodevtools-plugin/pom.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: geronimo/devtools/eclipse-plugin/trunk/maven-plugins/maven-geronimodevtools-plugin/src/main/java/org/apache/geronimo/eclipse/devtools/DownloadMojo.java
URL: http://svn.apache.org/viewcvs/geronimo/devtools/eclipse-plugin/trunk/maven-plugins/maven-geronimodevtools-plugin/src/main/java/org/apache/geronimo/eclipse/devtools/DownloadMojo.java?rev=382131&view=auto
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/maven-plugins/maven-geronimodevtools-plugin/src/main/java/org/apache/geronimo/eclipse/devtools/DownloadMojo.java (added)
+++ geronimo/devtools/eclipse-plugin/trunk/maven-plugins/maven-geronimodevtools-plugin/src/main/java/org/apache/geronimo/eclipse/devtools/DownloadMojo.java Wed Mar  1 11:34:08 2006
@@ -0,0 +1,128 @@
+package org.apache.geronimo.eclipse.devtools;
+
+/**
+ * Copyright 2004, 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+import java.io.File;
+import java.net.URL;
+
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugin.install.InstallFileMojo;
+import org.apache.maven.project.MavenProject;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.taskdefs.Expand;
+import org.apache.tools.ant.taskdefs.Get;
+import org.apache.tools.ant.taskdefs.Untar;
+
+/**
+ * @goal download
+ * @description Downloads eclipse project distributions into local repository.
+ */
+public class DownloadMojo extends AbstractMojo {
+
+	private static final String ECLIPSE_INSTALL_PATH = "eclipse/";
+	private static final String DISTRO_PATH = ECLIPSE_INSTALL_PATH
+			+ "distributions/";
+
+	/**
+	 * @parameter expression="${project}"
+	 * @required
+	 */
+	private MavenProject project;
+
+	/**
+	 * @parameter expression="${settings.localRepository}"
+	 */
+	private String localRepoLoc;
+
+	/**
+	 * @parameter
+	 */
+	private URL[] urls;
+
+	private File distributionDir;
+	private File installDir;
+
+	public DownloadMojo() {
+		super();
+	}
+
+	private void init() {
+		distributionDir = new File(localRepoLoc + File.separator + DISTRO_PATH);
+		installDir = new File(localRepoLoc + File.separator
+				+ ECLIPSE_INSTALL_PATH);
+		getLog().info("Distribution directory set to: "
+				+ distributionDir.getAbsolutePath());
+		getLog().info("Installation directory set to: "
+				+ installDir.getAbsolutePath());
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.apache.maven.plugin.Mojo#execute()
+	 */
+	public void execute() throws MojoExecutionException, MojoFailureException {
+		init();
+
+		if (urls == null) {
+			getLog().info("No URL's specified in configuration.  Nothing to download.");
+			return;
+		}
+
+		if (!distributionDir.exists())
+			distributionDir.mkdirs();
+
+		for (int i = 0; i < urls.length; i++) {
+			File distro = getRepositoryDestination(urls[i]);
+			if (!distro.exists()) {
+				download(urls[i]);
+			} else {
+				getLog().info(distro.getAbsolutePath()
+						+ " already exists in local repository");
+			}
+			install(distro);
+		}
+	}
+
+	private File getRepositoryDestination(URL url) {
+		File file = new File(url.getFile());
+		return new File(localRepoLoc + File.separator + DISTRO_PATH
+				+ file.getName());
+	}
+
+	private void download(URL url) {
+		Get getTask = new Get();
+		getTask.setProject(new Project());
+		getTask.setSrc(url);
+		getTask.setDest(getRepositoryDestination(url));
+		getLog().info("Downloading " + url.toExternalForm() + "...");
+		getTask.execute();
+	}
+
+	private void install(File file) {
+		if (file.getName().endsWith(".zip")) {
+			Expand expandTask = new Expand();
+			expandTask.setProject(new Project());
+			expandTask.setSrc(file);
+			expandTask.setDest(installDir);
+			getLog().info("Extracting " + file.getAbsolutePath());
+			expandTask.execute();
+		}
+	}
+
+}

Propchange: geronimo/devtools/eclipse-plugin/trunk/maven-plugins/maven-geronimodevtools-plugin/src/main/java/org/apache/geronimo/eclipse/devtools/DownloadMojo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/devtools/eclipse-plugin/trunk/maven-plugins/maven-geronimodevtools-plugin/src/main/java/org/apache/geronimo/eclipse/devtools/DownloadMojo.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/devtools/eclipse-plugin/trunk/maven-plugins/maven-geronimodevtools-plugin/src/main/java/org/apache/geronimo/eclipse/devtools/DownloadMojo.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/devtools/eclipse-plugin/trunk/maven-plugins/maven-geronimodevtools-plugin/src/main/java/org/apache/geronimo/eclipse/devtools/InstallPluginDependenciesMojo.java
URL: http://svn.apache.org/viewcvs/geronimo/devtools/eclipse-plugin/trunk/maven-plugins/maven-geronimodevtools-plugin/src/main/java/org/apache/geronimo/eclipse/devtools/InstallPluginDependenciesMojo.java?rev=382131&view=auto
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/maven-plugins/maven-geronimodevtools-plugin/src/main/java/org/apache/geronimo/eclipse/devtools/InstallPluginDependenciesMojo.java (added)
+++ geronimo/devtools/eclipse-plugin/trunk/maven-plugins/maven-geronimodevtools-plugin/src/main/java/org/apache/geronimo/eclipse/devtools/InstallPluginDependenciesMojo.java Wed Mar  1 11:34:08 2006
@@ -0,0 +1,207 @@
+/**
+ * Copyright 2004, 2005 The Apache Software Foundation or its licensors, as
+ * applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.apache.geronimo.eclipse.devtools;
+
+import java.io.File;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.artifact.installer.ArtifactInstallationException;
+import org.apache.maven.artifact.installer.ArtifactInstaller;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.model.Dependency;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.project.MavenProject;
+
+/**
+ * @goal install
+ */
+public class InstallPluginDependenciesMojo extends AbstractMojo {
+
+	private static final String GROUP_ID = "org.eclipse.plugins";
+
+	/**
+	 * @parameter expression="${project}"
+	 */
+	private MavenProject project;
+
+	/**
+	 * @parameter expression="${eclipse.home}"
+	 */
+	private File eclipsehome;
+
+	/**
+	 * @parameter expression="${component.org.apache.maven.artifact.factory.ArtifactFactory}"
+	 * @required
+	 * @readonly
+	 */
+	private ArtifactFactory artifactFactory;
+
+	/**
+	 * @parameter expression="${component.org.apache.maven.artifact.installer.ArtifactInstaller}"
+	 * @required
+	 * @readonly
+	 */
+	protected ArtifactInstaller installer;
+
+	/**
+	 * @parameter expression="${localRepository}"
+	 * @required
+	 * @readonly
+	 */
+	protected ArtifactRepository localRepository;
+
+	public InstallPluginDependenciesMojo() {
+		super();
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.apache.maven.plugin.Mojo#execute()
+	 */
+	public void execute() throws MojoExecutionException, MojoFailureException {
+
+		if (!isValid())
+			throw new MojoFailureException("Eclipse home directory is not valid. "
+					+ eclipsehome);
+
+		File pluginsDir = new File(eclipsehome.getAbsolutePath().concat(File.separator
+				+ "plugins"));
+		
+		//process(pluginsDir, 0, null);
+		processDependenciesOnly(pluginsDir);
+	}
+
+	protected void processDependenciesOnly(File pluginsDir) {
+		List dependencies = project.getDependencies();
+		Iterator i = dependencies.iterator();
+		while (i.hasNext()) {
+			Dependency dependency = (Dependency) i.next();
+			getLog().debug(dependency.toString());
+			if (GROUP_ID.equals(dependency.getGroupId())) {
+				process(pluginsDir, 0, dependency.getArtifactId());
+			}
+		}
+	}
+
+	protected boolean isValid() {
+		return eclipsehome != null && eclipsehome.isDirectory();
+	}
+
+	protected void process(File file, int depth, String artifactId) {
+		getLog().debug("processFile() depth = " + Integer.toString(depth) + " "
+				+ file.getAbsolutePath());
+		if (file.isDirectory()) {
+			depth++;
+			File[] members = file.listFiles();
+			for (int i = 0; i < members.length; i++) {
+				process(members[i], depth, artifactId);
+			}
+			depth--;
+		} else {
+			if (shouldInstall(artifactId, file)) {
+				install(file, depth);
+			}
+		}
+	}
+
+	protected boolean shouldInstall(String artifactId, File file) {
+		if (!file.getName().endsWith(".jar"))
+			return false;
+		return artifactId == null || getArtifactID(file).equals(artifactId);
+	}
+
+	protected void install(File file, int depth) {
+		String artifactId;
+		String version;
+		if (depth > 1) {
+			File bundleDir = getBundleDir(file, depth);
+			artifactId = getBundleName(bundleDir) + "." + getArtifactID(file);
+			version = getBundleVersion(bundleDir);
+		} else {
+			artifactId = getArtifactID(file);
+			version = getBundleVersion(file);
+		}
+
+		try {
+			doIt(file, GROUP_ID, artifactId, version, "jar");
+		} catch (MojoExecutionException e) {
+			e.printStackTrace();
+		} catch (MojoFailureException e) {
+			e.printStackTrace();
+		}
+	}
+
+	protected File getBundleDir(File file, int depth) {
+		File pluginDir = file.getParentFile();
+		for (int i = depth - 1; i > 1; i--) {
+			pluginDir = pluginDir.getParentFile();
+		}
+		return pluginDir;
+	}
+
+	public static String getBundleName(File bundle) {
+		String id = getArtifactID(bundle);
+		return id.substring(0, id.indexOf("_"));
+	}
+
+	public static String getBundleVersion(File bundle) {
+		String id = getArtifactID(bundle);
+		return id.substring(id.indexOf("_") + 1, id.length());
+	}
+
+	public static String getArtifactID(File file) {
+		String name = file.getName();
+		if (file.isFile())
+			name = name.substring(0, name.lastIndexOf(".jar"));
+		return name;
+	}
+
+	private void doIt(File file, String groupId, String artifactId,
+			String version, String packaging) throws MojoExecutionException,
+			MojoFailureException {
+		
+		Artifact artifact = artifactFactory.createArtifact(groupId, artifactId, version, null, packaging);
+
+		try {
+			String localPath = localRepository.pathOf(artifact);
+			File destination = new File(localRepository.getBasedir(), localPath);
+			
+			if(destination.exists()) {
+				getLog().info(artifactId + " " + version + " already exists in local repository.");
+				return;
+			}
+			
+			if (!file.getPath().equals(destination.getPath())) {
+				installer.install(file, artifact, localRepository);
+			} else {
+				throw new MojoFailureException("Cannot install artifact. Artifact is already in the local repository.\n\nFile in question is: "
+						+ file + "\n");
+			}
+		} catch (ArtifactInstallationException e) {
+			throw new MojoExecutionException("Error installing artifact '"
+					+ artifact.getDependencyConflictId() + "': "
+					+ e.getMessage(), e);
+		}
+	}
+
+}

Propchange: geronimo/devtools/eclipse-plugin/trunk/maven-plugins/maven-geronimodevtools-plugin/src/main/java/org/apache/geronimo/eclipse/devtools/InstallPluginDependenciesMojo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/devtools/eclipse-plugin/trunk/maven-plugins/maven-geronimodevtools-plugin/src/main/java/org/apache/geronimo/eclipse/devtools/InstallPluginDependenciesMojo.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/devtools/eclipse-plugin/trunk/maven-plugins/maven-geronimodevtools-plugin/src/main/java/org/apache/geronimo/eclipse/devtools/InstallPluginDependenciesMojo.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain