src/jdk.incubator.jpackage/share/classes/jdk/incubator/jpackage/internal/Bundlers.java
branchJDK-8200758-branch
changeset 58994 b09ba68c6a19
parent 57438 4a31db8d42bd
equal deleted inserted replaced
58993:b5e1baa9d2c3 58994:b09ba68c6a19
       
     1 /*
       
     2  * Copyright (c) 2014, 2019, 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 jdk.incubator.jpackage.internal;
       
    27 
       
    28 import java.util.Collection;
       
    29 import java.util.Iterator;
       
    30 import java.util.ServiceLoader;
       
    31 
       
    32 /**
       
    33  * Bundlers
       
    34  *
       
    35  * The interface implemented by BasicBundlers
       
    36  */
       
    37 public interface Bundlers {
       
    38 
       
    39     /**
       
    40      * This convenience method will call
       
    41      * {@link #createBundlersInstance(ClassLoader)}
       
    42      * with the classloader that this Bundlers is loaded from.
       
    43      *
       
    44      * @return an instance of Bundlers loaded and configured from
       
    45      *         the current ClassLoader.
       
    46      */
       
    47     public static Bundlers createBundlersInstance() {
       
    48         return createBundlersInstance(Bundlers.class.getClassLoader());
       
    49     }
       
    50 
       
    51     /**
       
    52      * This convenience method will automatically load a Bundlers instance
       
    53      * from either META-INF/services or the default
       
    54      * {@link BasicBundlers} if none are found in
       
    55      * the services meta-inf.
       
    56      *
       
    57      * After instantiating the bundlers instance it will load the default
       
    58      * bundlers via {@link #loadDefaultBundlers()} as well as requesting
       
    59      * the services loader to load any other bundelrs via
       
    60      * {@link #loadBundlersFromServices(ClassLoader)}.
       
    61 
       
    62      *
       
    63      * @param servicesClassLoader the classloader to search for
       
    64      *                            META-INF/service registered bundlers
       
    65      * @return an instance of Bundlers loaded and configured from
       
    66      *         the specified ClassLoader
       
    67      */
       
    68     public static Bundlers createBundlersInstance(
       
    69             ClassLoader servicesClassLoader) {
       
    70         ServiceLoader<Bundlers> bundlersLoader =
       
    71                 ServiceLoader.load(Bundlers.class, servicesClassLoader);
       
    72         Bundlers bundlers = null;
       
    73         Iterator<Bundlers> iter = bundlersLoader.iterator();
       
    74         if (iter.hasNext()) {
       
    75             bundlers = iter.next();
       
    76         }
       
    77         if (bundlers == null) {
       
    78             bundlers = new BasicBundlers();
       
    79         }
       
    80 
       
    81         bundlers.loadBundlersFromServices(servicesClassLoader);
       
    82         return bundlers;
       
    83     }
       
    84 
       
    85     /**
       
    86      * Returns all of the preconfigured, requested, and manually
       
    87      * configured bundlers loaded with this instance.
       
    88      *
       
    89      * @return  a read-only collection of the requested bundlers
       
    90      */
       
    91     Collection<Bundler> getBundlers();
       
    92 
       
    93     /**
       
    94      * Returns all of the preconfigured, requested, and manually
       
    95      * configured bundlers loaded with this instance that are of
       
    96      * a specific BundleType, such as disk images, installers, or
       
    97      * remote installers.
       
    98      *
       
    99      * @return a read-only collection of the requested bundlers
       
   100      */
       
   101     Collection<Bundler> getBundlers(String type);
       
   102 
       
   103     /**
       
   104      * Loads bundlers from the META-INF/services directly.
       
   105      *
       
   106      * This method is called from the
       
   107      * {@link #createBundlersInstance(ClassLoader)}
       
   108      * and {@link #createBundlersInstance()} methods.
       
   109      */
       
   110     void loadBundlersFromServices(ClassLoader cl);
       
   111 
       
   112 }