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  * @deprecated use {@link ToolProvider} to locate the {@code "javapackager"} tool instead.
  63  */
  64 @Deprecated(since="10", forRemoval=true)
  65 public class BasicBundlers implements Bundlers {
  66 
  67     boolean defaultsLoaded = false;
  68 
  69     private Collection<Bundler> bundlers = new CopyOnWriteArrayList<>();
  70 
  71     public Collection<Bundler> getBundlers() {
  72         return Collections.unmodifiableCollection(bundlers);
  73     }
  74 
  75     public Collection<Bundler> getBundlers(String type) {
  76         if (type == null) return Collections.emptySet();
  77         switch (type) {
  78             case "NONE":
  79                 return Collections.emptySet();
  80             case "ALL":
  81                 return getBundlers();
  82             default:
  83                 return Arrays.asList(getBundlers().stream()
  84                         .filter(b -> type.equalsIgnoreCase(b.getBundleType()))
  85                         .toArray(Bundler[]::new));
  86         }
  87     }
  88 
  89     /**
  90      * A list of the "standard" parameters that bundlers should support
  91      * or fall back to when their specific parameters are not used.
  92      * @return an unmodifieable collection of the standard parameters.
  93      */
  94     @Deprecated
  95     public Collection<BundlerParamInfo> getStandardParameters() {
  96         //TODO remove this method
  97         return null;
  98     }
  99 
 100     public void loadDefaultBundlers() {
 101         // no-op.  We now load all bundlers from module system.
 102     }
 103 
 104     /**
 105      * Loads bundlers from the META-INF/services direct
 106      */
 107     public void loadBundlersFromServices(ClassLoader cl) {
 108         ServiceLoader<Bundler> loader = ServiceLoader.load(Bundler.class, cl);
 109         for (Bundler aLoader : loader) {
 110             bundlers.add(aLoader);
 111         }
 112     }
 113 
 114     public void loadBundler(Bundler bundler) {
 115         bundlers.add(bundler);
 116     }
 117 }