Knopflerfish OSGi 5.2.0

org.knopflerfish.ant.taskdefs.bundle
Class BundlePackagesInfo

java.lang.Object
  extended by org.knopflerfish.ant.taskdefs.bundle.BundlePackagesInfo

public class BundlePackagesInfo
extends java.lang.Object

Class that holds the results of the Java package analysis of all classes in a bundle.

Class and package names should use either '/' or '.' as separator between package levels during build up phase. When all classes packages have been added, make a call to toJavaNames() to convert all class / packages names using the internal Java representation with '/' as separator to their non-internal representation with '.' as separator. Mixing of separator kinds is not supported!

When all classes have been added, before using the package using map a call to postProcessUsingMap(Set,Set) should be done.


Constructor Summary
BundlePackagesInfo(org.apache.tools.ant.Task task)
           
 
Method Summary
 void addProvidedActivatorClass(java.lang.String className)
          Adds a named class to the set of classes that implements the interface BundleActivator.
 java.lang.String addProvidedClass(java.lang.String className)
          Adds a named class to the set of classes provided by this bundle.
 void addProvidedPackage(java.lang.String packageName)
          Adds a named package to the set of packages provided by this bundle.
 void addReferencedClass(java.lang.String referencingPackage, java.lang.String referencedClass)
          Add a reference to a named class from some class in the referencing Java package.
 int countProvidedActivatorClasses()
          Gets the cardinality of the set of provided bundle activator classes.
 int countProvidedPackages()
          Gets the cardinality of the set of provided Java packages.
 boolean equals(java.lang.Object other)
           
 java.lang.String getActivatorClass()
          Get the bundle activator from the set of provided bundle activator classes.
 java.util.SortedSet<java.lang.String> getPackagesReferencedFromPackage(java.lang.String packageName)
          Get a the set of Java packages that are referenced by the given Java package.
 java.util.SortedSet<java.lang.String> getProvidedPackages()
          Get a copy of the set of provided Java packages.
 java.lang.String getProvidedPackagesAsExportPackageValue()
          Get the provided packages formatted as the value of an Export-Package-manifest attribute with package versions.
 Version getProvidedPackageVersion(java.lang.String pkgName)
          Get the version of a provided package as defined by the packageinfo-file in the package-directory.
 java.lang.String getProvidedPackageVersionSource(java.lang.String pkgName)
          Get the path of the file that the version of a provided package was found in.
 java.util.SortedSet<java.lang.String> getReferencedClasses()
          Get a copy of the set of referenced Java classes.
 java.util.SortedSet<java.lang.String> getReferencedPackages()
          Get a copy of the set of Java packages that are referenced by this bundle.
 java.util.SortedSet<java.lang.String> getUnprovidedReferencedPackages()
          Get a the set of Java packages that are referenced by this bundle but not provided by it.
static java.lang.String packageName(java.lang.String className)
          Get package name of class string representation.
 void postProcessUsingMap(java.util.Set<java.lang.String> removeFromReferencedSets, java.util.Set<java.lang.String> retainInReferencedSets)
          Post process the package to referenced packages map.
 java.lang.String providedActivatorClassesAsString()
          Return the set of provided activator classes as string suitable for use in messages.
 boolean providesActivatorClass(java.lang.String className)
          Checks if a named class is in the set of provided activator classes.
 boolean providesClass(java.lang.String className)
          Checks if a named class is provided by this bundle.
 boolean providesPackage(java.lang.String packageName)
          Checks if a named Java package is provided by this bundle.
 java.lang.String setPackageVersion(org.apache.tools.ant.types.Resource res)
          Try to assign a version to the Java that the given packageinfo-file resides in.
 void toJavaNames()
          Replaces all '/' in class and package names with '.' in all the collections that this class is holding.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BundlePackagesInfo

public BundlePackagesInfo(org.apache.tools.ant.Task task)
Method Detail

packageName

public static java.lang.String packageName(java.lang.String className)
Get package name of class string representation.

Parameters:
className - A fully qualified class name.
Returns:
The Java package name that the named class belongs to. Will return the empty string if the named class does not belong to any package.

addProvidedClass

public java.lang.String addProvidedClass(java.lang.String className)
Adds a named class to the set of classes provided by this bundle. This method also adds the package of the class to the set of provided packages. It also add a reference to the class from its own package.

Parameters:
className - the name of the class to add.
Returns:
the name of the Java package that the given class belongs to.

providesClass

public boolean providesClass(java.lang.String className)
Checks if a named class is provided by this bundle.

Parameters:
className - the name of the class to check for.
Returns:
true if the given class is in the set of classes provided by this bundle, false otherwise.

addProvidedActivatorClass

public void addProvidedActivatorClass(java.lang.String className)
Adds a named class to the set of classes that implements the interface BundleActivator.

Parameters:
className - the name of the activator class to add.

countProvidedActivatorClasses

public int countProvidedActivatorClasses()
Gets the cardinality of the set of provided bundle activator classes.

Returns:
Number of elements in the set of provided bundle activator classes.

providesActivatorClass

public boolean providesActivatorClass(java.lang.String className)
Checks if a named class is in the set of provided activator classes.

Parameters:
className - the name of the activator class to check for.
Returns:
true if the given class is in the set of provided activator classes, false otherwise.

providedActivatorClassesAsString

public java.lang.String providedActivatorClassesAsString()
Return the set of provided activator classes as string suitable for use in messages.

Returns:
The provided set of activator classes as a string.

getActivatorClass

public java.lang.String getActivatorClass()
Get the bundle activator from the set of provided bundle activator classes.

Returns:
The one and only activator class when the size of the set of provided bundle activator classes is one, otherwise null.

addProvidedPackage

public void addProvidedPackage(java.lang.String packageName)
Adds a named package to the set of packages provided by this bundle.

Parameters:
packageName - the name of the Java package to add.

providesPackage

public boolean providesPackage(java.lang.String packageName)
Checks if a named Java package is provided by this bundle.

Parameters:
packageName - the name of the package to check for.
Returns:
true if the given package is in the set of packages provided by this bundle, false otherwise.

getProvidedPackages

public java.util.SortedSet<java.lang.String> getProvidedPackages()
Get a copy of the set of provided Java packages. This method may be called before toJavaNames().

Returns:
A copy of the set of provided Java packages.

getProvidedPackagesAsExportPackageValue

public java.lang.String getProvidedPackagesAsExportPackageValue()
Get the provided packages formatted as the value of an Export-Package-manifest attribute with package versions.

Returns:
OSGi Export-Package header value.

countProvidedPackages

public int countProvidedPackages()
Gets the cardinality of the set of provided Java packages.

Returns:
Number of elements in the set of provided packages.

getProvidedPackageVersion

public Version getProvidedPackageVersion(java.lang.String pkgName)
Get the version of a provided package as defined by the packageinfo-file in the package-directory.

Parameters:
pkgName - The package to get the version of.
Returns:
The package version or null if not defined.

getProvidedPackageVersionSource

public java.lang.String getProvidedPackageVersionSource(java.lang.String pkgName)
Get the path of the file that the version of a provided package was found in.

Parameters:
pkgName - The version-ed package to get the version source of.
Returns:
The path of the packageinfo-file that the version was read from.

setPackageVersion

public java.lang.String setPackageVersion(org.apache.tools.ant.types.Resource res)
Try to assign a version to the Java that the given packageinfo-file resides in. This code assumes that the resource has been created in such a way that res.getName() returns a relative path to the packageinfo-file that starts in its package root. I.e., the path is the Java package that the packageinfo-file provides data for.

Parameters:
res - Resource encapsulating a packageinfo-file.
Returns:
The package name or null if no valid version was found.

getReferencedClasses

public java.util.SortedSet<java.lang.String> getReferencedClasses()
Get a copy of the set of referenced Java classes.

Returns:
A copy of the set of referenced Java packages.

getUnprovidedReferencedPackages

public java.util.SortedSet<java.lang.String> getUnprovidedReferencedPackages()
Get a the set of Java packages that are referenced by this bundle but not provided by it.

Returns:
The set of un-provided referenced Java packages.

getReferencedPackages

public java.util.SortedSet<java.lang.String> getReferencedPackages()
Get a copy of the set of Java packages that are referenced by this bundle.

Returns:
The set of referenced Java packages.

addReferencedClass

public void addReferencedClass(java.lang.String referencingPackage,
                               java.lang.String referencedClass)
Add a reference to a named class from some class in the referencing Java package. If the given referenced class is an inner class, then we also add a reference for its outer class. This is not really needed for static inner classes, but there is no way to detect that on this level.

Parameters:
referencingPackage - The Java package of the class having a reference to className.
referencedClass - Fully qualified name of the referenced class.

postProcessUsingMap

public void postProcessUsingMap(java.util.Set<java.lang.String> removeFromReferencedSets,
                                java.util.Set<java.lang.String> retainInReferencedSets)
Post process the package to referenced packages map.
  1. Remove all self references.
  2. Remove all references to "java.*".
  3. Remove all packages in the remove from referenced set are removed from all referenced sets.
  4. Retain all packages in the retain in referenced set. I.e., the referenced sets will only contain packages present in this set.

Parameters:
removeFromReferencedSets - Packages to remove
retainInReferencedSets - Packages to retain.

getPackagesReferencedFromPackage

public java.util.SortedSet<java.lang.String> getPackagesReferencedFromPackage(java.lang.String packageName)
Get a the set of Java packages that are referenced by the given Java package.

Parameters:
packageName - The name of the Java package to get referenced Java packages for.
Returns:
The set of referenced Java packages.

toJavaNames

public void toJavaNames()
Replaces all '/' in class and package names with '.' in all the collections that this class is holding.


equals

public boolean equals(java.lang.Object other)
Overrides:
equals in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

Knopflerfish OSGi 5.2.0