Search in sources :

Example 26 with UTF8Properties

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

Example 27 with UTF8Properties

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);
    }
}
Also used : Project(org.apache.tools.ant.Project) Processor(aQute.bnd.osgi.Processor) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException) Properties(java.util.Properties) UTF8Properties(aQute.lib.utf8properties.UTF8Properties) UTF8Properties(aQute.lib.utf8properties.UTF8Properties)

Example 28 with UTF8Properties

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");
}
Also used : JarInputStream(java.util.jar.JarInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) Attributes(java.util.jar.Attributes) UTF8Properties(aQute.lib.utf8properties.UTF8Properties) Properties(java.util.Properties) Manifest(java.util.jar.Manifest) PomFromManifest(aQute.bnd.maven.PomFromManifest) File(java.io.File) MultiMap(aQute.lib.collections.MultiMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap) PrintWriter(java.io.PrintWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) UTF8Properties(aQute.lib.utf8properties.UTF8Properties) Description(aQute.lib.getopt.Description)

Example 29 with UTF8Properties

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;
}
Also used : Parameters(aQute.bnd.header.Parameters) InputStream(java.io.InputStream) BndPlugin(aQute.bnd.annotation.plugin.BndPlugin) Properties(java.util.Properties) UTF8Properties(aQute.lib.utf8properties.UTF8Properties) IOException(java.io.IOException) UTF8Properties(aQute.lib.utf8properties.UTF8Properties)

Example 30 with UTF8Properties

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