NoState.java revision 3082:17d15aa9140d
1155093Smarius/*
2155093Smarius * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
3155093Smarius * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4155093Smarius *
5155093Smarius * This code is free software; you can redistribute it and/or modify it
6155093Smarius * under the terms of the GNU General Public License version 2 only, as
7155093Smarius * published by the Free Software Foundation.
8155093Smarius *
9155093Smarius * This code is distributed in the hope that it will be useful, but WITHOUT
10155093Smarius * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11155093Smarius * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12155093Smarius * version 2 for more details (a copy is included in the LICENSE file that
13155093Smarius * accompanied this code).
14155093Smarius *
15155093Smarius * You should have received a copy of the GNU General Public License version
16155093Smarius * 2 along with this work; if not, write to the Free Software Foundation,
17155093Smarius * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18155093Smarius *
19155093Smarius * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20155093Smarius * or visit www.oracle.com if you need additional information or have any
21155093Smarius * questions.
22155093Smarius */
23155093Smarius
24155093Smarius/*
25155093Smarius * @test
26155093Smarius * @summary Test --no-state option
27155093Smarius * @bug 8135131
28155093Smarius  * @library /tools/lib
29155093Smarius * @modules jdk.compiler/com.sun.tools.javac.api
30155093Smarius *          jdk.compiler/com.sun.tools.javac.file
31155093Smarius *          jdk.compiler/com.sun.tools.javac.main
32155093Smarius *          jdk.compiler/com.sun.tools.sjavac
33155093Smarius * @build Wrapper ToolBox
34155093Smarius * @run main Wrapper NoState
35155093Smarius */
36155093Smarius
37155093Smariusimport com.sun.tools.javac.util.Assert;
38155093Smarius
39155093Smariusimport java.io.IOException;
40155093Smariusimport java.nio.file.*;
41155093Smariusimport java.util.stream.Stream;
42155093Smarius
43155093Smariuspublic class NoState extends SJavacTester {
44155093Smarius    public static void main(String... args) throws Exception {
45155093Smarius        new NoState().run();
46155093Smarius    }
47155093Smarius
48155093Smarius    public void run() throws Exception {
49155093Smarius        clean(TEST_ROOT);
50155093Smarius        ToolBox tb = new ToolBox();
51155093Smarius        tb.writeFile(GENSRC.resolve("pkg/A.java"), "package pkg; class A {}");
52155093Smarius        Files.createDirectory(BIN);
53155093Smarius        compile("-d", BIN.toString(),
54155093Smarius                "--server:portfile=testserver,background=false",
55155093Smarius                GENSRC + "/pkg/A.java");
56155093Smarius
57155093Smarius        // Make sure file was compiled
58155093Smarius        Assert.check(Files.exists(BIN.resolve("pkg/A.class")));
59155093Smarius
60155093Smarius        // Make sure we have no other files (such as a javac_state file) in the bin directory
61155093Smarius        Assert.check(countPathsInDir(BIN) == 1);
62155093Smarius        Assert.check(countPathsInDir(BIN.resolve("pkg")) == 1);
63155093Smarius    }
64155093Smarius
65158663Smarius    private long countPathsInDir(Path dir) throws IOException {
66155093Smarius        try (Stream<Path> files = Files.list(dir)) {
67155093Smarius            return files.count();
68155093Smarius        }
69155093Smarius    }
70155093Smarius}
71155093Smarius