Search in sources :

Example 31 with UTF8Properties

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

the class Project method _ide.

public String _ide(String[] args) throws IOException {
    if (args.length < 2) {
        error("The ${ide;<>} macro needs an argument");
        return null;
    }
    if (ide == null) {
        ide = new UTF8Properties();
        File file = getFile(".settings/org.eclipse.jdt.core.prefs");
        if (!file.isFile()) {
            error("The ${ide;<>} macro requires a .settings/org.eclipse.jdt.core.prefs file in the project");
            return null;
        }
        try (InputStream in = IO.stream(file)) {
            ide.load(in);
        }
    }
    String deflt = args.length > 2 ? args[2] : null;
    if ("javac.target".equals(args[1])) {
        return ide.getProperty("org.eclipse.jdt.core.compiler.codegen.targetPlatform", deflt);
    }
    if ("javac.source".equals(args[1])) {
        return ide.getProperty("org.eclipse.jdt.core.compiler.source", deflt);
    }
    return null;
}
Also used : BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) File(java.io.File) UTF8Properties(aQute.lib.utf8properties.UTF8Properties)

Example 32 with UTF8Properties

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

the class BndEditModel method getProperties.

/**
	 * Return a processor for this model. This processor is based on the parent
	 * project or the bndrun file. It will contain the properties of the project
	 * file and the changes from the model.
	 * 
	 * @return a processor that reflects the actual project or bndrun file setup
	 */
public Processor getProperties() throws Exception {
    Processor parent = null;
    if (isProjectFile() && project != null)
        parent = project;
    else if (getBndResource() != null) {
        parent = Workspace.getRun(getBndResource());
        if (parent == null) {
            parent = new Processor();
            parent.setProperties(getBndResource(), getBndResource().getParentFile());
        }
    }
    Processor result;
    if (parent == null)
        result = new Processor();
    else
        result = new Processor(parent);
    StringBuilder sb = new StringBuilder();
    for (Entry<String, String> e : changesToSave.entrySet()) {
        sb.append(e.getKey()).append(": ").append(e.getValue()).append("\n\n");
    }
    UTF8Properties p = new UTF8Properties();
    p.load(new StringReader(sb.toString()));
    result.getProperties().putAll(properties);
    result.getProperties().putAll(p);
    return result;
}
Also used : Processor(aQute.bnd.osgi.Processor) StringReader(java.io.StringReader) UTF8Properties(aQute.lib.utf8properties.UTF8Properties)

Example 33 with UTF8Properties

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

the class GenerateLauncherJarRunnable method run.

@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException {
    try {
        Entry<String, Resource> export = project.export("bnd.executablejar", Collections.emptyMap());
        if (export != null) {
            try (JarResource r = (JarResource) export.getValue()) {
                File destination = new File(path);
                Jar jar = r.getJar();
                if (folder) {
                    // Set launch.embedded=false since we expanded to folder
                    Resource launcherprops = jar.getResource("launcher.properties");
                    if (launcherprops != null) {
                        UTF8Properties props = new UTF8Properties();
                        try (InputStream in = launcherprops.openInputStream()) {
                            props.load(in);
                        }
                        props.put("launch.embedded", Boolean.toString(false));
                        try (ByteBufferOutputStream bbos = new ByteBufferOutputStream(((int) launcherprops.size()) + 1)) {
                            props.store(bbos);
                            launcherprops = new EmbeddedResource(bbos.toByteBuffer(), launcherprops.lastModified());
                        }
                        jar.putResource("launcher.properties", launcherprops);
                    }
                    jar.writeFolder(destination);
                    File start = IO.getFile(destination, "start");
                    if (start.isFile()) {
                        start.setExecutable(true);
                    }
                } else {
                    jar.write(destination);
                }
            }
        }
    } catch (Exception e) {
        throw new InvocationTargetException(e);
    }
}
Also used : EmbeddedResource(aQute.bnd.osgi.EmbeddedResource) ByteBufferOutputStream(aQute.lib.io.ByteBufferOutputStream) JarResource(aQute.bnd.osgi.JarResource) InputStream(java.io.InputStream) JarResource(aQute.bnd.osgi.JarResource) EmbeddedResource(aQute.bnd.osgi.EmbeddedResource) Resource(aQute.bnd.osgi.Resource) Jar(aQute.bnd.osgi.Jar) File(java.io.File) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) 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