Package aQute.bnd.osgi

Examples of aQute.bnd.osgi.Builder


        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

        // Calculate the manifest
        try {
            Project bndProject = Central.getInstance().getModel(JavaCore.create(project));
            if (bndProject == null)
                return null;
            Builder builder;
            if (file.getName().equals(Project.BNDFILE)) {
                builder = bndProject.getSubBuilders().iterator().next();
            } else {
                builder = bndProject.getSubBuilder(file);
            }

            if (builder == null) {
                builder = new Builder();
                builder.setProperties(file);
            }
            builder.build();
            return builder;
        } catch (Exception e) {
            throw new CoreException(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, "Bnd analysis failed", e));
        }
    }
View Full Code Here

            @Override
            public void update(ViewerCell cell) {
                Object element = cell.getElement();

                if (element instanceof Builder) {
                    Builder builder = (Builder) element;
                    StyledString label = new StyledString(builder.getBsn(), StyledString.QUALIFIER_STYLER);
                    cell.setText(label.getString());
                    cell.setStyleRanges(label.getStyleRanges());
                    cell.setImage(projectImg);
                } else {
                    super.update(cell);
View Full Code Here

            FileUtils.writeFully(doc, bndFile, false);
        }
    }

    private void updateIncludeResourceIfNecessary(BndEditModel editModel, String blueprintrelativePath, IFile blueprintFile) throws Exception {
        Builder b = new Builder();
        try {
            b.setBase(blueprintFile.getProject().getFullPath().toFile());
            StringBuilder sb = new StringBuilder();
            for (String s : editModel.getIncludeResource()) {
                sb.append(s).append(',');
            }
            if (sb.length() > 0) {
                sb.deleteCharAt(sb.length() - 1);
            }
            b.setIncludeResource(sb.toString());
            if (!b.isInScope(Collections.singleton(blueprintFile.getFullPath().toFile()))) {
                editModel.addIncludeResource(blueprintrelativePath);
            }
        } finally {
            b.close();
        }
    }
View Full Code Here

        Jar[] classpath ) throws MojoExecutionException
    {
        try
        {
            File jarFile = new File( getBuildDirectory(), getBundleName( currentProject ) );
            Builder builder = buildOSGiBundle( currentProject, originalInstructions, properties, classpath );
            boolean hasErrors = reportErrors( "Bundle " + currentProject.getArtifact(), builder );
            if ( hasErrors )
            {
                String failok = builder.getProperty( "-failok" );
                if ( null == failok || "false".equalsIgnoreCase( failok ) )
                {
                    jarFile.delete();

                    throw new MojoFailureException( "Error(s) found in bundle configuration" );
                }
            }

            // attach bundle to maven project
            jarFile.getParentFile().mkdirs();
            builder.getJar().write( jarFile );

            Artifact mainArtifact = currentProject.getArtifact();

            if ( "bundle".equals( mainArtifact.getType() ) )
            {
                // workaround for MNG-1682: force maven to install artifact using the "jar" handler
                mainArtifact.setArtifactHandler( m_artifactHandlerManager.getArtifactHandler( "jar" ) );
            }

            boolean customClassifier = null != classifier && classifier.trim().length() > 0;
            boolean customPackaging = null != packaging && packaging.trim().length() > 0;

            if ( customClassifier && customPackaging )
            {
                m_projectHelper.attachArtifact( currentProject, packaging, classifier, jarFile );
            }
            else if ( customClassifier )
            {
                m_projectHelper.attachArtifact( currentProject, jarFile, classifier );
            }
            else if ( customPackaging )
            {
                m_projectHelper.attachArtifact( currentProject, packaging, jarFile );
            }
            else
            {
                mainArtifact.setFile( jarFile );
            }

            if ( unpackBundle )
            {
                unpackBundle( jarFile );
            }

            if ( manifestLocation != null )
            {
                File outputFile = new File( manifestLocation, "MANIFEST.MF" );

                try
                {
                    Manifest manifest = builder.getJar().getManifest();
                    ManifestPlugin.writeManifest( manifest, outputFile, niceManifest );
                }
                catch ( IOException e )
                {
                    getLog().error( "Error trying to write Manifest to file " + outputFile, e );
                }
            }

            // cleanup...
            builder.close();
        }
        catch ( MojoFailureException e )
        {
            getLog().error( e.getLocalizedMessage() );
            throw new MojoExecutionException( "Error(s) found in bundle configuration", e );
View Full Code Here

                sb.append(sb);
            }
            properties.setProperty(Analyzer.PLUGIN, sb.toString());
        }

        Builder builder = new Builder();
        synchronized ( BundlePlugin.class ) // protect setBase...getBndLastModified which uses static DateFormat
        {
            builder.setBase( getBase( currentProject ) );
        }
        builder.setProperties( sanitize( properties ) );
        if ( classpath != null )
        {
            builder.setClasspath( classpath );
        }

        return builder;
    }
View Full Code Here


    protected Builder buildOSGiBundle( MavenProject currentProject, Map originalInstructions, Properties properties,
        Jar[] classpath ) throws Exception
    {
        Builder builder = getOSGiBuilder( currentProject, originalInstructions, properties, classpath );

        addMavenInstructions( currentProject, builder );

        builder.build();

        mergeMavenManifest( currentProject, builder );

        return builder;
    }
View Full Code Here

        instructions.put( "Export-Service", "p7.Foo;mk=mv" );
        instructions.put( "Import-Service", "org.osgi.service.cm.ConfigurationAdmin;availability:=optional" );

        Properties props = new Properties();
        Builder builder = plugin.buildOSGiBundle( project, instructions, props, plugin.getClasspath( project ) );

        Manifest manifest = builder.getJar().getManifest();
        String expSvc = manifest.getMainAttributes().getValue( Constants.EXPORT_SERVICE );
        String impSvc = manifest.getMainAttributes().getValue( Constants.IMPORT_SERVICE );
        assertNotNull( expSvc );
        assertNotNull( impSvc );
View Full Code Here

            {
                throw new FileNotFoundException( file.getPath() );
            }
        }

        Builder analyzer = getOSGiBuilder( project, instructions, properties, classpath );

        analyzer.setJar( file );

        // calculateExportsFromContents when we have no explicit instructions defining
        // the contents of the bundle *and* we are not analyzing the output directory,
        // otherwise fall-back to addMavenInstructions approach

        boolean isOutputDirectory = file.equals( getOutputDirectory() );

        if ( analyzer.getProperty( Analyzer.EXPORT_PACKAGE ) == null
            && analyzer.getProperty( Analyzer.EXPORT_CONTENTS ) == null
            && analyzer.getProperty( Analyzer.PRIVATE_PACKAGE ) == null && !isOutputDirectory )
        {
            String export = calculateExportsFromContents( analyzer.getJar() );
            analyzer.setProperty( Analyzer.EXPORT_PACKAGE, export );
        }

        addMavenInstructions( project, analyzer );

        // if we spot Embed-Dependency and the bundle is "target/classes", assume we need to rebuild
        if ( analyzer.getProperty( DependencyEmbedder.EMBED_DEPENDENCY ) != null && isOutputDirectory )
        {
            analyzer.build();
        }
        else
        {
            analyzer.mergeManifest( analyzer.getJar().getManifest() );
            analyzer.getJar().setManifest( analyzer.calcManifest() );
        }

        mergeMavenManifest( project, analyzer );

        return analyzer;
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.