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/04/13 15:58:15 UTC
svn commit: r393811 - in
/geronimo/devtools/eclipse-plugin/trunk/maven-plugins/maven-geronimodevtools-plugin/src/main/java/org/apache/geronimo/eclipse/devtools:
InstallPluginDependenciesMojo.java ManifestDependenciesMojo.java
Author: sppatel
Date: Thu Apr 13 06:58:12 2006
New Revision: 393811
URL: http://svn.apache.org/viewcvs?rev=393811&view=rev
Log:
improved plugin dependency management, don't have to sync dependencies in both osgi manifest and POM
Added:
geronimo/devtools/eclipse-plugin/trunk/maven-plugins/maven-geronimodevtools-plugin/src/main/java/org/apache/geronimo/eclipse/devtools/ManifestDependenciesMojo.java (with props)
Modified:
geronimo/devtools/eclipse-plugin/trunk/maven-plugins/maven-geronimodevtools-plugin/src/main/java/org/apache/geronimo/eclipse/devtools/InstallPluginDependenciesMojo.java
Modified: 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=393811&r1=393810&r2=393811&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/maven-plugins/maven-geronimodevtools-plugin/src/main/java/org/apache/geronimo/eclipse/devtools/InstallPluginDependenciesMojo.java (original)
+++ geronimo/devtools/eclipse-plugin/trunk/maven-plugins/maven-geronimodevtools-plugin/src/main/java/org/apache/geronimo/eclipse/devtools/InstallPluginDependenciesMojo.java Thu Apr 13 06:58:12 2006
@@ -19,6 +19,7 @@
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
+import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@@ -42,23 +43,25 @@
* This maven plugin installs to the local maven repository eclipse plugin
* dependencies for a pom from an eclipse distribution.
*
+ * Plugins dependencies are defined with the "org.eclipse.plugins" groupId.
+ *
+ * The artifactId is the bundle id. If the bundle is a directory, then all jars
+ * inside the bundle will be installed. The bundle id can be appendend with "." +
+ * the name of the jar inside the bundle, excluding the ".jar" extension in
+ * order to explicitly define a jar dependency.
+ *
* @goal install
*/
public class InstallPluginDependenciesMojo extends AbstractMojo {
- private static final String GROUP_ID = "org.eclipse.plugins";
-
+ public static final String GROUP_ID = "org.eclipse.plugins";
+
/**
* @parameter expression="${project}"
*/
private MavenProject project;
/**
- * @parameter expression="${eclipseHome}"
- */
- private File eclipseHome;
-
- /**
* @parameter expression="${component.org.apache.maven.artifact.factory.ArtifactFactory}"
* @required
* @readonly
@@ -78,12 +81,21 @@
* @readonly
*/
protected ArtifactRepository localRepository;
-
+
+ /**
+ * @parameter expression="${eclipseHome}"
+ */
+ private File eclipseHome;
+
/**
* @parameter expression="${useDistributionVersions}"
*/
protected boolean useDistributionVersion;
+ private List removeList = new ArrayList();
+
+ private int depth = 0;
+
public InstallPluginDependenciesMojo() {
super();
}
@@ -98,35 +110,33 @@
if (!isValid())
throw new MojoFailureException("Eclipse home directory is not valid. "
+ eclipseHome);
-
- File pluginsDir = new File(eclipseHome.getAbsolutePath().concat(File.separator
- + "plugins"));
-
- processDependenciesOnly(pluginsDir);
+
+ processDependencies();
+ project.getDependencies().removeAll(removeList);
}
- protected void processDependenciesOnly(File pluginsDir) {
+ protected void processDependencies() {
List dependencies = project.getDependencies();
Iterator i = dependencies.iterator();
while (i.hasNext()) {
Dependency dependency = (Dependency) i.next();
if (GROUP_ID.equals(dependency.getGroupId())) {
updateForSWTFragment(dependency);
- getLog().debug("Eclipse dependency: " + dependency.toString());
- process(pluginsDir, 0, dependency);
+ File file = findBundleForDependency(dependency);
+ process(file, dependency);
}
}
}
private void updateForSWTFragment(Dependency dependency) {
- if("org.eclipse.swt.fragment".equals(dependency.getArtifactId())) {
+ if ("org.eclipse.swt.fragment".equals(dependency.getArtifactId())) {
String platform = System.getProperty("os.name");
String id = dependency.getArtifactId();
- if(platform.startsWith("Windows")) {
+ if (platform.startsWith("Windows")) {
dependency.setArtifactId(id.replaceFirst("fragment", "win32.win32.x86"));
- } else if(platform.startsWith("Linux")) {
+ } else if (platform.startsWith("Linux")) {
dependency.setArtifactId(id.replaceFirst("fragment", "gtk.linux.x86"));
- } else if(platform.startsWith("Mac")) {
+ } else if (platform.startsWith("Mac")) {
dependency.setArtifactId(id.replaceFirst("fragment", "carbon.macosx.ppc"));
}
}
@@ -136,22 +146,41 @@
return eclipseHome != null && eclipseHome.isDirectory();
}
- protected void process(File file, int depth, Dependency dependency) {
+ private File findBundleForDependency(Dependency dependency) {
+ File pluginsDir = new File(eclipseHome + File.separator + "plugins");
+ File[] members = pluginsDir.listFiles();
+ for (int i = 0; i < members.length; i++) {
+ if (isBundleForDependency(dependency, members[i]))
+ return members[i];
+ }
+ return null;
+ }
+
+ private boolean isBundleForDependency(Dependency dependency, File bundle) {
+ String bundleName = getBundleName(bundle);
+ return dependency.getArtifactId().startsWith(bundleName);
+ }
+
+ protected void process(File file, Dependency dependency) {
if (file.isDirectory()) {
depth++;
File[] members = file.listFiles();
for (int i = 0; i < members.length; i++) {
- process(members[i], depth, dependency);
+ process(members[i], dependency);
}
depth--;
} else {
if (file.getName().endsWith(".jar")) {
- File bundle = getBundle(file, depth);
- if (getArtifactID(file, bundle).equals(dependency.getArtifactId())) {
- install(file, bundle);
- if(useDistributionVersion)
- dependency.setVersion(getBundleVersion(bundle));
+ File bundle = getBundle(file);
+
+ if(bundle.isDirectory()) {
+ getLog().info("removing dependency " + dependency.getArtifactId());
+ removeList.add(dependency);
}
+
+ install(file, bundle);
+ if (useDistributionVersion)
+ dependency.setVersion(getBundleVersion(bundle));
}
}
}
@@ -160,10 +189,10 @@
String artifactId = getArtifactID(artifact, bundle);
String version = getBundleVersion(bundle);
-
- if(!useDistributionVersion)
+
+ if (!useDistributionVersion)
version = fixVersion(version);
-
+
try {
doIt(artifact, GROUP_ID, artifactId, version, "jar");
} catch (MojoExecutionException e) {
@@ -172,30 +201,31 @@
e.printStackTrace();
}
}
-
+
/**
* Converts eclipse qualifier convention to maven convention.
*
- * major.minor.revision.qualifier is converted to major.minor.revision-build where
- * build is the eclipse qualifier with all non-numeric characters removed.
+ * major.minor.revision.qualifier is converted to major.minor.revision-build
+ * where build is the eclipse qualifier with all non-numeric characters
+ * removed.
*
* @param version
* @return
*/
public static String fixVersion(String version) {
int qualifierIndex = version.indexOf(".", 5);
- if(qualifierIndex == -1)
- return version; //has no qualifier
+ if (qualifierIndex == -1)
+ return version; // has no qualifier
String eclipseQualifier = version.substring(qualifierIndex + 1);
String newQualifier = eclipseQualifier.replaceAll("[^\\d]", "");
return version.substring(0, qualifierIndex) + "-" + newQualifier;
}
- protected File getBundle(File file, int depth) {
+ protected File getBundle(File file) {
File bundle = file;
- if (depth > 1) {
+ if (depth > 0) {
bundle = file.getParentFile();
- for (int i = depth - 1; i > 1; i--) {
+ for (int i = depth - 1; i > 0; i--) {
bundle = bundle.getParentFile();
}
}
@@ -251,7 +281,8 @@
}
}
- private void generatePOM(Artifact artifact, String groupId, String artifactId, String version) throws MojoExecutionException{
+ private void generatePOM(Artifact artifact, String groupId,
+ String artifactId, String version) throws MojoExecutionException {
FileWriter fw = null;
try {
@@ -286,4 +317,4 @@
return fileName;
}
-}
+}
\ No newline at end of file
Added: geronimo/devtools/eclipse-plugin/trunk/maven-plugins/maven-geronimodevtools-plugin/src/main/java/org/apache/geronimo/eclipse/devtools/ManifestDependenciesMojo.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/ManifestDependenciesMojo.java?rev=393811&view=auto
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/maven-plugins/maven-geronimodevtools-plugin/src/main/java/org/apache/geronimo/eclipse/devtools/ManifestDependenciesMojo.java (added)
+++ geronimo/devtools/eclipse-plugin/trunk/maven-plugins/maven-geronimodevtools-plugin/src/main/java/org/apache/geronimo/eclipse/devtools/ManifestDependenciesMojo.java Thu Apr 13 06:58:12 2006
@@ -0,0 +1,101 @@
+/**
+ * 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.io.FileInputStream;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.StringTokenizer;
+import java.util.jar.Manifest;
+
+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 manifestbundles
+ * @description Adds dependencies from plugin manfiest at build time
+ */
+public class ManifestDependenciesMojo extends AbstractMojo {
+
+ /**
+ * @parameter expression="${project}"
+ * @required
+ */
+ private MavenProject project;
+
+ /**
+ * @parameter expression="${project.basedir}/META-INF/MANIFEST.MF"
+ * @required
+ */
+ private File manifestFile;
+
+ /**
+ * @parameter expression="true"
+ */
+ private boolean excludePOMDependencies;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.maven.plugin.Mojo#execute()
+ */
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ try {
+ FileInputStream fis = new FileInputStream(manifestFile);
+ Manifest manifest = new Manifest();
+ manifest.read(fis);
+ fis.close();
+ String bundles = manifest.getMainAttributes().getValue("Require-Bundle");
+
+ StringTokenizer st = new StringTokenizer(bundles);
+ List bundleEntries = new ArrayList();
+ while (st.hasMoreTokens()) {
+ bundleEntries.add(st.nextToken(","));
+ }
+
+ List excludeList = new ArrayList();
+ if (excludePOMDependencies) {
+ Iterator i = project.getDependencies().iterator();
+ while (i.hasNext())
+ excludeList.add(((Dependency) i.next()).getArtifactId());
+ }
+
+ Iterator i = bundleEntries.iterator();
+ while (i.hasNext()) {
+ String artifactId = (String) i.next();
+ if (!excludeList.contains(artifactId)) {
+ Dependency dependency = createDependency(artifactId);
+ project.getDependencies().add(dependency);
+ }
+ }
+ } catch (Exception e) {
+ throw new MojoFailureException(e.getMessage());
+ }
+ }
+
+ private Dependency createDependency(String artifactId) {
+ Dependency dependency = new Dependency();
+ dependency.setGroupId("org.eclipse.plugins");
+ dependency.setArtifactId(artifactId);
+ return dependency;
+ }
+
+}
Propchange: geronimo/devtools/eclipse-plugin/trunk/maven-plugins/maven-geronimodevtools-plugin/src/main/java/org/apache/geronimo/eclipse/devtools/ManifestDependenciesMojo.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/devtools/eclipse-plugin/trunk/maven-plugins/maven-geronimodevtools-plugin/src/main/java/org/apache/geronimo/eclipse/devtools/ManifestDependenciesMojo.java
------------------------------------------------------------------------------
svn:keywords = Date Rev
Propchange: geronimo/devtools/eclipse-plugin/trunk/maven-plugins/maven-geronimodevtools-plugin/src/main/java/org/apache/geronimo/eclipse/devtools/ManifestDependenciesMojo.java
------------------------------------------------------------------------------
svn:mime-type = text/plain