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;
}
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);
}
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;
}
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;
}
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()]);
}
Aggregations