1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/test/tools/sjavac/SJavac.java Wed Apr 27 01:34:52 2016 +0800 1.3 @@ -0,0 +1,602 @@ 1.4 +/* 1.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + */ 1.26 + 1.27 +import java.util.*; 1.28 +import java.io.*; 1.29 +import java.net.*; 1.30 +import java.nio.file.*; 1.31 +import java.nio.file.attribute.*; 1.32 +import java.nio.charset.*; 1.33 + 1.34 +import com.sun.tools.sjavac.Main; 1.35 + 1.36 +public 1.37 +class SJavac { 1.38 + 1.39 + public static void main(String... args) throws Exception { 1.40 + SJavac s = new SJavac(); 1.41 + s.test(); 1.42 + } 1.43 + 1.44 + FileSystem defaultfs = FileSystems.getDefault(); 1.45 + 1.46 + // Where to put generated sources that will 1.47 + // test aspects of sjavac, ie JTWork/scratch/gensrc 1.48 + Path gensrc; 1.49 + // More gensrc dirs are used to test merging of serveral source roots. 1.50 + Path gensrc2; 1.51 + Path gensrc3; 1.52 + 1.53 + // Where to put compiled classes. 1.54 + Path bin; 1.55 + // Where to put c-header files. 1.56 + Path headers; 1.57 + 1.58 + // The sjavac compiler. 1.59 + Main main = new Main(); 1.60 + 1.61 + // Remember the previous bin and headers state here. 1.62 + Map<String,Long> previous_bin_state; 1.63 + Map<String,Long> previous_headers_state; 1.64 + 1.65 + public void test() throws Exception { 1.66 + gensrc = defaultfs.getPath("gensrc"); 1.67 + gensrc2 = defaultfs.getPath("gensrc2"); 1.68 + gensrc3 = defaultfs.getPath("gensrc3"); 1.69 + bin = defaultfs.getPath("bin"); 1.70 + headers = defaultfs.getPath("headers"); 1.71 + 1.72 + Files.createDirectory(gensrc); 1.73 + Files.createDirectory(gensrc2); 1.74 + Files.createDirectory(gensrc3); 1.75 + Files.createDirectory(bin); 1.76 + Files.createDirectory(headers); 1.77 + 1.78 + initialCompile(); 1.79 + incrementalCompileNoChanges(); 1.80 + incrementalCompileDroppingClasses(); 1.81 + incrementalCompileWithChange(); 1.82 + incrementalCompileDropAllNatives(); 1.83 + incrementalCompileAddNative(); 1.84 + incrementalCompileChangeNative(); 1.85 + compileWithOverrideSource(); 1.86 + compileWithInvisibleSources(); 1.87 + compileCircularSources(); 1.88 + compileExcludingDependency(); 1.89 + 1.90 + delete(gensrc); 1.91 + delete(gensrc2); 1.92 + delete(gensrc3); 1.93 + delete(bin); 1.94 + delete(headers); 1.95 + } 1.96 + 1.97 + void initialCompile() throws Exception { 1.98 + System.out.println("\nInitial compile of gensrc."); 1.99 + System.out.println("----------------------------"); 1.100 + populate(gensrc, 1.101 + "alfa/AINT.java", 1.102 + "package alfa; public interface AINT { void aint(); }", 1.103 + 1.104 + "alfa/A.java", 1.105 + "package alfa; public class A implements AINT { "+ 1.106 + "public final static int DEFINITION = 17; public void aint() { } }", 1.107 + 1.108 + "alfa/AA.java", 1.109 + "package alfa;"+ 1.110 + "// A package private class, not contributing to the public api.\n"+ 1.111 + "class AA {"+ 1.112 + " // A properly nested static inner class.\n"+ 1.113 + " static class AAA { }\n"+ 1.114 + " // A properly nested inner class.\n"+ 1.115 + " class AAAA { }\n"+ 1.116 + " Runnable foo() {\n"+ 1.117 + " // A proper anonymous class.\n"+ 1.118 + " return new Runnable() { public void run() { } };\n"+ 1.119 + " }\n"+ 1.120 + " AAA aaa;\n"+ 1.121 + " AAAA aaaa;\n"+ 1.122 + " AAAAA aaaaa;\n"+ 1.123 + "}\n"+ 1.124 + "class AAAAA {\n"+ 1.125 + " // A bad auxiliary class, but no one is referencing it\n"+ 1.126 + " // from outside of this source file, therefore it is ok.\n"+ 1.127 + "}\n", 1.128 + 1.129 + "beta/BINT.java", 1.130 + "package beta;public interface BINT { void foo(); }", 1.131 + 1.132 + "beta/B.java", 1.133 + "package beta; import alfa.A; public class B {"+ 1.134 + "private int b() { return A.DEFINITION; } native void foo(); }"); 1.135 + 1.136 + compile("gensrc", "-d", "bin", "-h", "headers", "-j", "1", 1.137 + "--server:portfile=testserver,background=false", "--log=debug"); 1.138 + previous_bin_state = collectState(bin); 1.139 + previous_headers_state = collectState(headers); 1.140 + } 1.141 + 1.142 + void incrementalCompileNoChanges() throws Exception { 1.143 + System.out.println("\nTesting that no change in sources implies no change in binaries."); 1.144 + System.out.println("------------------------------------------------------------------"); 1.145 + compile("gensrc", "-d", "bin", "-h", "headers", "-j", "1", 1.146 + "--server:portfile=testserver,background=false", "--log=debug"); 1.147 + Map<String,Long> new_bin_state = collectState(bin); 1.148 + verifyEqual(new_bin_state, previous_bin_state); 1.149 + Map<String,Long> new_headers_state = collectState(headers); 1.150 + verifyEqual(previous_headers_state, new_headers_state); 1.151 + } 1.152 + 1.153 + void incrementalCompileDroppingClasses() throws Exception { 1.154 + System.out.println("\nTesting that deleting AA.java deletes all"); 1.155 + System.out.println("generated inner class as well as AA.class"); 1.156 + System.out.println("-----------------------------------------"); 1.157 + removeFrom(gensrc, "alfa/AA.java"); 1.158 + compile("gensrc", "-d", "bin", "-h", "headers", "-j", "1", 1.159 + "--server:portfile=testserver,background=false", "--log=debug"); 1.160 + Map<String,Long> new_bin_state = collectState(bin); 1.161 + verifyThatFilesHaveBeenRemoved(previous_bin_state, new_bin_state, 1.162 + "bin/alfa/AA$1.class", 1.163 + "bin/alfa/AA$AAAA.class", 1.164 + "bin/alfa/AA$AAA.class", 1.165 + "bin/alfa/AAAAA.class", 1.166 + "bin/alfa/AA.class"); 1.167 + 1.168 + previous_bin_state = new_bin_state; 1.169 + Map<String,Long> new_headers_state = collectState(headers); 1.170 + verifyEqual(previous_headers_state, new_headers_state); 1.171 + } 1.172 + 1.173 + void incrementalCompileWithChange() throws Exception { 1.174 + System.out.println("\nNow update the A.java file with a new timestamps and"); 1.175 + System.out.println("new final static definition. This should trigger a recompile,"); 1.176 + System.out.println("not only of alfa, but also beta."); 1.177 + System.out.println("But check that the generated native header was not updated!"); 1.178 + System.out.println("Since we did not modify the native api of B."); 1.179 + System.out.println("-------------------------------------------------------------"); 1.180 + 1.181 + populate(gensrc,"alfa/A.java", 1.182 + "package alfa; public class A implements AINT { "+ 1.183 + "public final static int DEFINITION = 18; public void aint() { } private void foo() { } }"); 1.184 + 1.185 + compile("gensrc", "-d", "bin", "-h", "headers", "-j", "1", 1.186 + "--server:portfile=testserver,background=false", "--log=debug"); 1.187 + Map<String,Long> new_bin_state = collectState(bin); 1.188 + 1.189 + verifyNewerFiles(previous_bin_state, new_bin_state, 1.190 + "bin/alfa/A.class", 1.191 + "bin/alfa/AINT.class", 1.192 + "bin/beta/B.class", 1.193 + "bin/beta/BINT.class", 1.194 + "bin/javac_state"); 1.195 + previous_bin_state = new_bin_state; 1.196 + 1.197 + Map<String,Long> new_headers_state = collectState(headers); 1.198 + verifyEqual(new_headers_state, previous_headers_state); 1.199 + } 1.200 + 1.201 + void incrementalCompileDropAllNatives() throws Exception { 1.202 + System.out.println("\nNow update the B.java file with one less native method,"); 1.203 + System.out.println("ie it has no longer any methods!"); 1.204 + System.out.println("Verify that beta_B.h is removed!"); 1.205 + System.out.println("---------------------------------------------------------"); 1.206 + 1.207 + populate(gensrc,"beta/B.java", 1.208 + "package beta; import alfa.A; public class B {"+ 1.209 + "private int b() { return A.DEFINITION; } }"); 1.210 + 1.211 + compile("gensrc", "-d", "bin", "-h", "headers", "-j", "1", 1.212 + "--server:portfile=testserver,background=false", "--log=debug"); 1.213 + Map<String,Long> new_bin_state = collectState(bin); 1.214 + verifyNewerFiles(previous_bin_state, new_bin_state, 1.215 + "bin/beta/B.class", 1.216 + "bin/beta/BINT.class", 1.217 + "bin/javac_state"); 1.218 + previous_bin_state = new_bin_state; 1.219 + 1.220 + Map<String,Long> new_headers_state = collectState(headers); 1.221 + verifyThatFilesHaveBeenRemoved(previous_headers_state, new_headers_state, 1.222 + "headers/beta_B.h"); 1.223 + previous_headers_state = new_headers_state; 1.224 + } 1.225 + 1.226 + void incrementalCompileAddNative() throws Exception { 1.227 + System.out.println("\nNow update the B.java file with a final static annotated with @Native."); 1.228 + System.out.println("Verify that beta_B.h is added again!"); 1.229 + System.out.println("------------------------------------------------------------------------"); 1.230 + 1.231 + populate(gensrc,"beta/B.java", 1.232 + "package beta; import alfa.A; public class B {"+ 1.233 + "private int b() { return A.DEFINITION; } "+ 1.234 + "@java.lang.annotation.Native final static int alfa = 42; }"); 1.235 + 1.236 + compile("gensrc", "-d", "bin", "-h", "headers", "-j", "1", 1.237 + "--server:portfile=testserver,background=false", "--log=debug"); 1.238 + Map<String,Long> new_bin_state = collectState(bin); 1.239 + verifyNewerFiles(previous_bin_state, new_bin_state, 1.240 + "bin/beta/B.class", 1.241 + "bin/beta/BINT.class", 1.242 + "bin/javac_state"); 1.243 + previous_bin_state = new_bin_state; 1.244 + 1.245 + Map<String,Long> new_headers_state = collectState(headers); 1.246 + verifyThatFilesHaveBeenAdded(previous_headers_state, new_headers_state, 1.247 + "headers/beta_B.h"); 1.248 + previous_headers_state = new_headers_state; 1.249 + } 1.250 + 1.251 + void incrementalCompileChangeNative() throws Exception { 1.252 + System.out.println("\nNow update the B.java file with a new value for the final static"+ 1.253 + " annotated with @Native."); 1.254 + System.out.println("Verify that beta_B.h is rewritten again!"); 1.255 + System.out.println("-------------------------------------------------------------------"); 1.256 + 1.257 + populate(gensrc,"beta/B.java", 1.258 + "package beta; import alfa.A; public class B {"+ 1.259 + "private int b() { return A.DEFINITION; } "+ 1.260 + "@java.lang.annotation.Native final static int alfa = 43; }"); 1.261 + 1.262 + compile("gensrc", "-d", "bin", "-h", "headers", "-j", "1", 1.263 + "--server:portfile=testserver,background=false", "--log=debug"); 1.264 + Map<String,Long> new_bin_state = collectState(bin); 1.265 + verifyNewerFiles(previous_bin_state, new_bin_state, 1.266 + "bin/beta/B.class", 1.267 + "bin/beta/BINT.class", 1.268 + "bin/javac_state"); 1.269 + previous_bin_state = new_bin_state; 1.270 + 1.271 + Map<String,Long> new_headers_state = collectState(headers); 1.272 + verifyNewerFiles(previous_headers_state, new_headers_state, 1.273 + "headers/beta_B.h"); 1.274 + previous_headers_state = new_headers_state; 1.275 + } 1.276 + 1.277 + void compileWithOverrideSource() throws Exception { 1.278 + System.out.println("\nNow verify that we can override sources to be compiled."); 1.279 + System.out.println("Compile gensrc and gensrc2. However do not compile broken beta.B in gensrc,"); 1.280 + System.out.println("only compile ok beta.B in gensrc2."); 1.281 + System.out.println("---------------------------------------------------------------------------"); 1.282 + 1.283 + delete(gensrc); 1.284 + delete(gensrc2); 1.285 + delete(bin); 1.286 + previous_bin_state = collectState(bin); 1.287 + 1.288 + populate(gensrc,"alfa/A.java", 1.289 + "package alfa; import beta.B; import gamma.C; public class A { B b; C c; }", 1.290 + "beta/B.java", 1.291 + "package beta; public class B { broken", 1.292 + "gamma/C.java", 1.293 + "package gamma; public class C { }"); 1.294 + 1.295 + populate(gensrc2, 1.296 + "beta/B.java", 1.297 + "package beta; public class B { }"); 1.298 + 1.299 + compile("-x", "beta", "gensrc", "gensrc2", "-d", "bin", "-h", "headers", "-j", "1", 1.300 + "--server:portfile=testserver,background=false"); 1.301 + Map<String,Long> new_bin_state = collectState(bin); 1.302 + verifyThatFilesHaveBeenAdded(previous_bin_state, new_bin_state, 1.303 + "bin/alfa/A.class", 1.304 + "bin/beta/B.class", 1.305 + "bin/gamma/C.class", 1.306 + "bin/javac_state"); 1.307 + 1.308 + System.out.println("----- Compile with exluded beta went well!"); 1.309 + delete(bin); 1.310 + compileExpectFailure("gensrc", "gensrc2", "-d", "bin", "-h", "headers", "-j", "1", 1.311 + "--server:portfile=testserver,background=false"); 1.312 + 1.313 + System.out.println("----- Compile without exluded beta failed, as expected! Good!"); 1.314 + delete(bin); 1.315 + } 1.316 + 1.317 + void compileWithInvisibleSources() throws Exception { 1.318 + System.out.println("\nNow verify that we can make sources invisible to linking (sourcepath)."); 1.319 + System.out.println("Compile gensrc and link against gensrc2 and gensrc3, however"); 1.320 + System.out.println("gensrc2 contains broken code in beta.B, thus we must exclude that package"); 1.321 + System.out.println("fortunately gensrc3 contains a proper beta.B."); 1.322 + System.out.println("------------------------------------------------------------------------"); 1.323 + 1.324 + // Start with a fresh gensrcs and bin. 1.325 + delete(gensrc); 1.326 + delete(gensrc2); 1.327 + delete(gensrc3); 1.328 + delete(bin); 1.329 + previous_bin_state = collectState(bin); 1.330 + 1.331 + populate(gensrc,"alfa/A.java", 1.332 + "package alfa; import beta.B; import gamma.C; public class A { B b; C c; }"); 1.333 + populate(gensrc2,"beta/B.java", 1.334 + "package beta; public class B { broken", 1.335 + "gamma/C.java", 1.336 + "package gamma; public class C { }"); 1.337 + populate(gensrc3, "beta/B.java", 1.338 + "package beta; public class B { }"); 1.339 + 1.340 + compile("gensrc", "-x", "beta", "-sourcepath", "gensrc2", 1.341 + "-sourcepath", "gensrc3", "-d", "bin", "-h", "headers", "-j", "1", 1.342 + "--server:portfile=testserver,background=false"); 1.343 + 1.344 + System.out.println("The first compile went well!"); 1.345 + Map<String,Long> new_bin_state = collectState(bin); 1.346 + verifyThatFilesHaveBeenAdded(previous_bin_state, new_bin_state, 1.347 + "bin/alfa/A.class", 1.348 + "bin/javac_state"); 1.349 + 1.350 + System.out.println("----- Compile with exluded beta went well!"); 1.351 + delete(bin); 1.352 + compileExpectFailure("gensrc", "-sourcepath", "gensrc2", "-sourcepath", "gensrc3", 1.353 + "-d", "bin", "-h", "headers", "-j", "1", 1.354 + "--server:portfile=testserver,background=false"); 1.355 + 1.356 + System.out.println("----- Compile without exluded beta failed, as expected! Good!"); 1.357 + delete(bin); 1.358 + } 1.359 + 1.360 + void compileCircularSources() throws Exception { 1.361 + System.out.println("\nNow verify that circular sources split on multiple cores can be compiled."); 1.362 + System.out.println("---------------------------------------------------------------------------"); 1.363 + 1.364 + // Start with a fresh gensrcs and bin. 1.365 + delete(gensrc); 1.366 + delete(gensrc2); 1.367 + delete(gensrc3); 1.368 + delete(bin); 1.369 + previous_bin_state = collectState(bin); 1.370 + 1.371 + populate(gensrc,"alfa/A.java", 1.372 + "package alfa; public class A { beta.B b; }", 1.373 + "beta/B.java", 1.374 + "package beta; public class B { gamma.C c; }", 1.375 + "gamma/C.java", 1.376 + "package gamma; public class C { alfa.A a; }"); 1.377 + 1.378 + compile("gensrc", "-d", "bin", "-h", "headers", "-j", "3", 1.379 + "--server:portfile=testserver,background=false","--log=debug"); 1.380 + Map<String,Long> new_bin_state = collectState(bin); 1.381 + verifyThatFilesHaveBeenAdded(previous_bin_state, new_bin_state, 1.382 + "bin/alfa/A.class", 1.383 + "bin/beta/B.class", 1.384 + "bin/gamma/C.class", 1.385 + "bin/javac_state"); 1.386 + delete(bin); 1.387 + } 1.388 + 1.389 + /** 1.390 + * Tests compiling class A that depends on class B without compiling class B 1.391 + * @throws Exception If test fails 1.392 + */ 1.393 + void compileExcludingDependency() throws Exception { 1.394 + System.out.println("\nVerify that excluding classes from compilation but not from linking works."); 1.395 + System.out.println("---------------------------------------------------------------------------"); 1.396 + 1.397 + delete(gensrc); 1.398 + delete(bin); 1.399 + previous_bin_state = collectState(bin); 1.400 + 1.401 + populate(gensrc, 1.402 + "alfa/A.java", 1.403 + "package alfa; public class A { beta.B b; }", 1.404 + "beta/B.java", 1.405 + "package beta; public class B { }"); 1.406 + 1.407 + compile("-x", "beta", "-src", "gensrc", "-x", "alfa", "-sourcepath", "gensrc", 1.408 + "-d", "bin", "--server:portfile=testserver,background=false"); 1.409 + 1.410 + Map<String,Long> new_bin_state = collectState(bin); 1.411 + verifyThatFilesHaveBeenAdded(previous_bin_state, new_bin_state, 1.412 + "bin/alfa/A.class", 1.413 + "bin/javac_state"); 1.414 + } 1.415 + 1.416 + void removeFrom(Path dir, String... args) throws IOException { 1.417 + for (String filename : args) { 1.418 + Path p = dir.resolve(filename); 1.419 + Files.delete(p); 1.420 + } 1.421 + } 1.422 + 1.423 + void populate(Path src, String... args) throws IOException { 1.424 + if (!Files.exists(src)) { 1.425 + Files.createDirectory(src); 1.426 + } 1.427 + String[] a = args; 1.428 + for (int i = 0; i<a.length; i+=2) { 1.429 + String filename = a[i]; 1.430 + String content = a[i+1]; 1.431 + Path p = src.resolve(filename); 1.432 + Files.createDirectories(p.getParent()); 1.433 + PrintWriter out = new PrintWriter(Files.newBufferedWriter(p, 1.434 + Charset.defaultCharset())); 1.435 + out.println(content); 1.436 + out.close(); 1.437 + } 1.438 + } 1.439 + 1.440 + void delete(final Path root) throws IOException { 1.441 + if (!Files.exists(root)) return; 1.442 + Files.walkFileTree(root, new SimpleFileVisitor<Path>() { 1.443 + @Override 1.444 + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException 1.445 + { 1.446 + Files.delete(file); 1.447 + return FileVisitResult.CONTINUE; 1.448 + } 1.449 + 1.450 + @Override 1.451 + public FileVisitResult postVisitDirectory(Path dir, IOException e) throws IOException 1.452 + { 1.453 + if (e == null) { 1.454 + if (!dir.equals(root)) Files.delete(dir); 1.455 + return FileVisitResult.CONTINUE; 1.456 + } else { 1.457 + // directory iteration failed 1.458 + throw e; 1.459 + } 1.460 + } 1.461 + }); 1.462 + } 1.463 + 1.464 + void compile(String... args) throws Exception { 1.465 + int rc = main.go(args, System.out, System.err); 1.466 + if (rc != 0) throw new Exception("Error during compile!"); 1.467 + 1.468 + // Wait a second, to get around the (temporary) problem with 1.469 + // second resolution in the Java file api. But do not do this 1.470 + // on windows where the timestamps work. 1.471 + long in_a_sec = System.currentTimeMillis()+1000; 1.472 + while (in_a_sec > System.currentTimeMillis()) { 1.473 + try { 1.474 + Thread.sleep(1000); 1.475 + } catch (InterruptedException e) { 1.476 + } 1.477 + } 1.478 + } 1.479 + 1.480 + void compileExpectFailure(String... args) throws Exception { 1.481 + int rc = main.go(args, System.out, System.err); 1.482 + if (rc == 0) throw new Exception("Expected error during compile! Did not fail!"); 1.483 + } 1.484 + 1.485 + Map<String,Long> collectState(Path dir) throws IOException 1.486 + { 1.487 + final Map<String,Long> files = new HashMap<>(); 1.488 + Files.walkFileTree(dir, new SimpleFileVisitor<Path>() { 1.489 + @Override 1.490 + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) 1.491 + throws IOException 1.492 + { 1.493 + files.put(file.toString(),new Long(Files.getLastModifiedTime(file).toMillis())); 1.494 + return FileVisitResult.CONTINUE; 1.495 + } 1.496 + }); 1.497 + return files; 1.498 + } 1.499 + 1.500 + void verifyThatFilesHaveBeenRemoved(Map<String,Long> from, 1.501 + Map<String,Long> to, 1.502 + String... args) throws Exception { 1.503 + 1.504 + Set<String> froms = from.keySet(); 1.505 + Set<String> tos = to.keySet(); 1.506 + 1.507 + if (froms.equals(tos)) { 1.508 + throw new Exception("Expected new state to have fewer files than previous state!"); 1.509 + } 1.510 + 1.511 + for (String t : tos) { 1.512 + if (!froms.contains(t)) { 1.513 + throw new Exception("Expected "+t+" to exist in previous state!"); 1.514 + } 1.515 + } 1.516 + 1.517 + for (String f : args) { 1.518 + f = f.replace("/", File.separator); 1.519 + if (!froms.contains(f)) { 1.520 + throw new Exception("Expected "+f+" to exist in previous state!"); 1.521 + } 1.522 + if (tos.contains(f)) { 1.523 + throw new Exception("Expected "+f+" to have been removed from the new state!"); 1.524 + } 1.525 + } 1.526 + 1.527 + if (froms.size() - args.length != tos.size()) { 1.528 + throw new Exception("There are more removed files than the expected list!"); 1.529 + } 1.530 + } 1.531 + 1.532 + void verifyThatFilesHaveBeenAdded(Map<String,Long> from, 1.533 + Map<String,Long> to, 1.534 + String... args) throws Exception { 1.535 + 1.536 + Set<String> froms = from.keySet(); 1.537 + Set<String> tos = to.keySet(); 1.538 + 1.539 + if (froms.equals(tos)) { 1.540 + throw new Exception("Expected new state to have more files than previous state!"); 1.541 + } 1.542 + 1.543 + for (String t : froms) { 1.544 + if (!tos.contains(t)) { 1.545 + throw new Exception("Expected "+t+" to exist in new state!"); 1.546 + } 1.547 + } 1.548 + 1.549 + for (String f : args) { 1.550 + f = f.replace("/", File.separator); 1.551 + if (!tos.contains(f)) { 1.552 + throw new Exception("Expected "+f+" to have been added to new state!"); 1.553 + } 1.554 + if (froms.contains(f)) { 1.555 + throw new Exception("Expected "+f+" to not exist in previous state!"); 1.556 + } 1.557 + } 1.558 + 1.559 + if (froms.size() + args.length != tos.size()) { 1.560 + throw new Exception("There are more added files than the expected list!"); 1.561 + } 1.562 + } 1.563 + 1.564 + void verifyNewerFiles(Map<String,Long> from, 1.565 + Map<String,Long> to, 1.566 + String... args) throws Exception { 1.567 + if (!from.keySet().equals(to.keySet())) { 1.568 + throw new Exception("Expected the set of files to be identical!"); 1.569 + } 1.570 + Set<String> files = new HashSet<String>(); 1.571 + for (String s : args) { 1.572 + files.add(s.replace("/", File.separator)); 1.573 + } 1.574 + for (String fn : from.keySet()) { 1.575 + long f = from.get(fn); 1.576 + long t = to.get(fn); 1.577 + if (files.contains(fn)) { 1.578 + if (t <= f) { 1.579 + throw new Exception("Expected "+fn+" to have a more recent timestamp!"); 1.580 + } 1.581 + } else { 1.582 + if (t != f) { 1.583 + throw new Exception("Expected "+fn+" to have the same timestamp!"); 1.584 + } 1.585 + } 1.586 + } 1.587 + } 1.588 + 1.589 + String print(Map<String,Long> m) { 1.590 + StringBuilder b = new StringBuilder(); 1.591 + Set<String> keys = m.keySet(); 1.592 + for (String k : keys) { 1.593 + b.append(k+" "+m.get(k)+"\n"); 1.594 + } 1.595 + return b.toString(); 1.596 + } 1.597 + 1.598 + void verifyEqual(Map<String,Long> from, Map<String,Long> to) throws Exception { 1.599 + if (!from.equals(to)) { 1.600 + System.out.println("FROM---"+print(from)); 1.601 + System.out.println("TO-----"+print(to)); 1.602 + throw new Exception("The dir should not differ! But it does!"); 1.603 + } 1.604 + } 1.605 +}