aQute.lib.osgi
Class Processor

java.lang.Object
  extended by aQute.lib.osgi.Processor
All Implemented Interfaces:
Registry, Constants, Reporter, Closeable
Direct Known Subclasses:
Analyzer, MavenCommand, MavenDeployCmd, PomParser, Project, Signer, Workspace

public class Processor
extends Object
implements Reporter, Registry, Constants, Closeable


Field Summary
static String LIST_SPLITTER
           
 
Fields inherited from interface aQute.lib.osgi.Constants
BLUEPRINT_TIMEOUT_ATTRIBUTE, BLUEPRINT_WAIT_FOR_DEPENDENCIES_ATTRIBUTE, BND_ADDXMLTOTEST, BND_LASTMODIFIED, BUILDFILES, BUILDPACKAGES, 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, COMPILER_SOURCE, COMPILER_TARGET, COMPONENT_ACTIVATE, COMPONENT_CONFIGURATION_POLICY, COMPONENT_DEACTIVATE, COMPONENT_DESCRIPTORS, COMPONENT_DESIGNATE, COMPONENT_DESIGNATEFACTORY, COMPONENT_DYNAMIC, COMPONENT_ENABLED, COMPONENT_FACTORY, COMPONENT_IMMEDIATE, COMPONENT_IMPLEMENTATION, COMPONENT_MODIFIED, COMPONENT_MULTIPLE, COMPONENT_NAME, COMPONENT_OPTIONAL, COMPONENT_PROPERTIES, COMPONENT_PROVIDE, COMPONENT_SERVICEFACTORY, COMPONENT_VERSION, componentDirectives, CONDITIONAL_PACKAGE, CONDUIT, CONSUMER_POLICY, CREATED_BY, CURRENT_PACKAGE, CURRENT_USES, CURRENT_VERSION, DEBUG, DEFAULT_BAR_EXTENSION, DEFAULT_BND_EXTENSION, DEFAULT_BNDRUN_EXTENSION, DEFAULT_CHARSET, DEFAULT_DO_NOT_COPY, DEFAULT_JAR_EXTENSION, DEFAULT_LAUNCHER_BSN, DEFAULT_TESTER_BSN, DEPENDSON, DEPLOY, DEPLOYREPO, DESCRIPTION_ATTRIBUTE, directives, DONOTCOPY, DUPLICATE_MARKER, DYNAMICIMPORT_PACKAGE, EMBEDDED_REPO, EMPTY, EMPTY_HEADER, EXCLUDE_DIRECTIVE, EXPORT_CONTENTS, EXPORT_PACKAGE, EXPORT_SERVICE, EXTENSION_DIRECTIVE, FAIL_OK, FRAGMENT_ATTACHMENT_DIRECTIVE, FRAGMENT_HOST, FROM_DIRECTIVE, headers, IGNORE_PACKAGE, IMPORT_DIRECTIVE, IMPORT_PACKAGE, IMPORT_PRIVATE, IMPORT_REFERENCE, IMPORT_SERVICE, importDirectives, INCLUDE, INCLUDE_DIRECTIVE, INCLUDE_RESOURCE, INCLUDERESOURCE, JIDENTIFIER, KEYSTORE_LOCATION_DIRECTIVE, KEYSTORE_PASSWORD_DIRECTIVE, KEYSTORE_PROVIDER_DIRECTIVE, LANGUAGE_ATTRIBUTE, LAUNCHER_PLUGIN, LIB_DIRECTIVE, LINK_ATTRIBUTE, MAKE, MANDATORY_DIRECTIVE, MANIFEST, METAPACKAGES, METATYPE, NAME_ATTRIBUTE, NAMESECTION, NAMESPACE_STEM, NO_IMPORT_DIRECTIVE, NOANNOTATIONS, NOBUNDLES, NODEFAULTVERSION, NOEXTRAHEADERS, NOMANIFEST, NONE, NOPE, NOUSES, options, OSNAME_ATTRIBUTE, OSVERSION_ATTRIBUTE, PATH_DIRECTIVE, PEDANTIC, PLUGIN, POM, PRESENCE_DIRECTIVE, PRIVATE_DIRECTIVE, PRIVATE_PACKAGE, PROCESSOR_ATTRIBUTE, PROVIDE_DIRECTIVE, PROVIDER_POLICY, RELEASEREPO, REMOVE_ATTRIBUTE_DIRECTIVE, REMOVEHEADERS, REPORTNEWER, REQUIRE_BND, REQUIRE_BUNDLE, RESOLUTION_DIRECTIVE, RESOURCEONLY, RUNBUILDS, RUNBUNDLES, RUNFRAMEWORK, RUNFRAMEWORK_NONE, RUNFRAMEWORK_SERVICES, RUNPATH, RUNPATH_LAUNCHER_DIRECTIVE, RUNPATH_MAIN_DIRECTIVE, RUNPROPERTIES, RUNSTORAGE, RUNSYSTEMPACKAGES, RUNTIMEOUT, RUNTRACE, RUNVM, SAVEMANIFEST, SELECTION_FILTER_ATTRIBUTE, SERVICE_COMPONENT, SET_COMPONENT_DIRECTIVES, SET_COMPONENT_DIRECTIVES_1_1, SIGN, SIGN_PASSWORD_DIRECTIVE, SIGNATURE_TEST, SINGLETON_DIRECTIVE, SIZE_ATTRIBUTE, SNAPSHOT, SOURCEPATH, SOURCES, SPECIFICATION_VERSION, SPLIT_PACKAGE_DIRECTIVE, SUB, TESTCASES, TESTCONTINUOUS, TESTER_PLUGIN, TESTPACKAGES, TESTPATH, TESTREPORT, TOOL, UNDERTEST, USES_DIRECTIVE, USES_USES, VALID_PROPERTY_TYPES, VERBOSE, VERSION_ATTRIBUTE, VERSION_FILTER, VERSIONPOLICY, VERSIONPOLICY_IMPL, VERSIONPOLICY_USES, VISIBILITY_DIRECTIVE, WAB, WABLIB
 
Constructor Summary
Processor()
           
Processor(Processor parent)
           
Processor(Properties parent)
           
 
Method Summary
 String _basedir(String[] args)
           
 String _random(String[] args)
          Generate a random string, which is guaranteed to be a valid Java identifier (first character is an ASCII letter, subsequent characters are ASCII letters or numbers).
 void addBasicPlugin(Object plugin)
          These plugins are added to the total list of plugins.
 void addClose(Closeable jar)
           
 void addIncluded(File file)
           
 void addProperties(File file)
           
static String append(String... strings)
           
static String appendPath(String... parts)
          Append two strings to for a path in a ZIP or JAR file.
protected  void begin()
           
protected  Processor beginHandleErrors(String message)
          Set the current command thread.
 void clear()
           
 void close()
           
protected
<T> T
customize(T plugin, Map<String,String> map)
           
static Map<String,String> doAttrbutes(Object[] attrs, Clazz clazz, Macro macro)
          Parse the a=b strings and return a map of them.
 void doIncludeFile(File file, boolean overwrite, Properties target)
           
protected  void endHandleErrors(Processor previous)
          End a command.
 void error(String string, Object... args)
           
 void error(String string, Throwable t, Object... args)
           
 boolean exists()
           
 void forceRefresh()
           
static String formatArrays(String string, Object... parms)
          This method is the same as String.format but it makes sure that any arrays are transformed to strings.
 File getBase()
           
 Class<?> getClass(String type, File jar)
           
static long getDuration(String tm, long dflt)
           
 List<String> getErrors()
           
static Executor getExecutor()
           
static File getFile(File base, String file)
           
 File getFile(String file)
           
 Properties getFlattenedProperties()
          Return the properties but expand all macros.
 void getInfo(Processor processor)
           
 void getInfo(Processor processor, String prefix)
           
protected  Object[] getMacroDomains()
          This should be overridden by subclasses to add extra macro command domains on the search list.
static Properties getManifestAsProperties(InputStream in)
          Read a manifest but return a properties object.
 Processor getParent()
           
<T> T
getPlugin(Class<T> clazz)
          Returns the first plugin it can find of the given type.
protected  Set<Object> getPlugins()
          Return a list of plugins.
<T> List<T>
getPlugins(Class<T> clazz)
          Return a list of plugins that implement the given class.
 Properties getProperties()
          Property handling ...
 File getPropertiesFile()
           
 String getProperty(String key)
           
 String getProperty(String key, String deflt)
          Get a property with a proper default
 Macro getReplacer()
           
 Processor getTop()
           
 List<String> getWarnings()
           
static boolean isDuplicate(String name)
           
 boolean isExceptions()
           
 boolean isFailOk()
           
 boolean isMissingPlugin(String name)
          Answer if the name is a missing plugin's command name.
 boolean isOk()
           
 boolean isPedantic()
           
 boolean isPerfect()
           
 boolean isTrace()
           
static boolean isTrue(String value)
           
static String join(Collection<?>... list)
           
static String join(Collection<?> list, String delimeter)
          Join a list.
static String join(Object[] list, String delimeter)
           
static String join(String delimeter, Collection<?>... list)
           
static
<T> String
join(T[] list)
           
 long lastModified()
           
protected  void loadPlugins(Set<Object> list, String spe)
           
 Properties loadProperties(File file)
          Helper to load a properties file from disk.
static Object makePrintable(Object object)
          Check if the object is an array and turn it into a string if it is, otherwise unchanged.
static String merge(String... strings)
           
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.
 void mergeProperties(File file, boolean override)
           
 void mergeProperties(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)
           
 String normalize(File f)
           
 String normalize(String f)
          Make the file short if it is inside our base directory, otherwise long.
 Map<String,Map<String,String>> parseHeader(String value)
           
static Map<String,Map<String,String>> parseHeader(String value, Processor logger)
          Standard OSGi header parser.
static void printClause(Map<String,String> map, StringBuffer sb)
           
static String printClauses(Map<String,Map<String,String>> exports)
          Print a standard Map based OSGi header.
static String printClauses(Map<String,Map<String,String>> exports, boolean checkMultipleVersions)
           
 void progress(String s, Object... args)
           
 void propertiesChanged()
           
static String read(InputStream in)
           
 boolean refresh()
           
 void removeBasicPlugin(Object plugin)
           
static String removeDuplicateMarker(String key)
           
static Properties replaceAll(Properties p, String pattern, String replacement)
          Replace a string in all the values of the map.
 void setBase(File base)
           
 void setExceptions(boolean exceptions)
           
 void setFileMustExist(boolean mustexist)
           
 void setForceLocal(Collection<String> local)
           
 void setParent(Processor processor)
           
 void setPedantic(boolean pedantic)
           
 void setProperties(File propertiesFile)
          Set the properties by file.
 void setProperties(File propertiesFile, File base)
           
 void setProperties(Properties properties)
           
 void setProperty(String key, String value)
          Add or override a new property.
 void setTrace(boolean x)
           
protected  void setTypeSpecificPlugins(Set<Object> list)
           
 void signal()
           
static Collection<String> split(String s)
           
static void split(String s, Collection<String> set)
           
static Collection<String> split(String s, String splitter)
           
 void trace(String msg, Object... parms)
           
 void unsetProperty(String string)
           
 boolean updateModified(long time, String reason)
           
 void warning(String string, Object... args)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LIST_SPLITTER

public static String LIST_SPLITTER
Constructor Detail

Processor

public Processor()

Processor

public Processor(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,
                    String prefix)

getInfo

public void getInfo(Processor processor)

warning

public void warning(String string,
                    Object... args)
Specified by:
warning in interface Reporter

error

public void error(String string,
                  Object... args)
Specified by:
error in interface Reporter

error

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

signal

public void signal()

getWarnings

public List<String> getWarnings()
Specified by:
getWarnings in interface Reporter

getErrors

public List<String> getErrors()
Specified by:
getErrors in interface Reporter

parseHeader

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

parseHeader

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

Parameters:
value -
Returns:

addClose

public void addClose(Closeable jar)

progress

public void progress(String s,
                     Object... args)
Specified by:
progress in interface Reporter

isPedantic

public boolean isPedantic()
Specified by:
isPedantic in interface Reporter

setPedantic

public void setPedantic(boolean pedantic)

getFile

public static File getFile(File base,
                           String file)

getFile

public File getFile(String file)

getPlugins

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

Specified by:
getPlugins in interface Registry
Parameters:
clazz - Each returned plugin implements this class/interface
Returns:
A list of plugins

getPlugin

public <T> T getPlugin(Class<T> clazz)
Returns the first plugin it can find of the given type.

Specified by:
getPlugin in interface Registry
Type Parameters:
T -
Parameters:
clazz -
Returns:

getPlugins

protected Set<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:

loadPlugins

protected void loadPlugins(Set<Object> list,
                           String spe)
Parameters:
list -
spe -

setTypeSpecificPlugins

protected void setTypeSpecificPlugins(Set<Object> list)

customize

protected <T> T customize(T plugin,
                          Map<String,String> map)
Parameters:
plugin -
entry -

isFailOk

public boolean isFailOk()

getBase

public File getBase()

setBase

public void setBase(File base)

clear

public void clear()

trace

public void trace(String msg,
                  Object... parms)
Specified by:
trace in interface Reporter

newList

public <T> List<T> newList()

newSet

public <T> Set<T> newSet()

newMap

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

newHashMap

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

newList

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

newSet

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

newMap

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

close

public void close()
Specified by:
close in interface Closeable

_basedir

public String _basedir(String[] args)

getProperties

public Properties getProperties()
Property handling ...

Returns:

getProperty

public String getProperty(String key)

mergeProperties

public void mergeProperties(File file,
                            boolean override)

mergeProperties

public void mergeProperties(Properties properties,
                            boolean override)

setProperties

public void setProperties(Properties properties)

addProperties

public void addProperties(File file)
                   throws Exception
Throws:
Exception

addIncluded

public void addIncluded(File file)

doIncludeFile

public void doIncludeFile(File file,
                          boolean overwrite,
                          Properties target)
                   throws Exception
Parameters:
file -
parent -
done -
overwrite -
Throws:
FileNotFoundException
IOException
Exception

unsetProperty

public void unsetProperty(String string)

refresh

public boolean refresh()

forceRefresh

public void forceRefresh()

propertiesChanged

public void propertiesChanged()

setProperties

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

setProperties

public void setProperties(File propertiesFile,
                          File base)

begin

protected void begin()

isTrue

public static boolean isTrue(String value)

getProperty

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

Parameters:
headerName -
deflt -
Returns:

loadProperties

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

Parameters:
file -
Returns:
Throws:
IOException

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


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

printClauses

public static String printClauses(Map<String,Map<String,String>> exports)
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,
                                  boolean checkMultipleVersions)

printClause

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

getReplacer

public Macro getReplacer()

getMacroDomains

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

Returns:

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:

updateModified

public boolean updateModified(long time,
                              String reason)

lastModified

public long lastModified()

setProperty

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

Parameters:
key -
value -

getManifestAsProperties

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

Parameters:
in -
Returns:
Throws:
IOException

getPropertiesFile

public File getPropertiesFile()

setFileMustExist

public void setFileMustExist(boolean mustexist)

read

public static String read(InputStream in)
                   throws Exception
Throws:
Exception

join

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

Parameters:
args -
Returns:

join

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

join

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

join

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

join

public static <T> String join(T[] list)

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)

merge

public static String merge(String... strings)

isExceptions

public boolean isExceptions()

setExceptions

public void setExceptions(boolean exceptions)

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)

removeDuplicateMarker

public static String removeDuplicateMarker(String key)

isDuplicate

public static boolean isDuplicate(String name)

setTrace

public void setTrace(boolean x)

exists

public boolean exists()

isOk

public boolean isOk()

isPerfect

public boolean isPerfect()

setForceLocal

public void setForceLocal(Collection<String> local)

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:

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"
  
 @param prefix
 @param suffix
 @return


doAttrbutes

public static Map<String,String> doAttrbutes(Object[] attrs,
                                             Clazz clazz,
                                             Macro macro)
Parse the a=b strings and return a map of them.

Parameters:
attrs -
clazz -
Returns:

formatArrays

public static String formatArrays(String string,
                                  Object... parms)
This method is the same as String.format but it makes sure that any arrays are transformed to strings.

Parameters:
string -
parms -
Returns:

makePrintable

public static Object makePrintable(Object object)
Check if the object is an array and turn it into a string if it is, otherwise unchanged.

Parameters:
object - the object to make printable
Returns:
a string if it was an array or the original object

append

public static String append(String... strings)

getClass

public Class<?> getClass(String type,
                         File jar)
                  throws Exception
Throws:
Exception

isTrace

public boolean isTrace()

getDuration

public static long getDuration(String tm,
                               long dflt)

_random

public String _random(String[] args)
Generate a random string, which is guaranteed to be a valid Java identifier (first character is an ASCII letter, subsequent characters are ASCII letters or numbers). Takes an optional parameter for the length of string to generate; default is 8 characters.


beginHandleErrors

protected Processor beginHandleErrors(String message)
Set the current command thread. This must be balanced with the #end(Processor) method. The method returns the previous command owner or null. The command owner will receive all warnings and error reports.


endHandleErrors

protected void endHandleErrors(Processor previous)
End a command. Will restore the previous command owner.

Parameters:
previous -

getExecutor

public static Executor getExecutor()

addBasicPlugin

public void addBasicPlugin(Object plugin)
These plugins are added to the total list of plugins. The separation is necessary because the list of plugins is refreshed now and then so we need to be able to add them at any moment in time.

Parameters:
plugin -

removeBasicPlugin

public void removeBasicPlugin(Object plugin)


Copyright © 2012 aQute SARL. All Rights Reserved.