author | akulyakh |
Thu, 21 May 2015 11:41:04 -0700 | |
changeset 30730 | d3ce7619db2c |
parent 28332 | cd3ea1087d2b |
permissions | -rw-r--r-- |
28332
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
1 |
/* |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
2 |
* Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
4 |
* |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
8 |
* |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
13 |
* accompanied this code). |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
14 |
* |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
18 |
* |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
21 |
* questions. |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
22 |
*/ |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
23 |
|
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
24 |
/* |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
25 |
* @test |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
26 |
* @bug 8059977 |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
27 |
* @summary StandardJavaFileManager should support java.nio.file.Path. |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
28 |
* Test isSameFile method. |
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
28332
diff
changeset
|
29 |
* @modules java.compiler |
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
28332
diff
changeset
|
30 |
* jdk.compiler |
28332
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
31 |
* @build SJFM_TestBase |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
32 |
* @run main SJFM_IsSameFile |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
33 |
*/ |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
34 |
|
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
35 |
import java.nio.file.Path; |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
36 |
import java.util.List; |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
37 |
import java.util.concurrent.Callable; |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
38 |
import javax.tools.JavaFileObject; |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
39 |
import javax.tools.StandardJavaFileManager; |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
40 |
|
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
41 |
/** |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
42 |
* For those paths which are supported by a file manager, such that |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
43 |
* a file object can encapsulate the path, verify that the underlying |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
44 |
* paths can be compared. |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
45 |
*/ |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
46 |
public class SJFM_IsSameFile extends SJFM_TestBase { |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
47 |
public static void main(String... args) throws Exception { |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
48 |
new SJFM_IsSameFile().run(); |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
49 |
} |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
50 |
|
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
51 |
@Test |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
52 |
void test_isSameFile(StandardJavaFileManager fm) throws Exception { |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
53 |
test_isSameFile(fm, () -> getTestFilePaths()); |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
54 |
test_isSameFile(fm, () -> getTestZipPaths()); |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
55 |
} |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
56 |
|
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
57 |
/** |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
58 |
* Tests the isSameFile method for a specific file manager |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
59 |
* and a series of paths. |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
60 |
* |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
61 |
* Note: instances of MyStandardJavaFileManager only support |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
62 |
* encapsulating paths for files in the default file system. |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
63 |
* |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
64 |
* @param fm the file manager to be tested |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
65 |
* @param paths a generator for the paths to be tested |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
66 |
* @throws IOException |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
67 |
*/ |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
68 |
void test_isSameFile(StandardJavaFileManager fm, Callable<List<Path>> paths) throws Exception { |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
69 |
if (!isGetFileObjectsSupported(fm, paths.call())) |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
70 |
return; |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
71 |
|
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
72 |
// use distinct paths and file objects in the following two sets |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
73 |
Iterable<? extends JavaFileObject> setA = fm.getJavaFileObjectsFromPaths(paths.call()); |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
74 |
Iterable<? extends JavaFileObject> setB = fm.getJavaFileObjectsFromPaths(paths.call()); |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
75 |
for (JavaFileObject a : setA) { |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
76 |
for (JavaFileObject b : setB) { |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
77 |
System.err.println("compare: a: " + a); |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
78 |
System.err.println(" b: " + b); |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
79 |
// Use the fileObject getName method to determine the expected result. |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
80 |
// For the files being tested, getName is the absolute path. |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
81 |
boolean expect = a.getName().equals(b.getName()); |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
82 |
boolean actual = fm.isSameFile(a, b); |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
83 |
if (actual != expect) { |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
84 |
error("mismatch: actual:" + (actual ? "same" : "not same") |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
85 |
+ ", expect:" + (expect ? "same" : "not same")); |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
86 |
} |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
87 |
} |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
88 |
} |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
89 |
} |
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
diff
changeset
|
90 |
} |