Search in sources :

Example 21 with UTF8Properties

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;
}
Also used : InputStream(java.io.InputStream) UTF8Properties(aQute.lib.utf8properties.UTF8Properties) Properties(java.util.Properties) URL(java.net.URL) ParseException(java.text.ParseException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) UTF8Properties(aQute.lib.utf8properties.UTF8Properties)

Example 22 with UTF8Properties

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;
}
Also used : Attributes(java.util.jar.Attributes) UTF8Properties(aQute.lib.utf8properties.UTF8Properties) Properties(java.util.Properties) Manifest(java.util.jar.Manifest) UTF8Properties(aQute.lib.utf8properties.UTF8Properties)

Example 23 with UTF8Properties

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;
}
Also used : UTF8Properties(aQute.lib.utf8properties.UTF8Properties) Properties(java.util.Properties) UTF8Properties(aQute.lib.utf8properties.UTF8Properties)

Example 24 with UTF8Properties

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();
    }
}
Also used : FileNotFoundException(java.io.FileNotFoundException) InvocationTargetException(java.lang.reflect.InvocationTargetException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) UTF8Properties(aQute.lib.utf8properties.UTF8Properties)

Example 25 with 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;
}
Also used : Pattern(java.util.regex.Pattern) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) UTF8Properties(aQute.lib.utf8properties.UTF8Properties)

Aggregations

UTF8Properties (aQute.lib.utf8properties.UTF8Properties)33 Properties (java.util.Properties)18 File (java.io.File)14 InputStream (java.io.InputStream)11 IOException (java.io.IOException)10 Jar (aQute.bnd.osgi.Jar)7 Attributes (java.util.jar.Attributes)5 Manifest (java.util.jar.Manifest)5 FileNotFoundException (java.io.FileNotFoundException)4 StringReader (java.io.StringReader)4 Parameters (aQute.bnd.header.Parameters)3 Processor (aQute.bnd.osgi.Processor)3 MalformedURLException (java.net.MalformedURLException)3 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 Builder (aQute.bnd.osgi.Builder)2 EmbeddedResource (aQute.bnd.osgi.EmbeddedResource)2 Resource (aQute.bnd.osgi.Resource)2 LauncherConstants (aQute.launcher.constants.LauncherConstants)2 Command (aQute.libg.command.Command)2