use of aQute.libg.sed.Sed in project bnd by bndtools.
the class bnd method _bash.
@Description("Generate autocompletion file for bash")
public void _bash(Options options) throws Exception {
File tmp = File.createTempFile("bnd-completion", ".tmp");
tmp.deleteOnExit();
try {
IO.copy(getClass().getResource("bnd-completion.bash"), tmp);
Sed sed = new Sed(tmp);
sed.setBackup(false);
Reporter r = new ReporterAdapter();
CommandLine c = new CommandLine(r);
Map<String, Method> commands = c.getCommands(this);
StringBuilder sb = new StringBuilder();
for (String commandName : commands.keySet()) {
sb.append(" " + commandName);
}
sb.append(" help");
sed.replace("%listCommands%", sb.toString().substring(1));
sed.doIt();
IO.copy(tmp, out);
} finally {
IO.delete(tmp);
}
}
use of aQute.libg.sed.Sed in project bnd by bndtools.
the class Platform method parseCompletion.
public void parseCompletion(Object target, File f) throws Exception {
IO.copy(getClass().getResource("unix/jpm-completion.bash"), f);
Sed sed = new Sed(f);
sed.setBackup(false);
Reporter r = new ReporterAdapter();
CommandLine c = new CommandLine(r);
Map<String, Method> commands = c.getCommands(target);
StringBuilder sb = new StringBuilder();
for (String commandName : commands.keySet()) {
sb.append(" " + commandName);
}
sb.append(" help");
sed.replace("%listJpmCommands%", sb.toString().substring(1));
sed.doIt();
}
use of aQute.libg.sed.Sed in project bnd by bndtools.
the class Project method replace.
boolean replace(File f, String pattern, String replacement) throws IOException {
final Macro macro = getReplacer();
Sed sed = new Sed(new Replacer() {
public String process(String line) {
return macro.process(line);
}
}, f);
sed.replace(pattern, replacement);
return sed.doIt() > 0;
}
use of aQute.libg.sed.Sed in project bnd by bndtools.
the class Platform method process.
protected void process(String resource, CommandData data, String path, Map<String, String> map, String... extra) throws Exception {
File file = new File(path);
copy(getClass().getResourceAsStream(resource), file);
Sed sed = new Sed(file);
sed.setBackup(false);
if (data.title == null || data.title.trim().length() == 0)
data.title = data.name;
//
// Allow commands to be done in java or javaw
//
sed.replace("%java%", data.windows ? "javaw" : "java");
for (Field key : data.getClass().getFields()) {
Object value = key.get(data);
if (value == null) {
value = "";
}
// executed as one command and thus logged as one command
if ("epilog".equals(key.getName()) || "prolog".equals(key.getName())) {
String s = (String) value;
if (s != null && s.trim().length() > 0) {
value = "(" + s + ")";
}
}
String v = "" + value;
v = v.replace("\\", "\\\\");
sed.replace("%" + key.getName() + "%", v);
}
ExtList<String> deps = new ExtList<String>();
for (byte[] dependency : data.dependencies) {
ArtifactData d = jpm.get(dependency);
deps.add(d.file);
}
for (String x : extra) {
deps.add(x);
}
String classpath = deps.join(File.pathSeparator);
sed.replace("%classpath%", classpath.replace("\\", "\\\\"));
if (map != null) {
StringBuilder sb = new StringBuilder();
String del = "-D";
for (Map.Entry<String, String> e : map.entrySet()) {
sed.replace("%" + e.getKey() + "%", e.getValue());
sb.append(del).append(e.getKey()).append("=\"").append(e.getValue()).append("\"");
del = " -D";
}
sed.replace("%defines%", sb.toString());
} else {
sed.replace("%defines%", "");
}
sed.doIt();
}
Aggregations