Package aQute.bnd.osgi

Examples of aQute.bnd.osgi.Analyzer


   *
   * @param props   the properties
   * @param project the maven project.
   */
  static void postProcessAdditionalProperties(@NotNull Map<String, String> props, @NotNull MavenProject project) {
    Analyzer myFakeAnalyzer = new FakeAnalyzer(props);
    Collection<MavenArtifact> dependencies = collectDependencies(props, project);

    DependencyEmbedder embedder = new DependencyEmbedder(dependencies);
    try {
      embedder.processHeaders(myFakeAnalyzer);
View Full Code Here


            if (rc.isEmpty()) {
                break;
            }
            String value = (String) bundle.getHeaders().get("Export-Package");
            if (Strings.notEmpty(value)) {
                Parameters values = new Analyzer().parseHeader(value);
                for (String packageName : packages) {
                    Map<String, String> map = values.get(packageName);
                    if (map != null) {
                        String version = map.get("version");
                        if (version != null) {
View Full Code Here

    public static String getOSGiPackageVersion(DependencyTree dependency, String packageName) {
        // lets find the export packages and use the version from that
        if (dependency.isBundle()) {
            String exportPackages = dependency.getManifestEntry("Export-Package");
            if (notEmpty(exportPackages)) {
                Parameters values = new Analyzer().parseHeader(exportPackages);
                Map<String, String> map = values.get(packageName);
                if (map != null) {
                    String version = map.get("version");
                    if (version != null) {
                        return version;
View Full Code Here

            for (DependencyTree dependency : info.getBundles()) {
                if (dependency.isBundle()) {
                    // Expand the actual imports list with imports of our dependencies
                    String importPackages = dependency.getManifestEntry(Analyzer.IMPORT_PACKAGE);
                    if( notEmpty(importPackages) ) {
                        Parameters values = new Analyzer().parseHeader(importPackages);
                        for (Map.Entry<String, Attrs> entry : values.entrySet()) {
                            String res = entry.getValue().get("resolution:");
                            if( !"optional".equals(res) ) {
                                // add all the non-optional deps..
                                actualImports.add(entry.getKey());
View Full Code Here

        importExportFilter  = DependencyTreeFilters.parse(join(importExportFilterPatterns, " "));

        bundleClassPath.addAll(Strings.splitAsList(getManifestProperty(ServiceConstants.INSTR_BUNDLE_CLASSPATH), ","));
        requireBundles.addAll(Strings.splitAsList(getManifestProperty(ServiceConstants.INSTR_REQUIRE_BUNDLE), ","));

        importPackages.putAll(new Analyzer().parseHeader(emptyIfNull(getManifestProperty(ServiceConstants.INSTR_IMPORT_PACKAGE))));


        Filter<Dependency> optionalFilter = DependencyFilters.parseExcludeOptionalFilter(join(optionalDependencyPatterns, " "));
        Filter<Dependency> excludeFilter = DependencyFilters.parseExcludeFilter(join(excludeDependencyFilterPatterns, " "), optionalFilter);
View Full Code Here

    protected void importAllExportedPackages(DependencyTree dependencyTree) {
        try {
            String text = dependencyTree.getManifestEntry(ServiceConstants.INSTR_EXPORT_PACKAGE);
            if (text != null && text.length() > 0) {
                Parameters map = new Analyzer().parseHeader(text);
                for (Map.Entry<String, Attrs> entry : map.entrySet()) {
                    String key = entry.getKey();
                    Map<String, String> values = entry.getValue();
                    // TODO add optional resolution if this dependency is otional??
View Full Code Here

            properties.putAll(instructions);

            properties.put("Generated-By-FAB-From", jarInfo);
            properties.put(Analyzer.PLUGIN, ANALYZER_PLUGIN_NAMES);

            final Analyzer analyzer = new Analyzer();
            analyzer.setJar(jar);
            analyzer.setProperties(properties);

            // now lets add all the new embedded jars
            for (Map.Entry<String, Object> entry : embeddedResources.entrySet()) {
                String path = entry.getKey();
                Object value = entry.getValue();
                Resource resource = toResource(value);
                if (resource != null) {
                    jar.putResource(path, resource);
                    try {
                        File file = toFile(value);
                        analyzer.addClasspath(file);
                    } catch (IOException e) {
                        LOG.warn("Failed to get File for " + value + ". " + e, e);
                    }
                }
            }


            if (manifest != null && OverwriteMode.MERGE == overwriteMode) {
                analyzer.mergeManifest(manifest);
            }
            checkMandatoryProperties(analyzer, jar, jarInfo);

            Manifest newManifest = analyzer.calcManifest();
            jar.setManifest( newManifest );

            Attributes main = jar.getManifest().getMainAttributes();

            // Hack to add back META-INF imports
            String importPackage = main.getValue(Analyzer.IMPORT_PACKAGE);
            for (Descriptors.PackageRef key : analyzer.getReferred().keySet()) {
                if (key.getFQN().startsWith("META-INF.")) {
                    if (importPackage == null) {
                        importPackage = key.getFQN();
                    } else {
                        importPackage += "," + key.getFQN();
                    }
                }
            }
            if (importPackage != null) {
                main.putValue(Analyzer.IMPORT_PACKAGE, importPackage);
            }

            String importPackages = emptyIfNull(main.getValue(Analyzer.IMPORT_PACKAGE));
            Parameters values = new Analyzer().parseHeader(importPackages);

            // add any missing version clauses
            if (versionResolver != null) {
                for (Map.Entry<String, Attrs> entry : values.entrySet()) {
                    String packageName = entry.getKey();
                    Map<String, String> packageValues = entry.getValue();
                    if (!packageValues.containsKey("version")) {
                        String version = versionResolver.resolvePackageVersion(packageName);
                        if (version != null) {
                            packageValues.put("version", version);
                        }
                    }
                }
            }

            // Merge in the extra imports - lets not add versions to extra imports as they come from exports which might not have versions.
            for (Map.Entry<String, Map<String, String>> entry : extraImportPackages.entrySet()) {
                Map<String, String> original = values.get(entry.getKey());
                if (original == null) {
                    original = entry.getValue();
                } else {
                    original.putAll(entry.getValue());
                }
                Attrs newAttrs = new Attrs();
                newAttrs.putAll(original);
                values.put(entry.getKey(), newAttrs);
            }

            // lets remove any excluded import packages
            String excludedPackagesText = main.getValue(ServiceConstants.INSTR_FAB_EXCLUDE_IMPORTS_PACKAGE);
            if (notEmpty(excludedPackagesText)) {
                StringTokenizer e = new StringTokenizer(excludedPackagesText);
                while (e.hasMoreTokens()) {
                    String expression = e.nextToken();
                    String ignore = expression;
                    if (ignore.endsWith("*")) {
                        do {
                            ignore = ignore.substring(0, ignore.length() - 1);
                        } while (ignore.endsWith("*"));

                        if (ignore.length() == 0) {
                            LOG.debug("Ignoring all imports due to %s value of %s", ServiceConstants.INSTR_FAB_EXCLUDE_IMPORTS_PACKAGE, expression);
                            values.clear();
                        } else {
                            List<String> packageNames = new ArrayList<String>(values.keySet());
                            for (String packageName : packageNames) {
                                if (packageName.equals(ignore) || packageName.startsWith(ignore)) {
                                    if (LOG.isDebugEnabled()) {
                                        LOG.debug("Ignoring package " + packageName + " due to " + ServiceConstants.INSTR_FAB_EXCLUDE_IMPORTS_PACKAGE + " value of " + expression);
                                    }
                                    values.remove(packageName);
                                }
                            }
                        }
                    } else {
                        if (LOG.isDebugEnabled()) {
                            LOG.debug("Ignoring package " + ignore + " due to " + ServiceConstants.INSTR_FAB_EXCLUDE_IMPORTS_PACKAGE + " header");
                        }
                        values.remove(ignore);
                    }
                }
            }

            // lets remove optional dependency if they are exported from a non-optional dependency...
            for (Map.Entry<String, Attrs> entry : values.entrySet()) {
                String packageName = entry.getKey();
                Map<String, String> map = entry.getValue();
                String res = map.get("resolution:");
                if ("optional".equals(res)) {
                    if (!versionResolver.isPackageOptional(packageName)) {
                        map.remove("resolution:");
                        res = null;
                    }
                }
                if (!"optional".equals(res)) {
                    // add all the non-optional deps..
                    actualImports.add(packageName);
                }
            }

            // TODO do we really need to filter out any of the attribute values?
            // we were filtering out everything bar resolution:
            //importPackages  = Processor.printClauses(values, "resolution:");
            importPackages = Processor.printClauses(values /*, ALLOWED_PACKAGE_CLAUSES */);
            if (notEmpty(importPackages)) {
                main.putValue(Analyzer.IMPORT_PACKAGE, importPackages);
            }


            String exportPackages = emptyIfNull(main.getValue(Analyzer.EXPORT_PACKAGE));
            Parameters exports = new Analyzer().parseHeader(exportPackages);
            for (Map.Entry<String, Attrs> entry : exports.entrySet()) {
                String packageName = entry.getKey();
                Map<String, String> map = entry.getValue();
                String version = map.get("version");
                if (version == null) {
View Full Code Here

        if (dependency != null) {
            // lets find the export packages and use the version from that
            if (dependency.isBundle()) {
                String exportPackages = dependency.getManifestEntry("Export-Package");
                if (notEmpty(exportPackages)) {
                    Parameters values = new Analyzer().parseHeader(exportPackages);
                    Map<String, String> map = values.get(packageName);
                    if (map != null) {
                        String version = map.get("version");
                        if (version == null) {
                            version = map.get("specification-version");
View Full Code Here

    private File wrapPlainJar(File tempFile, String fileName) {
        try {
            JarFile jar = new JarFile(tempFile);

            final Analyzer analyzer = new Analyzer();
            final String manifestVersion = ManifestUtils.getImplementationVersion(jar);
            if (manifestVersion != null) {
                analyzer.setBundleVersion(manifestVersion);
            }
            String name = ManifestUtils.getImplementationTitle(jar);
            if (name == null) {
                if (fileName == null) {
                    return null;
                } else {
                    name = fileName.replaceFirst("^(.+)\\.\\w+$", "$1");
                }
            }
            analyzer.setBundleSymbolicName(name);

            analyzer.setJar(tempFile);
            analyzer.setImportPackage("*;resolution:=optional");
            analyzer.setExportPackage("*");
            analyzer.analyze();
            final Manifest manifest = analyzer.calcManifest();
            analyzer.getJar().setManifest(manifest);
            final File wrappedTempFile = File.createTempFile("wrapped", ".jar");
            analyzer.save(wrappedTempFile, true);
            return wrappedTempFile;
        } catch (Exception e) {
            logger.warn(String.format("Failed to wrap plain %s jar using bnd.", tempFile), e);
            return null;
        }
View Full Code Here

TOP

Related Classes of aQute.bnd.osgi.Analyzer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.