author | avstepan |
Tue, 19 May 2015 16:04:14 +0400 | |
changeset 30655 | d83f50188ca9 |
parent 27319 | 030080f03e4f |
child 30730 | d3ce7619db2c |
permissions | -rw-r--r-- |
10 | 1 |
/* |
27319
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
13631
diff
changeset
|
2 |
* Copyright (c) 2006, 2014, 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 |
|
29 |
*/ |
|
30 |
||
31 |
import java.io.File; |
|
11384 | 32 |
import java.net.URI; |
10 | 33 |
import java.util.Arrays; |
34 |
import javax.tools.*; |
|
35 |
import javax.tools.JavaFileManager.Location; |
|
36 |
||
37 |
import static javax.tools.StandardLocation.CLASS_OUTPUT; |
|
38 |
||
39 |
public class T6397104 { |
|
40 |
||
41 |
JavaCompiler tool = ToolProvider.getSystemJavaCompiler(); |
|
42 |
||
43 |
void test(StandardJavaFileManager fm, |
|
44 |
Location location, |
|
45 |
File siblingFile, |
|
46 |
String relName, |
|
47 |
String expectedPath) |
|
48 |
throws Exception |
|
49 |
{ |
|
50 |
JavaFileObject sibling = siblingFile == null |
|
51 |
? null |
|
52 |
: fm.getJavaFileObjectsFromFiles(Arrays.asList(siblingFile)).iterator().next(); |
|
53 |
FileObject fileObject = |
|
54 |
fm.getFileForOutput(location, "java.lang", relName, sibling); |
|
11384 | 55 |
|
56 |
File expectedFile = new File(expectedPath).getCanonicalFile(); |
|
57 |
File fileObjectFile = new File(fileObject.toUri()).getCanonicalFile(); |
|
58 |
||
59 |
if (!fileObjectFile.equals(expectedFile)) |
|
60 |
throw new AssertionError("Expected " + expectedFile + |
|
61 |
", got " + fileObjectFile); |
|
62 |
System.out.format("OK: (%s, %s) => %s%n", siblingFile, relName, fileObjectFile); |
|
10 | 63 |
} |
64 |
||
65 |
void test(boolean hasLocation, File siblingFile, String relName, String expectedPath) |
|
66 |
throws Exception |
|
67 |
{ |
|
27319
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
13631
diff
changeset
|
68 |
try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) { |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
13631
diff
changeset
|
69 |
if (hasLocation) { |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
13631
diff
changeset
|
70 |
for (Location location : StandardLocation.values()) { |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
13631
diff
changeset
|
71 |
fm.setLocation(location, Arrays.asList(new File("."))); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
13631
diff
changeset
|
72 |
test(fm, location, siblingFile, relName, expectedPath); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
13631
diff
changeset
|
73 |
} |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
13631
diff
changeset
|
74 |
} else { |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
13631
diff
changeset
|
75 |
test(fm, CLASS_OUTPUT, siblingFile, relName, expectedPath); |
10 | 76 |
} |
77 |
} |
|
78 |
} |
|
79 |
||
80 |
public static void main(String... args) throws Exception { |
|
81 |
T6397104 tester = new T6397104(); |
|
82 |
tester.test(false, |
|
83 |
new File(new File("foo", "bar"), "baz.java"), |
|
84 |
"qux/baz.xml", |
|
85 |
"foo/bar/baz.xml"); |
|
86 |
tester.test(false, |
|
87 |
null, |
|
88 |
"qux/baz.xml", |
|
89 |
"baz.xml"); // sb "java/lang/qux/baz.xml" |
|
90 |
tester.test(true, |
|
91 |
new File(new File("foo", "bar"), "baz.java"), |
|
92 |
"qux/baz.xml", |
|
93 |
"./java/lang/qux/baz.xml"); |
|
94 |
tester.test(true, |
|
95 |
null, |
|
96 |
"qux/baz.xml", |
|
97 |
"./java/lang/qux/baz.xml"); |
|
98 |
} |
|
99 |
||
100 |
} |