langtools/src/share/classes/com/sun/tools/javac/file/JavacFileManager.java
author jjg
Mon, 29 Nov 2010 14:15:36 -0800
changeset 7335 8b390fd27190
parent 7334 f432af22de29
child 7839 a1ca72d05b20
permissions -rw-r--r--
6900037: javac should warn if earlier -source is used and bootclasspath not set Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
6719
1ce993f87850 6502392: Invalid relative names for Filer.createResource and Filer.getResource
jjg
parents: 5847
diff changeset
     2
 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5007
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5007
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    20
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5007
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5007
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5007
diff changeset
    23
 * questions.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
731
1dd22bdb9ca5 6714364: refactor javac File handling code into new javac.file package
jjg
parents: 657
diff changeset
    26
package com.sun.tools.javac.file;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
7334
f432af22de29 7003006: add option to list directory in deterministic order
jjg
parents: 6721
diff changeset
    28
import java.util.Comparator;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
import java.io.ByteArrayOutputStream;
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
import java.io.File;
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
import java.io.FileNotFoundException;
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
import java.io.IOException;
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
import java.io.OutputStreamWriter;
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
import java.net.MalformedURLException;
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
import java.net.URI;
3782
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents: 3656
diff changeset
    36
import java.net.URISyntaxException;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
import java.net.URL;
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
import java.nio.CharBuffer;
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
import java.nio.charset.Charset;
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
import java.util.ArrayList;
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
import java.util.Arrays;
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
import java.util.Collection;
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
import java.util.Collections;
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
import java.util.EnumSet;
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
import java.util.HashMap;
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
import java.util.Iterator;
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
import java.util.Map;
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
import java.util.Set;
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
import java.util.zip.ZipFile;
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
import javax.lang.model.SourceVersion;
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
import javax.tools.FileObject;
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
import javax.tools.JavaFileManager;
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
import javax.tools.JavaFileObject;
731
1dd22bdb9ca5 6714364: refactor javac File handling code into new javac.file package
jjg
parents: 657
diff changeset
    55
import javax.tools.StandardJavaFileManager;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
1205
b316e32eb90c 6508981: cleanup file separator handling in JavacFileManager
jjg
parents: 815
diff changeset
    57
import com.sun.tools.javac.file.RelativePath.RelativeFile;
b316e32eb90c 6508981: cleanup file separator handling in JavacFileManager
jjg
parents: 815
diff changeset
    58
import com.sun.tools.javac.file.RelativePath.RelativeDirectory;
731
1dd22bdb9ca5 6714364: refactor javac File handling code into new javac.file package
jjg
parents: 657
diff changeset
    59
import com.sun.tools.javac.main.OptionName;
4548
bc0d5b3c3b2d 6906175: bridge JSR199 and JSR 203 APIs
jjg
parents: 4073
diff changeset
    60
import com.sun.tools.javac.util.BaseFileManager;
731
1dd22bdb9ca5 6714364: refactor javac File handling code into new javac.file package
jjg
parents: 657
diff changeset
    61
import com.sun.tools.javac.util.Context;
1dd22bdb9ca5 6714364: refactor javac File handling code into new javac.file package
jjg
parents: 657
diff changeset
    62
import com.sun.tools.javac.util.List;
1dd22bdb9ca5 6714364: refactor javac File handling code into new javac.file package
jjg
parents: 657
diff changeset
    63
import com.sun.tools.javac.util.ListBuffer;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
1205
b316e32eb90c 6508981: cleanup file separator handling in JavacFileManager
jjg
parents: 815
diff changeset
    65
import static javax.tools.StandardLocation.*;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
import static com.sun.tools.javac.main.OptionName.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
 * This class provides access to the source, class and other files
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
 * used by the compiler and related tools.
3380
a6c2bcab0fec 6865399: some javac files are missing Sun internal API comment
jjg
parents: 1789
diff changeset
    71
 *
5847
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    72
 * <p><b>This is NOT part of any supported API.
3380
a6c2bcab0fec 6865399: some javac files are missing Sun internal API comment
jjg
parents: 1789
diff changeset
    73
 * If you write code that depends on this, you do so at your own risk.
a6c2bcab0fec 6865399: some javac files are missing Sun internal API comment
jjg
parents: 1789
diff changeset
    74
 * This code and its internal interfaces are subject to change or
a6c2bcab0fec 6865399: some javac files are missing Sun internal API comment
jjg
parents: 1789
diff changeset
    75
 * deletion without notice.</b>
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
 */
4548
bc0d5b3c3b2d 6906175: bridge JSR199 and JSR 203 APIs
jjg
parents: 4073
diff changeset
    77
public class JavacFileManager extends BaseFileManager implements StandardJavaFileManager {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
    boolean useZipFileIndex;
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
    public static char[] toArray(CharBuffer buffer) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
        if (buffer.hasArray())
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
            return ((CharBuffer)buffer.compact().flip()).array();
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
        else
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
            return buffer.toString().toCharArray();
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
    /** Encapsulates knowledge of paths
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
    private Paths paths;
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
1208
5072b0dd3d52 6743107: clean up use of static caches in file manager
jjg
parents: 1205
diff changeset
    92
    private FSInfo fsInfo;
5072b0dd3d52 6743107: clean up use of static caches in file manager
jjg
parents: 1205
diff changeset
    93
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
    private final File uninited = new File("U N I N I T E D");
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
    private final Set<JavaFileObject.Kind> sourceOrClass =
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
        EnumSet.of(JavaFileObject.Kind.SOURCE, JavaFileObject.Kind.CLASS);
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
    /** The standard output directory, primarily used for classes.
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
     *  Initialized by the "-d" option.
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
     *  If classOutDir = null, files are written into same directory as the sources
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
     *  they were generated from.
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
    private File classOutDir = uninited;
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
    /** The output directory, used when generating sources while processing annotations.
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
     *  Initialized by the "-s" option.
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
    private File sourceOutDir = uninited;
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
    protected boolean mmappedIO;
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
    protected boolean ignoreSymbolFile;
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
7334
f432af22de29 7003006: add option to list directory in deterministic order
jjg
parents: 6721
diff changeset
   114
    protected enum SortFiles implements Comparator<File> {
f432af22de29 7003006: add option to list directory in deterministic order
jjg
parents: 6721
diff changeset
   115
        FORWARD {
f432af22de29 7003006: add option to list directory in deterministic order
jjg
parents: 6721
diff changeset
   116
            public int compare(File f1, File f2) {
f432af22de29 7003006: add option to list directory in deterministic order
jjg
parents: 6721
diff changeset
   117
                return f1.getName().compareTo(f2.getName());
f432af22de29 7003006: add option to list directory in deterministic order
jjg
parents: 6721
diff changeset
   118
            }
f432af22de29 7003006: add option to list directory in deterministic order
jjg
parents: 6721
diff changeset
   119
        },
f432af22de29 7003006: add option to list directory in deterministic order
jjg
parents: 6721
diff changeset
   120
        REVERSE {
f432af22de29 7003006: add option to list directory in deterministic order
jjg
parents: 6721
diff changeset
   121
            public int compare(File f1, File f2) {
f432af22de29 7003006: add option to list directory in deterministic order
jjg
parents: 6721
diff changeset
   122
                return -f1.getName().compareTo(f2.getName());
f432af22de29 7003006: add option to list directory in deterministic order
jjg
parents: 6721
diff changeset
   123
            }
f432af22de29 7003006: add option to list directory in deterministic order
jjg
parents: 6721
diff changeset
   124
        };
f432af22de29 7003006: add option to list directory in deterministic order
jjg
parents: 6721
diff changeset
   125
    };
f432af22de29 7003006: add option to list directory in deterministic order
jjg
parents: 6721
diff changeset
   126
    protected SortFiles sortFiles;
f432af22de29 7003006: add option to list directory in deterministic order
jjg
parents: 6721
diff changeset
   127
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
     * Register a Context.Factory to create a JavacFileManager.
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
    public static void preRegister(final Context context) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
        context.put(JavaFileManager.class, new Context.Factory<JavaFileManager>() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
            public JavaFileManager make() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
                return new JavacFileManager(context, true, null);
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
        });
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
     * Create a JavacFileManager using a given context, optionally registering
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
     * it as the JavaFileManager for that context.
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
    public JavacFileManager(Context context, boolean register, Charset charset) {
4548
bc0d5b3c3b2d 6906175: bridge JSR199 and JSR 203 APIs
jjg
parents: 4073
diff changeset
   144
        super(charset);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
        if (register)
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
            context.put(JavaFileManager.class, this);
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
        setContext(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
     * Set the context for JavacFileManager.
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
     */
4548
bc0d5b3c3b2d 6906175: bridge JSR199 and JSR 203 APIs
jjg
parents: 4073
diff changeset
   153
    @Override
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
    public void setContext(Context context) {
4548
bc0d5b3c3b2d 6906175: bridge JSR199 and JSR 203 APIs
jjg
parents: 4073
diff changeset
   155
        super.setContext(context);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
        if (paths == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
            paths = Paths.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
            // Reuse the Paths object as it stores the locations that
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
            // have been set with setLocation, etc.
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
            paths.setContext(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
1208
5072b0dd3d52 6743107: clean up use of static caches in file manager
jjg
parents: 1205
diff changeset
   164
        fsInfo = FSInfo.instance(context);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
        useZipFileIndex = System.getProperty("useJavaUtilZip") == null;// TODO: options.get("useJavaUtilZip") == null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
6721
d92073844278 6988436: Cleanup javac option handling
jjg
parents: 6719
diff changeset
   168
        mmappedIO = options.isSet("mmappedIO");
d92073844278 6988436: Cleanup javac option handling
jjg
parents: 6719
diff changeset
   169
        ignoreSymbolFile = options.isSet("ignore.symbol.file");
7334
f432af22de29 7003006: add option to list directory in deterministic order
jjg
parents: 6721
diff changeset
   170
f432af22de29 7003006: add option to list directory in deterministic order
jjg
parents: 6721
diff changeset
   171
        String sf = options.get("sortFiles");
f432af22de29 7003006: add option to list directory in deterministic order
jjg
parents: 6721
diff changeset
   172
        if (sf != null) {
f432af22de29 7003006: add option to list directory in deterministic order
jjg
parents: 6721
diff changeset
   173
            sortFiles = (sf.equals("reverse") ? SortFiles.REVERSE : SortFiles.FORWARD);
f432af22de29 7003006: add option to list directory in deterministic order
jjg
parents: 6721
diff changeset
   174
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
7335
8b390fd27190 6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents: 7334
diff changeset
   177
    @Override
8b390fd27190 6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents: 7334
diff changeset
   178
    public boolean isDefaultBootClassPath() {
8b390fd27190 6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents: 7334
diff changeset
   179
        return paths.isDefaultBootClassPath();
8b390fd27190 6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents: 7334
diff changeset
   180
    }
8b390fd27190 6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents: 7334
diff changeset
   181
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
    public JavaFileObject getFileForInput(String name) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
        return getRegularFile(new File(name));
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
    public JavaFileObject getRegularFile(File file) {
810
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents: 809
diff changeset
   187
        return new RegularFileObject(this, file);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
    public JavaFileObject getFileForOutput(String classname,
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
                                           JavaFileObject.Kind kind,
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
                                           JavaFileObject sibling)
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
        throws IOException
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
    {
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
        return getJavaFileForOutput(CLASS_OUTPUT, classname, kind, sibling);
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
    public Iterable<? extends JavaFileObject> getJavaFileObjectsFromStrings(Iterable<String> names) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
        ListBuffer<File> files = new ListBuffer<File>();
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
        for (String name : names)
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
            files.append(new File(nullCheck(name)));
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
        return getJavaFileObjectsFromFiles(files.toList());
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
    public Iterable<? extends JavaFileObject> getJavaFileObjects(String... names) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
        return getJavaFileObjectsFromStrings(Arrays.asList(nullCheck(names)));
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
    private static boolean isValidName(String name) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
        // Arguably, isValidName should reject keywords (such as in SourceVersion.isName() ),
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
        // but the set of keywords depends on the source level, and we don't want
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
        // impls of JavaFileManager to have to be dependent on the source level.
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
        // Therefore we simply check that the argument is a sequence of identifiers
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
        // separated by ".".
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
        for (String s : name.split("\\.", -1)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
            if (!SourceVersion.isIdentifier(s))
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
                return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
        return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   221
06bc494ca11e Initial load
duke
parents:
diff changeset
   222
    private static void validateClassName(String className) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
        if (!isValidName(className))
06bc494ca11e Initial load
duke
parents:
diff changeset
   224
            throw new IllegalArgumentException("Invalid class name: " + className);
06bc494ca11e Initial load
duke
parents:
diff changeset
   225
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
06bc494ca11e Initial load
duke
parents:
diff changeset
   227
    private static void validatePackageName(String packageName) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   228
        if (packageName.length() > 0 && !isValidName(packageName))
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
            throw new IllegalArgumentException("Invalid packageName name: " + packageName);
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   231
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
    public static void testName(String name,
06bc494ca11e Initial load
duke
parents:
diff changeset
   233
                                boolean isValidPackageName,
06bc494ca11e Initial load
duke
parents:
diff changeset
   234
                                boolean isValidClassName)
06bc494ca11e Initial load
duke
parents:
diff changeset
   235
    {
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   237
            validatePackageName(name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
            if (!isValidPackageName)
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
                throw new AssertionError("Invalid package name accepted: " + name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
            printAscii("Valid package name: \"%s\"", name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
        } catch (IllegalArgumentException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
            if (isValidPackageName)
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
                throw new AssertionError("Valid package name rejected: " + name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
            printAscii("Invalid package name: \"%s\"", name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   247
            validateClassName(name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   248
            if (!isValidClassName)
06bc494ca11e Initial load
duke
parents:
diff changeset
   249
                throw new AssertionError("Invalid class name accepted: " + name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
            printAscii("Valid class name: \"%s\"", name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   251
        } catch (IllegalArgumentException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   252
            if (isValidClassName)
06bc494ca11e Initial load
duke
parents:
diff changeset
   253
                throw new AssertionError("Valid class name rejected: " + name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   254
            printAscii("Invalid class name: \"%s\"", name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   255
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   256
    }
1205
b316e32eb90c 6508981: cleanup file separator handling in JavacFileManager
jjg
parents: 815
diff changeset
   257
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   258
    private static void printAscii(String format, Object... args) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   259
        String message;
06bc494ca11e Initial load
duke
parents:
diff changeset
   260
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
            final String ascii = "US-ASCII";
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
            message = new String(String.format(null, format, args).getBytes(ascii), ascii);
06bc494ca11e Initial load
duke
parents:
diff changeset
   263
        } catch (java.io.UnsupportedEncodingException ex) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   264
            throw new AssertionError(ex);
06bc494ca11e Initial load
duke
parents:
diff changeset
   265
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   266
        System.out.println(message);
06bc494ca11e Initial load
duke
parents:
diff changeset
   267
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   268
06bc494ca11e Initial load
duke
parents:
diff changeset
   269
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   270
     * Insert all files in subdirectory `subdirectory' of `directory' which end
06bc494ca11e Initial load
duke
parents:
diff changeset
   271
     * in one of the extensions in `extensions' into packageSym.
06bc494ca11e Initial load
duke
parents:
diff changeset
   272
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   273
    private void listDirectory(File directory,
1205
b316e32eb90c 6508981: cleanup file separator handling in JavacFileManager
jjg
parents: 815
diff changeset
   274
                               RelativeDirectory subdirectory,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   275
                               Set<JavaFileObject.Kind> fileKinds,
06bc494ca11e Initial load
duke
parents:
diff changeset
   276
                               boolean recurse,
06bc494ca11e Initial load
duke
parents:
diff changeset
   277
                               ListBuffer<JavaFileObject> l) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   278
        Archive archive = archives.get(directory);
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
1208
5072b0dd3d52 6743107: clean up use of static caches in file manager
jjg
parents: 1205
diff changeset
   280
        boolean isFile = fsInfo.isFile(directory);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   281
06bc494ca11e Initial load
duke
parents:
diff changeset
   282
        if (archive != null || isFile) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   283
            if (archive == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   284
                try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   285
                    archive = openArchive(directory);
06bc494ca11e Initial load
duke
parents:
diff changeset
   286
                } catch (IOException ex) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   287
                    log.error("error.reading.file",
5007
28dee2489196 6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents: 4548
diff changeset
   288
                       directory, getMessage(ex));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   289
                    return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   290
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   291
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   292
06bc494ca11e Initial load
duke
parents:
diff changeset
   293
            List<String> files = archive.getFiles(subdirectory);
06bc494ca11e Initial load
duke
parents:
diff changeset
   294
            if (files != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   295
                for (String file; !files.isEmpty(); files = files.tail) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   296
                    file = files.head;
06bc494ca11e Initial load
duke
parents:
diff changeset
   297
                    if (isValidFile(file, fileKinds)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   298
                        l.append(archive.getFileObject(subdirectory, file));
06bc494ca11e Initial load
duke
parents:
diff changeset
   299
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   300
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   301
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   302
            if (recurse) {
1205
b316e32eb90c 6508981: cleanup file separator handling in JavacFileManager
jjg
parents: 815
diff changeset
   303
                for (RelativeDirectory s: archive.getSubdirectories()) {
b316e32eb90c 6508981: cleanup file separator handling in JavacFileManager
jjg
parents: 815
diff changeset
   304
                    if (subdirectory.contains(s)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   305
                        // Because the archive map is a flat list of directories,
06bc494ca11e Initial load
duke
parents:
diff changeset
   306
                        // the enclosing loop will pick up all child subdirectories.
06bc494ca11e Initial load
duke
parents:
diff changeset
   307
                        // Therefore, there is no need to recurse deeper.
06bc494ca11e Initial load
duke
parents:
diff changeset
   308
                        listDirectory(directory, s, fileKinds, false, l);
06bc494ca11e Initial load
duke
parents:
diff changeset
   309
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   310
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   311
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   312
        } else {
1205
b316e32eb90c 6508981: cleanup file separator handling in JavacFileManager
jjg
parents: 815
diff changeset
   313
            File d = subdirectory.getFile(directory);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   314
            if (!caseMapCheck(d, subdirectory))
06bc494ca11e Initial load
duke
parents:
diff changeset
   315
                return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   316
06bc494ca11e Initial load
duke
parents:
diff changeset
   317
            File[] files = d.listFiles();
06bc494ca11e Initial load
duke
parents:
diff changeset
   318
            if (files == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   319
                return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   320
7334
f432af22de29 7003006: add option to list directory in deterministic order
jjg
parents: 6721
diff changeset
   321
            if (sortFiles != null)
f432af22de29 7003006: add option to list directory in deterministic order
jjg
parents: 6721
diff changeset
   322
                Arrays.sort(files, sortFiles);
f432af22de29 7003006: add option to list directory in deterministic order
jjg
parents: 6721
diff changeset
   323
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   324
            for (File f: files) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   325
                String fname = f.getName();
06bc494ca11e Initial load
duke
parents:
diff changeset
   326
                if (f.isDirectory()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   327
                    if (recurse && SourceVersion.isIdentifier(fname)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   328
                        listDirectory(directory,
1205
b316e32eb90c 6508981: cleanup file separator handling in JavacFileManager
jjg
parents: 815
diff changeset
   329
                                      new RelativeDirectory(subdirectory, fname),
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   330
                                      fileKinds,
06bc494ca11e Initial load
duke
parents:
diff changeset
   331
                                      recurse,
06bc494ca11e Initial load
duke
parents:
diff changeset
   332
                                      l);
06bc494ca11e Initial load
duke
parents:
diff changeset
   333
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   334
                } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   335
                    if (isValidFile(fname, fileKinds)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   336
                        JavaFileObject fe =
810
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents: 809
diff changeset
   337
                            new RegularFileObject(this, fname, new File(d, fname));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   338
                        l.append(fe);
06bc494ca11e Initial load
duke
parents:
diff changeset
   339
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   340
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   341
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   342
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   343
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   344
06bc494ca11e Initial load
duke
parents:
diff changeset
   345
    private boolean isValidFile(String s, Set<JavaFileObject.Kind> fileKinds) {
4548
bc0d5b3c3b2d 6906175: bridge JSR199 and JSR 203 APIs
jjg
parents: 4073
diff changeset
   346
        JavaFileObject.Kind kind = getKind(s);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   347
        return fileKinds.contains(kind);
06bc494ca11e Initial load
duke
parents:
diff changeset
   348
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   349
06bc494ca11e Initial load
duke
parents:
diff changeset
   350
    private static final boolean fileSystemIsCaseSensitive =
06bc494ca11e Initial load
duke
parents:
diff changeset
   351
        File.separatorChar == '/';
06bc494ca11e Initial load
duke
parents:
diff changeset
   352
06bc494ca11e Initial load
duke
parents:
diff changeset
   353
    /** Hack to make Windows case sensitive. Test whether given path
06bc494ca11e Initial load
duke
parents:
diff changeset
   354
     *  ends in a string of characters with the same case as given name.
06bc494ca11e Initial load
duke
parents:
diff changeset
   355
     *  Ignore file separators in both path and name.
06bc494ca11e Initial load
duke
parents:
diff changeset
   356
     */
1205
b316e32eb90c 6508981: cleanup file separator handling in JavacFileManager
jjg
parents: 815
diff changeset
   357
    private boolean caseMapCheck(File f, RelativePath name) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   358
        if (fileSystemIsCaseSensitive) return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   359
        // Note that getCanonicalPath() returns the case-sensitive
06bc494ca11e Initial load
duke
parents:
diff changeset
   360
        // spelled file name.
06bc494ca11e Initial load
duke
parents:
diff changeset
   361
        String path;
06bc494ca11e Initial load
duke
parents:
diff changeset
   362
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   363
            path = f.getCanonicalPath();
06bc494ca11e Initial load
duke
parents:
diff changeset
   364
        } catch (IOException ex) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   365
            return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   366
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   367
        char[] pcs = path.toCharArray();
1205
b316e32eb90c 6508981: cleanup file separator handling in JavacFileManager
jjg
parents: 815
diff changeset
   368
        char[] ncs = name.path.toCharArray();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   369
        int i = pcs.length - 1;
06bc494ca11e Initial load
duke
parents:
diff changeset
   370
        int j = ncs.length - 1;
06bc494ca11e Initial load
duke
parents:
diff changeset
   371
        while (i >= 0 && j >= 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   372
            while (i >= 0 && pcs[i] == File.separatorChar) i--;
1205
b316e32eb90c 6508981: cleanup file separator handling in JavacFileManager
jjg
parents: 815
diff changeset
   373
            while (j >= 0 && ncs[j] == '/') j--;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   374
            if (i >= 0 && j >= 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   375
                if (pcs[i] != ncs[j]) return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   376
                i--;
06bc494ca11e Initial load
duke
parents:
diff changeset
   377
                j--;
06bc494ca11e Initial load
duke
parents:
diff changeset
   378
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   379
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   380
        return j < 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   381
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   382
06bc494ca11e Initial load
duke
parents:
diff changeset
   383
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   384
     * An archive provides a flat directory structure of a ZipFile by
06bc494ca11e Initial load
duke
parents:
diff changeset
   385
     * mapping directory names to lists of files (basenames).
06bc494ca11e Initial load
duke
parents:
diff changeset
   386
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   387
    public interface Archive {
06bc494ca11e Initial load
duke
parents:
diff changeset
   388
        void close() throws IOException;
06bc494ca11e Initial load
duke
parents:
diff changeset
   389
1205
b316e32eb90c 6508981: cleanup file separator handling in JavacFileManager
jjg
parents: 815
diff changeset
   390
        boolean contains(RelativePath name);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   391
1205
b316e32eb90c 6508981: cleanup file separator handling in JavacFileManager
jjg
parents: 815
diff changeset
   392
        JavaFileObject getFileObject(RelativeDirectory subdirectory, String file);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   393
1205
b316e32eb90c 6508981: cleanup file separator handling in JavacFileManager
jjg
parents: 815
diff changeset
   394
        List<String> getFiles(RelativeDirectory subdirectory);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   395
1205
b316e32eb90c 6508981: cleanup file separator handling in JavacFileManager
jjg
parents: 815
diff changeset
   396
        Set<RelativeDirectory> getSubdirectories();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   397
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   398
06bc494ca11e Initial load
duke
parents:
diff changeset
   399
    public class MissingArchive implements Archive {
06bc494ca11e Initial load
duke
parents:
diff changeset
   400
        final File zipFileName;
06bc494ca11e Initial load
duke
parents:
diff changeset
   401
        public MissingArchive(File name) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   402
            zipFileName = name;
06bc494ca11e Initial load
duke
parents:
diff changeset
   403
        }
1205
b316e32eb90c 6508981: cleanup file separator handling in JavacFileManager
jjg
parents: 815
diff changeset
   404
        public boolean contains(RelativePath name) {
810
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents: 809
diff changeset
   405
            return false;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   406
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   407
06bc494ca11e Initial load
duke
parents:
diff changeset
   408
        public void close() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   409
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   410
1205
b316e32eb90c 6508981: cleanup file separator handling in JavacFileManager
jjg
parents: 815
diff changeset
   411
        public JavaFileObject getFileObject(RelativeDirectory subdirectory, String file) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   412
            return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   413
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   414
1205
b316e32eb90c 6508981: cleanup file separator handling in JavacFileManager
jjg
parents: 815
diff changeset
   415
        public List<String> getFiles(RelativeDirectory subdirectory) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   416
            return List.nil();
06bc494ca11e Initial load
duke
parents:
diff changeset
   417
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   418
1205
b316e32eb90c 6508981: cleanup file separator handling in JavacFileManager
jjg
parents: 815
diff changeset
   419
        public Set<RelativeDirectory> getSubdirectories() {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   420
            return Collections.emptySet();
06bc494ca11e Initial load
duke
parents:
diff changeset
   421
        }
1205
b316e32eb90c 6508981: cleanup file separator handling in JavacFileManager
jjg
parents: 815
diff changeset
   422
3782
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents: 3656
diff changeset
   423
        @Override
1205
b316e32eb90c 6508981: cleanup file separator handling in JavacFileManager
jjg
parents: 815
diff changeset
   424
        public String toString() {
b316e32eb90c 6508981: cleanup file separator handling in JavacFileManager
jjg
parents: 815
diff changeset
   425
            return "MissingArchive[" + zipFileName + "]";
b316e32eb90c 6508981: cleanup file separator handling in JavacFileManager
jjg
parents: 815
diff changeset
   426
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   427
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   428
06bc494ca11e Initial load
duke
parents:
diff changeset
   429
    /** A directory of zip files already opened.
06bc494ca11e Initial load
duke
parents:
diff changeset
   430
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   431
    Map<File, Archive> archives = new HashMap<File,Archive>();
06bc494ca11e Initial load
duke
parents:
diff changeset
   432
1205
b316e32eb90c 6508981: cleanup file separator handling in JavacFileManager
jjg
parents: 815
diff changeset
   433
    private static final String[] symbolFileLocation = { "lib", "ct.sym" };
b316e32eb90c 6508981: cleanup file separator handling in JavacFileManager
jjg
parents: 815
diff changeset
   434
    private static final RelativeDirectory symbolFilePrefix
b316e32eb90c 6508981: cleanup file separator handling in JavacFileManager
jjg
parents: 815
diff changeset
   435
            = new RelativeDirectory("META-INF/sym/rt.jar/");
b316e32eb90c 6508981: cleanup file separator handling in JavacFileManager
jjg
parents: 815
diff changeset
   436
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   437
    /** Open a new zip file directory.
06bc494ca11e Initial load
duke
parents:
diff changeset
   438
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   439
    protected Archive openArchive(File zipFileName) throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   440
        Archive archive = archives.get(zipFileName);
06bc494ca11e Initial load
duke
parents:
diff changeset
   441
        if (archive == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   442
            File origZipFileName = zipFileName;
06bc494ca11e Initial load
duke
parents:
diff changeset
   443
            if (!ignoreSymbolFile && paths.isBootClassPathRtJar(zipFileName)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   444
                File file = zipFileName.getParentFile().getParentFile(); // ${java.home}
06bc494ca11e Initial load
duke
parents:
diff changeset
   445
                if (new File(file.getName()).equals(new File("jre")))
06bc494ca11e Initial load
duke
parents:
diff changeset
   446
                    file = file.getParentFile();
06bc494ca11e Initial load
duke
parents:
diff changeset
   447
                // file == ${jdk.home}
06bc494ca11e Initial load
duke
parents:
diff changeset
   448
                for (String name : symbolFileLocation)
06bc494ca11e Initial load
duke
parents:
diff changeset
   449
                    file = new File(file, name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   450
                // file == ${jdk.home}/lib/ct.sym
06bc494ca11e Initial load
duke
parents:
diff changeset
   451
                if (file.exists())
06bc494ca11e Initial load
duke
parents:
diff changeset
   452
                    zipFileName = file;
06bc494ca11e Initial load
duke
parents:
diff changeset
   453
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   454
06bc494ca11e Initial load
duke
parents:
diff changeset
   455
            try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   456
06bc494ca11e Initial load
duke
parents:
diff changeset
   457
                ZipFile zdir = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   458
06bc494ca11e Initial load
duke
parents:
diff changeset
   459
                boolean usePreindexedCache = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   460
                String preindexCacheLocation = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   461
06bc494ca11e Initial load
duke
parents:
diff changeset
   462
                if (!useZipFileIndex) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   463
                    zdir = new ZipFile(zipFileName);
06bc494ca11e Initial load
duke
parents:
diff changeset
   464
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   465
                else {
6721
d92073844278 6988436: Cleanup javac option handling
jjg
parents: 6719
diff changeset
   466
                    usePreindexedCache = options.isSet("usezipindex");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   467
                    preindexCacheLocation = options.get("java.io.tmpdir");
06bc494ca11e Initial load
duke
parents:
diff changeset
   468
                    String optCacheLoc = options.get("cachezipindexdir");
06bc494ca11e Initial load
duke
parents:
diff changeset
   469
06bc494ca11e Initial load
duke
parents:
diff changeset
   470
                    if (optCacheLoc != null && optCacheLoc.length() != 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   471
                        if (optCacheLoc.startsWith("\"")) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   472
                            if (optCacheLoc.endsWith("\"")) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   473
                                optCacheLoc = optCacheLoc.substring(1, optCacheLoc.length() - 1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   474
                            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   475
                           else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   476
                                optCacheLoc = optCacheLoc.substring(1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   477
                            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   478
                        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   479
06bc494ca11e Initial load
duke
parents:
diff changeset
   480
                        File cacheDir = new File(optCacheLoc);
06bc494ca11e Initial load
duke
parents:
diff changeset
   481
                        if (cacheDir.exists() && cacheDir.canWrite()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   482
                            preindexCacheLocation = optCacheLoc;
06bc494ca11e Initial load
duke
parents:
diff changeset
   483
                            if (!preindexCacheLocation.endsWith("/") &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   484
                                !preindexCacheLocation.endsWith(File.separator)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   485
                                preindexCacheLocation += File.separator;
06bc494ca11e Initial load
duke
parents:
diff changeset
   486
                            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   487
                        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   488
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   489
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   490
06bc494ca11e Initial load
duke
parents:
diff changeset
   491
                if (origZipFileName == zipFileName) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   492
                    if (!useZipFileIndex) {
810
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents: 809
diff changeset
   493
                        archive = new ZipArchive(this, zdir);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   494
                    } else {
1205
b316e32eb90c 6508981: cleanup file separator handling in JavacFileManager
jjg
parents: 815
diff changeset
   495
                        archive = new ZipFileIndexArchive(this,
b316e32eb90c 6508981: cleanup file separator handling in JavacFileManager
jjg
parents: 815
diff changeset
   496
                                ZipFileIndex.getZipFileIndex(zipFileName,
b316e32eb90c 6508981: cleanup file separator handling in JavacFileManager
jjg
parents: 815
diff changeset
   497
                                    null,
b316e32eb90c 6508981: cleanup file separator handling in JavacFileManager
jjg
parents: 815
diff changeset
   498
                                    usePreindexedCache,
b316e32eb90c 6508981: cleanup file separator handling in JavacFileManager
jjg
parents: 815
diff changeset
   499
                                    preindexCacheLocation,
6721
d92073844278 6988436: Cleanup javac option handling
jjg
parents: 6719
diff changeset
   500
                                    options.isSet("writezipindexfiles")));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   501
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   502
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   503
                else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   504
                    if (!useZipFileIndex) {
810
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents: 809
diff changeset
   505
                        archive = new SymbolArchive(this, origZipFileName, zdir, symbolFilePrefix);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   506
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   507
                    else {
810
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents: 809
diff changeset
   508
                        archive = new ZipFileIndexArchive(this,
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents: 809
diff changeset
   509
                                ZipFileIndex.getZipFileIndex(zipFileName,
1205
b316e32eb90c 6508981: cleanup file separator handling in JavacFileManager
jjg
parents: 815
diff changeset
   510
                                    symbolFilePrefix,
b316e32eb90c 6508981: cleanup file separator handling in JavacFileManager
jjg
parents: 815
diff changeset
   511
                                    usePreindexedCache,
b316e32eb90c 6508981: cleanup file separator handling in JavacFileManager
jjg
parents: 815
diff changeset
   512
                                    preindexCacheLocation,
6721
d92073844278 6988436: Cleanup javac option handling
jjg
parents: 6719
diff changeset
   513
                                    options.isSet("writezipindexfiles")));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   514
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   515
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   516
            } catch (FileNotFoundException ex) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   517
                archive = new MissingArchive(zipFileName);
06bc494ca11e Initial load
duke
parents:
diff changeset
   518
            } catch (IOException ex) {
809
2106a64c0a38 6625520: javac handles missing entries on classpath badly
jjg
parents: 731
diff changeset
   519
                if (zipFileName.exists())
5007
28dee2489196 6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents: 4548
diff changeset
   520
                    log.error("error.reading.file", zipFileName, getMessage(ex));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   521
                archive = new MissingArchive(zipFileName);
06bc494ca11e Initial load
duke
parents:
diff changeset
   522
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   523
06bc494ca11e Initial load
duke
parents:
diff changeset
   524
            archives.put(origZipFileName, archive);
06bc494ca11e Initial load
duke
parents:
diff changeset
   525
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   526
        return archive;
06bc494ca11e Initial load
duke
parents:
diff changeset
   527
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   528
06bc494ca11e Initial load
duke
parents:
diff changeset
   529
    /** Flush any output resources.
06bc494ca11e Initial load
duke
parents:
diff changeset
   530
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   531
    public void flush() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   532
        contentCache.clear();
06bc494ca11e Initial load
duke
parents:
diff changeset
   533
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   534
06bc494ca11e Initial load
duke
parents:
diff changeset
   535
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   536
     * Close the JavaFileManager, releasing resources.
06bc494ca11e Initial load
duke
parents:
diff changeset
   537
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   538
    public void close() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   539
        for (Iterator<Archive> i = archives.values().iterator(); i.hasNext(); ) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   540
            Archive a = i.next();
06bc494ca11e Initial load
duke
parents:
diff changeset
   541
            i.remove();
06bc494ca11e Initial load
duke
parents:
diff changeset
   542
            try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   543
                a.close();
06bc494ca11e Initial load
duke
parents:
diff changeset
   544
            } catch (IOException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   545
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   546
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   547
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   548
06bc494ca11e Initial load
duke
parents:
diff changeset
   549
    private String defaultEncodingName;
06bc494ca11e Initial load
duke
parents:
diff changeset
   550
    private String getDefaultEncodingName() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   551
        if (defaultEncodingName == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   552
            defaultEncodingName =
06bc494ca11e Initial load
duke
parents:
diff changeset
   553
                new OutputStreamWriter(new ByteArrayOutputStream()).getEncoding();
06bc494ca11e Initial load
duke
parents:
diff changeset
   554
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   555
        return defaultEncodingName;
06bc494ca11e Initial load
duke
parents:
diff changeset
   556
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   557
06bc494ca11e Initial load
duke
parents:
diff changeset
   558
    public ClassLoader getClassLoader(Location location) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   559
        nullCheck(location);
06bc494ca11e Initial load
duke
parents:
diff changeset
   560
        Iterable<? extends File> path = getLocation(location);
06bc494ca11e Initial load
duke
parents:
diff changeset
   561
        if (path == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   562
            return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   563
        ListBuffer<URL> lb = new ListBuffer<URL>();
06bc494ca11e Initial load
duke
parents:
diff changeset
   564
        for (File f: path) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   565
            try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   566
                lb.append(f.toURI().toURL());
06bc494ca11e Initial load
duke
parents:
diff changeset
   567
            } catch (MalformedURLException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   568
                throw new AssertionError(e);
06bc494ca11e Initial load
duke
parents:
diff changeset
   569
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   570
        }
3656
d4e34b76b0c3 6558476: com/sun/tools/javac/Main.compile don't release file handles on return
jjg
parents: 3380
diff changeset
   571
4548
bc0d5b3c3b2d 6906175: bridge JSR199 and JSR 203 APIs
jjg
parents: 4073
diff changeset
   572
        return getClassLoader(lb.toArray(new URL[lb.size()]));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   573
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   574
06bc494ca11e Initial load
duke
parents:
diff changeset
   575
    public Iterable<JavaFileObject> list(Location location,
06bc494ca11e Initial load
duke
parents:
diff changeset
   576
                                         String packageName,
06bc494ca11e Initial load
duke
parents:
diff changeset
   577
                                         Set<JavaFileObject.Kind> kinds,
06bc494ca11e Initial load
duke
parents:
diff changeset
   578
                                         boolean recurse)
06bc494ca11e Initial load
duke
parents:
diff changeset
   579
        throws IOException
06bc494ca11e Initial load
duke
parents:
diff changeset
   580
    {
06bc494ca11e Initial load
duke
parents:
diff changeset
   581
        // validatePackageName(packageName);
06bc494ca11e Initial load
duke
parents:
diff changeset
   582
        nullCheck(packageName);
06bc494ca11e Initial load
duke
parents:
diff changeset
   583
        nullCheck(kinds);
06bc494ca11e Initial load
duke
parents:
diff changeset
   584
06bc494ca11e Initial load
duke
parents:
diff changeset
   585
        Iterable<? extends File> path = getLocation(location);
06bc494ca11e Initial load
duke
parents:
diff changeset
   586
        if (path == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   587
            return List.nil();
1205
b316e32eb90c 6508981: cleanup file separator handling in JavacFileManager
jjg
parents: 815
diff changeset
   588
        RelativeDirectory subdirectory = RelativeDirectory.forPackage(packageName);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   589
        ListBuffer<JavaFileObject> results = new ListBuffer<JavaFileObject>();
06bc494ca11e Initial load
duke
parents:
diff changeset
   590
06bc494ca11e Initial load
duke
parents:
diff changeset
   591
        for (File directory : path)
06bc494ca11e Initial load
duke
parents:
diff changeset
   592
            listDirectory(directory, subdirectory, kinds, recurse, results);
06bc494ca11e Initial load
duke
parents:
diff changeset
   593
06bc494ca11e Initial load
duke
parents:
diff changeset
   594
        return results.toList();
06bc494ca11e Initial load
duke
parents:
diff changeset
   595
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   596
06bc494ca11e Initial load
duke
parents:
diff changeset
   597
    public String inferBinaryName(Location location, JavaFileObject file) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   598
        file.getClass(); // null check
06bc494ca11e Initial load
duke
parents:
diff changeset
   599
        location.getClass(); // null check
06bc494ca11e Initial load
duke
parents:
diff changeset
   600
        // Need to match the path semantics of list(location, ...)
06bc494ca11e Initial load
duke
parents:
diff changeset
   601
        Iterable<? extends File> path = getLocation(location);
06bc494ca11e Initial load
duke
parents:
diff changeset
   602
        if (path == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   603
            return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   604
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   605
810
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents: 809
diff changeset
   606
        if (file instanceof BaseFileObject) {
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents: 809
diff changeset
   607
            return ((BaseFileObject) file).inferBinaryName(path);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   608
        } else
06bc494ca11e Initial load
duke
parents:
diff changeset
   609
            throw new IllegalArgumentException(file.getClass().getName());
06bc494ca11e Initial load
duke
parents:
diff changeset
   610
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   611
06bc494ca11e Initial load
duke
parents:
diff changeset
   612
    public boolean isSameFile(FileObject a, FileObject b) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   613
        nullCheck(a);
06bc494ca11e Initial load
duke
parents:
diff changeset
   614
        nullCheck(b);
06bc494ca11e Initial load
duke
parents:
diff changeset
   615
        if (!(a instanceof BaseFileObject))
06bc494ca11e Initial load
duke
parents:
diff changeset
   616
            throw new IllegalArgumentException("Not supported: " + a);
06bc494ca11e Initial load
duke
parents:
diff changeset
   617
        if (!(b instanceof BaseFileObject))
06bc494ca11e Initial load
duke
parents:
diff changeset
   618
            throw new IllegalArgumentException("Not supported: " + b);
06bc494ca11e Initial load
duke
parents:
diff changeset
   619
        return a.equals(b);
06bc494ca11e Initial load
duke
parents:
diff changeset
   620
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   621
06bc494ca11e Initial load
duke
parents:
diff changeset
   622
    public boolean hasLocation(Location location) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   623
        return getLocation(location) != null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   624
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   625
06bc494ca11e Initial load
duke
parents:
diff changeset
   626
    public JavaFileObject getJavaFileForInput(Location location,
06bc494ca11e Initial load
duke
parents:
diff changeset
   627
                                              String className,
06bc494ca11e Initial load
duke
parents:
diff changeset
   628
                                              JavaFileObject.Kind kind)
06bc494ca11e Initial load
duke
parents:
diff changeset
   629
        throws IOException
06bc494ca11e Initial load
duke
parents:
diff changeset
   630
    {
06bc494ca11e Initial load
duke
parents:
diff changeset
   631
        nullCheck(location);
06bc494ca11e Initial load
duke
parents:
diff changeset
   632
        // validateClassName(className);
06bc494ca11e Initial load
duke
parents:
diff changeset
   633
        nullCheck(className);
06bc494ca11e Initial load
duke
parents:
diff changeset
   634
        nullCheck(kind);
06bc494ca11e Initial load
duke
parents:
diff changeset
   635
        if (!sourceOrClass.contains(kind))
6719
1ce993f87850 6502392: Invalid relative names for Filer.createResource and Filer.getResource
jjg
parents: 5847
diff changeset
   636
            throw new IllegalArgumentException("Invalid kind: " + kind);
1205
b316e32eb90c 6508981: cleanup file separator handling in JavacFileManager
jjg
parents: 815
diff changeset
   637
        return getFileForInput(location, RelativeFile.forClass(className, kind));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   638
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   639
06bc494ca11e Initial load
duke
parents:
diff changeset
   640
    public FileObject getFileForInput(Location location,
06bc494ca11e Initial load
duke
parents:
diff changeset
   641
                                      String packageName,
06bc494ca11e Initial load
duke
parents:
diff changeset
   642
                                      String relativeName)
06bc494ca11e Initial load
duke
parents:
diff changeset
   643
        throws IOException
06bc494ca11e Initial load
duke
parents:
diff changeset
   644
    {
06bc494ca11e Initial load
duke
parents:
diff changeset
   645
        nullCheck(location);
06bc494ca11e Initial load
duke
parents:
diff changeset
   646
        // validatePackageName(packageName);
06bc494ca11e Initial load
duke
parents:
diff changeset
   647
        nullCheck(packageName);
3782
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents: 3656
diff changeset
   648
        if (!isRelativeUri(relativeName))
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   649
            throw new IllegalArgumentException("Invalid relative name: " + relativeName);
1205
b316e32eb90c 6508981: cleanup file separator handling in JavacFileManager
jjg
parents: 815
diff changeset
   650
        RelativeFile name = packageName.length() == 0
b316e32eb90c 6508981: cleanup file separator handling in JavacFileManager
jjg
parents: 815
diff changeset
   651
            ? new RelativeFile(relativeName)
b316e32eb90c 6508981: cleanup file separator handling in JavacFileManager
jjg
parents: 815
diff changeset
   652
            : new RelativeFile(RelativeDirectory.forPackage(packageName), relativeName);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   653
        return getFileForInput(location, name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   654
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   655
1205
b316e32eb90c 6508981: cleanup file separator handling in JavacFileManager
jjg
parents: 815
diff changeset
   656
    private JavaFileObject getFileForInput(Location location, RelativeFile name) throws IOException {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   657
        Iterable<? extends File> path = getLocation(location);
06bc494ca11e Initial load
duke
parents:
diff changeset
   658
        if (path == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   659
            return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   660
06bc494ca11e Initial load
duke
parents:
diff changeset
   661
        for (File dir: path) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   662
            if (dir.isDirectory()) {
1205
b316e32eb90c 6508981: cleanup file separator handling in JavacFileManager
jjg
parents: 815
diff changeset
   663
                File f = name.getFile(dir);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   664
                if (f.exists())
810
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents: 809
diff changeset
   665
                    return new RegularFileObject(this, f);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   666
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   667
                Archive a = openArchive(dir);
06bc494ca11e Initial load
duke
parents:
diff changeset
   668
                if (a.contains(name)) {
1205
b316e32eb90c 6508981: cleanup file separator handling in JavacFileManager
jjg
parents: 815
diff changeset
   669
                    return a.getFileObject(name.dirname(), name.basename());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   670
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   671
06bc494ca11e Initial load
duke
parents:
diff changeset
   672
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   673
        }
1205
b316e32eb90c 6508981: cleanup file separator handling in JavacFileManager
jjg
parents: 815
diff changeset
   674
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   675
        return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   676
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   677
06bc494ca11e Initial load
duke
parents:
diff changeset
   678
    public JavaFileObject getJavaFileForOutput(Location location,
06bc494ca11e Initial load
duke
parents:
diff changeset
   679
                                               String className,
06bc494ca11e Initial load
duke
parents:
diff changeset
   680
                                               JavaFileObject.Kind kind,
06bc494ca11e Initial load
duke
parents:
diff changeset
   681
                                               FileObject sibling)
06bc494ca11e Initial load
duke
parents:
diff changeset
   682
        throws IOException
06bc494ca11e Initial load
duke
parents:
diff changeset
   683
    {
06bc494ca11e Initial load
duke
parents:
diff changeset
   684
        nullCheck(location);
06bc494ca11e Initial load
duke
parents:
diff changeset
   685
        // validateClassName(className);
06bc494ca11e Initial load
duke
parents:
diff changeset
   686
        nullCheck(className);
06bc494ca11e Initial load
duke
parents:
diff changeset
   687
        nullCheck(kind);
06bc494ca11e Initial load
duke
parents:
diff changeset
   688
        if (!sourceOrClass.contains(kind))
6719
1ce993f87850 6502392: Invalid relative names for Filer.createResource and Filer.getResource
jjg
parents: 5847
diff changeset
   689
            throw new IllegalArgumentException("Invalid kind: " + kind);
1205
b316e32eb90c 6508981: cleanup file separator handling in JavacFileManager
jjg
parents: 815
diff changeset
   690
        return getFileForOutput(location, RelativeFile.forClass(className, kind), sibling);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   691
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   692
06bc494ca11e Initial load
duke
parents:
diff changeset
   693
    public FileObject getFileForOutput(Location location,
06bc494ca11e Initial load
duke
parents:
diff changeset
   694
                                       String packageName,
06bc494ca11e Initial load
duke
parents:
diff changeset
   695
                                       String relativeName,
06bc494ca11e Initial load
duke
parents:
diff changeset
   696
                                       FileObject sibling)
06bc494ca11e Initial load
duke
parents:
diff changeset
   697
        throws IOException
06bc494ca11e Initial load
duke
parents:
diff changeset
   698
    {
06bc494ca11e Initial load
duke
parents:
diff changeset
   699
        nullCheck(location);
06bc494ca11e Initial load
duke
parents:
diff changeset
   700
        // validatePackageName(packageName);
06bc494ca11e Initial load
duke
parents:
diff changeset
   701
        nullCheck(packageName);
3782
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents: 3656
diff changeset
   702
        if (!isRelativeUri(relativeName))
6719
1ce993f87850 6502392: Invalid relative names for Filer.createResource and Filer.getResource
jjg
parents: 5847
diff changeset
   703
            throw new IllegalArgumentException("Invalid relative name: " + relativeName);
1205
b316e32eb90c 6508981: cleanup file separator handling in JavacFileManager
jjg
parents: 815
diff changeset
   704
        RelativeFile name = packageName.length() == 0
b316e32eb90c 6508981: cleanup file separator handling in JavacFileManager
jjg
parents: 815
diff changeset
   705
            ? new RelativeFile(relativeName)
b316e32eb90c 6508981: cleanup file separator handling in JavacFileManager
jjg
parents: 815
diff changeset
   706
            : new RelativeFile(RelativeDirectory.forPackage(packageName), relativeName);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   707
        return getFileForOutput(location, name, sibling);
06bc494ca11e Initial load
duke
parents:
diff changeset
   708
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   709
06bc494ca11e Initial load
duke
parents:
diff changeset
   710
    private JavaFileObject getFileForOutput(Location location,
1205
b316e32eb90c 6508981: cleanup file separator handling in JavacFileManager
jjg
parents: 815
diff changeset
   711
                                            RelativeFile fileName,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   712
                                            FileObject sibling)
06bc494ca11e Initial load
duke
parents:
diff changeset
   713
        throws IOException
06bc494ca11e Initial load
duke
parents:
diff changeset
   714
    {
06bc494ca11e Initial load
duke
parents:
diff changeset
   715
        File dir;
06bc494ca11e Initial load
duke
parents:
diff changeset
   716
        if (location == CLASS_OUTPUT) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   717
            if (getClassOutDir() != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   718
                dir = getClassOutDir();
06bc494ca11e Initial load
duke
parents:
diff changeset
   719
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   720
                File siblingDir = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   721
                if (sibling != null && sibling instanceof RegularFileObject) {
4073
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents: 3998
diff changeset
   722
                    siblingDir = ((RegularFileObject)sibling).file.getParentFile();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   723
                }
1205
b316e32eb90c 6508981: cleanup file separator handling in JavacFileManager
jjg
parents: 815
diff changeset
   724
                return new RegularFileObject(this, new File(siblingDir, fileName.basename()));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   725
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   726
        } else if (location == SOURCE_OUTPUT) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   727
            dir = (getSourceOutDir() != null ? getSourceOutDir() : getClassOutDir());
06bc494ca11e Initial load
duke
parents:
diff changeset
   728
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   729
            Iterable<? extends File> path = paths.getPathForLocation(location);
06bc494ca11e Initial load
duke
parents:
diff changeset
   730
            dir = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   731
            for (File f: path) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   732
                dir = f;
06bc494ca11e Initial load
duke
parents:
diff changeset
   733
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   734
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   735
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   736
1205
b316e32eb90c 6508981: cleanup file separator handling in JavacFileManager
jjg
parents: 815
diff changeset
   737
        File file = fileName.getFile(dir); // null-safe
810
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents: 809
diff changeset
   738
        return new RegularFileObject(this, file);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   739
06bc494ca11e Initial load
duke
parents:
diff changeset
   740
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   741
06bc494ca11e Initial load
duke
parents:
diff changeset
   742
    public Iterable<? extends JavaFileObject> getJavaFileObjectsFromFiles(
06bc494ca11e Initial load
duke
parents:
diff changeset
   743
        Iterable<? extends File> files)
06bc494ca11e Initial load
duke
parents:
diff changeset
   744
    {
06bc494ca11e Initial load
duke
parents:
diff changeset
   745
        ArrayList<RegularFileObject> result;
1789
7ac8c0815000 6765045: Remove rawtypes warnings from langtools
mcimadamore
parents: 1208
diff changeset
   746
        if (files instanceof Collection<?>)
7ac8c0815000 6765045: Remove rawtypes warnings from langtools
mcimadamore
parents: 1208
diff changeset
   747
            result = new ArrayList<RegularFileObject>(((Collection<?>)files).size());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   748
        else
06bc494ca11e Initial load
duke
parents:
diff changeset
   749
            result = new ArrayList<RegularFileObject>();
06bc494ca11e Initial load
duke
parents:
diff changeset
   750
        for (File f: files)
810
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents: 809
diff changeset
   751
            result.add(new RegularFileObject(this, nullCheck(f)));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   752
        return result;
06bc494ca11e Initial load
duke
parents:
diff changeset
   753
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   754
06bc494ca11e Initial load
duke
parents:
diff changeset
   755
    public Iterable<? extends JavaFileObject> getJavaFileObjects(File... files) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   756
        return getJavaFileObjectsFromFiles(Arrays.asList(nullCheck(files)));
06bc494ca11e Initial load
duke
parents:
diff changeset
   757
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   758
06bc494ca11e Initial load
duke
parents:
diff changeset
   759
    public void setLocation(Location location,
06bc494ca11e Initial load
duke
parents:
diff changeset
   760
                            Iterable<? extends File> path)
06bc494ca11e Initial load
duke
parents:
diff changeset
   761
        throws IOException
06bc494ca11e Initial load
duke
parents:
diff changeset
   762
    {
06bc494ca11e Initial load
duke
parents:
diff changeset
   763
        nullCheck(location);
06bc494ca11e Initial load
duke
parents:
diff changeset
   764
        paths.lazy();
06bc494ca11e Initial load
duke
parents:
diff changeset
   765
06bc494ca11e Initial load
duke
parents:
diff changeset
   766
        final File dir = location.isOutputLocation() ? getOutputDirectory(path) : null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   767
06bc494ca11e Initial load
duke
parents:
diff changeset
   768
        if (location == CLASS_OUTPUT)
06bc494ca11e Initial load
duke
parents:
diff changeset
   769
            classOutDir = getOutputLocation(dir, D);
06bc494ca11e Initial load
duke
parents:
diff changeset
   770
        else if (location == SOURCE_OUTPUT)
06bc494ca11e Initial load
duke
parents:
diff changeset
   771
            sourceOutDir = getOutputLocation(dir, S);
06bc494ca11e Initial load
duke
parents:
diff changeset
   772
        else
06bc494ca11e Initial load
duke
parents:
diff changeset
   773
            paths.setPathForLocation(location, path);
06bc494ca11e Initial load
duke
parents:
diff changeset
   774
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   775
    // where
06bc494ca11e Initial load
duke
parents:
diff changeset
   776
        private File getOutputDirectory(Iterable<? extends File> path) throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   777
            if (path == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   778
                return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   779
            Iterator<? extends File> pathIter = path.iterator();
06bc494ca11e Initial load
duke
parents:
diff changeset
   780
            if (!pathIter.hasNext())
06bc494ca11e Initial load
duke
parents:
diff changeset
   781
                throw new IllegalArgumentException("empty path for directory");
06bc494ca11e Initial load
duke
parents:
diff changeset
   782
            File dir = pathIter.next();
06bc494ca11e Initial load
duke
parents:
diff changeset
   783
            if (pathIter.hasNext())
06bc494ca11e Initial load
duke
parents:
diff changeset
   784
                throw new IllegalArgumentException("path too long for directory");
06bc494ca11e Initial load
duke
parents:
diff changeset
   785
            if (!dir.exists())
06bc494ca11e Initial load
duke
parents:
diff changeset
   786
                throw new FileNotFoundException(dir + ": does not exist");
06bc494ca11e Initial load
duke
parents:
diff changeset
   787
            else if (!dir.isDirectory())
06bc494ca11e Initial load
duke
parents:
diff changeset
   788
                throw new IOException(dir + ": not a directory");
06bc494ca11e Initial load
duke
parents:
diff changeset
   789
            return dir;
06bc494ca11e Initial load
duke
parents:
diff changeset
   790
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   791
06bc494ca11e Initial load
duke
parents:
diff changeset
   792
    private File getOutputLocation(File dir, OptionName defaultOptionName) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   793
        if (dir != null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   794
            return dir;
06bc494ca11e Initial load
duke
parents:
diff changeset
   795
        String arg = options.get(defaultOptionName);
06bc494ca11e Initial load
duke
parents:
diff changeset
   796
        if (arg == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   797
            return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   798
        return new File(arg);
06bc494ca11e Initial load
duke
parents:
diff changeset
   799
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   800
06bc494ca11e Initial load
duke
parents:
diff changeset
   801
    public Iterable<? extends File> getLocation(Location location) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   802
        nullCheck(location);
06bc494ca11e Initial load
duke
parents:
diff changeset
   803
        paths.lazy();
06bc494ca11e Initial load
duke
parents:
diff changeset
   804
        if (location == CLASS_OUTPUT) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   805
            return (getClassOutDir() == null ? null : List.of(getClassOutDir()));
06bc494ca11e Initial load
duke
parents:
diff changeset
   806
        } else if (location == SOURCE_OUTPUT) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   807
            return (getSourceOutDir() == null ? null : List.of(getSourceOutDir()));
06bc494ca11e Initial load
duke
parents:
diff changeset
   808
        } else
06bc494ca11e Initial load
duke
parents:
diff changeset
   809
            return paths.getPathForLocation(location);
06bc494ca11e Initial load
duke
parents:
diff changeset
   810
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   811
06bc494ca11e Initial load
duke
parents:
diff changeset
   812
    private File getClassOutDir() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   813
        if (classOutDir == uninited)
06bc494ca11e Initial load
duke
parents:
diff changeset
   814
            classOutDir = getOutputLocation(null, D);
06bc494ca11e Initial load
duke
parents:
diff changeset
   815
        return classOutDir;
06bc494ca11e Initial load
duke
parents:
diff changeset
   816
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   817
06bc494ca11e Initial load
duke
parents:
diff changeset
   818
    private File getSourceOutDir() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   819
        if (sourceOutDir == uninited)
06bc494ca11e Initial load
duke
parents:
diff changeset
   820
            sourceOutDir = getOutputLocation(null, S);
06bc494ca11e Initial load
duke
parents:
diff changeset
   821
        return sourceOutDir;
06bc494ca11e Initial load
duke
parents:
diff changeset
   822
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   823
06bc494ca11e Initial load
duke
parents:
diff changeset
   824
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   825
     * Enforces the specification of a "relative" URI as used in
06bc494ca11e Initial load
duke
parents:
diff changeset
   826
     * {@linkplain #getFileForInput(Location,String,URI)
06bc494ca11e Initial load
duke
parents:
diff changeset
   827
     * getFileForInput}.  This method must follow the rules defined in
06bc494ca11e Initial load
duke
parents:
diff changeset
   828
     * that method, do not make any changes without consulting the
06bc494ca11e Initial load
duke
parents:
diff changeset
   829
     * specification.
06bc494ca11e Initial load
duke
parents:
diff changeset
   830
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   831
    protected static boolean isRelativeUri(URI uri) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   832
        if (uri.isAbsolute())
06bc494ca11e Initial load
duke
parents:
diff changeset
   833
            return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   834
        String path = uri.normalize().getPath();
06bc494ca11e Initial load
duke
parents:
diff changeset
   835
        if (path.length() == 0 /* isEmpty() is mustang API */)
06bc494ca11e Initial load
duke
parents:
diff changeset
   836
            return false;
6719
1ce993f87850 6502392: Invalid relative names for Filer.createResource and Filer.getResource
jjg
parents: 5847
diff changeset
   837
        if (!path.equals(uri.getPath())) // implicitly checks for embedded . and ..
1ce993f87850 6502392: Invalid relative names for Filer.createResource and Filer.getResource
jjg
parents: 5847
diff changeset
   838
            return false;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   839
        char first = path.charAt(0);
06bc494ca11e Initial load
duke
parents:
diff changeset
   840
        return first != '.' && first != '/';
06bc494ca11e Initial load
duke
parents:
diff changeset
   841
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   842
3782
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents: 3656
diff changeset
   843
    // Convenience method
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents: 3656
diff changeset
   844
    protected static boolean isRelativeUri(String u) {
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents: 3656
diff changeset
   845
        try {
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents: 3656
diff changeset
   846
            return isRelativeUri(new URI(u));
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents: 3656
diff changeset
   847
        } catch (URISyntaxException e) {
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents: 3656
diff changeset
   848
            return false;
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents: 3656
diff changeset
   849
        }
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents: 3656
diff changeset
   850
    }
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents: 3656
diff changeset
   851
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   852
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   853
     * Converts a relative file name to a relative URI.  This is
06bc494ca11e Initial load
duke
parents:
diff changeset
   854
     * different from File.toURI as this method does not canonicalize
06bc494ca11e Initial load
duke
parents:
diff changeset
   855
     * the file before creating the URI.  Furthermore, no schema is
06bc494ca11e Initial load
duke
parents:
diff changeset
   856
     * used.
06bc494ca11e Initial load
duke
parents:
diff changeset
   857
     * @param file a relative file name
06bc494ca11e Initial load
duke
parents:
diff changeset
   858
     * @return a relative URI
06bc494ca11e Initial load
duke
parents:
diff changeset
   859
     * @throws IllegalArgumentException if the file name is not
06bc494ca11e Initial load
duke
parents:
diff changeset
   860
     * relative according to the definition given in {@link
06bc494ca11e Initial load
duke
parents:
diff changeset
   861
     * javax.tools.JavaFileManager#getFileForInput}
06bc494ca11e Initial load
duke
parents:
diff changeset
   862
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   863
    public static String getRelativeName(File file) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   864
        if (!file.isAbsolute()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   865
            String result = file.getPath().replace(File.separatorChar, '/');
3782
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents: 3656
diff changeset
   866
            if (isRelativeUri(result))
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   867
                return result;
06bc494ca11e Initial load
duke
parents:
diff changeset
   868
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   869
        throw new IllegalArgumentException("Invalid relative path: " + file);
06bc494ca11e Initial load
duke
parents:
diff changeset
   870
    }
5007
28dee2489196 6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents: 4548
diff changeset
   871
28dee2489196 6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents: 4548
diff changeset
   872
    /**
28dee2489196 6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents: 4548
diff changeset
   873
     * Get a detail message from an IOException.
28dee2489196 6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents: 4548
diff changeset
   874
     * Most, but not all, instances of IOException provide a non-null result
28dee2489196 6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents: 4548
diff changeset
   875
     * for getLocalizedMessage().  But some instances return null: in these
28dee2489196 6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents: 4548
diff changeset
   876
     * cases, fallover to getMessage(), and if even that is null, return the
28dee2489196 6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents: 4548
diff changeset
   877
     * name of the exception itself.
28dee2489196 6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents: 4548
diff changeset
   878
     * @param e an IOException
28dee2489196 6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents: 4548
diff changeset
   879
     * @return a string to include in a compiler diagnostic
28dee2489196 6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents: 4548
diff changeset
   880
     */
28dee2489196 6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents: 4548
diff changeset
   881
    public static String getMessage(IOException e) {
28dee2489196 6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents: 4548
diff changeset
   882
        String s = e.getLocalizedMessage();
28dee2489196 6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents: 4548
diff changeset
   883
        if (s != null)
28dee2489196 6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents: 4548
diff changeset
   884
            return s;
28dee2489196 6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents: 4548
diff changeset
   885
        s = e.getMessage();
28dee2489196 6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents: 4548
diff changeset
   886
        if (s != null)
28dee2489196 6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents: 4548
diff changeset
   887
            return s;
28dee2489196 6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents: 4548
diff changeset
   888
        return e.toString();
28dee2489196 6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents: 4548
diff changeset
   889
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   890
}