author | sundar |
Thu, 28 Jul 2016 19:34:58 +0530 | |
changeset 39834 | 53a6fb443c20 |
parent 39505 | be0bbd76ae51 |
child 41559 | 5b33f33df1fb |
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.builder.ImageBuilder; |
|
36 |
import jdk.tools.jlink.Jlink; |
|
37 |
import jdk.tools.jlink.plugin.Plugin; |
|
38 |
import jdk.tools.jlink.plugin.PluginException; |
|
38320 | 39 |
import jdk.tools.jlink.plugin.Plugin.Category; |
39834
53a6fb443c20
8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents:
39505
diff
changeset
|
40 |
import jdk.tools.jlink.plugin.ResourcePool; |
36511 | 41 |
|
42 |
/** |
|
43 |
* Plugins configuration. |
|
44 |
*/ |
|
45 |
public final class ImagePluginConfiguration { |
|
46 |
||
39308 | 47 |
private static final List<Category> CATEGORIES_ORDER = new ArrayList<>(); |
36511 | 48 |
|
49 |
static { |
|
39308 | 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); |
|
36511 | 59 |
} |
60 |
||
61 |
private ImagePluginConfiguration() { |
|
62 |
} |
|
63 |
||
64 |
/* |
|
65 |
* Create a stack of plugins from a a configuration. |
|
66 |
*/ |
|
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
67 |
public static ImagePluginStack parseConfiguration(Jlink.PluginsConfiguration pluginsConfiguration) |
36511 | 68 |
throws Exception { |
69 |
if (pluginsConfiguration == null) { |
|
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
70 |
return new ImagePluginStack(); |
36511 | 71 |
} |
39308 | 72 |
Map<Category, List<Plugin>> plugins = new LinkedHashMap<>(); |
73 |
for (Category cat : CATEGORIES_ORDER) { |
|
36511 | 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()); |
|
39321
c60f34e8c057
8160641: PostProcessingPlugin and ExecutableImage should not be part of plugin API
sundar
parents:
39308
diff
changeset
|
85 |
Category category = plug.getType(); |
36511 | 86 |
if (category == null) { |
87 |
throw new PluginException("Invalid category for " |
|
88 |
+ plug.getName()); |
|
89 |
} |
|
90 |
List<Plugin> lst = plugins.get(category); |
|
91 |
lst.add(plug); |
|
92 |
} |
|
93 |
||
39321
c60f34e8c057
8160641: PostProcessingPlugin and ExecutableImage should not be part of plugin API
sundar
parents:
39308
diff
changeset
|
94 |
List<Plugin> orderedPlugins = new ArrayList<>(); |
39308 | 95 |
plugins.entrySet().stream().forEach((entry) -> { |
39505
be0bbd76ae51
8161055: Remove plugin ordering by isAfter, isBefore.
sundar
parents:
39321
diff
changeset
|
96 |
orderedPlugins.addAll(entry.getValue()); |
39308 | 97 |
}); |
36511 | 98 |
Plugin lastSorter = null; |
39321
c60f34e8c057
8160641: PostProcessingPlugin and ExecutableImage should not be part of plugin API
sundar
parents:
39308
diff
changeset
|
99 |
for (Plugin plugin : orderedPlugins) { |
36511 | 100 |
if (plugin.getName().equals(pluginsConfiguration.getLastSorterPluginName())) { |
101 |
lastSorter = plugin; |
|
102 |
break; |
|
103 |
} |
|
104 |
} |
|
105 |
if (pluginsConfiguration.getLastSorterPluginName() != null && lastSorter == null) { |
|
106 |
throw new IOException("Unknown last plugin " |
|
107 |
+ pluginsConfiguration.getLastSorterPluginName()); |
|
108 |
} |
|
109 |
ImageBuilder builder = pluginsConfiguration.getImageBuilder(); |
|
110 |
if (builder == null) { |
|
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 |
|
39834
53a6fb443c20
8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents:
39505
diff
changeset
|
125 |
public void storeFiles(ResourcePool files) { |
36511 | 126 |
throw new PluginException("No directory setup to store files"); |
127 |
} |
|
128 |
}; |
|
129 |
} |
|
130 |
||
39321
c60f34e8c057
8160641: PostProcessingPlugin and ExecutableImage should not be part of plugin API
sundar
parents:
39308
diff
changeset
|
131 |
return new ImagePluginStack(builder, orderedPlugins, lastSorter); |
36511 | 132 |
} |
133 |
} |