modules/jdk.packager/src/main/java/com/sun/javafx/tools/packager/PackagerLib.java

Print this page

        

*** 32,41 **** --- 32,42 ---- import com.oracle.tools.packager.UnsupportedPlatformException; import com.sun.javafx.tools.packager.JarSignature.InputStreamSource; import com.sun.javafx.tools.packager.bundlers.BundleParams; import com.sun.javafx.tools.packager.bundlers.Bundler.BundleType; import com.sun.javafx.tools.resource.PackagerResource; + import com.sun.javafx.css.parser.Css2Bin; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException;
*** 44,57 **** import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.Writer; - import java.lang.reflect.Method; - import java.net.MalformedURLException; - import java.net.URL; - import java.net.URLClassLoader; import java.nio.file.Files; import java.nio.file.StandardCopyOption; import java.security.InvalidKeyException; import java.security.KeyStore; import java.security.KeyStoreException; --- 45,54 ----
*** 96,119 **** private File bssTmpDir; private enum Filter {ALL, CLASSES_ONLY, RESOURCES} - private ClassLoader classLoader; - - private ClassLoader getClassLoader() throws PackagerException { - if (classLoader == null) { - try { - URL[] urls = {new URL(getJfxrtPath())}; - classLoader = URLClassLoader.newInstance(urls); - } catch (MalformedURLException ex) { - throw new PackagerException(ex, "ERR_CantFindRuntime"); - } - } - return classLoader; - } - // if set of input resources consist of SINGLE element and // this element is jar file then we expect this to be request to // "update" jar file // Input jar file MUST be executable jar file // --- 93,102 ----
*** 515,532 **** throw new PackagerException("ERR_MissingJavaHome"); } final File javac = new File(new File(jHome), "bin/javac" + exe); - String jfxHome = System.getenv("JAVAFX_HOME"); - if (jfxHome == null) { - jfxHome = System.getProperty("javafx.home"); - } - if (jfxHome == null) { - throw new PackagerException("ERR_MissingJavaFxHome"); - } - final String srcDirName = "src"; final String compiledDirName = "compiled"; final String distDirName = "dist"; final String outfileName = "dist"; final String jarName = outfileName + ".jar"; --- 498,507 ----
*** 540,566 **** final File tmpFile = File.createTempFile("javac", "sources", new File(".")); tmpFile.deleteOnExit(); try (FileWriter sources = new FileWriter(tmpFile)) { scanAndCopy(new PackagerResource(new File(srcDirName), "."), sources, compiledDir); } ! String classpath = jfxHome + "/../lib/jfxrt.jar"; ! if (makeAllParams.classpath != null) { ! classpath += File.pathSeparator + makeAllParams.classpath; ! } if (makeAllParams.verbose) { Log.info("Executing javac:"); Log.infof("%s %s %s %s %s %s%n", javac.getAbsolutePath(), "-d", compiledDirName, ! "-cp", classpath, "@" + tmpFile.getAbsolutePath()); } ! int ret = execute( javac.getAbsolutePath(), "-d", compiledDirName, - "-cp", classpath, "@" + tmpFile.getAbsolutePath()); if (ret != 0) { throw new PackagerException("ERR_JavacFailed", Integer.toString(ret)); } } catch (PackagerException e) { throw e; --- 515,549 ---- final File tmpFile = File.createTempFile("javac", "sources", new File(".")); tmpFile.deleteOnExit(); try (FileWriter sources = new FileWriter(tmpFile)) { scanAndCopy(new PackagerResource(new File(srcDirName), "."), sources, compiledDir); } ! if (makeAllParams.verbose) { Log.info("Executing javac:"); Log.infof("%s %s %s %s %s %s%n", javac.getAbsolutePath(), "-d", compiledDirName, ! "-cp", makeAllParams.classpath != null ? ! makeAllParams.classpath : "<null>", "@" + tmpFile.getAbsolutePath()); } ! ! int ret = -1; ! if (makeAllParams.classpath != null) { ! ret = execute( ! javac.getAbsolutePath(), ! "-d", compiledDirName, ! "-cp", makeAllParams.classpath, ! "@" + tmpFile.getAbsolutePath()); ! } else { ! ret = execute( javac.getAbsolutePath(), "-d", compiledDirName, "@" + tmpFile.getAbsolutePath()); + } + if (ret != 0) { throw new PackagerException("ERR_JavacFailed", Integer.toString(ret)); } } catch (PackagerException e) { throw e;
*** 831,868 **** .getAbsolutePath(); createBinaryCss(cssFileName, bssFileName); } } - // Returns path to jfxrt.jar relatively to jar containing PackagerLib.class - private String getJfxrtPath() throws PackagerException { - String theClassFile = "PackagerLib.class"; - Class theClass = PackagerLib.class; - String classUrl = theClass.getResource(theClassFile).toString(); - - if (!classUrl.startsWith("jar:file:") || !classUrl.contains("!")){ - throw new PackagerException("ERR_CantFindRuntime"); - } - - // Strip everything after and including the "!" - classUrl = classUrl.substring(0, classUrl.lastIndexOf("!")); - // Strip everything after the last "/" or "\" to get rid of the jar filename - int lastIndexOfSlash = Math.max(classUrl.lastIndexOf("/"), classUrl.lastIndexOf("\\")); - - return classUrl.substring(0, lastIndexOfSlash) - + "/../lib/jfxrt.jar!/"; - } - - private Class loadClassFromRuntime(String className) throws PackagerException { - try { - ClassLoader cl = getClassLoader(); - return cl.loadClass(className); - } catch (ClassNotFoundException ex) { - throw new PackagerException(ex, "ERR_CantFindRuntime"); - } - } - private void createBinaryCss(String cssFile, String binCssFile) throws PackagerException { String ofname = (binCssFile != null) ? binCssFile : replaceExtensionByBSS(cssFile); --- 814,823 ----
*** 871,895 **** File parentFile = of.getParentFile(); if (parentFile != null) { parentFile.mkdirs(); } - // Using reflection because CSS parser is part of runtime - // and we want to avoid dependency on jfxrt during build - Class<?> clazz; - try { - clazz = Class.forName("com.sun.javafx.css.parser.Css2Bin"); - } catch (ClassNotFoundException e) { - // class was not found with default class loader, trying to - // locate it by loading from jfxrt.jar - clazz = loadClassFromRuntime("com.sun.javafx.css.parser.Css2Bin"); - } - try { ! Method m = clazz.getMethod("convertToBinary", String.class, String.class); ! m.invoke(null, cssFile, ofname); ! } catch (Exception ex) { Throwable causeEx = ex.getCause(); String cause = (causeEx != null) ? causeEx.getMessage() : bundle.getString("ERR_UnknownReason"); throw new PackagerException(ex, "ERR_BSSConversionFailed", cssFile, cause); --- 826,838 ---- File parentFile = of.getParentFile(); if (parentFile != null) { parentFile.mkdirs(); } try { ! Css2Bin.convertToBinary(cssFile, ofname); ! } catch (IOException ex) { Throwable causeEx = ex.getCause(); String cause = (causeEx != null) ? causeEx.getMessage() : bundle.getString("ERR_UnknownReason"); throw new PackagerException(ex, "ERR_BSSConversionFailed", cssFile, cause);