Search in sources :

Example 1 with ByteBufferOutputStream

use of aQute.lib.io.ByteBufferOutputStream 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

EmbeddedResource (aQute.bnd.osgi.EmbeddedResource)1 Jar (aQute.bnd.osgi.Jar)1 JarResource (aQute.bnd.osgi.JarResource)1 Resource (aQute.bnd.osgi.Resource)1 ByteBufferOutputStream (aQute.lib.io.ByteBufferOutputStream)1 UTF8Properties (aQute.lib.utf8properties.UTF8Properties)1 File (java.io.File)1 InputStream (java.io.InputStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1