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/lib/spring/JPAComponent.java b/bundleplugin/src/main/java/aQute/lib/spring/JPAComponent.java
index d9c60cd..4fcbc34 100644
--- a/bundleplugin/src/main/java/aQute/lib/spring/JPAComponent.java
+++ b/bundleplugin/src/main/java/aQute/lib/spring/JPAComponent.java
@@ -6,19 +6,17 @@
/**
* This component is called when we find a resource in the META-INF/*.xml
- * pattern. We parse the resource and and the imports to the builder.
- *
- * Parsing is done with XSLT (first time I see the use of having XML for the
- * Spring configuration files!).
+ * pattern. We parse the resource and and the imports to the builder. Parsing is
+ * done with XSLT (first time I see the use of having XML for the Spring
+ * configuration files!).
*
* @author aqute
- *
*/
public class JPAComponent extends XMLTypeProcessor {
-
- protected List<XMLType> getTypes(Analyzer analyzer) throws Exception {
- List<XMLType> types = new ArrayList<XMLType>();
- process(types,"jpa.xsl", "META-INF", "persistence.xml");
- return types;
- }
+
+ protected List<XMLType> getTypes(Analyzer analyzer) throws Exception {
+ List<XMLType> types = new ArrayList<XMLType>();
+ process(types, "jpa.xsl", "META-INF", "persistence.xml");
+ return types;
+ }
}
diff --git a/bundleplugin/src/main/java/aQute/lib/spring/SpringComponent.java b/bundleplugin/src/main/java/aQute/lib/spring/SpringComponent.java
index 0109ad4..c8678a8 100644
--- a/bundleplugin/src/main/java/aQute/lib/spring/SpringComponent.java
+++ b/bundleplugin/src/main/java/aQute/lib/spring/SpringComponent.java
@@ -15,24 +15,21 @@
/**
* This component is called when we find a resource in the META-INF/*.xml
- * pattern. We parse the resource and and the imports to the builder.
- *
- * Parsing is done with XSLT (first time I see the use of having XML for the
- * Spring configuration files!).
+ * pattern. We parse the resource and and the imports to the builder. Parsing is
+ * done with XSLT (first time I see the use of having XML for the Spring
+ * configuration files!).
*
* @author aqute
- *
*/
public class SpringComponent implements AnalyzerPlugin {
- static Transformer transformer;
- static Pattern SPRING_SOURCE = Pattern.compile("META-INF/spring/.*\\.xml");
- static Pattern QN = Pattern.compile("[_A-Za-z$][_A-Za-z0-9$]*(\\.[_A-Za-z$][_A-Za-z0-9$]*)*");
+ static Transformer transformer;
+ static Pattern SPRING_SOURCE = Pattern.compile("META-INF/spring/.*\\.xml");
+ static Pattern QN = Pattern.compile("[_A-Za-z$][_A-Za-z0-9$]*(\\.[_A-Za-z$][_A-Za-z0-9$]*)*");
public static Set<CharSequence> analyze(InputStream in) throws Exception {
if (transformer == null) {
TransformerFactory tf = TransformerFactory.newInstance();
- Source source = new StreamSource(SpringComponent.class
- .getResourceAsStream("extract.xsl"));
+ Source source = new StreamSource(SpringComponent.class.getResourceAsStream("extract.xsl"));
transformer = tf.newTransformer(source);
}
@@ -66,30 +63,32 @@
return refers;
}
- public boolean analyzeJar(Analyzer analyzer) throws Exception {
- Jar jar = analyzer.getJar();
- Map<String, Resource> dir = jar.getDirectories().get("META-INF/spring");
- if ( dir == null || dir.isEmpty())
+ public boolean analyzeJar(Analyzer analyzer) throws Exception {
+ Jar jar = analyzer.getJar();
+ Map<String,Resource> dir = jar.getDirectories().get("META-INF/spring");
+ if (dir == null || dir.isEmpty())
return false;
-
- for (Iterator<Entry<String, Resource>> i = dir.entrySet().iterator(); i.hasNext();) {
- Entry<String, Resource> entry = i.next();
+
+ for (Iterator<Entry<String,Resource>> i = dir.entrySet().iterator(); i.hasNext();) {
+ Entry<String,Resource> entry = i.next();
String path = entry.getKey();
Resource resource = entry.getValue();
if (SPRING_SOURCE.matcher(path).matches()) {
try {
- InputStream in = resource.openInputStream();
- Set<CharSequence> set = analyze(in);
- in.close();
- for (Iterator<CharSequence> r = set.iterator(); r.hasNext();) {
- PackageRef pack = analyzer.getPackageRef((String) r.next());
- if ( !QN.matcher(pack.getFQN()).matches())
- analyzer.warning("Package does not seem a package in spring resource ("+path+"): " + pack );
- if (!analyzer.getReferred().containsKey(pack))
- analyzer.getReferred().put(pack, new Attrs());
+ InputStream in = resource.openInputStream();
+ Set<CharSequence> set = analyze(in);
+ in.close();
+ for (Iterator<CharSequence> r = set.iterator(); r.hasNext();) {
+ PackageRef pack = analyzer.getPackageRef((String) r.next());
+ if (!QN.matcher(pack.getFQN()).matches())
+ analyzer.warning("Package does not seem a package in spring resource (" + path + "): "
+ + pack);
+ if (!analyzer.getReferred().containsKey(pack))
+ analyzer.getReferred().put(pack, new Attrs());
+ }
}
- } catch( Exception e ) {
- analyzer.error("Unexpected exception in processing spring resources("+path+"): " + e );
+ catch (Exception e) {
+ analyzer.error("Unexpected exception in processing spring resources(" + path + "): " + e);
}
}
}
diff --git a/bundleplugin/src/main/java/aQute/lib/spring/SpringXMLType.java b/bundleplugin/src/main/java/aQute/lib/spring/SpringXMLType.java
index 60eb922..b4840d0 100644
--- a/bundleplugin/src/main/java/aQute/lib/spring/SpringXMLType.java
+++ b/bundleplugin/src/main/java/aQute/lib/spring/SpringXMLType.java
@@ -6,28 +6,23 @@
/**
* This component is called when we find a resource in the META-INF/*.xml
- * pattern. We parse the resource and and the imports to the builder.
- *
- * Parsing is done with XSLT (first time I see the use of having XML for the
- * Spring configuration files!).
+ * pattern. We parse the resource and and the imports to the builder. Parsing is
+ * done with XSLT (first time I see the use of having XML for the Spring
+ * configuration files!).
*
* @author aqute
- *
*/
public class SpringXMLType extends XMLTypeProcessor {
- protected List<XMLType> getTypes(Analyzer analyzer) throws Exception {
- List<XMLType> types = new ArrayList<XMLType>();
-
- String header = analyzer.getProperty("Bundle-Blueprint", "OSGI-INF/blueprint");
- process(types,"extract.xsl", header, ".*\\.xml");
- header = analyzer.getProperty("Spring-Context", "META-INF/spring");
- process(types,"extract.xsl", header, ".*\\.xml");
-
- return types;
- }
+ protected List<XMLType> getTypes(Analyzer analyzer) throws Exception {
+ List<XMLType> types = new ArrayList<XMLType>();
-
+ String header = analyzer.getProperty("Bundle-Blueprint", "OSGI-INF/blueprint");
+ process(types, "extract.xsl", header, ".*\\.xml");
+ header = analyzer.getProperty("Spring-Context", "META-INF/spring");
+ process(types, "extract.xsl", header, ".*\\.xml");
+ return types;
+ }
}
diff --git a/bundleplugin/src/main/java/aQute/lib/spring/XMLType.java b/bundleplugin/src/main/java/aQute/lib/spring/XMLType.java
index f7c6b33..7d65d1c 100644
--- a/bundleplugin/src/main/java/aQute/lib/spring/XMLType.java
+++ b/bundleplugin/src/main/java/aQute/lib/spring/XMLType.java
@@ -12,97 +12,92 @@
import aQute.lib.osgi.Descriptors.PackageRef;
public class XMLType {
-
- Transformer transformer;
- Pattern paths;
- String root;
-
-
- static Pattern QN = Pattern
- .compile("[_A-Za-z$][_A-Za-z0-9$]*(\\.[_A-Za-z$][_A-Za-z0-9$]*)*");
- public XMLType(URL source, String root, String paths ) throws Exception {
- transformer = getTransformer(source);
- this.paths = Pattern.compile(paths);
- this.root = root;
- }
-
- public Set<String> analyze(InputStream in) throws Exception {
- Set<String> refers = new HashSet<String>();
+ Transformer transformer;
+ Pattern paths;
+ String root;
- ByteArrayOutputStream bout = new ByteArrayOutputStream();
- Result r = new StreamResult(bout);
- Source s = new StreamSource(in);
- transformer.transform(s, r);
+ static Pattern QN = Pattern.compile("[_A-Za-z$][_A-Za-z0-9$]*(\\.[_A-Za-z$][_A-Za-z0-9$]*)*");
- ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
- bout.close();
+ public XMLType(URL source, String root, String paths) throws Exception {
+ transformer = getTransformer(source);
+ this.paths = Pattern.compile(paths);
+ this.root = root;
+ }
- BufferedReader br = new BufferedReader(new InputStreamReader(bin, "UTF8"));
+ public Set<String> analyze(InputStream in) throws Exception {
+ Set<String> refers = new HashSet<String>();
- String line = br.readLine();
- while (line != null) {
- line = line.trim();
- if (line.length() > 0) {
- String parts[] = line.split("\\s*,\\s*");
- for (int i = 0; i < parts.length; i++) {
- int n = parts[i].lastIndexOf('.');
- if (n > 0) {
- refers.add(parts[i].subSequence(0, n).toString());
- }
- }
- }
- line = br.readLine();
- }
- br.close();
- return refers;
- }
+ ByteArrayOutputStream bout = new ByteArrayOutputStream();
+ Result r = new StreamResult(bout);
+ Source s = new StreamSource(in);
+ transformer.transform(s, r);
- public boolean analyzeJar(Analyzer analyzer) throws Exception {
- Jar jar = analyzer.getJar();
- Map<String,Resource> dir = jar.getDirectories().get(root);
- if (dir == null || dir.isEmpty()) {
- Resource resource = jar.getResource(root);
- if ( resource != null )
- process(analyzer, root, resource);
- return false;
- }
+ ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
+ bout.close();
- for (Iterator<Map.Entry<String,Resource>> i = dir.entrySet().iterator(); i.hasNext();) {
- Map.Entry<String,Resource> entry = i.next();
- String path = entry.getKey();
- Resource resource = entry.getValue();
- if (paths.matcher(path).matches()) {
- process(analyzer, path, resource);
- }
- }
- return false;
- }
+ BufferedReader br = new BufferedReader(new InputStreamReader(bin, "UTF8"));
- private void process(Analyzer analyzer, String path, Resource resource) {
- try {
- InputStream in = resource.openInputStream();
- Set<String> set = analyze(in);
- in.close();
- for (Iterator<String> r = set.iterator(); r.hasNext();) {
- PackageRef pack = analyzer.getPackageRef(r.next());
- if (!QN.matcher(pack.getFQN()).matches())
- analyzer
- .warning("Package does not seem a package in spring resource ("
- + path + "): " + pack);
- if (!analyzer.getReferred().containsKey(pack))
- analyzer.getReferred().put(pack);
- }
- } catch (Exception e) {
- analyzer
- .error("Unexpected exception in processing spring resources("
- + path + "): " + e);
- }
- }
+ String line = br.readLine();
+ while (line != null) {
+ line = line.trim();
+ if (line.length() > 0) {
+ String parts[] = line.split("\\s*,\\s*");
+ for (int i = 0; i < parts.length; i++) {
+ int n = parts[i].lastIndexOf('.');
+ if (n > 0) {
+ refers.add(parts[i].subSequence(0, n).toString());
+ }
+ }
+ }
+ line = br.readLine();
+ }
+ br.close();
+ return refers;
+ }
- protected Transformer getTransformer(java.net.URL url) throws Exception {
- TransformerFactory tf = TransformerFactory.newInstance();
- Source source = new StreamSource(url.openStream());
- return tf.newTransformer(source);
- }
+ public boolean analyzeJar(Analyzer analyzer) throws Exception {
+ Jar jar = analyzer.getJar();
+ Map<String,Resource> dir = jar.getDirectories().get(root);
+ if (dir == null || dir.isEmpty()) {
+ Resource resource = jar.getResource(root);
+ if (resource != null)
+ process(analyzer, root, resource);
+ return false;
+ }
+
+ for (Iterator<Map.Entry<String,Resource>> i = dir.entrySet().iterator(); i.hasNext();) {
+ Map.Entry<String,Resource> entry = i.next();
+ String path = entry.getKey();
+ Resource resource = entry.getValue();
+ if (paths.matcher(path).matches()) {
+ process(analyzer, path, resource);
+ }
+ }
+ return false;
+ }
+
+ private void process(Analyzer analyzer, String path, Resource resource) {
+ try {
+ InputStream in = resource.openInputStream();
+ Set<String> set = analyze(in);
+ in.close();
+ for (Iterator<String> r = set.iterator(); r.hasNext();) {
+ PackageRef pack = analyzer.getPackageRef(r.next());
+ if (!QN.matcher(pack.getFQN()).matches())
+ analyzer.warning("Package does not seem a package in spring resource (" + path + "): " + pack);
+ if (!analyzer.getReferred().containsKey(pack))
+ analyzer.getReferred().put(pack);
+ }
+ }
+ catch (Exception e) {
+ analyzer.error("Unexpected exception in processing spring resources(" + path + "): " + e);
+ }
+ }
+
+ protected Transformer getTransformer(java.net.URL url) throws Exception {
+ TransformerFactory tf = TransformerFactory.newInstance();
+ Source source = new StreamSource(url.openStream());
+ return tf.newTransformer(source);
+ }
}
diff --git a/bundleplugin/src/main/java/aQute/lib/spring/XMLTypeProcessor.java b/bundleplugin/src/main/java/aQute/lib/spring/XMLTypeProcessor.java
index 6ae0e7e..64abf3c 100644
--- a/bundleplugin/src/main/java/aQute/lib/spring/XMLTypeProcessor.java
+++ b/bundleplugin/src/main/java/aQute/lib/spring/XMLTypeProcessor.java
@@ -7,28 +7,25 @@
import aQute.libg.header.*;
public class XMLTypeProcessor implements AnalyzerPlugin {
-
- public boolean analyzeJar(Analyzer analyzer) throws Exception {
- List<XMLType> types = getTypes(analyzer);
- for ( XMLType type : types ) {
- type.analyzeJar(analyzer);
- }
- return false;
- }
-
- protected List<XMLType> getTypes(Analyzer analyzer) throws Exception {
- return new ArrayList<XMLType>();
- }
+ public boolean analyzeJar(Analyzer analyzer) throws Exception {
+ List<XMLType> types = getTypes(analyzer);
+ for (XMLType type : types) {
+ type.analyzeJar(analyzer);
+ }
+ return false;
+ }
- protected void process(List<XMLType> types, String resource, String paths,
- String pattern) throws Exception {
-
- Parameters map = Processor.parseHeader(paths,null);
- for ( String path : map.keySet() ) {
- types.add( new XMLType( getClass().getResource(resource), path, pattern ));
- }
- }
+ protected List<XMLType> getTypes(Analyzer analyzer) throws Exception {
+ return new ArrayList<XMLType>();
+ }
+ protected void process(List<XMLType> types, String resource, String paths, String pattern) throws Exception {
+
+ Parameters map = Processor.parseHeader(paths, null);
+ for (String path : map.keySet()) {
+ types.add(new XMLType(getClass().getResource(resource), path, pattern));
+ }
+ }
}