src/jdk.packager/share/classes/jdk/packager/internal/BasicBundlers.java
branchJDK-8200758-branch
changeset 57017 1b08af362a30
parent 57016 f63f13da91c0
child 57018 9d782e357916
equal deleted inserted replaced
57016:f63f13da91c0 57017:1b08af362a30
     1 /*
       
     2  * Copyright (c) 2014, 2018, 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.packager.internal;
       
    27 
       
    28 import java.util.Arrays;
       
    29 import java.util.Collection;
       
    30 import java.util.Collections;
       
    31 import java.util.ServiceLoader;
       
    32 import java.util.concurrent.CopyOnWriteArrayList;
       
    33 
       
    34 /**
       
    35  * BasicBundlers
       
    36  *
       
    37  * A basic bundlers collection that loads the default bundlers.
       
    38  * Loads the common bundlers.
       
    39  * <UL>
       
    40  *     <LI>Windows file image</LI>
       
    41  *     <LI>Mac .app</LI>
       
    42  *     <LI>Linux file image</LI>
       
    43  *     <LI>Windows MSI</LI>
       
    44  *     <LI>Windows EXE</LI>
       
    45  *     <LI>Mac DMG</LI>
       
    46  *     <LI>Mac PKG</LI>
       
    47  *     <LI>Linux DEB</LI>
       
    48  *     <LI>Linux RPM</LI>
       
    49  *
       
    50  * </UL>
       
    51  */
       
    52 public class BasicBundlers implements Bundlers {
       
    53 
       
    54     boolean defaultsLoaded = false;
       
    55 
       
    56     private final Collection<Bundler> bundlers = new CopyOnWriteArrayList<>();
       
    57 
       
    58     @Override
       
    59     public Collection<Bundler> getBundlers() {
       
    60         return Collections.unmodifiableCollection(bundlers);
       
    61     }
       
    62 
       
    63     @Override
       
    64     public Collection<Bundler> getBundlers(String type) {
       
    65         if (type == null) return Collections.emptySet();
       
    66         switch (type) {
       
    67             case "NONE":
       
    68                 return Collections.emptySet();
       
    69             case "ALL":
       
    70                 return getBundlers();
       
    71             default:
       
    72                 return Arrays.asList(getBundlers().stream()
       
    73                         .filter(b -> type.equalsIgnoreCase(b.getBundleType()))
       
    74                         .toArray(Bundler[]::new));
       
    75         }
       
    76     }
       
    77 
       
    78     @Override
       
    79     public void loadDefaultBundlers() {
       
    80         // no-op.  We now load all bundlers from module system.
       
    81     }
       
    82 
       
    83     // Loads bundlers from the META-INF/services direct
       
    84     @Override
       
    85     public void loadBundlersFromServices(ClassLoader cl) {
       
    86         ServiceLoader<Bundler> loader = ServiceLoader.load(Bundler.class, cl);
       
    87         for (Bundler aLoader : loader) {
       
    88             bundlers.add(aLoader);
       
    89         }
       
    90     }
       
    91     
       
    92     @Override
       
    93     public void loadBundler(Bundler bundler) {
       
    94         bundlers.add(bundler);
       
    95     }
       
    96 }