Search in sources :

Example 1 with ManifestHeader

use of org.apache.sling.commons.osgi.ManifestHeader in project sling by apache.

the class TracerSet method parseTracerConfigs.

private static List<TracerConfig> parseTracerConfigs(String config) {
    ManifestHeader parsedConfig = ManifestHeader.parse(config);
    List<TracerConfig> result = new ArrayList<TracerConfig>(parsedConfig.getEntries().length);
    for (ManifestHeader.Entry e : parsedConfig.getEntries()) {
        String category = e.getValue();
        //Defaults to Debug
        Level level = Level.valueOf(e.getAttributeValue(LEVEL));
        CallerStackReporter reporter = createReporter(e);
        result.add(new TracerConfig(category, level, reporter));
    }
    return Collections.unmodifiableList(result);
}
Also used : ManifestHeader(org.apache.sling.commons.osgi.ManifestHeader) ArrayList(java.util.ArrayList) Level(ch.qos.logback.classic.Level)

Example 2 with ManifestHeader

use of org.apache.sling.commons.osgi.ManifestHeader in project sling by apache.

the class SlingInitialContentMounter method mount.

/**
     * Add configurations to a running OSGi instance for initial content.
     * @param targetUrl The web console base url
     * @param bundleFile The artifact (bundle)
     * @throws MojoExecutionException
     */
public void mount(final String targetUrl, final File bundleFile) throws MojoExecutionException {
    // first, let's get the manifest and see if initial content is configured
    ManifestHeader header = null;
    try {
        final Manifest mf = getManifest(bundleFile);
        final String value = mf.getMainAttributes().getValue(HEADER_INITIAL_CONTENT);
        if (value == null) {
            log.debug("Bundle has no initial content - no file system provider config created.");
            return;
        }
        header = ManifestHeader.parse(value);
        if (header == null || header.getEntries().length == 0) {
            log.warn("Unable to parse header or header is empty: " + value);
            return;
        }
    } catch (IOException ioe) {
        throw new MojoExecutionException("Unable to read manifest from file " + bundleFile, ioe);
    }
    log.info("Trying to configure file system provider...");
    // quick check if resources are configured
    final List resources = project.getResources();
    if (resources == null || resources.size() == 0) {
        throw new MojoExecutionException("No resources configured for this project.");
    }
    final List<FsResourceConfiguration> cfgs = new ArrayList<>();
    final Entry[] entries = header.getEntries();
    for (final Entry entry : entries) {
        String path = entry.getValue();
        if (path != null && !path.endsWith("/")) {
            path += "/";
        }
        // check if we should ignore this
        final String ignoreValue = entry.getDirectiveValue("maven:mount");
        if (ignoreValue != null && ignoreValue.equalsIgnoreCase("false")) {
            log.debug("Ignoring " + path);
            continue;
        }
        String installPath = entry.getDirectiveValue("path");
        if (installPath == null) {
            installPath = "/";
        }
        // search the path in the resources (usually this should be the first resource
        // entry but this might be reconfigured
        File dir = null;
        final Iterator i = resources.iterator();
        while (dir == null && i.hasNext()) {
            final Resource rsrc = (Resource) i.next();
            String child = path;
            // if resource mapping defines a target path: remove target path from checked resource path
            String targetPath = rsrc.getTargetPath();
            if (targetPath != null && !targetPath.endsWith("/")) {
                targetPath = targetPath + "/";
            }
            if (targetPath != null && path.startsWith(targetPath)) {
                child = child.substring(targetPath.length());
            }
            dir = new File(rsrc.getDirectory(), child);
            if (!dir.exists()) {
                dir = null;
            }
        }
        if (dir == null) {
            throw new MojoExecutionException("No resource entry found containing " + path);
        }
        // check for root mapping - which we don't support atm
        if ("/".equals(installPath)) {
            throw new MojoExecutionException("Mapping to root path not supported by fs provider at the moment. Please adapt your initial content configuration.");
        }
        // check further initial content directives
        StringBuilder importOptions = new StringBuilder();
        String overwriteValue = entry.getDirectiveValue("overwrite");
        if (StringUtils.isNotBlank(overwriteValue)) {
            importOptions.append("overwrite:=" + overwriteValue);
        }
        String ignoreImportProvidersValue = entry.getDirectiveValue("ignoreImportProviders");
        if (StringUtils.isNotBlank(overwriteValue)) {
            if (importOptions.length() > 0) {
                importOptions.append(";");
            }
            importOptions.append("ignoreImportProviders:=\"" + ignoreImportProvidersValue + "\"");
        }
        cfgs.add(new FsResourceConfiguration().fsMode(FsMode.INITIAL_CONTENT).contentRootDir(dir.getAbsolutePath()).providerRootPath(installPath).initialContentImportOptions(importOptions.toString()));
    }
    if (!cfgs.isEmpty()) {
        helper.addConfigurations(targetUrl, cfgs);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ManifestHeader(org.apache.sling.commons.osgi.ManifestHeader) ArrayList(java.util.ArrayList) Resource(org.apache.maven.model.Resource) IOException(java.io.IOException) Manifest(java.util.jar.Manifest) Entry(org.apache.sling.commons.osgi.ManifestHeader.Entry) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) JarFile(java.util.jar.JarFile) File(java.io.File)

Example 3 with ManifestHeader

use of org.apache.sling.commons.osgi.ManifestHeader in project sling by apache.

the class BundleResourceProvider method getRoots.

public static MappedPath[] getRoots(final Bundle bundle, final String rootList) {
    List<MappedPath> prefixList = new ArrayList<>();
    final ManifestHeader header = ManifestHeader.parse(rootList);
    for (final ManifestHeader.Entry entry : header.getEntries()) {
        final String resourceRoot = entry.getValue();
        final String pathDirective = entry.getDirectiveValue("path");
        if (pathDirective != null) {
            prefixList.add(new MappedPath(resourceRoot, pathDirective));
        } else {
            prefixList.add(MappedPath.create(resourceRoot));
        }
    }
    return prefixList.toArray(new MappedPath[prefixList.size()]);
}
Also used : ArrayList(java.util.ArrayList) ManifestHeader(org.apache.sling.commons.osgi.ManifestHeader)

Example 4 with ManifestHeader

use of org.apache.sling.commons.osgi.ManifestHeader in project sling by apache.

the class PathEntry method getContentPaths.

public static Iterator<PathEntry> getContentPaths(final Bundle bundle) {
    final List<PathEntry> entries = new ArrayList<PathEntry>();
    String bundleLastModifiedStamp = (String) bundle.getHeaders().get("Bnd-LastModified");
    // time last modified inside the container
    long bundleLastModified = bundle.getLastModified();
    if (bundleLastModifiedStamp != null) {
        bundleLastModified = Math.min(bundleLastModified, Long.parseLong(bundleLastModifiedStamp));
    }
    final String root = (String) bundle.getHeaders().get(CONTENT_HEADER);
    if (root != null) {
        final ManifestHeader header = ManifestHeader.parse(root);
        for (final ManifestHeader.Entry entry : header.getEntries()) {
            entries.add(new PathEntry(entry, bundleLastModified));
        }
    }
    if (entries.size() == 0) {
        return null;
    }
    return entries.iterator();
}
Also used : ArrayList(java.util.ArrayList) ManifestHeader(org.apache.sling.commons.osgi.ManifestHeader)

Aggregations

ArrayList (java.util.ArrayList)4 ManifestHeader (org.apache.sling.commons.osgi.ManifestHeader)4 Level (ch.qos.logback.classic.Level)1 File (java.io.File)1 IOException (java.io.IOException)1 Iterator (java.util.Iterator)1 List (java.util.List)1 JarFile (java.util.jar.JarFile)1 Manifest (java.util.jar.Manifest)1 Resource (org.apache.maven.model.Resource)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 Entry (org.apache.sling.commons.osgi.ManifestHeader.Entry)1