duke@1: /* jjg@1358: * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved. duke@1: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@1: * duke@1: * This code is free software; you can redistribute it and/or modify it duke@1: * under the terms of the GNU General Public License version 2 only, as ohair@554: * published by the Free Software Foundation. Oracle designates this duke@1: * particular file as subject to the "Classpath" exception as provided ohair@554: * by Oracle in the LICENSE file that accompanied this code. duke@1: * duke@1: * This code is distributed in the hope that it will be useful, but WITHOUT duke@1: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@1: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@1: * version 2 for more details (a copy is included in the LICENSE file that duke@1: * accompanied this code). duke@1: * duke@1: * You should have received a copy of the GNU General Public License version duke@1: * 2 along with this work; if not, write to the Free Software Foundation, duke@1: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@1: * ohair@554: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ohair@554: * or visit www.oracle.com if you need additional information or have any ohair@554: * questions. duke@1: */ duke@1: duke@1: package com.sun.tools.javac.api; duke@1: duke@1: import java.io.InputStream; duke@1: import java.io.OutputStream; jjg@944: import java.io.OutputStreamWriter; duke@1: import java.io.PrintWriter; duke@1: import java.io.Writer; jjg@944: import java.nio.charset.Charset; duke@1: import java.util.Collections; duke@1: import java.util.EnumSet; duke@1: import java.util.Iterator; duke@1: import java.util.Locale; duke@1: import java.util.Set; duke@1: import javax.lang.model.SourceVersion; duke@1: import javax.tools.*; duke@1: duke@1: import com.sun.source.util.JavacTask; jjg@50: import com.sun.tools.javac.file.JavacFileManager; duke@1: import com.sun.tools.javac.main.Main; jjg@1157: import com.sun.tools.javac.main.Option; jjg@1157: import com.sun.tools.javac.main.OptionHelper; jjg@1157: import com.sun.tools.javac.main.OptionHelper.GrumpyHelper; jjg@946: import com.sun.tools.javac.util.ClientCodeException; duke@1: import com.sun.tools.javac.util.Context; duke@1: import com.sun.tools.javac.util.Log; jjg@1136: import com.sun.tools.javac.util.Log.PrefixKind; duke@1: import com.sun.tools.javac.util.Options; duke@1: duke@1: /** duke@1: * TODO: describe com.sun.tools.javac.api.Tool duke@1: * jjg@581: *
This is NOT part of any supported API. duke@1: * If you write code that depends on this, you do so at your own duke@1: * risk. This code and its internal interfaces are subject to change duke@1: * or deletion without notice.
duke@1: * duke@1: * @author Peter von der Ah\u00e9 duke@1: */ duke@1: public final class JavacTool implements JavaCompiler { duke@1: /** jjg@1157: * Constructor used by service provider mechanism. The recommended way to jjg@1157: * obtain an instance of this class is by using {@link #create} or the jjg@1157: * service provider mechanism. jjg@1358: * @see javax.tools.JavaCompiler duke@1: * @see javax.tools.ToolProvider duke@1: * @see #create duke@1: */ duke@1: @Deprecated duke@1: public JavacTool() {} duke@1: duke@1: /** duke@1: * Static factory method for creating new instances of this tool. duke@1: * @return new instance of this tool duke@1: */ duke@1: public static JavacTool create() { duke@1: return new JavacTool(); duke@1: } duke@1: duke@1: public JavacFileManager getStandardFileManager( duke@1: DiagnosticListener super JavaFileObject> diagnosticListener, duke@1: Locale locale, duke@1: Charset charset) { duke@1: Context context = new Context(); jjg@944: context.put(Locale.class, locale); duke@1: if (diagnosticListener != null) duke@1: context.put(DiagnosticListener.class, diagnosticListener); jjg@944: PrintWriter pw = (charset == null) jjg@944: ? new PrintWriter(System.err, true) jjg@944: : new PrintWriter(new OutputStreamWriter(System.err, charset), true); jjg@944: context.put(Log.outKey, pw); duke@1: return new JavacFileManager(context, true, charset); duke@1: } duke@1: jjg@1136: @Override duke@1: public JavacTask getTask(Writer out, duke@1: JavaFileManager fileManager, duke@1: DiagnosticListener super JavaFileObject> diagnosticListener, duke@1: Iterable