use of org.osgi.service.indexer.impl.util.AddOnlyList in project bnd by bndtools.
the class RepoIndex method generateResource.
private Tag generateResource(File file, Map<String, String> config) throws Exception {
JarResource resource = new JarResource(file);
List<Capability> caps = new AddOnlyList<Capability>(new LinkedList<Capability>());
List<Requirement> reqs = new AddOnlyList<Requirement>(new LinkedList<Requirement>());
Tag resourceTag = new Tag(Schema.ELEM_RESOURCE);
try {
// Read config settings and save in thread local state
if (config != null) {
URL rootURL;
String rootURLStr = config.get(ResourceIndexer.ROOT_URL);
if (rootURLStr != null) {
File rootDir = new File(rootURLStr);
if (rootDir.isDirectory())
rootURL = rootDir.toURI().toURL();
else
rootURL = new URL(rootURLStr);
} else
rootURL = new File(System.getProperty("user.dir")).toURI().toURL();
String urlTemplate = config.get(ResourceIndexer.URL_TEMPLATE);
bundleAnalyzer.setStateLocal(new GeneratorState(rootURL.toURI().normalize(), urlTemplate, resolvers));
} else {
bundleAnalyzer.setStateLocal(null);
}
// Iterate over the analyzers
try {
synchronized (analyzers) {
for (Pair<ResourceAnalyzer, Filter> entry : analyzers) {
ResourceAnalyzer analyzer = entry.getFirst();
Filter filter = entry.getSecond();
if (filter == null || filter.match(resource.getProperties())) {
try {
analyzer.analyzeResource(resource, caps, reqs);
} catch (Exception e) {
log(LogService.LOG_ERROR, MessageFormat.format("Error calling analyzer \"{0}\" on resource {1}.", analyzer.getClass().getName(), resource.getLocation()), e);
StringWriter writer = new StringWriter();
Formatter comment = new Formatter(writer);
comment.format("Error calling analyzer \"%s\" on resource %s with message %s and stack: ", analyzer.getClass().getName(), resource.getLocation(), e);
comment.close();
e.printStackTrace(new PrintWriter(writer));
resourceTag.addComment(writer.toString());
}
}
}
}
} finally {
bundleAnalyzer.setStateLocal(null);
}
} finally {
resource.close();
}
for (Capability cap : caps) {
Tag capTag = new Tag(Schema.ELEM_CAPABILITY);
capTag.addAttribute(Schema.ATTR_NAMESPACE, cap.getNamespace());
appendAttributeAndDirectiveTags(capTag, cap.getAttributes(), cap.getDirectives());
resourceTag.addContent(capTag);
}
for (Requirement req : reqs) {
Tag reqTag = new Tag(Schema.ELEM_REQUIREMENT);
reqTag.addAttribute(Schema.ATTR_NAMESPACE, req.getNamespace());
appendAttributeAndDirectiveTags(reqTag, req.getAttributes(), req.getDirectives());
resourceTag.addContent(reqTag);
}
return resourceTag;
}
Aggregations