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 java.util.Collection;
  29 import java.util.Iterator;
  30 import java.util.ServiceLoader;
  31 
  32 /**
  33  * @deprecated use {@link ToolProvider} to locate the {@code "javapackager"} tool instead.
  34  */
  35 @Deprecated(since="10", forRemoval=true)
  36 public interface Bundlers {
  37 
  38     /**
  39      * This convenience method will call {@link #createBundlersInstance(ClassLoader)}
  40      * with the classloader that this Bundlers is loaded from.
  41      *
  42      * @return an instance of Bundlers loaded and configured from the current ClassLoader.
  43      */
  44     public static Bundlers createBundlersInstance() {
  45         return createBundlersInstance(Bundlers.class.getClassLoader());
  46     }
  47 
  48     /**
  49      * This convenience method will automatically load a Bundlers instance
  50      * from either META-INF/services or the default
  51      * {@link BasicBundlers} if none are found in
  52      * the services meta-inf.
  53      *
  54      * After instantiating the bundlers instance it will load the default
  55      * bundlers via {@link #loadDefaultBundlers()} as well as requesting
  56      * the services loader to load any other bundelrs via
  57      * {@link #loadBundlersFromServices(ClassLoader)}.
  58 
  59      *
  60      * @param servicesClassLoader the classloader to search for
  61      *                            META-INF/service registered bundlers
  62      * @return an instance of Bundlers loaded and configured from the specified ClassLoader
  63      */
  64     public static Bundlers createBundlersInstance(ClassLoader servicesClassLoader) {
  65         ServiceLoader<Bundlers> bundlersLoader = ServiceLoader.load(Bundlers.class, servicesClassLoader);
  66         Bundlers bundlers = null;
  67         Iterator<Bundlers> iter = bundlersLoader.iterator();
  68         if (iter.hasNext()) {
  69             bundlers = iter.next();
  70         }
  71         if (bundlers == null) {
  72             bundlers = new BasicBundlers();
  73         }
  74 
  75         bundlers.loadBundlersFromServices(servicesClassLoader);
  76         return bundlers;
  77     }
  78 
  79     /**
  80      * Returns all of the preconfigured, requested, and manually
  81      * configured bundlers loaded with this instance.
  82      *
  83      * @return  a read-only collection of the requested bundlers
  84      */
  85     Collection<Bundler> getBundlers();
  86 
  87     /**
  88      * Returns all of the preconfigured, requested, and manually
  89      * configured bundlers loaded with this instance that are of
  90      * a specific BundleType, such as disk images, installers, or
  91      * remote installers.
  92      *
  93      * @return a read-only collection of the requested bundlers
  94      */
  95     Collection<Bundler> getBundlers(String type);
  96 
  97     /**
  98      * A list of the "standard" parameters that bundlers should support
  99      * or fall back to when their specific parameters are not used.
 100      *
 101      * @return an unmodifiable collection of the standard parameters.
 102      */
 103     Collection<BundlerParamInfo> getStandardParameters();
 104 
 105     /**
 106      * Loads the bundlers common to the JDK.  A typical implementation
 107      * would load:
 108      * <UL>
 109      *     <LI>Windows file image</LI>
 110      *     <LI>Mac .app</LI>
 111      *     <LI>Linux file image</LI>
 112 
 113      *     <LI>Windows MSI</LI>
 114      *     <LI>Windows EXE</LI>
 115      *     <LI>Mac DMG</LI>
 116      *     <LI>Mac PKG</LI>
 117      *     <LI>Linux DEB</LI>
 118      *     <LI>Linux RPM</LI>
 119      *
 120      * </UL>
 121      *
 122      * This method is called from the {@link #createBundlersInstance(ClassLoader)}
 123      * and {@link #createBundlersInstance()} methods.
 124      * NOTE: Because of the module system this method is now not used.
 125      */
 126     void loadDefaultBundlers();
 127 
 128     /**
 129      * Loads bundlers from the META-INF/services directly.
 130      *
 131      * This method is called from the {@link #createBundlersInstance(ClassLoader)}
 132      * and {@link #createBundlersInstance()} methods.
 133      */
 134     void loadBundlersFromServices(ClassLoader cl);
 135 
 136     /**
 137      * Loads a specific bundler into the set of bundlers.
 138      * Useful for a manually configured bundler.
 139      *
 140      * @param bundler the specific bundler to add
 141      */
 142     void loadBundler(Bundler bundler);
 143 }