1 /*
   2  * Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 6994608
  27  * @summary javah no longer accepts parameter files as input
  28  * @modules jdk.compiler
  29  */
  30 
  31 import java.io.*;
  32 import java.util.*;
  33 
  34 public class T6994608 {
  35     public static void main(String... args) throws Exception {
  36         new T6994608().run();
  37     }
  38 
  39     void run() throws Exception {
  40         Locale prev = Locale.getDefault();
  41         Locale.setDefault(Locale.ENGLISH);
  42         try {
  43             File f = writeFile(new File("classList"), "java.lang.Object");
  44             test(Arrays.asList("@" + f.getPath()), 0, null);
  45             test(Arrays.asList("@badfile"), 1, "Can't find file badfile");
  46             if (errors > 0)
  47                 throw new Exception(errors + " errors occurred");
  48         } finally {
  49             Locale.setDefault(prev);
  50         }
  51     }
  52 
  53     void test(List<String> args, int expectRC, String expectOut) {
  54         System.err.println("Test: " + args
  55                 + " rc:" + expectRC
  56                 + ((expectOut != null) ? " out:" + expectOut : ""));
  57 
  58         StringWriter sw = new StringWriter();
  59         PrintWriter pw = new PrintWriter(sw);
  60         int rc = com.sun.tools.javah.Main.run(args.toArray(new String[args.size()]), pw);
  61         pw.close();
  62         String out = sw.toString();
  63         if (!out.isEmpty())
  64             System.err.println(out);
  65 
  66         if (rc != expectRC)
  67             error("Unexpected exit code: " + rc + "; expected: " + expectRC);
  68         if (expectOut != null && !out.contains(expectOut))
  69             error("Expected string not found: " + expectOut);
  70 
  71         System.err.println();
  72     }
  73 
  74     File writeFile(File f, String s) throws IOException {
  75         if (f.getParentFile() != null)
  76             f.getParentFile().mkdirs();
  77         try (FileWriter out = new FileWriter(f)) {
  78             out.write(s);
  79         }
  80         return f;
  81     }
  82 
  83     void error(String msg) {
  84         System.err.println(msg);
  85         errors++;
  86     }
  87 
  88     int errors;
  89 }
  90