langtools/test/tools/sjavac/IncludeExcludePatterns.java
author alanb
Thu, 17 Mar 2016 19:04:28 +0000
changeset 36526 3b41f1c69604
parent 35356 e919fd8db52c
child 36778 e04318f39f92
permissions -rw-r--r--
8142968: Module System implementation Summary: Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282 Reviewed-by: jjg, jlahoda, vromero, mcimadamore, bpatel, ksrini, darcy, anazarov, dfuchs Contributed-by: alan.bateman@oracle.com, alex.buckley@oracle.com, jonathan.gibbons@oracle.com, karen.kinnear@oracle.com, mandy.chung@oracle.com, mark.reinhold@oracle.com, jan.lahoda@oracle.com, vicente.romero@oracle.com, andreas.lundblad@oracle.com, andrey.x.nazarov@oracle.com, chris.hegarty@oracle.com, erik.joelsson@oracle.com, kumar.x.srinivasan@oracle.com, sundararajan.athijegannathan@oracle.com
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
 *
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 26271
diff changeset
    29
 * @modules jdk.compiler/com.sun.tools.sjavac
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35356
diff changeset
    30
 *          jdk.jdeps/com.sun.tools.javap
34991
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    31
 * @library /tools/lib
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    32
 * @build Wrapper ToolBox
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    33
 * @run main Wrapper IncludeExcludePatterns
25603
d5fa4eab2d26 8046824: class SJavacTestUtil and *Wrapper are redundant and should be removed
jjg
parents: 24067
diff changeset
    34
 */
d5fa4eab2d26 8046824: class SJavacTestUtil and *Wrapper are redundant and should be removed
jjg
parents: 24067
diff changeset
    35
34991
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    36
import com.sun.tools.javac.util.Assert;
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    37
import com.sun.tools.sjavac.server.Sjavac;
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    38
34996
ed25a4c782c2 8146727: test tools/sjavac/IncludeExcludePatterns.java fails on Windows
jjg
parents: 34991
diff changeset
    39
import java.io.File;
24067
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    40
import java.io.IOException;
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    41
import java.nio.file.Files;
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    42
import java.nio.file.Path;
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    43
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
    44
import java.util.Arrays;
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    45
import java.util.Collection;
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    46
import java.util.HashSet;
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    47
import java.util.Set;
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    48
import java.util.stream.Collectors;
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    49
import java.util.stream.Stream;
24067
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    50
34991
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    51
public class IncludeExcludePatterns extends SjavacBase {
24067
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    52
34991
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    53
    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
    54
    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
    55
    final Path STATE_DIR = Paths.get("state-dir");
24067
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    56
34991
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    57
    // 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
    58
    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
    59
    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
    60
    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
    61
    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
    62
    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
    63
    final Path X2 = Paths.get("pkgc/Xx.java");
24067
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    64
34991
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    65
    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
    66
34991
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    67
    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
    68
        new IncludeExcludePatterns().runTest();
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    69
    }
24067
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    70
34991
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    71
    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
    72
        Files.createDirectories(BIN);
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    73
        Files.createDirectories(STATE_DIR);
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    74
        for (Path p : ALL_PATHS) {
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    75
            writeDummyClass(p);
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    76
        }
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    77
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    78
        // Single file
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    79
        testPattern("pkga/A.java", A);
24067
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    80
34991
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    81
        // Leading wild cards
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    82
        testPattern("*/A.java", A);
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    83
        testPattern("**/Xx.java", X1, X2);
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    84
        testPattern("**x.java", X1, X2);
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    85
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    86
        // 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
    87
        testPattern("pkga/*/Xx.java", X1);
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    88
        testPattern("pkga/**/Y.java", Y);
24067
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    89
34991
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    90
        // Trailing wild cards
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    91
        testPattern("pkga/*", A);
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    92
        testPattern("pkga/**", A, X1, Y);
24067
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    93
34991
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    94
        // Multiple wildcards
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    95
        testPattern("pkga/*/*/Y.java", Y);
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    96
        testPattern("**/*/**", X1, Y);
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
    97
24067
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    98
    }
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    99
34991
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   100
    // 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
   101
    String classNameOf(Path javaFile) {
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   102
        return javaFile.getFileName()
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   103
                       .toString()
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   104
                       .replace(".java", "");
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   105
    }
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   106
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   107
    // 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
   108
    void writeDummyClass(Path javaFile) throws IOException {
34996
ed25a4c782c2 8146727: test tools/sjavac/IncludeExcludePatterns.java fails on Windows
jjg
parents: 34991
diff changeset
   109
        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
   110
        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
   111
        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
   112
    }
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   113
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   114
    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
   115
            throws ReflectiveOperationException, IOException {
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   116
        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
   117
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   118
        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
   119
        complement.removeAll(Arrays.asList(sourcesExpectedToBeVisible));
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   120
        testFilter("-x " + filterArgs, complement);
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   121
    }
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   122
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   123
    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
   124
            throws IOException, ReflectiveOperationException {
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   125
        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
   126
        toolbox.cleanDirectory(BIN);
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   127
        toolbox.cleanDirectory(STATE_DIR);
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   128
        String args = filterArgs + " " + SRC
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   129
                + " -d " + BIN
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   130
                + " --state-dir=" + STATE_DIR;
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   131
        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
   132
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   133
        // Compilation should always pass in these tests
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   134
        Assert.check(rc == Sjavac.RC_OK, "Compilation failed unexpectedly.");
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   135
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   136
        // 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
   137
        Set<Path> result = allFilesInDir(BIN);
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   138
        Set<Path> expected = correspondingClassFiles(sourcesExpectedToBeVisible);
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   139
        if (!result.equals(expected)) {
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   140
            System.out.println("Result:");
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   141
            printPaths(result);
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   142
            System.out.println("Expected:");
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   143
            printPaths(expected);
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   144
            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
   145
        }
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   146
    }
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
    void printPaths(Collection<Path> paths) {
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   149
        paths.stream()
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   150
             .sorted()
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   151
             .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
   152
    }
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   153
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   154
    // 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
   155
    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
   156
        return javaFiles.stream()
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   157
                        .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
   158
                        .map(BIN::resolve)
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   159
                        .collect(Collectors.toSet());
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   160
    }
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   161
ff8be37d1164 8144226: Sjavac's handling of include/exclude patterns is buggy, redundant and inconsistent
alundblad
parents: 34752
diff changeset
   162
    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
   163
        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
   164
            return files.collect(Collectors.toSet());
24067
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   165
        }
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   166
    }
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   167
}