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();
}
}
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());
}
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);
}
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());
}
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()));
}
Aggregations