make/langtools/test/sym/CreateSymbolsTest.java
author coleenp
Tue, 31 Oct 2017 11:55:09 -0400
changeset 47765 b7c7428eaab9
parent 47216 71c04702a3d5
permissions -rw-r--r--
8189610: Reconcile jvm.h and all jvm_md.h between java.base and hotspot Summary: Removed hotspot version of jvm*h and jni*h files. Reviewed-by: ihse, mchung, dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
31506
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
     1
/*
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
     4
 *
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
     7
 * published by the Free Software Foundation.
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
     8
 *
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    13
 * accompanied this code).
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    14
 *
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    18
 *
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    21
 * questions.
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    22
 */
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    23
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    24
/**
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    25
 * @test
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    26
 * @bug 8072480
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    27
 * @summary Unit test for CreateSymbols
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    28
 * @clean *
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    29
 * @run main CreateSymbolsTest
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    30
 */
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    31
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    32
import java.io.IOException;
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    33
import java.net.URL;
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    34
import java.net.URLClassLoader;
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    35
import java.nio.file.FileVisitResult;
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    36
import java.nio.file.FileVisitor;
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    37
import java.nio.file.Files;
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    38
import java.nio.file.Path;
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    39
import java.nio.file.Paths;
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    40
import java.nio.file.attribute.BasicFileAttributes;
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    41
import java.util.Arrays;
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    42
import javax.tools.JavaCompiler;
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    43
import javax.tools.StandardJavaFileManager;
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    44
import javax.tools.ToolProvider;
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    45
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    46
public class CreateSymbolsTest {
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    47
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    48
    static final String CREATE_SYMBOLS_NAME = "symbolgenerator.CreateSymbols";
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    49
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    50
    public static void main(String... args) throws Exception {
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    51
        new CreateSymbolsTest().doRun();
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    52
    }
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    53
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    54
    void doRun() throws Exception {
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    55
        Path testClasses = Paths.get(System.getProperty("test.classes"));
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    56
        Path compileDir = testClasses.resolve("data");
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    57
        deleteRecursively(compileDir);
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    58
        Files.createDirectories(compileDir);
33551
1cd3c95fb546 8140766: langtools/make/test/sym/CreateSymbolsTest.java contains incorrect paths
jlahoda
parents: 31506
diff changeset
    59
        Path createSymbols = findFile("../../make/src/classes/build/tools/symbolgenerator/CreateSymbols.java");
31506
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    60
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    61
        if (createSymbols == null) {
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    62
            System.err.println("Warning: cannot find CreateSymbols, skipping.");
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    63
            return ;
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    64
        }
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    65
33551
1cd3c95fb546 8140766: langtools/make/test/sym/CreateSymbolsTest.java contains incorrect paths
jlahoda
parents: 31506
diff changeset
    66
        Path createTestImpl = findFile("../../make/test/sym/CreateSymbolsTestImpl.java");
31506
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    67
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    68
        if (createTestImpl == null) {
33551
1cd3c95fb546 8140766: langtools/make/test/sym/CreateSymbolsTest.java contains incorrect paths
jlahoda
parents: 31506
diff changeset
    69
            System.err.println("Warning: cannot find CreateSymbolsTestImpl, skipping.");
31506
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    70
            return ;
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    71
        }
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    72
33551
1cd3c95fb546 8140766: langtools/make/test/sym/CreateSymbolsTest.java contains incorrect paths
jlahoda
parents: 31506
diff changeset
    73
        Path toolBox = findFile("../../test/tools/lib/ToolBox.java");
31506
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    74
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    75
        if (toolBox == null) {
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    76
            System.err.println("Warning: cannot find ToolBox, skipping.");
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    77
            return ;
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    78
        }
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    79
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    80
        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    81
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    82
        try (StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null)) {
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    83
            compiler.getTask(null,
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    84
                             null,
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    85
                             null,
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    86
                             Arrays.asList("-d", compileDir.toAbsolutePath().toString()),
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    87
                             null,
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    88
                             fm.getJavaFileObjects(createSymbols, createTestImpl, toolBox)
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    89
                            ).call();
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    90
        }
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    91
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    92
        URLClassLoader cl = new URLClassLoader(new URL[] {testClasses.toUri().toURL(), compileDir.toUri().toURL()});
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    93
        Class<?> createSymbolTest = cl.loadClass("CreateSymbolsTestImpl");
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    94
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    95
        createSymbolTest.getMethod("main", String[].class).invoke(null, (Object) new String[0]);
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    96
    }
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    97
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    98
    Path findFile(String path) {
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
    99
        Path testSrc = Paths.get(System.getProperty("test.src", "."));
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
   100
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
   101
        for (Path d = testSrc; d != null; d = d.getParent()) {
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
   102
            if (Files.exists(d.resolve("TEST.ROOT"))) {
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
   103
                Path createSymbols = d.resolve(path);
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
   104
                if (Files.exists(createSymbols)) {
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
   105
                    return createSymbols;
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
   106
                }
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
   107
            }
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
   108
        }
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
   109
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
   110
        return null;
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
   111
    }
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
   112
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
   113
    void deleteRecursively(Path dir) throws IOException {
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
   114
        Files.walkFileTree(dir, new FileVisitor<Path>() {
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
   115
            @Override
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
   116
            public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
   117
                return FileVisitResult.CONTINUE;
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
   118
            }
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
   119
            @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
   120
                Files.delete(file);
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
   121
                return FileVisitResult.CONTINUE;
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
   122
            }
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
   123
            @Override public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
   124
                return FileVisitResult.CONTINUE;
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
   125
            }
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
   126
            @Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
   127
                Files.delete(dir);
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
   128
                return FileVisitResult.CONTINUE;
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
   129
            }
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
   130
        });
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
   131
    }
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff changeset
   132
}