duke@1: /* ohair@554: * Copyright (c) 2006, 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 javax.tools; duke@1: duke@1: import java.io.File; duke@1: import java.io.IOException; duke@1: import java.util.*; duke@1: duke@1: /** duke@1: * File manager based on {@linkplain File java.io.File}. A common way duke@1: * to obtain an instance of this class is using {@linkplain duke@1: * JavaCompiler#getStandardFileManager duke@1: * getStandardFileManager}, for example: duke@1: * duke@1: *
duke@1: * JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); duke@1: * {@code DiagnosticCollectorduke@1: * duke@1: * This file manager creates file objects representing regular duke@1: * {@linkplain File files}, duke@1: * {@linkplain java.util.zip.ZipEntry zip file entries}, or entries in duke@1: * similar file system based containers. Any file object returned duke@1: * from a file manager implementing this interface must observe the duke@1: * following behavior: duke@1: * duke@1: *} diagnostics = duke@1: * new {@code DiagnosticCollector ()}; duke@1: * StandardJavaFileManager fm = compiler.getStandardFileManager(diagnostics, null, null); duke@1: *
{@linkplain FileObject#delete()}
duke@1: * is equivalent to {@linkplain File#delete()}
,
duke@1: * {@linkplain FileObject#getLastModified()}
duke@1: * is equivalent to {@linkplain File#lastModified()}
,
duke@1: * {@linkplain FileObject#getCharContent(boolean)}
,
duke@1: * {@linkplain FileObject#openInputStream()}
, and
duke@1: * {@linkplain FileObject#openReader(boolean)}
duke@1: * must succeed if the following would succeed (ignoring
duke@1: * encoding issues):
duke@1: * duke@1: *duke@1: *new {@linkplain java.io.FileInputStream#FileInputStream(File) FileInputStream}(new {@linkplain File#File(java.net.URI) File}({@linkplain FileObject fileObject}.{@linkplain FileObject#toUri() toUri}()))duke@1: *
{@linkplain FileObject#openOutputStream()}
, and
duke@1: * {@linkplain FileObject#openWriter()}
must
duke@1: * succeed if the following would succeed (ignoring encoding
duke@1: * issues):
duke@1: * duke@1: *duke@1: *new {@linkplain java.io.FileOutputStream#FileOutputStream(File) FileOutputStream}(new {@linkplain File#File(java.net.URI) File}({@linkplain FileObject fileObject}.{@linkplain FileObject#toUri() toUri}()))duke@1: *
{@linkplain FileObject#toUri()}
duke@1: * file:///C:/Documents%20and%20Settings/UncleBob/BobsApp/Test.java
duke@1: * jar:///C:/Documents%20and%20Settings/UncleBob/lib/vendorA.jar!com/vendora/LibraryClass.class
duke@1: * file:BobsApp/Test.java
(the file name is relative
duke@1: * and depend on the current directory)
duke@1: * jar:lib/vendorA.jar!com/vendora/LibraryClass.class
duke@1: * (the first half of the path depends on the current directory,
duke@1: * whereas the component after ! is legal)
duke@1: * Test.java
(this URI depends on the current
duke@1: * directory and does not have a schema)
duke@1: * jar:///C:/Documents%20and%20Settings/UncleBob/BobsApp/../lib/vendorA.jar!com/vendora/LibraryClass.class
duke@1: * (the path is not normalized)
duke@1: * duke@1: * getJavaFileObjectsFromFiles({@linkplain java.util.Arrays#asList Arrays.asList}(files)) duke@1: *duke@1: * duke@1: * @param files an array of files duke@1: * @return a list of file objects duke@1: * @throws IllegalArgumentException if the array of files includes duke@1: * a directory duke@1: * @throws NullPointerException if the given array contains null duke@1: * elements duke@1: */ duke@1: Iterable extends JavaFileObject> getJavaFileObjects(File... files); duke@1: duke@1: /** duke@1: * Gets file objects representing the given file names. duke@1: * duke@1: * @param names a list of file names duke@1: * @return a list of file objects duke@1: * @throws IllegalArgumentException if the list of file names duke@1: * includes a directory duke@1: */ duke@1: Iterable extends JavaFileObject> getJavaFileObjectsFromStrings( duke@1: Iterable
duke@1: * getJavaFileObjectsFromStrings({@linkplain java.util.Arrays#asList Arrays.asList}(names)) duke@1: *duke@1: * duke@1: * @param names a list of file names duke@1: * @return a list of file objects duke@1: * @throws IllegalArgumentException if the array of file names duke@1: * includes a directory duke@1: * @throws NullPointerException if the given array contains null duke@1: * elements duke@1: */ duke@1: Iterable extends JavaFileObject> getJavaFileObjects(String... names); duke@1: duke@1: /** duke@1: * Associates the given path with the given location. Any duke@1: * previous value will be discarded. duke@1: * duke@1: * @param location a location duke@1: * @param path a list of files, if {@code null} use the default duke@1: * path for this location duke@1: * @see #getLocation duke@1: * @throws IllegalArgumentException if location is an output duke@1: * location and path does not contain exactly one element duke@1: * @throws IOException if location is an output location and path duke@1: * does not represent an existing directory duke@1: */ duke@1: void setLocation(Location location, Iterable extends File> path) duke@1: throws IOException; duke@1: duke@1: /** duke@1: * Gets the path associated with the given location. duke@1: * duke@1: * @param location a location duke@1: * @return a list of files or {@code null} if this location has no duke@1: * associated path duke@1: * @see #setLocation duke@1: */ duke@1: Iterable extends File> getLocation(Location location); duke@1: duke@1: }