Search in sources :

Example 51 with Parameters

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

the class VerifierTest method testCapability.

public static void testCapability() throws Exception {
    Parameters h = OSGiHeader.parseHeader("test; version.list:List < Version > = \"1.0, 1.1, 1.2\"; effective:=\"resolve\"; test =\"aName\";version : Version=\"1.0\"; long :Long=\"100\"; " + "double: Double=\"1.001\"; string:String =\"aString\";   " + "long.list : List <Long >=\"1, 2, 3, 4\";double.list: List< Double>= \"1.001, 1.002, 1.003\"; " + "string.list :List<String >= \"aString,bString,cString\"");
    assertEquals(Attrs.Type.VERSION, h.get("test").getType("version"));
    assertEquals(Attrs.Type.LONG, h.get("test").getType("long"));
    assertEquals(Attrs.Type.DOUBLE, h.get("test").getType("double"));
    assertEquals(Attrs.Type.STRING, h.get("test").getType("string"));
    assertEquals(Attrs.Type.STRING, h.get("test").getType("test"));
    assertEquals(Attrs.Type.LONGS, h.get("test").getType("long.list"));
    assertEquals(Attrs.Type.DOUBLES, h.get("test").getType("double.list"));
    assertEquals(Attrs.Type.STRINGS, h.get("test").getType("string.list"));
    assertEquals(Attrs.Type.VERSIONS, h.get("test").getType("version.list"));
}
Also used : Parameters(aQute.bnd.header.Parameters)

Example 52 with Parameters

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

the class ConnectionSettings method readSettings.

public void readSettings() throws Exception {
    File tmp = null;
    try {
        Parameters connectionSettings = new Parameters(mergeProperties(CONNECTION_SETTINGS), getParent());
        if (connectionSettings.isEmpty()) {
            File file = aQute.lib.io.IO.getFile(BND_CONNECTION_SETTINGS_XML);
            if (!file.isFile()) {
                file = aQute.lib.io.IO.getFile(M2_SETTINGS_XML);
                if (!file.isFile()) {
                    return;
                }
            }
            parse(file);
            return;
        }
        for (Map.Entry<String, Attrs> entry : connectionSettings.entrySet()) {
            String key = entry.getKey();
            if ("false".equalsIgnoreCase(key))
                continue;
            switch(key) {
                case "maven":
                    key = M2_SETTINGS_XML;
                    break;
                case "bnd":
                    key = BND_CONNECTION_SETTINGS_XML;
                    break;
                case "env":
                    Attrs attrs = entry.getValue();
                    String variable = attrs.get("var");
                    if (variable == null) {
                        getParent().error("Specified -connection-settings: %s, with 'env' but the 'var' parameter is no found", connectionSettings);
                    } else {
                        String value = System.getenv(key);
                        if (value != null) {
                            tmp = File.createTempFile("tmp", ".bnd");
                            IO.store(value, tmp);
                            key = tmp.getAbsolutePath();
                        } else
                            getParent().error("Specified -connection-settings: %s, but no such environment variable %s is found", connectionSettings, key);
                    }
                    break;
            }
            boolean ignoreError = false;
            if (key.startsWith("-")) {
                ignoreError = true;
                key = key.substring(1);
            }
            key = Processor.removeDuplicateMarker(key);
            if ("server".equals(key)) {
                parseServer(entry.getValue());
            } else {
                File file = getParent() != null ? IO.getFile(key) : getParent().getFile(key);
                if (!file.isFile()) {
                    if (!ignoreError) {
                        SetLocation error = getParent().error("Specified -connection-settings: %s, but no such file or is directory", file);
                        FileLine header = getParent().getHeader(CONNECTION_SETTINGS, key);
                        if (header != null)
                            header.set(error);
                    }
                } else
                    parse(file);
            }
        }
    } finally {
        if (tmp != null)
            IO.delete(tmp);
    }
}
Also used : Parameters(aQute.bnd.header.Parameters) Attrs(aQute.bnd.header.Attrs) File(java.io.File) Map(java.util.Map)

Example 53 with Parameters

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

the class DiffPluginImpl method setIgnore.

public void setIgnore(String diffignore) {
    if (diffignore == null) {
        localIgnore = null;
        return;
    }
    Parameters p = new Parameters(diffignore);
    localIgnore = new Instructions(p);
}
Also used : Parameters(aQute.bnd.header.Parameters) Instructions(aQute.bnd.osgi.Instructions)

Example 54 with Parameters

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

the class DiffPluginImpl method manifestElement.

/**
	 * Create an element for each manifest header. There are
	 * {@link #IGNORE_HEADERS} and {@link #MAJOR_HEADERS} that will be treated
	 * differently.
	 * 
	 * @param manifest
	 * @return the created {@code Element}
	 */
private Element manifestElement(Manifest manifest) {
    List<Element> result = new ArrayList<Element>();
    for (Object key : manifest.getMainAttributes().keySet()) {
        String header = key.toString();
        String value = manifest.getMainAttributes().getValue(header);
        if (IGNORE_HEADERS.contains(header))
            continue;
        if (localIgnore != null && localIgnore.matches(header)) {
            continue;
        }
        if (MAJOR_HEADERS.contains(header)) {
            if (header.equalsIgnoreCase(Constants.BUNDLE_VERSION)) {
                Version v = new Version(value).getWithoutQualifier();
                result.add(new Element(Type.HEADER, header + ":" + v.toString(), null, CHANGED, CHANGED, null));
            } else {
                Parameters clauses = OSGiHeader.parseHeader(value);
                Collection<Element> clausesDef = new ArrayList<Element>();
                for (Map.Entry<String, Attrs> clause : clauses.entrySet()) {
                    Collection<Element> parameterDef = new ArrayList<Element>();
                    for (Map.Entry<String, String> parameter : clause.getValue().entrySet()) {
                        String paramValue = parameter.getValue();
                        if (Constants.EXPORT_PACKAGE.equals(header) && Constants.USES_DIRECTIVE.equals(parameter.getKey())) {
                            ExtList<String> uses = ExtList.from(parameter.getValue());
                            Collections.sort(uses);
                            paramValue = uses.join();
                        }
                        parameterDef.add(new Element(Type.PARAMETER, parameter.getKey() + ":" + paramValue, null, CHANGED, CHANGED, null));
                    }
                    clausesDef.add(new Element(Type.CLAUSE, clause.getKey(), parameterDef, CHANGED, CHANGED, null));
                }
                result.add(new Element(Type.HEADER, header, clausesDef, CHANGED, CHANGED, null));
            }
        } else if (ORDERED_HEADERS.contains(header)) {
            ExtList<String> values = ExtList.from(value);
            Collections.sort(values);
            result.add(new Element(Type.HEADER, header + ":" + values.join(), null, CHANGED, CHANGED, null));
        } else {
            result.add(new Element(Type.HEADER, header + ":" + value, null, CHANGED, CHANGED, null));
        }
    }
    return new Element(Type.MANIFEST, "<manifest>", result, CHANGED, CHANGED, null);
}
Also used : Parameters(aQute.bnd.header.Parameters) ExtList(aQute.lib.collections.ExtList) ArrayList(java.util.ArrayList) Attrs(aQute.bnd.header.Attrs) Version(aQute.bnd.version.Version) Map(java.util.Map)

Example 55 with Parameters

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

the class Make method getMakeHeader.

Map<Instruction, Map<String, String>> getMakeHeader() {
    if (make != null)
        return make;
    make = Processor.newMap();
    Parameters make = builder.getMergedParameters(Builder.MAKE);
    for (Entry<String, Attrs> entry : make.entrySet()) {
        String pattern = Processor.removeDuplicateMarker(entry.getKey());
        Instruction instr = new Instruction(pattern);
        this.make.put(instr, entry.getValue());
    }
    return this.make;
}
Also used : Parameters(aQute.bnd.header.Parameters) Attrs(aQute.bnd.header.Attrs) Instruction(aQute.bnd.osgi.Instruction)

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