aQute.lib.osgi
Class Processor

java.lang.Object
  extended by aQute.lib.osgi.Processor
All Implemented Interfaces:
Constants, aQute.libg.reporter.Reporter, java.io.Closeable
Direct Known Subclasses:
Analyzer

public class Processor
extends java.lang.Object
implements aQute.libg.reporter.Reporter, Constants, java.io.Closeable


Field Summary
static java.lang.String DEFAULT_PLUGINS
           
static java.lang.String LIST_SPLITTER
           
 
Fields inherited from interface aQute.lib.osgi.Constants
BLUEPRINT_TIMEOUT_ATTRIBUTE, BLUEPRINT_WAIT_FOR_DEPENDENCIES_ATTRIBUTE, BND_LASTMODIFIED, BUILDFILES, BUILDPATH, BUMPPOLICY, BUNDLE_ACTIVATIONPOLICY, BUNDLE_ACTIVATOR, BUNDLE_BLUEPRINT, BUNDLE_CATEGORY, BUNDLE_CLASSPATH, BUNDLE_CONTACTADDRESS, BUNDLE_COPYRIGHT, BUNDLE_DESCRIPTION, BUNDLE_DOCURL, BUNDLE_ICON, BUNDLE_LICENSE, BUNDLE_LOCALIZATION, BUNDLE_MANIFESTVERSION, BUNDLE_NAME, BUNDLE_NATIVECODE, BUNDLE_REQUIREDEXECUTIONENVIRONMENT, BUNDLE_SPECIFIC_HEADERS, BUNDLE_SYMBOLIC_NAME_ATTRIBUTE, BUNDLE_SYMBOLICNAME, BUNDLE_UPDATELOCATION, BUNDLE_VENDOR, BUNDLE_VERSION, BUNDLE_VERSION_ATTRIBUTE, CLASSPATH, COMMAND_DIRECTIVE, CONDITIONAL_PACKAGE, CONDUIT, CREATED_BY, CURRENT_PACKAGE, CURRENT_USES, CURRENT_VERSION, DEBUG, DEFAULT_BAR_EXTENSION, DEFAULT_BND_EXTENSION, DEFAULT_JAR_EXTENSION, DEPENDSON, DEPLOYREPO, DESCRIPTION_ATTRIBUTE, directives, DONOTCOPY, DUPLICATE_MARKER, DYNAMICIMPORT_PACKAGE, EXCLUDE_DIRECTIVE, EXPORT_CONTENTS, EXPORT_PACKAGE, EXPORT_SERVICE, EXTENSION_DIRECTIVE, FAIL_OK, FRAGMENT_ATTACHMENT_DIRECTIVE, FRAGMENT_HOST, headers, IGNORE_PACKAGE, IMPORT_DIRECTIVE, IMPORT_PACKAGE, IMPORT_PRIVATE, IMPORT_REFERENCE, IMPORT_SERVICE, importDirectives, INCLUDE, INCLUDE_DIRECTIVE, INCLUDE_RESOURCE, INCLUDERESOURCE, KEYSTORE_LOCATION_DIRECTIVE, KEYSTORE_PASSWORD_DIRECTIVE, KEYSTORE_PROVIDER_DIRECTIVE, LANGUAGE_ATTRIBUTE, LINK_ATTRIBUTE, MAKE, MANDATORY_DIRECTIVE, MANIFEST, METAPACKAGES, NAME_ATTRIBUTE, NO_IMPORT_DIRECTIVE, NOEXTRAHEADERS, NOMANIFEST, NONE, NOPE, NOUSES, options, OSNAME_ATTRIBUTE, OSVERSION_ATTRIBUTE, PATH_DIRECTIVE, PEDANTIC, PLUGIN, POM, PRESENCE_DIRECTIVE, PRIVATE_PACKAGE, PROCESSOR_ATTRIBUTE, RELEASEREPO, REMOVE_ATTRIBUTE_DIRECTIVE, REMOVE_HEADERS, REPORTNEWER, REQUIRE_BUNDLE, RESOLUTION_DIRECTIVE, RESOURCEONLY, RUNBUNDLES, RUNPATH, RUNPROPERTIES, RUNSYSTEMPACKAGES, RUNVM, SELECTION_FILTER_ATTRIBUTE, SERVICE_COMPONENT, SIGN, SIGN_PASSWORD_DIRECTIVE, SIGNATURE_TEST, SINGLETON_DIRECTIVE, SIZE_ATTRIBUTE, SOURCEPATH, SOURCES, SPLIT_PACKAGE_DIRECTIVE, STRATEGY_HIGHEST, STRATEGY_LOWEST, SUB, TESTBUNDLES, TESTCASES, TESTPACKAGES, TESTREPORT, TOOL, UNDERTEST, USES_DIRECTIVE, USES_USES, VALID_PROPERTY_TYPES, VERBOSE, VERSION_ATTRIBUTE, VERSIONPOLICY, VISIBILITY_DIRECTIVE
 
Constructor Summary
Processor()
           
Processor(Processor parent)
           
Processor(java.util.Properties parent)
           
 
Method Summary
 java.lang.String _basedir(java.lang.String[] args)
           
 void addClose(java.io.Closeable jar)
           
 void addIncluded(java.io.File file)
           
 void addProperties(java.io.File file)
           
static java.lang.String appendPath(java.lang.String... parts)
          Append two strings to for a path in a ZIP or JAR file.
protected  void begin()
           
 void clear()
           
 void close()
           
 void error(java.lang.String string, java.lang.Object... args)
           
 void error(java.lang.String string, java.lang.Throwable t, java.lang.Object... args)
           
 boolean exists()
           
 java.io.File getBase()
           
 java.util.List<java.lang.String> getErrors()
           
static java.io.File getFile(java.io.File base, java.lang.String file)
           
 java.io.File getFile(java.lang.String file)
           
 java.util.Properties getFlattenedProperties()
          Return the properties but expand all macros.
 void getInfo(Processor processor)
           
 void getInfo(Processor processor, java.lang.String prefix)
           
protected  java.lang.Object[] getMacroDomains()
          This should be overridden by subclasses to add extra macro command domains on the search list.
static java.util.Properties getManifestAsProperties(java.io.InputStream in)
          Read a manifest but return a properties object.
 Processor getParent()
           
protected  java.util.List<java.lang.Object> getPlugins()
          Return a list of plugins.
<T> java.util.List<T>
getPlugins(java.lang.Class<T> clazz)
          Return a list of plugins that implement the given class.
 java.util.Properties getProperties()
          Property handling ...
 java.io.File getPropertiesFile()
           
 java.lang.String getProperty(java.lang.String key)
           
 java.lang.String getProperty(java.lang.String key, java.lang.String deflt)
          Get a property with a proper default
 Macro getReplacer()
           
 Processor getTop()
           
 java.util.List<java.lang.String> getWarnings()
           
static boolean isDuplicate(java.lang.String name)
           
 boolean isExceptions()
           
 boolean isFailOk()
           
 boolean isMissingPlugin(java.lang.String name)
          Answer if the name is a missing plugin's command name.
 boolean isOk()
           
 boolean isPedantic()
           
 boolean isPerfect()
           
static boolean isTrue(java.lang.String value)
           
static java.lang.String join(java.util.Collection<?> list)
           
static java.lang.String join(java.util.Collection<?> list, java.lang.String delimeter)
          Join a list.
static java.lang.String join(java.lang.Object[] list, java.lang.String delimeter)
           
 long lastModified()
           
 java.util.Properties loadProperties(java.io.File file)
          Helper to load a properties file from disk.
static java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.String>> merge(java.lang.String type, java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.String>> instructions, java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.String>> actual, java.util.Set<java.lang.String> superfluous, java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.String>> ignored)
          Merge the attributes of two maps, where the first map can contain wildcarded names.
 void mergeProperties(java.io.File file, boolean override)
           
 void mergeProperties(java.util.Properties properties, boolean override)
           
static
<K,V> java.util.Map<K,V>
newHashMap()
           
<T> java.util.List<T>
newList()
           
<T> java.util.List<T>
newList(java.util.Collection<T> t)
           
static
<K,V> java.util.Map<K,V>
newMap()
           
<K,V> java.util.Map<K,V>
newMap(java.util.Map<K,V> t)
           
<T> java.util.Set<T>
newSet()
           
<T> java.util.Set<T>
newSet(java.util.Collection<T> t)
           
 java.lang.String normalize(java.io.File f)
           
 java.lang.String normalize(java.lang.String f)
          Make the file short if it is inside our base directory, otherwise long.
 java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.String>> parseHeader(java.lang.String value)
           
static java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.String>> parseHeader(java.lang.String value, Processor logger)
          Standard OSGi header parser.
static void printClause(java.util.Map<java.lang.String,java.lang.String> map, java.lang.String allowedDirectives, java.lang.StringBuffer sb)
           
static java.lang.String printClauses(java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.String>> exports, java.lang.String allowedDirectives)
          Print a standard Map based OSGi header.
static java.lang.String printClauses(java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.String>> exports, java.lang.String allowedDirectives, boolean checkMultipleVersions)
           
 void progress(java.lang.String s, java.lang.Object... args)
           
 void propertiesChanged()
           
static java.lang.String read(java.io.InputStream in)
           
 boolean refresh()
           
static java.lang.String removeDuplicateMarker(java.lang.String key)
           
static java.util.Properties replaceAll(java.util.Properties p, java.lang.String pattern, java.lang.String replacement)
          Replace a string in all the values of the map.
static java.util.Map<Instruction,java.util.Map<java.lang.String,java.lang.String>> replaceWitInstruction(java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.String>> header, java.lang.String type)
           
 void setBase(java.io.File base)
           
 void setExceptions(boolean exceptions)
           
 void setFileMustExist(boolean mustexist)
           
 void setForceLocal(java.util.Collection<java.lang.String> local)
           
 void setParent(Processor processor)
           
 void setPedantic(boolean pedantic)
           
 void setProperties(java.io.File propertiesFile)
          Set the properties by file.
 void setProperties(java.io.File propertiesFile, java.io.File base)
           
 void setProperties(java.util.Properties properties)
           
 void setProperty(java.lang.String key, java.lang.String value)
          Add or override a new property.
 void setTrace(boolean x)
           
static java.util.Collection<java.lang.String> split(java.lang.String s)
           
static void split(java.lang.String s, java.util.Collection<java.lang.String> set)
           
static java.util.Collection<java.lang.String> split(java.lang.String s, java.lang.String splitter)
           
 void trace(java.lang.String msg, java.lang.Object... parms)
           
 void unsetProperty(java.lang.String string)
           
 void updateModified(long time, java.lang.String reason)
           
 void warning(java.lang.String string, java.lang.Object... args)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_PLUGINS

public static java.lang.String DEFAULT_PLUGINS

LIST_SPLITTER

public static java.lang.String LIST_SPLITTER
Constructor Detail

Processor

public Processor()

Processor

public Processor(java.util.Properties parent)

Processor

public Processor(Processor parent)
Method Detail

setParent

public void setParent(Processor processor)

getParent

public Processor getParent()

getTop

public Processor getTop()

getInfo

public void getInfo(Processor processor,
                    java.lang.String prefix)

getInfo

public void getInfo(Processor processor)

warning

public void warning(java.lang.String string,
                    java.lang.Object... args)
Specified by:
warning in interface aQute.libg.reporter.Reporter

error

public void error(java.lang.String string,
                  java.lang.Object... args)
Specified by:
error in interface aQute.libg.reporter.Reporter

error

public void error(java.lang.String string,
                  java.lang.Throwable t,
                  java.lang.Object... args)

getWarnings

public java.util.List<java.lang.String> getWarnings()
Specified by:
getWarnings in interface aQute.libg.reporter.Reporter

getErrors

public java.util.List<java.lang.String> getErrors()
Specified by:
getErrors in interface aQute.libg.reporter.Reporter

parseHeader

public java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.String>> parseHeader(java.lang.String value)

parseHeader

public static java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.String>> parseHeader(java.lang.String value,
                                                                                                           Processor logger)
Standard OSGi header parser.

Parameters:
value -
Returns:

addClose

public void addClose(java.io.Closeable jar)

progress

public void progress(java.lang.String s,
                     java.lang.Object... args)
Specified by:
progress in interface aQute.libg.reporter.Reporter

isPedantic

public boolean isPedantic()
Specified by:
isPedantic in interface aQute.libg.reporter.Reporter

setPedantic

public void setPedantic(boolean pedantic)

getFile

public static java.io.File getFile(java.io.File base,
                                   java.lang.String file)

getFile

public java.io.File getFile(java.lang.String file)

getPlugins

public <T> java.util.List<T> getPlugins(java.lang.Class<T> clazz)
Return a list of plugins that implement the given class.

Parameters:
clazz - Each returned plugin implements this class/interface
Returns:
A list of plugins

getPlugins

protected java.util.List<java.lang.Object> getPlugins()
Return a list of plugins. Plugins are defined with the -plugin command. They are class names, optionally associated with attributes. Plugins can implement the Plugin interface to see these attributes. Any object can be a plugin.

Returns:

isFailOk

public boolean isFailOk()

getBase

public java.io.File getBase()

setBase

public void setBase(java.io.File base)

clear

public void clear()

trace

public void trace(java.lang.String msg,
                  java.lang.Object... parms)
Specified by:
trace in interface aQute.libg.reporter.Reporter

newList

public <T> java.util.List<T> newList()

newSet

public <T> java.util.Set<T> newSet()

newMap

public static <K,V> java.util.Map<K,V> newMap()

newHashMap

public static <K,V> java.util.Map<K,V> newHashMap()

newList

public <T> java.util.List<T> newList(java.util.Collection<T> t)

newSet

public <T> java.util.Set<T> newSet(java.util.Collection<T> t)

newMap

public <K,V> java.util.Map<K,V> newMap(java.util.Map<K,V> t)

close

public void close()
Specified by:
close in interface java.io.Closeable

_basedir

public java.lang.String _basedir(java.lang.String[] args)

getProperties

public java.util.Properties getProperties()
Property handling ...

Returns:

getProperty

public java.lang.String getProperty(java.lang.String key)

mergeProperties

public void mergeProperties(java.io.File file,
                            boolean override)

mergeProperties

public void mergeProperties(java.util.Properties properties,
                            boolean override)

setProperties

public void setProperties(java.util.Properties properties)

addProperties

public void addProperties(java.io.File file)
                   throws java.lang.Exception
Throws:
java.lang.Exception

addIncluded

public void addIncluded(java.io.File file)

unsetProperty

public void unsetProperty(java.lang.String string)

refresh

public boolean refresh()

propertiesChanged

public void propertiesChanged()

setProperties

public void setProperties(java.io.File propertiesFile)
                   throws java.io.IOException
Set the properties by file. Setting the properties this way will also set the base for this analyzer. After reading the properties, this will call setProperties(Properties) which will handle the includes.

Parameters:
propertiesFile -
Throws:
java.io.FileNotFoundException
java.io.IOException

setProperties

public void setProperties(java.io.File propertiesFile,
                          java.io.File base)

begin

protected void begin()

isTrue

public static boolean isTrue(java.lang.String value)

getProperty

public java.lang.String getProperty(java.lang.String key,
                                    java.lang.String deflt)
Get a property with a proper default

Parameters:
headerName -
deflt -
Returns:

loadProperties

public java.util.Properties loadProperties(java.io.File file)
                                    throws java.io.IOException
Helper to load a properties file from disk.

Parameters:
file -
Returns:
Throws:
java.io.IOException

replaceAll

public static java.util.Properties replaceAll(java.util.Properties p,
                                              java.lang.String pattern,
                                              java.lang.String replacement)
Replace a string in all the values of the map. This can be used to preassign variables that change. I.e. the base directory ${.} for a loaded properties


merge

public static java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.String>> merge(java.lang.String type,
                                                                                                     java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.String>> instructions,
                                                                                                     java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.String>> actual,
                                                                                                     java.util.Set<java.lang.String> superfluous,
                                                                                                     java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.String>> ignored)
Merge the attributes of two maps, where the first map can contain wildcarded names. The idea is that the first map contains patterns (for example *) with a set of attributes. These patterns are matched against the found packages in actual. If they match, the result is set with the merged set of attributes. It is expected that the instructions are ordered so that the instructor can define which pattern matches first. Attributes in the instructions override any attributes from the actual.
A pattern is a modified regexp so it looks like globbing. The * becomes a .* just like the ? becomes a .?. '.' are replaced with \\. Additionally, if the pattern starts with an exclamation mark, it will remove that matches for that pattern (- the !) from the working set. So the following patterns should work: Enough rope to hang the average developer I would say.

Parameters:
instructions - the instructions with patterns. A
actual - the actual found packages

printClauses

public static java.lang.String printClauses(java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.String>> exports,
                                            java.lang.String allowedDirectives)
Print a standard Map based OSGi header.

Parameters:
exports - map { name => Map { attribute|directive => value } }
Returns:
the clauses

printClauses

public static java.lang.String printClauses(java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.String>> exports,
                                            java.lang.String allowedDirectives,
                                            boolean checkMultipleVersions)

printClause

public static void printClause(java.util.Map<java.lang.String,java.lang.String> map,
                               java.lang.String allowedDirectives,
                               java.lang.StringBuffer sb)

getReplacer

public Macro getReplacer()

getMacroDomains

protected java.lang.Object[] getMacroDomains()
This should be overridden by subclasses to add extra macro command domains on the search list.

Returns:

getFlattenedProperties

public java.util.Properties getFlattenedProperties()
Return the properties but expand all macros. This always returns a new Properties object that can be used in any way.

Returns:

updateModified

public void updateModified(long time,
                           java.lang.String reason)

lastModified

public long lastModified()

setProperty

public void setProperty(java.lang.String key,
                        java.lang.String value)
Add or override a new property.

Parameters:
key -
value -

getManifestAsProperties

public static java.util.Properties getManifestAsProperties(java.io.InputStream in)
                                                    throws java.io.IOException
Read a manifest but return a properties object.

Parameters:
in -
Returns:
Throws:
java.io.IOException

getPropertiesFile

public java.io.File getPropertiesFile()

setFileMustExist

public void setFileMustExist(boolean mustexist)

read

public static java.lang.String read(java.io.InputStream in)
                             throws java.lang.Exception
Throws:
java.lang.Exception

join

public static java.lang.String join(java.util.Collection<?> list,
                                    java.lang.String delimeter)
Join a list.

Parameters:
args -
Returns:

join

public static java.lang.String join(java.lang.Object[] list,
                                    java.lang.String delimeter)

join

public static java.lang.String join(java.util.Collection<?> list)

split

public static void split(java.lang.String s,
                         java.util.Collection<java.lang.String> set)

split

public static java.util.Collection<java.lang.String> split(java.lang.String s)

split

public static java.util.Collection<java.lang.String> split(java.lang.String s,
                                                           java.lang.String splitter)

isExceptions

public boolean isExceptions()

setExceptions

public void setExceptions(boolean exceptions)

normalize

public java.lang.String normalize(java.lang.String f)
Make the file short if it is inside our base directory, otherwise long.

Parameters:
f -
Returns:

normalize

public java.lang.String normalize(java.io.File f)

removeDuplicateMarker

public static java.lang.String removeDuplicateMarker(java.lang.String key)

isDuplicate

public static boolean isDuplicate(java.lang.String name)

setTrace

public void setTrace(boolean x)

exists

public boolean exists()

isOk

public boolean isOk()

isPerfect

public boolean isPerfect()

setForceLocal

public void setForceLocal(java.util.Collection<java.lang.String> local)

replaceWitInstruction

public static java.util.Map<Instruction,java.util.Map<java.lang.String,java.lang.String>> replaceWitInstruction(java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.String>> header,
                                                                                                                java.lang.String type)

isMissingPlugin

public boolean isMissingPlugin(java.lang.String name)
Answer if the name is a missing plugin's command name. If a bnd file contains the command name of a plugin, and that plugin is not available, then an error is reported during manifest calculation. This allows the plugin to fail to load when it is not needed. We first get the plugins to ensure it is properly initialized.

Parameters:
name -
Returns:

appendPath

public static java.lang.String appendPath(java.lang.String... parts)
Append two strings to for a path in a ZIP or JAR file. It is guaranteed to return a string that does not start, nor ends with a '/', while it is properly separated with slashes. Double slashes are properly removed.
  "/" + "abc/def/" becomes "abc/def"

Parameters:
prefix -
suffix -
Returns: