1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
|
---
layout: default
class: Project
title: -runprogramargs
summary: Additional arguments for the program invokation.
---
public Collection<String> getRunProgramArgs() {
Parameters hdr = getParameters(RUNPROGRAMARGS);
return hdr.keySet();
}
/**
* Collect all the aspect from the project and set the local fields from
* them. Should be called
*
* @throws Exception
*/
protected void updateFromProject() throws Exception {
// pkr: could not use this because this is killing the runtests.
// project.refresh();
runbundles.clear();
Collection<Container> run = project.getRunbundles();
for (Container container : run) {
File file = container.getFile();
if (file != null && (file.isFile() || file.isDirectory())) {
runbundles.add(file.getAbsolutePath());
} else {
error("Bundle file \"%s\" does not exist, given error is %s", file, container.getError());
}
}
if (project.getRunBuilds()) {
File[] builds = project.build();
if (builds != null)
for (File file : builds)
runbundles.add(file.getAbsolutePath());
}
Collection<Container> runpath = project.getRunpath();
runsystempackages = new Parameters( project.mergeProperties(Constants.RUNSYSTEMPACKAGES));
runsystemcapabilities = project.mergeProperties(Constants.RUNSYSTEMCAPABILITIES);
framework = getRunframework(project.getProperty(Constants.RUNFRAMEWORK));
timeout = Processor.getDuration(project.getProperty(Constants.RUNTIMEOUT), 0);
trace = Processor.isTrue(project.getProperty(Constants.RUNTRACE));
runpath.addAll(project.getRunFw());
for (Container c : runpath) {
addClasspath(c);
}
runvm.addAll(project.getRunVM());
runprogramargs.addAll(project.getRunProgramArgs());
runproperties = project.getRunProperties();
storageDir = project.getRunStorage();
if (storageDir == null) {
storageDir = new File(project.getTarget(), "fw");
}
}
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", "java"));
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);
project.trace("cmd line %s", java);
try {
int result = java.execute(System.in, System.err, System.err);
if (result == Integer.MIN_VALUE)
return TIMEDOUT;
reportResult(result);
return result;
}
finally {
cleanup();
listeners.clear();
}
}
public int start(ClassLoader parent) throws Exception {
prepare();
//
// Intermediate class loader to not load osgi framework packages
// from bnd's loader. Unfortunately, bnd uses some osgi classes
// itself that would unnecessarily constrain the framework.
//
ClassLoader fcl = new ClassLoader(parent) {
protected Class< ? > loadClass(String name, boolean resolve) throws ClassNotFoundException {
if ( IGNORE.matcher(name).matches())
throw new ClassNotFoundException();
return super.loadClass(name, resolve);
}
};
//
// Load the class that would have gone to the class path
// i.e. the framework etc.
//
List<URL> cp = new ArrayList<URL>();
for (String path : getClasspath()) {
cp.add(new File(path).toURI().toURL());
}
URLClassLoader cl = new URLClassLoader(cp.toArray(new URL[cp.size()]), fcl);
String[] args = getRunProgramArgs().toArray(new String[0]);
Class< ? > main = cl.loadClass(getMainTypeName());
return invoke(main, args);
}
|