langtools/test/tools/javac/6917288/GraphicalInstallerTest.java
author vasya
Mon, 14 Dec 2015 20:18:19 +0100
changeset 34752 9c262a013456
parent 30730 d3ce7619db2c
permissions -rw-r--r--
8145342: Some copyright notices are inconsistently and ill formatted Summary: Adjusted formatting of copyright notices. Reviewed-by: darcy, alundblad
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6029
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
     1
/*
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 6029
diff changeset
     2
 * Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved.
6029
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
     4
 *
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
     8
 *
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    13
 * accompanied this code).
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    14
 *
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    18
 *
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    21
 * questions.
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    22
 */
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    23
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    24
/* @test
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    25
 * @bug 6917288
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    26
 * @summary Unnamed nested class is not generated
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 6029
diff changeset
    27
 * @modules jdk.compiler
6029
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    28
 */
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    29
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    30
import java.io.*;
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    31
import java.util.*;
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    32
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    33
public class GraphicalInstallerTest {
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    34
    public static void main(String... args) throws Exception {
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    35
        new GraphicalInstallerTest().run();
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    36
    }
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    37
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    38
    void run() throws Exception {
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    39
        File testSrc = new File(System.getProperty("test.src"));
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    40
        File classes = new File("classes");
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    41
        classes.mkdirs();
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    42
        List<String> opts = Arrays.asList("-d", classes.getPath());
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    43
        int rc = compile(opts, new File(testSrc, "GraphicalInstaller.java"));
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    44
        if (rc != 0) {
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    45
            error("compilation failed: rc=" + rc);
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    46
            return;
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    47
        }
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    48
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    49
        check(classes,
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    50
            "GraphicalInstaller$1.class",
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    51
            "GraphicalInstaller$1X$1.class",
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    52
            "GraphicalInstaller$1X.class",
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    53
            "GraphicalInstaller$BackgroundInstaller.class",
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    54
            "GraphicalInstaller.class");
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    55
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    56
        if (errors > 0)
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    57
            throw new Exception(errors + " errors occurred");
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    58
    }
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    59
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    60
    /**
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    61
     *  Compile files with given options.
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    62
     *  Display any output from compiler, and return javac return code.
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    63
     */
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    64
    int compile(List<String> opts, File... files) {
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    65
        List<String> args = new ArrayList<String>();
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    66
        args.addAll(opts);
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    67
        for (File f: files)
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    68
            args.add(f.getPath());
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    69
        StringWriter sw = new StringWriter();
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    70
        PrintWriter pw = new PrintWriter(sw);
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    71
        int rc = com.sun.tools.javac.Main.compile(args.toArray(new String[args.size()]), pw);
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    72
        pw.close();
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    73
        String out = sw.toString();
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    74
        if (out.length() > 0)
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    75
            System.err.println(out);
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    76
        return rc;
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    77
    }
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    78
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    79
    /**
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    80
     *  Check that a directory contains the expected files.
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    81
     */
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    82
    void check(File dir, String... paths) {
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    83
        Set<String> found = new TreeSet<String>(Arrays.asList(dir.list()));
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    84
        Set<String> expect = new TreeSet<String>(Arrays.asList(paths));
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    85
        if (found.equals(expect))
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    86
            return;
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    87
        for (String f: found) {
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    88
            if (!expect.contains(f))
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    89
                error("Unexpected file found: " + f);
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    90
        }
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    91
        for (String e: expect) {
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    92
            if (!found.contains(e))
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    93
                error("Expected file not found: " + e);
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    94
        }
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    95
    }
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    96
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    97
    /**
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    98
     *  Record an error message.
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
    99
     */
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
   100
    void error(String msg) {
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
   101
        System.err.println(msg);
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
   102
        errors++;
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
   103
    }
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
   104
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
   105
    int errors;
89f2c9b62d31 6917288: Unnamed nested class is not generated
jjg
parents:
diff changeset
   106
}