Search in sources :

Example 11 with Parameters

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

the class Analyzer method doNamesection.

/**
	 * Parse the namesection as instructions and then match them against the
	 * current set of resources For example:
	 * 
	 * <pre>
	 *  -namesection: *;baz=true,
	 * abc/def/bar/X.class=3
	 * </pre>
	 * 
	 * The raw value of {@link Constants#NAMESECTION} is used but the values of
	 * the attributes are replaced where @ is set to the resource name. This
	 * allows macro to operate on the resource
	 */
private void doNamesection(Jar dot, Manifest manifest) {
    Parameters namesection = parseHeader(getProperties().getProperty(NAMESECTION));
    Instructions instructions = new Instructions(namesection);
    Set<String> resources = new HashSet<String>(dot.getResources().keySet());
    //
    for (Map.Entry<Instruction, Attrs> instr : instructions.entrySet()) {
        boolean matched = false;
        for (Iterator<String> i = resources.iterator(); i.hasNext(); ) {
            String path = i.next();
            if (instr.getKey().matches(path)) {
                // Instruction matches the resource
                matched = true;
                if (!instr.getKey().isNegated()) {
                    // Positive match, add the attributes
                    Attributes attrs = manifest.getAttributes(path);
                    if (attrs == null) {
                        attrs = new Attributes();
                        manifest.getEntries().put(path, attrs);
                    }
                    for (Map.Entry<String, String> property : instr.getValue().entrySet()) {
                        setProperty("@", path);
                        try {
                            String processed = getReplacer().process(property.getValue());
                            attrs.putValue(property.getKey(), processed);
                        } finally {
                            unsetProperty("@");
                        }
                    }
                }
                i.remove();
            }
        }
        if (!matched && resources.size() > 0)
            warning("The instruction %s in %s did not match any resources", instr.getKey(), NAMESECTION);
    }
}
Also used : Parameters(aQute.bnd.header.Parameters) Attrs(aQute.bnd.header.Attrs) Attributes(java.util.jar.Attributes) MultiMap(aQute.lib.collections.MultiMap) Map(java.util.Map) HashMap(java.util.HashMap) HashSet(java.util.HashSet)

Example 12 with Parameters

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

the class AnnotationHeaders method doLicense.

/*
	 * Bundle-License header
	 */
private void doLicense(Annotation a) throws Exception {
    BundleLicense annotation = a.getAnnotation(BundleLicense.class);
    Parameters p = new Parameters();
    p.put(annotation.name(), getAttributes(a, "name"));
    add(Constants.BUNDLE_LICENSE, p.toString());
}
Also used : Parameters(aQute.bnd.header.Parameters) BundleLicense(aQute.bnd.annotation.headers.BundleLicense)

Example 13 with Parameters

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

the class Builder method doDiff.

/**
	 * Diff this bundle to another bundle for the given packages.
	 * 
	 * @throws Exception
	 */
public void doDiff(@SuppressWarnings("unused") Jar dot) throws Exception {
    Parameters diffs = parseHeader(getProperty("-diff"));
    if (diffs.isEmpty())
        return;
    logger.debug("diff {}", diffs);
    if (tree == null)
        tree = differ.tree(this);
    for (Entry<String, Attrs> entry : diffs.entrySet()) {
        String path = entry.getKey();
        File file = getFile(path);
        if (!file.isFile()) {
            error("Diffing against %s that is not a file", file).header("-diff").context(path);
            continue;
        }
        boolean full = entry.getValue().get("--full") != null;
        boolean warning = entry.getValue().get("--warning") != null;
        Tree other = differ.tree(file);
        Diff api = tree.diff(other).get("<api>");
        Instructions instructions = new Instructions(entry.getValue().get("--pack"));
        logger.debug("diff against {} --full={} --pack={} --warning={}", file, full, instructions);
        for (Diff p : api.getChildren()) {
            String pname = p.getName();
            if (p.getType() == Type.PACKAGE && instructions.matches(pname)) {
                if (p.getDelta() != Delta.UNCHANGED) {
                    if (!full)
                        if (warning)
                            warning("Differ %s", p).header("-diff").context(path);
                        else
                            error("Differ %s", p).header("-diff").context(path);
                    else {
                        if (warning)
                            warning("Diff found a difference in %s for packages %s", file, instructions).header("-diff").context(path);
                        else
                            error("Diff found a difference in %s for packages %s", file, instructions).header("-diff").context(path);
                        show(p, "", warning);
                    }
                }
            }
        }
    }
}
Also used : Parameters(aQute.bnd.header.Parameters) Diff(aQute.bnd.service.diff.Diff) Attrs(aQute.bnd.header.Attrs) Tree(aQute.bnd.service.diff.Tree) File(java.io.File)

Example 14 with Parameters

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

the class Builder method doWab.

/**
	 * Turn this normal bundle in a web and add any resources.
	 * 
	 * @throws Exception
	 */
private Jar doWab(Jar dot) throws Exception {
    String wab = getProperty(WAB);
    String wablib = getProperty(WABLIB);
    if (wab == null && wablib == null)
        return dot;
    logger.debug("wab {} {}", wab, wablib);
    setBundleClasspath(append("WEB-INF/classes", getProperty(BUNDLE_CLASSPATH)));
    Set<String> paths = new HashSet<String>(dot.getResources().keySet());
    for (String path : paths) {
        if (path.indexOf('/') > 0 && !Character.isUpperCase(path.charAt(0))) {
            logger.debug("wab: moving: {}", path);
            dot.rename(path, "WEB-INF/classes/" + path);
        }
    }
    Parameters clauses = parseHeader(getProperty(WABLIB));
    for (String key : clauses.keySet()) {
        File f = getFile(key);
        addWabLib(dot, f);
    }
    doIncludeResource(dot, wab);
    return dot;
}
Also used : Parameters(aQute.bnd.header.Parameters) File(java.io.File) HashSet(java.util.HashSet)

Example 15 with Parameters

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

the class Builder method doIncludeResource.

private void doIncludeResource(Jar jar, String includes) throws Exception {
    Parameters clauses = parseHeader(includes);
    doIncludeResource(jar, clauses);
}
Also used : Parameters(aQute.bnd.header.Parameters)

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