31 * jdk.compiler/com.sun.tools.javac.main 32 * @build toolbox.JavacTask toolbox.ToolBox 33 * @run main GetLocationForModuleTest 34 */ 35 36 import java.io.IOException; 37 import java.nio.file.*; 38 import java.util.*; 39 import javax.tools.*; 40 import toolbox.JavacTask; 41 import toolbox.ToolBox; 42 43 public class GetLocationForModuleTest extends ModuleTestBase { 44 public static void main(String... args) throws Exception { 45 new GetLocationForModuleTest().run(Paths.get(".")); 46 } 47 48 public void run(Path base) throws Exception { 49 // Set up some trivial modules 50 Path moduleSrc = base.resolve("module-src"); 51 Path m1 = moduleSrc.resolve("m1"); 52 tb.writeJavaFiles(m1, "module m1 { }"); 53 Path m2 = moduleSrc.resolve("m2"); 54 tb.writeJavaFiles(m2, "module m2 { }"); 55 56 Path modulePath = base.resolve("module-path"); 57 Files.createDirectories(modulePath); 58 new JavacTask(tb) 59 .options("--module-source-path", moduleSrc.toString()) 60 .outdir(modulePath) 61 .files(findJavaFiles(moduleSrc)) 62 .run() 63 .writeAll(); 64 65 // Init file manager 66 StandardJavaFileManager fm = 67 ToolProvider.getSystemJavaCompiler().getStandardFileManager(null, null, null); 68 fm.setLocationFromPaths(StandardLocation.MODULE_PATH, Arrays.asList(modulePath)); 69 70 // Test 71 test(fm, StandardLocation.SYSTEM_MODULES, "java.base", "java.compiler"); 72 test(fm, StandardLocation.MODULE_PATH, "m1", "m2"); 73 } 74 75 void test(JavaFileManager fm, JavaFileManager.Location locn, String... mods) throws IOException { 76 for (String mod : mods) { 77 JavaFileManager.Location modLocn = fm.getLocationForModule(locn, mod); 78 if (modLocn == null) { 79 error(locn.getName() + ": can't find " + mod); 80 } else { 81 System.err.println(locn.getName() + ": found " + mod + ": " + modLocn.getName()); 82 } 83 } 84 } 85 } 86 | 31 * jdk.compiler/com.sun.tools.javac.main 32 * @build toolbox.JavacTask toolbox.ToolBox 33 * @run main GetLocationForModuleTest 34 */ 35 36 import java.io.IOException; 37 import java.nio.file.*; 38 import java.util.*; 39 import javax.tools.*; 40 import toolbox.JavacTask; 41 import toolbox.ToolBox; 42 43 public class GetLocationForModuleTest extends ModuleTestBase { 44 public static void main(String... args) throws Exception { 45 new GetLocationForModuleTest().run(Paths.get(".")); 46 } 47 48 public void run(Path base) throws Exception { 49 // Set up some trivial modules 50 Path moduleSrc = base.resolve("module-src"); 51 Path m1 = moduleSrc.resolve("m1x"); 52 tb.writeJavaFiles(m1, "module m1x { }"); 53 Path m2 = moduleSrc.resolve("m2x"); 54 tb.writeJavaFiles(m2, "module m2x { }"); 55 56 Path modulePath = base.resolve("module-path"); 57 Files.createDirectories(modulePath); 58 new JavacTask(tb) 59 .options("--module-source-path", moduleSrc.toString()) 60 .outdir(modulePath) 61 .files(findJavaFiles(moduleSrc)) 62 .run() 63 .writeAll(); 64 65 // Init file manager 66 StandardJavaFileManager fm = 67 ToolProvider.getSystemJavaCompiler().getStandardFileManager(null, null, null); 68 fm.setLocationFromPaths(StandardLocation.MODULE_PATH, Arrays.asList(modulePath)); 69 70 // Test 71 test(fm, StandardLocation.SYSTEM_MODULES, "java.base", "java.compiler"); 72 test(fm, StandardLocation.MODULE_PATH, "m1x", "m2x"); 73 } 74 75 void test(JavaFileManager fm, JavaFileManager.Location locn, String... mods) throws IOException { 76 for (String mod : mods) { 77 JavaFileManager.Location modLocn = fm.getLocationForModule(locn, mod); 78 if (modLocn == null) { 79 error(locn.getName() + ": can't find " + mod); 80 } else { 81 System.err.println(locn.getName() + ": found " + mod + ": " + modLocn.getName()); 82 } 83 } 84 } 85 } 86 |