51 * Plugins configuration. 52 */ 53 public final class ImagePluginConfiguration { 54 55 private static final List<Plugin.CATEGORY> CATEGORIES_ORDER = new ArrayList<>(); 56 57 static { 58 CATEGORIES_ORDER.add(Plugin.CATEGORY.FILTER); 59 CATEGORIES_ORDER.add(Plugin.CATEGORY.TRANSFORMER); 60 CATEGORIES_ORDER.add(Plugin.CATEGORY.MODULEINFO_TRANSFORMER); 61 CATEGORIES_ORDER.add(Plugin.CATEGORY.SORTER); 62 CATEGORIES_ORDER.add(Plugin.CATEGORY.COMPRESSOR); 63 CATEGORIES_ORDER.add(Plugin.CATEGORY.VERIFIER); 64 CATEGORIES_ORDER.add(Plugin.CATEGORY.PROCESSOR); 65 CATEGORIES_ORDER.add(Plugin.CATEGORY.PACKAGER); 66 } 67 68 private ImagePluginConfiguration() { 69 } 70 71 public static ImagePluginStack parseConfiguration(Jlink.PluginsConfiguration plugins) 72 throws Exception { 73 return parseConfiguration(plugins, null); 74 } 75 76 /* 77 * Create a stack of plugins from a a configuration. 78 * 79 */ 80 public static ImagePluginStack parseConfiguration(Jlink.PluginsConfiguration pluginsConfiguration, 81 String bom) 82 throws Exception { 83 if (pluginsConfiguration == null) { 84 return new ImagePluginStack(bom); 85 } 86 Map<Plugin.CATEGORY, List<Plugin>> plugins = new LinkedHashMap<>(); 87 for (Plugin.CATEGORY cat : CATEGORIES_ORDER) { 88 plugins.put(cat, new ArrayList<>()); 89 } 90 91 List<String> seen = new ArrayList<>(); 92 // split into categories and check for plugin with same name. 93 for (Plugin plug : pluginsConfiguration.getPlugins()) { 94 if (seen.contains(plug.getName())) { 95 throw new Exception("Plugin " + plug.getName() 96 + " added more than once to stack "); 97 } 98 seen.add(plug.getName()); 99 CATEGORY category = Utils.getCategory(plug); 100 if (category == null) { 101 throw new PluginException("Invalid category for " 102 + plug.getName()); 103 } 104 List<Plugin> lst = plugins.get(category); 133 if (pluginsConfiguration.getLastSorterPluginName() != null && lastSorter == null) { 134 throw new IOException("Unknown last plugin " 135 + pluginsConfiguration.getLastSorterPluginName()); 136 } 137 ImageBuilder builder = pluginsConfiguration.getImageBuilder(); 138 if (builder == null) { 139 // This should be the case for jimage only creation or post-install. 140 builder = new ImageBuilder() { 141 142 @Override 143 public DataOutputStream getJImageOutputStream() { 144 throw new PluginException("No directory setup to store files"); 145 } 146 147 @Override 148 public ExecutableImage getExecutableImage() { 149 throw new PluginException("No directory setup to store files"); 150 } 151 152 @Override 153 public void storeFiles(Pool files, String bom) { 154 throw new PluginException("No directory setup to store files"); 155 } 156 }; 157 } 158 159 PluginContext ctxt = pluginsConfiguration.getPluginContext(); 160 return new ImagePluginStack(builder, transformerPlugins, 161 lastSorter, postProcessingPlugins, ctxt, bom); 162 } 163 } | 51 * Plugins configuration. 52 */ 53 public final class ImagePluginConfiguration { 54 55 private static final List<Plugin.CATEGORY> CATEGORIES_ORDER = new ArrayList<>(); 56 57 static { 58 CATEGORIES_ORDER.add(Plugin.CATEGORY.FILTER); 59 CATEGORIES_ORDER.add(Plugin.CATEGORY.TRANSFORMER); 60 CATEGORIES_ORDER.add(Plugin.CATEGORY.MODULEINFO_TRANSFORMER); 61 CATEGORIES_ORDER.add(Plugin.CATEGORY.SORTER); 62 CATEGORIES_ORDER.add(Plugin.CATEGORY.COMPRESSOR); 63 CATEGORIES_ORDER.add(Plugin.CATEGORY.VERIFIER); 64 CATEGORIES_ORDER.add(Plugin.CATEGORY.PROCESSOR); 65 CATEGORIES_ORDER.add(Plugin.CATEGORY.PACKAGER); 66 } 67 68 private ImagePluginConfiguration() { 69 } 70 71 /* 72 * Create a stack of plugins from a a configuration. 73 */ 74 public static ImagePluginStack parseConfiguration(Jlink.PluginsConfiguration pluginsConfiguration) 75 throws Exception { 76 if (pluginsConfiguration == null) { 77 return new ImagePluginStack(); 78 } 79 Map<Plugin.CATEGORY, List<Plugin>> plugins = new LinkedHashMap<>(); 80 for (Plugin.CATEGORY cat : CATEGORIES_ORDER) { 81 plugins.put(cat, new ArrayList<>()); 82 } 83 84 List<String> seen = new ArrayList<>(); 85 // split into categories and check for plugin with same name. 86 for (Plugin plug : pluginsConfiguration.getPlugins()) { 87 if (seen.contains(plug.getName())) { 88 throw new Exception("Plugin " + plug.getName() 89 + " added more than once to stack "); 90 } 91 seen.add(plug.getName()); 92 CATEGORY category = Utils.getCategory(plug); 93 if (category == null) { 94 throw new PluginException("Invalid category for " 95 + plug.getName()); 96 } 97 List<Plugin> lst = plugins.get(category); 126 if (pluginsConfiguration.getLastSorterPluginName() != null && lastSorter == null) { 127 throw new IOException("Unknown last plugin " 128 + pluginsConfiguration.getLastSorterPluginName()); 129 } 130 ImageBuilder builder = pluginsConfiguration.getImageBuilder(); 131 if (builder == null) { 132 // This should be the case for jimage only creation or post-install. 133 builder = new ImageBuilder() { 134 135 @Override 136 public DataOutputStream getJImageOutputStream() { 137 throw new PluginException("No directory setup to store files"); 138 } 139 140 @Override 141 public ExecutableImage getExecutableImage() { 142 throw new PluginException("No directory setup to store files"); 143 } 144 145 @Override 146 public void storeFiles(Pool files) { 147 throw new PluginException("No directory setup to store files"); 148 } 149 }; 150 } 151 152 PluginContext ctxt = pluginsConfiguration.getPluginContext(); 153 return new ImagePluginStack(builder, transformerPlugins, 154 lastSorter, postProcessingPlugins, ctxt); 155 } 156 } |