use of aQute.libg.command.Command in project bnd by bndtools.
the class Project method getCommonJavac.
private Command getCommonJavac(boolean test) throws Exception {
Command javac = new Command();
javac.add(getProperty("javac", "javac"));
String target = getProperty("javac.target", "1.6");
String profile = getProperty("javac.profile", "");
String source = getProperty("javac.source", "1.6");
String debug = getProperty("javac.debug");
if ("on".equalsIgnoreCase(debug) || "true".equalsIgnoreCase(debug))
debug = "vars,source,lines";
Parameters options = new Parameters(getProperty("java.options"), this);
boolean deprecation = isTrue(getProperty("java.deprecation"));
javac.add("-encoding", "UTF-8");
javac.add("-source", source);
javac.add("-target", target);
if (!profile.isEmpty())
javac.add("-profile", profile);
if (deprecation)
javac.add("-deprecation");
if (test || debug == null) {
javac.add("-g:source,lines,vars" + debug);
} else {
javac.add("-g:" + debug);
}
for (String option : options.keySet()) javac.add(option);
StringBuilder bootclasspath = new StringBuilder();
String bootclasspathDel = "-Xbootclasspath/p:";
Collection<Container> bcp = Container.flatten(getBootclasspath());
for (Container c : bcp) {
bootclasspath.append(bootclasspathDel).append(c.getFile().getAbsolutePath());
bootclasspathDel = File.pathSeparator;
}
if (bootclasspath.length() != 0) {
javac.add(bootclasspath.toString());
}
return javac;
}
use of aQute.libg.command.Command in project bnd by bndtools.
the class ProjectLauncher method launch.
public int launch() throws Exception {
prepare();
java = new Command();
//
// Handle the environment
//
Map<String, String> env = getRunEnv();
for (Map.Entry<String, String> e : env.entrySet()) {
java.var(e.getKey(), e.getValue());
}
java.add(project.getProperty("java", getJavaExecutable()));
String javaagent = project.getProperty(Constants.JAVAAGENT);
if (Processor.isTrue(javaagent)) {
for (String agent : agents) {
java.add("-javaagent:" + agent);
}
}
String jdb = getRunJdb();
if (jdb != null) {
int port = 1044;
try {
port = Integer.parseInt(project.getProperty(Constants.RUNJDB));
} catch (Exception e) {
// ok, value can also be ok, or on, or true
}
String suspend = port > 0 ? "y" : "n";
java.add("-Xrunjdwp:server=y,transport=dt_socket,address=" + Math.abs(port) + ",suspend=" + suspend);
}
java.add("-cp");
java.add(Processor.join(getClasspath(), File.pathSeparator));
java.addAll(getRunVM());
java.add(getMainTypeName());
java.addAll(getRunProgramArgs());
if (timeout != 0)
java.setTimeout(timeout + 1000, TimeUnit.MILLISECONDS);
File cwd = getCwd();
if (cwd != null)
java.setCwd(cwd);
logger.debug("cmd line {}", java);
try {
int result = java.execute(in, out, err);
if (result == Integer.MIN_VALUE)
return TIMEDOUT;
reportResult(result);
return result;
} finally {
cleanup();
listeners.clear();
}
}
use of aQute.libg.command.Command in project bnd by bndtools.
the class MavenDeploy method javadoc.
private Jar javadoc(File tmp, Project b, Set<String> exports) throws Exception {
Command command = new Command();
command.add(b.getProperty("javadoc", "javadoc"));
command.add("-d");
command.add(tmp.getAbsolutePath());
command.add("-sourcepath");
command.add(Processor.join(b.getSourcePath(), File.pathSeparator));
for (String packageName : exports) {
command.add(packageName);
}
StringBuilder out = new StringBuilder();
StringBuilder err = new StringBuilder();
Command c = new Command();
c.setTrace();
int result = c.execute(out, err);
if (result == 0) {
Jar jar = new Jar(tmp);
b.addClose(jar);
return jar;
}
b.error("Error during execution of javadoc command: %s / %s", out, err);
return null;
}
use of aQute.libg.command.Command in project bnd by bndtools.
the class MavenCommand method javadoc.
private Jar javadoc(File source, Set<String> exports, Manifest m, Properties p) throws Exception {
File tmp = new File(temp, "javadoc");
IO.mkdirs(tmp);
Command command = new Command();
command.add(getProperty("javadoc", "javadoc"));
command.add("-quiet");
command.add("-protected");
// command.add("-classpath");
// command.add(binary.getAbsolutePath());
command.add("-d");
command.add(tmp.getAbsolutePath());
command.add("-charset");
command.add("UTF-8");
command.add("-sourcepath");
command.add(source.getAbsolutePath());
Attributes attr = m.getMainAttributes();
Properties pp = new UTF8Properties(p);
set(pp, "-doctitle", description(attr));
set(pp, "-header", description(attr));
set(pp, "-windowtitle", name(attr));
set(pp, "-bottom", copyright(attr));
set(pp, "-footer", license(attr));
command.add("-tag");
command.add("Immutable:t:Immutable");
command.add("-tag");
command.add("ThreadSafe:t:ThreadSafe");
command.add("-tag");
command.add("NotThreadSafe:t:NotThreadSafe");
command.add("-tag");
command.add("GuardedBy:mf:Guarded By:");
command.add("-tag");
command.add("security:m:Required Permissions");
command.add("-tag");
command.add("noimplement:t:Consumers of this API must not implement this interface");
for (Enumeration<?> e = pp.propertyNames(); e.hasMoreElements(); ) {
String key = (String) e.nextElement();
String value = pp.getProperty(key);
if (key.startsWith("javadoc")) {
key = key.substring("javadoc".length());
removeDuplicateMarker(key);
command.add(key);
command.add(value);
}
}
for (String packageName : exports) {
command.add(packageName);
}
StringBuilder out = new StringBuilder();
StringBuilder err = new StringBuilder();
System.err.println(command);
int result = command.execute(out, err);
if (result != 0) {
warning("Error during execution of javadoc command: %s\n******************\n%s", out, err);
}
Jar jar = new Jar(tmp);
addClose(jar);
return jar;
}
use of aQute.libg.command.Command in project bnd by bndtools.
the class FileRepo method exec.
/**
* Execute a command. Used in different stages so that the repository can be
* synced with external tools.
*
* @param line
* @param target
*/
void exec(String line, Object... args) {
if (line == null) {
logger.debug("Line is empty, args={}", args == null ? new Object[0] : args);
return;
}
logger.debug("exec {}", line);
try {
if (args != null) {
for (int i = 0; i < args.length; i++) {
if (i == 0) {
// replaceAll backslash magic ensures windows paths
// remain intact
line = line.replaceAll("\\$\\{@\\}", args[0].toString().replaceAll("\\\\", "\\\\\\\\"));
}
// replaceAll backslash magic ensures windows paths remain
// intact
line = line.replaceAll("\\$" + i, args[i].toString().replaceAll("\\\\", "\\\\\\\\"));
}
}
// purge remaining placeholders
line = line.replaceAll("\\s*\\$[0-9]\\s*", "");
int result = 0;
StringBuilder stdout = new StringBuilder();
StringBuilder stderr = new StringBuilder();
if (System.getProperty("os.name").toLowerCase().indexOf("win") >= 0) {
// FIXME ignoring possible shell setting stdin approach used
// below does not work in windows
Command cmd = new Command("cmd.exe /C " + line);
cmd.setCwd(getRoot());
result = cmd.execute(stdout, stderr);
} else {
if (shell == null) {
shell = "sh";
}
Command cmd = new Command(shell);
cmd.setCwd(getRoot());
if (path != null) {
cmd.inherit();
String oldpath = cmd.var("PATH");
path = path.replaceAll("\\s*,\\s*", File.pathSeparator);
path = path.replaceAll("\\$\\{@\\}", oldpath);
cmd.var("PATH", path);
}
result = cmd.execute(line, stdout, stderr);
}
if (result != 0) {
reporter.error("Command %s failed with %s %s %s", line, result, stdout, stderr);
}
} catch (Exception e) {
e.printStackTrace();
reporter.exception(e, "%s", e);
}
}
Aggregations