use of aQute.lib.utf8properties.UTF8Properties in project bnd by bndtools.
the class Analyzer method getBndInfo.
public String getBndInfo(String key, String defaultValue) {
if (bndInfo == null) {
try {
Properties bndInfoLocal = new UTF8Properties();
URL url = Analyzer.class.getResource("bnd.info");
if (url != null) {
try (InputStream in = url.openStream()) {
bndInfoLocal.load(in);
}
}
String v = bndInfoLocal.getProperty("version");
if (!Version.isVersion(v)) {
bndInfoLocal.put("version", About.CURRENT.toString());
}
bndInfo = bndInfoLocal;
} catch (Exception e) {
e.printStackTrace();
return defaultValue;
}
}
String value = bndInfo.getProperty(key);
if (value == null)
return defaultValue;
return value;
}
use of aQute.lib.utf8properties.UTF8Properties in project bnd by bndtools.
the class Processor method getManifestAsProperties.
/**
* Read a manifest but return a properties object.
*
* @param in
* @throws IOException
*/
public static Properties getManifestAsProperties(InputStream in) throws IOException {
Properties p = new UTF8Properties();
Manifest manifest = new Manifest(in);
for (Iterator<Object> it = manifest.getMainAttributes().keySet().iterator(); it.hasNext(); ) {
Attributes.Name key = (Attributes.Name) it.next();
String value = manifest.getMainAttributes().getValue(key);
p.put(key.toString(), value);
}
return p;
}
use of aQute.lib.utf8properties.UTF8Properties in project bnd by bndtools.
the class Processor method setParent.
public void setParent(Processor processor) {
this.parent = processor;
Properties updated = new UTF8Properties(processor.getProperties0());
updated.putAll(getProperties0());
properties = updated;
}
use of aQute.lib.utf8properties.UTF8Properties in project bnd by bndtools.
the class Processor method loadProperties0.
/**
* Load Properties from disk. The default encoding is ISO-8859-1 but
* nowadays all files are encoded with UTF-8. So we try to load it first as
* UTF-8 and if this fails we fail back to ISO-8859-1
*
* @param in The stream to load from
* @param name The name of the file for doc reasons
* @return a Properties
* @throws IOException
*/
UTF8Properties loadProperties0(File file) throws IOException {
String name = file.toURI().getPath();
int n = name.lastIndexOf('/');
if (n > 0)
name = name.substring(0, n);
if (name.length() == 0)
name = ".";
try {
UTF8Properties p = new UTF8Properties();
p.load(file, this);
return p.replaceAll("\\$\\{\\.\\}", Matcher.quoteReplacement(name));
} catch (Exception e) {
error("Error during loading properties file: %s, error: %s", name, e);
return new UTF8Properties();
}
}
use of aQute.lib.utf8properties.UTF8Properties in project bnd by bndtools.
the class Processor method replaceAll.
/**
* Replace a string in all the values of the map. This can be used to
* preassign variables that change. I.e. the base directory ${.} for a
* loaded properties
*/
public static Properties replaceAll(Properties p, String pattern, String replacement) {
UTF8Properties result = new UTF8Properties();
Pattern regex = Pattern.compile(pattern);
for (Map.Entry<Object, Object> entry : p.entrySet()) {
String key = (String) entry.getKey();
String value = (String) entry.getValue();
value = regex.matcher(value).replaceAll(replacement);
result.put(key, value);
}
return result;
}
Aggregations