use of aQute.bnd.osgi.Analyzer 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.Analyzer in project tdi-studio-se by Talend.
the class JobJavaScriptOSGIForESBManager method getManifest.
private Manifest getManifest(ExportFileResource libResource, ProcessItem processItem) throws IOException {
Analyzer analyzer = createAnalyzer(libResource, processItem);
// Calculate the manifest
Manifest manifest = null;
try {
manifest = analyzer.calcManifest();
} catch (IOException e) {
throw e;
} catch (Exception e) {
ExceptionHandler.process(e);
} finally {
analyzer.close();
}
return manifest;
}
use of aQute.bnd.osgi.Analyzer in project bnd by bndtools.
the class RemoteProjectLauncherPlugin method executable.
/**
* Created a JAR that is a bundle and that contains its dependencies
*/
@Override
public Jar executable() throws Exception {
Collection<String> bsns = getProject().getBsns();
if (bsns.size() != 1)
throw new IllegalArgumentException("Can only handle a single bsn for a run configuration " + bsns);
String bsn = bsns.iterator().next();
Jar jar = new Jar(bsn);
String path = "aQute/remote/embedded/activator/EmbeddedActivator.class";
URLResource resource = new URLResource(getClass().getClassLoader().getResource(path));
jar.putResource("aQute/remote/embedded/activator/EmbeddedActivator.class", resource);
Collection<Container> rb = getProject().getRunbundles();
rb = Container.flatten(rb);
Attrs attrs = new Attrs();
for (Container c : rb) {
if (c.getError() != null) {
getProject().error("invalid runbundle %s", c);
} else {
File f = c.getFile();
String tbsn = c.getBundleSymbolicName();
String version = c.getVersion();
if (version == null || !Version.isVersion(version))
getProject().warning("The version of embedded bundle %s does not have a proper version", c);
jar.putResource("jar/" + c.getBundleSymbolicName() + ".jar", new FileResource(f));
attrs.put(tbsn, version);
}
}
Analyzer a = new Analyzer(getProject());
a.setJar(jar);
a.setBundleActivator(EmbeddedActivator.class.getName());
a.setProperty("Bnd-Embedded", attrs.toString().replace(';', ','));
Manifest manifest = a.calcManifest();
jar.setManifest(manifest);
getProject().getInfo(a);
return jar;
}
use of aQute.bnd.osgi.Analyzer in project bnd by bndtools.
the class Classpath method visit.
/**
* Visit each class on the class path.
*
* @param visitor the visitor
*/
public void visit(ClassVisitor visitor) throws Exception {
try (Analyzer analyzer = new Analyzer()) {
for (File f : entries) {
try (Jar jar = new Jar(f)) {
for (String path : jar.getResources().keySet()) {
if (path.endsWith(".class")) {
Resource r = jar.getResource(path);
Clazz c = new Clazz(analyzer, path, r);
c.parseClassFile();
visitor.visit(c);
}
}
}
}
}
}
use of aQute.bnd.osgi.Analyzer in project bnd by bndtools.
the class bnd method doPrint.
private void doPrint(Jar jar, int options, printOptions po) throws ZipException, IOException, Exception {
if ((options & VERIFY) != 0) {
Verifier verifier = new Verifier(jar);
verifier.setPedantic(isPedantic());
verifier.verify();
getInfo(verifier);
}
if ((options & MANIFEST) != 0) {
Manifest manifest = jar.getManifest();
if (manifest == null)
warning("JAR has no manifest %s", jar);
else {
err.println("[MANIFEST " + jar.getName() + "]");
printManifest(manifest);
}
out.println();
}
if ((options & IMPEXP) != 0) {
out.println("[IMPEXP]");
Manifest m = jar.getManifest();
Domain domain = Domain.domain(m);
if (m != null) {
Parameters imports = domain.getImportPackage();
Parameters exports = domain.getExportPackage();
for (String p : exports.keySet()) {
if (imports.containsKey(p)) {
Attrs attrs = imports.get(p);
if (attrs.containsKey(VERSION_ATTRIBUTE)) {
exports.get(p).put("imported-as", attrs.get(VERSION_ATTRIBUTE));
}
}
}
print(Constants.IMPORT_PACKAGE, new TreeMap<String, Attrs>(imports));
print(Constants.EXPORT_PACKAGE, new TreeMap<String, Attrs>(exports));
} else
warning("File has no manifest");
}
if ((options & CAPABILITIES) != 0) {
out.println("[CAPABILITIES]");
Manifest m = jar.getManifest();
Domain domain = Domain.domain(m);
if (m != null) {
Parameters provide = domain.getProvideCapability();
Parameters require = domain.getRequireCapability();
print(Constants.PROVIDE_CAPABILITY, new TreeMap<String, Attrs>(provide));
print(Constants.REQUIRE_CAPABILITY, new TreeMap<String, Attrs>(require));
} else
warning("File has no manifest");
}
if ((options & (USES | USEDBY | API)) != 0) {
out.println();
try (Analyzer analyzer = new Analyzer()) {
analyzer.setPedantic(isPedantic());
analyzer.setJar(jar);
Manifest m = jar.getManifest();
if (m != null) {
String s = m.getMainAttributes().getValue(Constants.EXPORT_PACKAGE);
if (s != null)
analyzer.setExportPackage(s);
}
analyzer.analyze();
boolean java = po.java();
Packages exports = analyzer.getExports();
if ((options & API) != 0) {
Map<PackageRef, List<PackageRef>> apiUses = analyzer.cleanupUses(analyzer.getAPIUses(), !po.java());
if (!po.xport()) {
if (exports.isEmpty())
warning("Not filtering on exported only since exports are empty");
else
apiUses.keySet().retainAll(analyzer.getExports().keySet());
}
out.println("[API USES]");
printMultiMap(apiUses);
Set<PackageRef> privates = analyzer.getPrivates();
for (PackageRef export : exports.keySet()) {
Map<Def, List<TypeRef>> xRef = analyzer.getXRef(export, privates, Modifier.PROTECTED + Modifier.PUBLIC);
if (!xRef.isEmpty()) {
out.println();
out.printf("%s refers to private Packages (not good)\n\n", export);
for (Entry<Def, List<TypeRef>> e : xRef.entrySet()) {
TreeSet<PackageRef> refs = new TreeSet<Descriptors.PackageRef>();
for (TypeRef ref : e.getValue()) refs.add(ref.getPackageRef());
refs.retainAll(privates);
//
out.printf(//
"%60s %-40s %s\n", //
e.getKey().getOwnerType().getFQN(), e.getKey().getName(), refs);
}
out.println();
}
}
out.println();
}
Map<PackageRef, List<PackageRef>> uses = analyzer.cleanupUses(analyzer.getUses(), !po.java());
if ((options & USES) != 0) {
out.println("[USES]");
printMultiMap(uses);
out.println();
}
if ((options & USEDBY) != 0) {
out.println("[USEDBY]");
MultiMap<PackageRef, PackageRef> usedBy = new MultiMap<Descriptors.PackageRef, Descriptors.PackageRef>(uses).transpose();
printMultiMap(usedBy);
}
}
}
if ((options & COMPONENT) != 0) {
printComponents(out, jar);
}
if ((options & METATYPE) != 0) {
printMetatype(out, jar);
}
if ((options & LIST) != 0) {
out.println("[LIST]");
for (Map.Entry<String, Map<String, Resource>> entry : jar.getDirectories().entrySet()) {
String name = entry.getKey();
Map<String, Resource> contents = entry.getValue();
out.println(name);
if (contents != null) {
for (String element : contents.keySet()) {
int n = element.lastIndexOf('/');
if (n > 0)
element = element.substring(n + 1);
out.print(" ");
out.print(element);
String path = element;
if (name.length() != 0)
path = name + "/" + element;
Resource r = contents.get(path);
if (r != null) {
String extra = r.getExtra();
if (extra != null) {
out.print(" extra='" + escapeUnicode(extra) + "'");
}
}
out.println();
}
} else {
out.println(name + " <no contents>");
}
}
out.println();
}
}
Aggregations