langtools/test/tools/javac/file/ExplodedImage.java
author jjg
Thu, 31 Mar 2016 15:20:50 -0700
changeset 36778 e04318f39f92
parent 36526 3b41f1c69604
child 36991 7f814aac1f80
permissions -rw-r--r--
8152897: refactor ToolBox to allow reduced documented dependencies Reviewed-by: vromero
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
29053
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
     1
/*
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
     2
 * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
29053
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
     4
 *
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
     7
 * published by the Free Software Foundation.
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
     8
 *
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
    13
 * accompanied this code).
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
    14
 *
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
    18
 *
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
    21
 * questions.
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
    22
 */
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
    23
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    24
/**
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    25
 * @test
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    26
 * @bug 8067138
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    27
 * @summary Verify that compiling against the exploded JDK image works, and that Locations close
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    28
 *          the directory streams properly when working with exploded JDK image.
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    29
 * @library /tools/lib
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    30
 * @modules jdk.compiler/com.sun.tools.javac.api
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    31
 *          jdk.compiler/com.sun.tools.javac.code
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    32
 *          jdk.compiler/com.sun.tools.javac.main
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    33
 *          jdk.jdeps/com.sun.tools.javap
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    34
 * @build toolbox.ToolBox ExplodedImage
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    35
 * @run main/othervm ExplodedImage modules/* testDirectoryStreamClosed
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    36
 * @run main/othervm ExplodedImage modules/* testCanCompileAgainstExplodedImage
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    37
 */
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    38
29053
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
    39
import java.io.File;
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
    40
import java.io.IOException;
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
    41
import java.io.InputStream;
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
    42
import java.net.URI;
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
    43
import java.nio.file.DirectoryStream;
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
    44
import java.nio.file.FileSystems;
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
    45
import java.nio.file.Files;
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
    46
import java.nio.file.Path;
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
    47
import java.util.Arrays;
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
    48
import java.util.EnumSet;
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
    49
import java.util.List;
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
    50
import javax.lang.model.element.TypeElement;
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
    51
import javax.tools.Diagnostic;
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
    52
import javax.tools.DiagnosticListener;
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
    53
import javax.tools.JavaCompiler;
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
    54
import javax.tools.JavaFileObject;
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
    55
import javax.tools.StandardJavaFileManager;
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
    56
import javax.tools.StandardLocation;
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
    57
import javax.tools.ToolProvider;
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
    58
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    59
import com.sun.source.util.JavacTask;
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    60
import com.sun.tools.javac.code.Symbol.ClassSymbol;
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    61
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    62
import toolbox.ToolBox;
29053
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
    63
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
    64
public class ExplodedImage {
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
    65
    public static void main(String... args) throws IOException {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30730
diff changeset
    66
        new ExplodedImage().run(args);
29053
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
    67
    }
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
    68
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30730
diff changeset
    69
    void run(String... args) throws IOException {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30730
diff changeset
    70
        switch (args[0]) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30730
diff changeset
    71
            case "testDirectoryStreamClosed":
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30730
diff changeset
    72
                testDirectoryStreamClosed(args[1]);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30730
diff changeset
    73
                break;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30730
diff changeset
    74
            case "testCanCompileAgainstExplodedImage":
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30730
diff changeset
    75
                testCanCompileAgainstExplodedImage(args[1]);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30730
diff changeset
    76
                break;
29053
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
    77
        }
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
    78
    }
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
    79
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
    80
    void testDirectoryStreamClosed(String loc) throws IOException {
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
    81
        System.err.println("testDirectoryStreamClosed(" + loc + ")");
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
    82
        Path javaHome = prepareJavaHome();
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
    83
        Path targetPath = javaHome.resolve(loc.replace("*", "/java.base").replace("/", sep));
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
    84
        Path testClass = targetPath.resolve(("java/lang/" + TEST_FILE).replace("/", sep));
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
    85
        Files.createDirectories(testClass.getParent());
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
    86
        Files.createFile(testClass);
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
    87
        System.setProperty("java.home", javaHome.toString());
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
    88
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
    89
        for (int i = 0; i < REPEATS; i++) {
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
    90
            try (StandardJavaFileManager fm = javaCompiler.getStandardFileManager(null, null, null)) {
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
    91
                Iterable<JavaFileObject> javaLangContent =
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
    92
                        fm.list(StandardLocation.PLATFORM_CLASS_PATH,
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
    93
                                "java.lang",
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
    94
                                EnumSet.allOf(JavaFileObject.Kind.class),
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
    95
                                false);
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
    96
                boolean found = false;
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
    97
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
    98
                for (JavaFileObject fo : javaLangContent) {
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
    99
                    if (!fo.getName().endsWith(TEST_FILE)) {
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   100
                        throw new IllegalStateException("Wrong file: " + fo);
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   101
                    }
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   102
                    found = true;
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   103
                }
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   104
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   105
                if (!found)
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   106
                    throw new IllegalStateException("Could not find the expected file!");
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   107
            }
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   108
        }
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   109
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   110
        System.err.println("finished.");
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   111
    }
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   112
    //where:
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   113
        static final String TEST_FILE = "ExplodedImageTestFile.class";
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   114
        static final int REPEATS = 16 * 1024 + 1;
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   115
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   116
    void testCanCompileAgainstExplodedImage(String loc) throws IOException {
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   117
        System.err.println("testCanCompileAgainstExplodedImage(" + loc + ")");
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   118
        Path javaHome = prepareJavaHome();
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   119
        Path targetPath = javaHome.resolve(loc.replace("*", "/java.base").replace("/", sep));
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   120
        try (StandardJavaFileManager fm = javaCompiler.getStandardFileManager(null, null, null)) {
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   121
            for (String pack : REQUIRED_PACKAGES) {
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   122
                Iterable<JavaFileObject> content = fm.list(StandardLocation.PLATFORM_CLASS_PATH,
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   123
                                                           pack,
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   124
                                                           EnumSet.allOf(JavaFileObject.Kind.class),
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   125
                                                           false);
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   126
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   127
                for (JavaFileObject jfo : content) {
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   128
                    String name = jfo.getName();
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   129
                    int lastSlash = name.lastIndexOf('/');
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   130
                    name = lastSlash >= 0 ? name.substring(lastSlash + 1) : name;
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   131
                    Path target = targetPath.resolve(pack.replace(".", sep) + sep + name);
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   132
                    Files.createDirectories(target.getParent());
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   133
                    try (InputStream in = jfo.openInputStream()) {
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   134
                        Files.copy(in, target);
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   135
                    }
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   136
                }
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   137
            }
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   138
        }
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   139
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   140
        System.setProperty("java.home", javaHome.toString());
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   141
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   142
        try (StandardJavaFileManager fm = javaCompiler.getStandardFileManager(null, null, null)) {
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   143
            DiagnosticListener<JavaFileObject> noErrors = d -> {
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   144
                if (d.getKind() == Diagnostic.Kind.ERROR)
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   145
                    throw new IllegalStateException("Unexpected error: " + d);
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   146
            };
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   147
            ToolBox.JavaSource inputFile =
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   148
                    new ToolBox.JavaSource("import java.util.List; class Test { List l; }");
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   149
            List<JavaFileObject> inputFiles = Arrays.asList(inputFile);
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   150
            boolean result =
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   151
                    javaCompiler.getTask(null, fm, noErrors, null, null, inputFiles).call();
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   152
            if (!result) {
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   153
                throw new IllegalStateException("Could not compile correctly!");
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   154
            }
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   155
            JavacTask task =
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   156
                    (JavacTask) javaCompiler.getTask(null, fm, noErrors, null, null, inputFiles);
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   157
            task.parse();
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   158
            TypeElement juList = task.getElements().getTypeElement("java.util.List");
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   159
            if (juList == null)
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   160
                throw new IllegalStateException("Cannot resolve java.util.List!");
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   161
            URI listSource = ((ClassSymbol) juList).classfile.toUri();
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   162
            if (!listSource.toString().startsWith(javaHome.toUri().toString()))
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   163
                throw new IllegalStateException(  "Did not load java.util.List from correct place, " +
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   164
                                                  "actual location: " + listSource.toString() +
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   165
                                                "; expected prefix: " + javaHome.toUri());
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   166
        }
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   167
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   168
        System.err.println("finished.");
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   169
    }
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   170
    //where:
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   171
        static final String[] REQUIRED_PACKAGES = {"java.lang", "java.io", "java.util"};
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   172
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   173
    Path prepareJavaHome() throws IOException {
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   174
        Path javaHome = new File("javahome").getAbsoluteFile().toPath();
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   175
        delete(javaHome);
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   176
        Files.createDirectory(javaHome);
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   177
        return javaHome;
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   178
    }
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   179
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   180
    String sep = FileSystems.getDefault().getSeparator();
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   181
    JavaCompiler javaCompiler = ToolProvider.getSystemJavaCompiler();
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   182
    String originalJavaHome = System.getProperty("java.home");
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   183
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   184
    void delete(Path p) throws IOException {
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   185
        if (!Files.exists(p))
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   186
            return ;
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   187
        if (Files.isDirectory(p)) {
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   188
            try (DirectoryStream<Path> dir = Files.newDirectoryStream(p)) {
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   189
                for (Path child : dir) {
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   190
                    delete(child);
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   191
                }
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   192
            }
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   193
        }
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   194
        Files.delete(p);
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   195
    }
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
diff changeset
   196
}