Latest bnd code
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1350613 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/bundleplugin/src/main/java/aQute/bnd/component/AnnotationReader.java b/bundleplugin/src/main/java/aQute/bnd/component/AnnotationReader.java
index 35cec3f..d0b915c 100644
--- a/bundleplugin/src/main/java/aQute/bnd/component/AnnotationReader.java
+++ b/bundleplugin/src/main/java/aQute/bnd/component/AnnotationReader.java
@@ -47,7 +47,7 @@
MethodDef method;
TypeRef className;
Analyzer analyzer;
- MultiMap<String, String> methods = new MultiMap<String, String>();
+ MultiMap<String,String> methods = new MultiMap<String,String>();
TypeRef extendsClass;
boolean inherit;
boolean baseclass = true;
@@ -77,29 +77,26 @@
Clazz ec = analyzer.findClass(extendsClass);
if (ec == null) {
- analyzer.error("Missing super class for DS annotations: " + extendsClass
- + " from " + clazz.getClassName());
+ analyzer.error("Missing super class for DS annotations: " + extendsClass + " from "
+ + clazz.getClassName());
} else {
ec.parseClassFileWithCollector(this);
}
}
}
for (ReferenceDef rdef : component.references.values()) {
- rdef.unbind = referredMethod(analyzer, rdef, rdef.unbind, "add(.*)", "remove$1",
- "(.*)", "un$1");
- rdef.updated = referredMethod(analyzer, rdef, rdef.updated, "(add|set|bind)(.*)",
- "updated$2", "(.*)", "updated$1");
+ rdef.unbind = referredMethod(analyzer, rdef, rdef.unbind, "add(.*)", "remove$1", "(.*)", "un$1");
+ rdef.updated = referredMethod(analyzer, rdef, rdef.updated, "(add|set|bind)(.*)", "updated$2", "(.*)",
+ "updated$1");
}
return component;
}
/**
- *
* @param analyzer
* @param rdef
*/
- protected String referredMethod(Analyzer analyzer, ReferenceDef rdef, String value,
- String... matches) {
+ protected String referredMethod(Analyzer analyzer, ReferenceDef rdef, String value, String... matches) {
if (value == null) {
String bind = rdef.bind;
for (int i = 0; i < matches.length; i += 2) {
@@ -117,8 +114,7 @@
Matcher matcher = BINDDESCRIPTOR.matcher(descriptor);
if (matcher.matches()) {
String type = matcher.group(2);
- if (rdef.service.equals(Clazz.objectDescriptorToFQN(type))
- || type.equals("Ljava/util/Map;")
+ if (rdef.service.equals(Clazz.objectDescriptorToFQN(type)) || type.equals("Ljava/util/Map;")
|| type.equals("Lorg/osgi/framework/ServiceReference;")) {
return value;
@@ -145,7 +141,8 @@
doModified();
else if (a instanceof Reference)
doReference((Reference) a, annotation);
- } catch (Exception e) {
+ }
+ catch (Exception e) {
e.printStackTrace();
analyzer.error("During generation of a component on class %s, exception %s", clazz, e);
}
@@ -187,7 +184,7 @@
if (def.name == null) {
Matcher m = BINDNAME.matcher(method.getName());
- if ( m.matches() )
+ if (m.matches())
def.name = m.group(2);
else
analyzer.error("Invalid name for bind method %s", method.getName());
@@ -315,8 +312,7 @@
String value = m.group(4);
component.property.add(key, value);
} else
- throw new IllegalArgumentException("Malformed property '" + p
- + "' on component: " + className);
+ throw new IllegalArgumentException("Malformed property '" + p + "' on component: " + className);
}
}
}
@@ -325,15 +321,18 @@
* Are called during class parsing
*/
- @Override public void classBegin(int access, TypeRef name) {
+ @Override
+ public void classBegin(int access, TypeRef name) {
className = name;
}
- @Override public void implementsInterfaces(TypeRef[] interfaces) {
+ @Override
+ public void implementsInterfaces(TypeRef[] interfaces) {
this.interfaces = interfaces;
}
- @Override public void method(Clazz.MethodDef method) {
+ @Override
+ public void method(Clazz.MethodDef method) {
int access = method.getAccess();
if (Modifier.isAbstract(access) || Modifier.isStatic(access))
@@ -346,7 +345,8 @@
methods.add(method.getName(), method.getDescriptor().toString());
}
- @Override public void extendsClass(TypeRef name) {
+ @Override
+ public void extendsClass(TypeRef name) {
this.extendsClass = name;
}
diff --git a/bundleplugin/src/main/java/aQute/bnd/component/ComponentDef.java b/bundleplugin/src/main/java/aQute/bnd/component/ComponentDef.java
index 75b7b73..edcd909 100644
--- a/bundleplugin/src/main/java/aQute/bnd/component/ComponentDef.java
+++ b/bundleplugin/src/main/java/aQute/bnd/component/ComponentDef.java
@@ -21,8 +21,8 @@
class ComponentDef {
final static String NAMESPACE_STEM = "http://www.osgi.org/xmlns/scr";
final List<String> properties = new ArrayList<String>();
- final MultiMap<String, String> property = new MultiMap<String, String>();
- final Map<String, ReferenceDef> references = new TreeMap<String, ReferenceDef>();
+ final MultiMap<String,String> property = new MultiMap<String,String>();
+ final Map<String,ReferenceDef> references = new TreeMap<String,ReferenceDef>();
Version version = AnnotationReader.V1_1;
String name;
@@ -75,7 +75,7 @@
if (configurationPid != null)
version = ReferenceDef.max(version, AnnotationReader.V1_2);
- for (Map.Entry<String, List<String>> kvs : property.entrySet()) {
+ for (Map.Entry<String,List<String>> kvs : property.entrySet()) {
Tag property = new Tag("property");
String name = kvs.getKey();
String type = null;
@@ -127,8 +127,7 @@
component.addAttribute("servicefactory", servicefactory);
if (configurationPolicy != null)
- component.addAttribute("configuration-policy", configurationPolicy.toString()
- .toLowerCase());
+ component.addAttribute("configuration-policy", configurationPolicy.toString().toLowerCase());
if (enabled != null)
component.addAttribute("enabled", enabled);
@@ -185,7 +184,7 @@
return v;
try {
- Class<?> c = Class.forName("java.lang." + type);
+ Class< ? > c = Class.forName("java.lang." + type);
if (c == String.class)
return v;
@@ -194,13 +193,17 @@
c = Integer.class;
Method m = c.getMethod("valueOf", String.class);
m.invoke(null, v);
- } catch (ClassNotFoundException e) {
+ }
+ catch (ClassNotFoundException e) {
analyzer.error("Invalid data type %s", type);
- } catch (NoSuchMethodException e) {
+ }
+ catch (NoSuchMethodException e) {
analyzer.error("Cannot convert data %s to type %s", v, type);
- } catch (NumberFormatException e) {
+ }
+ catch (NumberFormatException e) {
analyzer.error("Not a valid number %s for %s, %s", v, type, e.getMessage());
- } catch (Exception e) {
+ }
+ catch (Exception e) {
analyzer.error("Cannot convert data %s to type %s", v, type);
}
return v;
diff --git a/bundleplugin/src/main/java/aQute/bnd/component/DSAnnotations.java b/bundleplugin/src/main/java/aQute/bnd/component/DSAnnotations.java
index 90a20af..0fd4011 100644
--- a/bundleplugin/src/main/java/aQute/bnd/component/DSAnnotations.java
+++ b/bundleplugin/src/main/java/aQute/bnd/component/DSAnnotations.java
@@ -8,23 +8,21 @@
/**
* Analyze the class space for any classes that have an OSGi annotation for DS.
- *
*/
public class DSAnnotations implements AnalyzerPlugin {
public boolean analyzeJar(Analyzer analyzer) throws Exception {
- Parameters header = OSGiHeader.parseHeader(analyzer
- .getProperty(Constants.DSANNOTATIONS));
- if ( header.size()==0)
+ Parameters header = OSGiHeader.parseHeader(analyzer.getProperty(Constants.DSANNOTATIONS));
+ if (header.size() == 0)
return false;
-
+
Instructions instructions = new Instructions(header);
Set<Clazz> list = new HashSet<Clazz>(analyzer.getClassspace().values());
String sc = analyzer.getProperty(Constants.SERVICE_COMPONENT);
List<String> names = new ArrayList<String>();
- if ( sc != null && sc.trim().length() > 0)
+ if (sc != null && sc.trim().length() > 0)
names.add(sc);
-
+
for (Iterator<Clazz> i = list.iterator(); i.hasNext();) {
for (Instruction instruction : instructions.keySet()) {
Clazz c = i.next();
@@ -38,8 +36,7 @@
definition.prepare(analyzer);
String name = "OSGI-INF/" + definition.name + ".xml";
names.add(name);
- analyzer.getJar().putResource(name,
- new TagResource(definition.getTag()));
+ analyzer.getJar().putResource(name, new TagResource(definition.getTag()));
}
}
}
diff --git a/bundleplugin/src/main/java/aQute/bnd/component/ReferenceDef.java b/bundleplugin/src/main/java/aQute/bnd/component/ReferenceDef.java
index 162bdb4..7dfc8b0 100644
--- a/bundleplugin/src/main/java/aQute/bnd/component/ReferenceDef.java
+++ b/bundleplugin/src/main/java/aQute/bnd/component/ReferenceDef.java
@@ -11,7 +11,7 @@
*/
class ReferenceDef {
- Version version = AnnotationReader.V1_1;
+ Version version = AnnotationReader.V1_1;
String name;
String service;
ReferenceCardinality cardinality;
@@ -25,25 +25,26 @@
/**
* Prepare the reference, will check for any errors.
*
- * @param analyzer the analyzer to report errors to.
- * @throws Exception
+ * @param analyzer
+ * the analyzer to report errors to.
+ * @throws Exception
*/
public void prepare(Analyzer analyzer) throws Exception {
if (name == null)
analyzer.error("No name for a reference");
-
- if ((updated != null && !updated.equals("-")) || policyOption!= null)
+
+ if ((updated != null && !updated.equals("-")) || policyOption != null)
version = max(version, AnnotationReader.V1_2);
if (target != null) {
String error = Verifier.validateFilter(target);
- if ( error != null)
+ if (error != null)
analyzer.error("Invalid target filter %s for %s", target, name);
}
- if ( service == null)
+ if (service == null)
analyzer.error("No interface specified on %s", name);
-
+
}
/**
@@ -71,12 +72,12 @@
if (unbind != null && !"-".equals(unbind))
ref.addAttribute("unbind", unbind);
- if (updated != null && !"-".equals(updated))
+ if (updated != null && !"-".equals(updated))
ref.addAttribute("updated", updated);
- if ( policyOption != null)
+ if (policyOption != null)
ref.addAttribute("policy-option", policyOption.toString());
-
+
return ref;
}