PermittedArtifact.java revision 3294:9adfb22ff08f
1284345Ssjg/*
2284345Ssjg * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
3284345Ssjg * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4284345Ssjg *
5284345Ssjg * This code is free software; you can redistribute it and/or modify it
6284345Ssjg * under the terms of the GNU General Public License version 2 only, as
7284345Ssjg * published by the Free Software Foundation.
8284345Ssjg *
9284345Ssjg * This code is distributed in the hope that it will be useful, but WITHOUT
10284345Ssjg * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11291563Sbdrewery * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12284345Ssjg * version 2 for more details (a copy is included in the LICENSE file that
13284345Ssjg * accompanied this code).
14284345Ssjg *
15284345Ssjg * You should have received a copy of the GNU General Public License version
16284345Ssjg * 2 along with this work; if not, write to the Free Software Foundation,
17284345Ssjg * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18284345Ssjg *
19284345Ssjg * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20284345Ssjg * or visit www.oracle.com if you need additional information or have any
21284345Ssjg * questions.
22284345Ssjg */
23284345Ssjg
24284345Ssjg/*
25 * @test
26 * @summary Test white listing of external artifacts inside the destination dir
27 * @bug 8054689
28 * @author Fredrik O
29 * @author sogoel (rewrite)
30 * @library /tools/lib
31 * @modules jdk.compiler/com.sun.tools.javac.api
32 *          jdk.compiler/com.sun.tools.javac.file
33 *          jdk.compiler/com.sun.tools.javac.main
34 *          jdk.compiler/com.sun.tools.sjavac
35 *          jdk.jdeps/com.sun.tools.javap
36 * @build Wrapper ToolBox
37 * @run main Wrapper PermittedArtifact
38 */
39
40import java.nio.file.Files;
41import java.util.Map;
42
43public class PermittedArtifact extends SJavacTester {
44    public static void main(String... args) throws Exception {
45        PermittedArtifact pa = new PermittedArtifact();
46        pa.test();
47    }
48
49    //Verify that --permit-artifact=bin works
50    void test() throws Exception {
51        Files.createDirectories(BIN);
52
53        Map<String,Long> previous_bin_state = collectState(BIN);
54
55        ToolBox tb = new ToolBox();
56        tb.writeFile(GENSRC + "/alfa/omega/A.java",
57                     "package alfa.omega; public class A { }");
58
59        tb.writeFile(BIN + "/alfa/omega/AA.class",
60                     "Ugh, a messy build system (tobefixed) wrote this class file, " +
61                     "sjavac must not delete it.");
62
63        compile("--log=debug",
64                "--permit-artifact=" + BIN + "/alfa/omega/AA.class",
65                "-src", GENSRC.toString(),
66                "-d", BIN.toString(),
67                "--state-dir=" + BIN);
68
69        Map<String,Long> new_bin_state = collectState(BIN);
70        verifyThatFilesHaveBeenAdded(previous_bin_state, new_bin_state,
71                                     BIN + "/alfa/omega/A.class",
72                                     BIN + "/alfa/omega/AA.class",
73                                     BIN + "/javac_state");
74    }
75}
76