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.lang.reflect.Layer;
28 import java.nio.ByteOrder;
29 import java.nio.file.Path;
30 import java.util.Collections;
31 import java.util.List;
32 import java.util.Map;
33 import java.util.Objects;
34 import java.util.Set;
35 import jdk.tools.jlink.plugin.Plugin;
36 import jdk.tools.jlink.plugin.PluginException;
37 import jdk.tools.jlink.builder.ImageBuilder;
38
39 /**
40 * API to call jlink.
41 */
42 public final class Jlink {
43
44 /**
45 * Create a plugin.
46 *
47 * @param name Plugin name
48 * @param configuration Plugin configuration.
49 * @param pluginsLayer Plugins Layer. null means boot layer.
261
262 /**
263 * Build the image.
264 *
265 * @param config Jlink config, must not be null.
266 * @throws PluginException
267 */
268 public void build(JlinkConfiguration config) {
269 build(config, null);
270 }
271
272 /**
273 * Build the image with a plugin configuration.
274 *
275 * @param config Jlink config, must not be null.
276 * @param pluginsConfig Plugins config, can be null
277 * @throws PluginException
278 */
279 public void build(JlinkConfiguration config, PluginsConfiguration pluginsConfig) {
280 Objects.requireNonNull(config);
281 try {
282 JlinkTask.createImage(config, pluginsConfig);
283 } catch (Exception ex) {
284 throw new PluginException(ex);
285 }
286 }
287
288 /**
289 * Post process the image with a plugin configuration.
290 *
291 * @param image Existing image.
292 * @param plugins Plugins cannot be null
293 */
294 public void postProcess(ExecutableImage image, List<Plugin> plugins) {
295 Objects.requireNonNull(image);
296 Objects.requireNonNull(plugins);
297 try {
298 JlinkTask.postProcessImage(image, plugins);
299 } catch (Exception ex) {
300 throw new PluginException(ex);
301 }
302 }
303 }
|
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.lang.reflect.Layer;
28 import java.nio.ByteOrder;
29 import java.nio.file.Path;
30 import java.util.ArrayList;
31 import java.util.Collections;
32 import java.util.List;
33 import java.util.Map;
34 import java.util.Objects;
35 import java.util.Set;
36 import jdk.tools.jlink.plugin.Plugin;
37 import jdk.tools.jlink.plugin.PluginException;
38 import jdk.tools.jlink.builder.ImageBuilder;
39
40 /**
41 * API to call jlink.
42 */
43 public final class Jlink {
44
45 /**
46 * Create a plugin.
47 *
48 * @param name Plugin name
49 * @param configuration Plugin configuration.
50 * @param pluginsLayer Plugins Layer. null means boot layer.
262
263 /**
264 * Build the image.
265 *
266 * @param config Jlink config, must not be null.
267 * @throws PluginException
268 */
269 public void build(JlinkConfiguration config) {
270 build(config, null);
271 }
272
273 /**
274 * Build the image with a plugin configuration.
275 *
276 * @param config Jlink config, must not be null.
277 * @param pluginsConfig Plugins config, can be null
278 * @throws PluginException
279 */
280 public void build(JlinkConfiguration config, PluginsConfiguration pluginsConfig) {
281 Objects.requireNonNull(config);
282 if (pluginsConfig == null) {
283 pluginsConfig = new PluginsConfiguration();
284 }
285
286 // add all auto-enabled plugins from boot layer
287 pluginsConfig = addAutoEnabledPlugins(pluginsConfig);
288
289 try {
290 JlinkTask.createImage(config, pluginsConfig);
291 } catch (Exception ex) {
292 throw new PluginException(ex);
293 }
294 }
295
296 private PluginsConfiguration addAutoEnabledPlugins(PluginsConfiguration pluginsConfig) {
297 List<Plugin> plugins = new ArrayList<>(pluginsConfig.getPlugins());
298 List<Plugin> bootPlugins = PluginRepository.getPlugins(Layer.boot());
299 for (Plugin bp : bootPlugins) {
300 if (Utils.isAutoEnabled(bp)) {
301 bp.configure(Collections.emptyMap());
302 plugins.add(bp);
303 }
304 }
305 return new PluginsConfiguration(plugins, pluginsConfig.getImageBuilder(),
306 pluginsConfig.getLastSorterPluginName());
307 }
308
309 /**
310 * Post process the image with a plugin configuration.
311 *
312 * @param image Existing image.
313 * @param plugins Plugins cannot be null
314 */
315 public void postProcess(ExecutableImage image, List<Plugin> plugins) {
316 Objects.requireNonNull(image);
317 Objects.requireNonNull(plugins);
318 try {
319 JlinkTask.postProcessImage(image, plugins);
320 } catch (Exception ex) {
321 throw new PluginException(ex);
322 }
323 }
324 }
|