geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sppa...@apache.org
Subject svn commit: r393915 - in /geronimo/devtools/eclipse-plugin/trunk/maven-plugins/maven-geronimodevtools-plugin/src/main/java/org/apache/geronimo/eclipse/devtools: InstallPluginDependenciesMojo.java ManifestDependenciesMojo.java
Date Thu, 13 Apr 2006 20:17:18 GMT
Author: sppatel
Date: Thu Apr 13 13:17:15 2006
New Revision: 393915

URL: http://svn.apache.org/viewcvs?rev=393915&view=rev
Log:
support for exported bundle entries

Modified:
    geronimo/devtools/eclipse-plugin/trunk/maven-plugins/maven-geronimodevtools-plugin/src/main/java/org/apache/geronimo/eclipse/devtools/InstallPluginDependenciesMojo.java
    geronimo/devtools/eclipse-plugin/trunk/maven-plugins/maven-geronimodevtools-plugin/src/main/java/org/apache/geronimo/eclipse/devtools/ManifestDependenciesMojo.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=393915&r1=393914&r2=393915&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 13:17:15 2006
@@ -93,7 +93,7 @@
 	protected boolean useDistributionVersion = true;
 
 	private List removeList = new ArrayList();
-	
+
 	private List addList = new ArrayList();
 
 	private int depth = 0;
@@ -112,7 +112,7 @@
 		if (!isValid())
 			throw new MojoFailureException("Eclipse home directory is not valid. "
 					+ eclipseHome);
-		
+
 		processDependencies();
 		project.getDependencies().removeAll(removeList);
 		project.getDependencies().addAll(addList);
@@ -126,10 +126,17 @@
 			if (GROUP_ID.equals(dependency.getGroupId())) {
 				updateForSWTFragment(dependency);
 				File bundle = findBundleForDependency(dependency);
-				process(bundle, dependency);
-				if(bundle.isDirectory() && getBundleName(bundle).equals(dependency.getArtifactId()))
{
-					getLog().info("Removing bundle directory dependency " + dependency.getArtifactId());
-					removeList.add(dependency);
+				if (bundle != null) {
+					process(bundle, dependency);
+					if (bundle.isDirectory()
+							&& getBundleName(bundle).equals(dependency.getArtifactId())) {
+						getLog().info("Removing bundle directory dependency: "
+								+ dependency.getArtifactId());
+						removeList.add(dependency);
+					}
+				} else {
+					getLog().info("Bundle for dependency not found: "
+							+ dependency.getArtifactId());
 				}
 			}
 		}
@@ -193,8 +200,8 @@
 
 		if (!useDistributionVersion)
 			version = fixVersion(version);
-		
-		if(bundle.isDirectory())
+
+		if (bundle.isDirectory())
 			addList.add(createDependency(artifactId, version));
 
 		try {

Modified: 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=393915&r1=393914&r2=393915&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/maven-plugins/maven-geronimodevtools-plugin/src/main/java/org/apache/geronimo/eclipse/devtools/ManifestDependenciesMojo.java
(original)
+++ geronimo/devtools/eclipse-plugin/trunk/maven-plugins/maven-geronimodevtools-plugin/src/main/java/org/apache/geronimo/eclipse/devtools/ManifestDependenciesMojo.java
Thu Apr 13 13:17:15 2006
@@ -17,10 +17,14 @@
 
 import java.io.File;
 import java.io.FileInputStream;
+import java.io.IOException;
 import java.util.ArrayList;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Set;
 import java.util.StringTokenizer;
+import java.util.jar.JarFile;
 import java.util.jar.Manifest;
 
 import org.apache.maven.model.Dependency;
@@ -35,6 +39,11 @@
  */
 public class ManifestDependenciesMojo extends AbstractMojo {
 
+	public static String MANIFEST_REXPORT_DEPENDENCY = "visibility:=reexport";
+
+	public static String MANIFEST_PATH = "META-INF" + File.separator
+			+ "MANIFEST.MF";
+
 	/**
 	 * @parameter expression="${project}"
 	 * @required
@@ -52,46 +61,116 @@
 	 */
 	private boolean excludePOMDependencies;
 
+	/**
+	 * @parameter expression="${eclipseHome}"
+	 */
+	private File eclipseHome;
+
+	private Set bundleEntries = new HashSet();
+	private Set exportedEntries = new HashSet();
+
 	/*
 	 * (non-Javadoc)
 	 * 
 	 * @see org.apache.maven.plugin.Mojo#execute()
 	 */
 	public void execute() throws MojoExecutionException, MojoFailureException {
+
+		addRequiredBundles(getManifestFromFile(manifestFile), false);
+
+		Iterator i = bundleEntries.iterator();
+		while (i.hasNext()) {
+			addExportedBundles((String) i.next());
+		}
+
+		bundleEntries.addAll(exportedEntries);
+
+		List excludeList = new ArrayList();
+		if (excludePOMDependencies) {
+			i = project.getDependencies().iterator();
+			while (i.hasNext())
+				excludeList.add(((Dependency) i.next()).getArtifactId());
+		}
+
+		i = bundleEntries.iterator();
+		while (i.hasNext()) {
+			String artifactId = (String) i.next();
+			if (!excludeList.contains(artifactId)) {
+				project.getDependencies().add(createDependency(artifactId));
+			}
+		}
+	}
+
+	private void addRequiredBundles(Manifest manifest,
+			boolean exportedEntriesOnly) {
+		String requiredBundles = getRequiredBundles(manifest);
+		if (requiredBundles != null) {
+			StringTokenizer st = new StringTokenizer(requiredBundles);
+			while (st.hasMoreTokens()) {
+				String nextToken = st.nextToken(",");
+				String bundleId = getBundleId(nextToken);
+				if (exportedEntriesOnly) {
+					if (export(nextToken)
+							&& !exportedEntries.contains(bundleId)) {
+						getLog().info("Adding exported bundle entry: "
+								+ bundleId);
+						exportedEntries.add(bundleId);
+					}
+				} else if (!bundleEntries.contains(bundleId)) {
+					getLog().info("Adding required bundle entry: " + bundleId);
+					bundleEntries.add(bundleId);
+				}
+			}
+		}
+	}
+
+	private String getRequiredBundles(Manifest manifest) {
+		return manifest.getMainAttributes().getValue("Require-Bundle");
+	}
+
+	private Manifest getManifestFromFile(File file) {
+		Manifest manifest = new Manifest();
 		try {
 			FileInputStream fis = new FileInputStream(manifestFile);
-			Manifest manifest = new Manifest();
 			manifest.read(fis);
 			fis.close();
-			String bundles = manifest.getMainAttributes().getValue("Require-Bundle");
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+		return manifest;
+	}
 
-			StringTokenizer st = new StringTokenizer(bundles);
-			List bundleEntries = new ArrayList();
-			while (st.hasMoreTokens()) {
-				String bundle = st.nextToken(",");
-				int extraInfoIndex = bundle.indexOf(";");
-				if(extraInfoIndex != -1)
-					bundle = bundle.substring(0, extraInfoIndex);
-				bundleEntries.add(bundle);
-			}
+	private String getBundleId(String element) {
+		String[] entry = element.split(";");
+		return entry[0].trim();
+	}
 
-			List excludeList = new ArrayList();
-			if (excludePOMDependencies) {
-				Iterator i = project.getDependencies().iterator();
-				while (i.hasNext())
-					excludeList.add(((Dependency) i.next()).getArtifactId());
-			}
+	private boolean export(String element) {
+		String[] entry = element.split(";");
+		return entry.length > 1
+				&& entry[1].trim().equals(MANIFEST_REXPORT_DEPENDENCY);
+	}
 
-			Iterator i = bundleEntries.iterator();
-			while (i.hasNext()) {
-				String artifactId = (String) i.next();
-				if (!excludeList.contains(artifactId)) {
-					Dependency dependency = createDependency(artifactId);
-					project.getDependencies().add(dependency);
+	private void addExportedBundles(String bundleId) {
+		File bundle = findBundleForDependency(bundleId);
+		Manifest manifest = null;
+		try {
+			if (bundle != null) {
+				if (bundle.isFile()) {
+					manifest = new JarFile(bundle).getManifest();
+				} else {
+					File manifestFile = new File(bundle + File.separator
+							+ MANIFEST_PATH);
+					manifest = getManifestFromFile(manifestFile);
 				}
+			} else {
+				// check exclude list
 			}
-		} catch (Exception e) {
-			throw new MojoFailureException(e.getMessage());
+			if (manifest != null) {
+				addRequiredBundles(manifest, true);
+			}
+		} catch (IOException e) {
+			e.printStackTrace();
 		}
 	}
 
@@ -102,4 +181,14 @@
 		return dependency;
 	}
 
+	private File findBundleForDependency(String artifactId) {
+		File pluginsDir = new File(eclipseHome + File.separator + "plugins");
+		File[] members = pluginsDir.listFiles();
+		for (int i = 0; i < members.length; i++) {
+			String bundleName = InstallPluginDependenciesMojo.getBundleName(members[i]);
+			if (artifactId.equals(bundleName))
+				return members[i];
+		}
+		return null;
+	}
 }



Mime
View raw message