langtools/test/tools/sjavac/SJavacTester.java
author shade
Thu, 03 Mar 2016 23:57:29 +0300
changeset 36553 203b2b5d149b
parent 35356 e919fd8db52c
child 36778 e04318f39f92
permissions -rw-r--r--
8150465: Unsafe methods to produce uninitialized arrays Reviewed-by: jrose, kvn, psandoz, aph, twisti, flar
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
/*
35356
e919fd8db52c 8056989: Sjavac --server option should be optional
alundblad
parents: 34473
diff changeset
     2
 * Copyright (c) 2014, 2016, 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
34473
5f7202c2125d 8144009: ToolBox should have a cleanDirectory method
alundblad
parents: 32799
diff changeset
    33
    final ToolBox tb = new ToolBox();
31115
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents: 28276
diff changeset
    34
    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
    35
28276
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    36
    // 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
    37
    final Path GENSRC = TEST_ROOT.resolve("gensrc");
28276
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    38
    // 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
    39
    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
    40
    final Path GENSRC3 = TEST_ROOT.resolve("gensrc3");
28276
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    41
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    42
    // Dir for compiled classes.
31115
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents: 28276
diff changeset
    43
    final Path BIN = TEST_ROOT.resolve("bin");
28276
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    44
    // Dir for c-header files.
31115
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents: 28276
diff changeset
    45
    final Path HEADERS = TEST_ROOT.resolve("headers");
28276
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    46
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    47
    // Remember the previous bin and headers state here.
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    48
    Map<String,Long> previous_bin_state;
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    49
    Map<String,Long> previous_headers_state;
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    50
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    51
    void initialCompile() throws Exception {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    52
        System.out.println("\nInitial compile of gensrc.");
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    53
        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
    54
                     "package alfa.omega; public interface AINT { void aint(); }");
28276
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    55
        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
    56
                     "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
    57
                     "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
    58
        tb.writeFile(GENSRC.resolve("alfa/omega/AA.java"),
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    59
            "package alfa.omega;"+
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    60
            "// 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
    61
            "class AA {"+
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    62
            "   // A properly nested static inner class.\n"+
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    63
            "    static class AAA { }\n"+
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    64
            "    // A properly nested inner class.\n"+
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    65
            "    class AAAA { }\n"+
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    66
            "    Runnable foo() {\n"+
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    67
            "        // A proper anonymous class.\n"+
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    68
            "        return new Runnable() { public void run() { } };\n"+
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    69
            "    }\n"+
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    70
            "    AAA aaa;\n"+
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    71
            "    AAAA aaaa;\n"+
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    72
            "    AAAAA aaaaa;\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
            "class AAAAA {\n"+
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    75
            "    // 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
    76
            "    // 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
    77
            "}\n");
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    78
        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
    79
                     "package beta;public interface BINT { void foo(); }");
28276
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    80
        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
    81
                     "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
    82
                     "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
    83
31115
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents: 28276
diff changeset
    84
        compile(GENSRC.toString(),
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents: 28276
diff changeset
    85
                "-d", BIN.toString(),
32799
ee577901f4bb 8135131: Enable thin server mode in Sjavac
alundblad
parents: 31115
diff changeset
    86
                "--state-dir=" + BIN,
31115
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents: 28276
diff changeset
    87
                "-h", HEADERS.toString(),
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents: 28276
diff changeset
    88
                "-j", "1",
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents: 28276
diff changeset
    89
                "--log=debug");
28276
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    90
    }
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    91
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    92
    void removeFrom(Path dir, String... args) throws IOException {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    93
        for (String filename : args) {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    94
            Path p = dir.resolve(filename);
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    95
            Files.delete(p);
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    96
        }
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    97
    }
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    98
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
    99
    void compile(String... args) throws Exception {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   100
        int rc = Main.go(args);
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   101
        if (rc != 0) throw new Exception("Error during compile!");
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
        // 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
   104
        // 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
   105
        // on windows where the timestamps work.
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   106
        long in_a_sec = System.currentTimeMillis()+1000;
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   107
        while (in_a_sec > System.currentTimeMillis()) {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   108
            try {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   109
                Thread.sleep(1000);
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   110
            } catch (InterruptedException e) {
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
    }
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   114
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   115
    void compileExpectFailure(String... args) throws Exception {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   116
        int rc = Main.go(args);
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   117
        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
   118
    }
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   119
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   120
    Map<String,Long> collectState(Path dir) throws IOException {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   121
        final Map<String,Long> files = new HashMap<>();
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   122
        Files.walkFileTree(dir, new SimpleFileVisitor<Path>() {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   123
                 @Override
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   124
                 public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   125
                   throws IOException
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
                     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
   128
                     return FileVisitResult.CONTINUE;
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   129
                 }
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
        return files;
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   132
    }
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   133
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   134
    void verifyThatFilesHaveBeenRemoved(Map<String,Long> from,
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   135
                                        Map<String,Long> to,
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   136
                                        String... args) throws Exception {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   137
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   138
        Set<String> froms = from.keySet();
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   139
        Set<String> tos = to.keySet();
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
        if (froms.equals(tos)) {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   142
            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
   143
        }
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   144
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   145
        for (String t : tos) {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   146
            if (!froms.contains(t)) {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   147
                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
   148
            }
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   149
        }
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   150
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   151
        for (String f : args) {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   152
            f = f.replace("/", File.separator);
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   153
            if (!froms.contains(f)) {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   154
                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
   155
            }
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   156
            if (tos.contains(f)) {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   157
                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
   158
            }
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   159
        }
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
        if (froms.size() - args.length != tos.size()) {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   162
            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
   163
        }
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   164
    }
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
    void verifyThatFilesHaveBeenAdded(Map<String,Long> from,
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   167
                                      Map<String,Long> to,
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   168
                                      String... args) throws Exception {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   169
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   170
        Set<String> froms = from.keySet();
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   171
        Set<String> tos = to.keySet();
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
        if (froms.equals(tos)) {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   174
            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
   175
        }
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
        for (String t : froms) {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   178
            if (!tos.contains(t)) {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   179
                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
   180
            }
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   181
        }
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   182
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   183
        for (String f : args) {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   184
            f = f.replace("/", File.separator);
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   185
            if (!tos.contains(f)) {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   186
                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
   187
            }
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   188
            if (froms.contains(f)) {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   189
                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
   190
            }
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
        if (froms.size() + args.length != tos.size()) {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   194
            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
   195
        }
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   196
    }
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
    void verifyNewerFiles(Map<String,Long> from,
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   199
                          Map<String,Long> to,
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   200
                          String... args) throws Exception {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   201
        if (!from.keySet().equals(to.keySet())) {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   202
            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
   203
        }
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   204
        Set<String> files = new HashSet<String>();
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   205
        for (String s : args) {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   206
            files.add(s.replace("/", File.separator));
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   207
        }
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   208
        for (String fn : from.keySet()) {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   209
            long f = from.get(fn);
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   210
            long t = to.get(fn);
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   211
            if (files.contains(fn)) {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   212
                if (t <= f) {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   213
                    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
   214
                }
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   215
            } else {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   216
                if (t != f) {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   217
                    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
   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
    }
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   222
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   223
    String print(Map<String,Long> m) {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   224
        StringBuilder b = new StringBuilder();
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   225
        Set<String> keys = m.keySet();
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   226
        for (String k : keys) {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   227
            b.append(k+" "+m.get(k)+"\n");
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   228
        }
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   229
        return b.toString();
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   230
    }
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
    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
   233
        if (!from.equals(to)) {
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   234
            System.out.println("FROM---"+print(from));
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   235
            System.out.println("TO-----"+print(to));
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   236
            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
   237
        }
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   238
    }
ec66954fa850 8054689: Split large SJavac.java test source into multiple files
sogoel
parents:
diff changeset
   239
}