1 /*
   2  * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  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 import java.io.File;
  26 import java.io.IOException;
  27 import java.nio.file.DirectoryStream;
  28 import java.nio.file.Files;
  29 import java.nio.file.Path;
  30 import java.nio.file.Paths;
  31 import java.util.ArrayList;
  32 import java.util.Collection;
  33 import java.util.HashMap;
  34 import java.util.List;
  35 import java.util.Map;
  36 import java.util.stream.Collectors;
  37 
  38 import com.oracle.tools.packager.Bundler;
  39 import com.oracle.tools.packager.Bundlers;
  40 import com.oracle.tools.packager.RelativeFileSet;
  41 import com.sun.javafx.tools.packager.bundlers.BundleParams;
  42 
  43 public class Tester {
  44 
  45     public static void main(String[] args) throws IOException {
  46         Bundlers createBundlersInstance = Bundlers.createBundlersInstance();
  47         Collection<Bundler> bundlers = createBundlersInstance.getBundlers();
  48         Bundler macApplicationImageInstance = null;
  49         for (Bundler bundler : bundlers) {
  50             if("Mac Application Image".equals(bundler.getName())) {
  51                 macApplicationImageInstance = bundler;
  52                 break;
  53             }
  54         }
  55         Map<String, Object> hashMap = new HashMap<String, Object>();
  56         hashMap.put("name", "SimpleTest");
  57         hashMap.put(Constants.APPLICATION_CLASS, "HelloWorld");
  58         hashMap.put(Constants.CLASSPATH, "hello.world.jar");
  59         hashMap.put(Constants.MAIN_JAR, "hello.world.jar");
  60         hashMap.put("srcdir", "jars");
  61         Path path = Paths.get("jars");
  62         List<Path> list = new ArrayList<>();
  63         list.add(path);
  64         try (DirectoryStream<Path> jarsStream = Files.newDirectoryStream(path, "*.jar")) {
  65             List<Path> jars = new ArrayList<>();
  66             jarsStream.forEach(jars::add);
  67             hashMap.put(BundleParams.PARAM_APP_RESOURCES,
  68                     new RelativeFileSet(path.toFile(), jars.stream()
  69                             .map(Path::toFile).collect(Collectors.toSet())));
  70             System.out.println("parameters are " + hashMap);
  71             macApplicationImageInstance.execute(hashMap,new File("output"));
  72         }
  73     }
  74 }