aQute.lib.osgi

Class Processor

public class Processor extends Object implements Reporter, Constants, Closeable

Field Summary
static StringDEFAULT_PLUGINS
static StringLIST_SPLITTER
Constructor Summary
Processor()
Processor(Properties parent)
Processor(Processor parent)
Method Summary
voidaddClose(Closeable jar)
voidaddIncluded(File file)
voidaddProperties(File file)
static StringappendPath(String... parts)
Append two strings to for a path in a ZIP or JAR file.
protected voidbegin()
voidclear()
voidclose()
voiderror(String string, Object... args)
voiderror(String string, Throwable t, Object... args)
booleanexists()
FilegetBase()
List<String>getErrors()
static FilegetFile(File base, String file)
FilegetFile(String file)
PropertiesgetFlattenedProperties()
Return the properties but expand all macros.
voidgetInfo(Processor processor, String prefix)
voidgetInfo(Processor processor)
protected Object[]getMacroDomains()
This should be overridden by subclasses to add extra macro command domains on the search list.
static PropertiesgetManifestAsProperties(InputStream in)
Read a manifest but return a properties object.
ProcessorgetParent()
<T> List<T>getPlugins(Class<T> clazz)
Return a list of plugins that implement the given class.
protected List<Object>getPlugins()
Return a list of plugins.
PropertiesgetProperties()
Property handling ...
FilegetPropertiesFile()
StringgetProperty(String key)
StringgetProperty(String key, String deflt)
Get a property with a proper default
MacrogetReplacer()
ProcessorgetTop()
List<String>getWarnings()
static booleanisDuplicate(String name)
booleanisExceptions()
booleanisFailOk()
booleanisMissingPlugin(String name)
Answer if the name is a missing plugin's command name.
booleanisOk()
booleanisPedantic()
booleanisPerfect()
static booleanisTrue(String value)
static Stringjoin(Collection<?> list, String delimeter)
Join a list.
static Stringjoin(Object[] list, String delimeter)
static Stringjoin(Collection<?> list)
longlastModified()
PropertiesloadProperties(File file)
Helper to load a properties file from disk.
static Map<String,Map<String,String>>merge(String type, Map<String,Map<String,String>> instructions, Map<String,Map<String,String>> actual, Set<String> superfluous, Map<String,Map<String,String>> ignored)
Merge the attributes of two maps, where the first map can contain wildcarded names.
voidmergeProperties(File file, boolean override)
voidmergeProperties(Properties properties, boolean override)
static <K,V> Map<K,V>newHashMap()
<T> List<T>newList()
<T> List<T>newList(Collection<T> t)
static <K,V> Map<K,V>newMap()
<K,V> Map<K,V>newMap(Map<K,V> t)
<T> Set<T>newSet()
<T> Set<T>newSet(Collection<T> t)
Stringnormalize(String f)
Make the file short if it is inside our base directory, otherwise long.
Stringnormalize(File f)
Map<String,Map<String,String>>parseHeader(String value)
Map<String,Map<String,String>>parseHeader(String value, Processor logger)
Standard OSGi header parser.
static voidprintClause(Map<String,String> map, String allowedDirectives, StringBuffer sb)
static StringprintClauses(Map<String,Map<String,String>> exports, String allowedDirectives)
Print a standard Map based OSGi header.
static StringprintClauses(Map<String,Map<String,String>> exports, String allowedDirectives, boolean checkMultipleVersions)
voidprogress(String s, Object... args)
voidpropertiesChanged()
static Stringread(InputStream in)
booleanrefresh()
static StringremoveDuplicateMarker(String key)
static PropertiesreplaceAll(Properties p, String pattern, String replacement)
Replace a string in all the values of the map.
static Map<Instruction,Map<String,String>>replaceWitInstruction(Map<String,Map<String,String>> header, String type)
voidsetBase(File base)
voidsetExceptions(boolean exceptions)
voidsetFileMustExist(boolean mustexist)
voidsetForceLocal(Collection<String> local)
voidsetParent(Processor processor)
voidsetPedantic(boolean pedantic)
voidsetProperties(Properties properties)
voidsetProperties(File propertiesFile)
Set the properties by file.
voidsetProperties(File propertiesFile, File base)
voidsetProperty(String key, String value)
Add or override a new property.
voidsetTrace(boolean x)
static voidsplit(String s, Collection<String> set)
static Collection<String>split(String s)
static Collection<String>split(String s, String splitter)
voidtrace(String msg, Object... parms)
voidunsetProperty(String string)
voidupdateModified(long time, String reason)
voidwarning(String string, Object... args)
String_basedir(String[] args)

Field Detail

DEFAULT_PLUGINS

public static String DEFAULT_PLUGINS

LIST_SPLITTER

public static String LIST_SPLITTER

Constructor Detail

Processor

public Processor()

Processor

public Processor(Properties parent)

Processor

public Processor(Processor parent)

Method Detail

addClose

public void addClose(Closeable jar)

addIncluded

public void addIncluded(File file)

addProperties

public void addProperties(File file)

appendPath

public static String appendPath(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:

begin

protected void begin()

clear

public void clear()

close

public void close()

error

public void error(String string, Object... args)

error

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

exists

public boolean exists()

getBase

public File getBase()

getErrors

public List<String> getErrors()

getFile

public static File getFile(File base, String file)

getFile

public File getFile(String file)

getFlattenedProperties

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

Returns:

getInfo

public void getInfo(Processor processor, String prefix)

getInfo

public void getInfo(Processor processor)

getMacroDomains

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

Returns:

getManifestAsProperties

public static Properties getManifestAsProperties(InputStream in)
Read a manifest but return a properties object.

Parameters: in

Returns:

Throws: IOException

getParent

public Processor getParent()

getPlugins

public <T> List<T> getPlugins(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 List<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:

getProperties

public Properties getProperties()
Property handling ...

Returns:

getPropertiesFile

public File getPropertiesFile()

getProperty

public String getProperty(String key)

getProperty

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

Parameters: headerName deflt

Returns:

getReplacer

public Macro getReplacer()

getTop

public Processor getTop()

getWarnings

public List<String> getWarnings()

isDuplicate

public static boolean isDuplicate(String name)

isExceptions

public boolean isExceptions()

isFailOk

public boolean isFailOk()

isMissingPlugin

public boolean isMissingPlugin(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:

isOk

public boolean isOk()

isPedantic

public boolean isPedantic()

isPerfect

public boolean isPerfect()

isTrue

public static boolean isTrue(String value)

join

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

Parameters: args

Returns:

join

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

join

public static String join(Collection<?> list)

lastModified

public long lastModified()

loadProperties

public Properties loadProperties(File file)
Helper to load a properties file from disk.

Parameters: file

Returns:

Throws: IOException

merge

public static Map<String,Map<String,String>> merge(String type, Map<String,Map<String,String>> instructions, Map<String,Map<String,String>> actual, Set<String> superfluous, Map<String,Map<String,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

mergeProperties

public void mergeProperties(File file, boolean override)

mergeProperties

public void mergeProperties(Properties properties, boolean override)

newHashMap

public static <K,V> Map<K,V> newHashMap()

newList

public <T> List<T> newList()

newList

public <T> List<T> newList(Collection<T> t)

newMap

public static <K,V> Map<K,V> newMap()

newMap

public <K,V> Map<K,V> newMap(Map<K,V> t)

newSet

public <T> Set<T> newSet()

newSet

public <T> Set<T> newSet(Collection<T> t)

normalize

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

Parameters: f

Returns:

normalize

public String normalize(File f)

parseHeader

public Map<String,Map<String,String>> parseHeader(String value)

parseHeader

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

Parameters: value

Returns:

printClause

public static void printClause(Map<String,String> map, String allowedDirectives, StringBuffer sb)

printClauses

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

Parameters: exports map { name => Map { attribute|directive => value } }

Returns: the clauses

printClauses

public static String printClauses(Map<String,Map<String,String>> exports, String allowedDirectives, boolean checkMultipleVersions)

progress

public void progress(String s, Object... args)

propertiesChanged

public void propertiesChanged()

read

public static String read(InputStream in)

refresh

public boolean refresh()

removeDuplicateMarker

public static String removeDuplicateMarker(String key)

replaceAll

public static Properties replaceAll(Properties p, String pattern, 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

replaceWitInstruction

public static Map<Instruction,Map<String,String>> replaceWitInstruction(Map<String,Map<String,String>> header, String type)

setBase

public void setBase(File base)

setExceptions

public void setExceptions(boolean exceptions)

setFileMustExist

public void setFileMustExist(boolean mustexist)

setForceLocal

public void setForceLocal(Collection<String> local)

setParent

public void setParent(Processor processor)

setPedantic

public void setPedantic(boolean pedantic)

setProperties

public void setProperties(Properties properties)

setProperties

public void setProperties(File propertiesFile)
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: FileNotFoundException IOException

setProperties

public void setProperties(File propertiesFile, File base)

setProperty

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

Parameters: key value

setTrace

public void setTrace(boolean x)

split

public static void split(String s, Collection<String> set)

split

public static Collection<String> split(String s)

split

public static Collection<String> split(String s, String splitter)

trace

public void trace(String msg, Object... parms)

unsetProperty

public void unsetProperty(String string)

updateModified

public void updateModified(long time, String reason)

warning

public void warning(String string, Object... args)

_basedir

public String _basedir(String[] args)