src/share/classes/javax/tools/StandardJavaFileManager.java

Wed, 16 Mar 2016 00:00:25 -0700

author
asaha
date
Wed, 16 Mar 2016 00:00:25 -0700
changeset 3095
37a348477fe8
parent 554
9d9f26857129
child 2525
2eb010b6cb22
permissions
-rw-r--r--

Added tag jdk8u77-b00 for changeset ae2485fab956

duke@1 1 /*
ohair@554 2 * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
duke@1 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@1 4 *
duke@1 5 * This code is free software; you can redistribute it and/or modify it
duke@1 6 * under the terms of the GNU General Public License version 2 only, as
ohair@554 7 * published by the Free Software Foundation. Oracle designates this
duke@1 8 * particular file as subject to the "Classpath" exception as provided
ohair@554 9 * by Oracle in the LICENSE file that accompanied this code.
duke@1 10 *
duke@1 11 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@1 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@1 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@1 14 * version 2 for more details (a copy is included in the LICENSE file that
duke@1 15 * accompanied this code).
duke@1 16 *
duke@1 17 * You should have received a copy of the GNU General Public License version
duke@1 18 * 2 along with this work; if not, write to the Free Software Foundation,
duke@1 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@1 20 *
ohair@554 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@554 22 * or visit www.oracle.com if you need additional information or have any
ohair@554 23 * questions.
duke@1 24 */
duke@1 25
duke@1 26 package javax.tools;
duke@1 27
duke@1 28 import java.io.File;
duke@1 29 import java.io.IOException;
duke@1 30 import java.util.*;
duke@1 31
duke@1 32 /**
duke@1 33 * File manager based on {@linkplain File java.io.File}. A common way
duke@1 34 * to obtain an instance of this class is using {@linkplain
duke@1 35 * JavaCompiler#getStandardFileManager
duke@1 36 * getStandardFileManager}, for example:
duke@1 37 *
duke@1 38 * <pre>
duke@1 39 * JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
duke@1 40 * {@code DiagnosticCollector<JavaFileObject>} diagnostics =
duke@1 41 * new {@code DiagnosticCollector<JavaFileObject>()};
duke@1 42 * StandardJavaFileManager fm = compiler.getStandardFileManager(diagnostics, null, null);
duke@1 43 * </pre>
duke@1 44 *
duke@1 45 * This file manager creates file objects representing regular
duke@1 46 * {@linkplain File files},
duke@1 47 * {@linkplain java.util.zip.ZipEntry zip file entries}, or entries in
duke@1 48 * similar file system based containers. Any file object returned
duke@1 49 * from a file manager implementing this interface must observe the
duke@1 50 * following behavior:
duke@1 51 *
duke@1 52 * <ul>
duke@1 53 * <li>
duke@1 54 * File names need not be canonical.
duke@1 55 * </li>
duke@1 56 * <li>
duke@1 57 * For file objects representing regular files
duke@1 58 * <ul>
duke@1 59 * <li>
duke@1 60 * the method <code>{@linkplain FileObject#delete()}</code>
duke@1 61 * is equivalent to <code>{@linkplain File#delete()}</code>,
duke@1 62 * </li>
duke@1 63 * <li>
duke@1 64 * the method <code>{@linkplain FileObject#getLastModified()}</code>
duke@1 65 * is equivalent to <code>{@linkplain File#lastModified()}</code>,
duke@1 66 * </li>
duke@1 67 * <li>
duke@1 68 * the methods <code>{@linkplain FileObject#getCharContent(boolean)}</code>,
duke@1 69 * <code>{@linkplain FileObject#openInputStream()}</code>, and
duke@1 70 * <code>{@linkplain FileObject#openReader(boolean)}</code>
duke@1 71 * must succeed if the following would succeed (ignoring
duke@1 72 * encoding issues):
duke@1 73 * <blockquote>
duke@1 74 * <pre>new {@linkplain java.io.FileInputStream#FileInputStream(File) FileInputStream}(new {@linkplain File#File(java.net.URI) File}({@linkplain FileObject fileObject}.{@linkplain FileObject#toUri() toUri}()))</pre>
duke@1 75 * </blockquote>
duke@1 76 * </li>
duke@1 77 * <li>
duke@1 78 * and the methods
duke@1 79 * <code>{@linkplain FileObject#openOutputStream()}</code>, and
duke@1 80 * <code>{@linkplain FileObject#openWriter()}</code> must
duke@1 81 * succeed if the following would succeed (ignoring encoding
duke@1 82 * issues):
duke@1 83 * <blockquote>
duke@1 84 * <pre>new {@linkplain java.io.FileOutputStream#FileOutputStream(File) FileOutputStream}(new {@linkplain File#File(java.net.URI) File}({@linkplain FileObject fileObject}.{@linkplain FileObject#toUri() toUri}()))</pre>
duke@1 85 * </blockquote>
duke@1 86 * </li>
duke@1 87 * </ul>
duke@1 88 * </li>
duke@1 89 * <li>
duke@1 90 * The {@linkplain java.net.URI URI} returned from
duke@1 91 * <code>{@linkplain FileObject#toUri()}</code>
duke@1 92 * <ul>
duke@1 93 * <li>
duke@1 94 * must be {@linkplain java.net.URI#isAbsolute() absolute} (have a schema), and
duke@1 95 * </li>
duke@1 96 * <li>
duke@1 97 * must have a {@linkplain java.net.URI#normalize() normalized}
duke@1 98 * {@linkplain java.net.URI#getPath() path component} which
duke@1 99 * can be resolved without any process-specific context such
duke@1 100 * as the current directory (file names must be absolute).
duke@1 101 * </li>
duke@1 102 * </ul>
duke@1 103 * </li>
duke@1 104 * </ul>
duke@1 105 *
duke@1 106 * According to these rules, the following URIs, for example, are
duke@1 107 * allowed:
duke@1 108 * <ul>
duke@1 109 * <li>
duke@1 110 * <code>file:///C:/Documents%20and%20Settings/UncleBob/BobsApp/Test.java</code>
duke@1 111 * </li>
duke@1 112 * <li>
duke@1 113 * <code>jar:///C:/Documents%20and%20Settings/UncleBob/lib/vendorA.jar!com/vendora/LibraryClass.class</code>
duke@1 114 * </li>
duke@1 115 * </ul>
duke@1 116 * Whereas these are not (reason in parentheses):
duke@1 117 * <ul>
duke@1 118 * <li>
duke@1 119 * <code>file:BobsApp/Test.java</code> (the file name is relative
duke@1 120 * and depend on the current directory)
duke@1 121 * </li>
duke@1 122 * <li>
duke@1 123 * <code>jar:lib/vendorA.jar!com/vendora/LibraryClass.class</code>
duke@1 124 * (the first half of the path depends on the current directory,
duke@1 125 * whereas the component after ! is legal)
duke@1 126 * </li>
duke@1 127 * <li>
duke@1 128 * <code>Test.java</code> (this URI depends on the current
duke@1 129 * directory and does not have a schema)
duke@1 130 * </li>
duke@1 131 * <li>
duke@1 132 * <code>jar:///C:/Documents%20and%20Settings/UncleBob/BobsApp/../lib/vendorA.jar!com/vendora/LibraryClass.class</code>
duke@1 133 * (the path is not normalized)
duke@1 134 * </li>
duke@1 135 * </ul>
duke@1 136 *
duke@1 137 * @author Peter von der Ah&eacute;
duke@1 138 * @since 1.6
duke@1 139 */
duke@1 140 public interface StandardJavaFileManager extends JavaFileManager {
duke@1 141
duke@1 142 /**
duke@1 143 * Compares two file objects and return true if they represent the
duke@1 144 * same canonical file, zip file entry, or entry in any file
duke@1 145 * system based container.
duke@1 146 *
duke@1 147 * @param a a file object
duke@1 148 * @param b a file object
duke@1 149 * @return true if the given file objects represent the same
duke@1 150 * canonical file or zip file entry; false otherwise
duke@1 151 *
duke@1 152 * @throws IllegalArgumentException if either of the arguments
duke@1 153 * were created with another file manager implementation
duke@1 154 */
duke@1 155 boolean isSameFile(FileObject a, FileObject b);
duke@1 156
duke@1 157 /**
duke@1 158 * Gets file objects representing the given files.
duke@1 159 *
duke@1 160 * @param files a list of files
duke@1 161 * @return a list of file objects
duke@1 162 * @throws IllegalArgumentException if the list of files includes
duke@1 163 * a directory
duke@1 164 */
duke@1 165 Iterable<? extends JavaFileObject> getJavaFileObjectsFromFiles(
duke@1 166 Iterable<? extends File> files);
duke@1 167
duke@1 168 /**
duke@1 169 * Gets file objects representing the given files.
duke@1 170 * Convenience method equivalent to:
duke@1 171 *
duke@1 172 * <pre>
duke@1 173 * getJavaFileObjectsFromFiles({@linkplain java.util.Arrays#asList Arrays.asList}(files))
duke@1 174 * </pre>
duke@1 175 *
duke@1 176 * @param files an array of files
duke@1 177 * @return a list of file objects
duke@1 178 * @throws IllegalArgumentException if the array of files includes
duke@1 179 * a directory
duke@1 180 * @throws NullPointerException if the given array contains null
duke@1 181 * elements
duke@1 182 */
duke@1 183 Iterable<? extends JavaFileObject> getJavaFileObjects(File... files);
duke@1 184
duke@1 185 /**
duke@1 186 * Gets file objects representing the given file names.
duke@1 187 *
duke@1 188 * @param names a list of file names
duke@1 189 * @return a list of file objects
duke@1 190 * @throws IllegalArgumentException if the list of file names
duke@1 191 * includes a directory
duke@1 192 */
duke@1 193 Iterable<? extends JavaFileObject> getJavaFileObjectsFromStrings(
duke@1 194 Iterable<String> names);
duke@1 195
duke@1 196 /**
duke@1 197 * Gets file objects representing the given file names.
duke@1 198 * Convenience method equivalent to:
duke@1 199 *
duke@1 200 * <pre>
duke@1 201 * getJavaFileObjectsFromStrings({@linkplain java.util.Arrays#asList Arrays.asList}(names))
duke@1 202 * </pre>
duke@1 203 *
duke@1 204 * @param names a list of file names
duke@1 205 * @return a list of file objects
duke@1 206 * @throws IllegalArgumentException if the array of file names
duke@1 207 * includes a directory
duke@1 208 * @throws NullPointerException if the given array contains null
duke@1 209 * elements
duke@1 210 */
duke@1 211 Iterable<? extends JavaFileObject> getJavaFileObjects(String... names);
duke@1 212
duke@1 213 /**
duke@1 214 * Associates the given path with the given location. Any
duke@1 215 * previous value will be discarded.
duke@1 216 *
duke@1 217 * @param location a location
duke@1 218 * @param path a list of files, if {@code null} use the default
duke@1 219 * path for this location
duke@1 220 * @see #getLocation
duke@1 221 * @throws IllegalArgumentException if location is an output
duke@1 222 * location and path does not contain exactly one element
duke@1 223 * @throws IOException if location is an output location and path
duke@1 224 * does not represent an existing directory
duke@1 225 */
duke@1 226 void setLocation(Location location, Iterable<? extends File> path)
duke@1 227 throws IOException;
duke@1 228
duke@1 229 /**
duke@1 230 * Gets the path associated with the given location.
duke@1 231 *
duke@1 232 * @param location a location
duke@1 233 * @return a list of files or {@code null} if this location has no
duke@1 234 * associated path
duke@1 235 * @see #setLocation
duke@1 236 */
duke@1 237 Iterable<? extends File> getLocation(Location location);
duke@1 238
duke@1 239 }

mercurial