Search in sources :

Example 1 with UnzipUtility

use of com.codename1.impl.javase.UnzipUtility in project CodenameOne by codenameone.

the class CN1Console method downloadGroovy.

private void downloadGroovy() throws IOException {
    try {
        String url = GROOVY_URL;
        if (url == null) {
            throw new RuntimeException("No Groovy URL found for this platform");
        }
        File groovyDir = new File(GROOVY_HOME);
        if (groovyDir.exists()) {
            delTree(groovyDir);
        }
        groovyDir.getParentFile().mkdirs();
        File groovyZip = new File(groovyDir.getParentFile(), "groovy.zip");
        downloadToFile(url, groovyZip);
        File tmpDir = new File(groovyZip.getParentFile(), "groovy.tmp." + System.currentTimeMillis());
        try {
            new UnzipUtility().unzip(groovyZip.getAbsolutePath(), tmpDir.getAbsolutePath());
            groovyDir.mkdir();
            File libDirTmp = findDir(tmpDir, "lib");
            File legalDirTmp = findDir(tmpDir, "licenses");
            if (libDirTmp == null || !libDirTmp.exists()) {
                throw new IOException("No lib dir found within Groovy zip");
            }
            if (legalDirTmp == null || !legalDirTmp.exists()) {
                throw new IOException("No legal dir found within Groovy zip");
            }
            libDirTmp.renameTo(new File(groovyDir, "lib"));
            legalDirTmp.renameTo(new File(groovyDir, "licenses"));
        } finally {
            delTree(tmpDir);
            groovyZip.delete();
        }
    } catch (MalformedURLException ex) {
        Logger.getLogger(CN1Console.class.getName()).log(Level.SEVERE, null, ex);
        throw new RuntimeException(ex);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) UnzipUtility(com.codename1.impl.javase.UnzipUtility) IOException(java.io.IOException) File(java.io.File)

Example 2 with UnzipUtility

use of com.codename1.impl.javase.UnzipUtility in project CodenameOne by codenameone.

the class JavaFXLoader method downloadJavaFX.

private void downloadJavaFX() throws IOException {
    try {
        String url = getJavaFXURL();
        if (url == null) {
            throw new RuntimeException("No JavaFX URL found for this platform");
        }
        if (javafxDir.exists()) {
            delTree(javafxDir);
        }
        javafxDir.getParentFile().mkdirs();
        File javafxZip = new File(javafxDir.getParentFile(), "javafx.zip");
        downloadToFile(url, javafxZip);
        System.out.println("Downladed " + javafxZip + " " + javafxZip.length() + " bytes");
        File tmpDir = new File(javafxZip.getParentFile(), "javafx.tmp." + System.currentTimeMillis());
        try {
            new UnzipUtility().unzip(javafxZip.getAbsolutePath(), tmpDir.getAbsolutePath());
            javafxDir.mkdir();
            File libDirTmp = findDir(tmpDir, "lib");
            File legalDirTmp = findDir(tmpDir, "legal");
            File binDirTmp = findDir(tmpDir, "bin");
            if (libDirTmp == null || !libDirTmp.exists()) {
                throw new IOException("No lib dir found within JavaFX zip");
            }
            // System.out.println("Files:");
            // for (File f : libDirTmp.listFiles()) {
            // System.out.println(f);
            // if (f.isDirectory()) {
            // for (File child : f.listFiles()) {
            // System.out.println("  "+child);
            // }
            // }
            // }
            // if (legalDirTmp == null || !legalDirTmp.exists()) {
            // throw new IOException("No legal dir found within JavaFX zip");
            // }
            libDirTmp.renameTo(new File(javafxDir, "lib"));
            if (legalDirTmp != null && legalDirTmp.exists()) {
                legalDirTmp.renameTo(new File(javafxDir, "legal"));
            }
            if (binDirTmp != null && binDirTmp.exists()) {
                binDirTmp.renameTo(new File(javafxDir, "bin"));
            }
        } finally {
            delTree(tmpDir);
            javafxZip.delete();
        }
    } catch (MalformedURLException ex) {
        Logger.getLogger(JavaFXLoader.class.getName()).log(Level.SEVERE, null, ex);
        throw new RuntimeException(ex);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) UnzipUtility(com.codename1.impl.javase.UnzipUtility) IOException(java.io.IOException) File(java.io.File)

Aggregations

UnzipUtility (com.codename1.impl.javase.UnzipUtility)2 File (java.io.File)2 IOException (java.io.IOException)2 MalformedURLException (java.net.MalformedURLException)2