Search in sources :

Example 86 with Parameters

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

the class CapReqBuilderTest method testAliasedRequirementWithVersion.

public void testAliasedRequirementWithVersion() throws Exception {
    Parameters params = OSGiHeader.parseHeader("bnd.identity; id=org.example.foo; version=1.2");
    Requirement req = CapReqBuilder.getRequirementsFrom(params).get(0);
    assertEquals("osgi.identity", req.getNamespace());
    assertEquals("(&(osgi.identity=org.example.foo)(version>=1.2.0))", req.getDirectives().get("filter"));
}
Also used : Requirement(org.osgi.resource.Requirement) Parameters(aQute.bnd.header.Parameters)

Example 87 with Parameters

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

the class Domain method getIcon.

/**
	 * Find an icon with the requested size in the list of icons.
	 * 
	 * @param requestedSize the number of pixels desired
	 * @return null or a the selected URI (which may be relative)
	 */
public String getIcon(int requestedSize) throws Exception {
    String spec = get(Constants.BUNDLE_ICON);
    if (spec == null)
        return null;
    Parameters p = OSGiHeader.parseHeader(spec);
    int dist = Integer.MAX_VALUE;
    String selected = null;
    for (Entry<String, Attrs> e : p.entrySet()) {
        String url = e.getKey();
        if (selected == null)
            selected = url;
        if (e.getValue() != null) {
            String s = e.getValue().get("size");
            if (s != null) {
                int size = Converter.cnv(Integer.class, s);
                if (size != 0 && Math.abs(requestedSize - size) < dist) {
                    dist = Math.abs(requestedSize - size);
                    selected = url;
                }
            }
        }
    }
    return selected;
}
Also used : Parameters(aQute.bnd.header.Parameters) Attrs(aQute.bnd.header.Attrs)

Example 88 with Parameters

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

the class Processor method fixupMessages.

/**
	 * Move errors and warnings to their proper place by scanning the fixup
	 * messages property.
	 */
private void fixupMessages() {
    if (fixupMessages)
        return;
    fixupMessages = true;
    Parameters fixup = getMergedParameters(Constants.FIXUPMESSAGES);
    if (fixup.isEmpty())
        return;
    Instructions instrs = new Instructions(fixup);
    doFixup(instrs, errors, warnings, FIXUPMESSAGES_IS_ERROR);
    doFixup(instrs, warnings, errors, FIXUPMESSAGES_IS_WARNING);
}
Also used : Parameters(aQute.bnd.header.Parameters)

Example 89 with Parameters

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

the class Domain method getPrivatePackage.

public Parameters getPrivatePackage() {
    Parameters p = getParameters(PRIVATE_PACKAGE);
    p.putAll(getParameters(PRIVATEPACKAGE));
    return p;
}
Also used : Parameters(aQute.bnd.header.Parameters)

Example 90 with Parameters

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

the class ProjectLauncherImpl method executable.

/**
	 * Create a standalone executable. All entries on the runpath are rolled out
	 * into the JAR and the runbundles are copied to a directory in the jar. The
	 * launcher will see that it starts in embedded mode and will automatically
	 * detect that it should load the bundles from inside. This is drive by the
	 * launcher.embedded flag.
	 * 
	 * @throws Exception
	 */
@Override
public Jar executable() throws Exception {
    // TODO use constants in the future
    Parameters packageHeader = OSGiHeader.parseHeader(getProject().getProperty("-package"));
    boolean useShas = packageHeader.containsKey("jpm");
    logger.debug("useShas {} {}", useShas, packageHeader);
    Jar jar = new Jar(getProject().getName());
    Builder b = new Builder();
    getProject().addClose(b);
    if (!getProject().getIncludeResource().isEmpty()) {
        b.setIncludeResource(getProject().getIncludeResource().toString());
        b.setProperty(Constants.RESOURCEONLY, "true");
        b.build();
        if (b.isOk()) {
            jar.addAll(b.getJar());
        }
        getProject().getInfo(b);
    }
    List<String> runpath = getRunpath();
    Set<String> runpathShas = new LinkedHashSet<String>();
    Set<String> runbundleShas = new LinkedHashSet<String>();
    List<String> classpath = new ArrayList<String>();
    for (String path : runpath) {
        logger.debug("embedding runpath {}", path);
        File file = new File(path);
        if (file.isFile()) {
            if (useShas) {
                String sha = SHA1.digest(file).asHex();
                runpathShas.add(sha + ";name=\"" + file.getName() + "\"");
            } else {
                String newPath = nonCollidingPath(file, jar);
                jar.putResource(newPath, new FileResource(file));
                classpath.add(newPath);
            }
        }
    }
    // Copy the bundles to the JAR
    List<String> runbundles = (List<String>) getRunBundles();
    List<String> actualPaths = new ArrayList<String>();
    for (String path : runbundles) {
        logger.debug("embedding run bundles {}", path);
        File file = new File(path);
        if (!file.isFile())
            getProject().error("Invalid entry in -runbundles %s", file);
        else {
            if (useShas) {
                String sha = SHA1.digest(file).asHex();
                runbundleShas.add(sha + ";name=\"" + file.getName() + "\"");
                actualPaths.add("${JPMREPO}/" + sha);
            } else {
                String newPath = nonCollidingPath(file, jar);
                jar.putResource(newPath, new FileResource(file));
                actualPaths.add(newPath);
            }
        }
    }
    LauncherConstants lc = getConstants(actualPaths, true);
    lc.embedded = !useShas;
    // cannot use local info
    lc.storageDir = null;
    final Properties p = lc.getProperties(new UTF8Properties());
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    p.store(bout, "");
    jar.putResource(LauncherConstants.DEFAULT_LAUNCHER_PROPERTIES, new EmbeddedResource(bout.toByteArray(), 0L));
    Manifest m = new Manifest();
    Attributes main = m.getMainAttributes();
    for (Entry<Object, Object> e : getProject().getFlattenedProperties().entrySet()) {
        String key = (String) e.getKey();
        if (key.length() > 0 && Character.isUpperCase(key.charAt(0)))
            main.putValue(key, (String) e.getValue());
    }
    Instructions instructions = new Instructions(getProject().getProperty(Constants.REMOVEHEADERS));
    Collection<Object> result = instructions.select(main.keySet(), false);
    main.keySet().removeAll(result);
    if (useShas) {
        logger.debug("Use JPM launcher");
        m.getMainAttributes().putValue("Main-Class", JPM_LAUNCHER_FQN);
        m.getMainAttributes().putValue("JPM-Classpath", Processor.join(runpathShas));
        m.getMainAttributes().putValue("JPM-Runbundles", Processor.join(runbundleShas));
        URLResource jpmLauncher = new URLResource(this.getClass().getResource("/" + JPM_LAUNCHER));
        jar.putResource(JPM_LAUNCHER, jpmLauncher);
        doStart(jar, JPM_LAUNCHER_FQN);
    } else {
        logger.debug("Use Embedded launcher");
        m.getMainAttributes().putValue("Main-Class", EMBEDDED_LAUNCHER_FQN);
        m.getMainAttributes().putValue(EmbeddedLauncher.EMBEDDED_RUNPATH, Processor.join(classpath));
        URLResource embeddedLauncher = new URLResource(this.getClass().getResource("/" + EMBEDDED_LAUNCHER));
        jar.putResource(EMBEDDED_LAUNCHER, embeddedLauncher);
        doStart(jar, EMBEDDED_LAUNCHER_FQN);
    }
    if (getProject().getProperty(Constants.DIGESTS) != null)
        jar.setDigestAlgorithms(getProject().getProperty(Constants.DIGESTS).trim().split("\\s*,\\s*"));
    else
        jar.setDigestAlgorithms(new String[] { "SHA-1", "MD-5" });
    jar.setManifest(m);
    cleanup();
    return jar;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Parameters(aQute.bnd.header.Parameters) Builder(aQute.bnd.osgi.Builder) ArrayList(java.util.ArrayList) FileResource(aQute.bnd.osgi.FileResource) Attributes(java.util.jar.Attributes) Instructions(aQute.bnd.osgi.Instructions) ByteArrayOutputStream(java.io.ByteArrayOutputStream) UTF8Properties(aQute.lib.utf8properties.UTF8Properties) Properties(java.util.Properties) Manifest(java.util.jar.Manifest) URLResource(aQute.bnd.osgi.URLResource) EmbeddedResource(aQute.bnd.osgi.EmbeddedResource) Jar(aQute.bnd.osgi.Jar) ArrayList(java.util.ArrayList) List(java.util.List) LauncherConstants(aQute.launcher.constants.LauncherConstants) File(java.io.File) UTF8Properties(aQute.lib.utf8properties.UTF8Properties)

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