Search in sources :

Example 61 with Parameters

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

the class GitHubWorkspaceTemplateLoader method findTemplates.

@Override
public Promise<List<Template>> findTemplates(String type, Reporter reporter) {
    if (!TEMPLATE_TYPE.equals(type))
        return Promises.resolved(Collections.<Template>emptyList());
    List<Promise<Template>> promises = new LinkedList<>();
    Parameters githubRepos = new GitRepoPreferences().getGithubRepos();
    for (Entry<String, Attrs> entry : githubRepos.entrySet()) {
        final String repo = GitRepoPreferences.removeDuplicateMarker(entry.getKey());
        final Attrs attribs = entry.getValue();
        try {
            final GitHub gitHub = new GitHub(cache, executor);
            promises.add(gitHub.loadRepoDetails(repo).map(new Function<GithubRepoDetailsDTO, Template>() {

                @Override
                public Template apply(GithubRepoDetailsDTO detailsDTO) {
                    if (detailsDTO.clone_url == null)
                        throw new IllegalArgumentException("Missing clone URL");
                    // Generate icon URI from the owner avatar. The s=16 parameter
                    // is added to select a 16x16 icon.
                    URI avatarUri = null;
                    if (detailsDTO.owner.avatar_url != null)
                        avatarUri = URI.create(detailsDTO.owner.avatar_url + "&s=16");
                    String name = attribs.get("name");
                    if (name == null)
                        name = repo;
                    String branch = attribs.get("branch");
                    final GitCloneTemplateParams params = new GitCloneTemplateParams();
                    params.cloneUrl = detailsDTO.clone_url;
                    if (branch != null)
                        params.branch = branch;
                    else
                        params.branch = "origin/" + detailsDTO.default_branch;
                    params.name = name;
                    params.category = "GitHub";
                    params.iconUri = avatarUri;
                    if (detailsDTO.html_url != null) {
                        params.helpUri = createHelpUri(repo, detailsDTO.html_url);
                    }
                    return new GitCloneTemplate(params);
                }
            }));
        } catch (Exception e) {
            reporter.exception(e, "Error loading template from Github repository %s", repo);
        }
    }
    return Promises.all(promises);
}
Also used : Parameters(aQute.bnd.header.Parameters) Attrs(aQute.bnd.header.Attrs) URI(java.net.URI) LinkedList(java.util.LinkedList) Template(org.bndtools.templating.Template) Promise(org.osgi.util.promise.Promise) Function(org.osgi.util.function.Function)

Example 62 with Parameters

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

the class Profiles method _create.

public void _create(CreateOptions options) throws Exception {
    Builder b = new Builder();
    bnd.addClose(b);
    b.setBase(bnd.getBase());
    if (options.properties() != null) {
        for (String propertyFile : options.properties()) {
            File pf = bnd.getFile(propertyFile);
            b.addProperties(pf);
        }
    }
    if (options.bsn() != null)
        b.setProperty(Constants.BUNDLE_SYMBOLICNAME, options.bsn());
    if (options.version() != null)
        b.setProperty(Constants.BUNDLE_VERSION, options.version().toString());
    Instructions match = options.match();
    Parameters packages = new Parameters();
    Parameters capabilities = new Parameters();
    Collection<String> paths = new ArrayList<String>(new Parameters(b.getProperty("-paths"), bnd).keySet());
    if (paths.isEmpty())
        paths = options._arguments();
    logger.debug("input {}", paths);
    ResourceBuilder pb = new ResourceBuilder();
    for (String root : paths) {
        File f = bnd.getFile(root);
        if (!f.exists()) {
            error("could not find %s", f);
        } else {
            Glob g = options.extension();
            if (g == null)
                g = new Glob("*.jar");
            Collection<File> files = IO.tree(f, "*.jar");
            logger.debug("will profile {}", files);
            for (File file : files) {
                Domain domain = Domain.domain(file);
                if (domain == null) {
                    error("Not a bundle because no manifest %s", file);
                    continue;
                }
                String bsn = domain.getBundleSymbolicName().getKey();
                if (bsn == null) {
                    error("Not a bundle because no manifest %s", file);
                    continue;
                }
                if (match != null) {
                    Instruction instr = match.finder(bsn);
                    if (instr == null || instr.isNegated()) {
                        logger.debug("skipped {} because of non matching bsn {}", file, bsn);
                        continue;
                    }
                }
                Parameters eps = domain.getExportPackage();
                Parameters pcs = domain.getProvideCapability();
                logger.debug("parse {}:\ncaps: {}\npac: {}\n", file, pcs, eps);
                packages.mergeWith(eps, false);
                capabilities.mergeWith(pcs, false);
            }
        }
    }
    b.setProperty(Constants.PROVIDE_CAPABILITY, capabilities.toString());
    b.setProperty(Constants.EXPORT_PACKAGE, packages.toString());
    logger.debug("Found {} packages and {} capabilities", packages.size(), capabilities.size());
    Jar jar = b.build();
    File f = b.getOutputFile(options.output());
    logger.debug("Saving as {}", f);
    jar.write(f);
}
Also used : ResourceBuilder(aQute.bnd.osgi.resource.ResourceBuilder) Parameters(aQute.bnd.header.Parameters) ResourceBuilder(aQute.bnd.osgi.resource.ResourceBuilder) Builder(aQute.bnd.osgi.Builder) ArrayList(java.util.ArrayList) Instructions(aQute.bnd.osgi.Instructions) Instruction(aQute.bnd.osgi.Instruction) Glob(aQute.libg.glob.Glob) Jar(aQute.bnd.osgi.Jar) Domain(aQute.bnd.osgi.Domain) File(java.io.File)

Example 63 with Parameters

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

the class RemoteCommand method _distro.

public void _distro(DistroOptions opts) throws Exception {
    List<String> args = opts._arguments();
    String bsn;
    String version;
    bsn = args.remove(0);
    if (!Verifier.isBsn(bsn)) {
        error("Not a bundle symbolic name %s", bsn);
    }
    if (args.isEmpty())
        version = "0";
    else {
        version = args.remove(0);
        if (!Version.isVersion(version)) {
            error("Invalid version %s", version);
        }
    }
    File output = getFile(opts.output("distro.jar"));
    if (output.getParentFile() == null || !output.getParentFile().isDirectory()) {
        error("Cannot write to %s because parent not a directory", output);
    }
    if (output.isFile() && !output.canWrite()) {
        error("Cannot write to %s", output);
    }
    logger.debug("Starting distro {};{}", bsn, version);
    List<BundleRevisionDTO> bundleRevisons = agent.getBundleRevisons();
    logger.debug("Found {} bundle revisions", bundleRevisons.size());
    Parameters packages = new Parameters();
    List<Parameters> provided = new ArrayList<>();
    for (BundleRevisionDTO brd : bundleRevisons) {
        for (CapabilityDTO c : brd.capabilities) {
            CapabilityBuilder cb = new CapabilityBuilder(c.namespace);
            for (Entry<String, Object> e : c.attributes.entrySet()) {
                String key = e.getKey();
                Object value = e.getValue();
                if (key.equals("version")) {
                    if (value instanceof Collection || value.getClass().isArray())
                        value = Converter.cnv(tref, value);
                    else
                        value = new Version((String) value);
                }
                cb.addAttribute(key, value);
            }
            cb.addDirectives(c.directives);
            Attrs attrs = cb.toAttrs();
            if (cb.isPackage()) {
                attrs.remove(Constants.BUNDLE_SYMBOLIC_NAME_ATTRIBUTE);
                attrs.remove(Constants.BUNDLE_VERSION_ATTRIBUTE);
                String pname = attrs.remove(PackageNamespace.PACKAGE_NAMESPACE);
                if (pname == null) {
                    warning("Invalid package capability found %s", c);
                } else
                    packages.put(pname, attrs);
                logger.debug("P: {};{}", pname, attrs);
            } else if (NativeNamespace.NATIVE_NAMESPACE.equals(c.namespace)) {
                Attrs newAttrs = new Attrs();
                for (Entry<String, String> entry : attrs.entrySet()) {
                    if (entry.getKey().startsWith(NativeNamespace.NATIVE_NAMESPACE)) {
                        newAttrs.put(entry.getKey(), entry.getValue());
                    }
                }
                Parameters p = new Parameters();
                p.put(c.namespace, newAttrs);
                provided.add(p);
            } else if (!IGNORED_NAMESPACES.contains(c.namespace)) {
                logger.debug("C {};{}", c.namespace, attrs);
                Parameters p = new Parameters();
                p.put(c.namespace, attrs);
                provided.add(p);
            }
        }
    }
    if (isOk()) {
        Manifest m = new Manifest();
        Attributes main = m.getMainAttributes();
        main.putValue(Constants.BUNDLE_MANIFESTVERSION, "2");
        main.putValue(Constants.BUNDLE_SYMBOLICNAME, bsn);
        main.putValue(Constants.BUNDLE_VERSION, version);
        main.putValue(Constants.EXPORT_PACKAGE, packages.toString());
        // Make distro unresolvable
        Parameters unresolveable = new Parameters("osgi.unresolvable; filter:='(&(must.not.resolve=*)(!(must.not.resolve=*)))'");
        main.putValue(Constants.REQUIRE_CAPABILITY, unresolveable.toString());
        provided.add(new Parameters("osgi.unresolvable"));
        StringBuilder sb = new StringBuilder();
        for (Parameters parameter : provided) {
            sb.append(parameter.toString());
            sb.append(",");
        }
        String capabilities = sb.toString().substring(0, sb.length() - 1);
        main.putValue(Constants.PROVIDE_CAPABILITY, capabilities);
        if (opts.description() != null)
            main.putValue(Constants.BUNDLE_DESCRIPTION, opts.description());
        if (opts.license() != null)
            main.putValue(Constants.BUNDLE_LICENSE, opts.license());
        if (opts.copyright() != null)
            main.putValue(Constants.BUNDLE_COPYRIGHT, opts.copyright());
        if (opts.vendor() != null)
            main.putValue(Constants.BUNDLE_VENDOR, opts.vendor());
        Jar jar = new Jar("distro");
        jar.setManifest(m);
        Verifier v = new Verifier(jar);
        v.setProperty(Constants.FIXUPMESSAGES, "osgi.* namespace must not be specified with generic capabilities");
        v.verify();
        v.getErrors();
        if (isFailOk() || v.isOk()) {
            jar.updateModified(System.currentTimeMillis(), "Writing distro jar");
            jar.write(output);
        } else
            getInfo(v);
    }
}
Also used : Parameters(aQute.bnd.header.Parameters) BundleRevisionDTO(org.osgi.framework.wiring.dto.BundleRevisionDTO) ArrayList(java.util.ArrayList) Attrs(aQute.bnd.header.Attrs) Attributes(java.util.jar.Attributes) CapabilityBuilder(aQute.bnd.osgi.resource.CapabilityBuilder) Manifest(java.util.jar.Manifest) Verifier(aQute.bnd.osgi.Verifier) Entry(java.util.Map.Entry) CapabilityDTO(org.osgi.resource.dto.CapabilityDTO) Version(aQute.bnd.version.Version) Collection(java.util.Collection) Jar(aQute.bnd.osgi.Jar) File(java.io.File)

Example 64 with Parameters

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

the class NoUsesTest method findUses.

static String findUses(Builder bmaker, String pack, String... ignore) throws Exception {
    File[] cp = { new File("bin"), IO.getFile("jar/osgi.jar") };
    bmaker.setClasspath(cp);
    Jar jar = bmaker.build();
    assertTrue(bmaker.check(ignore));
    String exports = jar.getManifest().getMainAttributes().getValue("Export-Package");
    assertNotNull("exports", exports);
    Parameters map = Processor.parseHeader(exports, null);
    if (map == null)
        return null;
    Map<String, String> clause = map.get(pack);
    if (clause == null)
        return null;
    return clause.get("uses:");
}
Also used : Parameters(aQute.bnd.header.Parameters) Jar(aQute.bnd.osgi.Jar) File(java.io.File)

Example 65 with Parameters

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

the class ParseHeaderTest method assertNames.

static void assertNames(String header, String[] keys, String expectedError, String expectedWarning) {
    Processor p = new Processor();
    p.setPedantic(true);
    Parameters map = Processor.parseHeader(header, p);
    for (String key : keys) assertTrue(map.containsKey(key));
    assertEquals(keys.length, map.size());
    if (expectedError != null) {
        System.err.println(p.getErrors());
        assertTrue(p.getErrors().size() > 0);
        assertTrue(p.getErrors().get(0).indexOf(expectedError) >= 0);
    } else
        assertEquals(0, p.getErrors().size());
    if (expectedWarning != null) {
        System.err.println(p.getWarnings());
        assertTrue(p.getWarnings().size() > 0);
        String w = p.getWarnings().get(0);
        assertTrue(w.contains(expectedWarning));
    } else
        assertEquals(0, p.getWarnings().size());
}
Also used : Processor(aQute.bnd.osgi.Processor) Parameters(aQute.bnd.header.Parameters)

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