Search in sources :

Example 16 with Workspace

use of aQute.bnd.build.Workspace in project bnd by bndtools.

the class bnd method _runtests.

/**
	 * Run the tests from a prepared bnd file.
	 * 
	 * @throws Exception
	 */
@Description("Run OSGi tests and create report")
public void _runtests(runtestsOptions opts) throws Exception {
    int errors = 0;
    File cwd = new File("").getAbsoluteFile();
    Workspace ws = new Workspace(cwd);
    try {
        File reportDir = getFile("reports");
        IO.delete(reportDir);
        Tag summary = new Tag("summary");
        summary.addAttribute("date", new Date());
        summary.addAttribute("ws", ws.getBase());
        if (opts.reportdir() != null) {
            reportDir = getFile(opts.reportdir());
        }
        IO.mkdirs(reportDir);
        if (!reportDir.isDirectory())
            error("reportdir must be a directory %s (tried to create it ...)", reportDir);
        if (opts.title() != null)
            summary.addAttribute("title", opts.title());
        if (opts.dir() != null)
            cwd = getFile(opts.dir());
        if (opts.workspace() != null) {
            ws.close();
            ws = Workspace.getWorkspace(getFile(opts.workspace()));
        }
        // TODO check all the arguments
        boolean hadOne = false;
        try {
            for (String arg : opts._arguments()) {
                logger.debug("will run test {}", arg);
                File f = getFile(arg);
                errors += runtTest(f, ws, reportDir, summary);
                hadOne = true;
            }
            if (!hadOne) {
                // See if we had any, if so, just use all files in
                // the current directory
                File[] files = cwd.listFiles();
                for (File f : files) {
                    if (f.getName().endsWith(".bnd")) {
                        errors += runtTest(f, ws, reportDir, summary);
                    }
                }
            }
        } catch (Throwable e) {
            if (isExceptions()) {
                printExceptionSummary(e, out);
            }
            exception(e, "FAILURE IN RUNTESTS");
            errors++;
        }
        if (errors > 0)
            summary.addAttribute("errors", errors);
        for (String error : getErrors()) {
            Tag e = new Tag("error");
            e.addContent(error);
        }
        for (String warning : getWarnings()) {
            Tag e = new Tag("warning");
            e.addContent(warning);
        }
        File r = getFile(reportDir, "summary.xml");
        try (PrintWriter pw = IO.writer(r, UTF_8)) {
            summary.print(0, pw);
        }
        if (errors != 0)
            error("Errors found %s", errors);
    } finally {
        ws.close();
    }
}
Also used : Tag(aQute.lib.tag.Tag) File(java.io.File) Date(java.util.Date) Workspace(aQute.bnd.build.Workspace) PrintWriter(java.io.PrintWriter) Description(aQute.lib.getopt.Description)

Example 17 with Workspace

use of aQute.bnd.build.Workspace in project bnd by bndtools.

the class bnd method doRun.

private void doRun(List<String> args, boolean verify, String project) throws Exception {
    Project run = null;
    if (args.isEmpty()) {
        run = getProject(project);
        if (run == null) {
            messages.NoProject();
            return;
        }
    } else {
        File f = getFile(args.get(0));
        File dir = f.getParentFile();
        File wsdir = dir.getParentFile();
        if (wsdir == null) {
            // We are in the filesystem root?? Create a standalone run.
            run = Run.createRun(null, f);
        } else {
            Workspace workspace = Workspace.getWorkspaceWithoutException(wsdir);
            run = Run.createRun(workspace, f);
        }
    }
    verifyDependencies(run, verify, false);
    try {
        run.run();
    } catch (Exception e) {
        messages.Failed__(e, "Running " + run);
    }
    getInfo(run);
    getInfo(run.getWorkspace());
}
Also used : Project(aQute.bnd.build.Project) File(java.io.File) InvocationTargetException(java.lang.reflect.InvocationTargetException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException) XPathExpressionException(javax.xml.xpath.XPathExpressionException) ZipException(java.util.zip.ZipException) Workspace(aQute.bnd.build.Workspace)

Example 18 with Workspace

use of aQute.bnd.build.Workspace in project bnd by bndtools.

the class bnd method main.

public static void main(String[] args) throws Exception {
    Workspace.setDriver(Constants.BNDDRIVER_BND);
    Workspace.addGestalt(Constants.GESTALT_SHELL, null);
    Workspace.addGestalt(Constants.GESTALT_INTERACTIVE, null);
    Workspace ws = Workspace.findWorkspace(IO.work);
    try (bnd main = new bnd()) {
        // ws == null ? new bnd() : new bnd(ws);
        main.start(args);
    }
    exitWithCode(0);
}
Also used : Workspace(aQute.bnd.build.Workspace)

Example 19 with Workspace

use of aQute.bnd.build.Workspace in project bnd by bndtools.

the class ProjectTest method testWildcardBuildPathWithRepoFilter.

public void testWildcardBuildPathWithRepoFilter() throws Exception {
    Workspace ws = getWorkspace(IO.getFile("testresources/ws"));
    Project project = ws.getProject("repofilter");
    assertNotNull(project);
    project.setProperty("-buildpath", "*; repo=Relea*");
    ArrayList<Container> buildpath = new ArrayList<Container>(project.getBuildpath());
    assertEquals(2, buildpath.size());
    assertEquals(Container.TYPE.REPO, buildpath.get(0).getType());
    assertEquals("org.apache.felix.configadmin", buildpath.get(0).getBundleSymbolicName());
    assertEquals(Container.TYPE.REPO, buildpath.get(1).getType());
    assertEquals("p3", buildpath.get(1).getBundleSymbolicName());
}
Also used : Project(aQute.bnd.build.Project) Container(aQute.bnd.build.Container) ArrayList(java.util.ArrayList) Workspace(aQute.bnd.build.Workspace)

Example 20 with Workspace

use of aQute.bnd.build.Workspace in project bnd by bndtools.

the class ProjectTest method testGetOutputFile.

/**
	 * Check that the output property can be used to name the output binary.
	 */
public void testGetOutputFile() throws Exception {
    Workspace ws = getWorkspace(IO.getFile("testresources/ws"));
    Project top = ws.getProject("p1");
    //
    // We expect p1 to be a single project (no sub builders)
    //
    assertEquals("p1 must be singleton", 1, top.getSubBuilders().size());
    Builder builder = top.getSubBuilders().iterator().next();
    assertEquals("p1 must be singleton", "p1", builder.getBsn());
    // Check the default bsn.jar form
    assertEquals(new File(top.getTarget(), "p1.jar"), top.getOutputFile("p1"));
    assertEquals(new File(top.getTarget(), "p1.jar"), top.getOutputFile("p1", "0"));
    // Add the version to the filename
    top.setProperty("-outputmask", "${@bsn}-${version;===s;${@version}}.jar");
    assertEquals(new File(top.getTarget(), "p1-1.260.0.jar"), top.getOutputFile(builder.getBsn(), builder.getVersion()));
    top.setProperty("Bundle-Version", "1.260.0.SNAPSHOT");
    assertEquals(new File(top.getTarget(), "p1-1.260.0-SNAPSHOT.jar"), top.getOutputFile(builder.getBsn(), builder.getVersion()));
    top.setProperty("-outputmask", "${@bsn}-${version;===S;${@version}}.jar");
    assertEquals(new File(top.getTarget(), "p1-1.260.0-SNAPSHOT.jar"), top.getOutputFile(builder.getBsn(), builder.getVersion()));
    top.setProperty("Bundle-Version", "1.260.0.NOTSNAPSHOT");
    top.setProperty("-outputmask", "${@bsn}-${version;===S;${@version}}.jar");
    assertEquals(new File(top.getTarget(), "p1-1.260.0.NOTSNAPSHOT.jar"), top.getOutputFile(builder.getBsn(), builder.getVersion()));
    top.setProperty("-outputmask", "${@bsn}-${version;===s;${@version}}.jar");
    assertEquals(new File(top.getTarget(), "p1-1.260.0.jar"), top.getOutputFile(builder.getBsn(), builder.getVersion()));
    top.setProperty("Bundle-Version", "42");
    top.setProperty("-outputmask", "${@bsn}-${version;===S;${@version}}.jar");
    assertEquals(new File(top.getTarget(), "p1-42.0.0.jar"), top.getOutputFile(builder.getBsn(), builder.getVersion()));
    top.setProperty("-outputmask", "${@bsn}-${version;===s;${@version}}.jar");
    assertEquals(new File(top.getTarget(), "p1-42.0.0.jar"), top.getOutputFile(builder.getBsn(), builder.getVersion()));
}
Also used : Project(aQute.bnd.build.Project) Builder(aQute.bnd.osgi.Builder) File(java.io.File) Workspace(aQute.bnd.build.Workspace)

Aggregations

Workspace (aQute.bnd.build.Workspace)171 Project (aQute.bnd.build.Project)71 File (java.io.File)66 Processor (aQute.bnd.osgi.Processor)27 HashMap (java.util.HashMap)22 IOException (java.io.IOException)20 ArrayList (java.util.ArrayList)19 Container (aQute.bnd.build.Container)17 RepositoryPlugin (aQute.bnd.service.RepositoryPlugin)13 Version (aQute.bnd.version.Version)13 Run (aQute.bnd.build.Run)11 IProject (org.eclipse.core.resources.IProject)11 CoreException (org.eclipse.core.runtime.CoreException)10 IResource (org.eclipse.core.resources.IResource)8 BndEditModel (aQute.bnd.build.model.BndEditModel)7 Description (aQute.lib.getopt.Description)7 Bndrun (biz.aQute.resolve.Bndrun)7 Attrs (aQute.bnd.header.Attrs)5 HttpClient (aQute.bnd.http.HttpClient)5 Jar (aQute.bnd.osgi.Jar)5