Search in sources :

Example 31 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)

Example 32 with Builder

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

the class MergeTest method testMerge.

static void testMerge(String type, String[] in, String[] out, String c, int errors, int warnings) throws Exception {
    Builder b = new Builder();
    try {
        b.setClasspath(new File[] { IO.getFile("src/test/split/split-a.jar"), IO.getFile("src/test/split/split-b.jar") });
        Properties p = new Properties();
        if (type != null)
            p.put("Export-Package", "test.split;-split-package:=" + type);
        else
            p.put("Export-Package", "test.split");
        p.put("Import-Package", "");
        b.setProperties(p);
        Jar jar = b.build();
        System.err.println("Errors     :" + b.getErrors());
        System.err.println("Warnings   :" + b.getWarnings());
        assertEquals(errors, b.getErrors().size());
        assertEquals(warnings, b.getWarnings().size());
        if (errors != 0)
            return;
        for (int i = 0; in != null && i < in.length; i++) assertNotNull("Contains " + in[i], jar.getResource("test/split/" + in[i]));
        for (int i = 0; out != null && i < out.length; i++) assertNull("Does not contain " + out[i], jar.getResource("test/split/" + out[i]));
        Resource r = jar.getResource("test/split/C");
        InputStream is = r.openInputStream();
        BufferedReader dis = new BufferedReader(new InputStreamReader(is));
        String s = dis.readLine();
        assertEquals(s, c);
    } finally {
        b.close();
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) Builder(aQute.bnd.osgi.Builder) Resource(aQute.bnd.osgi.Resource) BufferedReader(java.io.BufferedReader) Jar(aQute.bnd.osgi.Jar) Properties(java.util.Properties)

Example 33 with Builder

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

the class PluginTest method testMissingPluginNotUsed.

public void testMissingPluginNotUsed() throws Exception {
    Builder p = new Builder();
    p.setProperty("-plugin", "missing;command:=\"-abc,-def\"");
    /* List<?> plugins = */
    p.getPlugins(Object.class);
    assertTrue(p.check());
    p.setProperty("-abc", "whatever");
    p.setProperty("-resourceonly", "true");
    p.setProperty("Include-Resource", "jar/osgi.jar");
    p.build();
    assertEquals(1, p.getErrors().size());
    assertTrue(p.getErrors().get(0).contains("Missing plugin"));
}
Also used : Builder(aQute.bnd.osgi.Builder)

Example 34 with Builder

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

the class PreprocessTest method testPreProcess.

/**
	 * Spaces at the end of a clause cause the preprocess to fail.
	 * 
	 * @throws Exception
	 */
public static void testPreProcess() throws Exception {
    Properties base = new Properties();
    base.put(Analyzer.INCLUDE_RESOURCE, "{src/test/top.mf}     ");
    Builder analyzer = new Builder();
    analyzer.setProperties(base);
    analyzer.build();
    assertTrue(analyzer.check());
    Jar jar = analyzer.getJar();
    assertTrue(jar.getResource("top.mf") != null);
    analyzer.close();
}
Also used : Builder(aQute.bnd.osgi.Builder) Jar(aQute.bnd.osgi.Jar) Properties(java.util.Properties)

Example 35 with Builder

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

the class PreprocessTest method testPreProcessExcludeExtensionGlobal.

/**
	 * Check if we can override
	 * 
	 * @throws Exception
	 */
public static void testPreProcessExcludeExtensionGlobal() throws Exception {
    Builder b = new Builder();
    b.setProperty(Analyzer.PREPROCESSMATCHERS, "!*.TXT:i,*");
    b.setProperty(Analyzer.INCLUDE_RESOURCE, "{src/test/builder-preprocess.txt},{src/test/builder-preprocess.txt2}");
    b.setProperty("var", "Yes!");
    ;
    b.build();
    assertTrue(b.check());
    System.out.println("testPreProcessExcludeExtensionsGlobal");
    Jar jar = b.getJar();
    Resource resource = jar.getResource("builder-preprocess.txt");
    String s = IO.collect(resource.openInputStream());
    System.out.println(s);
    assertTrue(s.contains("${var}"));
    assertFalse(s.contains("!Yes"));
    resource = jar.getResource("builder-preprocess.txt2");
    s = IO.collect(resource.openInputStream());
    System.out.println(s);
    assertTrue(s.contains("Yes!"));
    assertFalse(s.contains("${var}"));
    b.close();
}
Also used : Builder(aQute.bnd.osgi.Builder) Resource(aQute.bnd.osgi.Resource) Jar(aQute.bnd.osgi.Jar)

Aggregations

Builder (aQute.bnd.osgi.Builder)426 Jar (aQute.bnd.osgi.Jar)225 File (java.io.File)197 Manifest (java.util.jar.Manifest)93 Properties (java.util.Properties)91 Resource (aQute.bnd.osgi.Resource)82 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 Domain (aQute.bnd.osgi.Domain)16 ArrayList (java.util.ArrayList)13 Project (aQute.bnd.build.Project)10 Baseline (aQute.bnd.differ.Baseline)9 Packages (aQute.bnd.osgi.Packages)9 CapReqBuilder (aQute.bnd.osgi.resource.CapReqBuilder)9