use of aQute.bnd.build.Workspace in project bnd by bndtools.
the class EnrouteCommand method _workspace.
public void _workspace(WorkspaceOptions opts) throws Exception {
File base = bnd.getBase();
String name = opts._arguments().get(0);
File workspaceDir = Processor.getFile(base, name);
name = workspaceDir.getName();
base = workspaceDir.getParentFile();
if (base == null) {
bnd.error("You cannot create a workspace in the root (%s). The parent of a workspace %n" + "must be a valid directory. Recommended is to dedicate a directory to %n" + "all (or related) workspaces.", workspaceDir);
return;
}
if (!opts.anyname() && !Verifier.isBsn(name)) {
bnd.error("You specified a workspace name that does not follow the recommended pattern " + "(it should be like a Bundle Symbolic name). It is a bit pedantic but it " + "really helps hwne you get many workspaces. If you insist on this name, use the -a/--anyname option.");
return;
}
Workspace ws = bnd.getWorkspace((File) null);
if (ws != null && ws.isValid()) {
bnd.error("You are currently in a workspace already (%s) in %s. You can only create a new workspace outside an existing workspace", ws, base);
return;
}
File eclipseDir = workspaceDir;
IO.mkdirs(workspaceDir);
if (!opts.single())
workspaceDir = new File(workspaceDir, "scm");
IO.mkdirs(workspaceDir);
if (!base.isDirectory()) {
bnd.error("Could not create directory for the bnd workspace %s", base);
} else if (!eclipseDir.isDirectory()) {
bnd.error("Could not create directory for the Eclipse workspace %s", eclipseDir);
}
if (!workspaceDir.isDirectory()) {
bnd.error("Could not create the workspace directory %s", workspaceDir);
return;
}
if (!opts.update() && !opts.force() && workspaceDir.list().length > 0) {
bnd.error("The workspace directory %s is not empty, specify -u/--update to update or -f/--force to replace", workspaceDir);
}
InputStream in = getClass().getResourceAsStream("/templates/enroute.zip");
if (in == null) {
bnd.error("Cannot find template in this jar %s", "/templates/enroute.zip");
return;
}
Pattern glob = Pattern.compile("[^/]+|cnf/.*|\\...+/.*");
copy(workspaceDir, in, glob, opts.force());
File readme = new File(workspaceDir, "README.md");
if (readme.isFile())
IO.copy(readme, bnd.out);
bnd.out.printf(//
"%nWorkspace %s created.%n%n" + //
" Start Eclipse:%n" + //
" 1) Select the Eclipse workspace %s%n" + " 2) Package Explorer context menu: Import/General/Existing Projects from %s%n" + "%n" + //
"", workspaceDir.getName(), eclipseDir, workspaceDir);
}
use of aQute.bnd.build.Workspace in project bnd by bndtools.
the class ResolveCommand method _resolve.
@Description("Resolve a bndrun file")
public void _resolve(ResolveOptions options) throws Exception {
Project project = bnd.getProject(options.project());
Workspace ws = null;
if (options.workspace() != null) {
File file = bnd.getFile(options.workspace());
if (file.isDirectory()) {
ws = Workspace.getWorkspace(file);
if (!ws.isValid()) {
error("Invalid workspace %s", file);
return;
}
} else {
error("Workspace directory %s is not a directory", file);
return;
}
} else {
if (project != null)
ws = project.getWorkspace();
}
List<String> paths = options._arguments();
for (String path : paths) {
File f = getFile(path);
if (!f.isFile()) {
error("Missing bndrun file: %s", f);
} else {
try (Bndrun bndrun = Bndrun.createBndrun(ws, f)) {
try {
String runbundles = bndrun.resolve(false, options.write(), runbundlesFormatter);
if (bndrun.isOk()) {
System.out.printf("# %-50s ok%n", f.getName());
if (options.bundles()) {
System.out.println(runbundles);
}
}
} catch (Exception e) {
System.out.printf("%-50s %s\n", f.getName(), e);
exception(e, "Failed to resolve %s: %s", f, e);
}
getInfo(bndrun);
}
}
}
}
use of aQute.bnd.build.Workspace in project bnd by bndtools.
the class PrepareTask method execute.
@Override
public void execute() throws BuildException {
try {
if (basedir == null || !basedir.isDirectory())
throw new BuildException("The given base dir does not exist " + basedir);
Workspace workspace = Workspace.getWorkspace(basedir.getParentFile());
workspace.addBasicPlugin(new ConsoleProgress());
Project project = workspace.getProject(basedir.getName());
if (project == null)
throw new BuildException("Unable to find bnd project in directory: " + basedir);
project.setProperty("in.ant", "true");
project.setProperty("environment", "ant");
// top project.
if (top != null && top.length() > 0 && !top.startsWith("$"))
project.setProperty("top", top);
project.setExceptions(true);
Properties properties = project.getFlattenedProperties();
checkForTesting(project, properties);
if (report() || report(workspace) || report(project))
throw new BuildException("Errors during preparing bnd");
copyProperties(properties);
} catch (Exception e) {
e.printStackTrace();
throw new BuildException(e);
}
}
use of aQute.bnd.build.Workspace in project bnd by bndtools.
the class ProjectBuildOrderTask method execute.
@Override
public void execute() throws BuildException {
try {
if (workspaceLocation == null) {
throw new BuildException("The given workspace dir is not set");
}
if (!workspaceLocation.isDirectory()) {
throw new BuildException("The given workspace dir not exist " + workspaceLocation);
}
if (projectLocation != null && bndFile == null) {
throw new BuildException("Attributes projectLocation and bndFile must be used together.");
}
Collection<Project> projects;
workspaceLocation = workspaceLocation.getCanonicalFile();
Workspace workspace = Workspace.getWorkspace(workspaceLocation);
if (projectLocation == null) {
// all projects in workspace
try {
for (Project project : workspace.getAllProjects()) {
project.setDelayRunDependencies(this.delayRunDependencies);
}
projects = workspace.getBuildOrder();
} catch (Exception e) {
throw new BuildException(e);
}
} else {
try (Project p = new Project(workspace, projectLocation, new File(projectLocation, bndFile))) {
p.setDelayRunDependencies(this.delayRunDependencies);
projects = p.getDependson();
}
}
StringBuilder sb = new StringBuilder();
String sep = "";
for (Project project : projects) {
sb.append(sep);
if (fullpath) {
sb.append(project.getBase().getAbsolutePath());
} else {
sb.append(project.getName());
}
sep = separator;
}
getProject().setProperty(propertyName, sb.toString());
} catch (Exception e) {
throw new BuildException(e);
}
}
use of aQute.bnd.build.Workspace in project bnd by bndtools.
the class ProjectTest method testCanonicalName.
/**
* Test linked canonical name
*/
public void testCanonicalName() throws Exception {
Workspace ws = getWorkspace("testresources/ws");
Project project = ws.getProject("p6");
project.setProperty("-outputmask", "blabla");
project.clean();
// Now we build it.
File[] files = project.build();
assertTrue(project.check());
assertNotNull(files);
assertEquals(1, files.length);
assertEquals("blabla", files[0].getName());
File f = new File(project.getTarget(), "p6.jar");
assertTrue(f.isFile());
}
Aggregations