GetLocationForModuleTest.java revision 3799:7282b1bc25f2
1116742Ssam/* 2116904Ssam * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. 3186904Ssam * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4116742Ssam * 5116742Ssam * This code is free software; you can redistribute it and/or modify it 6116742Ssam * under the terms of the GNU General Public License version 2 only, as 7116742Ssam * published by the Free Software Foundation. 8116742Ssam * 9116742Ssam * This code is distributed in the hope that it will be useful, but WITHOUT 10116904Ssam * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11116904Ssam * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12116904Ssam * version 2 for more details (a copy is included in the LICENSE file that 13116904Ssam * accompanied this code). 14116742Ssam * 15116904Ssam * You should have received a copy of the GNU General Public License version 16116904Ssam * 2 along with this work; if not, write to the Free Software Foundation, 17116904Ssam * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18116904Ssam * 19116904Ssam * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20116904Ssam * or visit www.oracle.com if you need additional information or have any 21116904Ssam * questions. 22116904Ssam */ 23116904Ssam 24116904Ssam/* 25116742Ssam * @test 26116742Ssam * @bug 8162712 27116742Ssam * @summary StandardJavaFileManager.getModuleLocation() can't find a module 28116742Ssam * @library /tools/lib 29116742Ssam * @modules 30178354Ssam * jdk.compiler/com.sun.tools.javac.api 31178354Ssam * jdk.compiler/com.sun.tools.javac.main 32116742Ssam * @build toolbox.JavacTask toolbox.ToolBox 33138568Ssam * @run main GetLocationForModuleTest 34116742Ssam */ 35116742Ssam 36138568Ssamimport java.io.IOException; 37142283Ssamimport java.nio.file.*; 38138568Ssamimport java.util.*; 39116742Ssamimport javax.tools.*; 40178354Ssamimport toolbox.JavacTask; 41178354Ssamimport toolbox.ToolBox; 42116742Ssam 43178354Ssampublic class GetLocationForModuleTest extends ModuleTestBase { 44116742Ssam public static void main(String... args) throws Exception { 45138568Ssam new GetLocationForModuleTest().run(Paths.get(".")); 46116742Ssam } 47116742Ssam 48178354Ssam public void run(Path base) throws Exception { 49195618Srpaulo // Set up some trivial modules 50195618Srpaulo Path moduleSrc = base.resolve("module-src"); 51195618Srpaulo Path m1 = moduleSrc.resolve("m1"); 52116742Ssam tb.writeJavaFiles(m1, "module m1 { }"); 53116742Ssam Path m2 = moduleSrc.resolve("m2"); 54116742Ssam tb.writeJavaFiles(m2, "module m2 { }"); 55178354Ssam 56178354Ssam Path modulePath = base.resolve("module-path"); 57178354Ssam Files.createDirectories(modulePath); 58178354Ssam new JavacTask(tb) 59116742Ssam .options("--module-source-path", moduleSrc.toString()) 60220445Sadrian .outdir(modulePath) 61220445Sadrian .files(findJavaFiles(moduleSrc)) 62220445Sadrian .run() 63220445Sadrian .writeAll(); 64220445Sadrian 65220445Sadrian // Init file manager 66220445Sadrian StandardJavaFileManager fm = 67220445Sadrian ToolProvider.getSystemJavaCompiler().getStandardFileManager(null, null, null); 68220445Sadrian fm.setLocationFromPaths(StandardLocation.MODULE_PATH, Arrays.asList(modulePath)); 69220445Sadrian 70220445Sadrian // Test 71220445Sadrian test(fm, StandardLocation.SYSTEM_MODULES, "java.base", "java.compiler"); 72220445Sadrian test(fm, StandardLocation.MODULE_PATH, "m1", "m2"); 73220445Sadrian } 74220445Sadrian 75220445Sadrian void test(JavaFileManager fm, JavaFileManager.Location locn, String... mods) throws IOException { 76220445Sadrian for (String mod : mods) { 77220445Sadrian JavaFileManager.Location modLocn = fm.getLocationForModule(locn, mod); 78220445Sadrian if (modLocn == null) { 79220445Sadrian error(locn.getName() + ": can't find " + mod); 80220445Sadrian } else { 81220445Sadrian System.err.println(locn.getName() + ": found " + mod + ": " + modLocn.getName()); 82220445Sadrian } 83220445Sadrian } 84144616Ssam } 85220445Sadrian} 86220445Sadrian 87220445Sadrian