Search in sources :

Example 1 with BlueprintAnnotationScanner

use of org.apache.aries.blueprint.annotation.service.BlueprintAnnotationScanner in project aries by apache.

the class BlueprintExtender method getBlueprintPaths.

private List<URL> getBlueprintPaths(Bundle bundle) {
    LOGGER.debug("Scanning bundle {}/{} for blueprint application", bundle.getSymbolicName(), bundle.getVersion());
    try {
        List<URL> pathList = new ArrayList<URL>();
        String blueprintHeader = bundle.getHeaders().get(BlueprintConstants.BUNDLE_BLUEPRINT_HEADER);
        String blueprintHeaderAnnotation = bundle.getHeaders().get(BlueprintConstants.BUNDLE_BLUEPRINT_ANNOTATION_HEADER);
        if (blueprintHeader == null) {
            blueprintHeader = "OSGI-INF/blueprint/";
        }
        List<PathElement> paths = HeaderParser.parseHeader(blueprintHeader);
        for (PathElement path : paths) {
            String name = path.getName();
            if (name.endsWith("/")) {
                addEntries(bundle, name, "*.xml", pathList);
            } else {
                String baseName;
                String filePattern;
                int pos = name.lastIndexOf('/');
                if (pos < 0) {
                    baseName = "/";
                    filePattern = name;
                } else {
                    baseName = name.substring(0, pos + 1);
                    filePattern = name.substring(pos + 1);
                }
                addEntries(bundle, baseName, filePattern, pathList);
            }
        }
        // Check annotations
        if (blueprintHeaderAnnotation != null && blueprintHeaderAnnotation.trim().equalsIgnoreCase("true")) {
            LOGGER.debug("Scanning bundle {}/{} for blueprint annotations", bundle.getSymbolicName(), bundle.getVersion());
            ServiceReference sr = this.context.getServiceReference(BlueprintAnnotationScanner.class.getName());
            if (sr != null) {
                BlueprintAnnotationScanner bas = (BlueprintAnnotationScanner) this.context.getService(sr);
                try {
                    // try to generate the blueprint definition XML
                    URL url = bas.createBlueprintModel(bundle);
                    if (url != null) {
                        pathList.add(url);
                    }
                } finally {
                    this.context.ungetService(sr);
                }
            }
        }
        if (!pathList.isEmpty()) {
            LOGGER.debug("Found blueprint application in bundle {}/{} with paths: {}", bundle.getSymbolicName(), bundle.getVersion(), pathList);
            // ServiceReference, or just not do this check, which could be quite harmful.
            if (isCompatible(bundle)) {
                return pathList;
            } else {
                LOGGER.info("Bundle {}/{} is not compatible with this blueprint extender", bundle.getSymbolicName(), bundle.getVersion());
            }
        } else {
            LOGGER.debug("No blueprint application found in bundle {}/{}", bundle.getSymbolicName(), bundle.getVersion());
        }
    } catch (Throwable t) {
        if (!stopping) {
            LOGGER.warn("Error creating blueprint container for bundle {}/{}", bundle.getSymbolicName(), bundle.getVersion(), t);
            eventDispatcher.blueprintEvent(new BlueprintEvent(BlueprintEvent.FAILURE, bundle, context.getBundle(), t));
        }
    }
    return null;
}
Also used : BlueprintAnnotationScanner(org.apache.aries.blueprint.annotation.service.BlueprintAnnotationScanner) PathElement(org.apache.aries.blueprint.utils.HeaderParser.PathElement) ArrayList(java.util.ArrayList) URL(java.net.URL) BlueprintEvent(org.osgi.service.blueprint.container.BlueprintEvent) ServiceReference(org.osgi.framework.ServiceReference)

Aggregations

URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 BlueprintAnnotationScanner (org.apache.aries.blueprint.annotation.service.BlueprintAnnotationScanner)1 PathElement (org.apache.aries.blueprint.utils.HeaderParser.PathElement)1 ServiceReference (org.osgi.framework.ServiceReference)1 BlueprintEvent (org.osgi.service.blueprint.container.BlueprintEvent)1