langtools/src/share/classes/com/sun/tools/javac/file/Locations.java
author briangoetz
Wed, 18 Dec 2013 16:05:18 -0500
changeset 22163 3651128c74eb
parent 22153 f9f06fcca59d
child 24897 655b72d7b96e
permissions -rw-r--r--
8030244: Update langtools to use Diamond Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
22153
f9f06fcca59d 8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents: 14360
diff changeset
     2
 * Copyright (c) 2003, 2013, 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
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
    28
import java.io.FileNotFoundException;
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
    29
import java.util.Iterator;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
import java.io.File;
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
import java.io.IOException;
4937
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
    32
import java.net.MalformedURLException;
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
    33
import java.net.URL;
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
    34
import java.util.Arrays;
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
    35
import java.util.Collection;
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
    36
import java.util.Collections;
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
    37
import java.util.EnumMap;
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
    38
import java.util.EnumSet;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
import java.util.HashMap;
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
import java.util.HashSet;
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
    41
import java.util.LinkedHashSet;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
import java.util.Map;
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
import java.util.Set;
4937
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
    44
import java.util.StringTokenizer;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
import java.util.zip.ZipFile;
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
import javax.tools.JavaFileManager.Location;
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
    47
import javax.tools.StandardLocation;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
731
1dd22bdb9ca5 6714364: refactor javac File handling code into new javac.file package
jjg
parents: 171
diff changeset
    49
import com.sun.tools.javac.code.Lint;
11314
b612aaca08d0 7120736: refactor javac option handling
jjg
parents: 10819
diff changeset
    50
import com.sun.tools.javac.main.Option;
1486
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
    51
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
    52
import com.sun.tools.javac.util.Log;
1dd22bdb9ca5 6714364: refactor javac File handling code into new javac.file package
jjg
parents: 171
diff changeset
    53
import com.sun.tools.javac.util.Options;
22153
f9f06fcca59d 8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents: 14360
diff changeset
    54
import com.sun.tools.javac.util.StringUtils;
731
1dd22bdb9ca5 6714364: refactor javac File handling code into new javac.file package
jjg
parents: 171
diff changeset
    55
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
    56
import javax.tools.JavaFileManager;
14259
fb94a1df0d53 8000208: fix langtools javadoc comment issues
jjg
parents: 14049
diff changeset
    57
import javax.tools.StandardJavaFileManager;
731
1dd22bdb9ca5 6714364: refactor javac File handling code into new javac.file package
jjg
parents: 171
diff changeset
    58
import static javax.tools.StandardLocation.*;
11314
b612aaca08d0 7120736: refactor javac option handling
jjg
parents: 10819
diff changeset
    59
import static com.sun.tools.javac.main.Option.*;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
/** This class converts command line arguments, environment variables
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
 *  and system properties (in File.pathSeparator-separated String form)
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
 *  into a boot class path, user class path, and source path (in
14259
fb94a1df0d53 8000208: fix langtools javadoc comment issues
jjg
parents: 14049
diff changeset
    64
 *  {@code Collection<String>} form).
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
 *
5847
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    66
 *  <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
    67
 *  If you write code that depends on this, you do so at your own risk.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
 *  This code and its internal interfaces are subject to change or
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
 *  deletion without notice.</b>
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
 */
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
    71
public class Locations {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
    /** The log to use for warning output */
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
    private Log log;
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
    /** Collection of command-line options */
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
    private Options options;
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
    /** Handler for -Xlint options */
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
    private Lint lint;
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
1208
5072b0dd3d52 6743107: clean up use of static caches in file manager
jjg
parents: 735
diff changeset
    82
    /** Access to (possibly cached) file info */
5072b0dd3d52 6743107: clean up use of static caches in file manager
jjg
parents: 735
diff changeset
    83
    private FSInfo fsInfo;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
    85
    /** Whether to warn about non-existent path elements */
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
    86
    private boolean warn;
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
    87
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
    88
    // TODO: remove need for this
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
    89
    private boolean inited = false; // TODO? caching bad?
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
    90
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
    91
    public Locations() {
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
    92
        initHandlers();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
10813
95b39a692cd0 7101146: Paths should more directly managed by BaseFileManager
jjg
parents: 8424
diff changeset
    95
    public void update(Log log, Options options, Lint lint, FSInfo fsInfo) {
95b39a692cd0 7101146: Paths should more directly managed by BaseFileManager
jjg
parents: 8424
diff changeset
    96
        this.log = log;
95b39a692cd0 7101146: Paths should more directly managed by BaseFileManager
jjg
parents: 8424
diff changeset
    97
        this.options = options;
95b39a692cd0 7101146: Paths should more directly managed by BaseFileManager
jjg
parents: 8424
diff changeset
    98
        this.lint = lint;
95b39a692cd0 7101146: Paths should more directly managed by BaseFileManager
jjg
parents: 8424
diff changeset
    99
        this.fsInfo = fsInfo;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   102
    public Collection<File> bootClassPath() {
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   103
        return getLocation(PLATFORM_CLASS_PATH);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
7336
3fd30668e9b5 7003477: Paths.isDefaultBootClassPath needs to be public
jjg
parents: 7335
diff changeset
   106
    public boolean isDefaultBootClassPath() {
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   107
        BootClassPathLocationHandler h =
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   108
                (BootClassPathLocationHandler) getHandler(PLATFORM_CLASS_PATH);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   109
        return h.isDefault();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
8034
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents: 7847
diff changeset
   112
    boolean isDefaultBootClassPathRtJar(File file) {
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   113
        BootClassPathLocationHandler h =
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   114
                (BootClassPathLocationHandler) getHandler(PLATFORM_CLASS_PATH);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   115
        return h.isDefaultRtJar(file);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   116
    }
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   117
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   118
    public Collection<File> userClassPath() {
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   119
        return getLocation(CLASS_PATH);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   120
    }
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   121
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   122
    public Collection<File> sourcePath() {
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   123
        Collection<File> p = getLocation(SOURCE_PATH);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   124
        // TODO: this should be handled by the LocationHandler
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   125
        return p == null || p.isEmpty() ? null : p;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
1486
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   128
    /**
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   129
     * Split a path into its elements. Empty path elements will be ignored.
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   130
     * @param path The path to be split
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   131
     * @return The elements of the path
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   132
     */
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   133
    private static Iterable<File> getPathEntries(String path) {
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   134
        return getPathEntries(path, null);
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   135
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
1486
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   137
    /**
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   138
     * Split a path into its elements. If emptyPathDefault is not null, all
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   139
     * empty elements in the path, including empty elements at either end of
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   140
     * the path, will be replaced with the value of emptyPathDefault.
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   141
     * @param path The path to be split
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   142
     * @param emptyPathDefault The value to substitute for empty path elements,
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   143
     *  or null, to ignore empty path elements
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   144
     * @return The elements of the path
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   145
     */
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   146
    private static Iterable<File> getPathEntries(String path, File emptyPathDefault) {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22153
diff changeset
   147
        ListBuffer<File> entries = new ListBuffer<>();
1486
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   148
        int start = 0;
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   149
        while (start <= path.length()) {
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   150
            int sep = path.indexOf(File.pathSeparatorChar, start);
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   151
            if (sep == -1)
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   152
                sep = path.length();
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   153
            if (start < sep)
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   154
                entries.add(new File(path.substring(start, sep)));
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   155
            else if (emptyPathDefault != null)
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   156
                entries.add(emptyPathDefault);
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   157
            start = sep + 1;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
        }
1486
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   159
        return entries;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   162
    /**
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   163
     * Utility class to help evaluate a path option.
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   164
     * Duplicate entries are ignored, jar class paths can be expanded.
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   165
     */
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
    private class Path extends LinkedHashSet<File> {
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
        private static final long serialVersionUID = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
        private boolean expandJarClassPaths = false;
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22153
diff changeset
   170
        private Set<File> canonicalValues = new HashSet<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
        public Path expandJarClassPaths(boolean x) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
            expandJarClassPaths = x;
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
            return this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
        /** What to use when path element is the empty string */
1486
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   178
        private File emptyPathDefault = null;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
1486
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   180
        public Path emptyPathDefault(File x) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
            emptyPathDefault = x;
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
            return this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
        public Path() { super(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
        public Path addDirectories(String dirs, boolean warn) {
8424
5e31b2eb5aa3 6485027: javac incorrectly handles relative paths in manifest classpath
jjg
parents: 8034
diff changeset
   188
            boolean prev = expandJarClassPaths;
5e31b2eb5aa3 6485027: javac incorrectly handles relative paths in manifest classpath
jjg
parents: 8034
diff changeset
   189
            expandJarClassPaths = true;
5e31b2eb5aa3 6485027: javac incorrectly handles relative paths in manifest classpath
jjg
parents: 8034
diff changeset
   190
            try {
5e31b2eb5aa3 6485027: javac incorrectly handles relative paths in manifest classpath
jjg
parents: 8034
diff changeset
   191
                if (dirs != null)
5e31b2eb5aa3 6485027: javac incorrectly handles relative paths in manifest classpath
jjg
parents: 8034
diff changeset
   192
                    for (File dir : getPathEntries(dirs))
5e31b2eb5aa3 6485027: javac incorrectly handles relative paths in manifest classpath
jjg
parents: 8034
diff changeset
   193
                        addDirectory(dir, warn);
5e31b2eb5aa3 6485027: javac incorrectly handles relative paths in manifest classpath
jjg
parents: 8034
diff changeset
   194
                return this;
5e31b2eb5aa3 6485027: javac incorrectly handles relative paths in manifest classpath
jjg
parents: 8034
diff changeset
   195
            } finally {
5e31b2eb5aa3 6485027: javac incorrectly handles relative paths in manifest classpath
jjg
parents: 8034
diff changeset
   196
                expandJarClassPaths = prev;
5e31b2eb5aa3 6485027: javac incorrectly handles relative paths in manifest classpath
jjg
parents: 8034
diff changeset
   197
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
        public Path addDirectories(String dirs) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
            return addDirectories(dirs, warn);
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
1486
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   204
        private void addDirectory(File dir, boolean warn) {
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   205
            if (!dir.isDirectory()) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
                if (warn)
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   207
                    log.warning(Lint.LintCategory.PATH,
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   208
                            "dir.path.element.not.found", dir);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
                return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
1486
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   212
            File[] files = dir.listFiles();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
            if (files == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
                return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
            for (File direntry : files) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
                if (isArchive(direntry))
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
                    addFile(direntry, warn);
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   221
06bc494ca11e Initial load
duke
parents:
diff changeset
   222
        public Path addFiles(String files, boolean warn) {
7335
8b390fd27190 6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents: 6151
diff changeset
   223
            if (files != null) {
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   224
                addFiles(getPathEntries(files, emptyPathDefault), warn);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   225
            }
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   226
            return this;
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   227
        }
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   228
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   229
        public Path addFiles(String files) {
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   230
            return addFiles(files, warn);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   231
        }
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   232
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   233
        public Path addFiles(Iterable<? extends File> files, boolean warn) {
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   234
            if (files != null) {
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   235
                for (File file: files)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
                    addFile(file, warn);
7335
8b390fd27190 6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents: 6151
diff changeset
   237
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
            return this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   241
        public Path addFiles(Iterable<? extends File> files) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
            return addFiles(files, warn);
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
        public void addFile(File file, boolean warn) {
7839
a1ca72d05b20 6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents: 7336
diff changeset
   246
            if (contains(file)) {
a1ca72d05b20 6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents: 7336
diff changeset
   247
                // discard duplicates
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   248
                return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   249
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
1208
5072b0dd3d52 6743107: clean up use of static caches in file manager
jjg
parents: 735
diff changeset
   251
            if (! fsInfo.exists(file)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   252
                /* No such file or directory exists */
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   253
                if (warn) {
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   254
                    log.warning(Lint.LintCategory.PATH,
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   255
                            "path.element.not.found", file);
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   256
                }
7839
a1ca72d05b20 6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents: 7336
diff changeset
   257
                super.add(file);
a1ca72d05b20 6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents: 7336
diff changeset
   258
                return;
a1ca72d05b20 6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents: 7336
diff changeset
   259
            }
a1ca72d05b20 6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents: 7336
diff changeset
   260
a1ca72d05b20 6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents: 7336
diff changeset
   261
            File canonFile = fsInfo.getCanonicalFile(file);
a1ca72d05b20 6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents: 7336
diff changeset
   262
            if (canonicalValues.contains(canonFile)) {
a1ca72d05b20 6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents: 7336
diff changeset
   263
                /* Discard duplicates and avoid infinite recursion */
a1ca72d05b20 6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents: 7336
diff changeset
   264
                return;
a1ca72d05b20 6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents: 7336
diff changeset
   265
            }
a1ca72d05b20 6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents: 7336
diff changeset
   266
a1ca72d05b20 6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents: 7336
diff changeset
   267
            if (fsInfo.isFile(file)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   268
                /* File is an ordinary file. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   269
                if (!isArchive(file)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   270
                    /* Not a recognized extension; open it to see if
06bc494ca11e Initial load
duke
parents:
diff changeset
   271
                     it looks like a valid zip file. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   272
                    try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   273
                        ZipFile z = new ZipFile(file);
06bc494ca11e Initial load
duke
parents:
diff changeset
   274
                        z.close();
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   275
                        if (warn) {
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   276
                            log.warning(Lint.LintCategory.PATH,
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   277
                                    "unexpected.archive.file", file);
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   278
                        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
                    } catch (IOException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   280
                        // FIXME: include e.getLocalizedMessage in warning
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   281
                        if (warn) {
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   282
                            log.warning(Lint.LintCategory.PATH,
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   283
                                    "invalid.archive.file", file);
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   284
                        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   285
                        return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   286
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   287
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   288
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   289
06bc494ca11e Initial load
duke
parents:
diff changeset
   290
            /* Now what we have left is either a directory or a file name
7839
a1ca72d05b20 6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents: 7336
diff changeset
   291
               conforming to archive naming convention */
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   292
            super.add(file);
1208
5072b0dd3d52 6743107: clean up use of static caches in file manager
jjg
parents: 735
diff changeset
   293
            canonicalValues.add(canonFile);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   294
7839
a1ca72d05b20 6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents: 7336
diff changeset
   295
            if (expandJarClassPaths && fsInfo.isFile(file))
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   296
                addJarClassPath(file, warn);
06bc494ca11e Initial load
duke
parents:
diff changeset
   297
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   298
06bc494ca11e Initial load
duke
parents:
diff changeset
   299
        // Adds referenced classpath elements from a jar's Class-Path
06bc494ca11e Initial load
duke
parents:
diff changeset
   300
        // Manifest entry.  In some future release, we may want to
06bc494ca11e Initial load
duke
parents:
diff changeset
   301
        // update this code to recognize URLs rather than simple
06bc494ca11e Initial load
duke
parents:
diff changeset
   302
        // filenames, but if we do, we should redo all path-related code.
06bc494ca11e Initial load
duke
parents:
diff changeset
   303
        private void addJarClassPath(File jarFile, boolean warn) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   304
            try {
1208
5072b0dd3d52 6743107: clean up use of static caches in file manager
jjg
parents: 735
diff changeset
   305
                for (File f: fsInfo.getJarClassPath(jarFile)) {
5072b0dd3d52 6743107: clean up use of static caches in file manager
jjg
parents: 735
diff changeset
   306
                    addFile(f, warn);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   307
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   308
            } catch (IOException e) {
5007
28dee2489196 6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents: 4937
diff changeset
   309
                log.error("error.reading.file", jarFile, JavacFileManager.getMessage(e));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   310
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   311
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   312
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   313
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   314
    /**
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   315
     * Base class for handling support for the representation of Locations.
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   316
     * Implementations are responsible for handling the interactions between
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   317
     * the command line options for a location, and API access via setLocation.
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   318
     * @see #initHandlers
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   319
     * @see #getHandler
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   320
     */
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   321
    protected abstract class LocationHandler {
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   322
        final Location location;
11314
b612aaca08d0 7120736: refactor javac option handling
jjg
parents: 10819
diff changeset
   323
        final Set<Option> options;
7335
8b390fd27190 6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents: 6151
diff changeset
   324
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   325
        /**
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   326
         * Create a handler. The location and options provide a way to map
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   327
         * from a location or an option to the corresponding handler.
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   328
         * @see #initHandlers
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   329
         */
11314
b612aaca08d0 7120736: refactor javac option handling
jjg
parents: 10819
diff changeset
   330
        protected LocationHandler(Location location, Option... options) {
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   331
            this.location = location;
10819
e1a8df45d8b0 7104905: Java SE build fails on call to CreateSymbols
jjh
parents: 10818
diff changeset
   332
            this.options = options.length == 0 ?
11314
b612aaca08d0 7120736: refactor javac option handling
jjg
parents: 10819
diff changeset
   333
                EnumSet.noneOf(Option.class):
10819
e1a8df45d8b0 7104905: Java SE build fails on call to CreateSymbols
jjh
parents: 10818
diff changeset
   334
                EnumSet.copyOf(Arrays.asList(options));
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   335
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   336
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   337
        // TODO: TEMPORARY, while Options still used for command line options
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   338
        void update(Options optionTable) {
11314
b612aaca08d0 7120736: refactor javac option handling
jjg
parents: 10819
diff changeset
   339
            for (Option o: options) {
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   340
                String v = optionTable.get(o);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   341
                if (v != null) {
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   342
                    handleOption(o, v);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   343
                }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   344
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   345
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   346
14259
fb94a1df0d53 8000208: fix langtools javadoc comment issues
jjg
parents: 14049
diff changeset
   347
        /** @see JavaFileManager#handleOption */
11314
b612aaca08d0 7120736: refactor javac option handling
jjg
parents: 10819
diff changeset
   348
        abstract boolean handleOption(Option option, String value);
14259
fb94a1df0d53 8000208: fix langtools javadoc comment issues
jjg
parents: 14049
diff changeset
   349
        /** @see StandardJavaFileManager#getLocation */
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   350
        abstract Collection<File> getLocation();
14259
fb94a1df0d53 8000208: fix langtools javadoc comment issues
jjg
parents: 14049
diff changeset
   351
        /** @see StandardJavaFileManager#setLocation */
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   352
        abstract void setLocation(Iterable<? extends File> files) throws IOException;
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   353
    }
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   354
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   355
    /**
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   356
     * General purpose implementation for output locations,
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   357
     * such as -d/CLASS_OUTPUT and -s/SOURCE_OUTPUT.
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   358
     * All options are treated as equivalent (i.e. aliases.)
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   359
     * The value is a single file, possibly null.
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   360
     */
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   361
    private class OutputLocationHandler extends LocationHandler {
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   362
        private File outputDir;
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   363
11314
b612aaca08d0 7120736: refactor javac option handling
jjg
parents: 10819
diff changeset
   364
        OutputLocationHandler(Location location, Option... options) {
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   365
            super(location, options);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   366
        }
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   367
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   368
        @Override
11314
b612aaca08d0 7120736: refactor javac option handling
jjg
parents: 10819
diff changeset
   369
        boolean handleOption(Option option, String value) {
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   370
            if (!options.contains(option))
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   371
                return false;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   372
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   373
            // TODO: could/should validate outputDir exists and is a directory
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   374
            // need to decide how best to report issue for benefit of
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   375
            // direct API call on JavaFileManager.handleOption(specifies IAE)
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   376
            // vs. command line decoding.
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   377
            outputDir = new File(value);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   378
            return true;
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   379
        }
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   380
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   381
        @Override
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   382
        Collection<File> getLocation() {
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   383
            return (outputDir == null) ? null : Collections.singleton(outputDir);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   384
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   385
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   386
        @Override
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   387
        void setLocation(Iterable<? extends File> files) throws IOException {
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   388
            if (files == null) {
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   389
                outputDir = null;
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   390
            } else {
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   391
                Iterator<? extends File> pathIter = files.iterator();
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   392
                if (!pathIter.hasNext())
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   393
                    throw new IllegalArgumentException("empty path for directory");
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   394
                File dir = pathIter.next();
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   395
                if (pathIter.hasNext())
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   396
                    throw new IllegalArgumentException("path too long for directory");
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   397
                if (!dir.exists())
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   398
                    throw new FileNotFoundException(dir + ": does not exist");
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   399
                else if (!dir.isDirectory())
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   400
                    throw new IOException(dir + ": not a directory");
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   401
                outputDir = dir;
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   402
            }
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   403
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   404
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   405
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   406
    /**
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   407
     * General purpose implementation for search path locations,
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   408
     * such as -sourcepath/SOURCE_PATH and -processorPath/ANNOTATION_PROCESS_PATH.
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   409
     * All options are treated as equivalent (i.e. aliases.)
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   410
     * The value is an ordered set of files and/or directories.
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   411
     */
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   412
    private class SimpleLocationHandler extends LocationHandler {
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   413
        protected Collection<File> searchPath;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   414
11314
b612aaca08d0 7120736: refactor javac option handling
jjg
parents: 10819
diff changeset
   415
        SimpleLocationHandler(Location location, Option... options) {
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   416
            super(location, options);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   417
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   418
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   419
        @Override
11314
b612aaca08d0 7120736: refactor javac option handling
jjg
parents: 10819
diff changeset
   420
        boolean handleOption(Option option, String value) {
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   421
            if (!options.contains(option))
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   422
                return false;
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   423
            searchPath = value == null ? null :
14360
2a8304e421ed 6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents: 14259
diff changeset
   424
                    Collections.unmodifiableCollection(createPath().addFiles(value));
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   425
            return true;
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   426
        }
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   427
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   428
        @Override
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   429
        Collection<File> getLocation() {
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   430
            return searchPath;
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   431
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   432
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   433
        @Override
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   434
        void setLocation(Iterable<? extends File> files) {
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   435
            Path p;
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   436
            if (files == null) {
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   437
                p = computePath(null);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   438
            } else {
14360
2a8304e421ed 6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents: 14259
diff changeset
   439
                p = createPath().addFiles(files);
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   440
            }
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   441
            searchPath = Collections.unmodifiableCollection(p);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   442
        }
14360
2a8304e421ed 6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents: 14259
diff changeset
   443
2a8304e421ed 6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents: 14259
diff changeset
   444
        protected Path computePath(String value) {
2a8304e421ed 6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents: 14259
diff changeset
   445
            return createPath().addFiles(value);
2a8304e421ed 6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents: 14259
diff changeset
   446
        }
2a8304e421ed 6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents: 14259
diff changeset
   447
2a8304e421ed 6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents: 14259
diff changeset
   448
        protected Path createPath() {
2a8304e421ed 6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents: 14259
diff changeset
   449
            return new Path();
2a8304e421ed 6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents: 14259
diff changeset
   450
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   451
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   452
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   453
    /**
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   454
     * Subtype of SimpleLocationHandler for -classpath/CLASS_PATH.
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   455
     * If no value is given, a default is provided, based on system properties
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   456
     * and other values.
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   457
     */
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   458
    private class ClassPathLocationHandler extends SimpleLocationHandler {
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   459
        ClassPathLocationHandler() {
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   460
            super(StandardLocation.CLASS_PATH,
11314
b612aaca08d0 7120736: refactor javac option handling
jjg
parents: 10819
diff changeset
   461
                    Option.CLASSPATH, Option.CP);
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   462
        }
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   463
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   464
        @Override
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   465
        Collection<File> getLocation() {
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   466
            lazy();
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   467
            return searchPath;
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   468
        }
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   469
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   470
        @Override
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   471
        protected Path computePath(String value) {
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   472
            String cp = value;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   473
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   474
            // CLASSPATH environment variable when run from `javac'.
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   475
            if (cp == null) cp = System.getProperty("env.class.path");
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   476
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   477
            // If invoked via a java VM (not the javac launcher), use the
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   478
            // platform class path
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   479
            if (cp == null && System.getProperty("application.home") == null)
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   480
                cp = System.getProperty("java.class.path");
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   481
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   482
            // Default to current working directory.
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   483
            if (cp == null) cp = ".";
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   484
14360
2a8304e421ed 6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents: 14259
diff changeset
   485
            return createPath().addFiles(cp);
2a8304e421ed 6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents: 14259
diff changeset
   486
        }
2a8304e421ed 6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents: 14259
diff changeset
   487
2a8304e421ed 6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents: 14259
diff changeset
   488
        @Override
2a8304e421ed 6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents: 14259
diff changeset
   489
        protected Path createPath() {
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   490
            return new Path()
14360
2a8304e421ed 6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents: 14259
diff changeset
   491
                .expandJarClassPaths(true)         // Only search user jars for Class-Paths
2a8304e421ed 6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents: 14259
diff changeset
   492
                .emptyPathDefault(new File("."));  // Empty path elt ==> current directory
2a8304e421ed 6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents: 14259
diff changeset
   493
        }
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   494
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   495
        private void lazy() {
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   496
            if (searchPath == null)
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   497
                setLocation(null);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   498
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   499
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   500
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   501
    /**
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   502
     * Custom subtype of LocationHandler for PLATFORM_CLASS_PATH.
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   503
     * Various options are supported for different components of the
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   504
     * platform class path.
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   505
     * Setting a value with setLocation overrides all existing option values.
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   506
     * Setting any option overrides any value set with setLocation, and reverts
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   507
     * to using default values for options that have not been set.
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   508
     * Setting -bootclasspath or -Xbootclasspath overrides any existing
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   509
     * value for -Xbootclasspath/p: and -Xbootclasspath/a:.
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   510
     */
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   511
    private class BootClassPathLocationHandler extends LocationHandler {
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   512
        private Collection<File> searchPath;
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22153
diff changeset
   513
        final Map<Option, String> optionValues = new EnumMap<>(Option.class);
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   514
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   515
        /**
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   516
         * rt.jar as found on the default bootclasspath.
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   517
         * If the user specified a bootclasspath, null is used.
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   518
         */
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   519
        private File defaultBootClassPathRtJar = null;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   520
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   521
        /**
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   522
         *  Is bootclasspath the default?
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   523
         */
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   524
        private boolean isDefaultBootClassPath;
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   525
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   526
        BootClassPathLocationHandler() {
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   527
            super(StandardLocation.PLATFORM_CLASS_PATH,
11314
b612aaca08d0 7120736: refactor javac option handling
jjg
parents: 10819
diff changeset
   528
                    Option.BOOTCLASSPATH, Option.XBOOTCLASSPATH,
b612aaca08d0 7120736: refactor javac option handling
jjg
parents: 10819
diff changeset
   529
                    Option.XBOOTCLASSPATH_PREPEND,
b612aaca08d0 7120736: refactor javac option handling
jjg
parents: 10819
diff changeset
   530
                    Option.XBOOTCLASSPATH_APPEND,
b612aaca08d0 7120736: refactor javac option handling
jjg
parents: 10819
diff changeset
   531
                    Option.ENDORSEDDIRS, Option.DJAVA_ENDORSED_DIRS,
b612aaca08d0 7120736: refactor javac option handling
jjg
parents: 10819
diff changeset
   532
                    Option.EXTDIRS, Option.DJAVA_EXT_DIRS);
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   533
        }
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   534
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   535
        boolean isDefault() {
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   536
            lazy();
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   537
            return isDefaultBootClassPath;
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   538
        }
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   539
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   540
        boolean isDefaultRtJar(File file) {
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   541
            lazy();
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   542
            return file.equals(defaultBootClassPathRtJar);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   543
        }
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   544
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   545
        @Override
11314
b612aaca08d0 7120736: refactor javac option handling
jjg
parents: 10819
diff changeset
   546
        boolean handleOption(Option option, String value) {
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   547
            if (!options.contains(option))
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   548
                return false;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   549
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   550
            option = canonicalize(option);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   551
            optionValues.put(option, value);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   552
            if (option == BOOTCLASSPATH) {
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   553
                optionValues.remove(XBOOTCLASSPATH_PREPEND);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   554
                optionValues.remove(XBOOTCLASSPATH_APPEND);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   555
            }
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   556
            searchPath = null;  // reset to "uninitialized"
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   557
            return true;
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   558
        }
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   559
        // where
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   560
            // TODO: would be better if option aliasing was handled at a higher
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   561
            // level
11314
b612aaca08d0 7120736: refactor javac option handling
jjg
parents: 10819
diff changeset
   562
            private Option canonicalize(Option option) {
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   563
                switch (option) {
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   564
                    case XBOOTCLASSPATH:
11314
b612aaca08d0 7120736: refactor javac option handling
jjg
parents: 10819
diff changeset
   565
                        return Option.BOOTCLASSPATH;
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   566
                    case DJAVA_ENDORSED_DIRS:
11314
b612aaca08d0 7120736: refactor javac option handling
jjg
parents: 10819
diff changeset
   567
                        return Option.ENDORSEDDIRS;
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   568
                    case DJAVA_EXT_DIRS:
11314
b612aaca08d0 7120736: refactor javac option handling
jjg
parents: 10819
diff changeset
   569
                        return Option.EXTDIRS;
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   570
                    default:
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   571
                        return option;
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   572
                }
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   573
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   574
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   575
        @Override
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   576
        Collection<File> getLocation() {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   577
            lazy();
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   578
            return searchPath;
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   579
        }
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   580
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   581
        @Override
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   582
        void setLocation(Iterable<? extends File> files) {
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   583
            if (files == null) {
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   584
                searchPath = null;  // reset to "uninitialized"
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   585
            } else {
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   586
                defaultBootClassPathRtJar = null;
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   587
                isDefaultBootClassPath = false;
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   588
                Path p = new Path().addFiles(files, false);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   589
                searchPath = Collections.unmodifiableCollection(p);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   590
                optionValues.clear();
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   591
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   592
        }
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   593
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   594
        Path computePath() {
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   595
            defaultBootClassPathRtJar = null;
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   596
            Path path = new Path();
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   597
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   598
            String bootclasspathOpt = optionValues.get(BOOTCLASSPATH);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   599
            String endorseddirsOpt = optionValues.get(ENDORSEDDIRS);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   600
            String extdirsOpt = optionValues.get(EXTDIRS);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   601
            String xbootclasspathPrependOpt = optionValues.get(XBOOTCLASSPATH_PREPEND);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   602
            String xbootclasspathAppendOpt = optionValues.get(XBOOTCLASSPATH_APPEND);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   603
            path.addFiles(xbootclasspathPrependOpt);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   604
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   605
            if (endorseddirsOpt != null)
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   606
                path.addDirectories(endorseddirsOpt);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   607
            else
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   608
                path.addDirectories(System.getProperty("java.endorsed.dirs"), false);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   609
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   610
            if (bootclasspathOpt != null) {
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   611
                path.addFiles(bootclasspathOpt);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   612
            } else {
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   613
                // Standard system classes for this compiler's release.
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   614
                String files = System.getProperty("sun.boot.class.path");
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   615
                path.addFiles(files, false);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   616
                File rt_jar = new File("rt.jar");
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   617
                for (File file : getPathEntries(files)) {
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   618
                    if (new File(file.getName()).equals(rt_jar))
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   619
                        defaultBootClassPathRtJar = file;
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   620
                }
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   621
            }
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   622
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   623
            path.addFiles(xbootclasspathAppendOpt);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   624
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   625
            // Strictly speaking, standard extensions are not bootstrap
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   626
            // classes, but we treat them identically, so we'll pretend
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   627
            // that they are.
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   628
            if (extdirsOpt != null)
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   629
                path.addDirectories(extdirsOpt);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   630
            else
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   631
                path.addDirectories(System.getProperty("java.ext.dirs"), false);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   632
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   633
            isDefaultBootClassPath =
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   634
                    (xbootclasspathPrependOpt == null) &&
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   635
                    (bootclasspathOpt == null) &&
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   636
                    (xbootclasspathAppendOpt == null);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   637
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   638
            return path;
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   639
        }
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   640
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   641
        private void lazy() {
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   642
            if (searchPath == null)
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   643
                searchPath = Collections.unmodifiableCollection(computePath());
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   644
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   645
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   646
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   647
    Map<Location, LocationHandler> handlersForLocation;
11314
b612aaca08d0 7120736: refactor javac option handling
jjg
parents: 10819
diff changeset
   648
    Map<Option, LocationHandler> handlersForOption;
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   649
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   650
    void initHandlers() {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22153
diff changeset
   651
        handlersForLocation = new HashMap<>();
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22153
diff changeset
   652
        handlersForOption = new EnumMap<>(Option.class);
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   653
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   654
        LocationHandler[] handlers = {
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   655
            new BootClassPathLocationHandler(),
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   656
            new ClassPathLocationHandler(),
11314
b612aaca08d0 7120736: refactor javac option handling
jjg
parents: 10819
diff changeset
   657
            new SimpleLocationHandler(StandardLocation.SOURCE_PATH, Option.SOURCEPATH),
b612aaca08d0 7120736: refactor javac option handling
jjg
parents: 10819
diff changeset
   658
            new SimpleLocationHandler(StandardLocation.ANNOTATION_PROCESSOR_PATH, Option.PROCESSORPATH),
b612aaca08d0 7120736: refactor javac option handling
jjg
parents: 10819
diff changeset
   659
            new OutputLocationHandler((StandardLocation.CLASS_OUTPUT), Option.D),
12213
516b112d6c68 7150368: javac should include basic ability to generate native headers
jjg
parents: 11314
diff changeset
   660
            new OutputLocationHandler((StandardLocation.SOURCE_OUTPUT), Option.S),
516b112d6c68 7150368: javac should include basic ability to generate native headers
jjg
parents: 11314
diff changeset
   661
            new OutputLocationHandler((StandardLocation.NATIVE_HEADER_OUTPUT), Option.H)
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   662
        };
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   663
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   664
        for (LocationHandler h: handlers) {
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   665
            handlersForLocation.put(h.location, h);
11314
b612aaca08d0 7120736: refactor javac option handling
jjg
parents: 10819
diff changeset
   666
            for (Option o: h.options)
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   667
                handlersForOption.put(o, h);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   668
        }
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   669
    }
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   670
11314
b612aaca08d0 7120736: refactor javac option handling
jjg
parents: 10819
diff changeset
   671
    boolean handleOption(Option option, String value) {
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   672
        LocationHandler h = handlersForOption.get(option);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   673
        return (h == null ? false : h.handleOption(option, value));
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   674
    }
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   675
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   676
    Collection<File> getLocation(Location location) {
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   677
        LocationHandler h = getHandler(location);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   678
        return (h == null ? null : h.getLocation());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   679
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   680
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   681
    File getOutputLocation(Location location) {
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   682
        if (!location.isOutputLocation())
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   683
            throw new IllegalArgumentException();
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   684
        LocationHandler h = getHandler(location);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   685
        return ((OutputLocationHandler) h).outputDir;
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   686
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   687
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   688
    void setLocation(Location location, Iterable<? extends File> files) throws IOException {
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   689
        LocationHandler h = getHandler(location);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   690
        if (h == null) {
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   691
            if (location.isOutputLocation())
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   692
                h = new OutputLocationHandler(location);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   693
            else
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   694
                h = new SimpleLocationHandler(location);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   695
            handlersForLocation.put(location, h);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   696
        }
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   697
        h.setLocation(files);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   698
    }
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   699
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   700
    protected LocationHandler getHandler(Location location) {
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   701
        location.getClass(); // null check
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   702
        lazy();
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   703
        return handlersForLocation.get(location);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   704
    }
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   705
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   706
// TOGO
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   707
    protected void lazy() {
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   708
        if (!inited) {
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   709
            warn = lint.isEnabled(Lint.LintCategory.PATH);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   710
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   711
            for (LocationHandler h: handlersForLocation.values()) {
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   712
                h.update(options);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   713
            }
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   714
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   715
            inited = true;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   716
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   717
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   718
06bc494ca11e Initial load
duke
parents:
diff changeset
   719
    /** 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
   720
    private boolean isArchive(File file) {
22153
f9f06fcca59d 8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents: 14360
diff changeset
   721
        String n = StringUtils.toLowerCase(file.getName());
1208
5072b0dd3d52 6743107: clean up use of static caches in file manager
jjg
parents: 735
diff changeset
   722
        return fsInfo.isFile(file)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   723
            && (n.endsWith(".jar") || n.endsWith(".zip"));
06bc494ca11e Initial load
duke
parents:
diff changeset
   724
    }
4937
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   725
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   726
    /**
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   727
     * 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
   728
     * of directory and JAR file URLs.
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   729
     *
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   730
     * 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
   731
     *
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   732
     * @param path the search path string
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   733
     * @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
   734
     */
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   735
    public static URL[] pathToURLs(String path) {
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   736
        StringTokenizer st = new StringTokenizer(path, File.pathSeparator);
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   737
        URL[] urls = new URL[st.countTokens()];
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   738
        int count = 0;
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   739
        while (st.hasMoreTokens()) {
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   740
            URL url = fileToURL(new File(st.nextToken()));
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   741
            if (url != null) {
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   742
                urls[count++] = url;
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   743
            }
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   744
        }
14049
3207422a0f9b 7193657: provide internal ArrayUtils class to simplify common usage of arrays in javac
jjg
parents: 12213
diff changeset
   745
        urls = Arrays.copyOf(urls, count);
4937
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   746
        return urls;
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   747
    }
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   748
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   749
    /**
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   750
     * 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
   751
     * local file name.
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   752
     *
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   753
     * @param file the File object
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   754
     * @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
   755
     */
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   756
    private static URL fileToURL(File file) {
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   757
        String name;
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   758
        try {
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   759
            name = file.getCanonicalPath();
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   760
        } catch (IOException e) {
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   761
            name = file.getAbsolutePath();
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   762
        }
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   763
        name = name.replace(File.separatorChar, '/');
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   764
        if (!name.startsWith("/")) {
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   765
            name = "/" + name;
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   766
        }
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   767
        // 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
   768
        if (!file.isFile()) {
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   769
            name = name + "/";
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   770
        }
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   771
        try {
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   772
            return new URL("file", "", name);
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   773
        } catch (MalformedURLException e) {
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   774
            throw new IllegalArgumentException(file.toString());
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   775
        }
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
   776
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   777
}