author | duke |
Wed, 05 Jul 2017 23:01:50 +0200 (2017-07-05) | |
changeset 44228 | e46434c65a2b |
parent 42261 | bb52b5514ad5 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
36526 | 2 |
* Copyright (c) 2006, 2016, Oracle and/or its affiliates. All rights reserved. |
10 | 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 |
* |
|
5520 | 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. |
|
10 | 22 |
*/ |
23 |
||
24 |
/** |
|
25 |
* @test |
|
26 |
* @bug 6397104 |
|
27 |
* @summary JSR 199: JavaFileManager.getFileForOutput should have sibling argument |
|
28 |
* @author Peter von der Ah\u00e9 |
|
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
27319
diff
changeset
|
29 |
* @modules java.compiler |
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
27319
diff
changeset
|
30 |
* jdk.compiler |
10 | 31 |
*/ |
32 |
||
33 |
import java.io.File; |
|
11384 | 34 |
import java.net.URI; |
10 | 35 |
import java.util.Arrays; |
36 |
import javax.tools.*; |
|
37 |
import javax.tools.JavaFileManager.Location; |
|
38 |
||
39 |
import static javax.tools.StandardLocation.CLASS_OUTPUT; |
|
40 |
||
41 |
public class T6397104 { |
|
42 |
||
43 |
JavaCompiler tool = ToolProvider.getSystemJavaCompiler(); |
|
44 |
||
45 |
void test(StandardJavaFileManager fm, |
|
46 |
Location location, |
|
47 |
File siblingFile, |
|
48 |
String relName, |
|
49 |
String expectedPath) |
|
50 |
throws Exception |
|
51 |
{ |
|
52 |
JavaFileObject sibling = siblingFile == null |
|
53 |
? null |
|
54 |
: fm.getJavaFileObjectsFromFiles(Arrays.asList(siblingFile)).iterator().next(); |
|
55 |
FileObject fileObject = |
|
56 |
fm.getFileForOutput(location, "java.lang", relName, sibling); |
|
11384 | 57 |
|
58 |
File expectedFile = new File(expectedPath).getCanonicalFile(); |
|
59 |
File fileObjectFile = new File(fileObject.toUri()).getCanonicalFile(); |
|
60 |
||
61 |
if (!fileObjectFile.equals(expectedFile)) |
|
62 |
throw new AssertionError("Expected " + expectedFile + |
|
63 |
", got " + fileObjectFile); |
|
36526 | 64 |
System.err.format("OK: (%s, %s) => %s%n", siblingFile, relName, fileObjectFile); |
10 | 65 |
} |
66 |
||
67 |
void test(boolean hasLocation, File siblingFile, String relName, String expectedPath) |
|
68 |
throws Exception |
|
69 |
{ |
|
36526 | 70 |
System.err.format("test: hasLocation:%s, siblingFile:%s, relName:%s, expectedPath:%s%n", |
71 |
hasLocation, siblingFile, relName, expectedPath); |
|
27319
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
13631
diff
changeset
|
72 |
try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) { |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
13631
diff
changeset
|
73 |
if (hasLocation) { |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
13631
diff
changeset
|
74 |
for (Location location : StandardLocation.values()) { |
36526 | 75 |
System.err.format(" location:%s, moduleLocn:%b%n", |
42261
bb52b5514ad5
8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents:
36526
diff
changeset
|
76 |
location, location.isModuleOrientedLocation()); |
bb52b5514ad5
8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents:
36526
diff
changeset
|
77 |
if (!location.isOutputLocation()) { |
36526 | 78 |
continue; |
79 |
} |
|
27319
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
13631
diff
changeset
|
80 |
fm.setLocation(location, Arrays.asList(new File("."))); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
13631
diff
changeset
|
81 |
test(fm, location, siblingFile, relName, expectedPath); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
13631
diff
changeset
|
82 |
} |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
13631
diff
changeset
|
83 |
} else { |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
13631
diff
changeset
|
84 |
test(fm, CLASS_OUTPUT, siblingFile, relName, expectedPath); |
10 | 85 |
} |
86 |
} |
|
87 |
} |
|
88 |
||
89 |
public static void main(String... args) throws Exception { |
|
90 |
T6397104 tester = new T6397104(); |
|
91 |
tester.test(false, |
|
92 |
new File(new File("foo", "bar"), "baz.java"), |
|
93 |
"qux/baz.xml", |
|
94 |
"foo/bar/baz.xml"); |
|
95 |
tester.test(false, |
|
96 |
null, |
|
97 |
"qux/baz.xml", |
|
98 |
"baz.xml"); // sb "java/lang/qux/baz.xml" |
|
99 |
tester.test(true, |
|
100 |
new File(new File("foo", "bar"), "baz.java"), |
|
101 |
"qux/baz.xml", |
|
102 |
"./java/lang/qux/baz.xml"); |
|
103 |
tester.test(true, |
|
104 |
null, |
|
105 |
"qux/baz.xml", |
|
106 |
"./java/lang/qux/baz.xml"); |
|
107 |
} |
|
108 |
||
109 |
} |