langtools/src/share/classes/com/sun/tools/javac/file/Paths.java
author jjg
Thu, 10 Jun 2010 16:08:01 -0700
changeset 5847 1908176fd6e3
parent 5520 86e4b9a9da40
child 6151 dd513881e71d
permissions -rw-r--r--
6944312: Potential rebranding issues in openjdk/langtools repository sources Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5007
diff changeset
     2
 * Copyright (c) 2003, 2008, 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: 171
diff changeset
    26
package com.sun.tools.javac.file;
1dd22bdb9ca5 6714364: refactor javac File handling code into new javac.file package
jjg
parents: 171
diff changeset
    27
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
import java.io.File;
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
import java.io.IOException;
4937
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
    30
import java.net.MalformedURLException;
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
    31
import java.net.URL;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
import java.util.HashMap;
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
import java.util.HashSet;
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
import java.util.Map;
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
import java.util.Set;
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
import java.util.Collection;
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
import java.util.Collections;
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
import java.util.LinkedHashSet;
4937
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
    39
import java.util.StringTokenizer;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
import java.util.zip.ZipFile;
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
import javax.tools.JavaFileManager.Location;
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
731
1dd22bdb9ca5 6714364: refactor javac File handling code into new javac.file package
jjg
parents: 171
diff changeset
    43
import com.sun.tools.javac.code.Lint;
1dd22bdb9ca5 6714364: refactor javac File handling code into new javac.file package
jjg
parents: 171
diff changeset
    44
import com.sun.tools.javac.util.Context;
1486
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
    45
import com.sun.tools.javac.util.ListBuffer;
731
1dd22bdb9ca5 6714364: refactor javac File handling code into new javac.file package
jjg
parents: 171
diff changeset
    46
import com.sun.tools.javac.util.Log;
1dd22bdb9ca5 6714364: refactor javac File handling code into new javac.file package
jjg
parents: 171
diff changeset
    47
import com.sun.tools.javac.util.Options;
1dd22bdb9ca5 6714364: refactor javac File handling code into new javac.file package
jjg
parents: 171
diff changeset
    48
1dd22bdb9ca5 6714364: refactor javac File handling code into new javac.file package
jjg
parents: 171
diff changeset
    49
import static javax.tools.StandardLocation.*;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
import static com.sun.tools.javac.main.OptionName.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
/** This class converts command line arguments, environment variables
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
 *  and system properties (in File.pathSeparator-separated String form)
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
 *  into a boot class path, user class path, and source path (in
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
 *  Collection<String> form).
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
 *
5847
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    57
 *  <p><b>This is NOT part of any supported API.
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    58
 *  If you write code that depends on this, you do so at your own risk.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
 *  This code and its internal interfaces are subject to change or
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
 *  deletion without notice.</b>
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
public class Paths {
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
    /** The context key for the todo list */
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
    protected static final Context.Key<Paths> pathsKey =
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
        new Context.Key<Paths>();
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
171
2afbdd3321d0 6638501: Regression with Javac in JDK6 U4 b03?
jjg
parents: 10
diff changeset
    68
    /** Get the Paths instance for this context.
2afbdd3321d0 6638501: Regression with Javac in JDK6 U4 b03?
jjg
parents: 10
diff changeset
    69
     *  @param context the context
2afbdd3321d0 6638501: Regression with Javac in JDK6 U4 b03?
jjg
parents: 10
diff changeset
    70
     *  @return the Paths instance for this context
2afbdd3321d0 6638501: Regression with Javac in JDK6 U4 b03?
jjg
parents: 10
diff changeset
    71
     */
4548
bc0d5b3c3b2d 6906175: bridge JSR199 and JSR 203 APIs
jjg
parents: 2981
diff changeset
    72
    public static Paths instance(Context context) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
        Paths instance = context.get(pathsKey);
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
        if (instance == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
            instance = new Paths(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
        return instance;
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
    /** The log to use for warning output */
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
    private Log log;
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
    /** Collection of command-line options */
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
    private Options options;
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
    /** Handler for -Xlint options */
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
    private Lint lint;
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
1208
5072b0dd3d52 6743107: clean up use of static caches in file manager
jjg
parents: 735
diff changeset
    88
    /** Access to (possibly cached) file info */
5072b0dd3d52 6743107: clean up use of static caches in file manager
jjg
parents: 735
diff changeset
    89
    private FSInfo fsInfo;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
    protected Paths(Context context) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
        context.put(pathsKey, this);
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
        pathsForLocation = new HashMap<Location,Path>(16);
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
        setContext(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
    void setContext(Context context) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
        log = Log.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
        options = Options.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
        lint = Lint.instance(context);
1208
5072b0dd3d52 6743107: clean up use of static caches in file manager
jjg
parents: 735
diff changeset
   101
        fsInfo = FSInfo.instance(context);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
    /** Whether to warn about non-existent path elements */
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
    private boolean warn;
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
    private Map<Location, Path> pathsForLocation;
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
    private boolean inited = false; // TODO? caching bad?
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
     * rt.jar as found on the default bootclass path.  If the user specified a
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
     * bootclasspath, null is used.
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
    private File bootClassPathRtJar = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
    Path getPathForLocation(Location location) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
        Path path = pathsForLocation.get(location);
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
        if (path == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
            setPathForLocation(location, null);
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
        return pathsForLocation.get(location);
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
    void setPathForLocation(Location location, Iterable<? extends File> path) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
        // TODO? if (inited) throw new IllegalStateException
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
        // TODO: otherwise reset sourceSearchPath, classSearchPath as needed
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
        Path p;
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
        if (path == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
            if (location == CLASS_PATH)
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
                p = computeUserClassPath();
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
            else if (location == PLATFORM_CLASS_PATH)
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
                p = computeBootClassPath();
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
            else if (location == ANNOTATION_PROCESSOR_PATH)
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
                p = computeAnnotationProcessorPath();
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
            else if (location == SOURCE_PATH)
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
                p = computeSourcePath();
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
            else
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
                // no defaults for other paths
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
                p = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
            p = new Path();
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
            for (File f: path)
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
                p.addFile(f, warn); // TODO: is use of warn appropriate?
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
        pathsForLocation.put(location, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
    protected void lazy() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
        if (!inited) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
            warn = lint.isEnabled(Lint.LintCategory.PATH);
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
            pathsForLocation.put(PLATFORM_CLASS_PATH, computeBootClassPath());
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
            pathsForLocation.put(CLASS_PATH, computeUserClassPath());
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
            pathsForLocation.put(SOURCE_PATH, computeSourcePath());
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
            inited = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
    public Collection<File> bootClassPath() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
        lazy();
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
        return Collections.unmodifiableCollection(getPathForLocation(PLATFORM_CLASS_PATH));
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
    public Collection<File> userClassPath() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
        lazy();
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
        return Collections.unmodifiableCollection(getPathForLocation(CLASS_PATH));
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
    public Collection<File> sourcePath() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
        lazy();
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
        Path p = getPathForLocation(SOURCE_PATH);
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
        return p == null || p.size() == 0
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
            ? null
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
            : Collections.unmodifiableCollection(p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
    boolean isBootClassPathRtJar(File file) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
        return file.equals(bootClassPathRtJar);
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
1486
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   180
    /**
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   181
     * Split a path into its elements. Empty path elements will be ignored.
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   182
     * @param path The path to be split
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   183
     * @return The elements of the path
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   184
     */
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   185
    private static Iterable<File> getPathEntries(String path) {
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   186
        return getPathEntries(path, null);
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   187
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
1486
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   189
    /**
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   190
     * Split a path into its elements. If emptyPathDefault is not null, all
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   191
     * empty elements in the path, including empty elements at either end of
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   192
     * the path, will be replaced with the value of emptyPathDefault.
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   193
     * @param path The path to be split
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   194
     * @param emptyPathDefault The value to substitute for empty path elements,
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   195
     *  or null, to ignore empty path elements
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   196
     * @return The elements of the path
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   197
     */
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   198
    private static Iterable<File> getPathEntries(String path, File emptyPathDefault) {
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   199
        ListBuffer<File> entries = new ListBuffer<File>();
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   200
        int start = 0;
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   201
        while (start <= path.length()) {
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   202
            int sep = path.indexOf(File.pathSeparatorChar, start);
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   203
            if (sep == -1)
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   204
                sep = path.length();
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   205
            if (start < sep)
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   206
                entries.add(new File(path.substring(start, sep)));
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   207
            else if (emptyPathDefault != null)
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   208
                entries.add(emptyPathDefault);
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   209
            start = sep + 1;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
        }
1486
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   211
        return entries;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
    private class Path extends LinkedHashSet<File> {
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
        private static final long serialVersionUID = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
        private boolean expandJarClassPaths = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
        private Set<File> canonicalValues = new HashSet<File>();
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
        public Path expandJarClassPaths(boolean x) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   221
            expandJarClassPaths = x;
06bc494ca11e Initial load
duke
parents:
diff changeset
   222
            return this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   224
06bc494ca11e Initial load
duke
parents:
diff changeset
   225
        /** What to use when path element is the empty string */
1486
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   226
        private File emptyPathDefault = null;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   227
1486
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   228
        public Path emptyPathDefault(File x) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
            emptyPathDefault = x;
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
            return this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   231
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
06bc494ca11e Initial load
duke
parents:
diff changeset
   233
        public Path() { super(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   234
06bc494ca11e Initial load
duke
parents:
diff changeset
   235
        public Path addDirectories(String dirs, boolean warn) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
            if (dirs != null)
1486
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   237
                for (File dir : getPathEntries(dirs))
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
                    addDirectory(dir, warn);
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
            return this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
        public Path addDirectories(String dirs) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
            return addDirectories(dirs, warn);
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
1486
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   246
        private void addDirectory(File dir, boolean warn) {
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   247
            if (!dir.isDirectory()) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   248
                if (warn)
06bc494ca11e Initial load
duke
parents:
diff changeset
   249
                    log.warning("dir.path.element.not.found", dir);
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
                return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   251
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   252
1486
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   253
            File[] files = dir.listFiles();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   254
            if (files == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   255
                return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   256
06bc494ca11e Initial load
duke
parents:
diff changeset
   257
            for (File direntry : files) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   258
                if (isArchive(direntry))
06bc494ca11e Initial load
duke
parents:
diff changeset
   259
                    addFile(direntry, warn);
06bc494ca11e Initial load
duke
parents:
diff changeset
   260
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
06bc494ca11e Initial load
duke
parents:
diff changeset
   263
        public Path addFiles(String files, boolean warn) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   264
            if (files != null)
1486
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   265
                for (File file : getPathEntries(files, emptyPathDefault))
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   266
                    addFile(file, warn);
06bc494ca11e Initial load
duke
parents:
diff changeset
   267
            return this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   268
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   269
06bc494ca11e Initial load
duke
parents:
diff changeset
   270
        public Path addFiles(String files) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   271
            return addFiles(files, warn);
06bc494ca11e Initial load
duke
parents:
diff changeset
   272
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   273
06bc494ca11e Initial load
duke
parents:
diff changeset
   274
        public void addFile(File file, boolean warn) {
1208
5072b0dd3d52 6743107: clean up use of static caches in file manager
jjg
parents: 735
diff changeset
   275
            File canonFile = fsInfo.getCanonicalFile(file);
5072b0dd3d52 6743107: clean up use of static caches in file manager
jjg
parents: 735
diff changeset
   276
            if (contains(file) || canonicalValues.contains(canonFile)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   277
                /* Discard duplicates and avoid infinite recursion */
06bc494ca11e Initial load
duke
parents:
diff changeset
   278
                return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   280
1208
5072b0dd3d52 6743107: clean up use of static caches in file manager
jjg
parents: 735
diff changeset
   281
            if (! fsInfo.exists(file)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   282
                /* No such file or directory exists */
06bc494ca11e Initial load
duke
parents:
diff changeset
   283
                if (warn)
06bc494ca11e Initial load
duke
parents:
diff changeset
   284
                    log.warning("path.element.not.found", file);
1208
5072b0dd3d52 6743107: clean up use of static caches in file manager
jjg
parents: 735
diff changeset
   285
            } else if (fsInfo.isFile(file)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   286
                /* File is an ordinary file. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   287
                if (!isArchive(file)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   288
                    /* Not a recognized extension; open it to see if
06bc494ca11e Initial load
duke
parents:
diff changeset
   289
                     it looks like a valid zip file. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   290
                    try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   291
                        ZipFile z = new ZipFile(file);
06bc494ca11e Initial load
duke
parents:
diff changeset
   292
                        z.close();
06bc494ca11e Initial load
duke
parents:
diff changeset
   293
                        if (warn)
06bc494ca11e Initial load
duke
parents:
diff changeset
   294
                            log.warning("unexpected.archive.file", file);
06bc494ca11e Initial load
duke
parents:
diff changeset
   295
                    } catch (IOException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   296
                        // FIXME: include e.getLocalizedMessage in warning
06bc494ca11e Initial load
duke
parents:
diff changeset
   297
                        if (warn)
06bc494ca11e Initial load
duke
parents:
diff changeset
   298
                            log.warning("invalid.archive.file", file);
06bc494ca11e Initial load
duke
parents:
diff changeset
   299
                        return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   300
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   301
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   302
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   303
06bc494ca11e Initial load
duke
parents:
diff changeset
   304
            /* Now what we have left is either a directory or a file name
06bc494ca11e Initial load
duke
parents:
diff changeset
   305
               confirming to archive naming convention */
06bc494ca11e Initial load
duke
parents:
diff changeset
   306
            super.add(file);
1208
5072b0dd3d52 6743107: clean up use of static caches in file manager
jjg
parents: 735
diff changeset
   307
            canonicalValues.add(canonFile);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   308
1208
5072b0dd3d52 6743107: clean up use of static caches in file manager
jjg
parents: 735
diff changeset
   309
            if (expandJarClassPaths && fsInfo.exists(file) && fsInfo.isFile(file))
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   310
                addJarClassPath(file, warn);
06bc494ca11e Initial load
duke
parents:
diff changeset
   311
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   312
06bc494ca11e Initial load
duke
parents:
diff changeset
   313
        // Adds referenced classpath elements from a jar's Class-Path
06bc494ca11e Initial load
duke
parents:
diff changeset
   314
        // Manifest entry.  In some future release, we may want to
06bc494ca11e Initial load
duke
parents:
diff changeset
   315
        // update this code to recognize URLs rather than simple
06bc494ca11e Initial load
duke
parents:
diff changeset
   316
        // filenames, but if we do, we should redo all path-related code.
06bc494ca11e Initial load
duke
parents:
diff changeset
   317
        private void addJarClassPath(File jarFile, boolean warn) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   318
            try {
1208
5072b0dd3d52 6743107: clean up use of static caches in file manager
jjg
parents: 735
diff changeset
   319
                for (File f: fsInfo.getJarClassPath(jarFile)) {
5072b0dd3d52 6743107: clean up use of static caches in file manager
jjg
parents: 735
diff changeset
   320
                    addFile(f, warn);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   321
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   322
            } catch (IOException e) {
5007
28dee2489196 6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents: 4937
diff changeset
   323
                log.error("error.reading.file", jarFile, JavacFileManager.getMessage(e));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   324
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   325
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   326
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   327
06bc494ca11e Initial load
duke
parents:
diff changeset
   328
    private Path computeBootClassPath() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   329
        bootClassPathRtJar = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   330
        String optionValue;
06bc494ca11e Initial load
duke
parents:
diff changeset
   331
        Path path = new Path();
06bc494ca11e Initial load
duke
parents:
diff changeset
   332
06bc494ca11e Initial load
duke
parents:
diff changeset
   333
        path.addFiles(options.get(XBOOTCLASSPATH_PREPEND));
06bc494ca11e Initial load
duke
parents:
diff changeset
   334
06bc494ca11e Initial load
duke
parents:
diff changeset
   335
        if ((optionValue = options.get(ENDORSEDDIRS)) != null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   336
            path.addDirectories(optionValue);
06bc494ca11e Initial load
duke
parents:
diff changeset
   337
        else
06bc494ca11e Initial load
duke
parents:
diff changeset
   338
            path.addDirectories(System.getProperty("java.endorsed.dirs"), false);
06bc494ca11e Initial load
duke
parents:
diff changeset
   339
06bc494ca11e Initial load
duke
parents:
diff changeset
   340
        if ((optionValue = options.get(BOOTCLASSPATH)) != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   341
            path.addFiles(optionValue);
06bc494ca11e Initial load
duke
parents:
diff changeset
   342
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   343
            // Standard system classes for this compiler's release.
06bc494ca11e Initial load
duke
parents:
diff changeset
   344
            String files = System.getProperty("sun.boot.class.path");
06bc494ca11e Initial load
duke
parents:
diff changeset
   345
            path.addFiles(files, false);
06bc494ca11e Initial load
duke
parents:
diff changeset
   346
            File rt_jar = new File("rt.jar");
1486
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   347
            for (File file : getPathEntries(files)) {
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   348
                if (new File(file.getName()).equals(rt_jar))
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   349
                    bootClassPathRtJar = file;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   350
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   351
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   352
06bc494ca11e Initial load
duke
parents:
diff changeset
   353
        path.addFiles(options.get(XBOOTCLASSPATH_APPEND));
06bc494ca11e Initial load
duke
parents:
diff changeset
   354
06bc494ca11e Initial load
duke
parents:
diff changeset
   355
        // Strictly speaking, standard extensions are not bootstrap
06bc494ca11e Initial load
duke
parents:
diff changeset
   356
        // classes, but we treat them identically, so we'll pretend
06bc494ca11e Initial load
duke
parents:
diff changeset
   357
        // that they are.
06bc494ca11e Initial load
duke
parents:
diff changeset
   358
        if ((optionValue = options.get(EXTDIRS)) != null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   359
            path.addDirectories(optionValue);
06bc494ca11e Initial load
duke
parents:
diff changeset
   360
        else
06bc494ca11e Initial load
duke
parents:
diff changeset
   361
            path.addDirectories(System.getProperty("java.ext.dirs"), false);
06bc494ca11e Initial load
duke
parents:
diff changeset
   362
06bc494ca11e Initial load
duke
parents:
diff changeset
   363
        return path;
06bc494ca11e Initial load
duke
parents:
diff changeset
   364
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   365
06bc494ca11e Initial load
duke
parents:
diff changeset
   366
    private Path computeUserClassPath() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   367
        String cp = options.get(CLASSPATH);
06bc494ca11e Initial load
duke
parents:
diff changeset
   368
06bc494ca11e Initial load
duke
parents:
diff changeset
   369
        // CLASSPATH environment variable when run from `javac'.
06bc494ca11e Initial load
duke
parents:
diff changeset
   370
        if (cp == null) cp = System.getProperty("env.class.path");
06bc494ca11e Initial load
duke
parents:
diff changeset
   371
06bc494ca11e Initial load
duke
parents:
diff changeset
   372
        // If invoked via a java VM (not the javac launcher), use the
06bc494ca11e Initial load
duke
parents:
diff changeset
   373
        // platform class path
06bc494ca11e Initial load
duke
parents:
diff changeset
   374
        if (cp == null && System.getProperty("application.home") == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   375
            cp = System.getProperty("java.class.path");
06bc494ca11e Initial load
duke
parents:
diff changeset
   376
06bc494ca11e Initial load
duke
parents:
diff changeset
   377
        // Default to current working directory.
06bc494ca11e Initial load
duke
parents:
diff changeset
   378
        if (cp == null) cp = ".";
06bc494ca11e Initial load
duke
parents:
diff changeset
   379
06bc494ca11e Initial load
duke
parents:
diff changeset
   380
        return new Path()
1486
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   381
            .expandJarClassPaths(true)        // Only search user jars for Class-Paths
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   382
            .emptyPathDefault(new File("."))  // Empty path elt ==> current directory
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   383
            .addFiles(cp);
06bc494ca11e Initial load
duke
parents:
diff changeset
   384
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   385
06bc494ca11e Initial load
duke
parents:
diff changeset
   386
    private Path computeSourcePath() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   387
        String sourcePathArg = options.get(SOURCEPATH);
06bc494ca11e Initial load
duke
parents:
diff changeset
   388
        if (sourcePathArg == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   389
            return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   390
06bc494ca11e Initial load
duke
parents:
diff changeset
   391
        return new Path().addFiles(sourcePathArg);
06bc494ca11e Initial load
duke
parents:
diff changeset
   392
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   393
06bc494ca11e Initial load
duke
parents:
diff changeset
   394
    private Path computeAnnotationProcessorPath() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   395
        String processorPathArg = options.get(PROCESSORPATH);
06bc494ca11e Initial load
duke
parents:
diff changeset
   396
        if (processorPathArg == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   397
            return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   398
06bc494ca11e Initial load
duke
parents:
diff changeset
   399
        return new Path().addFiles(processorPathArg);
06bc494ca11e Initial load
duke
parents:
diff changeset
   400
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   401
06bc494ca11e Initial load
duke
parents:
diff changeset
   402
    /** The actual effective locations searched for sources */
06bc494ca11e Initial load
duke
parents:
diff changeset
   403
    private Path sourceSearchPath;
06bc494ca11e Initial load
duke
parents:
diff changeset
   404
06bc494ca11e Initial load
duke
parents:
diff changeset
   405
    public Collection<File> sourceSearchPath() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   406
        if (sourceSearchPath == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   407
            lazy();
06bc494ca11e Initial load
duke
parents:
diff changeset
   408
            Path sourcePath = getPathForLocation(SOURCE_PATH);
06bc494ca11e Initial load
duke
parents:
diff changeset
   409
            Path userClassPath = getPathForLocation(CLASS_PATH);
06bc494ca11e Initial load
duke
parents:
diff changeset
   410
            sourceSearchPath = sourcePath != null ? sourcePath : userClassPath;
06bc494ca11e Initial load
duke
parents:
diff changeset
   411
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   412
        return Collections.unmodifiableCollection(sourceSearchPath);
06bc494ca11e Initial load
duke
parents:
diff changeset
   413
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   414
06bc494ca11e Initial load
duke
parents:
diff changeset
   415
    /** The actual effective locations searched for classes */
06bc494ca11e Initial load
duke
parents:
diff changeset
   416
    private Path classSearchPath;
06bc494ca11e Initial load
duke
parents:
diff changeset
   417
06bc494ca11e Initial load
duke
parents:
diff changeset
   418
    public Collection<File> classSearchPath() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   419
        if (classSearchPath == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   420
            lazy();
06bc494ca11e Initial load
duke
parents:
diff changeset
   421
            Path bootClassPath = getPathForLocation(PLATFORM_CLASS_PATH);
06bc494ca11e Initial load
duke
parents:
diff changeset
   422
            Path userClassPath = getPathForLocation(CLASS_PATH);
06bc494ca11e Initial load
duke
parents:
diff changeset
   423
            classSearchPath = new Path();
06bc494ca11e Initial load
duke
parents:
diff changeset
   424
            classSearchPath.addAll(bootClassPath);
06bc494ca11e Initial load
duke
parents:
diff changeset
   425
            classSearchPath.addAll(userClassPath);
06bc494ca11e Initial load
duke
parents:
diff changeset
   426
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   427
        return Collections.unmodifiableCollection(classSearchPath);
06bc494ca11e Initial load
duke
parents:
diff changeset
   428
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   429
06bc494ca11e Initial load
duke
parents:
diff changeset
   430
    /** The actual effective locations for non-source, non-class files */
06bc494ca11e Initial load
duke
parents:
diff changeset
   431
    private Path otherSearchPath;
06bc494ca11e Initial load
duke
parents:
diff changeset
   432
06bc494ca11e Initial load
duke
parents:
diff changeset
   433
    Collection<File> otherSearchPath() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   434
        if (otherSearchPath == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   435
            lazy();
06bc494ca11e Initial load
duke
parents:
diff changeset
   436
            Path userClassPath = getPathForLocation(CLASS_PATH);
06bc494ca11e Initial load
duke
parents:
diff changeset
   437
            Path sourcePath = getPathForLocation(SOURCE_PATH);
06bc494ca11e Initial load
duke
parents:
diff changeset
   438
            if (sourcePath == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   439
                otherSearchPath = userClassPath;
06bc494ca11e Initial load
duke
parents:
diff changeset
   440
            else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   441
                otherSearchPath = new Path();
06bc494ca11e Initial load
duke
parents:
diff changeset
   442
                otherSearchPath.addAll(userClassPath);
06bc494ca11e Initial load
duke
parents:
diff changeset
   443
                otherSearchPath.addAll(sourcePath);
06bc494ca11e Initial load
duke
parents:
diff changeset
   444
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   445
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   446
        return Collections.unmodifiableCollection(otherSearchPath);
06bc494ca11e Initial load
duke
parents:
diff changeset
   447
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   448
06bc494ca11e Initial load
duke
parents:
diff changeset
   449
    /** Is this the name of an archive file? */
1208
5072b0dd3d52 6743107: clean up use of static caches in file manager
jjg
parents: 735
diff changeset
   450
    private boolean isArchive(File file) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   451
        String n = file.getName().toLowerCase();
1208
5072b0dd3d52 6743107: clean up use of static caches in file manager
jjg
parents: 735
diff changeset
   452
        return fsInfo.isFile(file)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   453
            && (n.endsWith(".jar") || n.endsWith(".zip"));
06bc494ca11e Initial load
duke
parents:
diff changeset
   454
    }
4937
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   455
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   456
    /**
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   457
     * Utility method for converting a search path string to an array
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   458
     * of directory and JAR file URLs.
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   459
     *
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   460
     * Note that this method is called by apt and the DocletInvoker.
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   461
     *
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   462
     * @param path the search path string
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   463
     * @return the resulting array of directory and JAR file URLs
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   464
     */
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   465
    public static URL[] pathToURLs(String path) {
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   466
        StringTokenizer st = new StringTokenizer(path, File.pathSeparator);
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   467
        URL[] urls = new URL[st.countTokens()];
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   468
        int count = 0;
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   469
        while (st.hasMoreTokens()) {
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   470
            URL url = fileToURL(new File(st.nextToken()));
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   471
            if (url != null) {
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   472
                urls[count++] = url;
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   473
            }
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   474
        }
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   475
        if (urls.length != count) {
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   476
            URL[] tmp = new URL[count];
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   477
            System.arraycopy(urls, 0, tmp, 0, count);
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   478
            urls = tmp;
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   479
        }
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   480
        return urls;
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   481
    }
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   482
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   483
    /**
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   484
     * Returns the directory or JAR file URL corresponding to the specified
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   485
     * local file name.
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   486
     *
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   487
     * @param file the File object
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   488
     * @return the resulting directory or JAR file URL, or null if unknown
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   489
     */
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   490
    private static URL fileToURL(File file) {
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   491
        String name;
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   492
        try {
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   493
            name = file.getCanonicalPath();
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   494
        } catch (IOException e) {
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   495
            name = file.getAbsolutePath();
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   496
        }
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   497
        name = name.replace(File.separatorChar, '/');
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   498
        if (!name.startsWith("/")) {
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   499
            name = "/" + name;
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   500
        }
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   501
        // If the file does not exist, then assume that it's a directory
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   502
        if (!file.isFile()) {
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   503
            name = name + "/";
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   504
        }
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   505
        try {
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   506
            return new URL("file", "", name);
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   507
        } catch (MalformedURLException e) {
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   508
            throw new IllegalArgumentException(file.toString());
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   509
        }
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   510
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   511
}