8304691: Remove jlink --post-process-path option
Reviewed-by: mchung
This commit is contained in:
parent
3859faf183
commit
af0504e3f3
@ -567,9 +567,6 @@ public final class DefaultImageBuilder implements ImageBuilder {
|
||||
Path binDir = root.resolve(BIN_DIRNAME);
|
||||
if (Files.exists(binDir.resolve("java")) ||
|
||||
Files.exists(binDir.resolve("java.exe"))) {
|
||||
// It may be possible to extract the platform info from the given image.
|
||||
// --post-process-path is a hidden option and pass unknown platform for now.
|
||||
// --generate-cds-archive plugin cannot be used with --post-process-path option.
|
||||
return new DefaultExecutableImage(root, retrieveModules(root), Platform.UNKNOWN);
|
||||
}
|
||||
return null;
|
||||
|
@ -300,19 +300,4 @@ public final class Jlink {
|
||||
pluginsConfig.getLastSorterPluginName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Post process the image with a plugin configuration.
|
||||
*
|
||||
* @param image Existing image.
|
||||
* @param plugins Plugins cannot be null
|
||||
*/
|
||||
public void postProcess(ExecutableImage image, List<Plugin> plugins) {
|
||||
Objects.requireNonNull(image);
|
||||
Objects.requireNonNull(plugins);
|
||||
try {
|
||||
JlinkTask.postProcessImage(image, plugins);
|
||||
} catch (Exception ex) {
|
||||
throw new PluginException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -265,12 +265,6 @@ public class JlinkTask {
|
||||
return EXIT_OK;
|
||||
}
|
||||
|
||||
if (taskHelper.getExistingImage() != null) {
|
||||
postProcessOnly(taskHelper.getExistingImage());
|
||||
return EXIT_OK;
|
||||
}
|
||||
|
||||
|
||||
if (options.modulePath.isEmpty()) {
|
||||
// no --module-path specified - try to set $JAVA_HOME/jmods if that exists
|
||||
Path jmods = getDefaultModulePath();
|
||||
@ -371,29 +365,6 @@ public class JlinkTask {
|
||||
stack.operate(imageProvider);
|
||||
}
|
||||
|
||||
/*
|
||||
* Jlink API entry point.
|
||||
*/
|
||||
public static void postProcessImage(ExecutableImage image, List<Plugin> postProcessorPlugins)
|
||||
throws Exception {
|
||||
Objects.requireNonNull(image);
|
||||
Objects.requireNonNull(postProcessorPlugins);
|
||||
PluginsConfiguration config = new PluginsConfiguration(postProcessorPlugins);
|
||||
ImagePluginStack stack = ImagePluginConfiguration.
|
||||
parseConfiguration(config);
|
||||
|
||||
stack.operate((ImagePluginStack stack1) -> image);
|
||||
}
|
||||
|
||||
private void postProcessOnly(Path existingImage) throws Exception {
|
||||
PluginsConfiguration config = taskHelper.getPluginsConfig(null, null);
|
||||
ExecutableImage img = DefaultImageBuilder.getExecutableImage(existingImage);
|
||||
if (img == null) {
|
||||
throw taskHelper.newBadArgs("err.existing.image.invalid");
|
||||
}
|
||||
postProcessImage(img, config.getPlugins());
|
||||
}
|
||||
|
||||
// the token for "all modules on the module path"
|
||||
private static final String ALL_MODULE_PATH = "ALL-MODULE-PATH";
|
||||
private JlinkConfiguration initJlinkConfig() throws BadArgs {
|
||||
|
@ -230,7 +230,6 @@ public final class TaskHelper {
|
||||
private final List<Plugin> plugins;
|
||||
private String lastSorter;
|
||||
private boolean listPlugins;
|
||||
private Path existingImage;
|
||||
|
||||
// plugin to args maps. Each plugin may be used more than once in command line.
|
||||
// Each such occurrence results in a Map of arguments. So, there could be multiple
|
||||
@ -259,13 +258,6 @@ public final class TaskHelper {
|
||||
throw newBadArgs("err.no.such.plugin", arg);
|
||||
},
|
||||
false, "--disable-plugin"));
|
||||
mainOptions.add(new PluginOption(true, (task, opt, arg) -> {
|
||||
Path path = Paths.get(arg);
|
||||
if (!Files.exists(path) || !Files.isDirectory(path)) {
|
||||
throw newBadArgs("err.image.must.exist", path);
|
||||
}
|
||||
existingImage = path.toAbsolutePath();
|
||||
}, true, "--post-process-path"));
|
||||
mainOptions.add(new PluginOption(true,
|
||||
(task, opt, arg) -> {
|
||||
lastSorter = arg;
|
||||
@ -721,10 +713,6 @@ public final class TaskHelper {
|
||||
return pluginOptions.getPluginsConfig(output, launchers);
|
||||
}
|
||||
|
||||
public Path getExistingImage() {
|
||||
return pluginOptions.existingImage;
|
||||
}
|
||||
|
||||
public void showVersion(boolean full) {
|
||||
log.println(version(full ? "full" : "release"));
|
||||
}
|
||||
|
@ -127,8 +127,6 @@ err.modulepath.must.be.specified:--module-path is not specified and this runtime
|
||||
err.mods.must.be.specified:no modules specified to {0}
|
||||
err.path.not.found=path not found: {0}
|
||||
err.path.not.valid=invalid path: {0}
|
||||
err.image.must.exist=image {0} does not exist or is not a directory
|
||||
err.existing.image.invalid=existing image is not valid
|
||||
err.file.not.found=cannot find file: {0}
|
||||
err.file.error=cannot access file: {0}
|
||||
err.dir.exists={0} already exists
|
||||
|
@ -294,9 +294,6 @@ List of available plugin options:
|
||||
plugin.opt.list-plugins=\
|
||||
\ --list-plugins List available plugins
|
||||
|
||||
plugin.opt.post-process-path=\
|
||||
\ --post-process-path <imagefile> Post process an existing image
|
||||
|
||||
plugin.opt.resources-last-sorter=\
|
||||
\ --resources-last-sorter <name> The last plugin allowed to sort\n\
|
||||
\ resources
|
||||
|
@ -1,154 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 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.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
import jdk.tools.jlink.plugin.Plugin;
|
||||
import jdk.tools.jlink.plugin.ResourcePool;
|
||||
import jdk.tools.jlink.plugin.ResourcePoolBuilder;
|
||||
import jdk.tools.jlink.internal.PluginRepository;
|
||||
import jdk.tools.jlink.internal.PostProcessor;
|
||||
import jdk.tools.jlink.internal.ExecutableImage;
|
||||
import tests.Helper;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary Test post processing
|
||||
* @author Jean-Francois Denise
|
||||
* @library ../lib
|
||||
* @modules java.base/jdk.internal.jimage
|
||||
* jdk.jdeps/com.sun.tools.classfile
|
||||
* jdk.jlink/jdk.tools.jlink.internal
|
||||
* jdk.jlink/jdk.tools.jlink.plugin
|
||||
* jdk.jlink/jdk.tools.jmod
|
||||
* jdk.jlink/jdk.tools.jimage
|
||||
* jdk.compiler
|
||||
* @build tests.*
|
||||
* @run main/othervm JLinkPostProcessingTest
|
||||
*/
|
||||
public class JLinkPostProcessingTest {
|
||||
|
||||
private static class PPPlugin implements PostProcessor, Plugin {
|
||||
|
||||
private static ExecutableImage called;
|
||||
private static final String NAME = "pp";
|
||||
|
||||
@Override
|
||||
public List<String> process(ExecutableImage image) {
|
||||
called = image;
|
||||
Path gen = image.getHome().resolve("lib").resolve("toto.txt");
|
||||
try {
|
||||
Files.createFile(gen);
|
||||
} catch (IOException ex) {
|
||||
throw new UncheckedIOException(ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourcePool transform(ResourcePool in, ResourcePoolBuilder out) {
|
||||
in.transformAndCopy(Function.identity(), out);
|
||||
return out.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Category getType() {
|
||||
return Category.PROCESSOR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return NAME;
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
Helper helper = Helper.newHelper();
|
||||
if (helper == null) {
|
||||
System.err.println("Test not run");
|
||||
return;
|
||||
}
|
||||
helper.generateDefaultModules();
|
||||
|
||||
PluginRepository.registerPlugin(new PPPlugin());
|
||||
|
||||
// Generate an image and post-process in same jlink execution.
|
||||
{
|
||||
String[] userOptions = {"--pp"};
|
||||
String moduleName = "postprocessing1";
|
||||
helper.generateDefaultJModule(moduleName, "composite2");
|
||||
String[] res = {};
|
||||
String[] files = {};
|
||||
Path imageDir = helper.generateDefaultImage(userOptions, moduleName).assertSuccess();
|
||||
helper.checkImage(imageDir, moduleName, res, files);
|
||||
|
||||
test(imageDir);
|
||||
}
|
||||
|
||||
// Generate an image, post-process in 2 jlink executions.
|
||||
{
|
||||
String[] userOptions = {};
|
||||
String moduleName = "postprocessing2";
|
||||
helper.generateDefaultJModule(moduleName, "composite2");
|
||||
String[] res = {};
|
||||
String[] files = {};
|
||||
Path imageDir = helper.generateDefaultImage(userOptions, moduleName).assertSuccess();
|
||||
helper.checkImage(imageDir, moduleName, res, files);
|
||||
|
||||
String[] ppOptions = {"--pp"};
|
||||
helper.postProcessImage(imageDir, ppOptions);
|
||||
test(imageDir);
|
||||
}
|
||||
}
|
||||
|
||||
private static void test(Path imageDir)
|
||||
throws Exception {
|
||||
if (PPPlugin.called == null) {
|
||||
throw new Exception("Post processor not called.");
|
||||
}
|
||||
if (!PPPlugin.called.getHome().equals(imageDir)) {
|
||||
throw new Exception("Not right imageDir " + PPPlugin.called.getHome());
|
||||
}
|
||||
if (PPPlugin.called.getExecutionArgs().isEmpty()) {
|
||||
throw new Exception("No arguments to run java...");
|
||||
}
|
||||
Path gen = imageDir.resolve("lib").resolve("toto.txt");
|
||||
if (!Files.exists(gen)) {
|
||||
throw new Exception("Generated file doesn;t exist");
|
||||
}
|
||||
PPPlugin.called = null;
|
||||
}
|
||||
}
|
@ -257,15 +257,6 @@ public class Helper {
|
||||
return jLinkTask.call();
|
||||
}
|
||||
|
||||
public Result postProcessImage(Path root, String[] options) {
|
||||
JLinkTask jLinkTask = JImageGenerator.getJLinkTask()
|
||||
.existing(root);
|
||||
for (String option : options) {
|
||||
jLinkTask.option(option);
|
||||
}
|
||||
return jLinkTask.callPostProcess();
|
||||
}
|
||||
|
||||
private List<String> getDefaultClasses(String module) {
|
||||
return Arrays.asList(module + ".Main", module + ".com.foo.bar.X");
|
||||
}
|
||||
|
@ -103,7 +103,6 @@ public class JImageGenerator {
|
||||
+ "}\n";
|
||||
|
||||
private static final String OUTPUT_OPTION = "--output";
|
||||
private static final String POST_PROCESS_OPTION = "--post-process-path";
|
||||
private static final String MAIN_CLASS_OPTION = "--main-class";
|
||||
private static final String CLASS_PATH_OPTION = "--class-path";
|
||||
private static final String MODULE_PATH_OPTION = "--module-path";
|
||||
@ -697,16 +696,6 @@ public class JImageGenerator {
|
||||
return options.toArray(new String[options.size()]);
|
||||
}
|
||||
|
||||
private String[] optionsPostProcessJLink() {
|
||||
List<String> options = new ArrayList<>();
|
||||
if (existing != null) {
|
||||
options.add(POST_PROCESS_OPTION);
|
||||
options.add(existing.toString());
|
||||
}
|
||||
options.addAll(this.options);
|
||||
return options.toArray(new String[options.size()]);
|
||||
}
|
||||
|
||||
public Result call() {
|
||||
String[] args = optionsJLink();
|
||||
System.err.println("jlink options: " + optionsPrettyPrint(args));
|
||||
@ -715,15 +704,6 @@ public class JImageGenerator {
|
||||
int exitCode = JLINK_TOOL.run(pw, pw, args);
|
||||
return new Result(exitCode, writer.toString(), output);
|
||||
}
|
||||
|
||||
public Result callPostProcess() {
|
||||
String[] args = optionsPostProcessJLink();
|
||||
System.err.println("jlink options: " + optionsPrettyPrint(args));
|
||||
StringWriter writer = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(writer);
|
||||
int exitCode = JLINK_TOOL.run(pw, pw, args);
|
||||
return new Result(exitCode, writer.toString(), output);
|
||||
}
|
||||
}
|
||||
|
||||
public static class InMemorySourceFile {
|
||||
|
Loading…
Reference in New Issue
Block a user