Search in sources :

Example 31 with Parameters

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

the class HeaderClauseListConverter method convert.

public List<R> convert(String input) throws IllegalArgumentException {
    if (input == null)
        return null;
    List<R> result = new ArrayList<R>();
    Parameters header = new Parameters(input);
    for (Entry<String, Attrs> entry : header.entrySet()) {
        String key = Processor.removeDuplicateMarker(entry.getKey());
        HeaderClause clause = new HeaderClause(key, entry.getValue());
        result.add(itemConverter.convert(clause));
    }
    return result;
}
Also used : Parameters(aQute.bnd.header.Parameters) ArrayList(java.util.ArrayList) Attrs(aQute.bnd.header.Attrs) HeaderClause(aQute.bnd.build.model.clauses.HeaderClause)

Example 32 with Parameters

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

the class ProjectLauncher method addClasspath.

public void addClasspath(Container container) throws Exception {
    if (container.getError() != null) {
        project.error("Cannot launch because %s has reported %s", container.getProject(), container.getError());
    } else {
        Collection<Container> members = container.getMembers();
        for (Container m : members) {
            String path = m.getFile().getAbsolutePath();
            if (!classpath.contains(path)) {
                Manifest manifest = m.getManifest();
                if (manifest != null) {
                    // We are looking for any agents, used if
                    // -javaagent=true is set
                    String agentClassName = manifest.getMainAttributes().getValue("Premain-Class");
                    if (agentClassName != null) {
                        String agent = path;
                        if (container.getAttributes().get("agent") != null) {
                            agent += "=" + container.getAttributes().get("agent");
                        }
                        agents.add(path);
                    }
                    Parameters exports = project.parseHeader(manifest.getMainAttributes().getValue(Constants.EXPORT_PACKAGE));
                    for (Entry<String, Attrs> e : exports.entrySet()) {
                        if (!runsystempackages.containsKey(e.getKey()))
                            runsystempackages.put(e.getKey(), e.getValue());
                    }
                    // Allow activators on the runpath. They are called
                    // after
                    // the framework is completely initialized wit the
                    // system
                    // context.
                    String activator = manifest.getMainAttributes().getValue(EMBEDDED_ACTIVATOR);
                    if (activator != null)
                        activators.add(activator);
                }
                classpath.add(path);
            }
        }
    }
}
Also used : Parameters(aQute.bnd.header.Parameters) Attrs(aQute.bnd.header.Attrs) Manifest(java.util.jar.Manifest)

Example 33 with Parameters

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

the class ProjectLauncher method updateFromProject.

/**
	 * Collect all the aspect from the project and set the local fields from
	 * them. Should be called
	 * 
	 * @throws Exception
	 */
protected void updateFromProject() throws Exception {
    setCwd(project.getBase());
    // pkr: could not use this because this is killing the runtests.
    // project.refresh();
    runbundles.clear();
    Collection<Container> run = project.getRunbundles();
    for (Container container : run) {
        File file = container.getFile();
        if (file != null && (file.isFile() || file.isDirectory())) {
            runbundles.add(file.getAbsolutePath());
        } else {
            project.error("Bundle file \"%s\" does not exist, given error is %s", file, container.getError());
        }
    }
    if (project.getRunBuilds()) {
        File[] builds = project.getBuildFiles(true);
        if (builds != null)
            for (File file : builds) runbundles.add(file.getAbsolutePath());
    }
    Collection<Container> runpath = project.getRunpath();
    runsystempackages = new Parameters(project.mergeProperties(Constants.RUNSYSTEMPACKAGES), project);
    runsystemcapabilities = new Parameters(project.mergeProperties(Constants.RUNSYSTEMCAPABILITIES), project);
    framework = getRunframework(project.getProperty(Constants.RUNFRAMEWORK));
    timeout = Processor.getDuration(project.getProperty(Constants.RUNTIMEOUT), 0);
    trace = Processor.isTrue(project.getProperty(Constants.RUNTRACE));
    runpath.addAll(project.getRunFw());
    for (Container c : runpath) {
        addClasspath(c);
    }
    runvm.addAll(project.getRunVM());
    runprogramargs.addAll(project.getRunProgramArgs());
    runproperties = project.getRunProperties();
    storageDir = project.getRunStorage();
    if (storageDir == null) {
        storageDir = new File(project.getTarget(), "fw");
    }
    setKeep(project.getRunKeep());
}
Also used : Parameters(aQute.bnd.header.Parameters) File(java.io.File)

Example 34 with Parameters

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

the class Verifier method verifyExports.

/**
	 * Verify that the exports only use versions.
	 */
private void verifyExports() {
    if (isStrict()) {
        Parameters map = parseHeader(manifest.getMainAttributes().getValue(Constants.EXPORT_PACKAGE));
        Set<String> noexports = new HashSet<String>();
        for (Entry<String, Attrs> e : map.entrySet()) {
            if (!analyzer.getContained().containsFQN(e.getKey())) {
                SetLocation warning = warning("Export-Package or -exportcontents refers to missing package '%s'", e.getKey());
                warning.header(Constants.EXPORT_PACKAGE + "|" + Constants.EXPORT_CONTENTS);
                warning.context(e.getKey());
            }
            String version = e.getValue().get(Constants.VERSION_ATTRIBUTE);
            if (version == null) {
                noexports.add(e.getKey());
            } else {
                if (!VERSION.matcher(version).matches()) {
                    Location location;
                    if (VERSIONRANGE.matcher(version).matches()) {
                        location = error("Export Package %s version is a range: %s; Exports do not allow for ranges.", e.getKey(), version).location();
                    } else {
                        location = error("Export Package %s version has invalid syntax: %s", e.getKey(), version).location();
                    }
                    location.header = Constants.EXPORT_PACKAGE;
                    location.context = e.getKey();
                }
            }
            if (e.getValue().containsKey(Constants.SPECIFICATION_VERSION)) {
                Location location = error("Export Package %s uses deprecated specification-version instead of version", e.getKey()).location();
                location.header = Constants.EXPORT_PACKAGE;
                location.context = e.getKey();
            }
            String mandatory = e.getValue().get(Constants.MANDATORY_DIRECTIVE);
            if (mandatory != null) {
                Set<String> missing = new HashSet<String>(split(mandatory));
                missing.removeAll(e.getValue().keySet());
                if (!missing.isEmpty()) {
                    Location location = error("Export Package %s misses mandatory attribute: %s", e.getKey(), missing).location();
                    location.header = Constants.EXPORT_PACKAGE;
                    location.context = e.getKey();
                }
            }
        }
        if (!noexports.isEmpty()) {
            Location location = error("Export Package clauses without version range: %s", noexports).location();
            location.header = Constants.EXPORT_PACKAGE;
        }
    }
}
Also used : Parameters(aQute.bnd.header.Parameters) Attrs(aQute.bnd.header.Attrs) HashSet(java.util.HashSet)

Example 35 with Parameters

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

the class Processor method doIncludes.

/**
	 * Inspect the properties and if you find -includes parse the line included
	 * manifest files or properties files. The files are relative from the given
	 * base, this is normally the base for the analyzer.
	 *
	 * @param ubase
	 * @param p
	 * @param done
	 * @throws IOException
	 * @throws IOException
	 */
private void doIncludes(File ubase, Properties p) {
    String includes = p.getProperty(INCLUDE);
    if (includes != null) {
        includes = getReplacer().process(includes);
        p.remove(INCLUDE);
        Collection<String> clauses = new Parameters(includes, this).keySet();
        for (String value : clauses) {
            boolean fileMustExist = true;
            boolean overwrite = true;
            while (true) {
                if (value.startsWith("-")) {
                    fileMustExist = false;
                    value = value.substring(1).trim();
                } else if (value.startsWith("~")) {
                    // Overwrite properties!
                    overwrite = false;
                    value = value.substring(1).trim();
                } else
                    break;
            }
            try {
                File file = getFile(ubase, value).getAbsoluteFile();
                if (!file.isFile()) {
                    try {
                        URL url = new URL(value);
                        int n = value.lastIndexOf('.');
                        String ext = ".jar";
                        if (n >= 0)
                            ext = value.substring(n);
                        File tmp = File.createTempFile("url", ext);
                        try {
                            IO.copy(url.openStream(), tmp);
                            doIncludeFile(tmp, overwrite, p);
                        } finally {
                            IO.delete(tmp);
                        }
                    } catch (MalformedURLException mue) {
                        if (fileMustExist)
                            error("Included file %s %s", file, (file.isDirectory() ? "is directory" : "does not exist"));
                    } catch (Exception e) {
                        if (fileMustExist)
                            exception(e, "Error in processing included URL: %s", value);
                    }
                } else
                    doIncludeFile(file, overwrite, p);
            } catch (Exception e) {
                if (fileMustExist)
                    exception(e, "Error in processing included file: %s", value);
            }
        }
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) Parameters(aQute.bnd.header.Parameters) JarFile(java.util.jar.JarFile) File(java.io.File) URL(java.net.URL) FileNotFoundException(java.io.FileNotFoundException) InvocationTargetException(java.lang.reflect.InvocationTargetException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

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