Search in sources :

Example 1 with ExtList

use of aQute.lib.collections.ExtList 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 2 with ExtList

use of aQute.lib.collections.ExtList in project bnd by bndtools.

the class ReplacerAdapter method _fmodified.

public String _fmodified(String[] args) throws Exception {
    verifyCommand(args, _fmodifiedHelp, null, 2, Integer.MAX_VALUE);
    long time = 0;
    Collection<String> names = new ExtList<String>();
    for (int i = 1; i < args.length; i++) {
        names.addAll(ExtList.from(args[i]));
    }
    for (String name : names) {
        File f = new File(name);
        if (f.exists() && f.lastModified() > time)
            time = f.lastModified();
    }
    return "" + time;
}
Also used : ExtList(aQute.lib.collections.ExtList) File(java.io.File)

Example 3 with ExtList

use of aQute.lib.collections.ExtList in project bnd by bndtools.

the class ReplacerAdapter method replace.

protected String replace(String key, Link link) {
    if (link != null && link.contains(key))
        return "${infinite:" + link + "}";
    if (key != null) {
        key = key.trim();
        if (key.length() > 0) {
            Domain source = domain;
            String value = null;
            if (key.indexOf(';') < 0) {
                if (WILDCARD.matcher(key).find()) {
                    Glob ins = new Glob(key);
                    StringBuilder sb = new StringBuilder();
                    String del = "";
                    for (String k : getAllKeys()) {
                        if (ins.matcher(k).find()) {
                            String v = replace(k, new Link(source, link, key));
                            if (v != null) {
                                sb.append(del);
                                del = ",";
                                sb.append(v);
                            }
                        }
                    }
                    return sb.toString();
                }
                while (value == null && source != null) {
                    value = source.getMap().get(key);
                    if (value != null)
                        return process(value, new Link(source, link, key));
                    source = source.getParent();
                }
            }
            value = doCommands(key, link);
            if (value != null)
                return process(value, new Link(source, link, key));
            if (key != null && key.trim().length() > 0) {
                value = System.getProperty(key);
                if (value != null)
                    return value;
            }
            if (key.indexOf(';') >= 0) {
                String[] parts = key.split(";");
                if (parts.length > 1) {
                    if (parts.length >= 16) {
                        error("too many arguments for template: %s, max is 16", key);
                    }
                    String template = domain.getMap().get(parts[0]);
                    if (template != null) {
                        final Domain old = domain;
                        try {
                            final Map<String, String> args = new HashMap<String, String>();
                            for (int i = 0; i < 16; i++) {
                                args.put("" + i, i < parts.length ? parts[i] : "null");
                            }
                            domain = new Domain() {

                                public Map<String, String> getMap() {
                                    return args;
                                }

                                public Domain getParent() {
                                    return old;
                                }
                            };
                            ExtList<String> args0 = new ExtList<String>(parts);
                            args0.remove(0);
                            args.put("#", args0.join());
                            value = process(template, new Link(domain, link, key));
                            if (value != null)
                                return value;
                        } finally {
                            domain = old;
                        }
                    }
                }
            }
            if (!flattening && !key.equals("@"))
                reporter.warning("No translation found for macro: %s", key);
        } else {
            reporter.warning("Found empty macro key");
        }
    } else {
        reporter.warning("Found null macro key");
    }
    return "${" + key + "}";
}
Also used : HashMap(java.util.HashMap) ExtList(aQute.lib.collections.ExtList) Glob(aQute.libg.glob.Glob) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with ExtList

use of aQute.lib.collections.ExtList in project bnd by bndtools.

the class Platform method process.

protected void process(String resource, CommandData data, String path, Map<String, String> map, String... extra) throws Exception {
    File file = new File(path);
    copy(getClass().getResourceAsStream(resource), file);
    Sed sed = new Sed(file);
    sed.setBackup(false);
    if (data.title == null || data.title.trim().length() == 0)
        data.title = data.name;
    //
    // Allow commands to be done in java or javaw
    //
    sed.replace("%java%", data.windows ? "javaw" : "java");
    for (Field key : data.getClass().getFields()) {
        Object value = key.get(data);
        if (value == null) {
            value = "";
        }
        // executed as one command and thus logged as one command
        if ("epilog".equals(key.getName()) || "prolog".equals(key.getName())) {
            String s = (String) value;
            if (s != null && s.trim().length() > 0) {
                value = "(" + s + ")";
            }
        }
        String v = "" + value;
        v = v.replace("\\", "\\\\");
        sed.replace("%" + key.getName() + "%", v);
    }
    ExtList<String> deps = new ExtList<String>();
    for (byte[] dependency : data.dependencies) {
        ArtifactData d = jpm.get(dependency);
        deps.add(d.file);
    }
    for (String x : extra) {
        deps.add(x);
    }
    String classpath = deps.join(File.pathSeparator);
    sed.replace("%classpath%", classpath.replace("\\", "\\\\"));
    if (map != null) {
        StringBuilder sb = new StringBuilder();
        String del = "-D";
        for (Map.Entry<String, String> e : map.entrySet()) {
            sed.replace("%" + e.getKey() + "%", e.getValue());
            sb.append(del).append(e.getKey()).append("=\"").append(e.getValue()).append("\"");
            del = " -D";
        }
        sed.replace("%defines%", sb.toString());
    } else {
        sed.replace("%defines%", "");
    }
    sed.doIt();
}
Also used : Field(java.lang.reflect.Field) Sed(aQute.libg.sed.Sed) ExtList(aQute.lib.collections.ExtList) File(java.io.File) Map(java.util.Map) ArtifactData(aQute.jpm.lib.ArtifactData)

Example 5 with ExtList

use of aQute.lib.collections.ExtList in project bnd by bndtools.

the class Main method run.

/**
	 * Main entry for the command line
	 * 
	 * @param args
	 * @throws Exception
	 */
public void run(String[] args) throws Exception {
    CommandLine cl = new CommandLine(this);
    ExtList<String> list = new ExtList<String>(args);
    String help = cl.execute(this, "jpm", list);
    check();
    if (help != null)
        err.println(help);
}
Also used : CommandLine(aQute.lib.getopt.CommandLine) ExtList(aQute.lib.collections.ExtList)

Aggregations

ExtList (aQute.lib.collections.ExtList)11 File (java.io.File)5 Map (java.util.Map)4 Attrs (aQute.bnd.header.Attrs)3 Parameters (aQute.bnd.header.Parameters)3 CommandLine (aQute.lib.getopt.CommandLine)2 Glob (aQute.libg.glob.Glob)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 JarFile (java.util.jar.JarFile)2 Version (aQute.bnd.version.Version)1 ArtifactData (aQute.jpm.lib.ArtifactData)1 IO.createTempFile (aQute.lib.io.IO.createTempFile)1 SpringXMLType (aQute.lib.spring.SpringXMLType)1 Sed (aQute.libg.sed.Sed)1 SetLocation (aQute.service.reporter.Reporter.SetLocation)1 Field (java.lang.reflect.Field)1 LinkedHashMap (java.util.LinkedHashMap)1 TreeMap (java.util.TreeMap)1 TreeSet (java.util.TreeSet)1