You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by te...@apache.org on 2006/10/26 19:00:55 UTC

svn commit: r468061 - in /incubator/harmony/enhanced/tools/trunk/manifest_checker: ./ .settings/ src/ src/org/ src/org/apache/ src/org/apache/harmony/ src/org/apache/harmony/tools/ src/org/apache/harmony/tools/manifestchecker/

Author: tellison
Date: Thu Oct 26 10:00:53 2006
New Revision: 468061

URL: http://svn.apache.org/viewvc?view=rev&rev=468061
Log:
Initial attempt at a project development tool to check manifests in Harmony modules.
Has a dependency on the Eclipse OSGi resolver to figure out problems.  Run Main.class
pointing at an HDK and it will report problems it finds.
Still work in progress.

Added:
    incubator/harmony/enhanced/tools/trunk/manifest_checker/   (with props)
    incubator/harmony/enhanced/tools/trunk/manifest_checker/.classpath   (with props)
    incubator/harmony/enhanced/tools/trunk/manifest_checker/.project   (with props)
    incubator/harmony/enhanced/tools/trunk/manifest_checker/.settings/
    incubator/harmony/enhanced/tools/trunk/manifest_checker/.settings/org.eclipse.jdt.core.prefs
    incubator/harmony/enhanced/tools/trunk/manifest_checker/.settings/org.eclipse.jdt.ui.prefs
    incubator/harmony/enhanced/tools/trunk/manifest_checker/src/
    incubator/harmony/enhanced/tools/trunk/manifest_checker/src/org/
    incubator/harmony/enhanced/tools/trunk/manifest_checker/src/org/apache/
    incubator/harmony/enhanced/tools/trunk/manifest_checker/src/org/apache/harmony/
    incubator/harmony/enhanced/tools/trunk/manifest_checker/src/org/apache/harmony/tools/
    incubator/harmony/enhanced/tools/trunk/manifest_checker/src/org/apache/harmony/tools/manifestchecker/
    incubator/harmony/enhanced/tools/trunk/manifest_checker/src/org/apache/harmony/tools/manifestchecker/Main.java   (with props)
    incubator/harmony/enhanced/tools/trunk/manifest_checker/src/org/apache/harmony/tools/manifestchecker/ManifestFinder.java   (with props)
    incubator/harmony/enhanced/tools/trunk/manifest_checker/src/org/apache/harmony/tools/manifestchecker/Resolver.java   (with props)
    incubator/harmony/enhanced/tools/trunk/manifest_checker/src/org/apache/harmony/tools/manifestchecker/SimpleManifest.java   (with props)

Propchange: incubator/harmony/enhanced/tools/trunk/manifest_checker/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Oct 26 10:00:53 2006
@@ -0,0 +1,2 @@
+bin
+org.eclipse.osgi_3.2.1.R32x_v20060919.jar

Added: incubator/harmony/enhanced/tools/trunk/manifest_checker/.classpath
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/tools/trunk/manifest_checker/.classpath?view=auto&rev=468061
==============================================================================
--- incubator/harmony/enhanced/tools/trunk/manifest_checker/.classpath (added)
+++ incubator/harmony/enhanced/tools/trunk/manifest_checker/.classpath Thu Oct 26 10:00:53 2006
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="lib" path="org.eclipse.osgi_3.2.1.R32x_v20060919.jar"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/Sun jdk1.5.0_06"/>
+	<classpathentry kind="output" path="bin"/>
+</classpath>

Propchange: incubator/harmony/enhanced/tools/trunk/manifest_checker/.classpath
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/tools/trunk/manifest_checker/.project
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/tools/trunk/manifest_checker/.project?view=auto&rev=468061
==============================================================================
--- incubator/harmony/enhanced/tools/trunk/manifest_checker/.project (added)
+++ incubator/harmony/enhanced/tools/trunk/manifest_checker/.project Thu Oct 26 10:00:53 2006
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>manifest_checker</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+	</natures>
+</projectDescription>

Propchange: incubator/harmony/enhanced/tools/trunk/manifest_checker/.project
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/tools/trunk/manifest_checker/.settings/org.eclipse.jdt.core.prefs
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/tools/trunk/manifest_checker/.settings/org.eclipse.jdt.core.prefs?view=auto&rev=468061
==============================================================================
--- incubator/harmony/enhanced/tools/trunk/manifest_checker/.settings/org.eclipse.jdt.core.prefs (added)
+++ incubator/harmony/enhanced/tools/trunk/manifest_checker/.settings/org.eclipse.jdt.core.prefs Thu Oct 26 10:00:53 2006
@@ -0,0 +1,12 @@
+#Thu Oct 26 16:59:04 BST 2006
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.5

Added: incubator/harmony/enhanced/tools/trunk/manifest_checker/.settings/org.eclipse.jdt.ui.prefs
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/tools/trunk/manifest_checker/.settings/org.eclipse.jdt.ui.prefs?view=auto&rev=468061
==============================================================================
--- incubator/harmony/enhanced/tools/trunk/manifest_checker/.settings/org.eclipse.jdt.ui.prefs (added)
+++ incubator/harmony/enhanced/tools/trunk/manifest_checker/.settings/org.eclipse.jdt.ui.prefs Thu Oct 26 10:00:53 2006
@@ -0,0 +1,3 @@
+#Thu Oct 26 16:59:04 BST 2006
+eclipse.preferences.version=1
+internal.default.compliance=default

Added: incubator/harmony/enhanced/tools/trunk/manifest_checker/src/org/apache/harmony/tools/manifestchecker/Main.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/tools/trunk/manifest_checker/src/org/apache/harmony/tools/manifestchecker/Main.java?view=auto&rev=468061
==============================================================================
--- incubator/harmony/enhanced/tools/trunk/manifest_checker/src/org/apache/harmony/tools/manifestchecker/Main.java (added)
+++ incubator/harmony/enhanced/tools/trunk/manifest_checker/src/org/apache/harmony/tools/manifestchecker/Main.java Thu Oct 26 10:00:53 2006
@@ -0,0 +1,76 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You 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.harmony.tools.manifestchecker;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.osgi.service.resolver.State;
+
+public class Main {
+
+	public static void main(String[] args) {
+		Main manifester = new Main();
+
+		if (args.length == 0) {
+			manifester.printUsage();
+			System.exit(-1);
+		}
+
+		File hdkPath = new File(args[0]);
+		if (!hdkPath.isDirectory()) {
+			System.err.println("Cannot find HDK rooted at " + hdkPath);
+			System.exit(-1);
+		}
+
+		System.out.println("Checking bundles in HDK rooted at " + hdkPath);
+
+		/* Collect up the manifests we wish to check */
+		ManifestFinder finder = new ManifestFinder();
+
+		// Bundles in the boot dir
+		File bootDir = new File(hdkPath, "jdk/jre/lib/boot");
+		Set<SimpleManifest> jarBundles = finder.gatherJarManifests(bootDir);
+		Set<SimpleManifest> expandedBundles = finder.gatherExpandedManifests(bootDir);
+
+		// Bundles in the test dir
+		File testDir = new File(hdkPath, "build/test");
+		Set<SimpleManifest> testBundles = finder.gatherJarManifests(testDir);
+
+		List<SimpleManifest> allManifests = new ArrayList<SimpleManifest>();
+		allManifests.addAll(jarBundles);
+		allManifests.addAll(expandedBundles);
+		allManifests.addAll(testBundles);
+		
+		Resolver resolver = new Resolver();
+		State state = resolver.resolve(allManifests);
+		resolver.reportResolutionProblems(state);
+		
+		if (resolver.hasUnresolvedBundles(state)) {
+			// Show callers that we were unhappy
+			System.exit(-2);
+		}
+	}
+
+	void printUsage() {
+		System.err.println("USAGE: ");
+		System.err.println("  java -jar manifestcheck.jar <hdk_dir>");
+	}
+}

Propchange: incubator/harmony/enhanced/tools/trunk/manifest_checker/src/org/apache/harmony/tools/manifestchecker/Main.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/tools/trunk/manifest_checker/src/org/apache/harmony/tools/manifestchecker/ManifestFinder.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/tools/trunk/manifest_checker/src/org/apache/harmony/tools/manifestchecker/ManifestFinder.java?view=auto&rev=468061
==============================================================================
--- incubator/harmony/enhanced/tools/trunk/manifest_checker/src/org/apache/harmony/tools/manifestchecker/ManifestFinder.java (added)
+++ incubator/harmony/enhanced/tools/trunk/manifest_checker/src/org/apache/harmony/tools/manifestchecker/ManifestFinder.java Thu Oct 26 10:00:53 2006
@@ -0,0 +1,88 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You 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.harmony.tools.manifestchecker;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.io.FilenameFilter;
+import java.io.IOException;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.jar.JarFile;
+import java.util.jar.Manifest;
+
+public class ManifestFinder {
+
+	public ManifestFinder() {
+		super();
+	}
+
+	Set<SimpleManifest> gatherJarManifests(File bundleDir) {
+		File[] jarFiles = bundleDir.listFiles(new FilenameFilter() {
+			public boolean accept(File dirName, String fileName) {
+				return fileName.endsWith(".jar");
+			}
+		});
+
+		Set<SimpleManifest> manifests = new HashSet<SimpleManifest>(
+				jarFiles.length);
+		for (File file : jarFiles) {
+			try {
+				JarFile jar = new JarFile(file);
+				Manifest manifest = jar.getManifest();
+				if (manifest == null) {
+					System.out.println("WARNING: No manifest found in " + file);
+				} else {
+					manifests.add(SimpleManifest.fromManifest(manifest));
+				}
+			} catch (IOException e) {
+				System.err.println("ERROR: Problem getting manifest from "
+						+ file + " : skipping...");
+			}
+		}
+		return manifests;
+	}
+
+	Set<SimpleManifest> gatherExpandedManifests(File bundleDir) {
+		File[] subdirs = bundleDir.listFiles(new FileFilter() {
+			public boolean accept(File pathname) {
+				return pathname.isDirectory();
+			}
+		});
+
+		Set<SimpleManifest> result = new HashSet<SimpleManifest>(subdirs.length);
+		for (int i = 0; i < subdirs.length; i++) {
+			File subdir = subdirs[i];
+			File manifest = new File(subdir, "META-INF" + File.separator
+					+ "MANIFEST.MF");
+			if (manifest.exists()) {
+				try {
+					result.add(SimpleManifest.fromFile(manifest));
+				} catch (IOException e) {
+					System.err.println("Problem getting manifest from "
+							+ manifest + " : skipping...");
+				}
+			} else {
+				System.out
+						.println("WARNING: No manifest found in expanded bundle "
+								+ subdir);
+			}
+		}
+		return result;
+	}
+}

Propchange: incubator/harmony/enhanced/tools/trunk/manifest_checker/src/org/apache/harmony/tools/manifestchecker/ManifestFinder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/tools/trunk/manifest_checker/src/org/apache/harmony/tools/manifestchecker/Resolver.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/tools/trunk/manifest_checker/src/org/apache/harmony/tools/manifestchecker/Resolver.java?view=auto&rev=468061
==============================================================================
--- incubator/harmony/enhanced/tools/trunk/manifest_checker/src/org/apache/harmony/tools/manifestchecker/Resolver.java (added)
+++ incubator/harmony/enhanced/tools/trunk/manifest_checker/src/org/apache/harmony/tools/manifestchecker/Resolver.java Thu Oct 26 10:00:53 2006
@@ -0,0 +1,115 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You 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.harmony.tools.manifestchecker;
+
+import java.util.Dictionary;
+import java.util.List;
+
+import org.eclipse.osgi.service.resolver.BundleDescription;
+import org.eclipse.osgi.service.resolver.State;
+import org.eclipse.osgi.service.resolver.StateObjectFactory;
+import org.eclipse.osgi.service.resolver.VersionConstraint;
+import org.osgi.framework.BundleException;
+
+public class Resolver {
+
+	StateObjectFactory factory;
+
+	Resolver() {
+		super();
+		factory = StateObjectFactory.defaultFactory;
+	}
+
+	State resolve(List<SimpleManifest> manifests) {
+
+		State state = factory.createState(true);
+
+		// Create bundle descriptions from our manifests
+		BundleDescription[] descriptions = new BundleDescription[manifests
+				.size()];
+		for (int i = 0; i < descriptions.length; i++) {
+			Dictionary<String, String> dict = manifests.get(i).toDictionary();
+			try {
+				descriptions[i] = factory.createBundleDescription(state, dict,
+						Integer.toString(i), i);
+			} catch (BundleException e) {
+				handleBundleException(e, manifests.get(i));
+				continue;
+			}
+			state.addBundle(descriptions[i]);
+		}
+
+		// This does the work...
+		state.resolve();
+
+		return state;
+	}
+
+	void reportResolutionProblems(State state) {
+		boolean resolutionErrors = hasUnresolvedBundles(state);
+
+		BundleDescription[] descriptions = state.getBundles();
+		VersionConstraint[] rootcauses = state.getStateHelper()
+				.getUnsatisfiedLeaves(descriptions);
+
+		// There may be warnings of unresolved constraints, show errors and
+		// warnings
+		if (resolutionErrors || rootcauses.length != 0) {
+			if (resolutionErrors) {
+				System.err.println("ERROR: There were resolution errors");
+			} else {
+				System.err.println("WARNING: There were resolution warnings");
+			}
+			System.err.println();
+
+			// Just being cute
+			System.err.print("The following ");
+			if (rootcauses.length == 1) {
+				System.err.println("root cause was identified");
+			} else {
+				System.err.println(rootcauses.length
+						+ " root causes were identified");
+			}
+
+			for (VersionConstraint constraint : rootcauses) {
+				System.err.print("Could not resolve following constraint in ");
+				System.err.println(constraint.getBundle().getName());
+				System.err.println("\t" + constraint);
+			}
+		} else {
+			System.out.println("There were no resolution problems.");
+		}
+	}
+
+	boolean hasUnresolvedBundles(State state) {
+		BundleDescription[] descriptions = state.getBundles();
+		for (int i = 0; i < descriptions.length; i++) {
+			if (!descriptions[i].isResolved()) {
+				return true;
+			}
+		}
+		return false;
+	}
+
+	private void handleBundleException(BundleException e,
+			SimpleManifest manifest) {
+		System.err.println("Problem found creating bundle description from "
+				+ manifest);
+		System.err.println("Error message was: " + e.getLocalizedMessage());
+	}
+}

Propchange: incubator/harmony/enhanced/tools/trunk/manifest_checker/src/org/apache/harmony/tools/manifestchecker/Resolver.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/tools/trunk/manifest_checker/src/org/apache/harmony/tools/manifestchecker/SimpleManifest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/tools/trunk/manifest_checker/src/org/apache/harmony/tools/manifestchecker/SimpleManifest.java?view=auto&rev=468061
==============================================================================
--- incubator/harmony/enhanced/tools/trunk/manifest_checker/src/org/apache/harmony/tools/manifestchecker/SimpleManifest.java (added)
+++ incubator/harmony/enhanced/tools/trunk/manifest_checker/src/org/apache/harmony/tools/manifestchecker/SimpleManifest.java Thu Oct 26 10:00:53 2006
@@ -0,0 +1,104 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You 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.harmony.tools.manifestchecker;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.Map.Entry;
+import java.util.jar.Attributes;
+import java.util.jar.Manifest;
+
+class SimpleManifest {
+
+	static SimpleManifest fromFile(File manifestFile) throws IOException {
+		FileInputStream fis = new FileInputStream(manifestFile);
+		Manifest manifest = new Manifest(fis);
+		return fromManifest(manifest);
+	}
+
+	static SimpleManifest fromManifest(Manifest manifest) {
+		return new SimpleManifest(manifest.getMainAttributes());
+	}
+
+	Attributes attributes;
+
+	SimpleManifest(Attributes attributes) {
+		super();
+		this.attributes = attributes;
+	}
+
+	String getBSN() {
+		String bsnValue = attributes.getValue("Bundle-SymbolicName");
+		return trimAttributes(bsnValue);
+	}
+
+	String[] getExportedPackages() {
+		String exportValue = attributes.getValue("Export-Package");
+		if (exportValue == null) {
+			return null;
+		}
+		String[] exportStrings = exportValue.split(",");
+		return trimAllAttributes(exportStrings);
+	}
+
+	String[] getImportedPackages() {
+		String importValue = attributes.getValue("Import-Package");
+		if (importValue == null) {
+			return null;
+		}
+		String[] importStrings = importValue.split(",");
+		return trimAllAttributes(importStrings);
+	}
+
+	public Dictionary<String, String> toDictionary() {
+		Dictionary<String, String> result = new Hashtable<String, String>(attributes.size());
+		Iterator<Entry<Object, Object>> entryItr = attributes.entrySet().iterator();
+		while (entryItr.hasNext()) {
+			Entry<Object, Object> entry = (Entry<Object, Object>) entryItr.next();
+			result.put((String) entry.getKey().toString(), (String) entry.getValue());
+		}
+		return result;
+	}
+
+	public String toString() {
+		return "Manifest for " + getBSN();
+	}
+
+	private String[] trimAllAttributes(String[] values) {
+		String[] trimmedImports = new String[values.length];
+		for (int i = 0; i < values.length; i++) {
+			trimmedImports[i] = trimAttributes(values[i]);
+		}
+		return trimmedImports;
+	}
+
+	private String trimAttributes(String value) {
+		if (value == null) {
+			return null;
+		}
+		int semi = value.indexOf(';');
+		if (semi == -1) {
+			return value;
+		}
+		return value.substring(0, semi);
+	}
+}

Propchange: incubator/harmony/enhanced/tools/trunk/manifest_checker/src/org/apache/harmony/tools/manifestchecker/SimpleManifest.java
------------------------------------------------------------------------------
    svn:eol-style = native