langtools/test/tools/javac/modules/PackageConflictTest.java
changeset 45682 fc3b228b9e2a
parent 42822 a84956e7ee4d
equal deleted inserted replaced
45600:6589d4088eaa 45682:fc3b228b9e2a
     1 /*
     1 /*
     2  * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
   275                 "DependsOnM.java:1:55: compiler.err.cant.resolve.location: kindname.variable, flagM, , , (compiler.misc.location: kindname.class, pkg.A, null)");
   275                 "DependsOnM.java:1:55: compiler.err.cant.resolve.location: kindname.variable, flagM, , , (compiler.misc.location: kindname.class, pkg.A, null)");
   276         if (!output.containsAll(expected)) {
   276         if (!output.containsAll(expected)) {
   277             throw new Exception("expected output not found");
   277             throw new Exception("expected output not found");
   278         }
   278         }
   279     }
   279     }
       
   280 
       
   281     @Test
       
   282     public void testConflictInDependenciesInUnnamed(Path base) throws Exception {
       
   283         Path msp = base.resolve("module-path-source");
       
   284         Path m1 = msp.resolve("m1x");
       
   285         Path m2 = msp.resolve("m2x");
       
   286         tb.writeJavaFiles(m1,
       
   287                           "module m1x { exports test; }",
       
   288                           "package test; public class A { }");
       
   289         tb.writeJavaFiles(m2,
       
   290                           "module m2x { exports test; }",
       
   291                           "package test; public class B { }");
       
   292         Path mp = base.resolve("module-path");
       
   293         Files.createDirectories(mp);
       
   294 
       
   295         new JavacTask(tb)
       
   296             .options("--module-source-path", msp.toString())
       
   297             .outdir(mp)
       
   298             .files(findJavaFiles(msp))
       
   299             .run()
       
   300             .writeAll();
       
   301 
       
   302         Path src = base.resolve("src");
       
   303 
       
   304         tb.writeJavaFiles(src,
       
   305                           "package impl; public class Impl { }");
       
   306 
       
   307         Path out = base.resolve("out");
       
   308         Files.createDirectories(out);
       
   309 
       
   310         List<String> log = new JavacTask(tb)
       
   311                        .options("-XDrawDiagnostic",
       
   312                                 "--module-path", mp.toString(),
       
   313                                 "--add-modules", "ALL-MODULE-PATH")
       
   314                        .outdir(out)
       
   315                        .files(findJavaFiles(src))
       
   316                        .run(Task.Expect.FAIL)
       
   317                        .writeAll()
       
   318                        .getOutputLines(Task.OutputKind.DIRECT);
       
   319 
       
   320         List<String> expected1 =
       
   321                 Arrays.asList("error: the unnamed module reads package test from both m1x and m2x",
       
   322                               "1 error");
       
   323 
       
   324         List<String> expected2 =
       
   325                 Arrays.asList("error: the unnamed module reads package test from both m2x and m1x",
       
   326                               "1 error");
       
   327 
       
   328         if (!expected1.equals(log) && !expected2.equals(log)) {
       
   329             throw new AssertionError("Unexpected output: " + log);
       
   330         }
       
   331     }
       
   332 
   280 }
   333 }