author | alundblad |
Wed, 26 Aug 2015 09:02:02 +0200 | |
changeset 32337 | c9d3ab9f601c |
parent 30730 | d3ce7619db2c |
child 32799 | ee577901f4bb |
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:
26271
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 |
32337 | 7 |
* published by the Free Software Foundation. |
24067
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
8 |
* |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
9 |
* 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
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
11 |
* 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
|
12 |
* 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
|
13 |
* accompanied this code). |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
14 |
* |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
15 |
* 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
|
16 |
* 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
|
17 |
* 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
|
18 |
* |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
19 |
* 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
|
20 |
* 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
|
21 |
* questions. |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
22 |
*/ |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
23 |
|
25603
d5fa4eab2d26
8046824: class SJavacTestUtil and *Wrapper are redundant and should be removed
jjg
parents:
24067
diff
changeset
|
24 |
|
d5fa4eab2d26
8046824: class SJavacTestUtil and *Wrapper are redundant and should be removed
jjg
parents:
24067
diff
changeset
|
25 |
/* |
d5fa4eab2d26
8046824: class SJavacTestUtil and *Wrapper are redundant and should be removed
jjg
parents:
24067
diff
changeset
|
26 |
* @test |
d5fa4eab2d26
8046824: class SJavacTestUtil and *Wrapper are redundant and should be removed
jjg
parents:
24067
diff
changeset
|
27 |
* @bug 8037085 |
d5fa4eab2d26
8046824: class SJavacTestUtil and *Wrapper are redundant and should be removed
jjg
parents:
24067
diff
changeset
|
28 |
* @summary Ensures that sjavac can handle various exclusion patterns. |
d5fa4eab2d26
8046824: class SJavacTestUtil and *Wrapper are redundant and should be removed
jjg
parents:
24067
diff
changeset
|
29 |
* |
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
26271
diff
changeset
|
30 |
* @modules jdk.compiler/com.sun.tools.sjavac |
25603
d5fa4eab2d26
8046824: class SJavacTestUtil and *Wrapper are redundant and should be removed
jjg
parents:
24067
diff
changeset
|
31 |
* @build Wrapper |
d5fa4eab2d26
8046824: class SJavacTestUtil and *Wrapper are redundant and should be removed
jjg
parents:
24067
diff
changeset
|
32 |
* @run main Wrapper ExclPattern |
d5fa4eab2d26
8046824: class SJavacTestUtil and *Wrapper are redundant and should be removed
jjg
parents:
24067
diff
changeset
|
33 |
*/ |
d5fa4eab2d26
8046824: class SJavacTestUtil and *Wrapper are redundant and should be removed
jjg
parents:
24067
diff
changeset
|
34 |
|
24067
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
35 |
import java.io.IOException; |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
36 |
import java.io.PrintWriter; |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
37 |
import java.nio.charset.Charset; |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
38 |
import java.nio.file.Files; |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
39 |
import java.nio.file.Path; |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
40 |
import java.nio.file.Paths; |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
41 |
|
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
42 |
public class ExclPattern { |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
43 |
|
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
44 |
public static void main(String[] ignore) throws IOException { |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
45 |
|
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
46 |
String toBeExcluded = "pkg/excl-dir/excluded.txt"; |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
47 |
String toBeIncluded = "pkg/incl-dir/included.txt"; |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
48 |
|
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
49 |
// Set up source directory with directory to be excluded |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
50 |
populate(Paths.get("srcdir"), |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
51 |
"pkg/SomeClass.java", |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
52 |
"package pkg; public class SomeClass { }", |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
53 |
|
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
54 |
toBeExcluded, |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
55 |
"This file should not end up in the dest directory.", |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
56 |
|
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
57 |
toBeIncluded, |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
58 |
"This file should end up in the dest directory."); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
59 |
|
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
60 |
String[] args = { |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
61 |
"-x", "pkg/excl-dir/*", |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
62 |
"-src", "srcdir", |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
63 |
"-d", "dest", |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
64 |
"-j", "1", |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
65 |
"-copy", ".txt", |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
66 |
"--server:portfile=testserver,background=false", |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
67 |
"--log=debug" |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
68 |
}; |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
69 |
|
26271
97603426a4ce
8054500: Refactor sjavac Main class into ClientMain and ServerMain
alundblad
parents:
25603
diff
changeset
|
70 |
int rc = com.sun.tools.sjavac.Main.go(args); |
24067
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
71 |
if (rc != 0) throw new RuntimeException("Error during compile!"); |
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 |
if (!Files.exists(Paths.get("dest/" + toBeIncluded))) |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
74 |
throw new AssertionError("File missing: " + toBeIncluded); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
75 |
|
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
76 |
if (Files.exists(Paths.get("dest/" + toBeExcluded))) |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
77 |
throw new AssertionError("File present: " + toBeExcluded); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
78 |
} |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
79 |
|
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
80 |
static void populate(Path root, String... args) throws IOException { |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
81 |
if (!Files.exists(root)) |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
82 |
Files.createDirectory(root); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
83 |
for (int i = 0; i < args.length; i += 2) { |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
84 |
String filename = args[i]; |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
85 |
String content = args[i+1]; |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
86 |
Path p = root.resolve(filename); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
87 |
Files.createDirectories(p.getParent()); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
88 |
try (PrintWriter out = new PrintWriter(Files.newBufferedWriter(p, |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
89 |
Charset.defaultCharset()))) { |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
90 |
out.println(content); |
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 |
} |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
94 |
} |