author | jlaskey |
Tue, 28 Jun 2016 16:07:23 -0300 | |
changeset 39308 | f6517755057f |
parent 39129 | 4b2086305b68 |
child 39321 | c60f34e8c057 |
permissions | -rw-r--r-- |
36511 | 1 |
/* |
2 |
* Copyright (c) 2015, 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 |
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.plugin.ExecutableImage; |
|
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; |
|
38320 | 40 |
import jdk.tools.jlink.plugin.Plugin.Category; |
41 |
import jdk.tools.jlink.plugin.ModulePool; |
|
36511 | 42 |
import jdk.tools.jlink.plugin.PostProcessorPlugin; |
43 |
import jdk.tools.jlink.plugin.TransformerPlugin; |
|
44 |
||
45 |
/** |
|
46 |
* Plugins configuration. |
|
47 |
*/ |
|
48 |
public final class ImagePluginConfiguration { |
|
49 |
||
39308 | 50 |
private static final List<Category> CATEGORIES_ORDER = new ArrayList<>(); |
36511 | 51 |
|
52 |
static { |
|
39308 | 53 |
CATEGORIES_ORDER.add(Category.FILTER); |
54 |
CATEGORIES_ORDER.add(Category.TRANSFORMER); |
|
55 |
CATEGORIES_ORDER.add(Category.MODULEINFO_TRANSFORMER); |
|
56 |
CATEGORIES_ORDER.add(Category.SORTER); |
|
57 |
CATEGORIES_ORDER.add(Category.COMPRESSOR); |
|
58 |
CATEGORIES_ORDER.add(Category.METAINFO_ADDER); |
|
59 |
CATEGORIES_ORDER.add(Category.VERIFIER); |
|
60 |
CATEGORIES_ORDER.add(Category.PROCESSOR); |
|
61 |
CATEGORIES_ORDER.add(Category.PACKAGER); |
|
36511 | 62 |
} |
63 |
||
64 |
private ImagePluginConfiguration() { |
|
65 |
} |
|
66 |
||
67 |
/* |
|
68 |
* Create a stack of plugins from a a configuration. |
|
69 |
*/ |
|
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
70 |
public static ImagePluginStack parseConfiguration(Jlink.PluginsConfiguration pluginsConfiguration) |
36511 | 71 |
throws Exception { |
72 |
if (pluginsConfiguration == null) { |
|
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
73 |
return new ImagePluginStack(); |
36511 | 74 |
} |
39308 | 75 |
Map<Category, List<Plugin>> plugins = new LinkedHashMap<>(); |
76 |
for (Category cat : CATEGORIES_ORDER) { |
|
36511 | 77 |
plugins.put(cat, new ArrayList<>()); |
78 |
} |
|
79 |
||
80 |
List<String> seen = new ArrayList<>(); |
|
81 |
// split into categories and check for plugin with same name. |
|
82 |
for (Plugin plug : pluginsConfiguration.getPlugins()) { |
|
83 |
if (seen.contains(plug.getName())) { |
|
84 |
throw new Exception("Plugin " + plug.getName() |
|
85 |
+ " added more than once to stack "); |
|
86 |
} |
|
87 |
seen.add(plug.getName()); |
|
38320 | 88 |
Category category = Utils.getCategory(plug); |
36511 | 89 |
if (category == null) { |
90 |
throw new PluginException("Invalid category for " |
|
91 |
+ plug.getName()); |
|
92 |
} |
|
93 |
List<Plugin> lst = plugins.get(category); |
|
94 |
lst.add(plug); |
|
95 |
} |
|
96 |
||
97 |
List<TransformerPlugin> transformerPlugins = new ArrayList<>(); |
|
98 |
List<PostProcessorPlugin> postProcessingPlugins = new ArrayList<>(); |
|
39308 | 99 |
plugins.entrySet().stream().forEach((entry) -> { |
36511 | 100 |
// Sort according to plugin constraints |
101 |
List<Plugin> orderedPlugins = PluginOrderingGraph.sort(entry.getValue()); |
|
38320 | 102 |
Category category = entry.getKey(); |
39308 | 103 |
orderedPlugins.stream().forEach((p) -> { |
39129
4b2086305b68
8159593: Plugin Set<Category> getType() should return a Category
sundar
parents:
38320
diff
changeset
|
104 |
if (category.isPostProcessor()) { |
36511 | 105 |
@SuppressWarnings("unchecked") |
39308 | 106 |
PostProcessorPlugin pp = (PostProcessorPlugin) p; |
36511 | 107 |
postProcessingPlugins.add(pp); |
108 |
} else { |
|
109 |
@SuppressWarnings("unchecked") |
|
39308 | 110 |
TransformerPlugin trans = (TransformerPlugin) p; |
36511 | 111 |
transformerPlugins.add(trans); |
112 |
} |
|
39308 | 113 |
}); |
114 |
}); |
|
36511 | 115 |
Plugin lastSorter = null; |
116 |
for (Plugin plugin : transformerPlugins) { |
|
117 |
if (plugin.getName().equals(pluginsConfiguration.getLastSorterPluginName())) { |
|
118 |
lastSorter = plugin; |
|
119 |
break; |
|
120 |
} |
|
121 |
} |
|
122 |
if (pluginsConfiguration.getLastSorterPluginName() != null && lastSorter == null) { |
|
123 |
throw new IOException("Unknown last plugin " |
|
124 |
+ pluginsConfiguration.getLastSorterPluginName()); |
|
125 |
} |
|
126 |
ImageBuilder builder = pluginsConfiguration.getImageBuilder(); |
|
127 |
if (builder == null) { |
|
128 |
// This should be the case for jimage only creation or post-install. |
|
129 |
builder = new ImageBuilder() { |
|
130 |
||
131 |
@Override |
|
132 |
public DataOutputStream getJImageOutputStream() { |
|
133 |
throw new PluginException("No directory setup to store files"); |
|
134 |
} |
|
135 |
||
136 |
@Override |
|
137 |
public ExecutableImage getExecutableImage() { |
|
138 |
throw new PluginException("No directory setup to store files"); |
|
139 |
} |
|
140 |
||
141 |
@Override |
|
38320 | 142 |
public void storeFiles(ModulePool files) { |
36511 | 143 |
throw new PluginException("No directory setup to store files"); |
144 |
} |
|
145 |
}; |
|
146 |
} |
|
147 |
||
148 |
return new ImagePluginStack(builder, transformerPlugins, |
|
38320 | 149 |
lastSorter, postProcessingPlugins); |
36511 | 150 |
} |
151 |
} |