author | jjg |
Fri, 04 Dec 2015 14:22:04 -0800 | |
changeset 34480 | 124ac002c969 |
permissions | -rw-r--r-- |
34480
124ac002c969
8143268: Langtools tools should create output directories as needed.
jjg
parents:
diff
changeset
|
1 |
/* |
124ac002c969
8143268: Langtools tools should create output directories as needed.
jjg
parents:
diff
changeset
|
2 |
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
124ac002c969
8143268: Langtools tools should create output directories as needed.
jjg
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
124ac002c969
8143268: Langtools tools should create output directories as needed.
jjg
parents:
diff
changeset
|
4 |
* |
124ac002c969
8143268: Langtools tools should create output directories as needed.
jjg
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
124ac002c969
8143268: Langtools tools should create output directories as needed.
jjg
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
124ac002c969
8143268: Langtools tools should create output directories as needed.
jjg
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
124ac002c969
8143268: Langtools tools should create output directories as needed.
jjg
parents:
diff
changeset
|
8 |
* |
124ac002c969
8143268: Langtools tools should create output directories as needed.
jjg
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
124ac002c969
8143268: Langtools tools should create output directories as needed.
jjg
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
124ac002c969
8143268: Langtools tools should create output directories as needed.
jjg
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
124ac002c969
8143268: Langtools tools should create output directories as needed.
jjg
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
124ac002c969
8143268: Langtools tools should create output directories as needed.
jjg
parents:
diff
changeset
|
13 |
* accompanied this code). |
124ac002c969
8143268: Langtools tools should create output directories as needed.
jjg
parents:
diff
changeset
|
14 |
* |
124ac002c969
8143268: Langtools tools should create output directories as needed.
jjg
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
124ac002c969
8143268: Langtools tools should create output directories as needed.
jjg
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
124ac002c969
8143268: Langtools tools should create output directories as needed.
jjg
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
124ac002c969
8143268: Langtools tools should create output directories as needed.
jjg
parents:
diff
changeset
|
18 |
* |
124ac002c969
8143268: Langtools tools should create output directories as needed.
jjg
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
124ac002c969
8143268: Langtools tools should create output directories as needed.
jjg
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
124ac002c969
8143268: Langtools tools should create output directories as needed.
jjg
parents:
diff
changeset
|
21 |
* questions. |
124ac002c969
8143268: Langtools tools should create output directories as needed.
jjg
parents:
diff
changeset
|
22 |
*/ |
124ac002c969
8143268: Langtools tools should create output directories as needed.
jjg
parents:
diff
changeset
|
23 |
|
124ac002c969
8143268: Langtools tools should create output directories as needed.
jjg
parents:
diff
changeset
|
24 |
/** |
124ac002c969
8143268: Langtools tools should create output directories as needed.
jjg
parents:
diff
changeset
|
25 |
* @test |
124ac002c969
8143268: Langtools tools should create output directories as needed.
jjg
parents:
diff
changeset
|
26 |
* @bug 8143268 |
124ac002c969
8143268: Langtools tools should create output directories as needed.
jjg
parents:
diff
changeset
|
27 |
* @summary javac should create output directories as needed |
124ac002c969
8143268: Langtools tools should create output directories as needed.
jjg
parents:
diff
changeset
|
28 |
* @modules jdk.compiler |
124ac002c969
8143268: Langtools tools should create output directories as needed.
jjg
parents:
diff
changeset
|
29 |
*/ |
124ac002c969
8143268: Langtools tools should create output directories as needed.
jjg
parents:
diff
changeset
|
30 |
|
124ac002c969
8143268: Langtools tools should create output directories as needed.
jjg
parents:
diff
changeset
|
31 |
import java.io.*; |
124ac002c969
8143268: Langtools tools should create output directories as needed.
jjg
parents:
diff
changeset
|
32 |
|
124ac002c969
8143268: Langtools tools should create output directories as needed.
jjg
parents:
diff
changeset
|
33 |
public class T8143268 { |
124ac002c969
8143268: Langtools tools should create output directories as needed.
jjg
parents:
diff
changeset
|
34 |
public static void main(String... args) throws Exception{ |
124ac002c969
8143268: Langtools tools should create output directories as needed.
jjg
parents:
diff
changeset
|
35 |
new T8143268().run(); |
124ac002c969
8143268: Langtools tools should create output directories as needed.
jjg
parents:
diff
changeset
|
36 |
} |
124ac002c969
8143268: Langtools tools should create output directories as needed.
jjg
parents:
diff
changeset
|
37 |
|
124ac002c969
8143268: Langtools tools should create output directories as needed.
jjg
parents:
diff
changeset
|
38 |
void run() throws IOException { |
124ac002c969
8143268: Langtools tools should create output directories as needed.
jjg
parents:
diff
changeset
|
39 |
File src = new File("src"); |
124ac002c969
8143268: Langtools tools should create output directories as needed.
jjg
parents:
diff
changeset
|
40 |
src.mkdirs(); |
124ac002c969
8143268: Langtools tools should create output directories as needed.
jjg
parents:
diff
changeset
|
41 |
try (FileWriter out = new FileWriter(new File(src, "Test.java"))) { |
124ac002c969
8143268: Langtools tools should create output directories as needed.
jjg
parents:
diff
changeset
|
42 |
out.write("public class Test { native void m(); }"); |
124ac002c969
8143268: Langtools tools should create output directories as needed.
jjg
parents:
diff
changeset
|
43 |
} |
124ac002c969
8143268: Langtools tools should create output directories as needed.
jjg
parents:
diff
changeset
|
44 |
|
124ac002c969
8143268: Langtools tools should create output directories as needed.
jjg
parents:
diff
changeset
|
45 |
javac("-d", "classes", "-h", "hdr", "src/Test.java"); |
124ac002c969
8143268: Langtools tools should create output directories as needed.
jjg
parents:
diff
changeset
|
46 |
|
124ac002c969
8143268: Langtools tools should create output directories as needed.
jjg
parents:
diff
changeset
|
47 |
check("classes/Test.class"); |
124ac002c969
8143268: Langtools tools should create output directories as needed.
jjg
parents:
diff
changeset
|
48 |
check("hdr/Test.h"); |
124ac002c969
8143268: Langtools tools should create output directories as needed.
jjg
parents:
diff
changeset
|
49 |
} |
124ac002c969
8143268: Langtools tools should create output directories as needed.
jjg
parents:
diff
changeset
|
50 |
|
124ac002c969
8143268: Langtools tools should create output directories as needed.
jjg
parents:
diff
changeset
|
51 |
void javac(String... args) { |
124ac002c969
8143268: Langtools tools should create output directories as needed.
jjg
parents:
diff
changeset
|
52 |
try (PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out))) { |
124ac002c969
8143268: Langtools tools should create output directories as needed.
jjg
parents:
diff
changeset
|
53 |
int rc = com.sun.tools.javac.Main.compile(args, pw); |
124ac002c969
8143268: Langtools tools should create output directories as needed.
jjg
parents:
diff
changeset
|
54 |
if (rc != 0) { |
124ac002c969
8143268: Langtools tools should create output directories as needed.
jjg
parents:
diff
changeset
|
55 |
throw new Error("compilation failed: " + rc); |
124ac002c969
8143268: Langtools tools should create output directories as needed.
jjg
parents:
diff
changeset
|
56 |
} |
124ac002c969
8143268: Langtools tools should create output directories as needed.
jjg
parents:
diff
changeset
|
57 |
} |
124ac002c969
8143268: Langtools tools should create output directories as needed.
jjg
parents:
diff
changeset
|
58 |
} |
124ac002c969
8143268: Langtools tools should create output directories as needed.
jjg
parents:
diff
changeset
|
59 |
|
124ac002c969
8143268: Langtools tools should create output directories as needed.
jjg
parents:
diff
changeset
|
60 |
void check(String path) { |
124ac002c969
8143268: Langtools tools should create output directories as needed.
jjg
parents:
diff
changeset
|
61 |
if (!new File(path).exists()) { |
124ac002c969
8143268: Langtools tools should create output directories as needed.
jjg
parents:
diff
changeset
|
62 |
throw new Error("file not found: " + path); |
124ac002c969
8143268: Langtools tools should create output directories as needed.
jjg
parents:
diff
changeset
|
63 |
} |
124ac002c969
8143268: Langtools tools should create output directories as needed.
jjg
parents:
diff
changeset
|
64 |
} |
124ac002c969
8143268: Langtools tools should create output directories as needed.
jjg
parents:
diff
changeset
|
65 |
} |
124ac002c969
8143268: Langtools tools should create output directories as needed.
jjg
parents:
diff
changeset
|
66 |