< prev index next >

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

Print this page
rev 9619 : imported patch 9-jake-fxpackager.patch


  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.javafx.tools.packager;
  27 
  28 import com.oracle.tools.packager.Bundlers;
  29 import com.oracle.tools.packager.ConfigException;
  30 import com.oracle.tools.packager.Log;
  31 import com.oracle.tools.packager.RelativeFileSet;
  32 import com.oracle.tools.packager.UnsupportedPlatformException;
  33 import com.sun.javafx.tools.packager.JarSignature.InputStreamSource;
  34 import com.sun.javafx.tools.packager.bundlers.BundleParams;
  35 import com.sun.javafx.tools.packager.bundlers.Bundler.BundleType;
  36 import com.sun.javafx.tools.resource.PackagerResource;
  37 
  38 import java.io.BufferedReader;
  39 import java.io.File;
  40 import java.io.FileInputStream;
  41 import java.io.FileNotFoundException;
  42 import java.io.FileOutputStream;
  43 import java.io.FileWriter;
  44 import java.io.IOException;
  45 import java.io.InputStream;
  46 import java.io.InputStreamReader;
  47 import java.io.OutputStream;
  48 import java.io.Writer;
  49 import java.lang.reflect.Method;
  50 import java.net.MalformedURLException;
  51 import java.net.URL;


 298                     new JarOutputStream(new FileOutputStream(applicationJar)),
 299                     Filter.ALL);
 300         } catch (IOException ex) {
 301             throw new PackagerException(
 302                     ex, "ERR_CreatingJarFailed", createJarParams.outfile);
 303         }
 304 
 305         // cleanup
 306         deleteDirectory(bssTmpDir);
 307         this.createJarParams = null;
 308     }
 309 
 310     public void generateDeploymentPackages(DeployParams deployParams) throws PackagerException {
 311         if (deployParams == null) {
 312             throw new IllegalArgumentException("Parameters must not be null.");
 313         }
 314 
 315         try {
 316             BundleParams bp = deployParams.getBundleParams();
 317             if (bp != null) {
 318                 generateNativeBundles(deployParams.outdir, bp.getBundleParamsAsMap(), "JNLP", "jnlp");
 319                 generateNativeBundles(new File(deployParams.outdir, "bundles"), bp.getBundleParamsAsMap(), deployParams.getBundleType().toString(), deployParams.getTargetFormat());


















 320             }
 321         } catch (PackagerException ex) {
 322             throw ex;
 323         } catch (Exception ex) {
 324             throw new PackagerException(ex, "ERR_DeployFailed", ex.getMessage());
 325         }
 326 
 327     }
 328 
 329     private void generateNativeBundles(File outdir, Map<String, ? super Object> params, String bundleType, String bundleFormat) throws PackagerException {
 330         if (params.containsKey(BundleParams.PARAM_RUNTIME)) {
 331             RelativeFileSet runtime = BundleParams.getRuntime(params);
 332             if (runtime == null) {
 333                 com.oracle.tools.packager.Log.info(bundle.getString("MSG_NoJREPackaged"));
 334             } else {
 335                 com.oracle.tools.packager.Log.info(MessageFormat.format(bundle.getString("MSG_UserProvidedJRE"), runtime.getBaseDirectory().getAbsolutePath()));
 336                 if (com.oracle.tools.packager.Log.isDebug()) {
 337                     runtime.dump();
 338                 }
 339             }
 340         } else {
 341             com.oracle.tools.packager.Log.info(bundle.getString("MSG_UseSystemJRE"));
 342         }
 343 
 344         for (com.oracle.tools.packager.Bundler bundler : Bundlers.createBundlersInstance().getBundlers(bundleType)) {
 345 
 346             // if they specify the bundle format, require we match the ID
 347             if (bundleFormat != null && !bundleFormat.equalsIgnoreCase(bundler.getID())) continue;
 348 
 349             Map<String, ? super Object> localParams = new HashMap<>(params);
 350             try {
 351                 if (bundler.validate(localParams)) {
 352                     File result = bundler.execute(localParams, outdir);
 353                     if (result == null) {
 354                         throw new PackagerException("MSG_BundlerFailed", bundler.getID(), bundler.getName());
 355                     }
 356                 }
 357 
 358             } catch (UnsupportedPlatformException e) {
 359                 com.oracle.tools.packager.Log.debug(MessageFormat.format(bundle.getString("MSG_BundlerPlatformException"), bundler.getName()));
 360             } catch (ConfigException e) {
 361                 com.oracle.tools.packager.Log.debug(e);
 362                 if (e.getAdvice() != null) {


 506             throw new PackagerException("ERR_MissingJavaFxHome");
 507         }
 508 
 509         final String srcDirName = "src";
 510         final String compiledDirName = "compiled";
 511         final String distDirName = "dist";
 512         final String outfileName = "dist";
 513         final String jarName = outfileName + ".jar";
 514 
 515         final File distDir = new File(distDirName);
 516 
 517         final File compiledDir = new File(compiledDirName);
 518         compiledDir.mkdir();
 519 
 520         try {
 521             final File tmpFile = File.createTempFile("javac", "sources", new File("."));
 522             tmpFile.deleteOnExit();
 523             try (FileWriter sources = new FileWriter(tmpFile)) {
 524                 scanAndCopy(new PackagerResource(new File(srcDirName), "."), sources, compiledDir);
 525             }
 526             String classpath = jfxHome + "/../rt/lib/ext/jfxrt.jar";
 527             if (makeAllParams.classpath != null) {
 528                 classpath += File.pathSeparator + makeAllParams.classpath;
 529             }
 530             if (makeAllParams.verbose) {
 531                 System.out.println("Executing javac:");
 532                 System.out.printf("%s %s %s %s %s %s%n",
 533                         javac.getAbsolutePath(),
 534                         "-d", compiledDirName,
 535                         "-cp", classpath,
 536                         "@" + tmpFile.getAbsolutePath());
 537             }
 538             int ret = execute(
 539                     javac.getAbsolutePath(),
 540                     "-d", compiledDirName,
 541                     "-cp", classpath,
 542                     "@" + tmpFile.getAbsolutePath());
 543             if (ret != 0) {
 544                 throw new PackagerException("ERR_JavacFailed", Integer.toString(ret));
 545             }
 546         } catch (PackagerException e) {


 814             createBinaryCss(cssFileName, bssFileName);
 815         }
 816     }
 817 
 818     // Returns path to jfxrt.jar relatively to jar containing PackagerLib.class
 819     private String getJfxrtPath() throws PackagerException {
 820         String theClassFile = "PackagerLib.class";
 821         Class theClass = PackagerLib.class;
 822         String classUrl = theClass.getResource(theClassFile).toString();
 823 
 824         if (!classUrl.startsWith("jar:file:") || !classUrl.contains("!")){
 825             throw new PackagerException("ERR_CantFindRuntime");
 826         }
 827 
 828         // Strip everything after and including the "!"
 829         classUrl = classUrl.substring(0, classUrl.lastIndexOf("!"));
 830         // Strip everything after the last "/" or "\" to get rid of the jar filename
 831         int lastIndexOfSlash = Math.max(classUrl.lastIndexOf("/"), classUrl.lastIndexOf("\\"));
 832 
 833         return classUrl.substring(0, lastIndexOfSlash)
 834                     + "/../rt/lib/ext/jfxrt.jar!/";
 835     }
 836 
 837     private Class loadClassFromRuntime(String className) throws PackagerException {
 838         try {
 839             ClassLoader cl = getClassLoader();
 840             return cl.loadClass(className);
 841         } catch (ClassNotFoundException ex) {
 842             throw new PackagerException(ex, "ERR_CantFindRuntime");
 843         }
 844     }
 845 
 846     private void createBinaryCss(String cssFile, String binCssFile) throws PackagerException {
 847         String ofname = (binCssFile != null)
 848                             ? binCssFile
 849                             : replaceExtensionByBSS(cssFile);
 850 
 851         // create parent directories
 852         File of = new File(ofname);
 853         File parentFile = of.getParentFile();
 854         if (parentFile != null) {




  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.javafx.tools.packager;
  27 
  28 import com.oracle.tools.packager.Bundlers;
  29 import com.oracle.tools.packager.ConfigException;
  30 import com.oracle.tools.packager.Log;

  31 import com.oracle.tools.packager.UnsupportedPlatformException;
  32 import com.sun.javafx.tools.packager.JarSignature.InputStreamSource;
  33 import com.sun.javafx.tools.packager.bundlers.BundleParams;
  34 import com.sun.javafx.tools.packager.bundlers.Bundler.BundleType;
  35 import com.sun.javafx.tools.resource.PackagerResource;
  36 
  37 import java.io.BufferedReader;
  38 import java.io.File;
  39 import java.io.FileInputStream;
  40 import java.io.FileNotFoundException;
  41 import java.io.FileOutputStream;
  42 import java.io.FileWriter;
  43 import java.io.IOException;
  44 import java.io.InputStream;
  45 import java.io.InputStreamReader;
  46 import java.io.OutputStream;
  47 import java.io.Writer;
  48 import java.lang.reflect.Method;
  49 import java.net.MalformedURLException;
  50 import java.net.URL;


 297                     new JarOutputStream(new FileOutputStream(applicationJar)),
 298                     Filter.ALL);
 299         } catch (IOException ex) {
 300             throw new PackagerException(
 301                     ex, "ERR_CreatingJarFailed", createJarParams.outfile);
 302         }
 303 
 304         // cleanup
 305         deleteDirectory(bssTmpDir);
 306         this.createJarParams = null;
 307     }
 308 
 309     public void generateDeploymentPackages(DeployParams deployParams) throws PackagerException {
 310         if (deployParams == null) {
 311             throw new IllegalArgumentException("Parameters must not be null.");
 312         }
 313 
 314         try {
 315             BundleParams bp = deployParams.getBundleParams();
 316             if (bp != null) {
 317                 if (deployParams.getBundleType().equals(BundleType.ALL) && deployParams.getTargetFormat() == null) {
 318                     // generate everything.
 319 
 320                     // generate JNLP in the main directory
 321                     generateNativeBundles(deployParams.outdir, bp.getBundleParamsAsMap(), BundleType.JNLP.toString(), "jnlp");
 322                     // generate the rest in .../bundles
 323 
 324                     // generate disk images
 325                     generateNativeBundles(new File(deployParams.outdir, "bundles"), bp.getBundleParamsAsMap(), BundleType.IMAGE.toString(), deployParams.getTargetFormat());
 326 
 327                     //TODO generate installers referencing disk image
 328                     // for now just generate all images
 329                     generateNativeBundles(new File(deployParams.outdir, "bundles"), bp.getBundleParamsAsMap(), BundleType.INSTALLER.toString(), deployParams.getTargetFormat());
 330                 } else if (deployParams.getBundleType().equals(BundleType.NONE) && deployParams.getTargetFormat() == null) {
 331                     // old school default.  Just generate JNLP.
 332                     generateNativeBundles(deployParams.outdir, bp.getBundleParamsAsMap(), BundleType.JNLP.toString(), "jnlp");
 333                 } else {
 334                     // a specefic output format, just generate that.
 335                     generateNativeBundles(deployParams.outdir, bp.getBundleParamsAsMap(), deployParams.getBundleType().toString(), deployParams.getTargetFormat());
 336                 }
 337             }
 338         } catch (PackagerException ex) {
 339             throw ex;
 340         } catch (Exception ex) {
 341             throw new PackagerException(ex, "ERR_DeployFailed", ex.getMessage());
 342         }
 343 
 344     }
 345 
 346     private void generateNativeBundles(File outdir, Map<String, ? super Object> params, String bundleType, String bundleFormat) throws PackagerException {
 347         //FIXME //TODO check for system JRE












 348 
 349         for (com.oracle.tools.packager.Bundler bundler : Bundlers.createBundlersInstance().getBundlers(bundleType)) {
 350 
 351             // if they specify the bundle format, require we match the ID
 352             if (bundleFormat != null && !bundleFormat.equalsIgnoreCase(bundler.getID())) continue;
 353 
 354             Map<String, ? super Object> localParams = new HashMap<>(params);
 355             try {
 356                 if (bundler.validate(localParams)) {
 357                     File result = bundler.execute(localParams, outdir);
 358                     if (result == null) {
 359                         throw new PackagerException("MSG_BundlerFailed", bundler.getID(), bundler.getName());
 360                     }
 361                 }
 362 
 363             } catch (UnsupportedPlatformException e) {
 364                 com.oracle.tools.packager.Log.debug(MessageFormat.format(bundle.getString("MSG_BundlerPlatformException"), bundler.getName()));
 365             } catch (ConfigException e) {
 366                 com.oracle.tools.packager.Log.debug(e);
 367                 if (e.getAdvice() != null) {


 511             throw new PackagerException("ERR_MissingJavaFxHome");
 512         }
 513 
 514         final String srcDirName = "src";
 515         final String compiledDirName = "compiled";
 516         final String distDirName = "dist";
 517         final String outfileName = "dist";
 518         final String jarName = outfileName + ".jar";
 519 
 520         final File distDir = new File(distDirName);
 521 
 522         final File compiledDir = new File(compiledDirName);
 523         compiledDir.mkdir();
 524 
 525         try {
 526             final File tmpFile = File.createTempFile("javac", "sources", new File("."));
 527             tmpFile.deleteOnExit();
 528             try (FileWriter sources = new FileWriter(tmpFile)) {
 529                 scanAndCopy(new PackagerResource(new File(srcDirName), "."), sources, compiledDir);
 530             }
 531             String classpath = jfxHome + "/../lib/jfxrt.jar";
 532             if (makeAllParams.classpath != null) {
 533                 classpath += File.pathSeparator + makeAllParams.classpath;
 534             }
 535             if (makeAllParams.verbose) {
 536                 System.out.println("Executing javac:");
 537                 System.out.printf("%s %s %s %s %s %s%n",
 538                         javac.getAbsolutePath(),
 539                         "-d", compiledDirName,
 540                         "-cp", classpath,
 541                         "@" + tmpFile.getAbsolutePath());
 542             }
 543             int ret = execute(
 544                     javac.getAbsolutePath(),
 545                     "-d", compiledDirName,
 546                     "-cp", classpath,
 547                     "@" + tmpFile.getAbsolutePath());
 548             if (ret != 0) {
 549                 throw new PackagerException("ERR_JavacFailed", Integer.toString(ret));
 550             }
 551         } catch (PackagerException e) {


 819             createBinaryCss(cssFileName, bssFileName);
 820         }
 821     }
 822 
 823     // Returns path to jfxrt.jar relatively to jar containing PackagerLib.class
 824     private String getJfxrtPath() throws PackagerException {
 825         String theClassFile = "PackagerLib.class";
 826         Class theClass = PackagerLib.class;
 827         String classUrl = theClass.getResource(theClassFile).toString();
 828 
 829         if (!classUrl.startsWith("jar:file:") || !classUrl.contains("!")){
 830             throw new PackagerException("ERR_CantFindRuntime");
 831         }
 832 
 833         // Strip everything after and including the "!"
 834         classUrl = classUrl.substring(0, classUrl.lastIndexOf("!"));
 835         // Strip everything after the last "/" or "\" to get rid of the jar filename
 836         int lastIndexOfSlash = Math.max(classUrl.lastIndexOf("/"), classUrl.lastIndexOf("\\"));
 837 
 838         return classUrl.substring(0, lastIndexOfSlash)
 839                 + "/../lib/jfxrt.jar!/";
 840     }
 841 
 842     private Class loadClassFromRuntime(String className) throws PackagerException {
 843         try {
 844             ClassLoader cl = getClassLoader();
 845             return cl.loadClass(className);
 846         } catch (ClassNotFoundException ex) {
 847             throw new PackagerException(ex, "ERR_CantFindRuntime");
 848         }
 849     }
 850 
 851     private void createBinaryCss(String cssFile, String binCssFile) throws PackagerException {
 852         String ofname = (binCssFile != null)
 853                 ? binCssFile
 854                 : replaceExtensionByBSS(cssFile);
 855 
 856         // create parent directories
 857         File of = new File(ofname);
 858         File parentFile = of.getParentFile();
 859         if (parentFile != null) {


< prev index next >