8154090: Remove support for jimage recreate
authorjlaskey
Mon, 25 Apr 2016 09:57:55 -0300
changeset 37615 d4486cdacf4e
parent 37614 99a3cdeb43a7
child 37616 d7794846510d
8154090: Remove support for jimage recreate Reviewed-by: alanb
jdk/src/jdk.jlink/share/classes/jdk/tools/jimage/ExtractedImage.java
jdk/src/jdk.jlink/share/classes/jdk/tools/jimage/JImageTask.java
jdk/src/jdk.jlink/share/classes/jdk/tools/jimage/resources/jimage.properties
jdk/test/tools/jimage/JImageTest.java
jdk/test/tools/jimage/JImageToolTest.java
jdk/test/tools/lib/tests/JImageGenerator.java
--- a/jdk/src/jdk.jlink/share/classes/jdk/tools/jimage/ExtractedImage.java	Mon Apr 25 09:57:55 2016 -0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,78 +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.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * 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.
- */
-package jdk.tools.jimage;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
-import java.util.function.Consumer;
-import jdk.tools.jlink.internal.ImageFileCreator;
-import jdk.tools.jlink.internal.Archive;
-import jdk.tools.jlink.internal.ImagePluginStack;
-import jdk.tools.jlink.internal.DirArchive;
-/**
- *
- * Support for extracted image.
- */
-public final class ExtractedImage {
-
-    private Set<Archive> archives = new HashSet<>();
-    private final ImagePluginStack plugins;
-
-    ExtractedImage(Path dirPath, ImagePluginStack plugins, PrintWriter log,
-            boolean verbose) throws IOException {
-        if (!Files.isDirectory(dirPath)) {
-            throw new IOException("Not a directory");
-        }
-        Consumer<String> cons = (String t) -> {
-            if (verbose) {
-                log.println(t);
-            }
-        };
-        this.plugins = plugins;
-        Files.walk(dirPath, 1).forEach((p) -> {
-            if (!dirPath.equals(p)) {
-                if (Files.isDirectory(p)) {
-                    Archive a = new DirArchive(p, cons);
-                    archives.add(a);
-                }
-            }
-        });
-        archives = Collections.unmodifiableSet(archives);
-    }
-
-    void recreateJImage(Path path) throws IOException {
-        ImageFileCreator.recreateJimage(path, archives, plugins);
-    }
-
-    private static String getPathName(Path path) {
-        return path.toString().replace(File.separatorChar, '/');
-    }
-}
--- a/jdk/src/jdk.jlink/share/classes/jdk/tools/jimage/JImageTask.java	Mon Apr 25 09:57:55 2016 -0300
+++ b/jdk/src/jdk.jlink/share/classes/jdk/tools/jimage/JImageTask.java	Mon Apr 25 09:57:55 2016 -0300
@@ -32,7 +32,6 @@
 import java.nio.ByteOrder;
 import java.nio.channels.FileChannel;
 import java.nio.file.Files;
-import java.nio.file.Path;
 import static java.nio.file.StandardOpenOption.READ;
 import static java.nio.file.StandardOpenOption.WRITE;
 import java.util.LinkedList;
@@ -44,8 +43,6 @@
 import static jdk.internal.jimage.ImageHeader.MINOR_VERSION;
 import jdk.internal.jimage.ImageLocation;
 import jdk.tools.jlink.internal.ImageResourcesTree;
-import jdk.tools.jlink.internal.ImagePluginConfiguration;
-import jdk.tools.jlink.internal.ImagePluginStack;
 import jdk.tools.jlink.internal.TaskHelper;
 import jdk.tools.jlink.internal.TaskHelper.BadArgs;
 import static jdk.tools.jlink.internal.TaskHelper.JIMAGE_BUNDLE;
@@ -97,7 +94,6 @@
         EXTRACT,
         INFO,
         LIST,
-        RECREATE,
         SET,
         VERIFY
     };
@@ -160,18 +156,20 @@
         try {
             List<String> unhandled = optionsHelper.handleOptions(this, args);
             if(!unhandled.isEmpty()) {
-                options.task = Enum.valueOf(Task.class, unhandled.get(0).toUpperCase());
+                try {
+                    options.task = Enum.valueOf(Task.class, unhandled.get(0).toUpperCase());
+                } catch (IllegalArgumentException ex) {
+                    throw taskHelper.newBadArgs("err.not.a.task", unhandled.get(0));
+                }
                 for(int i = 1; i < unhandled.size(); i++) {
                     options.jimages.add(new File(unhandled.get(i)));
                 }
+            } else {
+                throw taskHelper.newBadArgs("err.not.a.task", "<unspecified>");
             }
             if (options.help) {
                 optionsHelper.showHelp(PROGNAME);
             }
-            if(optionsHelper.listPlugins()) {
-                optionsHelper.listPlugins(true);
-                return EXIT_OK;
-            }
             if (options.version || options.fullVersion) {
                 taskHelper.showVersion(options.fullVersion);
             }
@@ -191,30 +189,6 @@
         }
     }
 
-    private void recreate() throws Exception, BadArgs {
-        File directory = new File(options.directory);
-        if (!directory.isDirectory()) {
-            throw taskHelper.newBadArgs("err.not.a.dir", directory.getAbsolutePath());
-        }
-        Path dirPath = directory.toPath();
-        if (options.jimages.isEmpty()) {
-            throw taskHelper.newBadArgs("err.jimage.not.specified");
-        } else if (options.jimages.size() != 1) {
-            throw taskHelper.newBadArgs("err.only.one.jimage");
-        }
-
-        Path jimage = options.jimages.get(0).toPath();
-
-        if (jimage.toFile().createNewFile()) {
-            ImagePluginStack pc = ImagePluginConfiguration.parseConfiguration(taskHelper.
-                    getPluginsConfig(null, false));
-            ExtractedImage img = new ExtractedImage(dirPath, pc, log, options.verbose);
-            img.recreateJImage(jimage);
-        } else {
-            throw taskHelper.newBadArgs("err.jimage.already.exists", jimage.getFileName());
-        }
-    }
-
     private void title(File file, BasicImageReader reader) {
         log.println("jimage: " + file.getName());
     }
@@ -379,9 +353,6 @@
             case LIST:
                 iterate(this::listTitle, this::list);
                 break;
-            case RECREATE:
-                recreate();
-                break;
             case SET:
                 iterate(this::set, null);
                 break;
--- a/jdk/src/jdk.jlink/share/classes/jdk/tools/jimage/resources/jimage.properties	Mon Apr 25 09:57:55 2016 -0300
+++ b/jdk/src/jdk.jlink/share/classes/jdk/tools/jimage/resources/jimage.properties	Mon Apr 25 09:57:55 2016 -0300
@@ -1,30 +1,25 @@
 main.usage.summary=\
-Usage: {0} <extract|info|list|recreate|set|verify> <options> jimage...\n\
+Usage: {0} <extract|info|list|set|verify> <options> jimage...\n\
 use --help for a list of possible options
 
 main.usage=\
-Usage: {0} <extract|info|list|recreate|set|verify> <options> jimage...\n\
+Usage: {0} <extract|info|list|set|verify> <options> jimage...\n\
 \n\
 \  extract  - Extract all jimage entries into separate files into the directory\n\
 \             specified by --dir=<directory> (default='.')\n\
 \  info     - Prints information specified in the jimage header.\n\
 \  list     - Prints the names of all the entries in the jimage.  When used with\n\
 \             --verbose will also print entry attributes ex. size and offset.\n\
-\  recreate - Reconstructs a jimage from an extracted directory (--dir)\n\
 \  set      - sets the value of specific jimage header entries\n\
 \  verify   - Reports errors on any .class entries that don't verify as classes.\n\
 \n\
 Possible options include:
 
-main.extended.help=\
-jimage recreate is extensible by the main of plugins. Following plugins have been discovered \
-thanks to ServiceLoader and can be used when re-creating a jimage.
-
 error.prefix=Error:
 warn.prefix=Warning:
 
 main.opt.dir=\
-\  --dir                                Target directory for extract/recreate
+\  --dir                                Target directory for extract
 
 main.opt.flags=\
 \  --flags=value                        Set the jimage flags to value
@@ -38,14 +33,8 @@
 main.opt.version=\
 \  --version                            Version information
 
-main.opt.configuration=\
-\  --configuration <path>               Path to properties file containing defaults\
-\ options for recreate
-
 main.command.files=\
 \  @<filename>                          Read options from file
-
-err.cannot.create.dir=cannot create directory: {0}
 err.cannot.read.file=cannot read file: {0}
 err.cannot.update.file=cannot update file: {0}
 err.file.not.found=cannot find file: {0}
@@ -53,12 +42,10 @@
 err.flags.not.int=--flags value not integer: {0}
 err.internal.error=internal error: {0} {1} {2}
 err.invalid.arg.for.option=invalid argument for option: {0}
-err.invalid.task=task must be extract|recreate|info|list|verify: {0}
-err.jimage.already.exists=jimage already exists: {0}
-err.jimage.not.specified=no jimage specified
+err.invalid.task=task must be extract|info|list|verify: {0}
 err.missing.arg=no value given for {0}
 err.not.a.dir=not a directory: {0}
 err.not.a.jimage=not a jimage file: {0}
-err.only.one.jimage=only one jimage should be specified
+err.not.a.task=not a valid task: {0}
 err.option.unsupported={0} not supported: {1}
 err.unknown.option=unknown option: {0}
--- a/jdk/test/tools/jimage/JImageTest.java	Mon Apr 25 09:57:55 2016 -0300
+++ b/jdk/test/tools/jimage/JImageTest.java	Mon Apr 25 09:57:55 2016 -0300
@@ -110,54 +110,5 @@
                 .dir(helper.createNewExtractedDir("modules"))
                 .image(image.resolve("lib").resolve("modules"))
                 .extract().assertSuccess();
-
-        Path recreatedImage = JImageGenerator.getJImageTask()
-                .dir(extractedDir)
-                .image(helper.createNewRecreatedDir(extractedDir.getFileName().toString()))
-                .recreate().assertSuccess();
-        JImageValidator.validate(recreatedImage, bootClasses, Collections.emptyList());
-
-        // Check replacing the boot image by recreated one
-        Path destFile = image.resolve("lib").resolve("modules");
-        Files.copy(recreatedImage, destFile, REPLACE_EXISTING);
-        JImageValidator validator = new JImageValidator(module, Collections.emptyList(),
-                image.toFile(), Collections.emptyList(), Collections.emptyList());
-        validator.validate();
-
-        Path recreatedImage2 = JImageGenerator.getJImageTask()
-                .dir(extractedDir)
-                .option("--compress").option("2")
-                .image(helper.createNewRecreatedDir(extractedDir.getFileName().toString()))
-                .recreate().assertSuccess();
-        JImageValidator.validate(recreatedImage2, bootClasses, Collections.emptyList());
-
-        Path recreatedImage3 = JImageGenerator.getJImageTask()
-                .dir(extractedDir)
-                .option("--strip-debug")
-                .image(helper.createNewRecreatedDir(extractedDir.getFileName().toString()))
-                .recreate().assertSuccess();
-        JImageValidator.validate(recreatedImage3, bootClasses, Collections.emptyList());
-
-        Path recreatedImage4 = JImageGenerator.getJImageTask()
-                .dir(extractedDir)
-                .option("--exclude-resources")
-                .option("*.jcov, */META-INF/*")
-                .image(helper.createNewRecreatedDir(extractedDir.getFileName().toString()))
-                .recreate().assertSuccess();
-        List<String> unexpectedPaths = new ArrayList<>();
-        unexpectedPaths.add(".jcov");
-        unexpectedPaths.add("/META-INF/");
-        JImageValidator.validate(recreatedImage4, bootClasses, unexpectedPaths);
-
-        Path recreatedImage5 = JImageGenerator.getJImageTask()
-                .dir(extractedDir)
-                .option("--compress")
-                .option("2")
-                .option("--strip-debug")
-                .option("--exclude-resources")
-                .option("*.jcov, */META-INF/*")
-                .image(helper.createNewRecreatedDir(extractedDir.getFileName().toString()))
-                .recreate().assertSuccess();
-        JImageValidator.validate(recreatedImage5, bootClasses, unexpectedPaths);
     }
 }
--- a/jdk/test/tools/jimage/JImageToolTest.java	Mon Apr 25 09:57:55 2016 -0300
+++ b/jdk/test/tools/jimage/JImageToolTest.java	Mon Apr 25 09:57:55 2016 -0300
@@ -63,11 +63,7 @@
             String jimage = jimagePath.toAbsolutePath().toString();
             String bootimage = modulesimagePath.toAbsolutePath().toString();
             String extractDir = Paths.get(".", "extract").toAbsolutePath().toString();
-            String recreateImage = Paths.get(".", "recreate").toAbsolutePath().toString();
-            String relativeRecreateImage = Paths.get(".", "recreate2").toString();
             jimage("extract", "--dir", extractDir, bootimage);
-            jimage("recreate", "--dir", extractDir, recreateImage);
-            jimage("recreate", "--dir", extractDir, relativeRecreateImage);
             System.out.println("Test successful");
          } else {
             System.out.println("Test skipped, not an images build");
--- a/jdk/test/tools/lib/tests/JImageGenerator.java	Mon Apr 25 09:57:55 2016 -0300
+++ b/jdk/test/tools/lib/tests/JImageGenerator.java	Mon Apr 25 09:57:55 2016 -0300
@@ -553,10 +553,6 @@
         public Result extract() {
             return cmd("extract", dir);
         }
-
-        public Result recreate() {
-            return cmd("recreate", image);
-        }
     }
 
     public static class JLinkTask {