< prev index next > src/jdk.jlink/share/classes/jdk/tools/jlink/internal/JlinkTask.java
Print this page
/*
- * Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
Objects.requireNonNull(config);
Objects.requireNonNull(config.getOutput());
plugins = plugins == null ? new PluginsConfiguration() : plugins;
// First create the image provider
- ImageProvider imageProvider =
- createImageProvider(config,
- null,
- IGNORE_SIGNING_DEFAULT,
- false,
- null,
- false,
- new OptionsValues(),
- null);
-
- // Then create the Plugin Stack
- ImagePluginStack stack = ImagePluginConfiguration.parseConfiguration(plugins);
-
- //Ask the stack to proceed;
- stack.operate(imageProvider);
+ try (ImageHelper imageProvider =
+ createImageProvider(config,
+ null,
+ IGNORE_SIGNING_DEFAULT,
+ false,
+ null,
+ false,
+ new OptionsValues(),
+ null)) {
+
+ // Then create the Plugin Stack
+ ImagePluginStack stack = ImagePluginConfiguration.parseConfiguration(plugins);
+
+ // Ask the stack to proceed;
+ stack.operate(imageProvider);
+ }
}
// the token for "all modules on the module path"
private static final String ALL_MODULE_PATH = "ALL-MODULE-PATH";
private JlinkConfiguration initJlinkConfig() throws BadArgs {
throw taskHelper.newBadArgs("err.mods.must.be.specified", "--add-modules")
.showUsage(true);
}
// First create the image provider
- ImageHelper imageProvider = createImageProvider(config,
- options.packagedModulesPath,
- options.ignoreSigning,
- options.bindServices,
- options.endian,
- options.verbose,
- options,
- log);
-
- // Then create the Plugin Stack
- ImagePluginStack stack = ImagePluginConfiguration.parseConfiguration(
- taskHelper.getPluginsConfig(options.output, options.launchers,
- imageProvider.targetPlatform));
-
- //Ask the stack to proceed
- stack.operate(imageProvider);
+ try (ImageHelper imageProvider = createImageProvider(config,
+ options.packagedModulesPath,
+ options.ignoreSigning,
+ options.bindServices,
+ options.endian,
+ options.verbose,
+ options,
+ log)) {
+ // Then create the Plugin Stack
+ ImagePluginStack stack = ImagePluginConfiguration.parseConfiguration(
+ taskHelper.getPluginsConfig(
+ options.output,
+ options.launchers,
+ imageProvider.targetPlatform));
+
+ //Ask the stack to proceed
+ stack.operate(imageProvider);
+ }
}
/**
* @return the system module path or null
*/
}
return sb.toString();
}
- private static record ImageHelper(Set<Archive> archives,
- Platform targetPlatform,
- Path packagedModulesPath,
- boolean generateRuntimeImage) implements ImageProvider {
+ private record ImageHelper(Set<Archive> archives,
+ Platform targetPlatform,
+ Path packagedModulesPath,
+ boolean generateRuntimeImage)
+ implements ImageProvider, AutoCloseable {
@Override
public ExecutableImage retrieve(ImagePluginStack stack) throws IOException {
ExecutableImage image = ImageFileCreator.create(archives,
targetPlatform.arch().byteOrder(), stack, generateRuntimeImage);
if (packagedModulesPath != null) {
Files.copy(file, dest);
}
}
return image;
}
+
+ @Override
+ public void close() throws IOException {
+ List<IOException> thrown = null;
+ for (Archive archive : archives) {
+ try {
+ archive.close();
+ } catch (IOException ex) {
+ if (thrown == null) {
+ thrown = new ArrayList<>();
+ }
+ thrown.add(ex);
+ }
+ }
+ if (thrown != null) {
+ IOException ex = new IOException("Archives could not be closed", thrown.getFirst());
+ thrown.subList(1, thrown.size()).forEach(ex::addSuppressed);
+ throw ex;
+ }
+ }
}
}
< prev index next >