Search in sources :

Example 1 with FileResource

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;
}
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 FileResource

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;
}
Also used : Attrs(aQute.bnd.header.Attrs) FileResource(aQute.bnd.osgi.FileResource) EmbeddedActivator(aQute.remote.embedded.activator.EmbeddedActivator) Analyzer(aQute.bnd.osgi.Analyzer) Manifest(java.util.jar.Manifest) URLResource(aQute.bnd.osgi.URLResource) Container(aQute.bnd.build.Container) Jar(aQute.bnd.osgi.Jar) File(java.io.File)

Example 3 with FileResource

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);
    }
}
Also used : XMLAttributeFinder(aQute.bnd.xmlattribute.XMLAttributeFinder) FileResource(aQute.bnd.osgi.FileResource) Clazz(aQute.bnd.osgi.Clazz) Analyzer(aQute.bnd.osgi.Analyzer) File(java.io.File)

Example 4 with FileResource

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")));
}
Also used : FileResource(aQute.bnd.osgi.FileResource) Clazz(aQute.bnd.osgi.Clazz)

Example 5 with FileResource

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());
}
Also used : HashMap(java.util.HashMap) FileResource(aQute.bnd.osgi.FileResource) Clazz(aQute.bnd.osgi.Clazz) ClassDataCollector(aQute.bnd.osgi.ClassDataCollector) File(java.io.File)

Aggregations

FileResource (aQute.bnd.osgi.FileResource)20 File (java.io.File)14 Jar (aQute.bnd.osgi.Jar)10 EmbeddedResource (aQute.bnd.osgi.EmbeddedResource)7 Manifest (java.util.jar.Manifest)7 Clazz (aQute.bnd.osgi.Clazz)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 Analyzer (aQute.bnd.osgi.Analyzer)5 Resource (aQute.bnd.osgi.Resource)5 Container (aQute.bnd.build.Container)3 Parameters (aQute.bnd.header.Parameters)3 URLResource (aQute.bnd.osgi.URLResource)3 Attrs (aQute.bnd.header.Attrs)2 Domain (aQute.bnd.osgi.Domain)2 JarResource (aQute.bnd.osgi.JarResource)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 Properties (java.util.Properties)2 Workspace (aQute.bnd.build.Workspace)1