test/jdk/tools/launcher/MultipleJRERemoved.java
author mr
Wed, 16 Jan 2019 16:27:21 -0800
changeset 53372 4003935e6e5f
parent 47216 71c04702a3d5
permissions -rw-r--r--
8216532: tools/launcher/Test7029048.java fails (Solaris) Reviewed-by: rriggs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
28424
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
     1
/*
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
     2
 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
     4
 *
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
     7
 * published by the Free Software Foundation.
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
     8
 *
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    13
 * accompanied this code).
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    14
 *
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    18
 *
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    21
 * questions.
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    22
 */
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    23
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    24
/**
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    25
 * @test
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    26
 * @bug 8067437
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    27
 * @summary Verify Multiple JRE version support has been removed.
45944
882cea808912 8179292: a number of launcher tests fail when run with --limit-modules due to CNFE: javax.tools.ToolProvider
anazarov
parents: 28424
diff changeset
    28
 * @modules jdk.compiler
882cea808912 8179292: a number of launcher tests fail when run with --limit-modules due to CNFE: javax.tools.ToolProvider
anazarov
parents: 28424
diff changeset
    29
 *          jdk.zipfs
28424
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    30
 * @build TestHelper
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    31
 * @run main MultipleJRERemoved
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    32
 */
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    33
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    34
import java.io.File;
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    35
import java.io.FileOutputStream;
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    36
import java.io.IOException;
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    37
import java.nio.file.Files;
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    38
import java.util.*;
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    39
import java.util.jar.Attributes;
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    40
import java.util.jar.JarOutputStream;
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    41
import java.util.jar.Manifest;
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    42
import java.util.regex.Pattern;
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    43
import java.util.stream.Collectors;
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    44
import java.util.stream.Stream;
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    45
import java.util.zip.ZipEntry;
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    46
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    47
public class MultipleJRERemoved extends TestHelper {
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    48
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    49
    public static final String VERSION_JAR = "version.jar";
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    50
    public static final String PRINT_VERSION_CLASS = "PrintVersion";
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    51
    private final File javaFile = new File(PRINT_VERSION_CLASS + ".java");
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    52
    private final File clsFile = new File(PRINT_VERSION_CLASS + ".class");
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    53
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    54
    private MultipleJRERemoved() {
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    55
    }
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    56
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    57
    /**
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    58
     * @param args the command line arguments
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    59
     * @throws java.io.FileNotFoundException
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    60
     */
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    61
    public static void main(String[] args) throws Exception {
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    62
        MultipleJRERemoved a = new MultipleJRERemoved();
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    63
        a.run(args);
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    64
    }
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    65
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    66
    /**
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    67
     * Check all combinations of flags: "-version:", "-jre-restrict-search", "-jre-no-restrict-search". Test expects to see errors.
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    68
     */
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    69
    @Test
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    70
    public void allFlagCombinations() throws IOException {
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    71
        final Pattern newLine = Pattern.compile("\n");
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    72
        createJar(Collections.emptyMap());
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    73
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    74
        for (Flag flag1 : Flag.values()) {
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    75
            for (Flag flag2 : Flag.values()) {
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    76
                for (Flag flag3 : Flag.values()) {
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    77
                    List<Flag> flags = Stream.of(flag1, flag2, flag3)
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    78
                            .filter(f -> !Flag.EMPTY.equals(f))
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    79
                            .collect(Collectors.toList());
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    80
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    81
                    if (flags.size() == 0) continue;
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    82
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    83
                    List<String> flagValues = flags.stream()
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    84
                            .map(Flag::value)
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    85
                            .collect(Collectors.toList());
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    86
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    87
                    List<String> errorMessages = flags.stream()
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    88
                            .map(Flag::errorMessage)
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    89
                            .flatMap(newLine::splitAsStream)
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    90
                            .collect(Collectors.toList());
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    91
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    92
                    List<String> jarCmd = new ArrayList<>();
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    93
                    jarCmd.add(javaCmd);
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    94
                    jarCmd.addAll(flagValues);
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    95
                    jarCmd.add("-jar");
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    96
                    jarCmd.add("version.jar");
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    97
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    98
                    check(jarCmd, errorMessages);
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
    99
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   100
                    List<String> cmd = new ArrayList<>();
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   101
                    cmd.add(javaCmd);
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   102
                    cmd.addAll(flagValues);
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   103
                    cmd.add(PRINT_VERSION_CLASS);
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   104
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   105
                    check(cmd, errorMessages);
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   106
                }
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   107
            }
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   108
        }
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   109
    }
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   110
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   111
    private void check(List<String> cmd, List<String> errorMessages) {
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   112
        TestResult tr = doExec(cmd.toArray(new String[cmd.size()]));
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   113
        tr.checkNegative();
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   114
        tr.isNotZeroOutput();
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   115
        errorMessages.forEach(tr::contains);
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   116
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   117
        if (!tr.testStatus) {
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   118
            System.out.println(tr);
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   119
            throw new RuntimeException("test case: failed\n" + cmd);
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   120
        }
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   121
    }
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   122
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   123
    /**
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   124
     * Verifies that java -help output doesn't contain information about "mJRE" flags.
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   125
     */
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   126
    @Test
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   127
    public void javaHelp() {
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   128
        TestResult tr = doExec(javaCmd, "-help");
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   129
        tr.checkPositive();
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   130
        tr.isNotZeroOutput();
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   131
        tr.notContains("-version:<value>");
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   132
        tr.notContains("-jre-restrict-search");
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   133
        tr.notContains("-jre-no-restrict-search");
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   134
        tr.notContains("-no-jre-restrict-search");  //it's not a typo in flag name.
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   135
        if (!tr.testStatus) {
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   136
            System.out.println(tr);
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   137
            throw new RuntimeException("Failed. java -help output contains obsolete flags.\n");
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   138
        }
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   139
    }
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   140
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   141
    /**
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   142
     * Verifies that java -jar version.jar output ignores "mJRE" manifest directives.
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   143
     */
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   144
    @Test
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   145
    public void manifestDirectives() throws IOException {
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   146
        Map<String, String> manifest = new TreeMap<>();
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   147
        manifest.put("JRE-Version", "1.8");
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   148
        manifest.put("JRE-Restrict-Search", "1.8");
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   149
        createJar(manifest);
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   150
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   151
        TestResult tr = doExec(javaCmd, "-jar", VERSION_JAR);
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   152
        tr.checkPositive();
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   153
        tr.contains(System.getProperty("java.version"));
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   154
        if (!tr.testStatus) {
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   155
            System.out.println(tr);
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   156
            throw new RuntimeException("Failed.\n");
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   157
        }
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   158
    }
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   159
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   160
    private void emitFile() throws IOException {
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   161
        List<String> scr = new ArrayList<>();
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   162
        scr.add("public class PrintVersion {");
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   163
        scr.add("    public static void main(String... args) {");
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   164
        scr.add("       System.out.println(System.getProperty(\"java.version\"));");
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   165
        scr.add("    }");
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   166
        scr.add("}");
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   167
        createFile(javaFile, scr);
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   168
        compile(javaFile.getName());
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   169
    }
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   170
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   171
    private void createJar(Map<String, String> manifestAttributes) throws IOException {
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   172
        emitFile();
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   173
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   174
        Manifest manifest = new Manifest();
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   175
        final Attributes mainAttributes = manifest.getMainAttributes();
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   176
        mainAttributes.putValue("Manifest-Version", "1.0");
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   177
        mainAttributes.putValue("Main-Class", PRINT_VERSION_CLASS);
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   178
        manifestAttributes.forEach(mainAttributes::putValue);
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   179
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   180
        try (JarOutputStream jar = new JarOutputStream(new FileOutputStream(VERSION_JAR), manifest)) {
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   181
            jar.putNextEntry(new ZipEntry(PRINT_VERSION_CLASS + ".class"));
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   182
            jar.write(Files.readAllBytes(clsFile.toPath()));
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   183
            jar.closeEntry();
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   184
        } finally {
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   185
            javaFile.delete();
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   186
        }
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   187
    }
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   188
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   189
    private enum Flag {
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   190
        EMPTY("", ""),
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   191
        VERSION("-version:1.9", "Error: Specifying an alternate JDK/JRE version is no longer supported.\n" +
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   192
                "The use of the flag '-version:' is no longer valid.\n" +
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   193
                "Please download and execute the appropriate version."),
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   194
        JRE_RESTRICT_SEARCH("-jre-restrict-search", "Error: Specifying an alternate JDK/JRE is no longer supported.\n" +
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   195
                "The related flags -jre-restrict-search | -jre-no-restrict-search are also no longer valid."),
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   196
        JRE_NO_RESTRICT_SEARCH("-jre-no-restrict-search", "Error: Specifying an alternate JDK/JRE is no longer supported.\n" +
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   197
                "The related flags -jre-restrict-search | -jre-no-restrict-search are also no longer valid.");
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   198
        private final String flag;
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   199
        private final String errorMessage;
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   200
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   201
        Flag(String flag, String errorMessage) {
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   202
            this.flag = flag;
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   203
            this.errorMessage = errorMessage;
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   204
        }
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   205
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   206
        String value() {
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   207
            return flag;
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   208
        }
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   209
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   210
        String errorMessage() {
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   211
            return errorMessage;
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   212
        }
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   213
    }
3e9d7d7dd362 8067437: New tests for mJRE feature removal.
ksrini
parents:
diff changeset
   214
}