]> WPIA git - gigi.git/blobdiff - src/org/cacert/gigi/DevelLauncher.java
Implement template hot-redeploy :-).
[gigi.git] / src / org / cacert / gigi / DevelLauncher.java
index d3368c0dd96bcf55dab9e9653a887d181419b508..254b1e72f05d1e37b3816d0a9154b452874d9468 100644 (file)
@@ -7,11 +7,18 @@ import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.OutputStream;
 import java.nio.file.Files;
 import java.nio.file.Paths;
 import java.util.Properties;
 
+import org.kamranzafar.jtar.TarEntry;
+import org.kamranzafar.jtar.TarHeader;
+import org.kamranzafar.jtar.TarOutputStream;
+
 public class DevelLauncher {
+       public static final boolean DEVEL = true;
+
        public static void main(String[] args) throws Exception {
                Properties mainProps = new Properties();
                mainProps.load(new FileInputStream("config/gigi.properties"));
@@ -25,37 +32,45 @@ public class DevelLauncher {
                ByteArrayOutputStream chunkConfig = new ByteArrayOutputStream();
                DataOutputStream dos = new DataOutputStream(chunkConfig);
                byte[] cacerts = Files.readAllBytes(Paths.get("config/cacerts.jks"));
-               byte[] keystore = Files.readAllBytes(Paths
-                               .get("config/keystore.pkcs12"));
+               byte[] keystore = Files.readAllBytes(Paths.get("config/keystore.pkcs12"));
 
-               DevelLauncher.writeGigiConfig(dos, new byte[]{}, "changeit".getBytes(),
-                               mainProps, cacerts, keystore);
+               DevelLauncher.writeGigiConfig(dos, "changeit".getBytes(), "changeit".getBytes(), mainProps, cacerts, keystore);
                dos.flush();
                InputStream oldin = System.in;
                System.setIn(new ByteArrayInputStream(chunkConfig.toByteArray()));
                Launcher.main(args);
                System.setIn(oldin);
        }
-       public static void writeGigiConfig(DataOutputStream target,
-                       byte[] keystorepw, byte[] truststorepw, Properties mainprop,
-                       byte[] cacerts, byte[] keystore) throws IOException {
-               writeChunk(target, GigiConfig.GIGI_CONFIG_VERSION.getBytes());
-               writeChunk(target, keystorepw);
-               writeChunk(target, truststorepw);
-               ByteArrayOutputStream props = new ByteArrayOutputStream();
-               mainprop.store(props, "");
-               writeChunk(target, props.toByteArray());
-               writeChunk(target, cacerts);
-               writeChunk(target, keystore);
 
+       public static void writeGigiConfig(OutputStream target, byte[] keystorepw, byte[] truststorepw,
+               Properties mainprop, byte[] cacerts, byte[] keystore) throws IOException {
+               TarOutputStream tos = new TarOutputStream(target);
+               ByteArrayOutputStream baos = new ByteArrayOutputStream();
+               mainprop.store(baos, "");
+
+               putTarEntry(baos.toByteArray(), tos, "gigi.properties");
+               putTarEntry(keystorepw, tos, "keystorepw");
+               putTarEntry(truststorepw, tos, "truststorepw");
+               putTarEntry(keystore, tos, "keystore.pkcs12");
+               putTarEntry(cacerts, tos, "cacerts.jks");
+               tos.close();
+
+       }
+
+       private static void putTarEntry(byte[] data, TarOutputStream tos, String name) throws IOException {
+               TarHeader th = new TarHeader();
+               th.name = new StringBuffer(name);
+               th.size = data.length;
+               tos.putNextEntry(new TarEntry(th));
+               tos.write(data);
        }
-       public static void writeChunk(DataOutputStream dos, byte[] chunk)
-                       throws IOException {
+
+       public static void writeChunk(DataOutputStream dos, byte[] chunk) throws IOException {
                dos.writeInt(chunk.length);
                dos.write(chunk);
        }
-       public static void launch(Properties props, File cacerts, File keystore)
-                       throws IOException {
+
+       public static void launch(Properties props, File cacerts, File keystore) throws IOException {
                ByteArrayOutputStream config = new ByteArrayOutputStream();
                props.store(config, "");
        }