415N/A/*
553N/A * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
415N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
415N/A *
415N/A * This code is free software; you can redistribute it and/or modify it
415N/A * under the terms of the GNU General Public License version 2 only, as
553N/A * published by the Free Software Foundation. Oracle designates this
415N/A * particular file as subject to the "Classpath" exception as provided
553N/A * by Oracle in the LICENSE file that accompanied this code.
415N/A *
415N/A * This code is distributed in the hope that it will be useful, but WITHOUT
415N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
415N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
415N/A * version 2 for more details (a copy is included in the LICENSE file that
415N/A * accompanied this code).
415N/A *
415N/A * You should have received a copy of the GNU General Public License version
415N/A * 2 along with this work; if not, write to the Free Software Foundation,
415N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
415N/A *
553N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
553N/A * or visit www.oracle.com if you need additional information or have any
553N/A * questions.
415N/A */
415N/A
415N/Apackage com.sun.tools.javah;
415N/A
415N/Aimport java.io.InputStream;
415N/Aimport java.io.OutputStream;
415N/Aimport java.io.Writer;
415N/Aimport java.nio.charset.Charset;
415N/Aimport java.util.Arrays;
415N/Aimport java.util.EnumSet;
415N/Aimport java.util.Locale;
415N/Aimport java.util.Set;
415N/Aimport javax.lang.model.SourceVersion;
415N/Aimport javax.tools.DiagnosticListener;
415N/Aimport javax.tools.JavaFileManager;
415N/Aimport javax.tools.JavaFileObject;
415N/Aimport javax.tools.StandardJavaFileManager;
415N/A
415N/A/*
580N/A * <p><b>This is NOT part of any supported API.
415N/A * If you write code that depends on this, you do so at your own
415N/A * risk. This code and its internal interfaces are subject to change
415N/A * or deletion without notice.</b></p>
415N/A */
415N/Apublic class JavahTool implements NativeHeaderTool {
415N/A
415N/A public NativeHeaderTask getTask(Writer out,
415N/A JavaFileManager fileManager,
415N/A DiagnosticListener<? super JavaFileObject> diagnosticListener,
415N/A Iterable<String> options,
415N/A Iterable<String> classes) {
415N/A return new JavahTask(out, fileManager, diagnosticListener, options, classes);
415N/A }
415N/A
415N/A public StandardJavaFileManager getStandardFileManager(DiagnosticListener<? super JavaFileObject> diagnosticListener, Locale locale, Charset charset) {
415N/A return JavahTask.getDefaultFileManager(diagnosticListener, null);
415N/A }
415N/A
415N/A public int run(InputStream in, OutputStream out, OutputStream err, String... arguments) {
415N/A JavahTask t = new JavahTask(
415N/A JavahTask.getPrintWriterForStream(out),
415N/A null,
415N/A null,
415N/A Arrays.asList(arguments),
415N/A null);
415N/A return (t.run() ? 0 : 1);
415N/A }
415N/A
415N/A public Set<SourceVersion> getSourceVersions() {
415N/A return EnumSet.allOf(SourceVersion.class);
415N/A }
415N/A
415N/A public int isSupportedOption(String option) {
415N/A JavahTask.Option[] options = JavahTask.recognizedOptions;
415N/A for (int i = 0; i < options.length; i++) {
415N/A if (options[i].matches(option))
415N/A return (options[i].hasArg ? 1 : 0);
415N/A }
415N/A return -1;
415N/A }
415N/A}