langtools/test/tools/sjavac/IncludeExcludePatterns.java
author jjg
Wed, 10 Aug 2016 15:47:46 -0700
changeset 40308 274367a99f98
parent 37643 626e07816dce
permissions -rw-r--r--
8136930: Simplify use of module-system options by custom launchers 8160489: Multiple -Xpatch lines ignored by javac 8156998: javac should support new option -XinheritRuntimeEnvironment Reviewed-by: jlahoda, ksrini
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24067
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
     1
/*
34996
ed25a4c782c2 8146727: test tools/sjavac/IncludeExcludePatterns.java fails on Windows
jjg
parents: 34991
diff changeset
     2
 * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
24067
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
     4
 *
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
32337
c9d3ab9f601c 8133671: langtools tests have bad license
alundblad
parents: 30730
diff changeset
     7
 * published by the Free Software Foundation.
24067
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
     8
 *
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    13
 * accompanied this code).
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    14
 *
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    18
 *
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    21
 * questions.
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    22
 */
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    23
25603
d5fa4eab2d26 8046824: class SJavacTestUtil and *Wrapper are redundant and should be removed
jjg
parents: 24067
diff changeset
    24
/*
d5fa4eab2d26 8046824: class SJavacTestUtil and *Wrapper are redundant and should be removed
jjg
parents: 24067
diff changeset
    25
 * @test
d5fa4eab2d26 8046824: class SJavacTestUtil and *Wrapper are redundant and should be removed
jjg
parents: 24067
diff changeset
    26
 * @bug 8037085
d5fa4eab2d26 8046824: class SJavacTestUtil and *Wrapper are redundant and should be removed
jjg
parents: 24067
diff changeset
    27
 * @summary Ensures that sjavac can handle various exclusion patterns.
d5fa4eab2d26 8046824: class SJavacTestUtil and *Wrapper are redundant and should be removed
jjg
parents: 24067
diff changeset
    28
 *
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37643
diff changeset
    29
 * @modules jdk.compiler/com.sun.tools.javac.main
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37643
diff changeset
    30
 *          jdk.compiler/com.sun.tools.sjavac
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37643
diff changeset
    31
 *          jdk.compiler/com.sun.tools.sjavac.server
34991
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    32
 * @library /tools/lib
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37643
diff changeset
    33
 * @build Wrapper toolbox.ToolBox toolbox.Assert
34991
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    34
 * @run main Wrapper IncludeExcludePatterns
25603
d5fa4eab2d26 8046824: class SJavacTestUtil and *Wrapper are redundant and should be removed
jjg
parents: 24067
diff changeset
    35
 */
d5fa4eab2d26 8046824: class SJavacTestUtil and *Wrapper are redundant and should be removed
jjg
parents: 24067
diff changeset
    36
34996
ed25a4c782c2 8146727: test tools/sjavac/IncludeExcludePatterns.java fails on Windows
jjg
parents: 34991
diff changeset
    37
import java.io.File;
24067
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    38
import java.io.IOException;
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    39
import java.nio.file.Files;
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    40
import java.nio.file.Path;
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    41
import java.nio.file.Paths;
34991
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    42
import java.util.Arrays;
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    43
import java.util.Collection;
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    44
import java.util.HashSet;
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    45
import java.util.Set;
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    46
import java.util.stream.Collectors;
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    47
import java.util.stream.Stream;
24067
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    48
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37643
diff changeset
    49
import com.sun.tools.javac.main.Main.Result;
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37643
diff changeset
    50
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37643
diff changeset
    51
import toolbox.Assert;
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37643
diff changeset
    52
34991
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    53
public class IncludeExcludePatterns extends SjavacBase {
24067
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    54
34991
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    55
    final Path SRC = Paths.get("src");
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    56
    final Path BIN = Paths.get("bin");
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    57
    final Path STATE_DIR = Paths.get("state-dir");
24067
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    58
34991
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    59
    // An arbitrarily but sufficiently complicated source tree.
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    60
    final Path A = Paths.get("pkga/A.java");
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    61
    final Path X1 = Paths.get("pkga/subpkg/Xx.java");
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    62
    final Path Y = Paths.get("pkga/subpkg/subsubpkg/Y.java");
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    63
    final Path B = Paths.get("pkgb/B.java");
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    64
    final Path C = Paths.get("pkgc/C.java");
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    65
    final Path X2 = Paths.get("pkgc/Xx.java");
24067
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    66
34991
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    67
    final Path[] ALL_PATHS = {A, X1, Y, B, C, X2};
24067
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    68
34991
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    69
    public static void main(String[] ignore) throws Exception {
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    70
        new IncludeExcludePatterns().runTest();
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    71
    }
24067
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    72
34991
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    73
    public void runTest() throws IOException, ReflectiveOperationException {
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    74
        Files.createDirectories(BIN);
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    75
        Files.createDirectories(STATE_DIR);
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    76
        for (Path p : ALL_PATHS) {
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    77
            writeDummyClass(p);
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    78
        }
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    79
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    80
        // Single file
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    81
        testPattern("pkga/A.java", A);
24067
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    82
34991
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    83
        // Leading wild cards
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    84
        testPattern("*/A.java", A);
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    85
        testPattern("**/Xx.java", X1, X2);
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    86
        testPattern("**x.java", X1, X2);
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    87
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    88
        // Wild card in middle of path
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    89
        testPattern("pkga/*/Xx.java", X1);
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    90
        testPattern("pkga/**/Y.java", Y);
24067
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    91
34991
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    92
        // Trailing wild cards
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    93
        testPattern("pkga/*", A);
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    94
        testPattern("pkga/**", A, X1, Y);
24067
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    95
34991
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    96
        // Multiple wildcards
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    97
        testPattern("pkga/*/*/Y.java", Y);
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    98
        testPattern("**/*/**", X1, Y);
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    99
24067
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   100
    }
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   101
34991
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   102
    // Given "src/pkg/subpkg/A.java" this method returns "A"
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   103
    String classNameOf(Path javaFile) {
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   104
        return javaFile.getFileName()
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   105
                       .toString()
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   106
                       .replace(".java", "");
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   107
    }
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   108
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   109
    // Puts an empty (dummy) class definition in the given path.
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   110
    void writeDummyClass(Path javaFile) throws IOException {
34996
ed25a4c782c2 8146727: test tools/sjavac/IncludeExcludePatterns.java fails on Windows
jjg
parents: 34991
diff changeset
   111
        String pkg = javaFile.getParent().toString().replace(File.separatorChar, '.');
34991
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   112
        String cls = javaFile.getFileName().toString().replace(".java", "");
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   113
        toolbox.writeFile(SRC.resolve(javaFile), "package " + pkg + "; class " + cls + " {}");
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   114
    }
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   115
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   116
    void testPattern(String filterArgs, Path... sourcesExpectedToBeVisible)
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   117
            throws ReflectiveOperationException, IOException {
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   118
        testFilter("-i " + filterArgs, Arrays.asList(sourcesExpectedToBeVisible));
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   119
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   120
        Set<Path> complement = new HashSet<>(Arrays.asList(ALL_PATHS));
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   121
        complement.removeAll(Arrays.asList(sourcesExpectedToBeVisible));
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   122
        testFilter("-x " + filterArgs, complement);
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   123
    }
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   124
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   125
    void testFilter(String filterArgs, Collection<Path> sourcesExpectedToBeVisible)
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   126
            throws IOException, ReflectiveOperationException {
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   127
        System.out.println("Testing filter: " + filterArgs);
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   128
        toolbox.cleanDirectory(BIN);
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   129
        toolbox.cleanDirectory(STATE_DIR);
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   130
        String args = filterArgs + " " + SRC
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   131
                + " -d " + BIN
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   132
                + " --state-dir=" + STATE_DIR;
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   133
        int rc = compile((Object[]) args.split(" "));
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   134
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   135
        // Compilation should always pass in these tests
37643
626e07816dce 8048146: sjavac uses unexpected exit code of -1
alundblad
parents: 36778
diff changeset
   136
        Assert.check(rc == Result.OK.exitCode, "Compilation failed unexpectedly.");
34991
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   137
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   138
        // The resulting .class files should correspond to the visible source files
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   139
        Set<Path> result = allFilesInDir(BIN);
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   140
        Set<Path> expected = correspondingClassFiles(sourcesExpectedToBeVisible);
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   141
        if (!result.equals(expected)) {
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   142
            System.out.println("Result:");
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   143
            printPaths(result);
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   144
            System.out.println("Expected:");
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   145
            printPaths(expected);
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   146
            Assert.error("Test case failed: " + filterArgs);
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   147
        }
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   148
    }
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   149
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   150
    void printPaths(Collection<Path> paths) {
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   151
        paths.stream()
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   152
             .sorted()
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   153
             .forEachOrdered(p -> System.out.println("    " + p));
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   154
    }
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   155
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   156
    // Given "pkg/A.java, pkg/B.java" this method returns "bin/pkg/A.class, bin/pkg/B.class"
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   157
    Set<Path> correspondingClassFiles(Collection<Path> javaFiles) {
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   158
        return javaFiles.stream()
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   159
                        .map(javaFile -> javaFile.resolveSibling(classNameOf(javaFile) + ".class"))
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   160
                        .map(BIN::resolve)
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   161
                        .collect(Collectors.toSet());
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   162
    }
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   163
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   164
    Set<Path> allFilesInDir(Path p) throws IOException {
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   165
        try (Stream<Path> files = Files.walk(p).filter(Files::isRegularFile)) {
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   166
            return files.collect(Collectors.toSet());
24067
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   167
        }
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   168
    }
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   169
}