421 .outdir(classes) |
421 .outdir(classes) |
422 .files(findJavaFiles(src)) |
422 .files(findJavaFiles(src)) |
423 .run() |
423 .run() |
424 .writeAll(); |
424 .writeAll(); |
425 } |
425 } |
|
426 |
|
427 @Test |
|
428 public void testLintRequireAutomatic(Path base) throws Exception { |
|
429 Path modulePath = base.resolve("module-path"); |
|
430 |
|
431 Files.createDirectories(modulePath); |
|
432 |
|
433 for (char c : new char[] {'A', 'B'}) { |
|
434 Path automaticSrc = base.resolve("automaticSrc" + c); |
|
435 tb.writeJavaFiles(automaticSrc, "package api" + c + "; public class Api {}"); |
|
436 Path automaticClasses = base.resolve("automaticClasses" + c); |
|
437 tb.createDirectories(automaticClasses); |
|
438 |
|
439 String automaticLog = new JavacTask(tb) |
|
440 .outdir(automaticClasses) |
|
441 .files(findJavaFiles(automaticSrc)) |
|
442 .run() |
|
443 .writeAll() |
|
444 .getOutput(Task.OutputKind.DIRECT); |
|
445 |
|
446 if (!automaticLog.isEmpty()) |
|
447 throw new Exception("expected output not found: " + automaticLog); |
|
448 |
|
449 Path automaticJar = modulePath.resolve("automatic" + c + "-1.0.jar"); |
|
450 |
|
451 new JarTask(tb, automaticJar) |
|
452 .baseDir(automaticClasses) |
|
453 .files("api" + c + "/Api.class") |
|
454 .run(); |
|
455 } |
|
456 |
|
457 Path src = base.resolve("src"); |
|
458 |
|
459 tb.writeJavaFiles(src, |
|
460 "module m1x {\n" + |
|
461 " requires transitive automaticA;\n" + |
|
462 " requires automaticB;\n" + |
|
463 "}"); |
|
464 |
|
465 Path classes = base.resolve("classes"); |
|
466 |
|
467 Files.createDirectories(classes); |
|
468 |
|
469 List<String> expected; |
|
470 List<String> log; |
|
471 |
|
472 log = new JavacTask(tb) |
|
473 .options("--source-path", src.toString(), |
|
474 "--module-path", modulePath.toString(), |
|
475 "-XDrawDiagnostics", |
|
476 "-Werror") |
|
477 .outdir(classes) |
|
478 .files(findJavaFiles(src)) |
|
479 .run(Task.Expect.FAIL) |
|
480 .writeAll() |
|
481 .getOutputLines(Task.OutputKind.DIRECT); |
|
482 |
|
483 expected = Arrays.asList("module-info.java:2:25: compiler.warn.requires.transitive.automatic", |
|
484 "- compiler.err.warnings.and.werror", |
|
485 "1 error", |
|
486 "1 warning"); |
|
487 |
|
488 if (!expected.equals(log)) { |
|
489 throw new Exception("expected output not found: " + log); |
|
490 } |
|
491 |
|
492 log = new JavacTask(tb) |
|
493 .options("--source-path", src.toString(), |
|
494 "--module-path", modulePath.toString(), |
|
495 "-Xlint:requires-automatic", |
|
496 "-XDrawDiagnostics", |
|
497 "-Werror") |
|
498 .outdir(classes) |
|
499 .files(findJavaFiles(src)) |
|
500 .run(Task.Expect.FAIL) |
|
501 .writeAll() |
|
502 .getOutputLines(Task.OutputKind.DIRECT); |
|
503 |
|
504 expected = Arrays.asList("module-info.java:2:25: compiler.warn.requires.transitive.automatic", |
|
505 "module-info.java:3:14: compiler.warn.requires.automatic", |
|
506 "- compiler.err.warnings.and.werror", |
|
507 "1 error", |
|
508 "2 warnings"); |
|
509 |
|
510 if (!expected.equals(log)) { |
|
511 throw new Exception("expected output not found: " + log); |
|
512 } |
|
513 |
|
514 log = new JavacTask(tb) |
|
515 .options("--source-path", src.toString(), |
|
516 "--module-path", modulePath.toString(), |
|
517 "-Xlint:-requires-transitive-automatic,requires-automatic", |
|
518 "-XDrawDiagnostics", |
|
519 "-Werror") |
|
520 .outdir(classes) |
|
521 .files(findJavaFiles(src)) |
|
522 .run(Task.Expect.FAIL) |
|
523 .writeAll() |
|
524 .getOutputLines(Task.OutputKind.DIRECT); |
|
525 |
|
526 expected = Arrays.asList("module-info.java:2:25: compiler.warn.requires.automatic", |
|
527 "module-info.java:3:14: compiler.warn.requires.automatic", |
|
528 "- compiler.err.warnings.and.werror", |
|
529 "1 error", |
|
530 "2 warnings"); |
|
531 |
|
532 if (!expected.equals(log)) { |
|
533 throw new Exception("expected output not found: " + log); |
|
534 } |
|
535 |
|
536 new JavacTask(tb) |
|
537 .options("--source-path", src.toString(), |
|
538 "--module-path", modulePath.toString(), |
|
539 "-Xlint:-requires-transitive-automatic", |
|
540 "-XDrawDiagnostics", |
|
541 "-Werror") |
|
542 .outdir(classes) |
|
543 .files(findJavaFiles(src)) |
|
544 .run(Task.Expect.SUCCESS) |
|
545 .writeAll() |
|
546 .getOutputLines(Task.OutputKind.DIRECT); |
|
547 |
|
548 tb.writeJavaFiles(src, |
|
549 "@SuppressWarnings(\"requires-transitive-automatic\")\n" + |
|
550 "module m1x {\n" + |
|
551 " requires transitive automaticA;\n" + |
|
552 " requires automaticB;\n" + |
|
553 "}"); |
|
554 |
|
555 new JavacTask(tb) |
|
556 .options("--source-path", src.toString(), |
|
557 "--module-path", modulePath.toString(), |
|
558 "-XDrawDiagnostics", |
|
559 "-Werror") |
|
560 .outdir(classes) |
|
561 .files(findJavaFiles(src)) |
|
562 .run(Task.Expect.SUCCESS) |
|
563 .writeAll() |
|
564 .getOutputLines(Task.OutputKind.DIRECT); |
|
565 |
|
566 log = new JavacTask(tb) |
|
567 .options("--source-path", src.toString(), |
|
568 "--module-path", modulePath.toString(), |
|
569 "-Xlint:requires-automatic", |
|
570 "-XDrawDiagnostics", |
|
571 "-Werror") |
|
572 .outdir(classes) |
|
573 .files(findJavaFiles(src)) |
|
574 .run(Task.Expect.FAIL) |
|
575 .writeAll() |
|
576 .getOutputLines(Task.OutputKind.DIRECT); |
|
577 |
|
578 expected = Arrays.asList("module-info.java:3:25: compiler.warn.requires.automatic", |
|
579 "module-info.java:4:14: compiler.warn.requires.automatic", |
|
580 "- compiler.err.warnings.and.werror", |
|
581 "1 error", |
|
582 "2 warnings"); |
|
583 |
|
584 if (!expected.equals(log)) { |
|
585 throw new Exception("expected output not found: " + log); |
|
586 } |
|
587 |
|
588 tb.writeJavaFiles(src, |
|
589 "@SuppressWarnings(\"requires-automatic\")\n" + |
|
590 "module m1x {\n" + |
|
591 " requires transitive automaticA;\n" + |
|
592 " requires automaticB;\n" + |
|
593 "}"); |
|
594 |
|
595 log = new JavacTask(tb) |
|
596 .options("--source-path", src.toString(), |
|
597 "--module-path", modulePath.toString(), |
|
598 "-Xlint:requires-automatic", |
|
599 "-XDrawDiagnostics", |
|
600 "-Werror") |
|
601 .outdir(classes) |
|
602 .files(findJavaFiles(src)) |
|
603 .run(Task.Expect.FAIL) |
|
604 .writeAll() |
|
605 .getOutputLines(Task.OutputKind.DIRECT); |
|
606 |
|
607 expected = Arrays.asList("module-info.java:3:25: compiler.warn.requires.transitive.automatic", |
|
608 "- compiler.err.warnings.and.werror", |
|
609 "1 error", |
|
610 "1 warning"); |
|
611 |
|
612 if (!expected.equals(log)) { |
|
613 throw new Exception("expected output not found: " + log); |
|
614 } |
|
615 } |
|
616 |
426 } |
617 } |