Package aQute.bnd.osgi

Examples of aQute.bnd.osgi.Builder


        assertTrue( osgiBundleFile.exists() );

        MavenProject project = getMavenProjectStub();

        //        PackageVersionAnalyzer analyzer = new PackageVersionAnalyzer();
        Builder analyzer = new Builder();
        Jar jar = new Jar( "name", osgiBundleFile );
        analyzer.setJar( jar );
        analyzer.setClasspath( new Jar[]
            { jar } );

        analyzer.setProperty( Analyzer.EXPORT_PACKAGE, "*" );
        analyzer.getJar().setManifest( analyzer.calcManifest() );

        assertEquals( 3, analyzer.getExports().size() );

        analyzer.close();
    }
View Full Code Here


        Map instructions = new HashMap();
        instructions.put( DependencyEmbedder.EMBED_DEPENDENCY, "*;classifier=;type=jar;scope=compile,"
            + "*;classifier=;type=jar;scope=runtime" );
        Properties props = new Properties();

        Builder builder = plugin.buildOSGiBundle( project, instructions, props, plugin.getClasspath( project ) );
        Manifest manifest = builder.getJar().getManifest();

        String bcp = manifest.getMainAttributes().getValue( Constants.BUNDLE_CLASSPATH );
        assertEquals( ".," + "compile-1.0.jar,b-1.0.jar,runtime-1.0.jar", bcp );

        String eas = manifest.getMainAttributes().getValue( "Embedded-Artifacts" );
View Full Code Here

        Map instructions = new HashMap();
        instructions.put( DependencyEmbedder.EMBED_DEPENDENCY, "!type=jar, !artifactId=c" );
        Properties props = new Properties();

        Builder builder = plugin.buildOSGiBundle( project, instructions, props, plugin.getClasspath( project ) );
        Manifest manifest = builder.getJar().getManifest();

        String bcp = manifest.getMainAttributes().getValue( Constants.BUNDLE_CLASSPATH );
        assertEquals( ".," + "a-1.0.war," + "d-1.0.zip," + "e-1.0.rar", bcp );

        String eas = manifest.getMainAttributes().getValue( "Embedded-Artifacts" );
View Full Code Here

        Map instructions = new HashMap();
        instructions.put( DependencyEmbedder.EMBED_DEPENDENCY, "c;type=jar,c;type=sources" );
        Properties props = new Properties();

        Builder builder = plugin.buildOSGiBundle( project, instructions, props, plugin.getClasspath( project ) );
        Manifest manifest = builder.getJar().getManifest();

        String bcp = manifest.getMainAttributes().getValue( Constants.BUNDLE_CLASSPATH );
        assertEquals( ".," + "c-1.0-three.jar," + "c-1.0.sources", bcp );

        String eas = manifest.getMainAttributes().getValue( "Embedded-Artifacts" );
View Full Code Here

        Map instructions = new HashMap();
        instructions.put( DependencyEmbedder.EMBED_DEPENDENCY, "artifactId=a|b" );
        Properties props = new Properties();

        Builder builder = plugin.buildOSGiBundle( project, instructions, props, plugin.getClasspath( project ) );
        Manifest manifest = builder.getJar().getManifest();

        String bcp = manifest.getMainAttributes().getValue( Constants.BUNDLE_CLASSPATH );
        assertEquals( ".," + "a-1.0-one.jar," + "b-1.0-two.jar," + "a-1.0.war," + "b-1.0.jar", bcp );

        String eas = manifest.getMainAttributes().getValue( "Embedded-Artifacts" );
View Full Code Here

        project.setDependencyArtifacts( artifacts );
        Properties props = new Properties();

        Map instructions1 = new HashMap();
        instructions1.put( DependencyEmbedder.EMBED_DEPENDENCY, "!scope=compile" );
        Builder builder1 = plugin.buildOSGiBundle( project, instructions1, props, plugin.getClasspath( project ) );
        Manifest manifest1 = builder1.getJar().getManifest();

        Map instructions2 = new HashMap();
        instructions2.put( DependencyEmbedder.EMBED_DEPENDENCY, "scope=!compile" );
        Builder builder2 = plugin.buildOSGiBundle( project, instructions2, props, plugin.getClasspath( project ) );
        Manifest manifest2 = builder2.getJar().getManifest();

        String bcp1 = manifest1.getMainAttributes().getValue( Constants.BUNDLE_CLASSPATH );
        assertEquals( ".," + "provided-1.0.jar," + "test-1.0.jar," + "runtime-1.0.jar," + "system-1.0.jar", bcp1 );

        String eas1 = manifest1.getMainAttributes().getValue( "Embedded-Artifacts" );
View Full Code Here

        props.put( "A", new File( "B" ) );
        props.put( "4", new HashMap( 2 ) );
        props.put( "1, two, 3.0", new char[5] );

        Builder builder = plugin.getOSGiBuilder( project, new HashMap(), props, plugin.getClasspath( project ) );

        File file = new File( getBasedir(), "target" + File.separatorChar + "test.props" );
        builder.getProperties().store( new FileOutputStream( file ), "TEST" );
    }
View Full Code Here

        final String baseDir = getProject().getBasedir().getPath();

        try
        {
            // assemble bundle as usual, but don't save it - this way we have all the instructions we need
            Builder builder = buildOSGiBundle( currentProject, originalInstructions, properties, classpath );
            Properties bndProperties = builder.getProperties();

            // cleanup and remove all non-strings from the builder properties
            for ( Iterator i = bndProperties.values().iterator(); i.hasNext(); )
            {
                if ( !( i.next() instanceof String ) )
                {
                    i.remove();
                }
            }

            // save the BND generated bundle to the same output directory that maven uses
            bndProperties.setProperty( "-output", "${maven.build.dir}/${maven.build.finalName}.jar" );

            OutputStream out = new FileOutputStream( baseDir + BUILD_BND );
            bndProperties.store( out, " Merged BND Instructions" );
            IOUtil.close( out );

            // modify build template
            String buildXml = IOUtil.toString( getClass().getResourceAsStream( BUILD_XML ) );
            buildXml = StringUtils.replace( buildXml, "BND_VERSION", builder.getVersion() );
            buildXml = StringUtils.replace( buildXml, "ARTIFACT_ID", artifactId );

            FileUtils.fileWrite( baseDir + BUILD_XML, buildXml );

            // cleanup...
            builder.close();
        }
        catch ( Exception e )
        {
            throw new MojoExecutionException( "Problem creating Ant script", e );
        }
View Full Code Here

        MultiMap<String,String> usedBy = new MultiMap<String,String>();
        Map<String,Set<Version>> bundleVersions = new HashMap<String,Set<Version>>();
        for (File inputFile : files) {
            if (inputFile.exists()) {
                try {
                    Builder builder;
                    if (inputFile.getName().endsWith(".bnd")) {
                        builder = setupBuilderForBndFile(inputFile);
                    } else {
                        builder = setupBuilderForJarFile(inputFile);
                    }
                    if (builder == null)
                        continue;
                    builderMap.put(inputFile, builder);
                    mergeCapabilities(exports, usedBy, bundleVersions, builder);
                } catch (CoreException e) {
                    logger.logError("Error in bnd resolution analysis.", e);
                } catch (Exception e) {
                    logger.logError("Error in bnd resolution analysis.", e);
                }
            }
        }

        // Merge together all the requirements, with access to the available
        // capabilities
        Map<String,List<ImportPackage>> imports = new HashMap<String,List<ImportPackage>>();
        Map<String,List<RequiredBundle>> requiredBundles = new HashMap<String,List<RequiredBundle>>();
        for (Entry<File,Builder> entry : builderMap.entrySet()) {
            Builder builder = entry.getValue();

            try {
                mergeRequirements(imports, exports, usedBy, requiredBundles, bundleVersions, builder);
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        // Generate the final results
        Set<File> resultFiles = builderMap.keySet();
        resultFileArray = resultFiles.toArray(new File[resultFiles.size()]);

        importResults = new ArrayList<ImportPackage>();
        for (List<ImportPackage> list : imports.values()) {
            importResults.addAll(list);
        }
        exportResults = new ArrayList<ExportPackage>();
        for (List<ExportPackage> list : exports.values()) {
            exportResults.addAll(list);
        }
        requiredBundleResults = new ArrayList<RequiredBundle>();
        for (List<RequiredBundle> list : requiredBundles.values()) {
            requiredBundleResults.addAll(list);
        }

        // Cleanup
        for (Builder builder : builderMap.values()) {
            builder.close();
        }

        // showResults(resultFileArray, importResults, exportResults);
        return Status.OK_STATUS;
    }
View Full Code Here

        // showResults(resultFileArray, importResults, exportResults);
        return Status.OK_STATUS;
    }

    static Builder setupBuilderForJarFile(File file) throws IOException, CoreException {
        Builder builder = new Builder();
        Jar jar = new Jar(file);
        builder.setJar(jar);
        try {
            builder.analyze();
        } catch (Exception e) {
            throw new CoreException(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, "Bnd analysis failed", e));
        }
        return builder;
    }
View Full Code Here

TOP

Related Classes of aQute.bnd.osgi.Builder

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.