1 /*
   2  * Copyright (c) 2014, 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 
  26 package com.oracle.bundlers;
  27 
  28 import com.oracle.bundlers.mac.MacAppStoreBundler;
  29 import com.oracle.bundlers.mac.MacPKGBundler;
  30 import com.sun.javafx.tools.packager.bundlers.LinuxAppBundler;
  31 import com.sun.javafx.tools.packager.bundlers.LinuxDebBundler;
  32 import com.sun.javafx.tools.packager.bundlers.LinuxRPMBundler;
  33 import com.sun.javafx.tools.packager.bundlers.MacAppBundler;
  34 import com.sun.javafx.tools.packager.bundlers.MacDMGBundler;
  35 import com.sun.javafx.tools.packager.bundlers.WinAppBundler;
  36 import com.sun.javafx.tools.packager.bundlers.WinExeBundler;
  37 import com.sun.javafx.tools.packager.bundlers.WinMsiBundler;
  38 
  39 import java.util.Arrays;
  40 import java.util.Collection;
  41 import java.util.Collections;
  42 import java.util.ServiceLoader;
  43 import java.util.concurrent.CopyOnWriteArrayList;
  44 
  45 /**
  46  * A basic bundlers collection that loads the OpenJFX default bundlers.
  47  * Loads the bundlers common to OpenJFX.
  48  * <UL>
  49  *     <LI>Windows file image</LI>
  50  *     <LI>Mac .app</LI>
  51  *     <LI>Linux file image</LI>
  52  *     <LI>Windows MSI</LI>
  53  *     <LI>Windows EXE</LI>
  54  *     <LI>Mac DMG</LI>
  55  *     <LI>Mac PKG</LI>
  56  *     <LI>Linux DEB</LI>
  57  *     <LI>Linux RPM</LI>
  58  *
  59  * </UL>
  60  */
  61 public class BasicBundlers implements Bundlers {
  62 
  63     boolean defaultsLoaded = false;
  64 
  65     private Collection<Bundler> bundlers = new CopyOnWriteArrayList<>();
  66 
  67     public Collection<Bundler> getBundlers() {
  68         return Collections.unmodifiableCollection(bundlers);
  69     }
  70 
  71     public Collection<Bundler> getBundlers(String type) {
  72         if (type == null) return Collections.emptySet();
  73         switch (type) {
  74             case "NONE":
  75                 return Collections.emptySet();
  76             case "ALL":
  77                 return getBundlers();
  78             default:
  79                 return Arrays.asList(getBundlers().stream()
  80                         .filter(b -> type.equals(b.getBundleType()))
  81                         .toArray(Bundler[]::new));
  82         }
  83     }
  84 
  85     /**
  86      * A list of the "standard" parameters that bundlers should support
  87      * or fall back to when their specific parameters are not used.
  88      * @return an unmodifieable collection of the standard parameters.
  89      */
  90     public Collection<BundlerParamInfo> getStandardParameters() {
  91         //TODO enumerate the stuff in BundleParams
  92         return null;
  93     }
  94 
  95     /**
  96      * Loads the bundlers common to OpenJFX.
  97      * <UL>
  98      *     <LI>Windows file image</LI>
  99      *     <LI>Mac .app</LI>
 100      *     <LI>Linux file image</LI>
 101      *     <LI>Windows MSI</LI>
 102      *     <LI>Windows EXE</LI>
 103      *     <LI>Mac DMG</LI>
 104      *     <LI>Mac PKG</LI>
 105      *     <LI>Linux DEB</LI>
 106      *     <LI>Linux RPM</LI>
 107      *
 108      * </UL>
 109      */
 110     public void loadDefaultBundlers() {
 111         if (defaultsLoaded) return;
 112 
 113         bundlers.add(new WinAppBundler());
 114         bundlers.add(new WinExeBundler());
 115         bundlers.add(new WinMsiBundler());
 116 
 117         bundlers.add(new LinuxAppBundler());
 118         bundlers.add(new LinuxDebBundler());
 119         bundlers.add(new LinuxRPMBundler());
 120 
 121         bundlers.add(new MacAppBundler());
 122         bundlers.add(new MacDMGBundler());
 123         bundlers.add(new MacPKGBundler());
 124         bundlers.add(new MacAppStoreBundler());
 125 
 126         //bundlers.add(new JNLPBundler());
 127 
 128         defaultsLoaded = true;
 129     }
 130 
 131     /**
 132      * Loads bundlers from the META-INF/services direct
 133      */
 134     public void loadBundlersFromServices(ClassLoader cl) {
 135         ServiceLoader<Bundler> loader = ServiceLoader.load(Bundler.class, cl);
 136         for (Bundler aLoader : loader) {
 137             bundlers.add(aLoader);
 138         }
 139     }
 140 
 141     public void loadBundler(Bundler bundler) {
 142         bundlers.add(bundler);
 143     }
 144 }