Knopflerfish OSGi 1.3.3

org.knopflerfish.ant.taskdefs.bundle
Class BundleInfoTask

java.lang.Object
  extended byorg.apache.tools.ant.ProjectComponent
      extended byorg.apache.tools.ant.Task
          extended byorg.knopflerfish.ant.taskdefs.bundle.BundleInfoTask

public class BundleInfoTask
extends org.apache.tools.ant.Task

Task that analyzes a set of java sources or class files, and lists all imported and defined packages. Also tries to find any class implementing org.osgi.framework.BundleActivator.

Parameters

Parameters specified as nested elements

fileset

(required)

All files must be specified as a fileset. Unsupported file types are ignored.

Examples

Check all imports and activator in implementation classes

This example assumes all implemention classes are in the package test.impl.*

  <bundleinfo  activator = "bundle.activator" 
               imports   = "impl.import.package">
   <fileset dir="classes" includes="test/impl/*"/>
  </bundleinfo>
  <echo message="imports   = ${impl.import.package}"/>
  <echo message="activator = ${bundle.activator}"/>
 

Check all imports and exports in API classes

This example assumes all API classes are in the package test.*

  <bundleinfo  exports  = "api.export.package" 
               imports  = "api.import.package">
   <fileset dir="classes" includes="test/*"/>
  </bundleinfo>
  <echo message="imports  = ${api.import.package}"/>
  <echo message="exports  = ${api.export.package}"/>
 


Attribute Description Required
imports Name of property that will receive a comma-separated list of all used packages.

If set to empty string, no property will be set.

Note: Some default packages are always added. These defaults can be set using the defaultimports parameter.

No.
Default value is ""
exports Name of property that will receive a comma-separated list of all defined packages.

If set to empty string, no property will be set.

No.
Default value is ""
activator Name of property that will receive name of class which implements org.osgi.framework.BundleActivator

If set to empty string, no property will be set.

If set to non-empty, and multiple activators are found, or an activator not equal to any previous content in the named property is found - a warning will be logged.

No.
Default value is ""
stdimports Comma-separated list of all prefixes to standard packages that should be ignored in exports list. No.
Default value is "java."
defaultimports Comma-separated list of all default imported packages.

Note: Do not set defaultimports to the empty string, since that might cause an later illegal bundle manifest file if no imported packages are found.

No.
Default value is "org.osgi.framework"
checkFoundationEE Flag for testing for the Foundation Execution Environment

If set to "true", the task will check if all used classes is in the set of the OSGi Foundation Execution Environment.

No.
Default value is "false"
Field Summary
 
Fields inherited from class org.apache.tools.ant.Task
description, location, target, taskName, taskType, wrapper
 
Fields inherited from class org.apache.tools.ant.ProjectComponent
project
 
Constructor Summary
BundleInfoTask()
           
 
Method Summary
protected  void addActivatorString(java.lang.String s)
           
protected  void addExportedPackageString(java.lang.String name)
           
 void addFileset(org.apache.tools.ant.types.FileSet set)
           
protected  void addImportedString(java.lang.String className)
          Add a class' package name to the list of imported packages.
protected  void addImportedType(org.apache.bcel.generic.Type t)
          Add a type's package name to the list of imported packages.
protected  void analyze(java.io.File file)
          Analyze a file by checking its suffix and delegate to analyzeClass, analyzeJava etc
protected  void analyzeClass(java.io.File file)
           
protected  void analyzeJar(java.io.File file)
           
protected  void analyzeJava(java.io.File file)
          Analyze java source file by reading line by line and looking for keywords such as "import", "package".
 void execute()
           
protected  boolean isStdImport(java.lang.String name)
          Check if package is included in prefix list of standard packages.
 void setActivator(java.lang.String propName)
          Set property receiving any BundleActivator class.
 void setCheckFoundationEE(java.lang.String s)
           
 void setCheckMinimumEE(java.lang.String s)
           
 void setCheckSMFEE(java.lang.String s)
           
 void setDefaultImports(java.lang.String packageList)
          Set default import set.
 void setExports(java.lang.String propName)
          Set property receiving list of exported packages.
 void setImports(java.lang.String s)
          Set property receiving list of imported packages.
 void setMain(java.lang.String propName)
          Set property receiving any Main class.
 void setPrintClasses(java.lang.String s)
           
 void setStdImports(java.lang.String packageList)
          Set set of packages always imported.
protected static java.lang.String toString(java.util.Set set, java.lang.String separator)
          Convert Set elements to a string.
 
Methods inherited from class org.apache.tools.ant.Task
getDescription, getLocation, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, init, isInvalid, log, log, maybeConfigure, perform, reconfigure, setDescription, setLocation, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskType
 
Methods inherited from class org.apache.tools.ant.ProjectComponent
getProject, setProject
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BundleInfoTask

public BundleInfoTask()
Method Detail

setImports

public void setImports(java.lang.String s)
Set property receiving list of imported packages.


setPrintClasses

public void setPrintClasses(java.lang.String s)

setCheckFoundationEE

public void setCheckFoundationEE(java.lang.String s)

setCheckMinimumEE

public void setCheckMinimumEE(java.lang.String s)

setCheckSMFEE

public void setCheckSMFEE(java.lang.String s)

setDefaultImports

public void setDefaultImports(java.lang.String packageList)
Set default import set.

Parameters:
packageList - Comma-separated list of package names.

setExports

public void setExports(java.lang.String propName)
Set property receiving list of exported packages.


setActivator

public void setActivator(java.lang.String propName)
Set property receiving any BundleActivator class.


setMain

public void setMain(java.lang.String propName)
Set property receiving any Main class.

Not yet implemented.


setStdImports

public void setStdImports(java.lang.String packageList)
Set set of packages always imported.

Parameters:
packageList - Comma-separated list of package names.

addFileset

public void addFileset(org.apache.tools.ant.types.FileSet set)

execute

public void execute()
             throws org.apache.tools.ant.BuildException
Throws:
org.apache.tools.ant.BuildException

analyze

protected void analyze(java.io.File file)
                throws org.apache.tools.ant.BuildException
Analyze a file by checking its suffix and delegate to analyzeClass, analyzeJava etc

Throws:
org.apache.tools.ant.BuildException

addExportedPackageString

protected void addExportedPackageString(java.lang.String name)

addActivatorString

protected void addActivatorString(java.lang.String s)

addImportedType

protected void addImportedType(org.apache.bcel.generic.Type t)
Add a type's package name to the list of imported packages.

Parameters:
t - Type of an object.

addImportedString

protected void addImportedString(java.lang.String className)
Add a class' package name to the list of imported packages.

Parameters:
className - Class name of an object. The class name is stripped from the part after the last '.' and added to set of imported packages, if its not one of the standard packages. Primitive class names are ignore.

isStdImport

protected boolean isStdImport(java.lang.String name)
Check if package is included in prefix list of standard packages.

Returns:
true if name is prefixed with any of the elements in stdImports set, false otherwise.

analyzeJar

protected void analyzeJar(java.io.File file)
                   throws org.apache.tools.ant.BuildException
Throws:
org.apache.tools.ant.BuildException

analyzeClass

protected void analyzeClass(java.io.File file)
                     throws org.apache.tools.ant.BuildException
Throws:
org.apache.tools.ant.BuildException

analyzeJava

protected void analyzeJava(java.io.File file)
                    throws org.apache.tools.ant.BuildException
Analyze java source file by reading line by line and looking for keywords such as "import", "package".

Note: This code does not attempt to find any class implementing BundleActivator

Throws:
org.apache.tools.ant.BuildException

toString

protected static java.lang.String toString(java.util.Set set,
                                           java.lang.String separator)
Convert Set elements to a string.

Parameters:
separator - String to use as sperator between elements.

Knopflerfish OSGi 1.3.3