483 } 484 } 485 486 static FileFilter createFilter(final String extension) { 487 return new FileFilter() { 488 @Override 489 public boolean accept(File pathname) { 490 String name = pathname.getName(); 491 if (name.endsWith(extension)) { 492 return true; 493 } 494 return false; 495 } 496 }; 497 } 498 499 static boolean isEnglishLocale() { 500 return Locale.getDefault().getLanguage().equals("en"); 501 } 502 503 /* 504 * A class to encapsulate the test results and stuff, with some ease 505 * of use methods to check the test results. 506 */ 507 static class TestResult { 508 PrintWriter status; 509 StringWriter sw; 510 int exitValue; 511 List<String> testOutput; 512 Map<String, String> env; 513 Throwable t; 514 boolean testStatus; 515 516 public TestResult(String str, int rv, List<String> oList, 517 Map<String, String> env, Throwable t) { 518 sw = new StringWriter(); 519 status = new PrintWriter(sw); 520 status.println("Executed command: " + str + "\n"); 521 exitValue = rv; 522 testOutput = oList; | 483 } 484 } 485 486 static FileFilter createFilter(final String extension) { 487 return new FileFilter() { 488 @Override 489 public boolean accept(File pathname) { 490 String name = pathname.getName(); 491 if (name.endsWith(extension)) { 492 return true; 493 } 494 return false; 495 } 496 }; 497 } 498 499 static boolean isEnglishLocale() { 500 return Locale.getDefault().getLanguage().equals("en"); 501 } 502 503 /** 504 * Helper method to initialize a simple module that just prints the passed in arguments 505 */ 506 static void createEchoArgumentsModule(File modulesDir) throws IOException { 507 if (modulesDir.exists()) { 508 recursiveDelete(modulesDir); 509 } 510 511 modulesDir.mkdirs(); 512 513 File srcDir = new File(modulesDir, "src"); 514 File modsDir = new File(modulesDir, "mods"); 515 File testDir = new File(srcDir, "test"); 516 File launcherTestDir = new File(testDir, "launcher"); 517 srcDir.mkdir(); 518 modsDir.mkdir(); 519 testDir.mkdir(); 520 launcherTestDir.mkdir(); 521 522 String[] moduleInfoCode = { "module test {}" }; 523 createFile(new File(testDir, "module-info.java"), Arrays.asList(moduleInfoCode)); 524 525 String[] moduleCode = { 526 "package launcher;", 527 "import java.util.Arrays;", 528 "public class Main {", 529 "public static void main(String[] args) {", 530 "System.out.println(Arrays.toString(args));", 531 "}", 532 "}" 533 }; 534 createFile(new File(launcherTestDir, "Main.java"), Arrays.asList(moduleCode)); 535 } 536 537 /* 538 * A class to encapsulate the test results and stuff, with some ease 539 * of use methods to check the test results. 540 */ 541 static class TestResult { 542 PrintWriter status; 543 StringWriter sw; 544 int exitValue; 545 List<String> testOutput; 546 Map<String, String> env; 547 Throwable t; 548 boolean testStatus; 549 550 public TestResult(String str, int rv, List<String> oList, 551 Map<String, String> env, Throwable t) { 552 sw = new StringWriter(); 553 status = new PrintWriter(sw); 554 status.println("Executed command: " + str + "\n"); 555 exitValue = rv; 556 testOutput = oList; |