author | amurillo |
Thu, 13 Aug 2015 15:50:52 -0700 | |
changeset 32224 | dae855d05f6c |
parent 30730 | d3ce7619db2c |
child 32335 | 7df616378cf3 |
permissions | -rw-r--r-- |
24067
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
1 |
/* |
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
27579
diff
changeset
|
2 |
* Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. |
24067
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
4 |
* |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
10 |
* |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
15 |
* accompanied this code). |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
16 |
* |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
20 |
* |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
23 |
* questions. |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
24 |
*/ |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
25 |
|
25603
d5fa4eab2d26
8046824: class SJavacTestUtil and *Wrapper are redundant and should be removed
jjg
parents:
24067
diff
changeset
|
26 |
/* |
d5fa4eab2d26
8046824: class SJavacTestUtil and *Wrapper are redundant and should be removed
jjg
parents:
24067
diff
changeset
|
27 |
* @test |
26089 | 28 |
* @bug 8035063 8054465 |
25603
d5fa4eab2d26
8046824: class SJavacTestUtil and *Wrapper are redundant and should be removed
jjg
parents:
24067
diff
changeset
|
29 |
* @summary Tests decoding of String[] into Options. |
d5fa4eab2d26
8046824: class SJavacTestUtil and *Wrapper are redundant and should be removed
jjg
parents:
24067
diff
changeset
|
30 |
* |
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
27579
diff
changeset
|
31 |
* @modules jdk.compiler/com.sun.tools.sjavac |
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
27579
diff
changeset
|
32 |
* jdk.compiler/com.sun.tools.sjavac.client |
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
27579
diff
changeset
|
33 |
* jdk.compiler/com.sun.tools.sjavac.options |
25603
d5fa4eab2d26
8046824: class SJavacTestUtil and *Wrapper are redundant and should be removed
jjg
parents:
24067
diff
changeset
|
34 |
* @build Wrapper |
d5fa4eab2d26
8046824: class SJavacTestUtil and *Wrapper are redundant and should be removed
jjg
parents:
24067
diff
changeset
|
35 |
* @run main Wrapper OptionDecoding |
d5fa4eab2d26
8046824: class SJavacTestUtil and *Wrapper are redundant and should be removed
jjg
parents:
24067
diff
changeset
|
36 |
*/ |
d5fa4eab2d26
8046824: class SJavacTestUtil and *Wrapper are redundant and should be removed
jjg
parents:
24067
diff
changeset
|
37 |
|
24067
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
38 |
import static util.OptionTestUtil.assertEquals; |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
39 |
import static util.OptionTestUtil.checkFilesFound; |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
40 |
|
27579 | 41 |
import java.io.File; |
24067
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
42 |
import java.io.IOException; |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
43 |
import java.nio.file.Files; |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
44 |
import java.nio.file.Path; |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
45 |
import java.nio.file.Paths; |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
46 |
import java.util.ArrayList; |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
47 |
import java.util.Arrays; |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
48 |
import java.util.Collections; |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
49 |
import java.util.HashMap; |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
50 |
import java.util.List; |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
51 |
import java.util.Map; |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
52 |
|
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
53 |
import com.sun.tools.sjavac.CopyFile; |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
54 |
import com.sun.tools.sjavac.Main; |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
55 |
import com.sun.tools.sjavac.Module; |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
56 |
import com.sun.tools.sjavac.Source; |
26271
97603426a4ce
8054500: Refactor sjavac Main class into ClientMain and ServerMain
alundblad
parents:
26089
diff
changeset
|
57 |
import com.sun.tools.sjavac.client.ClientMain; |
24067
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
58 |
import com.sun.tools.sjavac.options.Options; |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
59 |
import com.sun.tools.sjavac.options.SourceLocation; |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
60 |
|
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
61 |
public class OptionDecoding { |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
62 |
|
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
63 |
public static void main(String[] args) throws IOException { |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
64 |
|
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
65 |
testPaths(); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
66 |
testDupPaths(); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
67 |
testSourceLocations(); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
68 |
testSimpleOptions(); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
69 |
testServerConf(); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
70 |
testSearchPaths(); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
71 |
testTranslationRules(); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
72 |
|
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
73 |
} |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
74 |
|
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
75 |
// Test decoding of output paths |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
76 |
static void testPaths() throws IOException { |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
77 |
|
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
78 |
final String H = "headers"; |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
79 |
final String G = "gensrc"; |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
80 |
final String D = "dest"; |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
81 |
final String CMP = "srcRefList.txt"; |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
82 |
|
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
83 |
Options options = Options.parseArgs("-h", H, "-s", G, "-d", D, |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
84 |
"--compare-found-sources", CMP); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
85 |
|
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
86 |
assertEquals(Paths.get(H).toAbsolutePath(), options.getHeaderDir()); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
87 |
assertEquals(Paths.get(G).toAbsolutePath(), options.getGenSrcDir()); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
88 |
assertEquals(Paths.get(D).toAbsolutePath(), options.getDestDir()); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
89 |
assertEquals(Paths.get(CMP), options.getSourceReferenceList()); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
90 |
|
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
91 |
} |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
92 |
|
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
93 |
// Providing duplicate header / dest / gensrc paths should produce an error. |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
94 |
static void testDupPaths() throws IOException { |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
95 |
|
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
96 |
try { |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
97 |
Options.parseArgs("-h", "dir1", "-h", "dir2"); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
98 |
throw new RuntimeException("Duplicate header directories should fail."); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
99 |
} catch (IllegalArgumentException iae) { |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
100 |
// Expected |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
101 |
} |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
102 |
|
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
103 |
try { |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
104 |
Options.parseArgs("-s", "dir1", "-s", "dir2"); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
105 |
throw new RuntimeException("Duplicate paths for generated sources should fail."); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
106 |
} catch (IllegalArgumentException iae) { |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
107 |
// Expected |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
108 |
} |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
109 |
|
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
110 |
try { |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
111 |
Options.parseArgs("-d", "dir1", "-d", "dir2"); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
112 |
throw new RuntimeException("Duplicate destination directories should fail."); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
113 |
} catch (IllegalArgumentException iae) { |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
114 |
// Expected |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
115 |
} |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
116 |
|
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
117 |
} |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
118 |
|
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
119 |
// Test source locations and -x, -i, -xf, -if filters |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
120 |
static void testSourceLocations() throws IOException { |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
121 |
|
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
122 |
Path a1 = Paths.get("root/pkg1/ClassA1.java"); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
123 |
Path a2 = Paths.get("root/pkg1/ClassA2.java"); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
124 |
Path b1 = Paths.get("root/pkg1/pkg2/ClassB1.java"); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
125 |
Path b2 = Paths.get("root/pkg1/pkg2/ClassB2.java"); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
126 |
Path c1 = Paths.get("root/pkg3/ClassC1.java"); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
127 |
Path c2 = Paths.get("root/pkg3/ClassC2.java"); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
128 |
|
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
129 |
for (Path p : Arrays.asList(a1, a2, b1, b2, c1, c2)) { |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
130 |
Files.createDirectories(p.getParent()); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
131 |
Files.createFile(p); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
132 |
} |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
133 |
|
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
134 |
// Test -if |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
135 |
{ |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
136 |
Options options = Options.parseArgs("-if", "root/pkg1/ClassA1.java", "root"); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
137 |
|
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
138 |
Map<String, Source> foundFiles = new HashMap<>(); |
26271
97603426a4ce
8054500: Refactor sjavac Main class into ClientMain and ServerMain
alundblad
parents:
26089
diff
changeset
|
139 |
ClientMain.findSourceFiles(options.getSources(), Collections.singleton(".java"), foundFiles, |
24067
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
140 |
new HashMap<String, Module>(), new Module("", ""), false, true); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
141 |
|
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
142 |
checkFilesFound(foundFiles.keySet(), a1); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
143 |
} |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
144 |
|
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
145 |
// Test -i |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
146 |
System.out.println("--------------------------- CHECKING -i ----------------"); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
147 |
{ |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
148 |
Options options = Options.parseArgs("-i", "pkg1/*", "root"); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
149 |
|
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
150 |
Map<String, Source> foundFiles = new HashMap<>(); |
26271
97603426a4ce
8054500: Refactor sjavac Main class into ClientMain and ServerMain
alundblad
parents:
26089
diff
changeset
|
151 |
ClientMain.findSourceFiles(options.getSources(), Collections.singleton(".java"), foundFiles, |
24067
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
152 |
new HashMap<String, Module>(), new Module("", ""), false, true); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
153 |
|
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
154 |
checkFilesFound(foundFiles.keySet(), a1, a2, b1, b2); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
155 |
} |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
156 |
System.out.println("--------------------------------------------------------"); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
157 |
|
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
158 |
// Test -xf |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
159 |
{ |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
160 |
Options options = Options.parseArgs("-xf", "root/pkg1/ClassA1.java", "root"); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
161 |
|
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
162 |
Map<String, Source> foundFiles = new HashMap<>(); |
26271
97603426a4ce
8054500: Refactor sjavac Main class into ClientMain and ServerMain
alundblad
parents:
26089
diff
changeset
|
163 |
ClientMain.findSourceFiles(options.getSources(), Collections.singleton(".java"), foundFiles, |
24067
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
164 |
new HashMap<String, Module>(), new Module("", ""), false, true); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
165 |
|
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
166 |
checkFilesFound(foundFiles.keySet(), a2, b1, b2, c1, c2); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
167 |
} |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
168 |
|
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
169 |
// Test -x |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
170 |
{ |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
171 |
Options options = Options.parseArgs("-i", "pkg1/*", "root"); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
172 |
|
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
173 |
Map<String, Source> foundFiles = new HashMap<>(); |
26271
97603426a4ce
8054500: Refactor sjavac Main class into ClientMain and ServerMain
alundblad
parents:
26089
diff
changeset
|
174 |
ClientMain.findSourceFiles(options.getSources(), Collections.singleton(".java"), foundFiles, |
24067
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
175 |
new HashMap<String, Module>(), new Module("", ""), false, true); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
176 |
|
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
177 |
checkFilesFound(foundFiles.keySet(), a1, a2, b1, b2); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
178 |
} |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
179 |
|
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
180 |
// Test -x and -i |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
181 |
{ |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
182 |
Options options = Options.parseArgs("-i", "pkg1/*", "-x", "pkg1/pkg2/*", "root"); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
183 |
|
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
184 |
Map<String, Source> foundFiles = new HashMap<>(); |
26271
97603426a4ce
8054500: Refactor sjavac Main class into ClientMain and ServerMain
alundblad
parents:
26089
diff
changeset
|
185 |
ClientMain.findSourceFiles(options.getSources(), Collections.singleton(".java"), foundFiles, |
24067
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
186 |
new HashMap<String, Module>(), new Module("", ""), false, true); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
187 |
|
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
188 |
checkFilesFound(foundFiles.keySet(), a1, a2); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
189 |
} |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
190 |
|
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
191 |
} |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
192 |
|
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
193 |
// Test basic options |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
194 |
static void testSimpleOptions() { |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
195 |
|
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
196 |
Options options = Options.parseArgs("-j", "17", "--log=debug"); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
197 |
assertEquals(17, options.getNumCores()); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
198 |
assertEquals("debug", options.getLogLevel()); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
199 |
assertEquals(false, options.isDefaultPackagePermitted()); |
26089 | 200 |
assertEquals(false, options.areUnidentifiedArtifactsPermitted()); |
201 |
assertEquals(false, options.isUnidentifiedArtifactPermitted(Paths.get("bar.txt").toFile().getAbsolutePath())); |
|
24067
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
202 |
|
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
203 |
options = Options.parseArgs("--permit-unidentified-artifacts", |
26089 | 204 |
"--permit-artifact=bar.txt", |
24067
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
205 |
"--permit-sources-without-package"); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
206 |
assertEquals("info", options.getLogLevel()); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
207 |
assertEquals(true, options.isDefaultPackagePermitted()); |
26089 | 208 |
assertEquals(true, options.areUnidentifiedArtifactsPermitted()); |
209 |
assertEquals(true, options.isUnidentifiedArtifactPermitted(Paths.get("bar.txt").toFile().getAbsolutePath())); |
|
24067
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
210 |
} |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
211 |
|
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
212 |
// Test server configuration options |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
213 |
static void testServerConf() { |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
214 |
Options options = Options.parseArgs("--server:someServerConfiguration"); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
215 |
assertEquals("someServerConfiguration", options.getServerConf()); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
216 |
assertEquals(false, options.startServerFlag()); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
217 |
|
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
218 |
options = Options.parseArgs("--startserver:someServerConfiguration"); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
219 |
assertEquals("someServerConfiguration", options.getServerConf()); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
220 |
assertEquals(true, options.startServerFlag()); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
221 |
} |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
222 |
|
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
223 |
// Test input paths |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
224 |
static void testSearchPaths() { |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
225 |
List<String> i, x, iF, xF; |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
226 |
i = x = iF = xF = new ArrayList<>(); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
227 |
|
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
228 |
SourceLocation dir1 = new SourceLocation(Paths.get("dir1"), i, x, iF, xF); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
229 |
SourceLocation dir2 = new SourceLocation(Paths.get("dir2"), i, x, iF, xF); |
27579 | 230 |
String dir1_PS_dir2 = "dir1" + File.pathSeparator + "dir2"; |
24067
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
231 |
|
27579 | 232 |
Options options = Options.parseArgs("-sourcepath", dir1_PS_dir2); |
24067
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
233 |
assertEquals(options.getSourceSearchPaths(), Arrays.asList(dir1, dir2)); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
234 |
|
27579 | 235 |
options = Options.parseArgs("-modulepath", dir1_PS_dir2); |
24067
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
236 |
assertEquals(options.getModuleSearchPaths(), Arrays.asList(dir1, dir2)); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
237 |
|
27579 | 238 |
options = Options.parseArgs("-classpath", dir1_PS_dir2); |
24067
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
239 |
assertEquals(options.getClassSearchPath(), Arrays.asList(dir1, dir2)); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
240 |
} |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
241 |
|
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
242 |
// Test -tr option |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
243 |
static void testTranslationRules() { |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
244 |
|
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
245 |
Class<?> cls = com.sun.tools.sjavac.CompileJavaPackages.class; |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
246 |
|
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
247 |
Options options = Options.parseArgs( |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
248 |
"-tr", ".exa=" + cls.getName(), |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
249 |
"-tr", ".exb=" + cls.getName(), |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
250 |
"-copy", ".html"); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
251 |
|
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
252 |
assertEquals(cls, options.getTranslationRules().get(".exa").getClass()); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
253 |
assertEquals(cls, options.getTranslationRules().get(".exb").getClass()); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
254 |
assertEquals(CopyFile.class, options.getTranslationRules().get(".html").getClass()); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
255 |
|
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
256 |
} |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
257 |
} |