6994608: javah no longer accepts parameter files as input

Fri, 29 Oct 2010 13:12:38 -0700

author
jjg
date
Fri, 29 Oct 2010 13:12:38 -0700
changeset 728
895bea45a3e8
parent 727
460b2f588d0d
child 729
6ce6ee1b831a

6994608: javah no longer accepts parameter files as input
Reviewed-by: mcimadamore

src/share/classes/com/sun/tools/javah/JavahTask.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javah/resources/l10n.properties file | annotate | diff | comparison | revisions
test/tools/javah/T6994608.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/javah/JavahTask.java	Fri Oct 29 12:47:49 2010 -0700
     1.2 +++ b/src/share/classes/com/sun/tools/javah/JavahTask.java	Fri Oct 29 13:12:38 2010 -0700
     1.3 @@ -26,6 +26,7 @@
     1.4  package com.sun.tools.javah;
     1.5  
     1.6  import java.io.File;
     1.7 +import java.io.FileNotFoundException;
     1.8  import java.io.IOException;
     1.9  import java.io.OutputStream;
    1.10  import java.io.PrintWriter;
    1.11 @@ -74,6 +75,7 @@
    1.12  import static javax.tools.Diagnostic.Kind.*;
    1.13  
    1.14  import com.sun.tools.javac.code.Symbol.CompletionFailure;
    1.15 +import com.sun.tools.javac.main.CommandLine;
    1.16  
    1.17  /**
    1.18   * Javah generates support files for native methods.
    1.19 @@ -362,7 +364,7 @@
    1.20          if (fileManager == null)
    1.21              fileManager = getDefaultFileManager(diagnosticListener, log);
    1.22  
    1.23 -        Iterator<String> iter = args.iterator();
    1.24 +        Iterator<String> iter = expandAtArgs(args).iterator();
    1.25          noArgs = !iter.hasNext();
    1.26  
    1.27          while (iter.hasNext()) {
    1.28 @@ -416,6 +418,18 @@
    1.29          throw new BadArgs("err.unknown.option", name).showUsage(true);
    1.30      }
    1.31  
    1.32 +    private Iterable<String> expandAtArgs(Iterable<String> args) throws BadArgs {
    1.33 +        try {
    1.34 +            List<String> l = new ArrayList<String>();
    1.35 +            for (String arg: args) l.add(arg);
    1.36 +            return Arrays.asList(CommandLine.parse(l.toArray(new String[l.size()])));
    1.37 +        } catch (FileNotFoundException e) {
    1.38 +            throw new BadArgs("at.args.file.not.found", e.getLocalizedMessage());
    1.39 +        } catch (IOException e) {
    1.40 +            throw new BadArgs("at.args.io.exception", e.getLocalizedMessage());
    1.41 +        }
    1.42 +    }
    1.43 +
    1.44      public Boolean call() {
    1.45          return run();
    1.46      }
    1.47 @@ -607,8 +621,8 @@
    1.48              }
    1.49  
    1.50          };
    1.51 +    }
    1.52  
    1.53 -    }
    1.54      private String getMessage(String key, Object... args) {
    1.55          return getMessage(task_locale, key, args);
    1.56      }
     2.1 --- a/src/share/classes/com/sun/tools/javah/resources/l10n.properties	Fri Oct 29 12:47:49 2010 -0700
     2.2 +++ b/src/share/classes/com/sun/tools/javah/resources/l10n.properties	Fri Oct 29 13:12:38 2010 -0700
     2.3 @@ -30,6 +30,8 @@
     2.4          The directory {0} could not be create for output.
     2.5  at.args.cant.read=\
     2.6          Can''t read command line arguments from file {1}.
     2.7 +at.args.file.not.found=\
     2.8 +        Can''t find file {0}.
     2.9  at.args.io.exception=\
    2.10          The following I/O problem was encountered when processing an @ \
    2.11          argument on the command line: {0}.
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/tools/javah/T6994608.java	Fri Oct 29 13:12:38 2010 -0700
     3.3 @@ -0,0 +1,89 @@
     3.4 +/*
     3.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
     3.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3.7 + *
     3.8 + * This code is free software; you can redistribute it and/or modify it
     3.9 + * under the terms of the GNU General Public License version 2 only, as
    3.10 + * published by the Free Software Foundation.
    3.11 + *
    3.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    3.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    3.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    3.15 + * version 2 for more details (a copy is included in the LICENSE file that
    3.16 + * accompanied this code).
    3.17 + *
    3.18 + * You should have received a copy of the GNU General Public License version
    3.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    3.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    3.21 + *
    3.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    3.23 + * or visit www.oracle.com if you need additional information or have any
    3.24 + * questions.
    3.25 + */
    3.26 +
    3.27 +/*
    3.28 + * @test
    3.29 + * @bug 6994608
    3.30 + * @summary javah no longer accepts parameter files as input
    3.31 + */
    3.32 +
    3.33 +import java.io.*;
    3.34 +import java.util.*;
    3.35 +
    3.36 +public class T6994608 {
    3.37 +    public static void main(String... args) throws Exception {
    3.38 +        new T6994608().run();
    3.39 +    }
    3.40 +
    3.41 +    void run() throws Exception {
    3.42 +        Locale prev = Locale.getDefault();
    3.43 +        Locale.setDefault(Locale.ENGLISH);
    3.44 +        try {
    3.45 +            File f = writeFile(new File("classList"), "java.lang.Object");
    3.46 +            test(Arrays.asList("@" + f.getPath()), 0, null);
    3.47 +            test(Arrays.asList("@badfile"), 1, "Can't find file badfile");
    3.48 +            if (errors > 0)
    3.49 +                throw new Exception(errors + " errors occurred");
    3.50 +        } finally {
    3.51 +            Locale.setDefault(prev);
    3.52 +        }
    3.53 +    }
    3.54 +
    3.55 +    void test(List<String> args, int expectRC, String expectOut) {
    3.56 +        System.err.println("Test: " + args
    3.57 +                + " rc:" + expectRC
    3.58 +                + ((expectOut != null) ? " out:" + expectOut : ""));
    3.59 +
    3.60 +        StringWriter sw = new StringWriter();
    3.61 +        PrintWriter pw = new PrintWriter(sw);
    3.62 +        int rc = com.sun.tools.javah.Main.run(args.toArray(new String[args.size()]), pw);
    3.63 +        pw.close();
    3.64 +        String out = sw.toString();
    3.65 +        if (!out.isEmpty())
    3.66 +            System.err.println(out);
    3.67 +
    3.68 +        if (rc != expectRC)
    3.69 +            error("Unexpected exit code: " + rc + "; expected: " + expectRC);
    3.70 +        if (expectOut != null && !out.contains(expectOut))
    3.71 +            error("Expected string not found: " + expectOut);
    3.72 +
    3.73 +        System.err.println();
    3.74 +    }
    3.75 +
    3.76 +    File writeFile(File f, String s) throws IOException {
    3.77 +        if (f.getParentFile() != null)
    3.78 +            f.getParentFile().mkdirs();
    3.79 +        try (FileWriter out = new FileWriter(f)) {
    3.80 +            out.write(s);
    3.81 +        }
    3.82 +        return f;
    3.83 +    }
    3.84 +
    3.85 +    void error(String msg) {
    3.86 +        System.err.println(msg);
    3.87 +        errors++;
    3.88 +    }
    3.89 +
    3.90 +    int errors;
    3.91 +}
    3.92 +

mercurial