langtools/test/tools/sjavac/SJavacTester.java
author amurillo
Thu, 13 Aug 2015 15:50:52 -0700
changeset 32224 dae855d05f6c
parent 31115 8d8e98052d5d
child 32799 ee577901f4bb
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
28276
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
     1
/*
31115
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents: 28276
diff changeset
     2
 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
28276
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
     4
 *
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
     7
 * published by the Free Software Foundation.
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
     8
 *
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    13
 * accompanied this code).
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    14
 *
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    18
 *
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    21
 * questions.
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    22
 */
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    23
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    24
import java.util.*;
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    25
import java.io.*;
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    26
import java.nio.file.*;
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    27
import java.nio.file.attribute.*;
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    28
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    29
import com.sun.tools.sjavac.Main;
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    30
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    31
public class SJavacTester {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    32
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    33
    static final String SERVER_ARG = "--server:"
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    34
            + "portfile=testportfile,"
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    35
            + "background=false";
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    36
31115
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents: 28276
diff changeset
    37
    final Path TEST_ROOT = Paths.get(getClass().getSimpleName());
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents: 28276
diff changeset
    38
28276
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    39
    // Generated sources that will test aspects of sjavac
31115
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents: 28276
diff changeset
    40
    final Path GENSRC = TEST_ROOT.resolve("gensrc");
28276
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    41
    // Gensrc dirs used to test merging of serveral source roots.
31115
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents: 28276
diff changeset
    42
    final Path GENSRC2 = TEST_ROOT.resolve("gensrc2");
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents: 28276
diff changeset
    43
    final Path GENSRC3 = TEST_ROOT.resolve("gensrc3");
28276
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    44
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    45
    // Dir for compiled classes.
31115
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents: 28276
diff changeset
    46
    final Path BIN = TEST_ROOT.resolve("bin");
28276
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    47
    // Dir for c-header files.
31115
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents: 28276
diff changeset
    48
    final Path HEADERS = TEST_ROOT.resolve("headers");
28276
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    49
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    50
    // Remember the previous bin and headers state here.
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    51
    Map<String,Long> previous_bin_state;
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    52
    Map<String,Long> previous_headers_state;
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    53
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    54
    void initialCompile() throws Exception {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    55
        System.out.println("\nInitial compile of gensrc.");
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    56
        ToolBox tb = new ToolBox();
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    57
        tb.writeFile(GENSRC.resolve("alfa/omega/AINT.java"),
31115
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents: 28276
diff changeset
    58
                     "package alfa.omega; public interface AINT { void aint(); }");
28276
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    59
        tb.writeFile(GENSRC.resolve("alfa/omega/A.java"),
31115
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents: 28276
diff changeset
    60
                     "package alfa.omega; public class A implements AINT { "+
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents: 28276
diff changeset
    61
                     "public final static int DEFINITION = 17; public void aint() { } }");
28276
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    62
        tb.writeFile(GENSRC.resolve("alfa/omega/AA.java"),
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    63
            "package alfa.omega;"+
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    64
            "// A package private class, not contributing to the public api.\n"+
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    65
            "class AA {"+
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    66
            "   // A properly nested static inner class.\n"+
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    67
            "    static class AAA { }\n"+
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    68
            "    // A properly nested inner class.\n"+
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    69
            "    class AAAA { }\n"+
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    70
            "    Runnable foo() {\n"+
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    71
            "        // A proper anonymous class.\n"+
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    72
            "        return new Runnable() { public void run() { } };\n"+
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    73
            "    }\n"+
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    74
            "    AAA aaa;\n"+
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    75
            "    AAAA aaaa;\n"+
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    76
            "    AAAAA aaaaa;\n"+
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    77
            "}\n"+
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    78
            "class AAAAA {\n"+
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    79
            "    // A bad auxiliary class, but no one is referencing it\n"+
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    80
            "    // from outside of this source file, therefore it is ok.\n"+
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    81
            "}\n");
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    82
        tb.writeFile(GENSRC.resolve("beta/BINT.java"),
31115
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents: 28276
diff changeset
    83
                     "package beta;public interface BINT { void foo(); }");
28276
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    84
        tb.writeFile(GENSRC.resolve("beta/B.java"),
31115
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents: 28276
diff changeset
    85
                     "package beta; import alfa.omega.A; public class B {"+
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents: 28276
diff changeset
    86
                     "private int b() { return A.DEFINITION; } native void foo(); }");
28276
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    87
31115
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents: 28276
diff changeset
    88
        compile(GENSRC.toString(),
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents: 28276
diff changeset
    89
                "-d", BIN.toString(),
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents: 28276
diff changeset
    90
                "-h", HEADERS.toString(),
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents: 28276
diff changeset
    91
                "-j", "1",
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents: 28276
diff changeset
    92
                SERVER_ARG,
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents: 28276
diff changeset
    93
                "--log=debug");
28276
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    94
    }
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    95
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    96
    void removeFrom(Path dir, String... args) throws IOException {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    97
        for (String filename : args) {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    98
            Path p = dir.resolve(filename);
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    99
            Files.delete(p);
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   100
        }
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   101
    }
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   102
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   103
    void delete(final Path root) throws IOException {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   104
        if (!Files.exists(root)) return;
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   105
        Files.walkFileTree(root, new SimpleFileVisitor<Path>() {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   106
                 @Override
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   107
                 public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   108
                 {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   109
                     Files.delete(file);
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   110
                     return FileVisitResult.CONTINUE;
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   111
                 }
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   112
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   113
                 @Override
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   114
                 public FileVisitResult postVisitDirectory(Path dir, IOException e) throws IOException
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   115
                 {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   116
                     if (e == null) {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   117
                         if (!dir.equals(root)) Files.delete(dir);
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   118
                         return FileVisitResult.CONTINUE;
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   119
                     } else {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   120
                         // directory iteration failed
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   121
                         throw e;
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   122
                     }
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   123
                 }
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   124
            });
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   125
    }
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   126
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   127
    void compile(String... args) throws Exception {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   128
        int rc = Main.go(args);
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   129
        if (rc != 0) throw new Exception("Error during compile!");
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   130
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   131
        // Wait a second, to get around the (temporary) problem with
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   132
        // second resolution in the Java file api. But do not do this
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   133
        // on windows where the timestamps work.
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   134
        long in_a_sec = System.currentTimeMillis()+1000;
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   135
        while (in_a_sec > System.currentTimeMillis()) {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   136
            try {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   137
                Thread.sleep(1000);
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   138
            } catch (InterruptedException e) {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   139
            }
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   140
        }
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   141
    }
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   142
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   143
    void compileExpectFailure(String... args) throws Exception {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   144
        int rc = Main.go(args);
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   145
        if (rc == 0) throw new Exception("Expected error during compile! Did not fail!");
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   146
    }
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   147
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   148
    Map<String,Long> collectState(Path dir) throws IOException {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   149
        final Map<String,Long> files = new HashMap<>();
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   150
        Files.walkFileTree(dir, new SimpleFileVisitor<Path>() {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   151
                 @Override
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   152
                 public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   153
                   throws IOException
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   154
                 {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   155
                     files.put(file.toString(),new Long(Files.getLastModifiedTime(file).toMillis()));
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   156
                     return FileVisitResult.CONTINUE;
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   157
                 }
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   158
            });
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   159
        return files;
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   160
    }
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   161
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   162
    void verifyThatFilesHaveBeenRemoved(Map<String,Long> from,
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   163
                                        Map<String,Long> to,
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   164
                                        String... args) throws Exception {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   165
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   166
        Set<String> froms = from.keySet();
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   167
        Set<String> tos = to.keySet();
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   168
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   169
        if (froms.equals(tos)) {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   170
            throw new Exception("Expected new state to have fewer files than previous state!");
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   171
        }
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   172
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   173
        for (String t : tos) {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   174
            if (!froms.contains(t)) {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   175
                throw new Exception("Expected "+t+" to exist in previous state!");
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   176
            }
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   177
        }
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   178
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   179
        for (String f : args) {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   180
            f = f.replace("/", File.separator);
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   181
            if (!froms.contains(f)) {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   182
                throw new Exception("Expected "+f+" to exist in previous state!");
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   183
            }
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   184
            if (tos.contains(f)) {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   185
                throw new Exception("Expected "+f+" to have been removed from the new state!");
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   186
            }
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   187
        }
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   188
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   189
        if (froms.size() - args.length != tos.size()) {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   190
            throw new Exception("There are more removed files than the expected list!");
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   191
        }
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   192
    }
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   193
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   194
    void verifyThatFilesHaveBeenAdded(Map<String,Long> from,
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   195
                                      Map<String,Long> to,
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   196
                                      String... args) throws Exception {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   197
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   198
        Set<String> froms = from.keySet();
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   199
        Set<String> tos = to.keySet();
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   200
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   201
        if (froms.equals(tos)) {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   202
            throw new Exception("Expected new state to have more files than previous state!");
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   203
        }
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   204
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   205
        for (String t : froms) {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   206
            if (!tos.contains(t)) {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   207
                throw new Exception("Expected "+t+" to exist in new state!");
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   208
            }
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   209
        }
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   210
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   211
        for (String f : args) {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   212
            f = f.replace("/", File.separator);
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   213
            if (!tos.contains(f)) {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   214
                throw new Exception("Expected "+f+" to have been added to new state!");
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   215
            }
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   216
            if (froms.contains(f)) {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   217
                throw new Exception("Expected "+f+" to not exist in previous state!");
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   218
            }
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   219
        }
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   220
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   221
        if (froms.size() + args.length != tos.size()) {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   222
            throw new Exception("There are more added files than the expected list!");
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   223
        }
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   224
    }
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   225
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   226
    void verifyNewerFiles(Map<String,Long> from,
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   227
                          Map<String,Long> to,
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   228
                          String... args) throws Exception {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   229
        if (!from.keySet().equals(to.keySet())) {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   230
            throw new Exception("Expected the set of files to be identical!");
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   231
        }
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   232
        Set<String> files = new HashSet<String>();
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   233
        for (String s : args) {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   234
            files.add(s.replace("/", File.separator));
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   235
        }
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   236
        for (String fn : from.keySet()) {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   237
            long f = from.get(fn);
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   238
            long t = to.get(fn);
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   239
            if (files.contains(fn)) {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   240
                if (t <= f) {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   241
                    throw new Exception("Expected "+fn+" to have a more recent timestamp!");
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   242
                }
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   243
            } else {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   244
                if (t != f) {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   245
                    throw new Exception("Expected "+fn+" to have the same timestamp!");
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   246
                }
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   247
            }
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   248
        }
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   249
    }
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   250
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   251
    String print(Map<String,Long> m) {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   252
        StringBuilder b = new StringBuilder();
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   253
        Set<String> keys = m.keySet();
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   254
        for (String k : keys) {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   255
            b.append(k+" "+m.get(k)+"\n");
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   256
        }
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   257
        return b.toString();
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   258
    }
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   259
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   260
    void verifyEqual(Map<String,Long> from, Map<String,Long> to) throws Exception {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   261
        if (!from.equals(to)) {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   262
            System.out.println("FROM---"+print(from));
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   263
            System.out.println("TO-----"+print(to));
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   264
            throw new Exception("The dir should not differ! But it does!");
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   265
        }
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   266
    }
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   267
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   268
    void clean(Path... listOfDirs) throws Exception {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   269
        for (Path dir : listOfDirs) {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   270
            delete(dir);
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   271
        }
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   272
    }
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   273
}