jdk/src/jdk.jlink/share/classes/jdk/tools/jimage/ExtractedImage.java
changeset 37713 a3c34538726f
parent 37712 a34269e72fe1
parent 37646 84aba7335005
child 37714 7a0b1c7e7054
equal deleted inserted replaced
37712:a34269e72fe1 37713:a3c34538726f
     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.jimage;
       
    26 
       
    27 import java.io.File;
       
    28 import java.io.IOException;
       
    29 import java.io.PrintWriter;
       
    30 import java.nio.file.Files;
       
    31 import java.nio.file.Path;
       
    32 import java.util.Collections;
       
    33 import java.util.HashSet;
       
    34 import java.util.Set;
       
    35 import java.util.function.Consumer;
       
    36 import jdk.tools.jlink.internal.ImageFileCreator;
       
    37 import jdk.tools.jlink.internal.Archive;
       
    38 import jdk.tools.jlink.internal.ImagePluginStack;
       
    39 import jdk.tools.jlink.internal.DirArchive;
       
    40 /**
       
    41  *
       
    42  * Support for extracted image.
       
    43  */
       
    44 public final class ExtractedImage {
       
    45 
       
    46     private Set<Archive> archives = new HashSet<>();
       
    47     private final ImagePluginStack plugins;
       
    48 
       
    49     ExtractedImage(Path dirPath, ImagePluginStack plugins, PrintWriter log,
       
    50             boolean verbose) throws IOException {
       
    51         if (!Files.isDirectory(dirPath)) {
       
    52             throw new IOException("Not a directory");
       
    53         }
       
    54         Consumer<String> cons = (String t) -> {
       
    55             if (verbose) {
       
    56                 log.println(t);
       
    57             }
       
    58         };
       
    59         this.plugins = plugins;
       
    60         Files.walk(dirPath, 1).forEach((p) -> {
       
    61             if (!dirPath.equals(p)) {
       
    62                 if (Files.isDirectory(p)) {
       
    63                     Archive a = new DirArchive(p, cons);
       
    64                     archives.add(a);
       
    65                 }
       
    66             }
       
    67         });
       
    68         archives = Collections.unmodifiableSet(archives);
       
    69     }
       
    70 
       
    71     void recreateJImage(Path path) throws IOException {
       
    72         ImageFileCreator.recreateJimage(path, archives, plugins);
       
    73     }
       
    74 
       
    75     private static String getPathName(Path path) {
       
    76         return path.toString().replace(File.separatorChar, '/');
       
    77     }
       
    78 }