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 package jdk.tools.jlink.internal;
26
27 import java.io.DataOutputStream;
28
29 import java.io.IOException;
30 import java.util.ArrayList;
31 import java.util.LinkedHashMap;
32 import java.util.List;
33 import java.util.Map;
34 import java.util.Map.Entry;
35 import jdk.tools.jlink.builder.ImageBuilder;
36 import jdk.tools.jlink.Jlink;
37 import jdk.tools.jlink.plugin.Plugin;
38 import jdk.tools.jlink.plugin.PluginException;
39 import jdk.tools.jlink.plugin.Plugin.Category;
40 import jdk.tools.jlink.plugin.ResourcePool;
41
42 /**
43 * Plugins configuration.
44 */
45 public final class ImagePluginConfiguration {
46
47 private static final List<Category> CATEGORIES_ORDER = new ArrayList<>();
48
49 static {
50 CATEGORIES_ORDER.add(Category.FILTER);
51 CATEGORIES_ORDER.add(Category.TRANSFORMER);
52 CATEGORIES_ORDER.add(Category.MODULEINFO_TRANSFORMER);
53 CATEGORIES_ORDER.add(Category.SORTER);
54 CATEGORIES_ORDER.add(Category.COMPRESSOR);
55 CATEGORIES_ORDER.add(Category.METAINFO_ADDER);
56 CATEGORIES_ORDER.add(Category.VERIFIER);
57 CATEGORIES_ORDER.add(Category.PROCESSOR);
58 CATEGORIES_ORDER.add(Category.PACKAGER);
59 }
60
61 private ImagePluginConfiguration() {
62 }
63
64 /*
65 * Create a stack of plugins from a a configuration.
66 */
67 public static ImagePluginStack parseConfiguration(Jlink.PluginsConfiguration pluginsConfiguration)
68 throws Exception {
69 if (pluginsConfiguration == null) {
70 return new ImagePluginStack();
71 }
72 Map<Category, List<Plugin>> plugins = new LinkedHashMap<>();
73 for (Category cat : CATEGORIES_ORDER) {
74 plugins.put(cat, new ArrayList<>());
75 }
76
77 List<String> seen = new ArrayList<>();
78 // split into categories and check for plugin with same name.
79 for (Plugin plug : pluginsConfiguration.getPlugins()) {
80 if (seen.contains(plug.getName())) {
81 throw new Exception("Plugin " + plug.getName()
82 + " added more than once to stack ");
83 }
84 seen.add(plug.getName());
85 Category category = plug.getType();
86 if (category == null) {
87 throw new PluginException("Invalid category for "
88 + plug.getName());
111 // This should be the case for jimage only creation or post-install.
112 builder = new ImageBuilder() {
113
114 @Override
115 public DataOutputStream getJImageOutputStream() {
116 throw new PluginException("No directory setup to store files");
117 }
118
119 @Override
120 public ExecutableImage getExecutableImage() {
121 throw new PluginException("No directory setup to store files");
122 }
123
124 @Override
125 public void storeFiles(ResourcePool files) {
126 throw new PluginException("No directory setup to store files");
127 }
128 };
129 }
130
131 return new ImagePluginStack(builder, orderedPlugins, lastSorter);
132 }
133 }
|
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 package jdk.tools.jlink.internal;
26
27 import java.io.DataOutputStream;
28
29 import java.io.IOException;
30 import java.util.ArrayList;
31 import java.util.LinkedHashMap;
32 import java.util.List;
33 import java.util.Map;
34 import java.util.Map.Entry;
35 import java.util.Set;
36 import jdk.tools.jlink.builder.ImageBuilder;
37 import jdk.tools.jlink.Jlink;
38 import jdk.tools.jlink.plugin.Plugin;
39 import jdk.tools.jlink.plugin.PluginException;
40 import jdk.tools.jlink.plugin.Plugin.Category;
41 import jdk.tools.jlink.plugin.ResourcePool;
42
43 /**
44 * Plugins configuration.
45 */
46 public final class ImagePluginConfiguration {
47
48 private static final List<Category> CATEGORIES_ORDER = new ArrayList<>();
49
50 static {
51 CATEGORIES_ORDER.add(Category.FILTER);
52 CATEGORIES_ORDER.add(Category.TRANSFORMER);
53 CATEGORIES_ORDER.add(Category.MODULEINFO_TRANSFORMER);
54 CATEGORIES_ORDER.add(Category.SORTER);
55 CATEGORIES_ORDER.add(Category.COMPRESSOR);
56 CATEGORIES_ORDER.add(Category.METAINFO_ADDER);
57 CATEGORIES_ORDER.add(Category.VERIFIER);
58 CATEGORIES_ORDER.add(Category.PROCESSOR);
59 CATEGORIES_ORDER.add(Category.PACKAGER);
60 }
61
62 private ImagePluginConfiguration() {
63 }
64
65 /*
66 * Create a stack of plugins from a a configuration.
67 */
68 public static ImagePluginStack parseConfiguration(Jlink.PluginsConfiguration pluginsConfiguration)
69 throws Exception {
70 return parseConfiguration(pluginsConfiguration, null);
71 }
72
73 /*
74 * Create a stack of plugins from a a configuration.
75 */
76 public static ImagePluginStack parseConfiguration(Jlink.PluginsConfiguration pluginsConfiguration,
77 Set<String> roots)
78 throws Exception {
79 if (pluginsConfiguration == null) {
80 return new ImagePluginStack();
81 }
82 Map<Category, List<Plugin>> plugins = new LinkedHashMap<>();
83 for (Category cat : CATEGORIES_ORDER) {
84 plugins.put(cat, new ArrayList<>());
85 }
86
87 List<String> seen = new ArrayList<>();
88 // split into categories and check for plugin with same name.
89 for (Plugin plug : pluginsConfiguration.getPlugins()) {
90 if (seen.contains(plug.getName())) {
91 throw new Exception("Plugin " + plug.getName()
92 + " added more than once to stack ");
93 }
94 seen.add(plug.getName());
95 Category category = plug.getType();
96 if (category == null) {
97 throw new PluginException("Invalid category for "
98 + plug.getName());
121 // This should be the case for jimage only creation or post-install.
122 builder = new ImageBuilder() {
123
124 @Override
125 public DataOutputStream getJImageOutputStream() {
126 throw new PluginException("No directory setup to store files");
127 }
128
129 @Override
130 public ExecutableImage getExecutableImage() {
131 throw new PluginException("No directory setup to store files");
132 }
133
134 @Override
135 public void storeFiles(ResourcePool files) {
136 throw new PluginException("No directory setup to store files");
137 }
138 };
139 }
140
141 return new ImagePluginStack(builder, orderedPlugins, lastSorter, roots);
142 }
143 }
|