Search in sources :

Example 56 with Parameters

use of aQute.bnd.header.Parameters in project bnd by bndtools.

the class JustAnotherPackageManager method parseCommandData.

public CommandData parseCommandData(ArtifactData artifact) throws Exception {
    File source = new File(artifact.file);
    if (!source.isFile())
        throw new FileNotFoundException();
    CommandData data = new CommandData();
    data.sha = artifact.sha;
    data.jpmRepoDir = repoDir.getCanonicalPath();
    try (JarFile jar = new JarFile(source)) {
        logger.debug("Parsing {}", source);
        Manifest m = jar.getManifest();
        Attributes main = m.getMainAttributes();
        data.name = data.bsn = main.getValue(Constants.BUNDLE_SYMBOLICNAME);
        String version = main.getValue(Constants.BUNDLE_VERSION);
        if (version == null)
            data.version = Version.LOWEST;
        else
            data.version = new Version(version);
        data.main = main.getValue("Main-Class");
        data.description = main.getValue(Constants.BUNDLE_DESCRIPTION);
        data.title = main.getValue("JPM-Name");
        if (main.getValue("Class-Path") != null) {
            File parent = source.getParentFile();
            for (String entry : main.getValue("Class-Path").split("\\s+")) {
                File child = new File(parent, entry);
                if (!child.isFile()) {
                    reporter.error("Target specifies Class-Path in JAR but the indicated file %s is not found", child);
                } else {
                    ArtifactData x = put(child.toURI());
                    data.dependencies.add(x.sha);
                }
            }
        }
        logger.debug("name {} {} {}", data.name, data.main, data.title);
        DependencyCollector path = new DependencyCollector(this);
        path.add(artifact);
        DependencyCollector bundles = new DependencyCollector(this);
        if (main.getValue("JPM-Classpath") != null) {
            Parameters requires = OSGiHeader.parseHeader(main.getValue("JPM-Classpath"));
            for (Map.Entry<String, Attrs> e : requires.entrySet()) {
                // coordinate
                path.add(e.getKey(), e.getValue().get("name"));
            }
        } else if (!artifact.local) {
        // No JPM-Classpath, falling back to
        // server's revision
        // Iterable<RevisionRef> closure =
        // library.getClosure(artifact.sha,
        // false);
        // System.out.println("getting closure " + artifact.url + " " +
        // Strings.join("\n",closure));
        // if (closure != null) {
        // for (RevisionRef ref : closure) {
        // path.add(Hex.toHexString(ref.revision));
        // }
        // }
        }
        if (main.getValue("JPM-Runbundles") != null) {
            Parameters jpmrunbundles = OSGiHeader.parseHeader(main.getValue("JPM-Runbundles"));
            for (Map.Entry<String, Attrs> e : jpmrunbundles.entrySet()) {
                bundles.add(e.getKey(), e.getValue().get("name"));
            }
        }
        logger.debug("collect digests runpath");
        data.dependencies.addAll(path.getDigests());
        logger.debug("collect digests bundles");
        data.runbundles.addAll(bundles.getDigests());
        Parameters command = OSGiHeader.parseHeader(main.getValue("JPM-Command"));
        if (command.size() > 1)
            reporter.error("Only one command can be specified");
        for (Map.Entry<String, Attrs> e : command.entrySet()) {
            data.name = e.getKey();
            Attrs attrs = e.getValue();
            if (attrs.containsKey("jvmargs"))
                data.jvmArgs = attrs.get("jvmargs");
            if (attrs.containsKey("title"))
                data.title = attrs.get("title");
            if (data.title != null)
                data.title = data.name;
        }
        return data;
    }
}
Also used : Parameters(aQute.bnd.header.Parameters) FileNotFoundException(java.io.FileNotFoundException) Attributes(java.util.jar.Attributes) Attrs(aQute.bnd.header.Attrs) JarFile(java.util.jar.JarFile) Manifest(java.util.jar.Manifest) Version(aQute.bnd.version.Version) JarFile(java.util.jar.JarFile) IO.createTempFile(aQute.lib.io.IO.createTempFile) File(java.io.File) Map(java.util.Map) HashMap(java.util.HashMap)

Example 57 with Parameters

use of aQute.bnd.header.Parameters in project bnd by bndtools.

the class Tool method doJavadoc.

public Jar doJavadoc(Map<String, String> options, boolean exportsOnly) throws Exception {
    if (!hasSources())
        return new Jar("javadoc");
    IO.mkdirs(javadoc);
    List<String> args = new ArrayList<>();
    args.add("-quiet");
    args.add("-protected");
    args.add(String.format("%s '%s'", "-d", fileName(javadoc)));
    args.add("-charset 'UTF-8'");
    args.add(String.format("%s '%s'", "-sourcepath", fileName(sources)));
    Properties pp = new UTF8Properties();
    pp.putAll(options);
    String name = manifest.getBundleName();
    if (name == null)
        name = manifest.getBundleSymbolicName().getKey();
    String version = manifest.getBundleVersion();
    if (version == null)
        version = Version.LOWEST.toString();
    String bundleDescription = manifest.getBundleDescription();
    if (bundleDescription != null && !Strings.trim(bundleDescription).isEmpty()) {
        printOverview(name, version, bundleDescription);
    }
    set(pp, "-doctitle", name);
    set(pp, "-windowtitle", name);
    set(pp, "-header", manifest.getBundleVendor());
    set(pp, "-bottom", manifest.getBundleCopyright());
    set(pp, "-footer", manifest.getBundleDocURL());
    args.add("-tag 'Immutable:t:\"Immutable\"'");
    args.add("-tag 'ThreadSafe:t:\"ThreadSafe\"'");
    args.add("-tag 'NotThreadSafe:t:\"NotThreadSafe\"'");
    args.add("-tag 'GuardedBy:mf:\"Guarded By:\"'");
    args.add("-tag 'security:m:\"Required Permissions\"'");
    args.add("-tag 'noimplement:t:\"Consumers of this API must not implement this interface\"'");
    for (Enumeration<?> e = pp.propertyNames(); e.hasMoreElements(); ) {
        String key = (String) e.nextElement();
        String value = pp.getProperty(key);
        if (key.startsWith("-")) {
            //
            // Allow people to add the same command multiple times
            // by suffixing it with '.' something
            //
            int n = key.lastIndexOf('.');
            if (n > 0) {
                key = key.substring(0, n);
            }
            args.add(String.format("%s '%s'", key, escape(value)));
        }
    }
    FileSet set = new FileSet(sources, "**.java");
    for (File f : set.getFiles()) {
        args.add(String.format("'%s'", fileName(f)));
    }
    if (exportsOnly) {
        Parameters exports = manifest.getExportPackage();
        for (String packageName : exports.keySet()) {
            args.add(String.format("'%s'", packageName));
        }
    }
    StringBuilder sb = new StringBuilder();
    for (String arg : args) {
        sb.append(arg);
        sb.append('\n');
    }
    IO.store(sb, javadocOptions);
    Command command = new Command();
    command.add(getProperty("javadoc", "javadoc"));
    command.add("@" + fileName(javadocOptions));
    StringBuilder out = new StringBuilder();
    StringBuilder err = new StringBuilder();
    int result = command.execute(out, err);
    if (result != 0) {
        warning("Error during execution of javadoc command: %s\n******************\n%s", out, err);
    }
    return new Jar(javadoc);
}
Also used : Parameters(aQute.bnd.header.Parameters) FileSet(aQute.lib.fileset.FileSet) ArrayList(java.util.ArrayList) Properties(java.util.Properties) UTF8Properties(aQute.lib.utf8properties.UTF8Properties) Command(aQute.libg.command.Command) Jar(aQute.bnd.osgi.Jar) File(java.io.File) UTF8Properties(aQute.lib.utf8properties.UTF8Properties)

Example 58 with Parameters

use of aQute.bnd.header.Parameters in project bnd by bndtools.

the class MavenBndRepository method getReleaseDTO.

/*
	 * Parse the -maven-release header.
	 */
private ReleaseDTO getReleaseDTO(Processor context) {
    ReleaseDTO release = new ReleaseDTO();
    if (context == null)
        return release;
    Parameters p = new Parameters(context.getProperty(Constants.MAVEN_RELEASE), reporter);
    release.type = storage.isLocalOnly() ? ReleaseType.LOCAL : ReleaseType.REMOTE;
    Attrs attrs = p.remove("remote");
    if (attrs != null) {
        release.type = ReleaseType.REMOTE;
        String s = attrs.get("snapshot");
        if (s != null)
            release.snapshot = Long.parseLong(s);
    } else {
        attrs = p.remove("local");
        if (attrs != null) {
            release.type = ReleaseType.LOCAL;
        }
    }
    Attrs javadoc = p.remove("javadoc");
    if (javadoc != null) {
        release.javadoc.path = javadoc.get("path");
        if (NONE.equals(release.javadoc.path)) {
            release.javadoc = null;
        } else
            release.javadoc.options = javadoc;
    }
    Attrs sources = p.remove("sources");
    if (sources != null) {
        release.sources.path = sources.get("path");
        if (NONE.equals(release.sources.path))
            release.sources = null;
    }
    Attrs pom = p.remove("pom");
    if (pom != null) {
        release.pom.path = pom.get("path");
    }
    if (!p.isEmpty()) {
        reporter.warning("The -maven-release instruction contains unrecognized options: %s", p);
    }
    return release;
}
Also used : Parameters(aQute.bnd.header.Parameters) Attrs(aQute.bnd.header.Attrs)

Example 59 with Parameters

use of aQute.bnd.header.Parameters in project bndtools by bndtools.

the class BndBuilderCapReqLoader method loadCapabilities.

@Override
public Map<String, List<Capability>> loadCapabilities() throws Exception {
    Builder builder = getBuilder();
    if (builder == null)
        return Collections.emptyMap();
    Jar jar = builder.getJar();
    if (jar == null)
        return Collections.emptyMap();
    Manifest manifest = jar.getManifest();
    if (manifest == null)
        return Collections.emptyMap();
    Attributes attribs = manifest.getMainAttributes();
    Map<String, List<Capability>> capMap = new HashMap<String, List<Capability>>();
    // Load export packages
    String exportsPkgStr = attribs.getValue(Constants.EXPORT_PACKAGE);
    Parameters exportsMap = new Parameters(exportsPkgStr);
    for (Entry<String, Attrs> entry : exportsMap.entrySet()) {
        String pkg = Processor.removeDuplicateMarker(entry.getKey());
        org.osgi.framework.Version version = org.osgi.framework.Version.parseVersion(entry.getValue().getVersion());
        CapReqBuilder cb = new CapReqBuilder(PackageNamespace.PACKAGE_NAMESPACE).addAttribute(PackageNamespace.PACKAGE_NAMESPACE, pkg).addAttribute(PackageNamespace.CAPABILITY_VERSION_ATTRIBUTE, version);
        // TODO attributes and directives
        addCapability(capMap, cb.buildSyntheticCapability());
    }
    // Load identity/bundle/host
    String bsn = BundleUtils.getBundleSymbolicName(attribs);
    if (bsn != null) {
        // Ignore if not a bundle
        org.osgi.framework.Version version = org.osgi.framework.Version.parseVersion(attribs.getValue(Constants.BUNDLE_VERSION));
        // TODO attributes and directives
        addCapability(capMap, new CapReqBuilder(IdentityNamespace.IDENTITY_NAMESPACE).addAttribute(IdentityNamespace.IDENTITY_NAMESPACE, bsn).addAttribute(IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE, version).buildSyntheticCapability());
        addCapability(capMap, new CapReqBuilder(BundleNamespace.BUNDLE_NAMESPACE).addAttribute(BundleNamespace.BUNDLE_NAMESPACE, bsn).addAttribute(BundleNamespace.CAPABILITY_BUNDLE_VERSION_ATTRIBUTE, version).buildSyntheticCapability());
        addCapability(capMap, new CapReqBuilder(HostNamespace.HOST_NAMESPACE).addAttribute(HostNamespace.HOST_NAMESPACE, bsn).addAttribute(HostNamespace.CAPABILITY_BUNDLE_VERSION_ATTRIBUTE, version).buildSyntheticCapability());
    }
    // Generic capabilities
    String providesStr = attribs.getValue(Constants.PROVIDE_CAPABILITY);
    Parameters provides = new Parameters(providesStr);
    for (Entry<String, Attrs> entry : provides.entrySet()) {
        String ns = Processor.removeDuplicateMarker(entry.getKey());
        Attrs attrs = entry.getValue();
        CapReqBuilder cb = new CapReqBuilder(ns);
        for (String key : attrs.keySet()) {
            if (key.endsWith(":"))
                cb.addDirective(key.substring(0, key.length() - 1), attrs.get(key));
            else
                cb.addAttribute(key, attrs.getTyped(key));
        }
        addCapability(capMap, cb.buildSyntheticCapability());
    }
    return capMap;
}
Also used : CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) Parameters(aQute.bnd.header.Parameters) Capability(org.osgi.resource.Capability) HashMap(java.util.HashMap) CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) Builder(aQute.bnd.osgi.Builder) Attributes(java.util.jar.Attributes) Attrs(aQute.bnd.header.Attrs) Manifest(java.util.jar.Manifest) Jar(aQute.bnd.osgi.Jar) LinkedList(java.util.LinkedList) List(java.util.List)

Example 60 with Parameters

use of aQute.bnd.header.Parameters in project bndtools by bndtools.

the class BndBuilderCapReqLoader method loadRequirements.

@Override
public Map<String, List<RequirementWrapper>> loadRequirements() throws Exception {
    Builder builder = getBuilder();
    if (builder == null)
        return Collections.emptyMap();
    Jar jar = builder.getJar();
    if (jar == null)
        return Collections.emptyMap();
    Manifest manifest = jar.getManifest();
    if (manifest == null)
        return Collections.emptyMap();
    Attributes attribs = manifest.getMainAttributes();
    Map<String, List<RequirementWrapper>> requirements = new HashMap<String, List<RequirementWrapper>>();
    // Process imports
    String importPkgStr = attribs.getValue(Constants.IMPORT_PACKAGE);
    Parameters importsMap = new Parameters(importPkgStr);
    for (Entry<String, Attrs> entry : importsMap.entrySet()) {
        String pkgName = Processor.removeDuplicateMarker(entry.getKey());
        Attrs attrs = entry.getValue();
        CapReqBuilder rb = new CapReqBuilder(PackageNamespace.PACKAGE_NAMESPACE);
        String filter = createVersionFilter(PackageNamespace.PACKAGE_NAMESPACE, pkgName, attrs.get(Constants.VERSION_ATTRIBUTE), PackageNamespace.CAPABILITY_VERSION_ATTRIBUTE);
        rb.addDirective(PackageNamespace.REQUIREMENT_FILTER_DIRECTIVE, filter);
        if (Constants.RESOLUTION_OPTIONAL.equals(attrs.get(Constants.RESOLUTION_DIRECTIVE + ":")))
            rb.addDirective(Namespace.REQUIREMENT_RESOLUTION_DIRECTIVE, Namespace.RESOLUTION_OPTIONAL);
        Collection<Clazz> importers = findImportingClasses(pkgName, builder);
        RequirementWrapper rw = new RequirementWrapper();
        rw.requirement = rb.buildSyntheticRequirement();
        rw.requirers = importers;
        addRequirement(requirements, rw);
    }
    // Process require-bundle
    String requireBundleStr = attribs.getValue(Constants.REQUIRE_BUNDLE);
    Parameters requireBundles = new Parameters(requireBundleStr);
    for (Entry<String, Attrs> entry : requireBundles.entrySet()) {
        String bsn = Processor.removeDuplicateMarker(entry.getKey());
        Attrs attrs = entry.getValue();
        CapReqBuilder rb = new CapReqBuilder(BundleNamespace.BUNDLE_NAMESPACE);
        String filter = createVersionFilter(BundleNamespace.BUNDLE_NAMESPACE, bsn, attrs.get(Constants.BUNDLE_VERSION_ATTRIBUTE), BundleNamespace.CAPABILITY_BUNDLE_VERSION_ATTRIBUTE);
        rb.addDirective(BundleNamespace.REQUIREMENT_FILTER_DIRECTIVE, filter);
        if (Constants.RESOLUTION_OPTIONAL.equals(attrs.get(Constants.RESOLUTION_DIRECTIVE + ":")))
            rb.addDirective(Namespace.REQUIREMENT_RESOLUTION_DIRECTIVE, Namespace.RESOLUTION_OPTIONAL);
        RequirementWrapper rw = new RequirementWrapper();
        rw.requirement = rb.buildSyntheticRequirement();
        addRequirement(requirements, rw);
    }
    // Process generic requires
    String requiresStr = attribs.getValue(Constants.REQUIRE_CAPABILITY);
    Parameters requires = new Parameters(requiresStr);
    for (Entry<String, Attrs> entry : requires.entrySet()) {
        String ns = Processor.removeDuplicateMarker(entry.getKey());
        Attrs attrs = entry.getValue();
        CapReqBuilder rb = new CapReqBuilder(ns);
        for (String key : attrs.keySet()) {
            if (key.endsWith(":"))
                rb.addDirective(key.substring(0, key.length() - 1), attrs.get(key));
            else
                rb.addAttribute(key, attrs.getTyped(key));
        }
        RequirementWrapper rw = new RequirementWrapper();
        rw.requirement = rb.buildSyntheticRequirement();
        addRequirement(requirements, rw);
    }
    return requirements;
}
Also used : CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) Parameters(aQute.bnd.header.Parameters) HashMap(java.util.HashMap) CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) Builder(aQute.bnd.osgi.Builder) Attributes(java.util.jar.Attributes) Attrs(aQute.bnd.header.Attrs) Manifest(java.util.jar.Manifest) Jar(aQute.bnd.osgi.Jar) LinkedList(java.util.LinkedList) List(java.util.List) Clazz(aQute.bnd.osgi.Clazz) RequirementWrapper(bndtools.model.resolution.RequirementWrapper)

Aggregations

Parameters (aQute.bnd.header.Parameters)157 Attrs (aQute.bnd.header.Attrs)78 File (java.io.File)45 Jar (aQute.bnd.osgi.Jar)44 Manifest (java.util.jar.Manifest)39 Builder (aQute.bnd.osgi.Builder)35 Domain (aQute.bnd.osgi.Domain)24 ArrayList (java.util.ArrayList)20 Map (java.util.Map)16 Attributes (java.util.jar.Attributes)16 IOException (java.io.IOException)14 HashMap (java.util.HashMap)13 Version (aQute.bnd.version.Version)11 Instructions (aQute.bnd.osgi.Instructions)9 HashSet (java.util.HashSet)9 Requirement (org.osgi.resource.Requirement)9 FileNotFoundException (java.io.FileNotFoundException)8 Properties (java.util.Properties)8 Matcher (java.util.regex.Matcher)8 Analyzer (aQute.bnd.osgi.Analyzer)7