Search in sources :

Example 26 with Parameters

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

the class DistroCommandTest method testDistroJarNotResolvable.

public void testDistroJarNotResolvable() throws Exception {
    bnd bnd = new bnd();
    CommandLine cmdline = new CommandLine(null);
    List<String> remoteArgs = new ArrayList<>();
    RemoteOptions remoteOptions = cmdline.getOptions(RemoteOptions.class, remoteArgs);
    File distro = new File("generated/tmp/test.distro.jar");
    if (distro.exists()) {
        assertTrue(distro.delete());
    }
    List<String> distroArgs = new ArrayList<>();
    distroArgs.add("-o");
    distroArgs.add(distro.getPath());
    distroArgs.add("test.distro");
    distroArgs.add("1.0.0");
    DistroOptions distroOptions = cmdline.getOptions(DistroOptions.class, distroArgs);
    new RemoteCommand(bnd, remoteOptions)._distro(distroOptions);
    assertTrue(distro.exists());
    Domain domain = Domain.domain(distro);
    Parameters providedCapabilities = domain.getProvideCapability();
    assertTrue(providedCapabilities.containsKey("osgi.unresolvable"));
    Parameters requiredCapabilities = domain.getRequireCapability();
    assertTrue(requiredCapabilities.containsKey("osgi.unresolvable"));
    Attrs attrs = requiredCapabilities.get("osgi.unresolvable");
    assertEquals("(&(must.not.resolve=*)(!(must.not.resolve=*)))", attrs.get("filter:"));
}
Also used : CommandLine(aQute.lib.getopt.CommandLine) DistroOptions(aQute.bnd.main.RemoteCommand.DistroOptions) Parameters(aQute.bnd.header.Parameters) RemoteOptions(aQute.bnd.main.RemoteCommand.RemoteOptions) ArrayList(java.util.ArrayList) Attrs(aQute.bnd.header.Attrs) Domain(aQute.bnd.osgi.Domain) File(java.io.File)

Example 27 with Parameters

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

the class bnd method _export.

public void _export(ExportOptions opts) throws Exception {
    Project project = getProject(opts.project());
    if (project == null) {
        error("No project");
        return;
    }
    // temporary
    project.getWorkspace().addBasicPlugin(new SubsystemExporter());
    List<Exporter> exporters = project.getPlugins(Exporter.class);
    Exporter exporter = null;
    for (Exporter e : exporters) {
        String[] types = e.getTypes();
        for (String type : types) {
            if (type.equals(opts.exporter()))
                ;
        }
    }
    for (String bndrun : opts._arguments()) {
        File f = getFile(bndrun);
        if (!f.isFile()) {
            error("No such file: %s", f);
            continue;
        }
        Run run = new Run(project.getWorkspace(), getBase(), f);
        run.getSettings(this);
        Parameters exports = new Parameters();
        List<String> types = opts.exporter();
        if (types != null) {
            for (String type : types) {
                exports.putAll(new Parameters(type, this));
            }
        } else {
            String exportTypes = run.getProperty(Constants.EXPORTTYPE);
            exports.putAll(new Parameters(exportTypes, this));
        }
        for (Entry<String, Attrs> e : exports.entrySet()) {
            logger.debug("exporting {} to {} with {}", run, e.getKey(), e.getValue());
            Map.Entry<String, Resource> result = run.export(e.getKey(), e.getValue());
            getInfo(run);
            if (result != null && isOk()) {
                String name = result.getKey();
                File output = new File(project.getTarget(), opts.output() == null ? name : opts.output());
                if (output.isDirectory())
                    output = new File(output, name);
                IO.mkdirs(output.getParentFile());
                logger.debug("Got a result for {}, store in {}", e.getKey(), output);
                IO.copy(result.getValue().openInputStream(), output);
            }
        }
    }
}
Also used : Parameters(aQute.bnd.header.Parameters) Attrs(aQute.bnd.header.Attrs) FileResource(aQute.bnd.osgi.FileResource) Resource(aQute.bnd.osgi.Resource) Run(aQute.bnd.build.Run) Exporter(aQute.bnd.service.export.Exporter) Project(aQute.bnd.build.Project) File(java.io.File) MultiMap(aQute.lib.collections.MultiMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap)

Example 28 with Parameters

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

the class bnd method _find.

public void _find(FindOptions options) throws Exception {
    List<File> files = new ArrayList<File>();
    List<String> args = options._arguments();
    if (args.size() == 0) {
        Project p = getProject();
        if (p == null) {
            error("This is not a project directory and you have specified no jar files ...");
            return;
        }
        File output = p.getOutput();
        if (output.exists()) {
            files.add(output);
        }
        for (Container c : p.getBuildpath()) {
            files.add(c.getFile());
        }
    } else {
        for (String f : args) {
            File file = getFile(f);
            files.add(file);
        }
    }
    for (File f : files) {
        logger.debug("find {}", f);
        try (Jar jar = new Jar(f)) {
            Manifest m = jar.getManifest();
            if (m != null) {
                Domain domain = Domain.domain(m);
                if (options.exports() != null) {
                    Parameters ep = domain.getExportPackage();
                    for (Glob g : options.exports()) {
                        for (Entry<String, Attrs> exp : ep.entrySet()) {
                            if (g.matcher(exp.getKey()).matches()) {
                                String v = exp.getValue().get(VERSION_ATTRIBUTE);
                                if (v == null)
                                    v = "0";
                                out.printf(">%s: %s-%s%n", f.getPath(), exp.getKey(), v);
                            }
                        }
                    }
                }
                if (options.imports() != null) {
                    Parameters ip = domain.getImportPackage();
                    for (Glob g : options.imports()) {
                        for (Entry<String, Attrs> imp : ip.entrySet()) {
                            if (g.matcher(imp.getKey()).matches()) {
                                String v = imp.getValue().get(VERSION_ATTRIBUTE);
                                if (v == null)
                                    v = "0";
                                out.printf("<%s: %s-%s%n", f.getPath(), imp.getKey(), v);
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : Parameters(aQute.bnd.header.Parameters) ArrayList(java.util.ArrayList) Attrs(aQute.bnd.header.Attrs) Manifest(java.util.jar.Manifest) PomFromManifest(aQute.bnd.maven.PomFromManifest) Project(aQute.bnd.build.Project) Container(aQute.bnd.build.Container) Glob(aQute.libg.glob.Glob) Jar(aQute.bnd.osgi.Jar) Domain(aQute.bnd.osgi.Domain) File(java.io.File)

Example 29 with Parameters

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

the class DSAnnotations method addServiceCapability.

private void addServiceCapability(String[] objectClass, Set<String> provides) {
    if (objectClass.length > 0) {
        Parameters p = new Parameters();
        Attrs a = new Attrs();
        StringBuilder sb = new StringBuilder();
        String sep = "";
        for (String oc : objectClass) {
            sb.append(sep).append(oc);
            sep = ",";
        }
        a.put("objectClass:List<String>", sb.toString());
        p.put("osgi.service", a);
        String s = p.toString();
        provides.add(s);
    }
}
Also used : Parameters(aQute.bnd.header.Parameters) Attrs(aQute.bnd.header.Attrs)

Example 30 with Parameters

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

the class DSAnnotations method updateHeader.

/**
	 * Updates specified header, sorting and removing duplicates. Destroys
	 * contents of set parameter.
	 * 
	 * @param analyzer
	 * @param name header name
	 * @param set values to add to header; contents are not preserved.
	 */
private void updateHeader(Analyzer analyzer, String name, TreeSet<String> set) {
    if (!set.isEmpty()) {
        String value = analyzer.getProperty(name);
        if (value != null) {
            Parameters p = OSGiHeader.parseHeader(value);
            for (Map.Entry<String, Attrs> entry : p.entrySet()) {
                StringBuilder sb = new StringBuilder(entry.getKey());
                if (entry.getValue() != null) {
                    sb.append(";");
                    entry.getValue().append(sb);
                }
                set.add(sb.toString());
            }
        }
        String header = Strings.join(set);
        analyzer.setProperty(name, header);
    }
}
Also used : Parameters(aQute.bnd.header.Parameters) Attrs(aQute.bnd.header.Attrs) Map(java.util.Map)

Aggregations

Parameters (aQute.bnd.header.Parameters)167 Attrs (aQute.bnd.header.Attrs)80 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)23 Map (java.util.Map)19 Attributes (java.util.jar.Attributes)17 IOException (java.io.IOException)15 HashMap (java.util.HashMap)15 Version (aQute.bnd.version.Version)11 HashSet (java.util.HashSet)10 Instructions (aQute.bnd.osgi.Instructions)9 FileNotFoundException (java.io.FileNotFoundException)8 Properties (java.util.Properties)8 Matcher (java.util.regex.Matcher)8 Analyzer (aQute.bnd.osgi.Analyzer)7 PackageRef (aQute.bnd.osgi.Descriptors.PackageRef)7