1 /*
   2  * Copyright (c) 2014, 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 
  26 package com.oracle.tools.packager;
  27 
  28 import com.oracle.tools.packager.jnlp.JNLPBundler;
  29 import com.oracle.tools.packager.linux.LinuxRpmBundler;
  30 import com.oracle.tools.packager.mac.MacAppStoreBundler;
  31 import com.oracle.tools.packager.mac.MacDmgBundler;
  32 import com.oracle.tools.packager.mac.MacPkgBundler;
  33 import com.oracle.tools.packager.linux.LinuxAppBundler;
  34 import com.oracle.tools.packager.linux.LinuxDebBundler;
  35 import com.oracle.tools.packager.mac.MacAppBundler;
  36 import com.oracle.tools.packager.windows.WinAppBundler;
  37 import com.oracle.tools.packager.windows.WinExeBundler;
  38 import com.oracle.tools.packager.windows.WinMsiBundler;
  39 
  40 import java.util.Arrays;
  41 import java.util.Collection;
  42 import java.util.Collections;
  43 import java.util.ServiceLoader;
  44 import java.util.concurrent.CopyOnWriteArrayList;
  45 
  46 /**
  47  * A basic bundlers collection that loads the OpenJFX default bundlers.
  48  * Loads the bundlers common to OpenJFX.
  49  * <UL>
  50  *     <LI>Windows file image</LI>
  51  *     <LI>Mac .app</LI>
  52  *     <LI>Linux file image</LI>
  53  *     <LI>Windows MSI</LI>
  54  *     <LI>Windows EXE</LI>
  55  *     <LI>Mac DMG</LI>
  56  *     <LI>Mac PKG</LI>
  57  *     <LI>Linux DEB</LI>
  58  *     <LI>Linux RPM</LI>
  59  *
  60  * </UL>
  61  */
  62 public class BasicBundlers implements Bundlers {
  63 
  64     boolean defaultsLoaded = false;
  65 
  66     private Collection<Bundler> bundlers = new CopyOnWriteArrayList<>();
  67 
  68     public Collection<Bundler> getBundlers() {
  69         return Collections.unmodifiableCollection(bundlers);
  70     }
  71 
  72     public Collection<Bundler> getBundlers(String type) {
  73         if (type == null) return Collections.emptySet();
  74         switch (type) {
  75             case "NONE":
  76                 return Collections.emptySet();
  77             case "ALL":
  78                 return getBundlers();
  79             default:
  80                 return Arrays.asList(getBundlers().stream()
  81                         .filter(b -> type.equalsIgnoreCase(b.getBundleType()))
  82                         .toArray(Bundler[]::new));
  83         }
  84     }
  85 
  86     /**
  87      * A list of the "standard" parameters that bundlers should support
  88      * or fall back to when their specific parameters are not used.
  89      * @return an unmodifieable collection of the standard parameters.
  90      */
  91     @Deprecated
  92     public Collection<BundlerParamInfo> getStandardParameters() {
  93         //TODO remove this method
  94         return null;
  95     }
  96 
  97     public void loadDefaultBundlers() {
  98         // no-op.  We now load all bundlers from module system.
  99     }
 100 
 101     /**
 102      * Loads bundlers from the META-INF/services direct
 103      */
 104     public void loadBundlersFromServices(ClassLoader cl) {
 105         ServiceLoader<Bundler> loader = ServiceLoader.load(Bundler.class, cl);
 106         for (Bundler aLoader : loader) {
 107             bundlers.add(aLoader);
 108         }
 109     }
 110 
 111     public void loadBundler(Bundler bundler) {
 112         bundlers.add(bundler);
 113     }
 114 }