Search in sources :

Example 1 with PathElement

use of org.apache.aries.blueprint.utils.HeaderParser.PathElement in project aries by apache.

the class SpringOsgiExtender method getSpringPaths.

private List<URL> getSpringPaths(Bundle bundle) throws Exception {
    LOGGER.debug("Scanning bundle {}/{} for spring application", bundle.getSymbolicName(), bundle.getVersion());
    List<URL> pathList = new ArrayList<URL>();
    String springHeader = bundle.getHeaders().get(SPRING_CONTEXT_HEADER);
    if (springHeader == null) {
        springHeader = "*";
    }
    List<PathElement> paths = HeaderParser.parseHeader(springHeader);
    for (PathElement path : paths) {
        String name = path.getName();
        if ("*".equals(name)) {
            name = "META-INF/spring/*.xml";
        }
        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);
        }
        if (filePattern.contains("*")) {
            Enumeration<URL> e = bundle.findEntries(baseName, filePattern, false);
            while (e != null && e.hasMoreElements()) {
                pathList.add(e.nextElement());
            }
        } else {
            pathList.add(bundle.getEntry(name));
        }
    }
    if (!pathList.isEmpty()) {
        LOGGER.debug("Found spring 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());
    }
    return null;
}
Also used : PathElement(org.apache.aries.blueprint.utils.HeaderParser.PathElement) ArrayList(java.util.ArrayList) URL(java.net.URL)

Example 2 with PathElement

use of org.apache.aries.blueprint.utils.HeaderParser.PathElement 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)

Example 3 with PathElement

use of org.apache.aries.blueprint.utils.HeaderParser.PathElement in project aries by apache.

the class BlueprintContainerImpl method readDirectives.

private void readDirectives() {
    Dictionary headers = bundle.getHeaders();
    String symbolicName = (String) headers.get(Constants.BUNDLE_SYMBOLICNAME);
    List<PathElement> paths = HeaderParser.parseHeader(symbolicName);
    String timeoutDirective = paths.get(0).getDirective(BlueprintConstants.TIMEOUT_DIRECTIVE);
    if (timeoutDirective != null) {
        LOGGER.debug("Timeout directive: {}", timeoutDirective);
        timeout = Integer.parseInt(timeoutDirective);
    }
    String graceperiod = paths.get(0).getDirective(BlueprintConstants.GRACE_PERIOD);
    if (graceperiod != null) {
        LOGGER.debug("Grace-period directive: {}", graceperiod);
        waitForDependencies = Boolean.parseBoolean(graceperiod);
    }
    xmlValidation = paths.get(0).getDirective(BlueprintConstants.XML_VALIDATION);
    // enabled if null or "true"; structure-only if "structure"; disabled otherwise
    LOGGER.debug("Xml-validation directive: {}", xmlValidation);
}
Also used : Dictionary(java.util.Dictionary) PathElement(org.apache.aries.blueprint.utils.HeaderParser.PathElement)

Aggregations

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