use of aQute.bnd.build.Project in project bnd by bndtools.
the class bnd method runtTest.
/**
* Help function to run the tests
*/
private int runtTest(File testFile, Workspace ws, File reportDir, Tag summary) throws Exception {
File tmpDir = new File(reportDir, "tmp");
IO.mkdirs(tmpDir);
tmpDir.deleteOnExit();
Tag test = new Tag(summary, "test");
test.addAttribute("path", testFile.getAbsolutePath());
if (!testFile.isFile()) {
error("No bnd file: %s", testFile);
test.addAttribute("exception", "No bnd file found");
error("No bnd file found for %s", testFile.getAbsolutePath());
return 1;
}
Project project = new Project(ws, testFile.getAbsoluteFile().getParentFile(), testFile.getAbsoluteFile());
project.use(this);
project.setProperty(NOBUNDLES, "true");
ProjectTester tester = project.getProjectTester();
if (!project.isOk()) {
getInfo(project, project.toString() + ": " + testFile.getName() + ":");
// Indicate failure but do not abort
return 1;
}
tester.setContinuous(false);
tester.setReportDir(tmpDir);
test.addAttribute("title", project.toString());
long start = System.currentTimeMillis();
try {
int errors = tester.test();
Collection<File> reports = tester.getReports();
for (File report : reports) {
Tag bundle = new Tag(test, "bundle");
File dest = new File(reportDir, report.getName());
IO.rename(report, dest);
bundle.addAttribute("file", dest.getAbsolutePath());
doPerReport(bundle, dest);
}
switch(errors) {
case ProjectLauncher.OK:
return 0;
case ProjectLauncher.CANCELED:
test.addAttribute("failed", "canceled");
return 1;
case ProjectLauncher.DUPLICATE_BUNDLE:
test.addAttribute("failed", "duplicate bundle");
return 1;
case ProjectLauncher.ERROR:
test.addAttribute("failed", "unknown reason");
return 1;
case ProjectLauncher.RESOLVE_ERROR:
test.addAttribute("failed", "resolve error");
return 1;
case ProjectLauncher.TIMEDOUT:
test.addAttribute("failed", "timed out");
return 1;
case ProjectLauncher.WARNING:
test.addAttribute("warning", "true");
return 1;
case ProjectLauncher.ACTIVATOR_ERROR:
test.addAttribute("failed", "activator error");
return 1;
default:
if (errors > 0) {
test.addAttribute("errors", errors);
return errors;
}
test.addAttribute("failed", "unknown reason");
return errors;
}
} catch (Exception e) {
test.addAttribute("failed", e);
exception(e, "Exception in run %s", e);
return 1;
} finally {
long duration = System.currentTimeMillis() - start;
test.addAttribute("duration", (duration + 500) / 1000);
getInfo(project, project.toString() + ": ");
}
}
use of aQute.bnd.build.Project in project bnd by bndtools.
the class bnd method _release.
/**
* Release the project
*
* @throws Exception
*/
@Description("Release this project")
public void _release(releaseOptions options) throws Exception {
Set<Project> projects = new LinkedHashSet<Project>();
Workspace ws = Workspace.findWorkspace(getBase());
if (ws == null) {
error("Workspace option was specified but cannot find a workspace from %s", getBase());
return;
}
if (options.workspace()) {
projects.addAll(ws.getAllProjects());
}
Project project = getProject(options.project());
if (project != null) {
projects.add(project);
}
if (projects.isEmpty()) {
error("Cannot find any projects");
return;
}
String repo = options.repo();
if (repo != null) {
RepositoryPlugin repository = ws.getRepository(repo);
if (repository == null) {
error("No such release repo %s%nFound:%n%s", repository, Strings.join("\n", ws.getRepositories()));
}
}
for (Project p : projects) {
if (repo != null) {
p.setProperty(Constants.RELEASEREPO, repo);
}
p.release(options.test());
}
getInfo(project);
}
use of aQute.bnd.build.Project in project bnd by bndtools.
the class bnd method _bsn2url.
public void _bsn2url(Bsn2UrlOptions opts) throws Exception {
Project p = getProject(opts.project());
if (p == null) {
error("You need to be in a project or specify the project with -p/--project");
return;
}
MultiMap<String, Version> revisions = new MultiMap<String, Version>();
for (RepositoryPlugin repo : p.getPlugins(RepositoryPlugin.class)) {
if (!(repo instanceof InfoRepository))
continue;
for (String bsn : repo.list(null)) {
revisions.addAll(bsn, repo.versions(bsn));
}
}
for (List<Version> versions : revisions.values()) {
Collections.sort(versions, Collections.reverseOrder());
}
List<String> files = opts._arguments();
for (String f : files) {
try (BufferedReader r = IO.reader(getFile(f))) {
String line;
nextLine: while ((line = r.readLine()) != null) {
Matcher matcher = LINE_P.matcher(line);
if (!matcher.matches())
continue nextLine;
line = matcher.group(1);
Parameters bundles = new Parameters(line, this);
for (Map.Entry<String, Attrs> entry : bundles.entrySet()) {
String bsn = entry.getKey();
VersionRange range = new VersionRange(entry.getValue().getVersion());
List<Version> versions = revisions.get(bsn);
if (versions == null) {
error("No for versions for %s", bsn);
break nextLine;
}
for (Version version : versions) {
if (range.includes(version)) {
for (RepositoryPlugin repo : p.getPlugins(RepositoryPlugin.class)) {
if (!(repo instanceof InfoRepository))
continue;
InfoRepository rp = (InfoRepository) repo;
ResourceDescriptor descriptor = rp.getDescriptor(bsn, version);
if (descriptor == null) {
error("Found bundle, but no descriptor %s;version=%s", bsn, version);
return;
}
out.println(descriptor.url + " #" + descriptor.bsn + ";version=" + descriptor.version);
}
}
}
}
}
} catch (Exception e) {
error("failed to create url list from file %s : %s", f, e);
}
}
}
use of aQute.bnd.build.Project in project bnd by bndtools.
the class bnd method _deliverables.
@Description("Show all deliverables from this workspace. with their current version and path.")
public void _deliverables(deliverableOptions options) throws Exception {
Project project = getProject(options.project());
if (project == null) {
messages.NoProject();
return;
}
Collection<Project> projects;
if (options.limit())
projects = Arrays.asList(project);
else
projects = project.getWorkspace().getAllProjects();
List<Container> containers = new ArrayList<Container>();
for (Project p : projects) {
containers.addAll(p.getDeliverables());
}
for (Container c : containers) {
Version v = new Version(c.getVersion());
err.printf("%-40s %8s %s\n", c.getBundleSymbolicName(), v.getWithoutQualifier(), c.getFile());
}
getInfo(project);
}
use of aQute.bnd.build.Project in project bnd by bndtools.
the class bnd method _bump.
/**
* Bump a version number
*
* @throws Exception
*/
@Description("Bumps the version of a project")
public void _bump(bumpoptions options) throws Exception {
Project project = getProject(options.project());
if (project == null) {
messages.NoProject();
return;
}
String mask = null;
if (!options._arguments().isEmpty()) {
mask = options._arguments().get(0);
if (mask.equalsIgnoreCase("major"))
mask = "+00";
else if (mask.equalsIgnoreCase("minor"))
mask = "=+0";
else if (mask.equalsIgnoreCase("micro"))
mask = "==+";
else if (!mask.matches("[+=0]{1,3}")) {
messages.InvalidBumpMask_(mask);
return;
}
}
if (mask == null)
project.bump();
else
project.bump(mask);
getInfo(project);
err.println(project.getProperty(BUNDLE_VERSION, "No version found"));
}
Aggregations