Path: blob/master/test/langtools/tools/javac/6917288/GraphicalInstallerTest.java
41149 views
/*1* Copyright (c) 2010, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/* @test24* @bug 691728825* @summary Unnamed nested class is not generated26* @modules jdk.compiler27*/2829import java.io.*;30import java.util.*;3132public class GraphicalInstallerTest {33public static void main(String... args) throws Exception {34new GraphicalInstallerTest().run();35}3637void run() throws Exception {38File testSrc = new File(System.getProperty("test.src"));39File classes = new File("classes");40classes.mkdirs();41List<String> opts = Arrays.asList("-d", classes.getPath());42int rc = compile(opts, new File(testSrc, "GraphicalInstaller.java"));43if (rc != 0) {44error("compilation failed: rc=" + rc);45return;46}4748check(classes,49"GraphicalInstaller$1X$1.class",50"GraphicalInstaller$1X.class",51"GraphicalInstaller$BackgroundInstaller.class",52"GraphicalInstaller.class");5354if (errors > 0)55throw new Exception(errors + " errors occurred");56}5758/**59* Compile files with given options.60* Display any output from compiler, and return javac return code.61*/62int compile(List<String> opts, File... files) {63List<String> args = new ArrayList<String>();64args.addAll(opts);65for (File f: files)66args.add(f.getPath());67StringWriter sw = new StringWriter();68PrintWriter pw = new PrintWriter(sw);69int rc = com.sun.tools.javac.Main.compile(args.toArray(new String[args.size()]), pw);70pw.close();71String out = sw.toString();72if (out.length() > 0)73System.err.println(out);74return rc;75}7677/**78* Check that a directory contains the expected files.79*/80void check(File dir, String... paths) {81Set<String> found = new TreeSet<String>(Arrays.asList(dir.list()));82Set<String> expect = new TreeSet<String>(Arrays.asList(paths));83if (found.equals(expect))84return;85for (String f: found) {86if (!expect.contains(f))87error("Unexpected file found: " + f);88}89for (String e: expect) {90if (!found.contains(e))91error("Expected file not found: " + e);92}93}9495/**96* Record an error message.97*/98void error(String msg) {99System.err.println(msg);100errors++;101}102103int errors;104}105106107