aQute.lib.osgi

Class Analyzer

public class Analyzer extends Processor

This class can calculate the required headers for a (potential) JAR file. It analyzes a directory or JAR for the packages that are contained and that are referred to by the bytecodes. The user can the use regular expressions to define the attributes and directives. The matching is not fully regex for convenience. A * and ? get a . prefixed and dots are escaped.
                                                             			*;auto=true				any		
                                                             			org.acme.*;auto=true    org.acme.xyz
                                                             			org.[abc]*;auto=true    org.acme.xyz
 
Additional, the package instruction can start with a '=' or a '!'. The '!' indicates negation. Any matching package is removed. The '=' is literal, the expression will be copied verbatim and no matching will take place. Any headers in the given properties are used in the output properties.
Constructor Summary
Analyzer(Processor parent)
Analyzer()
Method Summary
voidaddClasspath(Jar jar)
voidaddClasspath(File cp)
voidanalyze()
Calcualtes the data structures for generating a manifest.
Map<String,Clazz>analyzeBundleClasspath(Jar dot, Map<String,Map<String,String>> bundleClasspath, Map<String,Map<String,String>> contained, Map<String,Map<String,String>> referred, Map<String,Set<String>> uses)
protected voidbegin()
ManifestcalcManifest()
One of the main workhorses of this class.
StringcalculateExportsFromContents(Jar bundle)
Calculate an export header solely based on the contents of a JAR file
booleancheckClass(String interfaceName)
Check if the given class or interface name is contained in the jar.
static StringcleanupVersion(String version)
voidclear()
voidclose()
StringgetBndInfo(String key, String defaultValue)
longgetBndLastModified()
StringgetBsn()
Clear the key part of a header.
Map<String,Map<String,String>>getBundleClasspath()
Collection<Clazz>getClasses(String... args)
List<Jar>getClasspath()
Map<String,Clazz>getClassspace()
Map<String,Map<String,String>>getContained()
Map<String,Map<String,String>>getExports()
protected StringgetImportPackages()
Analyzer has an empty default but the builder has a * as default.
Map<String,Map<String,String>>getImports()
JargetJar()
static PropertiesgetManifest(File dirOrJar)
Specifically for Maven
StringgetPackage(String clazz)
Map<String,Map<String,String>>getReferred()
JargetTarget()
Set<String>getUnreachable()
Return the set of unreachable code depending on exports and the bundle activator.
Map<String,Set<String>>getUses()
StringgetVersion()
Get the version from the manifest, a lot of work!
StringgetVersionPolicy()
voidmergeManifest(Manifest manifest)
Merge the existing manifest with the instructions.
voidputAll(Map<String,String> additional, boolean force)
voidsetBase(File file)
voidsetClasspath(File[] classpath)
Set the classpath for this analyzer by file.
voidsetClasspath(Jar[] classpath)
voidsetClasspath(String[] classpath)
JarsetJar(File jar)
Set the JAR file we are going to work in.
JarsetJar(Jar jar)
Set the JAR directly we are going to work on.
String_bsn(String[] args)
String_classes(String... args)
String_exporters(String[] args)
Get the exporter of a package ...
String_findname(String[] args)
String_findpath(String[] args)
Findpath looks through the contents of the JAR and finds paths that end with the given regular expression ${findpath (; reg-expr (; replacement)?

Constructor Detail

Analyzer

public Analyzer(Processor parent)

Analyzer

public Analyzer()

Method Detail

addClasspath

public void addClasspath(Jar jar)

addClasspath

public void addClasspath(File cp)

analyze

public void analyze()
Calcualtes the data structures for generating a manifest.

Throws: IOException

analyzeBundleClasspath

public Map<String,Clazz> analyzeBundleClasspath(Jar dot, Map<String,Map<String,String>> bundleClasspath, Map<String,Map<String,String>> contained, Map<String,Map<String,String>> referred, Map<String,Set<String>> uses)

begin

protected void begin()

calcManifest

public Manifest calcManifest()
One of the main workhorses of this class. This will analyze the current setp and calculate a new manifest according to this setup. This method will also set the manifest on the main jar dot

Returns:

Throws: IOException

calculateExportsFromContents

public String calculateExportsFromContents(Jar bundle)
Calculate an export header solely based on the contents of a JAR file

Parameters: bundle The jar file to analyze

Returns:

checkClass

public boolean checkClass(String interfaceName)
Check if the given class or interface name is contained in the jar.

Parameters: interfaceName

Returns:

cleanupVersion

public static String cleanupVersion(String version)

clear

public void clear()

close

public void close()

getBndInfo

public String getBndInfo(String key, String defaultValue)

getBndLastModified

public long getBndLastModified()

getBsn

public String getBsn()
Clear the key part of a header. I.e. remove everything from the first ';'

Parameters: value

Returns:

getBundleClasspath

public Map<String,Map<String,String>> getBundleClasspath()

getClasses

public Collection<Clazz> getClasses(String... args)

getClasspath

public List<Jar> getClasspath()

getClassspace

public Map<String,Clazz> getClassspace()

getContained

public Map<String,Map<String,String>> getContained()

getExports

public Map<String,Map<String,String>> getExports()

getImportPackages

protected String getImportPackages()
Analyzer has an empty default but the builder has a * as default.

Returns:

getImports

public Map<String,Map<String,String>> getImports()

getJar

public Jar getJar()

getManifest

public static Properties getManifest(File dirOrJar)
Specifically for Maven

Parameters: properties the properties

getPackage

public String getPackage(String clazz)

getReferred

public Map<String,Map<String,String>> getReferred()

getTarget

public Jar getTarget()

getUnreachable

public Set<String> getUnreachable()
Return the set of unreachable code depending on exports and the bundle activator.

Returns:

getUses

public Map<String,Set<String>> getUses()

getVersion

public String getVersion()
Get the version from the manifest, a lot of work!

Returns: version or unknown.

getVersionPolicy

public String getVersionPolicy()

mergeManifest

public void mergeManifest(Manifest manifest)
Merge the existing manifest with the instructions.

Parameters: manifest The manifest to merge with

Throws: IOException

putAll

public void putAll(Map<String,String> additional, boolean force)

setBase

public void setBase(File file)

setClasspath

public void setClasspath(File[] classpath)
Set the classpath for this analyzer by file.

Parameters: classpath

Throws: IOException

setClasspath

public void setClasspath(Jar[] classpath)

setClasspath

public void setClasspath(String[] classpath)

setJar

public Jar setJar(File jar)
Set the JAR file we are going to work in. This will read the JAR in memory.

Parameters: jar

Returns:

Throws: IOException

setJar

public Jar setJar(Jar jar)
Set the JAR directly we are going to work on.

Parameters: jar

Returns:

_bsn

public String _bsn(String[] args)

_classes

public String _classes(String... args)

_exporters

public String _exporters(String[] args)
Get the exporter of a package ...

_findname

public String _findname(String[] args)

_findpath

public String _findpath(String[] args)
Findpath looks through the contents of the JAR and finds paths that end with the given regular expression ${findpath (; reg-expr (; replacement)? )? }

Parameters: args

Returns: