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.bundlers; 27 28 import com.oracle.bundlers.mac.MacAppStoreBundler; 29 import com.oracle.bundlers.mac.MacPKGBundler; 30 import com.sun.javafx.tools.packager.bundlers.*; 31 32 import java.util.*; 33 import java.util.concurrent.CopyOnWriteArrayList; 34 35 public class Bundlers { 36 37 public static Bundlers createBundlersInstance() { 38 return createBundlersInstance(Bundlers.class.getClassLoader()); 39 } 40 41 public static Bundlers createBundlersInstance(ClassLoader servicesClassLoader) { 42 Bundlers bundlers = new Bundlers(); 43 bundlers.loadDefaultBundlers(); 44 bundlers.loadBundlersFromServices(servicesClassLoader); 45 return bundlers; 46 } 47 48 private Collection<Bundler> bundlers = new CopyOnWriteArrayList<>(); 49 50 public Collection<Bundler> getBundlers() { 51 return Collections.unmodifiableCollection(bundlers); 52 } 53 54 public Collection<Bundler> getBundlers(BundleType type) { 55 if (type == null) return Collections.emptySet(); 56 switch (type) { 57 case NONE: 58 return Collections.emptySet(); 59 case ALL: 60 return getBundlers(); 61 default: 62 Collection<Bundler> results = new LinkedHashSet<>(); 63 for (Bundler bundler : getBundlers()) { 64 if (type.equals(bundler.getBundleType())) { 65 results.add(bundler); 66 } 67 } 68 return results; 69 //return Arrays.asList( 70 // getBundlers().stream() 71 // .filter(b -> type.equals(b.getBundleType())) 72 // .toArray(Bundler[]::new)); 73 } 74 } 75 76 /** 77 * A list of the "standard" parameters that bundlers should support 78 * or fall back to when their specific parameters are not used. 79 * @return an unmodifieable collection of the standard parameters. 80 */ 81 public static Collection<BundlerParamInfo> getStandardParameters() { 82 //TODO enumerate the stuff in BundleParams 83 return null; 84 } 85 86 /** 87 * Loads the bundlers common to the JDK. 88 * <UL> 89 * <LI>Windows file tree</LI> 90 * <LI>Mac .app</LI> 91 * <LI>Linux file tree</LI> 92 93 * <LI>Windows MSI</LI> 94 * <LI>Windows EXE</LI> 95 * <LI>Mac DMG</LI> 96 * <LI>Linux DEB</LI> 97 * <LI>Linux RPM</LI> 98 * 99 * </UL> 100 */ 101 public void loadDefaultBundlers() { 102 bundlers.add(new WinAppBundler()); 103 bundlers.add(new WinExeBundler()); 104 bundlers.add(new WinMsiBundler()); 105 106 bundlers.add(new LinuxAppBundler()); 107 bundlers.add(new LinuxDebBundler()); 108 bundlers.add(new LinuxRPMBundler()); 109 110 bundlers.add(new MacAppBundler()); 111 bundlers.add(new MacDMGBundler()); 112 bundlers.add(new MacPKGBundler()); 113 bundlers.add(new MacAppStoreBundler()); 114 115 //bundlers.add(new JNLPBundler()); 116 } 117 118 /** 119 * Loads bundlers from the META-INF/services direct 120 */ 121 public void loadBundlersFromServices(ClassLoader cl) { 122 ServiceLoader<Bundler> loader = ServiceLoader.load(Bundler.class, cl); 123 for (Bundler aLoader : loader) { 124 bundlers.add(aLoader); 125 } 126 } 127 128 public void loadBundler(Bundler bundler) { 129 bundlers.add(bundler); 130 } 131 } | 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.bundlers; 27 28 import com.sun.javafx.tools.packager.bundlers.BundleType; 29 30 import java.util.Collection; 31 import java.util.Iterator; 32 import java.util.ServiceLoader; 33 34 35 public interface Bundlers { 36 37 /** 38 * This convenience method will call {@link #createBundlersInstance(ClassLoader)} 39 * with the classloader that this Bundlers is loaded from. 40 * 41 * @return an instance of Bundlers loaded and configured from the current ClassLoader. 42 */ 43 public static Bundlers createBundlersInstance() { 44 return createBundlersInstance(Bundlers.class.getClassLoader()); 45 } 46 47 /** 48 * This convenience method will automatically load a Bundlers instance 49 * from either META-INF/services or the default 50 * {@link com.oracle.bundlers.BasicBundlers} if none are found in 51 * the services meta-inf. 52 * 53 * After instantiating the bundlers instance it will load the default 54 * bundlers via {@link #loadDefaultBundlers()} as well as requesting 55 * the services loader to load any other bundelrs via 56 * {@link #loadBundlersFromServices(ClassLoader)}. 57 58 * 59 * @param servicesClassLoader the classloader to search for 60 * META-INF/service registered bundlers 61 * @return an instance of Bundlers loaded and configured from the specified ClassLoader 62 */ 63 public static Bundlers createBundlersInstance(ClassLoader servicesClassLoader) { 64 ServiceLoader<Bundlers> bundlersLoader = ServiceLoader.load(Bundlers.class, servicesClassLoader); 65 Bundlers bundlers = null; 66 Iterator<Bundlers> iter = bundlersLoader.iterator(); 67 if (iter.hasNext()) { 68 bundlers = iter.next(); 69 } 70 if (bundlers == null) { 71 bundlers = new BasicBundlers(); 72 } 73 74 bundlers.loadDefaultBundlers(); 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(BundleType 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>Linux DEB</LI> 117 * <LI>Linux RPM</LI> 118 * 119 * </UL> 120 * 121 * This method is called from the {@link #createBundlersInstance(ClassLoader)} 122 * and {@link #createBundlersInstance()} methods. 123 */ 124 void loadDefaultBundlers(); 125 126 /** 127 * Loads bundlers from the META-INF/services directly. 128 * 129 * This method is called from the {@link #createBundlersInstance(ClassLoader)} 130 * and {@link #createBundlersInstance()} methods. 131 */ 132 void loadBundlersFromServices(ClassLoader cl); 133 134 /** 135 * Loads a specific bundler into the set of bundlers. 136 * Useful for a manually configured bundler. 137 * 138 * @param bundler the specific bundler to add 139 */ 140 void loadBundler(Bundler bundler); 141 } |