Search in sources :

Example 1 with Jar

use of aQute.bnd.osgi.Jar in project tdi-studio-se by Talend.

the class JobJavaScriptOSGIForESBManager method createAnalyzer.

protected Analyzer createAnalyzer(ExportFileResource libResource, ProcessItem processItem) throws IOException {
    Analyzer analyzer = new Analyzer();
    Jar bin = new Jar(classesLocation);
    analyzer.setJar(bin);
    final String bundleName = processItem.getProperty().getLabel();
    String symbolicName = bundleName;
    // http://jira.talendforge.org/browse/TESB-5382 LiXiaopeng
    Project project = ProjectManager.getInstance().getCurrentProject();
    if (project != null) {
        String proName = project.getLabel();
        if (proName != null) {
            symbolicName = proName.toLowerCase() + '.' + symbolicName;
        }
    }
    analyzer.setProperty(Analyzer.BUNDLE_NAME, bundleName);
    analyzer.setProperty(Analyzer.BUNDLE_SYMBOLICNAME, symbolicName);
    analyzer.setProperty(Analyzer.BUNDLE_VERSION, getBundleVersion());
    IBrandingService brandingService = (IBrandingService) GlobalServiceRegister.getDefault().getService(IBrandingService.class);
    analyzer.setProperty(Analyzer.BUNDLE_VENDOR, //$NON-NLS-1$
    brandingService.getFullProductName() + " (" + brandingService.getAcronym() + '_' + RepositoryPlugin.getDefault().getBundle().getVersion().toString() + //$NON-NLS-1$
    ")");
    addOsgiDependencies(analyzer, libResource, processItem);
    //$NON-NLS-1$
    final StringBuilder bundleClasspath = new StringBuilder(".");
    final StringBuilder bundleNativeCode = new StringBuilder();
    Set<String> relativePathList = libResource.getRelativePathList();
    for (String path : relativePathList) {
        Set<URL> resources = libResource.getResourcesByRelativePath(path);
        for (URL url : resources) {
            File dependencyFile = new File(FilesUtils.getFileRealPath(url.getPath()));
            String relativePath = libResource.getDirectoryName() + PATH_SEPARATOR + dependencyFile.getName();
            bundleClasspath.append(MANIFEST_ITEM_SEPARATOR).append(relativePath);
            bin.putResource(relativePath, new FileResource(dependencyFile));
            // Add dynamic library declaration in manifest
            if (relativePath.toLowerCase().endsWith(DLL_FILE) || relativePath.toLowerCase().endsWith(SO_FILE)) {
                bundleNativeCode.append(libResource.getDirectoryName() + PATH_SEPARATOR + dependencyFile.getName()).append(OSGI_OS_CODE);
            }
        }
    }
    analyzer.setProperty(Analyzer.BUNDLE_CLASSPATH, bundleClasspath.toString());
    // TESB-15680: Add Bundle-NativeCode in manifest
    if (bundleNativeCode.length() > 0) {
        bundleNativeCode.setLength(bundleNativeCode.length() - 1);
        analyzer.setProperty(Analyzer.BUNDLE_NATIVECODE, bundleNativeCode.toString());
    }
    return analyzer;
}
Also used : Project(org.talend.core.model.general.Project) ITalendProcessJavaProject(org.talend.core.runtime.process.ITalendProcessJavaProject) FileResource(aQute.bnd.osgi.FileResource) ExportFileResource(org.talend.repository.documentation.ExportFileResource) Jar(aQute.bnd.osgi.Jar) IBrandingService(org.talend.core.ui.branding.IBrandingService) Analyzer(aQute.bnd.osgi.Analyzer) File(java.io.File) URL(java.net.URL)

Example 2 with Jar

use of aQute.bnd.osgi.Jar in project felix by apache.

the class BndJarResourceStore method read.

public byte[] read(String path) throws IOException {
    // Find the resource either in the global jar or in one of the embed dependencies
    Resource resource = m_analyzer.getJar().getResource(path);
    if (resource == null) {
        Jar embed = findJar(path);
        if (embed == null) {
            throw new IOException(format("Cannot find resource %s in jar and classpath", path));
        }
        resource = embed.getResource(path);
    }
    InputStream is = null;
    try {
        is = resource.openInputStream();
    } catch (Exception e) {
        throw new IOException("Cannot read " + path);
    }
    return Streams.readBytes(is);
}
Also used : InputStream(java.io.InputStream) Resource(aQute.bnd.osgi.Resource) Jar(aQute.bnd.osgi.Jar) IOException(java.io.IOException) IOException(java.io.IOException)

Example 3 with Jar

use of aQute.bnd.osgi.Jar in project felix by apache.

the class PojoizationPlugin method analyzeJar.

public boolean analyzeJar(Analyzer analyzer) throws Exception {
    long start = System.currentTimeMillis();
    // Wraps the Bnd Reporter
    BndReporter reporter = new BndReporter(this.m_reporter);
    // Build ResourceStore
    BndJarResourceStore store = new BndJarResourceStore(analyzer, this.m_reporter);
    store.setIncludeEmbedComponents(m_includeEmbedBundles);
    CompositeMetadataProvider provider = buildMetadataProvider(analyzer, reporter, store);
    // Quick exit
    CacheableMetadataProvider cache = new CacheableMetadataProvider(provider);
    if (cache.getMetadatas().isEmpty() && !hasEmbedComponents(analyzer)) {
        return false;
    }
    // Compute the classpath to build the classloader.
    List<Jar> jars = analyzer.getClasspath();
    Jar jar = analyzer.getJar();
    Set<String> paths = new LinkedHashSet<String>();
    if (jar != null && jar.getSource() != null) {
        paths.add(jar.getSource().getAbsolutePath());
    }
    for (Jar j : jars) {
        if (j.getSource() != null) {
            paths.add(j.getSource().getAbsolutePath());
        }
    }
    Classpath cp = new Classpath(paths);
    manipulateComponents(reporter, store, cache, cp.createClassLoader());
    int nbComponents = findElements(cache.getMetadatas(), "component").size();
    int nbHandlers = findElements(cache.getMetadatas(), "handler").size();
    this.m_reporter.trace("iPOJO manipulation performed performed in %s ms (%d components, %d handlers).", (System.currentTimeMillis() - start), nbComponents, nbHandlers);
    // Return true if a new run should be performed after the analyze
    return false;
}
Also used : Classpath(org.apache.felix.ipojo.manipulator.util.Classpath) CompositeMetadataProvider(org.apache.felix.ipojo.manipulator.metadata.CompositeMetadataProvider) Jar(aQute.bnd.osgi.Jar) CacheableMetadataProvider(org.apache.felix.ipojo.manipulator.metadata.CacheableMetadataProvider)

Example 4 with Jar

use of aQute.bnd.osgi.Jar in project felix by apache.

the class SCRDescriptorBndPlugin method getDependencies.

private List<File> getDependencies(Analyzer a) {
    ArrayList<File> files = new ArrayList<File>();
    for (final Jar j : a.getClasspath()) {
        File file = j.getSource();
        if (file.isFile()) {
            files.add(file);
        }
    }
    log.info("Using dependencies: " + files);
    return files;
}
Also used : ArrayList(java.util.ArrayList) Jar(aQute.bnd.osgi.Jar) File(java.io.File)

Example 5 with Jar

use of aQute.bnd.osgi.Jar in project felix by apache.

the class SCRDescriptorBndPlugin method getClassPath.

private URL[] getClassPath(Analyzer a) throws Exception {
    final Set<URL> path = new HashSet<URL>();
    for (final Jar j : a.getClasspath()) {
        path.add(j.getSource().toURI().toURL());
    }
    // always add the target url (containing all compiled classes) because it it not necessarily part of the analyzer classpath
    if (a.getTarget() != null && a.getTarget().getSource() != null) {
        path.add(a.getTarget().getSource().toURI().toURL());
    }
    log.info("Using classpath: " + path);
    return path.toArray(new URL[path.size()]);
}
Also used : Jar(aQute.bnd.osgi.Jar) URL(java.net.URL) HashSet(java.util.HashSet)

Aggregations

Jar (aQute.bnd.osgi.Jar)367 Builder (aQute.bnd.osgi.Builder)228 File (java.io.File)183 Manifest (java.util.jar.Manifest)105 Resource (aQute.bnd.osgi.Resource)87 Properties (java.util.Properties)66 Attributes (java.util.jar.Attributes)49 Parameters (aQute.bnd.header.Parameters)44 JarResource (aQute.bnd.osgi.JarResource)27 Attrs (aQute.bnd.header.Attrs)25 Domain (aQute.bnd.osgi.Domain)24 XmlTester (aQute.bnd.test.XmlTester)24 DiffPluginImpl (aQute.bnd.differ.DiffPluginImpl)21 IOException (java.io.IOException)20 ArrayList (java.util.ArrayList)19 LogService (org.osgi.service.log.LogService)18 Analyzer (aQute.bnd.osgi.Analyzer)17 FileResource (aQute.bnd.osgi.FileResource)17 Processor (aQute.bnd.osgi.Processor)17 InputStream (java.io.InputStream)17