use of aQute.bnd.osgi.FileResource 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.FileResource 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.FileResource in project bnd by bndtools.
the class ClazzTest method testRecursiveAnnotation.
public void testRecursiveAnnotation() throws Exception {
File file = IO.getFile("bin/test/ClazzTest$RecursiveAnno.class");
try (Analyzer analyzer = new Analyzer()) {
Clazz clazz = new Clazz(analyzer, file.getPath(), new FileResource(file));
clazz.parseClassFile();
analyzer.getClassspace().put(clazz.getClassName(), clazz);
AnnotationReader.getDefinition(clazz, analyzer, EnumSet.noneOf(DSAnnotations.Options.class), new XMLAttributeFinder(analyzer), AnnotationReader.V1_3);
}
}
use of aQute.bnd.osgi.FileResource in project bnd by bndtools.
the class ClassParserTest method testGenericsSignature.
public static void testGenericsSignature() throws Exception {
Clazz c = new Clazz(a, "genericstest", new FileResource(IO.getFile("src/test/generics.clazz")));
c.parseClassFile();
assertTrue(c.getReferred().contains(a.getPackageRef("javax/swing/table")));
assertTrue(c.getReferred().contains(a.getPackageRef("javax/swing")));
}
use of aQute.bnd.osgi.FileResource in project bnd by bndtools.
the class ClassParserTest method testConstantValues.
/**
* Test the constant values
*
* @throws Exception
*/
public void testConstantValues() throws Exception {
final Map<String, Object> values = new HashMap<String, Object>();
Clazz c = new Clazz(a, "ConstantValues", new FileResource(IO.getFile(new File("").getAbsoluteFile(), "bin/test/ConstantValues.class")));
c.parseClassFileWithCollector(new ClassDataCollector() {
Clazz.FieldDef last;
@Override
public void field(Clazz.FieldDef referenced) {
last = referenced;
}
@Override
public void constant(Object value) {
values.put(last.getName(), value);
}
});
assertEquals(1, values.get("t"));
assertEquals(0, values.get("f"));
assertEquals((int) Byte.MAX_VALUE, values.get("bt"));
assertEquals((int) Short.MAX_VALUE, values.get("shrt"));
assertEquals((int) Character.MAX_VALUE, values.get("chr"));
assertEquals(Integer.MAX_VALUE, values.get("intgr"));
assertEquals(Long.MAX_VALUE, values.get("lng"));
assertEquals(Float.MAX_VALUE, values.get("flt"));
assertEquals(Double.MAX_VALUE, values.get("dbl"));
assertEquals("blabla", values.get("strng"));
// Classes are special
// assertEquals("java.lang.Object", ((Clazz.ClassConstant)
// values.get("clss")).getName());
}
Aggregations