You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by wa...@apache.org on 2006/08/24 13:05:00 UTC
svn commit: r434371 [2/3] - in /incubator/felix/trunk: ./ tools/mangen/
tools/mangen/src/ tools/mangen/src/main/ tools/mangen/src/main/java/
tools/mangen/src/main/java/org/ tools/mangen/src/main/java/org/apache/
tools/mangen/src/main/java/org/apache/fe...
Added: incubator/felix/trunk/tools/mangen/src/main/java/org/apache/felix/tool/mangen/OsgiPackage.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/tools/mangen/src/main/java/org/apache/felix/tool/mangen/OsgiPackage.java?rev=434371&view=auto
==============================================================================
--- incubator/felix/trunk/tools/mangen/src/main/java/org/apache/felix/tool/mangen/OsgiPackage.java (added)
+++ incubator/felix/trunk/tools/mangen/src/main/java/org/apache/felix/tool/mangen/OsgiPackage.java Thu Aug 24 04:04:56 2006
@@ -0,0 +1,187 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * 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.felix.tool.mangen;
+
+import java.util.Comparator;
+import java.util.Set;
+import java.util.StringTokenizer;
+import java.util.TreeSet;
+
+import org.apache.felix.framework.searchpolicy.*;
+import org.osgi.framework.Version;
+
+/**
+ * The OsgiPackage class is a wrapper for either simple string based package
+ * names or full Osgi package objects containing attributes and versions etc.
+ *
+ * @version $Revision: 31 $
+ * @author <A HREF="mailto:robw@ascert.com">Rob Walker</A>
+ */
+public abstract class OsgiPackage
+ implements Comparable
+{
+ //////////////////////////////////////////////////
+ // STATIC VARIABLES
+ //////////////////////////////////////////////////
+
+ public static Comparator pkgComparator = new PackageComparator();
+
+ //////////////////////////////////////////////////
+ // STATIC PUBLIC METHODS
+ //////////////////////////////////////////////////
+
+ /**
+ * Create a package wrapper for a simple package name string.
+ */
+ public static OsgiPackage createStringPackage(String pkgName)
+ {
+ return new OsgiStringPackage(pkgName);
+ }
+
+ /**
+ * Create a set of OSGi package wrappers by parsing the supplied import
+ * or export headers. At present, we only create true R4 packages for header
+ * strings which contain ";" (the header attribute separator char). All
+ * others we create as simple string packages
+ */
+ public static Set createFromHeaders(String headers)
+ {
+ Set set = getNewSet();
+
+ if (headers != null)
+ {
+ for (StringTokenizer tok = new StringTokenizer(headers, ","); tok.hasMoreTokens(); )
+ {
+ String pkgString = tok.nextToken().trim();
+
+ // look for presence of package attribute separator ';'
+ if (pkgString.indexOf(';') != -1)
+ {
+ // parse and add all R4 packages contained (can be multiple)
+ R4Package[] pkgs = R4Package.parseImportOrExportHeader(pkgString);
+ for (int ix = 0; ix < pkgs.length; ix++)
+ {
+ set.add(new OsgiR4Package(pkgs[ix]));
+ }
+ }
+ else
+ {
+ // treat as a simple string package name
+ set.add(new OsgiStringPackage(pkgString));
+ }
+ }
+ }
+
+ return set;
+ }
+
+ /**
+ * Creates and returns a new Set for holding package entries.
+ */
+ public static Set getNewSet()
+ {
+ return new TreeSet(pkgComparator);
+ }
+
+ //////////////////////////////////////////////////
+ // INSTANCE VARIABLES
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // CONSTRUCTORS
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // ACCESSOR METHODS
+ //////////////////////////////////////////////////
+
+ /**
+ * Return simple package name form without attributes
+ */
+ public abstract String getName();
+
+ /**
+ * Return specified package version, or <code>null</code> if none defined.
+ */
+ public abstract Version getVersion();
+
+ //////////////////////////////////////////////////
+ // PUBLIC INSTANCE METHODS
+ //////////////////////////////////////////////////
+
+ /**
+ * Very important to override standard equals method, since set based operations
+ * work using this method for comparisons
+ */
+ public boolean equals(Object o)
+ {
+ return compareTo(o) == 0 ? true : false;
+ }
+
+ //////////////////////////////////////////////////
+ // INTERFACE METHODS - Comparable
+ //////////////////////////////////////////////////
+
+ /**
+ * Just used for sorting in reports
+ */
+ public int compareTo(Object o)
+ {
+ return -1;
+ }
+
+ //////////////////////////////////////////////////
+ // PROTECTED INSTANCE METHODS
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // PRIVATE INSTANCE METHODS
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // STATIC INNER CLASSES
+ //////////////////////////////////////////////////
+
+ public static class PackageComparator
+ implements Comparator
+ {
+ public int compare(Object o1, Object o2)
+ {
+ int retval = -1;
+
+ if (o1 instanceof OsgiPackage)
+ {
+ retval = ((Comparable) o1).compareTo(o2);
+ }
+ else if (o2 instanceof OsgiPackage)
+ {
+ retval = ((Comparable) o2).compareTo(o1);
+ }
+ else
+ {
+ throw new ClassCastException("can't compare, neither o1 or o2 is an OsgiPackage");
+ }
+
+ return retval;
+ }
+ }
+
+ //////////////////////////////////////////////////
+ // NON-STATIC INNER CLASSES
+ //////////////////////////////////////////////////
+
+}
Added: incubator/felix/trunk/tools/mangen/src/main/java/org/apache/felix/tool/mangen/OsgiR4Package.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/tools/mangen/src/main/java/org/apache/felix/tool/mangen/OsgiR4Package.java?rev=434371&view=auto
==============================================================================
--- incubator/felix/trunk/tools/mangen/src/main/java/org/apache/felix/tool/mangen/OsgiR4Package.java (added)
+++ incubator/felix/trunk/tools/mangen/src/main/java/org/apache/felix/tool/mangen/OsgiR4Package.java Thu Aug 24 04:04:56 2006
@@ -0,0 +1,267 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * 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.felix.tool.mangen;
+
+import java.util.Iterator;
+import java.util.Properties;
+
+import org.apache.felix.framework.searchpolicy.*;
+import org.osgi.framework.Constants;
+import org.osgi.framework.Version;
+
+//TODO: need to look at VersionRange handling to see whether version checking
+// should be modified to cater for version ranges.
+/**
+ * Wrapper for a full R4 package name
+ *
+ * @version $Revision: 31 $
+ * @author <A HREF="mailto:robw@ascert.com">Rob Walker</A>
+ */
+public class OsgiR4Package
+ extends OsgiPackage
+{
+ //////////////////////////////////////////////////
+ // STATIC VARIABLES
+ //////////////////////////////////////////////////
+
+ public static String verString;
+
+ //////////////////////////////////////////////////
+ // STATIC PUBLIC METHODS
+ //////////////////////////////////////////////////
+
+ /**
+ * Compare two sets of packages versions.
+ */
+ public static int compareVersions(Version v1, Version v2)
+ {
+ int retval = -1;
+
+ if (v1 != null)
+ {
+ v1.compareTo(v2);
+ }
+ else if (v2 != null)
+ {
+ v2.compareTo(v1);
+ }
+ else
+ {
+ retval = 0;
+ }
+
+ return retval;
+ }
+
+ //////////////////////////////////////////////////
+ // INSTANCE VARIABLES
+ //////////////////////////////////////////////////
+
+ public R4Package pkg;
+
+ //////////////////////////////////////////////////
+ // CONSTRUCTORS
+ //////////////////////////////////////////////////
+
+ public OsgiR4Package(R4Package pkg)
+ {
+ this.pkg = pkg;
+
+ if (verString == null)
+ {
+ String val = PropertyManager.getProperty("mangen.osgi.level", "3");
+ if (val.equals("4"))
+ {
+ verString = Constants.VERSION_ATTRIBUTE;
+ }
+ else
+ {
+ verString = Constants.PACKAGE_SPECIFICATION_VERSION;
+ }
+ }
+ }
+
+ //////////////////////////////////////////////////
+ // ACCESSOR METHODS
+ //////////////////////////////////////////////////
+
+ /**
+ * Return the wrapped Oscar R4 package.
+ */
+ public R4Package getPackage()
+ {
+ return pkg;
+ }
+
+
+ public String getName()
+ {
+ return pkg.getName();
+ }
+
+
+ public Version getVersion()
+ {
+ Version ver = null;
+
+ // use 'version' attribute if present, fallback to getVersion if not
+ R4Attribute verAttr = getAttribute(verString);
+
+ if (verAttr != null)
+ {
+ String sVer = verAttr.getValue().toString();
+ ver = new Version(sVer);
+ }
+ else
+ {
+ Version v = pkg.getVersion();
+ if (!v.equals(Version.emptyVersion))
+ {
+ ver = v;
+ }
+ }
+
+ return ver;
+ }
+
+
+ //////////////////////////////////////////////////
+ // PUBLIC INSTANCE METHODS
+ //////////////////////////////////////////////////
+
+ /**
+ * Important to override standard toString method for pattern matching and
+ * manifest header value generation.
+ */
+ public String toString()
+ {
+ StringBuffer str = new StringBuffer(pkg.getName());
+
+ // bit over the top this - but ensures we preserve a version attribute
+ // specified as 1.2 rather than converting it to 1.2.0
+ R4Attribute verAttr = getAttribute(verString);
+ String sVer = null;
+
+ if (verAttr != null)
+ {
+ sVer = verAttr.getValue().toString();
+ }
+ else
+ {
+ Version v = getVersion();
+ if (v != null)
+ {
+ sVer = v.toString();
+ }
+ }
+
+ if (sVer != null)
+ {
+ str.append(";" + verString + "=");
+ str.append("\"" + sVer + "\"");
+ }
+
+ return str.toString();
+ }
+
+ //////////////////////////////////////////////////
+ // INTERFACE METHODS - Comparable
+ //////////////////////////////////////////////////
+
+ /**
+ * The Comparable interface is used as the basis for the OsgiPackage default
+ * implementation of equals() and also for the Comparator interface used to
+ * determine whether set members are present.
+ */
+ public int compareTo(Object o)
+ {
+ int retval = -1;
+
+ if (o instanceof OsgiR4Package)
+ {
+ OsgiR4Package otherPkg = (OsgiR4Package) o;
+ // first check for name match
+ retval = getName().compareTo(otherPkg.getName());
+
+ // check low versions match
+ if (retval == 0)
+ {
+ retval = compareVersions(getVersion(),
+ otherPkg.getVersion());
+ }
+ //TODO: Original Oscar2 mangen handled version ranges, may need to
+ // revisit this
+ // check high versions match
+ //if (retval == 0)
+ //{
+ // retval = compareVersions(pkg.getVersionHigh(),
+ // otherPkg.getVersionHigh());
+ //}
+ }
+ else if (o instanceof OsgiStringPackage || o instanceof String)
+ {
+ // simple package name comparison
+ retval = getName().compareTo(o.toString());
+ }
+ else
+ {
+ // prob won't do any better a job than we do, but fallback just in case
+ retval = super.compareTo(o);
+ }
+
+ return retval;
+ }
+
+ //////////////////////////////////////////////////
+ // PROTECTED INSTANCE METHODS
+ //////////////////////////////////////////////////
+
+ /**
+ * Get a specific attribute of the package.
+ */
+ public R4Attribute getAttribute(String name)
+ {
+ R4Attribute attrib = null;
+ R4Attribute[] attrs = pkg.getAttributes();
+
+ if (attrs != null)
+ {
+ for (int i = 0; (attrib == null) && (i < attrs.length); i++)
+ {
+ if (attrs[i].getName().equals(name))
+ {
+ attrib = attrs[i];
+ }
+ }
+ }
+
+ return attrib;
+ }
+
+ //////////////////////////////////////////////////
+ // PRIVATE INSTANCE METHODS
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // STATIC INNER CLASSES
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // NON-STATIC INNER CLASSES
+ //////////////////////////////////////////////////
+
+}
Added: incubator/felix/trunk/tools/mangen/src/main/java/org/apache/felix/tool/mangen/OsgiStringPackage.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/tools/mangen/src/main/java/org/apache/felix/tool/mangen/OsgiStringPackage.java?rev=434371&view=auto
==============================================================================
--- incubator/felix/trunk/tools/mangen/src/main/java/org/apache/felix/tool/mangen/OsgiStringPackage.java (added)
+++ incubator/felix/trunk/tools/mangen/src/main/java/org/apache/felix/tool/mangen/OsgiStringPackage.java Thu Aug 24 04:04:56 2006
@@ -0,0 +1,144 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * 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.felix.tool.mangen;
+
+import java.util.Iterator;
+import java.util.Properties;
+
+import org.apache.felix.framework.searchpolicy.*;
+import org.osgi.framework.Version;
+
+/**
+ * Wrapper for a simple string based package name.
+ *
+ * @version $Revision: 31 $
+ * @author <A HREF="mailto:robw@ascert.com">Rob Walker</A>
+ */
+public class OsgiStringPackage
+ extends OsgiPackage
+{
+ //////////////////////////////////////////////////
+ // STATIC VARIABLES
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // STATIC PUBLIC METHODS
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // INSTANCE VARIABLES
+ //////////////////////////////////////////////////
+
+ public String pkgname;
+
+ //////////////////////////////////////////////////
+ // CONSTRUCTORS
+ //////////////////////////////////////////////////
+
+ public OsgiStringPackage(String pkgname)
+ {
+ this.pkgname = pkgname;
+ }
+
+ //////////////////////////////////////////////////
+ // ACCESSOR METHODS
+ //////////////////////////////////////////////////
+
+ public String getName()
+ {
+ return pkgname;
+ }
+
+ public Version getVersion()
+ {
+ return null;
+ }
+
+
+
+ //////////////////////////////////////////////////
+ // PUBLIC INSTANCE METHODS
+ //////////////////////////////////////////////////
+
+ /**
+ * Important to override standard toString method for pattern matching and
+ * manifest header value generation.
+ */
+ public String toString()
+ {
+ return pkgname;
+ }
+
+ /**
+ * Important to override for hash table/set key lookups. Basically just need
+ * to return hashcode of our underlying object.
+ */
+ public int hashCode()
+ {
+ return pkgname.hashCode();
+ }
+
+ //////////////////////////////////////////////////
+ // INTERFACE METHODS - Comparable
+ //////////////////////////////////////////////////
+
+ /**
+ * The Comparable interface is used as the basis for the OsgiPackage default
+ * implementation of equals() and also for the Comparator interface used to
+ * determine whether set members are present.
+ */
+ public int compareTo(Object o)
+ {
+ int retval = -1;
+
+ if (o instanceof OsgiR4Package)
+ {
+ // R4 package comparison is complicated, so invert the compare and
+ // let the R4 package do the work
+ retval = ((OsgiR4Package) o).compareTo(this);
+ }
+ else if (o instanceof OsgiStringPackage || o instanceof String)
+ {
+ // simple string compare will suffice
+ retval = pkgname.compareTo(o.toString());
+ }
+ else
+ {
+ // prob won't do any better a job than we do, but fallback just in case
+ retval = super.compareTo(o);
+ }
+
+ return retval;
+ }
+
+ //////////////////////////////////////////////////
+ // PROTECTED INSTANCE METHODS
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // PRIVATE INSTANCE METHODS
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // STATIC INNER CLASSES
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // NON-STATIC INNER CLASSES
+ //////////////////////////////////////////////////
+
+}
Added: incubator/felix/trunk/tools/mangen/src/main/java/org/apache/felix/tool/mangen/PropertyManager.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/tools/mangen/src/main/java/org/apache/felix/tool/mangen/PropertyManager.java?rev=434371&view=auto
==============================================================================
--- incubator/felix/trunk/tools/mangen/src/main/java/org/apache/felix/tool/mangen/PropertyManager.java (added)
+++ incubator/felix/trunk/tools/mangen/src/main/java/org/apache/felix/tool/mangen/PropertyManager.java Thu Aug 24 04:04:56 2006
@@ -0,0 +1,243 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * 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.felix.tool.mangen;
+
+import java.io.File;
+import java.io.FileInputStream;
+
+import java.util.Properties;
+
+/**
+ *
+ * @version $Revision: 14 $
+ * @author <A HREF="mailto:robw@ascert.com">Rob Walker</A>
+ */
+public class PropertyManager
+{
+ //////////////////////////////////////////////////
+ // STATIC VARIABLES
+ //////////////////////////////////////////////////
+
+ private static final String DELIM_START = "${";
+ private static final char DELIM_STOP = '}';
+ private static final int DELIM_START_LEN = 2;
+ private static final int DELIM_STOP_LEN = 1;
+
+ public static Properties props = new Properties();
+
+ //////////////////////////////////////////////////
+ // STATIC PUBLIC METHODS
+ //////////////////////////////////////////////////
+
+ /**
+ * Initialise the properties either from a file specified by -Dmangen.properties
+ * or if this is not specified, from the default lib\mangen.properties file.
+ */
+ public static void initProperties(String propFileKey)
+ throws Exception
+ {
+ String propsFile = System.getProperty(propFileKey);
+
+ if (propsFile != null)
+ {
+ props.load(new FileInputStream(propsFile));
+ }
+ else
+ {
+ getDefaultProperties(propFileKey);
+ }
+
+ if (props.size() == 0)
+ {
+ System.err.println("Warning: no mangen properties specified.");
+ }
+ }
+
+ /**
+ * Get the default mangen properties from lib\mangen.properties
+ */
+ public static void getDefaultProperties(String propFileKey)
+ {
+ // Determine where mangen.jar is located by looking at the system class path.
+ String jarLoc = null;
+ String classpath = System.getProperty("java.class.path");
+ int index = classpath.toLowerCase().indexOf("mangen.jar");
+ int start = classpath.lastIndexOf(File.pathSeparator, index) + 1;
+ if (index > start)
+ {
+ jarLoc = classpath.substring(start, index);
+ if (jarLoc.length() == 0)
+ {
+ jarLoc = ".";
+ }
+ }
+
+ // see if we can load from a default mangen.properties file
+ try
+ {
+ props.load(new FileInputStream(jarLoc + propFileKey));
+ }
+ catch (Exception e)
+ {
+ // ok to ignore, we'll report error in caller
+ }
+ }
+
+ /**
+ * Provides a wrapper into either System properties, if the specified
+ * property is present there, or our mangen.properties if not. As with the
+ * standartd getProperty call the default value is returned if the key is not
+ * present in either of these property sets. Variable substitution using
+ * ${var} style markers is also supported.
+ */
+ public static String getProperty(String key, String def)
+ {
+ String retval = null;
+
+ retval = System.getProperty(key);
+ if (retval == null)
+ {
+ retval = props.getProperty(key, def);
+ }
+
+ if (retval != null)
+ {
+ retval = substVars(retval, key);
+ }
+
+ return retval;
+ }
+
+ /**
+ * No default wrapper for getProperty.
+ */
+ public static String getProperty(String key)
+ {
+ return getProperty(key, null);
+ }
+
+
+ /**
+ * <p>
+ * This method performs property variable substitution on the
+ * specified string value. If the specified string contains the
+ * syntax <code>${<system-prop-name>}</code>, then the corresponding
+ * system property value is substituted for the marker.
+ * </p>
+ * @param val The string on which to perform system property substitution.
+ * @param currentKey The current key name, used to detect recursion
+ * @return The value of the specified string after system property substitution.
+ * @throws IllegalArgumentException If there was a syntax error in the
+ * system property variable marker syntax or recursion will occur.
+ **/
+ public static String substVars(String val, String currentKey)
+ throws IllegalArgumentException
+ {
+ StringBuffer sbuf = new StringBuffer();
+
+ if (val == null)
+ {
+ return val;
+ }
+
+ int i = 0;
+ int j, k;
+
+ while (true)
+ {
+ j = val.indexOf(DELIM_START, i);
+ if (j == -1)
+ {
+ if (i == 0)
+ {
+ return val;
+ }
+ else
+ {
+ sbuf.append(val.substring(i, val.length()));
+ return sbuf.toString();
+ }
+ }
+ else
+ {
+ sbuf.append(val.substring(i, j));
+ k = val.indexOf(DELIM_STOP, j);
+ if (k == -1)
+ {
+ throw new IllegalArgumentException(
+ '"' + val +
+ "\" has no closing brace. Opening brace at position "
+ + j + '.');
+ }
+ else
+ {
+ j += DELIM_START_LEN;
+ String key = val.substring(j, k);
+
+ if (key.equals(currentKey))
+ {
+ throw new IllegalArgumentException("recursive property substitution in: " + currentKey);
+ }
+ // Try system properties.
+ String replacement = getProperty(key, null);
+ if (replacement != null)
+ {
+ sbuf.append(replacement);
+ }
+ i = k + DELIM_STOP_LEN;
+ }
+ }
+ }
+ }
+
+ //////////////////////////////////////////////////
+ // INSTANCE VARIABLES
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // CONSTRUCTORS
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // ACCESSOR METHODS
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // PUBLIC INSTANCE METHODS
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // INTERFACE METHODS
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // PROTECTED INSTANCE METHODS
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // PRIVATE INSTANCE METHODS
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // STATIC INNER CLASSES
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // NON-STATIC INNER CLASSES
+ //////////////////////////////////////////////////
+
+}
Added: incubator/felix/trunk/tools/mangen/src/main/java/org/apache/felix/tool/mangen/Report.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/tools/mangen/src/main/java/org/apache/felix/tool/mangen/Report.java?rev=434371&view=auto
==============================================================================
--- incubator/felix/trunk/tools/mangen/src/main/java/org/apache/felix/tool/mangen/Report.java (added)
+++ incubator/felix/trunk/tools/mangen/src/main/java/org/apache/felix/tool/mangen/Report.java Thu Aug 24 04:04:56 2006
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * 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.felix.tool.mangen;
+
+import java.io.IOException;
+import java.io.PrintStream;
+
+import java.util.List;
+
+/**
+ *
+ * @version $Revision: 29 $
+ * @author <A HREF="mailto:robw@ascert.com">Rob Walker</A>
+ */
+public interface Report
+ extends GenericHandlerItem
+{
+ //////////////////////////////////////////////////
+ // STATIC VARIABLES
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // SIGNATURES
+ //////////////////////////////////////////////////
+
+ /**
+ * Run Report for the specified list of BundleJars, generating output to
+ * specified PrintStream.
+ */
+ public void run(PrintStream rpt, List jarList)
+ throws IOException;
+}
Added: incubator/felix/trunk/tools/mangen/src/main/java/org/apache/felix/tool/mangen/ReportHandler.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/tools/mangen/src/main/java/org/apache/felix/tool/mangen/ReportHandler.java?rev=434371&view=auto
==============================================================================
--- incubator/felix/trunk/tools/mangen/src/main/java/org/apache/felix/tool/mangen/ReportHandler.java (added)
+++ incubator/felix/trunk/tools/mangen/src/main/java/org/apache/felix/tool/mangen/ReportHandler.java Thu Aug 24 04:04:56 2006
@@ -0,0 +1,108 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * 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.felix.tool.mangen;
+
+import java.io.IOException;
+import java.io.PrintStream;
+
+import java.util.List;
+import java.util.Iterator;
+import java.util.Properties;
+
+/**
+ *
+ * @version $Revision: 29 $
+ * @author <A HREF="mailto:robw@ascert.com">Rob Walker</A>
+ */
+public class ReportHandler
+ extends GenericHandler
+{
+ //////////////////////////////////////////////////
+ // STATIC VARIABLES
+ //////////////////////////////////////////////////
+
+ /** Classname prefix for basic report classes. */
+ public static final String REPORT_PACKAGE = "org.apache.felix.tool.mangen.report";
+ /** Report property prefix. **/
+ public static final String REPORT_KEY = "mangen-report-";
+
+ //////////////////////////////////////////////////
+ // STATIC PUBLIC METHODS
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // INSTANCE VARIABLES
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // CONSTRUCTORS
+ //////////////////////////////////////////////////
+
+ /**
+ * Initialise the set of reports based on the REPORT_KEY.<n> properties defined.
+ * Each reports is either a full classname implementing the Report interface, or a
+ * classname in REPORT_PACKAGE. The actual work to process the properties and
+ * create the report objects is done by our parent class, GenericHandler.
+ */
+ public ReportHandler()
+ {
+ super(REPORT_KEY, Report.class, REPORT_PACKAGE);
+ }
+
+
+ //////////////////////////////////////////////////
+ // ACCESSOR METHODS
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // PUBLIC INSTANCE METHODS
+ //////////////////////////////////////////////////
+
+ /**
+ * Retrieve each defined report and run it.
+ */
+ public void runReports(PrintStream rpt, List jarList)
+ throws IOException
+ {
+ for(Iterator i = handlerList.iterator(); i.hasNext(); )
+ {
+ Report report = (Report) i.next();
+ report.run(rpt, jarList);
+ }
+ }
+
+ //////////////////////////////////////////////////
+ // INTERFACE METHODS
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // PROTECTED INSTANCE METHODS
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // PRIVATE INSTANCE METHODS
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // STATIC INNER CLASSES
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // NON-STATIC INNER CLASSES
+ //////////////////////////////////////////////////
+
+}
Added: incubator/felix/trunk/tools/mangen/src/main/java/org/apache/felix/tool/mangen/Rule.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/tools/mangen/src/main/java/org/apache/felix/tool/mangen/Rule.java?rev=434371&view=auto
==============================================================================
--- incubator/felix/trunk/tools/mangen/src/main/java/org/apache/felix/tool/mangen/Rule.java (added)
+++ incubator/felix/trunk/tools/mangen/src/main/java/org/apache/felix/tool/mangen/Rule.java Thu Aug 24 04:04:56 2006
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * 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.felix.tool.mangen;
+
+import java.io.IOException;
+import java.io.PrintStream;
+
+import java.util.List;
+
+/**
+ *
+ * @version $Revision: 29 $
+ * @author <A HREF="mailto:robw@ascert.com">Rob Walker</A>
+ */
+public interface Rule
+ extends GenericHandlerItem
+{
+ //////////////////////////////////////////////////
+ // STATIC VARIABLES
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // SIGNATURES
+ //////////////////////////////////////////////////
+
+ /**
+ * Execute the Rule on the supplied list of BundleJars.
+ */
+ public void execute(List jarList);
+
+ /**
+ * Send any output for the Rule to the specified PrintStream.
+ */
+ public void report(PrintStream rpt)
+ throws IOException;
+
+ /**
+ * Should return true if Rule can be used globally (i.e. in mangen.properties).
+ */
+ public boolean isUsableGlobally();
+
+ /**
+ * Should return true if Rule can be used locally (i.e. in a bundle's manifest).
+ */
+ public boolean isUsableLocally();
+
+}
Added: incubator/felix/trunk/tools/mangen/src/main/java/org/apache/felix/tool/mangen/RuleHandler.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/tools/mangen/src/main/java/org/apache/felix/tool/mangen/RuleHandler.java?rev=434371&view=auto
==============================================================================
--- incubator/felix/trunk/tools/mangen/src/main/java/org/apache/felix/tool/mangen/RuleHandler.java (added)
+++ incubator/felix/trunk/tools/mangen/src/main/java/org/apache/felix/tool/mangen/RuleHandler.java Thu Aug 24 04:04:56 2006
@@ -0,0 +1,220 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * 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.felix.tool.mangen;
+
+import java.io.IOException;
+import java.io.PrintStream;
+
+import java.util.List;
+import java.util.Iterator;
+import java.util.Properties;
+import java.util.StringTokenizer;
+
+import java.util.jar.Attributes;
+
+/**
+ *
+ * @version $Revision: 31 $
+ * @author <A HREF="mailto:robw@ascert.com">Rob Walker</A>
+ */
+public class RuleHandler
+ extends GenericHandler
+{
+ //////////////////////////////////////////////////
+ // STATIC VARIABLES
+ //////////////////////////////////////////////////
+
+ /** Classname prefix for basic rule classes */
+ public static final String RULE_PACKAGE = "org.apache.felix.tool.mangen.rule";
+ /** Rule set property **/
+ public static final String RULESET_KEY = "mangen.rulesets";
+ /** Default rule property prefix **/
+ public static final String RULE_KEY = "mangen-rule-";
+
+ //////////////////////////////////////////////////
+ // STATIC PUBLIC METHODS
+ //////////////////////////////////////////////////
+
+ /**
+ * Initialise a set of rules to be run, based on the value of the
+ * mangen.rule property if present, or the default rule key if not.
+ */
+ public static RuleHandler[] initRuleSets()
+ {
+ String rulesetStr = PropertyManager.getProperty(RULESET_KEY, RULE_KEY);
+
+ StringTokenizer tok = new StringTokenizer(rulesetStr, ",");
+ RuleHandler[] handlers = new RuleHandler[tok.countTokens()];
+ for (int ix = 0; ix < handlers.length; ix++)
+ {
+ handlers[ix] = new RuleHandler(tok.nextToken().trim());
+ }
+
+ return handlers;
+ }
+
+ /**
+ * Run each specified ruleset.
+ */
+ public static void runRuleSets(RuleHandler[] handlers, List jarList)
+ {
+ for (int ix = 0; ix < handlers.length; ix++)
+ {
+ handlers[ix].executeRules(jarList);
+ }
+ }
+
+ /**
+ *
+ * Run reports for each specified ruleset.
+ */
+ public static void runRuleSetReports(RuleHandler[] handlers, PrintStream rpt, boolean header)
+ throws IOException
+ {
+ for (int ix = 0; ix < handlers.length; ix++)
+ {
+ handlers[ix].runReports(rpt, header);
+ }
+ }
+
+ //////////////////////////////////////////////////
+ // INSTANCE VARIABLES
+ //////////////////////////////////////////////////
+
+ public boolean isGlobalRule;
+
+ //////////////////////////////////////////////////
+ // CONSTRUCTORS
+ //////////////////////////////////////////////////
+
+ /**
+ * Initialise a rule handler usng the default RULE_KEY.
+ */
+ public RuleHandler()
+ {
+ this(RULE_KEY);
+ }
+
+ /**
+ * Initialise the set of rules based on the RULE_KEY.<n> properties defined.
+ * Each rule is either a full classname implementing the Rule interface, or a
+ * classname in RULE_PACKAGE. The actual work to process the properties and
+ * create the rule objects is done by our parent class, GenericHandler.
+ */
+ public RuleHandler(String key)
+ {
+ super(key, Rule.class, RULE_PACKAGE);
+ // for now, safe to assume Property set based rules are global
+ this.isGlobalRule = true;
+ }
+
+ /**
+ * Initialise a rule handler based on a set of Manifest attributes.
+ */
+ public RuleHandler(Attributes atts)
+ {
+ super(atts, RULE_KEY, Rule.class, RULE_PACKAGE);
+ // for now, safe to assume Attribute set based rules are local
+ this.isGlobalRule = false;
+ }
+
+ //////////////////////////////////////////////////
+ // ACCESSOR METHODS
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // PUBLIC INSTANCE METHODS
+ //////////////////////////////////////////////////
+
+ /**
+ * Retrieve each defined rule and apply it. At present we take the approach that
+ * each rule will be applied in it's entirety before proceeding to the next rule.
+ * For simple rules, this will result in multiple passes over
+ * the jarList set for simowhich obviously incurs a processing overhead, but it is felt
+ * that this simpler approach will have fewer nasty side-effects for more complex
+ * rules that span multiple bundle jars.
+ */
+ public void executeRules(List jarList)
+ {
+ for(Iterator i = handlerList.iterator(); i.hasNext(); )
+ {
+ Rule rule = (Rule) i.next();
+
+ if (isGlobalRule && !rule.isUsableGlobally())
+ {
+ throw new IllegalArgumentException("rule cannot be used globally: "
+ + rule.getClass().getName());
+ }
+
+ if (!isGlobalRule && !rule.isUsableLocally())
+ {
+ throw new IllegalArgumentException("rule cannot be used locally: "
+ + rule.getClass().getName());
+ }
+
+ rule.execute(jarList);
+ }
+ }
+
+ /**
+ * Run report for each rule. Bit of a hack for now!
+ */
+ public void runReports(PrintStream rpt, boolean header)
+ throws IOException
+ {
+ for(Iterator i = handlerList.iterator(); i.hasNext(); )
+ {
+ Rule rule = (Rule) i.next();
+
+ if (header)
+ {
+ rpt.println("");
+ rpt.println("============================================================");
+ rpt.println("Rule: " + rule.getClass().getName());
+ rpt.println("============================================================");
+ rpt.println("");
+ }
+ else
+ {
+ rpt.println("Rule: " + rule.getClass().getName());
+ }
+
+ rule.report(rpt);
+ }
+ }
+
+ //////////////////////////////////////////////////
+ // INTERFACE METHODS
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // PROTECTED INSTANCE METHODS
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // PRIVATE INSTANCE METHODS
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // STATIC INNER CLASSES
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // NON-STATIC INNER CLASSES
+ //////////////////////////////////////////////////
+
+}
Added: incubator/felix/trunk/tools/mangen/src/main/java/org/apache/felix/tool/mangen/report/BundleReport.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/tools/mangen/src/main/java/org/apache/felix/tool/mangen/report/BundleReport.java?rev=434371&view=auto
==============================================================================
--- incubator/felix/trunk/tools/mangen/src/main/java/org/apache/felix/tool/mangen/report/BundleReport.java (added)
+++ incubator/felix/trunk/tools/mangen/src/main/java/org/apache/felix/tool/mangen/report/BundleReport.java Thu Aug 24 04:04:56 2006
@@ -0,0 +1,206 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * 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.felix.tool.mangen.report;
+
+import java.io.IOException;
+import java.io.PrintStream;
+
+import java.util.List;
+import java.util.Iterator;
+import java.util.Set;
+import java.util.StringTokenizer;
+
+import java.util.regex.Pattern;
+
+import org.apache.felix.tool.mangen.BundleJar;
+import org.apache.felix.tool.mangen.OsgiPackage;
+import org.apache.felix.tool.mangen.Report;
+
+/**
+ *
+ * @version $Revision: 29 $
+ * @author <A HREF="mailto:robw@ascert.com">Rob Walker</A>
+ */
+public class BundleReport
+ implements Report
+{
+ //////////////////////////////////////////////////
+ // STATIC VARIABLES
+ //////////////////////////////////////////////////
+
+ public static Pattern[] pkgPatterns;
+
+ //////////////////////////////////////////////////
+ // STATIC PUBLIC METHODS
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // INSTANCE VARIABLES
+ //////////////////////////////////////////////////
+
+ public boolean optShowDiffs = false;
+ public boolean optShowLocalRules = false;
+
+ //////////////////////////////////////////////////
+ // CONSTRUCTORS
+ //////////////////////////////////////////////////
+
+ public BundleReport()
+ {
+ }
+
+ //////////////////////////////////////////////////
+ // ACCESSOR METHODS
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // PUBLIC INSTANCE METHODS
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // INTERFACE METHODS - Report
+ //////////////////////////////////////////////////
+
+ /**
+ */
+ public void run(PrintStream rpt, List jarList)
+ throws IOException
+ {
+ for(Iterator i = jarList.iterator(); i.hasNext(); )
+ {
+ BundleJar bund = (BundleJar) i.next();
+ doReport(rpt, bund);
+ }
+ }
+
+ //////////////////////////////////////////////////
+ // INTERFACE METHODS - GenericHandlerItem
+ //////////////////////////////////////////////////
+
+ /**
+ * Process the option set as a a space separated list of options.
+ *
+ * opt1 opt2
+ */
+ public void setOptions(String options)
+ {
+ for (StringTokenizer tok = new StringTokenizer(options, " "); tok.hasMoreTokens(); )
+ {
+ String opt = tok.nextToken().trim();
+ if (opt.compareToIgnoreCase("show-differences") == 0)
+ {
+ optShowDiffs = true;
+ }
+ else if (opt.compareToIgnoreCase("show-local-rules") == 0)
+ {
+ optShowLocalRules = true;
+ }
+ }
+ }
+
+ //////////////////////////////////////////////////
+ // PROTECTED INSTANCE METHODS
+ //////////////////////////////////////////////////
+
+ /**
+ * Produce a simple report on the current state of the imports and exports
+ * for the specified bundle's jar.
+ */
+ protected void doReport(PrintStream rpt, BundleJar bund)
+ throws IOException
+ {
+ rpt.println("");
+ rpt.println("============================================================");
+ rpt.println(bund.getName());
+ rpt.println("============================================================");
+ rpt.println("");
+
+ if (optShowLocalRules && bund.bundleRuleHandler != null)
+ {
+ rpt.println("Local bundle rules:");
+ bund.bundleRuleHandler.runReports(rpt, false);
+ }
+
+ if (optShowDiffs)
+ {
+ rpt.println("");
+ rpt.println("mangen import differences:");
+ showDiffs(bund.getPossibleImports(), bund.getCurrentImports(), rpt);
+
+ rpt.println("");
+ rpt.println("mangen export differences:");
+ showDiffs(bund.getPossibleExports(), bund.getCurrentExports(), rpt);
+ }
+ else
+ {
+ rpt.println("");
+ rpt.println("mangen proposed imports:");
+ Set imports = bund.getPossibleImports();
+ for(Iterator i = imports.iterator(); i.hasNext(); )
+ {
+ rpt.println(" " + (OsgiPackage) i.next());
+ }
+
+ rpt.println("");
+ rpt.println("mangen proposed exports:");
+ Set exports = bund.getPossibleExports();
+ for(Iterator i = exports.iterator(); i.hasNext(); )
+ {
+ rpt.println(" " + (OsgiPackage) i.next());
+ }
+
+ rpt.println("");
+ }
+ }
+
+ /**
+ * Show the differences in the generated Set of packages and the current Set.
+ */
+ protected void showDiffs(Set genSet, Set currSet, PrintStream rpt)
+ {
+ for(Iterator i = genSet.iterator(); i.hasNext(); )
+ {
+ OsgiPackage newPkg = (OsgiPackage) i.next();
+ if (!currSet.contains(newPkg))
+ {
+ rpt.println(" +++ ADDED :" + newPkg);
+ }
+ }
+
+ for(Iterator i = currSet.iterator(); i.hasNext(); )
+ {
+ OsgiPackage oldPkg = (OsgiPackage) i.next();
+ if (!genSet.contains(oldPkg))
+ {
+ rpt.println(" --- REMOVED :" + oldPkg);
+ }
+ }
+ }
+
+ //////////////////////////////////////////////////
+ // PRIVATE INSTANCE METHODS
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // STATIC INNER CLASSES
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // NON-STATIC INNER CLASSES
+ //////////////////////////////////////////////////
+
+}
Added: incubator/felix/trunk/tools/mangen/src/main/java/org/apache/felix/tool/mangen/report/ObrReport.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/tools/mangen/src/main/java/org/apache/felix/tool/mangen/report/ObrReport.java?rev=434371&view=auto
==============================================================================
--- incubator/felix/trunk/tools/mangen/src/main/java/org/apache/felix/tool/mangen/report/ObrReport.java (added)
+++ incubator/felix/trunk/tools/mangen/src/main/java/org/apache/felix/tool/mangen/report/ObrReport.java Thu Aug 24 04:04:56 2006
@@ -0,0 +1,234 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * 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.felix.tool.mangen.report;
+
+import java.io.IOException;
+import java.io.PrintStream;
+
+import java.util.List;
+import java.util.Iterator;
+import java.util.Set;
+
+import org.apache.felix.tool.mangen.BundleJar;
+import org.apache.felix.tool.mangen.GenericHandlerItemImpl;
+import org.apache.felix.tool.mangen.OsgiPackage;
+import org.apache.felix.tool.mangen.PropertyManager;
+import org.apache.felix.tool.mangen.Report;
+
+/**
+ *
+ * Produce a report for each bundle that can be used as an OBR descriptor
+ *
+ * @version $Revision: 14 $
+ * @author <A HREF="mailto:robw@ascert.com">Rob Walker</A>
+ */
+public class ObrReport
+ extends GenericHandlerItemImpl
+ implements Report
+{
+ //////////////////////////////////////////////////
+ // STATIC VARIABLES
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // STATIC PUBLIC METHODS
+ //////////////////////////////////////////////////
+
+ public static String getObrProperty(String key)
+ {
+ String descrKey = key + "." + PropertyManager.getProperty("mangen.obr.ver", "1");
+ return PropertyManager.getProperty(descrKey, "");
+ }
+
+ //////////////////////////////////////////////////
+ // INSTANCE VARIABLES
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // CONSTRUCTORS
+ //////////////////////////////////////////////////
+
+ public ObrReport()
+ {
+ }
+
+ //////////////////////////////////////////////////
+ // ACCESSOR METHODS
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // PUBLIC INSTANCE METHODS
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // INTERFACE METHODS - Report
+ //////////////////////////////////////////////////
+
+ /**
+ */
+ public void run(PrintStream rpt, List jarList)
+ throws IOException
+ {
+ for(Iterator i = jarList.iterator(); i.hasNext(); )
+ {
+ BundleJar bund = (BundleJar) i.next();
+ // only process JARs that don't match exclusion names
+ if (!isJarNameMatch(bund.getName(), "skip-jars"))
+ {
+ doReport(rpt, bund);
+ }
+ }
+ }
+
+ //////////////////////////////////////////////////
+ // PROTECTED INSTANCE METHODS
+ //////////////////////////////////////////////////
+
+ /**
+ * Produce a simple report on the current state of the imports and exports
+ * for the specified bundle's jar.
+ */
+ protected void doReport(PrintStream rpt, BundleJar bund)
+ throws IOException
+ {
+ String descrText = getObrProperty("mangen.obr.descr");
+ rpt.println(expandTags(descrText, bund, null));
+ }
+
+ /**
+ * Expands the tags in the OBR descriptor text. General method for
+ * tag expansion. Will be called either from main bundle iteration
+ * loop to expand the complete OBR descriptor template, and also recursively from
+ * within individual tags to expand package specific template details.
+ */
+ protected String expandTags(String descr, BundleJar bund, OsgiPackage pkg)
+ {
+ StringBuffer expanded = new StringBuffer();
+
+ int off = 0;
+ int tagPos = descr.indexOf("@@", off);
+
+ while (tagPos != -1)
+ {
+ expanded.append(descr.substring(off, tagPos));
+ off = descr.indexOf("@@", tagPos+2);
+ processTag(descr.substring(tagPos+2, off), expanded, bund, pkg);
+ off += 2;
+ tagPos = descr.indexOf("@@", off);
+ }
+ // final segment
+ expanded.append(descr.substring(off));
+ return expanded.toString();
+ }
+
+
+ /**
+ * Expand single tag in the OBR descriptor text
+ */
+ protected void processTag(String tag, StringBuffer buf, BundleJar bund, OsgiPackage pkg)
+ {
+ String tagVal = "";
+
+ if (tag.startsWith("hdr:"))
+ {
+ tagVal = bund.getManifestHeader(tag.substring(4), true);
+ }
+ else if (tag.equals("imports"))
+ {
+ Set imports = bund.getPossibleImports();
+ String template = getObrProperty("mangen.obr.import");
+ tagVal = expandPackageRefs(imports, template);
+ }
+ else if (tag.equals("exports"))
+ {
+ Set exports = bund.getPossibleExports();
+ String template = getObrProperty("mangen.obr.export");
+ tagVal = expandPackageRefs(exports, template);
+ }
+ else if (tag.equals("import-ver"))
+ {
+ // only include this if the version is non-null
+ if (pkg != null && pkg.getVersion() != null)
+ {
+ // recurse for version template
+ String template = getObrProperty("mangen.obr.import.ver");
+ tagVal = expandTags(template, null, pkg);
+ }
+ }
+ else if (tag.equals("export-ver"))
+ {
+ if (pkg != null && pkg.getVersion() != null)
+ {
+ // recurse for version template
+ String template = getObrProperty("mangen.obr.export.ver");
+ tagVal = expandTags(template, null, pkg);
+ }
+ }
+ else if (tag.equals("pkg:name"))
+ {
+ // this tag should only appear in templates where we've a package
+ if (pkg != null)
+ {
+ tagVal = pkg.getName();
+ }
+ }
+ else if (tag.equals("pkg:ver"))
+ {
+ // this tag should only appear in templates where we've a package
+ if (pkg != null && pkg.getVersion() != null)
+ {
+ tagVal = pkg.getVersion().toString();
+ }
+ }
+
+ if (tagVal != null)
+ {
+ buf.append(tagVal);
+ }
+ }
+
+ /**
+ * Iterate over a set of package refs and expand each one using the
+ * supplied template.
+ */
+ protected String expandPackageRefs(Set pkgSet, String template)
+ {
+ StringBuffer expanded = new StringBuffer();
+
+ for(Iterator i = pkgSet.iterator(); i.hasNext(); )
+ {
+ OsgiPackage pkg = (OsgiPackage) i.next();
+ // recurse to expand tags, but this time only need to supply package
+ expanded.append(expandTags(template, null, pkg));
+ }
+
+ return expanded.toString();
+ }
+
+ //////////////////////////////////////////////////
+ // PRIVATE INSTANCE METHODS
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // STATIC INNER CLASSES
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // NON-STATIC INNER CLASSES
+ //////////////////////////////////////////////////
+
+}
Added: incubator/felix/trunk/tools/mangen/src/main/java/org/apache/felix/tool/mangen/report/RuleReport.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/tools/mangen/src/main/java/org/apache/felix/tool/mangen/report/RuleReport.java?rev=434371&view=auto
==============================================================================
--- incubator/felix/trunk/tools/mangen/src/main/java/org/apache/felix/tool/mangen/report/RuleReport.java (added)
+++ incubator/felix/trunk/tools/mangen/src/main/java/org/apache/felix/tool/mangen/report/RuleReport.java Thu Aug 24 04:04:56 2006
@@ -0,0 +1,108 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * 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.felix.tool.mangen.report;
+
+import java.io.IOException;
+import java.io.PrintStream;
+
+import java.util.List;
+
+import java.util.regex.Pattern;
+
+import org.apache.felix.tool.mangen.MangenMain;
+import org.apache.felix.tool.mangen.Report;
+import org.apache.felix.tool.mangen.RuleHandler;
+
+/**
+ *
+ * @version $Revision: 29 $
+ * @author <A HREF="mailto:robw@ascert.com">Rob Walker</A>
+ */
+public class RuleReport
+ implements Report
+{
+ //////////////////////////////////////////////////
+ // STATIC VARIABLES
+ //////////////////////////////////////////////////
+
+ public static Pattern[] pkgPatterns;
+
+ //////////////////////////////////////////////////
+ // STATIC PUBLIC METHODS
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // INSTANCE VARIABLES
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // CONSTRUCTORS
+ //////////////////////////////////////////////////
+
+ public RuleReport()
+ {
+ }
+
+ //////////////////////////////////////////////////
+ // ACCESSOR METHODS
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // PUBLIC INSTANCE METHODS
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // INTERFACE METHODS - Report
+ //////////////////////////////////////////////////
+
+ /**
+ */
+ public void run(PrintStream rpt, List jarList)
+ throws IOException
+ {
+ //TODO: bit of a hack for now!
+ RuleHandler.runRuleSetReports(MangenMain.ruleSets, rpt, true);
+ }
+
+ //////////////////////////////////////////////////
+ // INTERFACE METHODS - GenericHandlerItem
+ //////////////////////////////////////////////////
+
+ /**
+ */
+ public void setOptions(String options)
+ {
+ //TODO: including checking of wildcard matching options
+ }
+
+ //////////////////////////////////////////////////
+ // PROTECTED INSTANCE METHODS
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // PRIVATE INSTANCE METHODS
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // STATIC INNER CLASSES
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // NON-STATIC INNER CLASSES
+ //////////////////////////////////////////////////
+
+}
Added: incubator/felix/trunk/tools/mangen/src/main/java/org/apache/felix/tool/mangen/rule/AttributeStamp.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/tools/mangen/src/main/java/org/apache/felix/tool/mangen/rule/AttributeStamp.java?rev=434371&view=auto
==============================================================================
--- incubator/felix/trunk/tools/mangen/src/main/java/org/apache/felix/tool/mangen/rule/AttributeStamp.java (added)
+++ incubator/felix/trunk/tools/mangen/src/main/java/org/apache/felix/tool/mangen/rule/AttributeStamp.java Thu Aug 24 04:04:56 2006
@@ -0,0 +1,187 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * 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.felix.tool.mangen.rule;
+
+import java.util.List;
+import java.util.Iterator;
+import java.util.Set;
+
+import org.apache.felix.tool.mangen.MangenMain;
+import org.apache.felix.tool.mangen.OsgiPackage;
+import org.apache.felix.tool.mangen.OsgiStringPackage;
+import org.apache.felix.tool.mangen.OsgiR4Package;
+import org.apache.felix.tool.mangen.BundleJar;
+import org.apache.felix.tool.mangen.Rule;
+
+/**
+ * Rule to match package name strings against a wildcard pattern and them stamp the
+ * package with additional OSGi attributes e.g. version information.
+ *
+ * @version $Revision: 29 $
+ * @author <A HREF="mailto:robw@ascert.com">Rob Walker</A>
+ */
+public class AttributeStamp
+ extends GenericRule
+{
+ //////////////////////////////////////////////////
+ // STATIC VARIABLES
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // STATIC PUBLIC METHODS
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // INSTANCE VARIABLES
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // CONSTRUCTORS
+ //////////////////////////////////////////////////
+
+ public AttributeStamp()
+ {
+ }
+
+ //////////////////////////////////////////////////
+ // ACCESSOR METHODS
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // PUBLIC INSTANCE METHODS
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // INTERFACE METHODS - Rule
+ //////////////////////////////////////////////////
+
+ /**
+ * Iterate over the list of bundles and for each bundle remove any import
+ * which matches an export in the same bundle.
+ */
+ public void execute(List jarList)
+ {
+ for(Iterator i = jarList.iterator(); i.hasNext(); )
+ {
+ BundleJar bund = (BundleJar) i.next();
+ rptOut.println("");
+ rptOut.println("> " + bund.getName() + " :");
+
+ stampPackages(bund.getPossibleImports(), "imports");
+ stampPackages(bund.getPossibleExports(), "exports");
+ }
+ }
+
+ /**
+ * This rule can be used globally.
+ */
+ public boolean isUsableGlobally()
+ {
+ return true;
+ }
+
+ /**
+ * This rule can be used locally.
+ */
+ public boolean isUsableLocally()
+ {
+ return true;
+ }
+
+ //////////////////////////////////////////////////
+ // PROTECTED INSTANCE METHODS
+ //////////////////////////////////////////////////
+
+ /**
+ * Any string packages from the specified set which match package patterns in the
+ * specified qualifier set will have the additional OSGi attributes "stamped"
+ * onto their package specification. Packages that already have attributes which
+ * match will generate warnings and be skipped.
+ *
+ */
+ protected void stampPackages(Set set, String qualName)
+ {
+ rptOut.println("");
+ rptOut.println("... stamping packages in " + qualName);
+ for(Iterator i = set.iterator(); i.hasNext(); )
+ {
+ OsgiPackage pkg = (OsgiPackage) i.next();
+ String stamp = getMatchingPatternString(pkg, qualName, true);
+ if (stamp != null)
+ {
+ stamp(pkg, stamp, set);
+ }
+ }
+ }
+
+ /**
+ * Stamp the supplied package with the specified attributes. This will be
+ * an error if the package is already an R4 pakage with conflicting attributes.
+ */
+ protected void stamp(OsgiPackage pkg, String stamp, Set set)
+ {
+ int delim = stamp.indexOf(";");
+
+ if (delim == -1)
+ {
+ MangenMain.warning(rptOut, "*** WARNING *** stamp has no attributes: " + stamp);
+ return;
+ }
+
+ // simple thing is to rebuild an OSGi header with attributes and use OsgiPackage
+ // methods to parse this into an R4 package.
+ String hdr = pkg.getName() + stamp.substring(delim);
+ OsgiPackage[] newPkgs = (OsgiPackage[]) OsgiPackage.createFromHeaders(hdr).toArray(new OsgiPackage[0]);
+ if (newPkgs.length != 1)
+ {
+ MangenMain.error(rptOut, "*** ERROR *** stamp doesn't create a single package : " + stamp);
+ return;
+ }
+ OsgiPackage stampedPkg = newPkgs[0];
+
+ // replace a simple string package with the stamped package
+ if (pkg instanceof OsgiStringPackage)
+ {
+ set.remove(pkg);
+ set.add(stampedPkg);
+ rptOut.println(" > replacing : " + pkg + " with : " + stampedPkg);
+ return;
+
+ }
+
+ // it's an error to try and stamp an existing package with different details
+ if (pkg instanceof OsgiR4Package && pkg.compareTo(stampedPkg) != 0)
+ {
+ MangenMain.error(rptOut, "*** ERROR *** stamp has conflicting package details: " + pkg
+ + " != " + stampedPkg);
+ return;
+ }
+ }
+
+ //////////////////////////////////////////////////
+ // PRIVATE INSTANCE METHODS
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // STATIC INNER CLASSES
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // NON-STATIC INNER CLASSES
+ //////////////////////////////////////////////////
+
+}
Added: incubator/felix/trunk/tools/mangen/src/main/java/org/apache/felix/tool/mangen/rule/DontImportOwnExports.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/tools/mangen/src/main/java/org/apache/felix/tool/mangen/rule/DontImportOwnExports.java?rev=434371&view=auto
==============================================================================
--- incubator/felix/trunk/tools/mangen/src/main/java/org/apache/felix/tool/mangen/rule/DontImportOwnExports.java (added)
+++ incubator/felix/trunk/tools/mangen/src/main/java/org/apache/felix/tool/mangen/rule/DontImportOwnExports.java Thu Aug 24 04:04:56 2006
@@ -0,0 +1,151 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * 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.felix.tool.mangen.rule;
+
+import java.util.List;
+import java.util.Iterator;
+import java.util.Set;
+
+import org.apache.felix.tool.mangen.OsgiPackage;
+import org.apache.felix.tool.mangen.BundleJar;
+import org.apache.felix.tool.mangen.Rule;
+
+/**
+ * Rule to exclude each bundle's own exports from it's list of possible imports.
+ * <p>
+ * Any packages which are exported by a bundle in general do not need to also
+ * be imported and hence can be excluded from the list of possible imports.
+ * <p>
+ * Note that with OSGi R4 comes support for a bundle to import versions of it's
+ * own packages from an alternate bundle. This may require enhancements to this
+ * rule, or possibly extra rules.
+ *
+ * @version $Revision: 29 $
+ * @author <A HREF="mailto:robw@ascert.com">Rob Walker</A>
+ */
+public class DontImportOwnExports
+ extends GenericRule
+{
+ //////////////////////////////////////////////////
+ // STATIC VARIABLES
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // STATIC PUBLIC METHODS
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // INSTANCE VARIABLES
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // CONSTRUCTORS
+ //////////////////////////////////////////////////
+
+ public DontImportOwnExports()
+ {
+ }
+
+ //////////////////////////////////////////////////
+ // ACCESSOR METHODS
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // PUBLIC INSTANCE METHODS
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // INTERFACE METHODS - Rule
+ //////////////////////////////////////////////////
+
+ /**
+ * Iterate over the list of bundles and for each bundle remove any import
+ * which matches an export in the same bundle.
+ */
+ public void execute(List jarList)
+ {
+ for(Iterator i = jarList.iterator(); i.hasNext(); )
+ {
+ BundleJar bund = (BundleJar) i.next();
+ rptOut.println("");
+ rptOut.println("> " + bund.getName() + " :");
+
+ Set exports = bund.getPossibleExports();
+ Set imports = bund.getPossibleImports();
+ for(Iterator j = exports.iterator(); j.hasNext(); )
+ {
+ remove(imports, (OsgiPackage) j.next());
+ }
+ }
+ }
+
+ /**
+ * This rule can be used globally.
+ */
+ public boolean isUsableGlobally()
+ {
+ return true;
+ }
+
+ /**
+ * This rule can be used locally.
+ */
+ public boolean isUsableLocally()
+ {
+ return true;
+ }
+
+ //////////////////////////////////////////////////
+ // INTERFACE METHODS - GenericHandlerItem
+ //////////////////////////////////////////////////
+
+ /**
+ * No required options for this rule.
+ */
+ public void setOptions(String options)
+ {
+ }
+
+ //////////////////////////////////////////////////
+ // PROTECTED INSTANCE METHODS
+ //////////////////////////////////////////////////
+
+ /**
+ * Removes any import which is an exact match for the supplied package.
+ */
+ protected void remove(Set set, OsgiPackage pkg)
+ {
+ if (set.contains(pkg))
+ {
+ rptOut.println("... removing import of own export: " + pkg);
+ set.remove(pkg);
+ }
+ }
+
+ //////////////////////////////////////////////////
+ // PRIVATE INSTANCE METHODS
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // STATIC INNER CLASSES
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // NON-STATIC INNER CLASSES
+ //////////////////////////////////////////////////
+
+}
Added: incubator/felix/trunk/tools/mangen/src/main/java/org/apache/felix/tool/mangen/rule/GenericRule.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/tools/mangen/src/main/java/org/apache/felix/tool/mangen/rule/GenericRule.java?rev=434371&view=auto
==============================================================================
--- incubator/felix/trunk/tools/mangen/src/main/java/org/apache/felix/tool/mangen/rule/GenericRule.java (added)
+++ incubator/felix/trunk/tools/mangen/src/main/java/org/apache/felix/tool/mangen/rule/GenericRule.java Thu Aug 24 04:04:56 2006
@@ -0,0 +1,94 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * 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.felix.tool.mangen.rule;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+
+import org.apache.felix.tool.mangen.GenericHandlerItemImpl;
+import org.apache.felix.tool.mangen.Rule;
+
+/**
+ * Holder for common Rule handling methods, such as reporting
+ *
+ * @version $Revision: 27 $
+ * @author <A HREF="mailto:robw@ascert.com">Rob Walker</A>
+ */
+public abstract class GenericRule
+ extends GenericHandlerItemImpl
+ implements Rule
+{
+ //////////////////////////////////////////////////
+ // STATIC VARIABLES
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // STATIC PUBLIC METHODS
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // INSTANCE VARIABLES
+ //////////////////////////////////////////////////
+
+ /** Holds buffered rule output in case a rule report is requested */
+ public ByteArrayOutputStream rptBuf = new ByteArrayOutputStream();
+ public PrintStream rptOut = new PrintStream(rptBuf);
+
+ //////////////////////////////////////////////////
+ // CONSTRUCTORS
+ //////////////////////////////////////////////////
+
+ public GenericRule()
+ {
+ }
+
+ //////////////////////////////////////////////////
+ // ACCESSOR METHODS
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // PUBLIC INSTANCE METHODS
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // INTERFACE METHODS - Rule
+ //////////////////////////////////////////////////
+
+ public void report(PrintStream rpt)
+ throws IOException
+ {
+ rptBuf.writeTo(rpt);
+ }
+
+ //////////////////////////////////////////////////
+ // PROTECTED INSTANCE METHODS
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // PRIVATE INSTANCE METHODS
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // STATIC INNER CLASSES
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // NON-STATIC INNER CLASSES
+ //////////////////////////////////////////////////
+
+}
Added: incubator/felix/trunk/tools/mangen/src/main/java/org/apache/felix/tool/mangen/rule/Ignore.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/tools/mangen/src/main/java/org/apache/felix/tool/mangen/rule/Ignore.java?rev=434371&view=auto
==============================================================================
--- incubator/felix/trunk/tools/mangen/src/main/java/org/apache/felix/tool/mangen/rule/Ignore.java (added)
+++ incubator/felix/trunk/tools/mangen/src/main/java/org/apache/felix/tool/mangen/rule/Ignore.java Thu Aug 24 04:04:56 2006
@@ -0,0 +1,137 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * 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.felix.tool.mangen.rule;
+
+import java.util.List;
+import java.util.Iterator;
+import java.util.Set;
+
+import org.apache.felix.tool.mangen.BundleJar;
+import org.apache.felix.tool.mangen.OsgiPackage;
+
+/**
+ * Rule to exclude specific packages from each bundle's possible imports.
+ * <p>
+ * Package names that match any of a list of regex based package name patterns
+ * will be excluded from the list of possible imports.
+ *
+ * @version $Revision: 29 $
+ * @author <A HREF="mailto:robw@ascert.com">Rob Walker</A>
+ */
+public class Ignore
+ extends GenericRule
+{
+ //////////////////////////////////////////////////
+ // STATIC VARIABLES
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // STATIC PUBLIC METHODS
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // INSTANCE VARIABLES
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // CONSTRUCTORS
+ //////////////////////////////////////////////////
+
+ public Ignore()
+ {
+ }
+
+ //////////////////////////////////////////////////
+ // ACCESSOR METHODS
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // PUBLIC INSTANCE METHODS
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // INTERFACE METHODS - Rule
+ //////////////////////////////////////////////////
+
+ /**
+ * Iterate over the list of bundle jars, removing any imports
+ * which match any of the specific package name Patterns
+ */
+ public void execute(List jarList)
+ {
+ for(Iterator i = jarList.iterator(); i.hasNext(); )
+ {
+ BundleJar bund = (BundleJar) i.next();
+ rptOut.println("");
+ rptOut.println("> " + bund.getName() + " :");
+
+ removeMatchingPackages(bund.getPossibleImports(), "imports");
+ removeMatchingPackages(bund.getPossibleExports(), "exports");
+ }
+ }
+
+ /**
+ * This rule can be used globally.
+ */
+ public boolean isUsableGlobally()
+ {
+ return true;
+ }
+
+ /**
+ * This rule can be used locally.
+ */
+ public boolean isUsableLocally()
+ {
+ return true;
+ }
+
+ //////////////////////////////////////////////////
+ // PROTECTED INSTANCE METHODS
+ //////////////////////////////////////////////////
+
+ /**
+ * Removes all packages from the set which match package patterns in the
+ * specified qualifier set.
+ */
+ public void removeMatchingPackages(Set set, String qualName)
+ {
+ for(Iterator i = set.iterator(); i.hasNext(); )
+ {
+ OsgiPackage pkg = (OsgiPackage) i.next();
+ if (isPackageMatch(pkg, qualName))
+ {
+ rptOut.println("... removing ignored package from " + qualName + " : " + pkg);
+ i.remove();
+ }
+ }
+ }
+
+
+ //////////////////////////////////////////////////
+ // PRIVATE INSTANCE METHODS
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // STATIC INNER CLASSES
+ //////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////
+ // NON-STATIC INNER CLASSES
+ //////////////////////////////////////////////////
+
+}