use of aQute.lib.utf8properties.UTF8Properties in project bnd by bndtools.
the class Env method setProperties.
public void setProperties(URI uri) throws Exception {
UTF8Properties props = new UTF8Properties();
try (InputStream in = uri.toURL().openStream()) {
props.load(in, null, this);
}
putAll(props);
}
use of aQute.lib.utf8properties.UTF8Properties in project bnd by bndtools.
the class ExpandPropertiesTask method execute.
@Override
@SuppressWarnings("cast")
public void execute() throws BuildException {
try {
if (propertyFile.exists()) {
Properties properties = new UTF8Properties();
properties.putAll((Map<?, ?>) getProject().getProperties());
try (Processor processor = new Processor(properties)) {
processor.setProperties(propertyFile);
Project project = getProject();
Properties flattened = processor.getFlattenedProperties();
for (Iterator<Object> i = flattened.keySet().iterator(); i.hasNext(); ) {
String key = (String) i.next();
if (project.getProperty(key) == null) {
project.setProperty(key, flattened.getProperty(key));
}
}
}
}
report();
} catch (IOException e) {
e.printStackTrace();
throw new BuildException(e);
}
}
use of aQute.lib.utf8properties.UTF8Properties in project bnd by bndtools.
the class bnd method _convert.
@Description("Converter to different formats")
public void _convert(convertOptions opts) throws IOException {
File from = getFile(opts._arguments().get(0));
File to = getFile(opts._arguments().get(1));
if (opts.m2p()) {
try (InputStream in = IO.stream(from)) {
Properties p = new UTF8Properties();
Manifest m = new Manifest(in);
Attributes attrs = m.getMainAttributes();
for (Map.Entry<Object, Object> i : attrs.entrySet()) {
p.put(i.getKey().toString(), i.getValue().toString());
}
try (OutputStream fout = IO.outputStream(to)) {
if (opts.xml())
p.storeToXML(fout, "converted from " + from);
else {
try (Writer osw = IO.writer(fout, UTF_8)) {
p.store(osw, "converted from " + from);
}
}
}
}
return;
}
error("no conversion specified");
}
use of aQute.lib.utf8properties.UTF8Properties in project bnd by bndtools.
the class Plugins method getAnnotatedPlugins.
private Map<String, Class<?>> getAnnotatedPlugins() throws IOException {
if (annotatedPlugins == null) {
annotatedPlugins = new TreeMap<String, Class<?>>();
try (InputStream in = bnd.class.getResourceAsStream("bnd.info")) {
Properties p = new UTF8Properties();
p.load(in);
Parameters classes = new Parameters(p.getProperty("plugins"), bnd);
for (String cname : classes.keySet()) {
try {
Class<?> c = getClass().getClassLoader().loadClass(cname);
aQute.bnd.annotation.plugin.BndPlugin annotation = c.getAnnotation(aQute.bnd.annotation.plugin.BndPlugin.class);
if (annotation != null) {
annotatedPlugins.put(annotation.name(), c);
}
} catch (Exception ex) {
bnd.error("Cannot find plugin %s", cname);
}
}
}
}
return annotatedPlugins;
}
use of aQute.lib.utf8properties.UTF8Properties in project bnd by bndtools.
the class Project method script.
@SuppressWarnings({ "unchecked", "rawtypes" })
public void script(String type, String script, Object... args) throws Exception {
// TODO check tyiping
List<Scripter> scripters = getPlugins(Scripter.class);
if (scripters.isEmpty()) {
msgs.NoScripters_(script);
return;
}
Properties p = new UTF8Properties(getProperties());
for (int i = 0; i < args.length; i++) p.setProperty("" + i, Converter.cnv(String.class, args[i]));
scripters.get(0).eval((Map) p, new StringReader(script));
}
Aggregations