1 /*
2 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
112 @Test
113 public void testJarFSPath(Path base) throws IOException {
114 // Test that we can look up in non-default file systems on the search path,
115 // such as an open jar file system.
116 Path src = base.resolve("src");
117 tb.writeJavaFiles(src, "package p; class C { }");
118 Path classes = Files.createDirectories(base.resolve("classes"));
119 new JavacTask(tb)
120 .options("-sourcepath", src.toString())
121 .outdir(classes)
122 .files(findJavaFiles(src))
123 .run()
124 .writeAll();
125
126 Path jar = base.resolve("classes.jar");
127 new JarTask(tb).run("cf", jar.toString(), "-C", classes.toString(), "p");
128
129 Path c = src.resolve("p/C.java");
130 Path x = base.resolve("src2/p/C.java");
131
132 try (FileSystem jarFS = FileSystems.newFileSystem(jar, null);
133 StandardJavaFileManager fm = javaCompiler.getStandardFileManager(null, null, null)) {
134 Path jarRoot = jarFS.getRootDirectories().iterator().next();
135 fm.setLocationFromPaths(StandardLocation.CLASS_PATH, List.of(src, jarRoot));
136
137 checkContains(fm, StandardLocation.CLASS_PATH, c, true);
138 checkContains(fm, StandardLocation.CLASS_PATH, x, false);
139
140 JavaFileObject fo = fm.list(StandardLocation.CLASS_PATH, "p",
141 EnumSet.of(JavaFileObject.Kind.CLASS), false).iterator().next();
142
143 checkContains(fm, StandardLocation.CLASS_PATH, fo, true);
144 checkContains(fm, StandardLocation.CLASS_PATH, jarRoot.resolve("p/C.class"), true);
145 }
146 }
147
148 void checkContains(StandardJavaFileManager fm, Location l, Path p, boolean expect) throws IOException {
149 JavaFileObject fo = fm.getJavaFileObjects(p).iterator().next();
150 checkContains(fm, l, fo, expect);
151 }
152
|
1 /*
2 * Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
112 @Test
113 public void testJarFSPath(Path base) throws IOException {
114 // Test that we can look up in non-default file systems on the search path,
115 // such as an open jar file system.
116 Path src = base.resolve("src");
117 tb.writeJavaFiles(src, "package p; class C { }");
118 Path classes = Files.createDirectories(base.resolve("classes"));
119 new JavacTask(tb)
120 .options("-sourcepath", src.toString())
121 .outdir(classes)
122 .files(findJavaFiles(src))
123 .run()
124 .writeAll();
125
126 Path jar = base.resolve("classes.jar");
127 new JarTask(tb).run("cf", jar.toString(), "-C", classes.toString(), "p");
128
129 Path c = src.resolve("p/C.java");
130 Path x = base.resolve("src2/p/C.java");
131
132 try (FileSystem jarFS = FileSystems.newFileSystem(jar, (ClassLoader)null);
133 StandardJavaFileManager fm = javaCompiler.getStandardFileManager(null, null, null)) {
134 Path jarRoot = jarFS.getRootDirectories().iterator().next();
135 fm.setLocationFromPaths(StandardLocation.CLASS_PATH, List.of(src, jarRoot));
136
137 checkContains(fm, StandardLocation.CLASS_PATH, c, true);
138 checkContains(fm, StandardLocation.CLASS_PATH, x, false);
139
140 JavaFileObject fo = fm.list(StandardLocation.CLASS_PATH, "p",
141 EnumSet.of(JavaFileObject.Kind.CLASS), false).iterator().next();
142
143 checkContains(fm, StandardLocation.CLASS_PATH, fo, true);
144 checkContains(fm, StandardLocation.CLASS_PATH, jarRoot.resolve("p/C.class"), true);
145 }
146 }
147
148 void checkContains(StandardJavaFileManager fm, Location l, Path p, boolean expect) throws IOException {
149 JavaFileObject fo = fm.getJavaFileObjects(p).iterator().next();
150 checkContains(fm, l, fo, expect);
151 }
152
|