jdk/test/tools/launcher/VersionCheck.java
author prr
Tue, 01 Jul 2014 10:20:56 -0700
changeset 25211 2476da7d73bf
parent 22613 4492f0cfdd38
child 27190 d3a9a634cc0b
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
22613
4492f0cfdd38 8027175: Existing regression tests in tl/langtools and tl/jdk need to be updated for @bug keyword
sogoel
parents: 21399
diff changeset
     2
 * Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @test
22613
4492f0cfdd38 8027175: Existing regression tests in tl/langtools and tl/jdk need to be updated for @bug keyword
sogoel
parents: 21399
diff changeset
    26
 * @bug 6545058 6611182 8016209
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    27
 * @summary validate and test -version, -fullversion, and internal, as well as
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    28
 *          sanity checks if a tool can be launched.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * @compile VersionCheck.java
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * @run main VersionCheck
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.io.File;
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    34
import java.io.FileFilter;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.ArrayList;
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    37
import java.util.HashMap;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.util.List;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    40
public class VersionCheck extends TestHelper {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    42
    // tools that do not accept -J-option
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    43
    static final String[] BLACKLIST_JOPTION = {
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    44
        "controlpanel",
15529
8112eb76bda3 8007135: tools/launcher/VersionCheck.java failing with new tool jabswitch
ksrini
parents: 14998
diff changeset
    45
        "jabswitch",
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    46
        "java-rmi",
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    47
        "java-rmi.cgi",
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    48
        "java",
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    49
        "javaw",
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    50
        "javaws",
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    51
        "jcontrol",
18152
804f7c54faa6 8016209: TEST_BUG: non-compliant jmc in the bin directory hangs testing
ksrini
parents: 16029
diff changeset
    52
        "jmc",
21327
9fc34e0b2a47 8026873: tools/launcher/VersionCheck.java fails in jprt because of jmc.ini
kizune
parents: 18152
diff changeset
    53
        "jmc.ini",
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    54
        "jvisualvm",
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    55
        "packager",
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    56
        "unpack200",
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    57
        "wsimport"
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    58
    };
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    60
    // tools that do not accept -version
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    61
    static final String[] BLACKLIST_VERSION = {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        "appletviewer",
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    63
        "controlpanel",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        "extcheck",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        "jar",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        "jarsigner",
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    67
        "java-rmi",
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    68
        "java-rmi.cgi",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        "javadoc",
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    70
        "javaws",
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    71
        "jcmd",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        "jconsole",
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    73
        "jcontrol",
14998
b9a99aac309e 8005634: tools/launcher/VersionCheck.java fails version check on jdeps
chegar
parents: 12301
diff changeset
    74
        "jdeps",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        "jinfo",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        "jmap",
18152
804f7c54faa6 8016209: TEST_BUG: non-compliant jmc in the bin directory hangs testing
ksrini
parents: 16029
diff changeset
    77
        "jmc",
21327
9fc34e0b2a47 8026873: tools/launcher/VersionCheck.java fails in jprt because of jmc.ini
kizune
parents: 18152
diff changeset
    78
        "jmc.ini",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        "jps",
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    80
        "jrunscript",
16029
4e88242da117 8008914: Add nashorn to the tl build
jjg
parents: 15529
diff changeset
    81
        "jjs",
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    82
        "jsadebugd",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        "jstack",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        "jstat",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        "jstatd",
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    86
        "jvisualvm",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        "keytool",
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    88
        "kinit",
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    89
        "klist",
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    90
        "ktab",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        "native2ascii",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        "orbd",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        "pack200",
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    94
        "packager",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        "policytool",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        "rmic",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        "rmid",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        "rmiregistry",
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
    99
        "schemagen", // returns error code 127
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        "serialver",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        "servertool",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        "tnameserv",
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   103
        "unpack200",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        "wsgen",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        "wsimport",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        "xjc"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    // expected reference strings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    static String refVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    static String refFullVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    static String getVersion(String... argv) {
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   114
        TestHelper.TestResult tr = doExec(argv);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        StringBuilder out = new StringBuilder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        // remove the HotSpot line
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   117
        for (String x : tr.testOutput) {
10053
43930b0d0564 7043125: TEST: tools/launcher/VersionCheck.java fails just against openjdk7 (b141 & b138-nightly) promoted
ksrini
parents: 5506
diff changeset
   118
            if (!x.matches(".*Client.*VM.*|.*Server.*VM.*")) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                out = out.append(x + "\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        return out.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   125
    /*
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   126
     * this tests if the tool can take a version string and returns
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   127
     * a 0 exit code, it is not possible to validate the contents
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   128
     * of the -version output as they are inconsistent.
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   129
     */
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   130
    static boolean testToolVersion() {
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   131
        TestResult tr = null;
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   132
        TestHelper.testExitValue = 0;
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   133
        for (File f : new File(JAVA_BIN).listFiles(new ToolFilter(BLACKLIST_VERSION))) {
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   134
            String x = f.getAbsolutePath();
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   135
            System.out.println("Testing (-version): " + x);
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   136
            tr = doExec(x, "-version");
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   137
            tr.checkPositive();
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   138
        }
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   139
        return TestHelper.testExitValue == 0;
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   140
    }
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   141
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   142
    static boolean compareJVersionStrings() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        int failcount = 0;
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   144
        for (File f : new File(JAVA_BIN).listFiles(new ToolFilter(BLACKLIST_JOPTION))) {
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   145
            String x = f.getAbsolutePath();
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   146
            System.out.println("Testing (-J-version): " + x);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            String testStr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            testStr = getVersion(x, "-J-version");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            if (refVersion.compareTo(testStr) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                failcount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                System.out.println("Error: " + x +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                                   " fails -J-version comparison");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                System.out.println("Expected:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                System.out.print(refVersion);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                System.out.println("Actual:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                System.out.print(testStr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            testStr = getVersion(x, "-J-fullversion");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            if (refFullVersion.compareTo(testStr) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                failcount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                System.out.println("Error: " + x +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                                   " fails -J-fullversion comparison");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                System.out.println("Expected:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                System.out.print(refFullVersion);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                System.out.println("Actual:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                System.out.print(testStr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        System.out.println("Version Test: " + failcount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        return failcount == 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    static boolean compareInternalStrings() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        int failcount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        String bStr = refVersion.substring(refVersion.lastIndexOf("build") +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                                           "build".length() + 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                                           refVersion.lastIndexOf(")"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        String[] vStr = bStr.split("\\.|-|_");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        String jdkMajor = vStr[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        String jdkMinor = vStr[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        String jdkMicro = vStr[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        String jdkBuild = vStr[vStr.length - 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        String expectedDotVersion = "dotversion:" + jdkMajor + "." + jdkMinor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        String expectedFullVersion = "fullversion:" + bStr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   190
        Map<String, String> envMap = new HashMap<>();
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   191
        envMap.put(TestHelper.JLDEBUG_KEY, "true");
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   192
        TestHelper.TestResult tr = doExec(envMap, javaCmd, "-version");
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   193
        List<String> alist = new ArrayList<>();
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   194
        alist.addAll(tr.testOutput);
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   195
        for (String x : tr.testOutput) {
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   196
            alist.add(x.trim());
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   197
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        if (!alist.contains(expectedDotVersion)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            System.out.println("Error: could not find " + expectedDotVersion);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            failcount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        if (!alist.contains(expectedFullVersion)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            System.out.println("Error: could not find " + expectedFullVersion);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            failcount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        System.out.println("Internal Strings Test: " + failcount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        return failcount == 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    // Initialize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    static void init() {
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   213
        refVersion = getVersion(javaCmd, "-version");
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   214
        refFullVersion = getVersion(javaCmd, "-fullversion");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    public static void main(String[] args) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        init();
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   219
        if (compareJVersionStrings() &&
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   220
                compareInternalStrings() &&
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   221
                testToolVersion()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            System.out.println("All Version string comparisons: PASS");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            throw new AssertionError("Some tests failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    }
12301
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   227
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   228
    static class ToolFilter implements FileFilter {
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   229
        final Iterable<String> exclude ;
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   230
        protected ToolFilter(String... exclude) {
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   231
            List<String> tlist = new ArrayList<>();
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   232
            this.exclude = tlist;
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   233
            for (String x : exclude) {
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   234
                String str = x + ((isWindows) ? EXE_FILE_EXT : "");
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   235
                tlist.add(str.toLowerCase());
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   236
            }
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   237
        }
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   238
        @Override
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   239
        public boolean accept(File pathname) {
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   240
            if (!pathname.isFile() || !pathname.canExecute()) {
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   241
                return false;
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   242
            }
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   243
            String name = pathname.getName().toLowerCase();
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   244
            if (isWindows && !name.endsWith(EXE_FILE_EXT)) {
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   245
                return false;
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   246
            }
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   247
            for (String x : exclude) {
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   248
                if (name.endsWith(x)) {
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   249
                    return false;
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   250
                }
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   251
            }
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   252
            return true;
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   253
        }
201cef0a3f12 7156976: improve java tools testing
ksrini
parents: 10053
diff changeset
   254
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
}