Search in sources :

Example 1 with UTF8Properties

use of aQute.lib.utf8properties.UTF8Properties in project intellij-plugins by JetBrains.

the class BundleManifestCache method readProperties.

private static BundleManifest readProperties(PsiFile propertiesFile) {
    try {
        UTF8Properties properties = new UTF8Properties();
        properties.load(new StringReader(propertiesFile.getText()));
        Map<String, String> map = ContainerUtil.newHashMap();
        for (Object key : properties.keySet()) {
            String name = key.toString();
            map.put(name, properties.getProperty(name));
        }
        if (map.get(Constants.BUNDLE_SYMBOLICNAME) == null) {
            VirtualFile file = propertiesFile.getVirtualFile();
            if (file != null) {
                if (!BndProjectImporter.BND_FILE.equals(file.getName())) {
                    map.put(Constants.BUNDLE_SYMBOLICNAME, FileUtil.getNameWithoutExtension(file.getName()));
                } else if (file.getParent() != null) {
                    map.put(Constants.BUNDLE_SYMBOLICNAME, file.getParent().getName());
                }
            }
        }
        return new BundleManifest(map, propertiesFile);
    } catch (IOException ignored) {
    } catch (InvalidVirtualFileAccessException ignored) {
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) StringReader(java.io.StringReader) IOException(java.io.IOException) InvalidVirtualFileAccessException(com.intellij.openapi.vfs.InvalidVirtualFileAccessException) UTF8Properties(aQute.lib.utf8properties.UTF8Properties)

Example 2 with UTF8Properties

use of aQute.lib.utf8properties.UTF8Properties in project bnd by bndtools.

the class Analyzer method parsePackageinfo.

Attrs parsePackageinfo(PackageRef packageRef, Resource r) throws Exception {
    Properties p = new UTF8Properties();
    try {
        try (InputStream in = r.openInputStream()) {
            p.load(in);
        }
        Attrs attrs = new Attrs();
        for (@SuppressWarnings("unchecked") Enumeration<String> t = (Enumeration<String>) p.propertyNames(); t.hasMoreElements(); ) {
            String key = t.nextElement();
            String propvalue = p.getProperty(key);
            if (key.equalsIgnoreCase("include")) {
                // Ouch, could be really old syntax
                // We ignore the include part upto we
                // ignored it long before.
                Matcher m = OLD_PACKAGEINFO_SYNTAX_P.matcher(propvalue);
                if (m.matches()) {
                    key = Constants.VERSION_ATTRIBUTE;
                    propvalue = m.group(2);
                    if (isPedantic())
                        warning("found old syntax in package info in package %s, from resource %s", packageRef, r);
                }
            }
            String value = propvalue;
            if (value.startsWith(":")) {
                key = key + ":";
                value = value.substring(1);
            }
            attrs.put(key, value);
        }
        return attrs;
    } catch (Exception e) {
        msgs.NoSuchFile_(r);
    }
    return null;
}
Also used : Enumeration(java.util.Enumeration) Matcher(java.util.regex.Matcher) InputStream(java.io.InputStream) Attrs(aQute.bnd.header.Attrs) UTF8Properties(aQute.lib.utf8properties.UTF8Properties) Properties(java.util.Properties) ParseException(java.text.ParseException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) UTF8Properties(aQute.lib.utf8properties.UTF8Properties)

Example 3 with UTF8Properties

use of aQute.lib.utf8properties.UTF8Properties in project bnd by bndtools.

the class Workspace method getDefaults.

public static synchronized Processor getDefaults() {
    if (defaults != null)
        return defaults;
    UTF8Properties props = new UTF8Properties();
    try (InputStream propStream = Workspace.class.getResourceAsStream("defaults.bnd")) {
        if (propStream != null) {
            props.load(propStream);
        } else {
            System.err.println("Cannot load defaults");
        }
    } catch (IOException e) {
        throw new IllegalArgumentException("Unable to load bnd defaults.", e);
    }
    defaults = new Processor(props, false);
    return defaults;
}
Also used : Processor(aQute.bnd.osgi.Processor) JarInputStream(java.util.jar.JarInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) UTF8Properties(aQute.lib.utf8properties.UTF8Properties)

Example 4 with UTF8Properties

use of aQute.lib.utf8properties.UTF8Properties in project bnd by bndtools.

the class Processor method loadProperties.

/**
	 * Helper to load a properties file from disk.
	 *
	 * @param file
	 * @throws IOException
	 */
public Properties loadProperties(File file) throws IOException {
    updateModified(file.lastModified(), "Properties file: " + file);
    UTF8Properties p = loadProperties0(file);
    return p;
}
Also used : UTF8Properties(aQute.lib.utf8properties.UTF8Properties)

Example 5 with UTF8Properties

use of aQute.lib.utf8properties.UTF8Properties in project bnd by bndtools.

the class KnownBundleAnalyzerPlugin method setProperties.

public void setProperties(Map<String, String> config) {
    String fileName = config.get(PROP_DATA);
    if (fileName == null)
        throw new IllegalArgumentException(String.format("Property name '%s' must be set on KnownBundleAnalyzerPlugin", PROP_DATA));
    File file = new File(fileName);
    if (!file.isFile())
        throw new IllegalArgumentException(String.format("Data file does not exist, or is not a plain file: %s", file));
    try {
        UTF8Properties props = new UTF8Properties();
        props.load(file, null);
        setKnownBundlesExtra(props);
    } catch (Exception e) {
        throw new IllegalArgumentException(String.format("Unable to read data file: %s", file), e);
    }
}
Also used : File(java.io.File) 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