Search in sources :

Example 21 with Parameters

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

the class Analyzer method analyzeBundleClasspath.

private void analyzeBundleClasspath() throws Exception {
    Parameters bcp = getBundleClasspath();
    if (bcp.isEmpty()) {
        analyzeJar(dot, "", true);
    } else {
        boolean okToIncludeDirs = true;
        for (String path : bcp.keySet()) {
            if (dot.getDirectories().containsKey(path)) {
                okToIncludeDirs = false;
                break;
            }
        }
        for (String path : bcp.keySet()) {
            Attrs info = bcp.get(path);
            if (path.equals(".")) {
                analyzeJar(dot, "", okToIncludeDirs);
                continue;
            }
            //
            // There are 3 cases:
            // - embedded JAR file
            // - directory
            // - error
            //
            Resource resource = dot.getResource(path);
            if (resource != null) {
                try {
                    Jar jar = Jar.fromResource(path, resource);
                    addClose(jar);
                    analyzeJar(jar, "", true);
                } catch (Exception e) {
                    warning("Invalid bundle classpath entry: %s: %s", path, e);
                }
            } else {
                if (dot.getDirectories().containsKey(path)) {
                    // class path twice.
                    if (bcp.containsKey("."))
                        warning(Constants.BUNDLE_CLASSPATH + " uses a directory '%s' as well as '.'. This means bnd does not know if a directory is a package.", path);
                    analyzeJar(dot, Processor.appendPath(path) + "/", true);
                } else {
                    if (!"optional".equals(info.get(RESOLUTION_DIRECTIVE)))
                        warning("No sub JAR or directory %s", path);
                }
            }
        }
    }
}
Also used : Parameters(aQute.bnd.header.Parameters) Attrs(aQute.bnd.header.Attrs) ParseException(java.text.ParseException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException)

Example 22 with Parameters

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

the class RemoteProjectLauncherPlugin method update.

/**
	 * Called when a change in the IDE is detected. We will then upate from the
	 * project and then update the remote framework.
	 */
@Override
public void update() throws Exception {
    updateFromProject();
    Parameters runremote = new Parameters(getProject().getProperty(Constants.RUNREMOTE), getProject());
    for (RunSessionImpl session : sessions) try {
        Attrs attrs = runremote.get(session.getName());
        RunRemoteDTO dto = Converter.cnv(RunRemoteDTO.class, attrs);
        session.update(dto);
    } catch (Exception e) {
        getProject().exception(e, "Failed to update session %s", session.getName());
    }
}
Also used : Parameters(aQute.bnd.header.Parameters) Attrs(aQute.bnd.header.Attrs)

Example 23 with Parameters

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

the class bnd method doPrint.

private void doPrint(Jar jar, int options, printOptions po) throws ZipException, IOException, Exception {
    if ((options & VERIFY) != 0) {
        Verifier verifier = new Verifier(jar);
        verifier.setPedantic(isPedantic());
        verifier.verify();
        getInfo(verifier);
    }
    if ((options & MANIFEST) != 0) {
        Manifest manifest = jar.getManifest();
        if (manifest == null)
            warning("JAR has no manifest %s", jar);
        else {
            err.println("[MANIFEST " + jar.getName() + "]");
            printManifest(manifest);
        }
        out.println();
    }
    if ((options & IMPEXP) != 0) {
        out.println("[IMPEXP]");
        Manifest m = jar.getManifest();
        Domain domain = Domain.domain(m);
        if (m != null) {
            Parameters imports = domain.getImportPackage();
            Parameters exports = domain.getExportPackage();
            for (String p : exports.keySet()) {
                if (imports.containsKey(p)) {
                    Attrs attrs = imports.get(p);
                    if (attrs.containsKey(VERSION_ATTRIBUTE)) {
                        exports.get(p).put("imported-as", attrs.get(VERSION_ATTRIBUTE));
                    }
                }
            }
            print(Constants.IMPORT_PACKAGE, new TreeMap<String, Attrs>(imports));
            print(Constants.EXPORT_PACKAGE, new TreeMap<String, Attrs>(exports));
        } else
            warning("File has no manifest");
    }
    if ((options & CAPABILITIES) != 0) {
        out.println("[CAPABILITIES]");
        Manifest m = jar.getManifest();
        Domain domain = Domain.domain(m);
        if (m != null) {
            Parameters provide = domain.getProvideCapability();
            Parameters require = domain.getRequireCapability();
            print(Constants.PROVIDE_CAPABILITY, new TreeMap<String, Attrs>(provide));
            print(Constants.REQUIRE_CAPABILITY, new TreeMap<String, Attrs>(require));
        } else
            warning("File has no manifest");
    }
    if ((options & (USES | USEDBY | API)) != 0) {
        out.println();
        try (Analyzer analyzer = new Analyzer()) {
            analyzer.setPedantic(isPedantic());
            analyzer.setJar(jar);
            Manifest m = jar.getManifest();
            if (m != null) {
                String s = m.getMainAttributes().getValue(Constants.EXPORT_PACKAGE);
                if (s != null)
                    analyzer.setExportPackage(s);
            }
            analyzer.analyze();
            boolean java = po.java();
            Packages exports = analyzer.getExports();
            if ((options & API) != 0) {
                Map<PackageRef, List<PackageRef>> apiUses = analyzer.cleanupUses(analyzer.getAPIUses(), !po.java());
                if (!po.xport()) {
                    if (exports.isEmpty())
                        warning("Not filtering on exported only since exports are empty");
                    else
                        apiUses.keySet().retainAll(analyzer.getExports().keySet());
                }
                out.println("[API USES]");
                printMultiMap(apiUses);
                Set<PackageRef> privates = analyzer.getPrivates();
                for (PackageRef export : exports.keySet()) {
                    Map<Def, List<TypeRef>> xRef = analyzer.getXRef(export, privates, Modifier.PROTECTED + Modifier.PUBLIC);
                    if (!xRef.isEmpty()) {
                        out.println();
                        out.printf("%s refers to private Packages (not good)\n\n", export);
                        for (Entry<Def, List<TypeRef>> e : xRef.entrySet()) {
                            TreeSet<PackageRef> refs = new TreeSet<Descriptors.PackageRef>();
                            for (TypeRef ref : e.getValue()) refs.add(ref.getPackageRef());
                            refs.retainAll(privates);
                            //
                            out.printf(//
                            "%60s %-40s %s\n", //
                            e.getKey().getOwnerType().getFQN(), e.getKey().getName(), refs);
                        }
                        out.println();
                    }
                }
                out.println();
            }
            Map<PackageRef, List<PackageRef>> uses = analyzer.cleanupUses(analyzer.getUses(), !po.java());
            if ((options & USES) != 0) {
                out.println("[USES]");
                printMultiMap(uses);
                out.println();
            }
            if ((options & USEDBY) != 0) {
                out.println("[USEDBY]");
                MultiMap<PackageRef, PackageRef> usedBy = new MultiMap<Descriptors.PackageRef, Descriptors.PackageRef>(uses).transpose();
                printMultiMap(usedBy);
            }
        }
    }
    if ((options & COMPONENT) != 0) {
        printComponents(out, jar);
    }
    if ((options & METATYPE) != 0) {
        printMetatype(out, jar);
    }
    if ((options & LIST) != 0) {
        out.println("[LIST]");
        for (Map.Entry<String, Map<String, Resource>> entry : jar.getDirectories().entrySet()) {
            String name = entry.getKey();
            Map<String, Resource> contents = entry.getValue();
            out.println(name);
            if (contents != null) {
                for (String element : contents.keySet()) {
                    int n = element.lastIndexOf('/');
                    if (n > 0)
                        element = element.substring(n + 1);
                    out.print("  ");
                    out.print(element);
                    String path = element;
                    if (name.length() != 0)
                        path = name + "/" + element;
                    Resource r = contents.get(path);
                    if (r != null) {
                        String extra = r.getExtra();
                        if (extra != null) {
                            out.print(" extra='" + escapeUnicode(extra) + "'");
                        }
                    }
                    out.println();
                }
            } else {
                out.println(name + " <no contents>");
            }
        }
        out.println();
    }
}
Also used : TypeRef(aQute.bnd.osgi.Descriptors.TypeRef) Attrs(aQute.bnd.header.Attrs) Verifier(aQute.bnd.osgi.Verifier) Analyzer(aQute.bnd.osgi.Analyzer) Packages(aQute.bnd.osgi.Packages) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) ExtList(aQute.lib.collections.ExtList) List(java.util.List) SortedList(aQute.lib.collections.SortedList) Descriptors(aQute.bnd.osgi.Descriptors) PackageRef(aQute.bnd.osgi.Descriptors.PackageRef) Parameters(aQute.bnd.header.Parameters) Def(aQute.bnd.osgi.Clazz.Def) FileResource(aQute.bnd.osgi.FileResource) Resource(aQute.bnd.osgi.Resource) Manifest(java.util.jar.Manifest) PomFromManifest(aQute.bnd.maven.PomFromManifest) Domain(aQute.bnd.osgi.Domain) MultiMap(aQute.lib.collections.MultiMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap)

Example 24 with Parameters

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

the class bnd method _bsn2url.

public void _bsn2url(Bsn2UrlOptions opts) throws Exception {
    Project p = getProject(opts.project());
    if (p == null) {
        error("You need to be in a project or specify the project with -p/--project");
        return;
    }
    MultiMap<String, Version> revisions = new MultiMap<String, Version>();
    for (RepositoryPlugin repo : p.getPlugins(RepositoryPlugin.class)) {
        if (!(repo instanceof InfoRepository))
            continue;
        for (String bsn : repo.list(null)) {
            revisions.addAll(bsn, repo.versions(bsn));
        }
    }
    for (List<Version> versions : revisions.values()) {
        Collections.sort(versions, Collections.reverseOrder());
    }
    List<String> files = opts._arguments();
    for (String f : files) {
        try (BufferedReader r = IO.reader(getFile(f))) {
            String line;
            nextLine: while ((line = r.readLine()) != null) {
                Matcher matcher = LINE_P.matcher(line);
                if (!matcher.matches())
                    continue nextLine;
                line = matcher.group(1);
                Parameters bundles = new Parameters(line, this);
                for (Map.Entry<String, Attrs> entry : bundles.entrySet()) {
                    String bsn = entry.getKey();
                    VersionRange range = new VersionRange(entry.getValue().getVersion());
                    List<Version> versions = revisions.get(bsn);
                    if (versions == null) {
                        error("No for versions for %s", bsn);
                        break nextLine;
                    }
                    for (Version version : versions) {
                        if (range.includes(version)) {
                            for (RepositoryPlugin repo : p.getPlugins(RepositoryPlugin.class)) {
                                if (!(repo instanceof InfoRepository))
                                    continue;
                                InfoRepository rp = (InfoRepository) repo;
                                ResourceDescriptor descriptor = rp.getDescriptor(bsn, version);
                                if (descriptor == null) {
                                    error("Found bundle, but no descriptor %s;version=%s", bsn, version);
                                    return;
                                }
                                out.println(descriptor.url + " #" + descriptor.bsn + ";version=" + descriptor.version);
                            }
                        }
                    }
                }
            }
        } catch (Exception e) {
            error("failed to create url list from file %s : %s", f, e);
        }
    }
}
Also used : Parameters(aQute.bnd.header.Parameters) Matcher(java.util.regex.Matcher) RepositoryPlugin(aQute.bnd.service.RepositoryPlugin) VersionRange(aQute.bnd.version.VersionRange) InfoRepository(aQute.bnd.service.repository.InfoRepository) InvocationTargetException(java.lang.reflect.InvocationTargetException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException) XPathExpressionException(javax.xml.xpath.XPathExpressionException) ZipException(java.util.zip.ZipException) Project(aQute.bnd.build.Project) MultiMap(aQute.lib.collections.MultiMap) Entry(java.util.Map.Entry) Version(aQute.bnd.version.Version) BufferedReader(java.io.BufferedReader) ArrayList(java.util.ArrayList) ExtList(aQute.lib.collections.ExtList) List(java.util.List) SortedList(aQute.lib.collections.SortedList) ResourceDescriptor(aQute.bnd.service.repository.SearchableRepository.ResourceDescriptor)

Example 25 with Parameters

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

the class bnd method printComponents.

/**
	 * Print the components in this JAR.
	 * 
	 * @param jar
	 */
private void printComponents(PrintStream out, Jar jar) throws Exception {
    out.println("[COMPONENTS]");
    Manifest manifest = jar.getManifest();
    if (manifest == null) {
        out.println("No manifest");
        return;
    }
    String componentHeader = manifest.getMainAttributes().getValue(Constants.SERVICE_COMPONENT);
    Parameters clauses = new Parameters(componentHeader, this);
    for (String path : clauses.keySet()) {
        out.println(path);
        Resource r = jar.getResource(path);
        if (r != null) {
            InputStreamReader ir = new InputStreamReader(r.openInputStream(), Constants.DEFAULT_CHARSET);
            OutputStreamWriter or = new OutputStreamWriter(out, Constants.DEFAULT_CHARSET);
            try {
                IO.copy(ir, or);
            } finally {
                or.flush();
                ir.close();
            }
        } else {
            out.println("  - no resource");
            warning("No Resource found for service component: %s", path);
        }
    }
    out.println();
}
Also used : Parameters(aQute.bnd.header.Parameters) InputStreamReader(java.io.InputStreamReader) FileResource(aQute.bnd.osgi.FileResource) Resource(aQute.bnd.osgi.Resource) OutputStreamWriter(java.io.OutputStreamWriter) Manifest(java.util.jar.Manifest) PomFromManifest(aQute.bnd.maven.PomFromManifest)

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