Search in sources :

Example 96 with Builder

use of aQute.bnd.osgi.Builder in project bnd by bndtools.

the class ResourcesTest method testOnTheFlyMerge.

/**
	 * Test the Include-Resource facility to generate resources on the fly. This
	 * is a a case where multiple resources and up in a single combined
	 * resource.
	 */
public static void testOnTheFlyMerge() throws Exception {
    if (!onWindows()) {
        Builder b = new Builder();
        b.setIncludeResource("count;for='1,2,3';cmd='echo YES_${@}'");
        b.setProperty("-resourceonly", "true");
        Jar jar = b.build();
        assertTrue(b.check());
        Resource r = jar.getResource("count");
        assertNotNull(r);
        String s = IO.collect(r.openInputStream());
        assertEquals("YES_1\nYES_2\nYES_3\n", s);
        b.close();
    }
}
Also used : Builder(aQute.bnd.osgi.Builder) JarResource(aQute.bnd.osgi.JarResource) Resource(aQute.bnd.osgi.Resource) Jar(aQute.bnd.osgi.Jar)

Example 97 with Builder

use of aQute.bnd.osgi.Builder in project bnd by bndtools.

the class ResourcesTest method testIncludeResourceDirectivesFilterRecursiveFlatten.

public static void testIncludeResourceDirectivesFilterRecursiveFlatten() throws Exception {
    Builder b = new Builder();
    b.setProperty("Include-Resource", "TargetFolder=testresources/ws/p2/Resources;filter:=re*.txt;flatten:=true");
    b.setProperty("-resourceonly", "true");
    Jar jar = b.build();
    Resource r = jar.getResource("TargetFolder/resource3.txt");
    assertNotNull(r);
    r = jar.getResource("TargetFolder/resource4.txt");
    assertNotNull(r);
    r = jar.getResource("TargetFolder/resource6.txt");
    assertNotNull(r);
    r = jar.getResource("TargetFolder/resource7.txt");
    assertNotNull(r);
    r = jar.getResource("TargetFolder/resource1.res");
    assertNull(r);
}
Also used : Builder(aQute.bnd.osgi.Builder) JarResource(aQute.bnd.osgi.JarResource) Resource(aQute.bnd.osgi.Resource) Jar(aQute.bnd.osgi.Jar)

Example 98 with Builder

use of aQute.bnd.osgi.Builder in project bnd by bndtools.

the class ResourcesTest method testOnTheFlySingleError.

/**
	 * Test the Include-Resource facility to generate resources on the fly. This
	 * is a simple case of one resource with an error.
	 */
public static void testOnTheFlySingleError() throws Exception {
    if (onWindows())
        return;
    Builder b = new Builder();
    b.setIncludeResource("testresources/x;cmd='I do not exist!!!!!!!!!!!'");
    b.setProperty("-resourceonly", "true");
    Jar jar = b.build();
    assertTrue(b.check("Cmd 'I do not exist!!!!!!!!!!!' failed"));
    b.close();
}
Also used : Builder(aQute.bnd.osgi.Builder) Jar(aQute.bnd.osgi.Jar)

Example 99 with Builder

use of aQute.bnd.osgi.Builder in project bnd by bndtools.

the class Profiles method _create.

public void _create(CreateOptions options) throws Exception {
    Builder b = new Builder();
    bnd.addClose(b);
    b.setBase(bnd.getBase());
    if (options.properties() != null) {
        for (String propertyFile : options.properties()) {
            File pf = bnd.getFile(propertyFile);
            b.addProperties(pf);
        }
    }
    if (options.bsn() != null)
        b.setProperty(Constants.BUNDLE_SYMBOLICNAME, options.bsn());
    if (options.version() != null)
        b.setProperty(Constants.BUNDLE_VERSION, options.version().toString());
    Instructions match = options.match();
    Parameters packages = new Parameters();
    Parameters capabilities = new Parameters();
    Collection<String> paths = new ArrayList<String>(new Parameters(b.getProperty("-paths"), bnd).keySet());
    if (paths.isEmpty())
        paths = options._arguments();
    logger.debug("input {}", paths);
    ResourceBuilder pb = new ResourceBuilder();
    for (String root : paths) {
        File f = bnd.getFile(root);
        if (!f.exists()) {
            error("could not find %s", f);
        } else {
            Glob g = options.extension();
            if (g == null)
                g = new Glob("*.jar");
            Collection<File> files = IO.tree(f, "*.jar");
            logger.debug("will profile {}", files);
            for (File file : files) {
                Domain domain = Domain.domain(file);
                if (domain == null) {
                    error("Not a bundle because no manifest %s", file);
                    continue;
                }
                String bsn = domain.getBundleSymbolicName().getKey();
                if (bsn == null) {
                    error("Not a bundle because no manifest %s", file);
                    continue;
                }
                if (match != null) {
                    Instruction instr = match.finder(bsn);
                    if (instr == null || instr.isNegated()) {
                        logger.debug("skipped {} because of non matching bsn {}", file, bsn);
                        continue;
                    }
                }
                Parameters eps = domain.getExportPackage();
                Parameters pcs = domain.getProvideCapability();
                logger.debug("parse {}:\ncaps: {}\npac: {}\n", file, pcs, eps);
                packages.mergeWith(eps, false);
                capabilities.mergeWith(pcs, false);
            }
        }
    }
    b.setProperty(Constants.PROVIDE_CAPABILITY, capabilities.toString());
    b.setProperty(Constants.EXPORT_PACKAGE, packages.toString());
    logger.debug("Found {} packages and {} capabilities", packages.size(), capabilities.size());
    Jar jar = b.build();
    File f = b.getOutputFile(options.output());
    logger.debug("Saving as {}", f);
    jar.write(f);
}
Also used : ResourceBuilder(aQute.bnd.osgi.resource.ResourceBuilder) Parameters(aQute.bnd.header.Parameters) ResourceBuilder(aQute.bnd.osgi.resource.ResourceBuilder) Builder(aQute.bnd.osgi.Builder) ArrayList(java.util.ArrayList) Instructions(aQute.bnd.osgi.Instructions) Instruction(aQute.bnd.osgi.Instruction) Glob(aQute.libg.glob.Glob) Jar(aQute.bnd.osgi.Jar) Domain(aQute.bnd.osgi.Domain) File(java.io.File)

Example 100 with Builder

use of aQute.bnd.osgi.Builder in project bnd by bndtools.

the class BndTask method executeBackwardCompatible.

@SuppressWarnings("cast")
private void executeBackwardCompatible() throws BuildException {
    try {
        if (files == null)
            throw new BuildException("No files set");
        if (eclipse) {
            File project = getProject().getBaseDir();
            EclipseClasspath cp = new EclipseClasspath(this, project.getParentFile(), project);
            classpath.addAll(cp.getClasspath());
            classpath.addAll(cp.getBootclasspath());
            sourcepath.addAll(cp.getSourcepath());
            // classpath.add(cp.getOutput());
            if (report())
                throw new BuildException("Errors during Eclipse Path inspection");
        }
        if (output == null)
            output = getProject().getBaseDir();
        for (Iterator<File> f = files.iterator(); f.hasNext(); ) {
            File file = f.next();
            Builder builder = new Builder();
            builder.setPedantic(isPedantic());
            if (file.exists()) {
                // Do nice property calculations
                // merging includes etc.
                builder.setProperties(file);
            }
            // properties, if the inherit flag is specified
            if (inherit) {
                Properties projectProperties = new UTF8Properties();
                @SuppressWarnings("unchecked") Hashtable<Object, Object> antProps = getProject().getProperties();
                projectProperties.putAll(antProps);
                projectProperties.putAll(builder.getProperties());
                builder.setProperties(projectProperties);
            }
            builder.setClasspath(toFiles(classpath, "classpath"));
            builder.setSourcepath(toFiles(sourcepath, "sourcepath"));
            Jar[] jars = builder.builds();
            // Report both task failures and bnd build failures.
            boolean taskFailed = report();
            boolean bndFailed = report(builder);
            // failed or the bnd build failed.
            if (!failok && (taskFailed || bndFailed)) {
                throw new BuildException("bnd failed", new org.apache.tools.ant.Location(file.getAbsolutePath()));
            }
            for (int i = 0; i < jars.length; i++) {
                Jar jar = jars[i];
                String bsn = jar.getName();
                File base = file.getParentFile();
                File output = this.output;
                String path = builder.getProperty("-output");
                if (output == null) {
                    if (path == null)
                        output = getFile(base, bsn + ".jar");
                    else {
                        output = getFile(base, path);
                    }
                } else if (output.isDirectory()) {
                    if (path == null)
                        output = getFile(this.output, bsn + ".jar");
                    else
                        output = getFile(this.output, path);
                } else if (output.isFile()) {
                    if (files.size() > 1)
                        messages.GotFileNeedDir_(output.getAbsoluteFile());
                }
                String msg = "";
                if (!output.exists() || output.lastModified() <= jar.lastModified()) {
                    jar.write(output);
                } else {
                    msg = "(not modified)";
                }
                logger.debug("{} ({}) {} {}", jar.getName(), output.getName(), jar.getResources().size(), msg);
                report();
                jar.close();
            }
            builder.close();
        }
    } catch (Exception e) {
        // if (exceptions)
        e.printStackTrace();
        if (!failok)
            throw new BuildException("Failed to build jar file: ", e);
    }
}
Also used : EclipseClasspath(aQute.bnd.osgi.eclipse.EclipseClasspath) Builder(aQute.bnd.osgi.Builder) Properties(java.util.Properties) UTF8Properties(aQute.lib.utf8properties.UTF8Properties) BuildException(org.apache.tools.ant.BuildException) Jar(aQute.bnd.osgi.Jar) BuildException(org.apache.tools.ant.BuildException) File(java.io.File) UTF8Properties(aQute.lib.utf8properties.UTF8Properties)

Aggregations

Builder (aQute.bnd.osgi.Builder)440 Jar (aQute.bnd.osgi.Jar)228 File (java.io.File)203 Properties (java.util.Properties)99 Manifest (java.util.jar.Manifest)99 Resource (aQute.bnd.osgi.Resource)83 Attributes (java.util.jar.Attributes)43 DocumentBuilder (javax.xml.parsers.DocumentBuilder)41 XmlTester (aQute.bnd.test.XmlTester)39 Parameters (aQute.bnd.header.Parameters)35 Document (org.w3c.dom.Document)27 Attrs (aQute.bnd.header.Attrs)21 JarResource (aQute.bnd.osgi.JarResource)20 LogService (org.osgi.service.log.LogService)17 ProjectBuilder (aQute.bnd.build.ProjectBuilder)16 Domain (aQute.bnd.osgi.Domain)16 ArrayList (java.util.ArrayList)14 DependencyGraphBuilder (org.apache.maven.shared.dependency.graph.DependencyGraphBuilder)13 HashMap (java.util.HashMap)12 Project (aQute.bnd.build.Project)10