langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/file/Locations.java
author sadayapalam
Mon, 23 May 2016 10:08:48 +0530
changeset 38536 42569f7fe4e6
parent 38519 d70d50ec27bb
child 40302 8c0d8d2c3519
permissions -rw-r--r--
8154824: Compiler should handle java.nio.file.FileSystemNotFoundException gracefully and not abort Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
     2
 * Copyright (c) 2003, 2016, 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
 */
34752
9c262a013456 8145342: Some copyright notices are inconsistently and ill formatted
vasya
parents: 29780
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
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
    28
import java.io.Closeable;
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
    29
import java.io.File;
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
    30
import java.io.FileNotFoundException;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
import java.io.IOException;
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
    32
import java.io.UncheckedIOException;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
    33
import java.net.URI;
4937
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
    34
import java.net.URL;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
    35
import java.net.URLClassLoader;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
    36
import java.nio.file.DirectoryIteratorException;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
    37
import java.nio.file.DirectoryStream;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
    38
import java.nio.file.FileSystem;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
    39
import java.nio.file.FileSystemNotFoundException;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
    40
import java.nio.file.FileSystems;
27852
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
    41
import java.nio.file.Files;
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
    42
import java.nio.file.Path;
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
    43
import java.nio.file.Paths;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
    44
import java.nio.file.ProviderNotFoundException;
27852
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
    45
import java.util.ArrayList;
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
    46
import java.util.Arrays;
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
    47
import java.util.Collection;
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
    48
import java.util.Collections;
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
    49
import java.util.EnumMap;
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
    50
import java.util.EnumSet;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
import java.util.HashMap;
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
import java.util.HashSet;
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
    53
import java.util.Iterator;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
    54
import java.util.LinkedHashMap;
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
    55
import java.util.LinkedHashSet;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
    56
import java.util.List;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
import java.util.Map;
29291
076c277565f7 8073550: java* tools: replace obj.getClass hacks with Assert.checkNonNull or Objects.requireNonNull
mcimadamore
parents: 29053
diff changeset
    58
import java.util.Objects;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
    59
import java.util.NoSuchElementException;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
import java.util.Set;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
    61
import java.util.regex.Matcher;
27852
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
    62
import java.util.regex.Pattern;
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
    63
import java.util.stream.Collectors;
27852
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
    64
import java.util.stream.Stream;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
import java.util.zip.ZipFile;
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
    66
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
    67
import javax.lang.model.SourceVersion;
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
    68
import javax.tools.JavaFileManager;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
import javax.tools.JavaFileManager.Location;
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
    70
import javax.tools.StandardJavaFileManager;
37944
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 37848
diff changeset
    71
import javax.tools.StandardJavaFileManager.PathFactory;
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
    72
import javax.tools.StandardLocation;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
731
1dd22bdb9ca5 6714364: refactor javac File handling code into new javac.file package
jjg
parents: 171
diff changeset
    74
import com.sun.tools.javac.code.Lint;
11314
b612aaca08d0 7120736: refactor javac option handling
jjg
parents: 10819
diff changeset
    75
import com.sun.tools.javac.main.Option;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
    76
import com.sun.tools.javac.resources.CompilerProperties.Errors;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
    77
import com.sun.tools.javac.resources.CompilerProperties.Warnings;
37848
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36526
diff changeset
    78
import com.sun.tools.javac.util.DefinedBy;
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36526
diff changeset
    79
import com.sun.tools.javac.util.DefinedBy.Api;
1486
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
    80
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
    81
import com.sun.tools.javac.util.Log;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
    82
import com.sun.tools.javac.util.Pair;
22153
f9f06fcca59d 8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents: 14360
diff changeset
    83
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
    84
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
    85
import static javax.tools.StandardLocation.PLATFORM_CLASS_PATH;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
    87
import static com.sun.tools.javac.main.Option.BOOTCLASSPATH;
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
    88
import static com.sun.tools.javac.main.Option.DJAVA_ENDORSED_DIRS;
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
    89
import static com.sun.tools.javac.main.Option.DJAVA_EXT_DIRS;
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
    90
import static com.sun.tools.javac.main.Option.ENDORSEDDIRS;
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
    91
import static com.sun.tools.javac.main.Option.EXTDIRS;
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
    92
import static com.sun.tools.javac.main.Option.XBOOTCLASSPATH;
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
    93
import static com.sun.tools.javac.main.Option.XBOOTCLASSPATH_APPEND;
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
    94
import static com.sun.tools.javac.main.Option.XBOOTCLASSPATH_PREPEND;
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
    95
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
    96
/**
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
    97
 * This class converts command line arguments, environment variables and system properties (in
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
    98
 * File.pathSeparator-separated String form) into a boot class path, user class path, and source
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
    99
 * path (in {@code Collection<String>} form).
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
 *
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   101
 * <p>
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   102
 * <b>This is NOT part of any supported API. If you write code that depends on this, you do so at
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   103
 * your own risk. This code and its internal interfaces are subject to change or deletion without
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   104
 * notice.</b>
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
 */
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   106
public class Locations {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   108
    /**
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   109
     * The log to use for warning output
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   110
     */
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
    private Log log;
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   113
    /**
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   114
     * Access to (possibly cached) file info
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   115
     */
1208
5072b0dd3d52 6743107: clean up use of static caches in file manager
jjg
parents: 735
diff changeset
   116
    private FSInfo fsInfo;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   118
    /**
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   119
     * Whether to warn about non-existent path elements
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   120
     */
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   121
    private boolean warn;
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   122
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   123
    private ModuleNameReader moduleNameReader;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   124
37944
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 37848
diff changeset
   125
    private PathFactory pathFactory = Paths::get;
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 37848
diff changeset
   126
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 37848
diff changeset
   127
    static final Path javaHome = FileSystems.getDefault().getPath(System.getProperty("java.home"));
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   128
    static final Path thisSystemModules = javaHome.resolve("lib").resolve("modules");
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   129
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   130
    Map<Path, FileSystem> fileSystems = new LinkedHashMap<>();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   131
    List<Closeable> closeables = new ArrayList<>();
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   132
29780
8f8e54a1fa20 8076420: Consolidate javac file handling in javac.file package
jjg
parents: 29291
diff changeset
   133
    Locations() {
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   134
        initHandlers();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
37944
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 37848
diff changeset
   137
    Path getPath(String first, String... more) {
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 37848
diff changeset
   138
        return pathFactory.getPath(first, more);
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 37848
diff changeset
   139
    }
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 37848
diff changeset
   140
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   141
    public void close() throws IOException {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   142
        ListBuffer<IOException> list = new ListBuffer<>();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   143
        closeables.forEach(closeable -> {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   144
            try {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   145
                closeable.close();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   146
            } catch (IOException ex) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   147
                list.add(ex);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   148
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   149
        });
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   150
        if (list.nonEmpty()) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   151
            IOException ex = new IOException();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   152
            for (IOException e: list)
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   153
                ex.addSuppressed(e);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   154
            throw ex;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   155
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   156
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   157
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   158
    // could replace Lint by "boolean warn"
29780
8f8e54a1fa20 8076420: Consolidate javac file handling in javac.file package
jjg
parents: 29291
diff changeset
   159
    void update(Log log, Lint lint, FSInfo fsInfo) {
10813
95b39a692cd0 7101146: Paths should more directly managed by BaseFileManager
jjg
parents: 8424
diff changeset
   160
        this.log = log;
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   161
        warn = lint.isEnabled(Lint.LintCategory.PATH);
10813
95b39a692cd0 7101146: Paths should more directly managed by BaseFileManager
jjg
parents: 8424
diff changeset
   162
        this.fsInfo = fsInfo;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
37944
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 37848
diff changeset
   165
    void setPathFactory(PathFactory f) {
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 37848
diff changeset
   166
        pathFactory = f;
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 37848
diff changeset
   167
    }
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 37848
diff changeset
   168
29780
8f8e54a1fa20 8076420: Consolidate javac file handling in javac.file package
jjg
parents: 29291
diff changeset
   169
    boolean isDefaultBootClassPath() {
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   170
        BootClassPathLocationHandler h
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   171
                = (BootClassPathLocationHandler) getHandler(PLATFORM_CLASS_PATH);
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   172
        return h.isDefault();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
1486
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   175
    /**
27852
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
   176
     * Split a search path into its elements. Empty path elements will be ignored.
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   177
     *
27852
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
   178
     * @param searchPath The search path to be split
1486
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   179
     * @return The elements of the path
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   180
     */
37944
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 37848
diff changeset
   181
    private Iterable<Path> getPathEntries(String searchPath) {
27852
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
   182
        return getPathEntries(searchPath, null);
1486
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   183
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
1486
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   185
    /**
27852
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
   186
     * Split a search path into its elements. If emptyPathDefault is not null, all empty elements in the
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   187
     * path, including empty elements at either end of the path, will be replaced with the value of
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   188
     * emptyPathDefault.
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   189
     *
27852
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
   190
     * @param searchPath The search path to be split
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   191
     * @param emptyPathDefault The value to substitute for empty path elements, or null, to ignore
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   192
     * empty path elements
1486
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   193
     * @return The elements of the path
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   194
     */
37944
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 37848
diff changeset
   195
    private Iterable<Path> getPathEntries(String searchPath, Path emptyPathDefault) {
27852
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
   196
        ListBuffer<Path> entries = new ListBuffer<>();
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
   197
        for (String s: searchPath.split(Pattern.quote(File.pathSeparator), -1)) {
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
   198
            if (s.isEmpty()) {
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
   199
                if (emptyPathDefault != null) {
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
   200
                    entries.add(emptyPathDefault);
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
   201
                }
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
   202
            } else {
37944
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 37848
diff changeset
   203
                entries.add(getPath(s));
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   204
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
        }
1486
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   206
        return entries;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   209
    /**
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   210
     * Utility class to help evaluate a path option. Duplicate entries are ignored, jar class paths
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   211
     * can be expanded.
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   212
     */
27852
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
   213
    private class SearchPath extends LinkedHashSet<Path> {
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   214
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
        private static final long serialVersionUID = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
        private boolean expandJarClassPaths = false;
27852
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
   218
        private final Set<Path> canonicalValues = new HashSet<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
27118
3c8314271af7 8060043: Rename Locations.Path to Locations.SearchPath
jjg
parents: 25874
diff changeset
   220
        public SearchPath expandJarClassPaths(boolean x) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   221
            expandJarClassPaths = x;
06bc494ca11e Initial load
duke
parents:
diff changeset
   222
            return this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   224
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   225
        /**
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   226
         * What to use when path element is the empty string
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   227
         */
27852
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
   228
        private Path emptyPathDefault = null;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
27852
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
   230
        public SearchPath emptyPathDefault(Path x) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   231
            emptyPathDefault = x;
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
            return this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   233
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   234
27118
3c8314271af7 8060043: Rename Locations.Path to Locations.SearchPath
jjg
parents: 25874
diff changeset
   235
        public SearchPath addDirectories(String dirs, boolean warn) {
8424
5e31b2eb5aa3 6485027: javac incorrectly handles relative paths in manifest classpath
jjg
parents: 8034
diff changeset
   236
            boolean prev = expandJarClassPaths;
5e31b2eb5aa3 6485027: javac incorrectly handles relative paths in manifest classpath
jjg
parents: 8034
diff changeset
   237
            expandJarClassPaths = true;
5e31b2eb5aa3 6485027: javac incorrectly handles relative paths in manifest classpath
jjg
parents: 8034
diff changeset
   238
            try {
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   239
                if (dirs != null) {
27852
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
   240
                    for (Path dir : getPathEntries(dirs)) {
8424
5e31b2eb5aa3 6485027: javac incorrectly handles relative paths in manifest classpath
jjg
parents: 8034
diff changeset
   241
                        addDirectory(dir, warn);
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   242
                    }
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   243
                }
8424
5e31b2eb5aa3 6485027: javac incorrectly handles relative paths in manifest classpath
jjg
parents: 8034
diff changeset
   244
                return this;
5e31b2eb5aa3 6485027: javac incorrectly handles relative paths in manifest classpath
jjg
parents: 8034
diff changeset
   245
            } finally {
5e31b2eb5aa3 6485027: javac incorrectly handles relative paths in manifest classpath
jjg
parents: 8034
diff changeset
   246
                expandJarClassPaths = prev;
5e31b2eb5aa3 6485027: javac incorrectly handles relative paths in manifest classpath
jjg
parents: 8034
diff changeset
   247
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   248
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   249
27118
3c8314271af7 8060043: Rename Locations.Path to Locations.SearchPath
jjg
parents: 25874
diff changeset
   250
        public SearchPath addDirectories(String dirs) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   251
            return addDirectories(dirs, warn);
06bc494ca11e Initial load
duke
parents:
diff changeset
   252
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   253
27852
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
   254
        private void addDirectory(Path dir, boolean warn) {
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
   255
            if (!Files.isDirectory(dir)) {
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   256
                if (warn) {
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   257
                    log.warning(Lint.LintCategory.PATH,
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   258
                            "dir.path.element.not.found", dir);
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   259
                }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   260
                return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
27852
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
   263
            try (Stream<Path> s = Files.list(dir)) {
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
   264
                s.filter(dirEntry -> isArchive(dirEntry))
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
   265
                        .forEach(dirEntry -> addFile(dirEntry, warn));
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
   266
            } catch (IOException ignore) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   267
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   268
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   269
27118
3c8314271af7 8060043: Rename Locations.Path to Locations.SearchPath
jjg
parents: 25874
diff changeset
   270
        public SearchPath 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
   271
            if (files != null) {
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   272
                addFiles(getPathEntries(files, emptyPathDefault), warn);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   273
            }
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   274
            return this;
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   275
        }
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   276
27118
3c8314271af7 8060043: Rename Locations.Path to Locations.SearchPath
jjg
parents: 25874
diff changeset
   277
        public SearchPath addFiles(String files) {
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   278
            return addFiles(files, warn);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   279
        }
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   280
27852
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
   281
        public SearchPath addFiles(Iterable<? extends Path> files, boolean warn) {
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   282
            if (files != null) {
27852
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
   283
                for (Path file : files) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   284
                    addFile(file, warn);
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   285
                }
7335
8b390fd27190 6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents: 6151
diff changeset
   286
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   287
            return this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   288
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   289
27852
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
   290
        public SearchPath addFiles(Iterable<? extends Path> files) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   291
            return addFiles(files, warn);
06bc494ca11e Initial load
duke
parents:
diff changeset
   292
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   293
27852
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
   294
        public void addFile(Path 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
   295
            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
   296
                // discard duplicates
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   297
                return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   298
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   299
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   300
            if (!fsInfo.exists(file)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   301
                /* No such file or directory exists */
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   302
                if (warn) {
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   303
                    log.warning(Lint.LintCategory.PATH,
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   304
                            "path.element.not.found", file);
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   305
                }
7839
a1ca72d05b20 6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents: 7336
diff changeset
   306
                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
   307
                return;
a1ca72d05b20 6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents: 7336
diff changeset
   308
            }
a1ca72d05b20 6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents: 7336
diff changeset
   309
27852
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
   310
            Path canonFile = fsInfo.getCanonicalFile(file);
7839
a1ca72d05b20 6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents: 7336
diff changeset
   311
            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
   312
                /* 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
   313
                return;
a1ca72d05b20 6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents: 7336
diff changeset
   314
            }
a1ca72d05b20 6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents: 7336
diff changeset
   315
a1ca72d05b20 6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents: 7336
diff changeset
   316
            if (fsInfo.isFile(file)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   317
                /* File is an ordinary file. */
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   318
                if (!isArchive(file)
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   319
                        && !file.getFileName().toString().endsWith(".jmod")
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   320
                        && !file.endsWith("modules")) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   321
                    /* Not a recognized extension; open it to see if
06bc494ca11e Initial load
duke
parents:
diff changeset
   322
                     it looks like a valid zip file. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   323
                    try {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   324
                        // TODO: use of ZipFile should be updated
27852
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
   325
                        ZipFile z = new ZipFile(file.toFile());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   326
                        z.close();
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   327
                        if (warn) {
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   328
                            log.warning(Lint.LintCategory.PATH,
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   329
                                    "unexpected.archive.file", file);
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   330
                        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   331
                    } catch (IOException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   332
                        // FIXME: include e.getLocalizedMessage in warning
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   333
                        if (warn) {
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   334
                            log.warning(Lint.LintCategory.PATH,
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   335
                                    "invalid.archive.file", file);
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   336
                        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   337
                        return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   338
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   339
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   340
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   341
06bc494ca11e Initial load
duke
parents:
diff changeset
   342
            /* Now what we have left is either a directory or a file name
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   343
             conforming to archive naming convention */
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   344
            super.add(file);
1208
5072b0dd3d52 6743107: clean up use of static caches in file manager
jjg
parents: 735
diff changeset
   345
            canonicalValues.add(canonFile);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   346
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   347
            if (expandJarClassPaths && fsInfo.isFile(file) && !file.endsWith("modules")) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   348
                addJarClassPath(file, warn);
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   349
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   350
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   351
06bc494ca11e Initial load
duke
parents:
diff changeset
   352
        // Adds referenced classpath elements from a jar's Class-Path
06bc494ca11e Initial load
duke
parents:
diff changeset
   353
        // Manifest entry.  In some future release, we may want to
06bc494ca11e Initial load
duke
parents:
diff changeset
   354
        // update this code to recognize URLs rather than simple
06bc494ca11e Initial load
duke
parents:
diff changeset
   355
        // filenames, but if we do, we should redo all path-related code.
27852
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
   356
        private void addJarClassPath(Path jarFile, boolean warn) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   357
            try {
27852
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
   358
                for (Path f : fsInfo.getJarClassPath(jarFile)) {
1208
5072b0dd3d52 6743107: clean up use of static caches in file manager
jjg
parents: 735
diff changeset
   359
                    addFile(f, warn);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   360
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   361
            } catch (IOException e) {
5007
28dee2489196 6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents: 4937
diff changeset
   362
                log.error("error.reading.file", jarFile, JavacFileManager.getMessage(e));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   363
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   364
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   365
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   366
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   367
    /**
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   368
     * Base class for handling support for the representation of Locations.
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   369
     *
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   370
     * Locations are (by design) opaque handles that can easily be implemented
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   371
     * by enums like StandardLocation. Within JavacFileManager, each Location
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   372
     * has an associated LocationHandler, which provides much of the appropriate
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   373
     * functionality for the corresponding Location.
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   374
     *
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   375
     * @see #initHandlers
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   376
     * @see #getHandler
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   377
     */
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   378
    protected abstract class LocationHandler {
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   379
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   380
        /**
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   381
         * @see JavaFileManager#handleOption
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   382
         */
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   383
        abstract boolean handleOption(Option option, String value);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   384
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   385
        /**
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   386
         * @see StandardJavaFileManager#hasLocation
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   387
         */
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   388
        boolean isSet() {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   389
            return (getPaths() != null);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   390
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   391
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   392
        /**
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   393
         * @see StandardJavaFileManager#getLocation
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   394
         */
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   395
        abstract Collection<Path> getPaths();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   396
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   397
        /**
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   398
         * @see StandardJavaFileManager#setLocation
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   399
         */
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   400
        abstract void setPaths(Iterable<? extends Path> files) throws IOException;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   401
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   402
        /**
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   403
         * @see JavaFileManager#getModuleLocation(Location, String)
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   404
         */
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   405
        Location getModuleLocation(String moduleName) throws IOException {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   406
            return null;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   407
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   408
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   409
        /**
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   410
         * @see JavaFileManager#getModuleLocation(Location, JavaFileObject, String)
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   411
         */
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   412
        Location getModuleLocation(Path dir) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   413
            return null;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   414
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   415
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   416
        /**
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   417
         * @see JavaFileManager#inferModuleName
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   418
         */
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   419
        String inferModuleName() {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   420
            return null;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   421
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   422
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   423
        /**
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   424
         * @see JavaFileManager#listModuleLocations
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   425
         */
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   426
        Iterable<Set<Location>> listModuleLocations() throws IOException {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   427
            return null;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   428
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   429
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   430
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   431
    /**
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   432
     * A LocationHandler for a given Location, and associated set of options.
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   433
     */
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   434
    private abstract class BasicLocationHandler extends LocationHandler {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   435
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   436
        final Location location;
11314
b612aaca08d0 7120736: refactor javac option handling
jjg
parents: 10819
diff changeset
   437
        final Set<Option> options;
7335
8b390fd27190 6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents: 6151
diff changeset
   438
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   439
        /**
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   440
         * Create a handler. The location and options provide a way to map from a location or an
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   441
         * option to the corresponding handler.
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   442
         *
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   443
         * @param location the location for which this is the handler
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   444
         * @param options the options affecting this location
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   445
         * @see #initHandlers
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   446
         */
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   447
        protected BasicLocationHandler(Location location, Option... options) {
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   448
            this.location = location;
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   449
            this.options = options.length == 0
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   450
                    ? EnumSet.noneOf(Option.class)
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   451
                    : EnumSet.copyOf(Arrays.asList(options));
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   452
        }
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
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   455
    /**
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   456
     * General purpose implementation for output locations, such as -d/CLASS_OUTPUT and
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   457
     * -s/SOURCE_OUTPUT. All options are treated as equivalent (i.e. aliases.)
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   458
     * The value is a single file, possibly null.
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   459
     */
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   460
    private class OutputLocationHandler extends BasicLocationHandler {
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   461
27852
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
   462
        private Path outputDir;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   463
        private Map<String, Location> moduleLocations;
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   464
11314
b612aaca08d0 7120736: refactor javac option handling
jjg
parents: 10819
diff changeset
   465
        OutputLocationHandler(Location location, Option... options) {
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   466
            super(location, options);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   467
        }
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
        @Override
11314
b612aaca08d0 7120736: refactor javac option handling
jjg
parents: 10819
diff changeset
   470
        boolean handleOption(Option option, String value) {
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   471
            if (!options.contains(option)) {
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   472
                return false;
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   473
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   474
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   475
            // TODO: could/should validate outputDir exists and is a directory
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   476
            // need to decide how best to report issue for benefit of
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   477
            // direct API call on JavaFileManager.handleOption(specifies IAE)
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   478
            // vs. command line decoding.
37944
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 37848
diff changeset
   479
            outputDir = (value == null) ? null : getPath(value);
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   480
            return true;
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
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   483
        @Override
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   484
        Collection<Path> getPaths() {
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   485
            return (outputDir == null) ? null : Collections.singleton(outputDir);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   486
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   487
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   488
        @Override
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   489
        void setPaths(Iterable<? extends Path> files) throws IOException {
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   490
            if (files == null) {
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   491
                outputDir = null;
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   492
            } else {
27852
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
   493
                Iterator<? extends Path> pathIter = files.iterator();
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   494
                if (!pathIter.hasNext()) {
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   495
                    throw new IllegalArgumentException("empty path for directory");
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   496
                }
27852
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
   497
                Path dir = pathIter.next();
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   498
                if (pathIter.hasNext()) {
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   499
                    throw new IllegalArgumentException("path too long for directory");
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   500
                }
27852
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
   501
                if (!Files.exists(dir)) {
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   502
                    throw new FileNotFoundException(dir + ": does not exist");
27852
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
   503
                } else if (!Files.isDirectory(dir)) {
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   504
                    throw new IOException(dir + ": not a directory");
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   505
                }
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   506
                outputDir = dir;
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   507
            }
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   508
            moduleLocations = null;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   509
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   510
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   511
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   512
        Location getModuleLocation(String name) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   513
            if (moduleLocations == null)
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   514
                moduleLocations = new HashMap<>();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   515
            Location l = moduleLocations.get(name);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   516
            if (l == null) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   517
                l = new ModuleLocationHandler(location.getName() + "[" + name + "]",
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   518
                        name,
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   519
                        Collections.singleton(outputDir.resolve(name)),
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   520
                        true, false);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   521
                moduleLocations.put(name, l);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   522
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   523
            return l;
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   524
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   525
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   526
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   527
    /**
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   528
     * General purpose implementation for search path locations,
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   529
     * such as -sourcepath/SOURCE_PATH and -processorPath/ANNOTATION_PROCESSOR_PATH.
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   530
     * All options are treated as equivalent (i.e. aliases.)
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   531
     * The value is an ordered set of files and/or directories.
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   532
     */
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   533
    private class SimpleLocationHandler extends BasicLocationHandler {
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   534
27852
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
   535
        protected Collection<Path> searchPath;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   536
11314
b612aaca08d0 7120736: refactor javac option handling
jjg
parents: 10819
diff changeset
   537
        SimpleLocationHandler(Location location, Option... options) {
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   538
            super(location, options);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   539
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   540
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   541
        @Override
11314
b612aaca08d0 7120736: refactor javac option handling
jjg
parents: 10819
diff changeset
   542
        boolean handleOption(Option option, String value) {
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   543
            if (!options.contains(option)) {
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   544
                return false;
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   545
            }
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   546
            searchPath = value == null ? null
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   547
                    : Collections.unmodifiableCollection(createPath().addFiles(value));
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   548
            return true;
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   549
        }
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   550
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   551
        @Override
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   552
        Collection<Path> getPaths() {
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   553
            return searchPath;
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   554
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   555
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   556
        @Override
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   557
        void setPaths(Iterable<? extends Path> files) {
27118
3c8314271af7 8060043: Rename Locations.Path to Locations.SearchPath
jjg
parents: 25874
diff changeset
   558
            SearchPath p;
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   559
            if (files == null) {
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   560
                p = computePath(null);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   561
            } else {
14360
2a8304e421ed 6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents: 14259
diff changeset
   562
                p = createPath().addFiles(files);
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   563
            }
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   564
            searchPath = Collections.unmodifiableCollection(p);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   565
        }
14360
2a8304e421ed 6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents: 14259
diff changeset
   566
27118
3c8314271af7 8060043: Rename Locations.Path to Locations.SearchPath
jjg
parents: 25874
diff changeset
   567
        protected SearchPath computePath(String value) {
14360
2a8304e421ed 6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents: 14259
diff changeset
   568
            return createPath().addFiles(value);
2a8304e421ed 6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents: 14259
diff changeset
   569
        }
2a8304e421ed 6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents: 14259
diff changeset
   570
27118
3c8314271af7 8060043: Rename Locations.Path to Locations.SearchPath
jjg
parents: 25874
diff changeset
   571
        protected SearchPath createPath() {
3c8314271af7 8060043: Rename Locations.Path to Locations.SearchPath
jjg
parents: 25874
diff changeset
   572
            return new SearchPath();
14360
2a8304e421ed 6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents: 14259
diff changeset
   573
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   574
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   575
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   576
    /**
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   577
     * Subtype of SimpleLocationHandler for -classpath/CLASS_PATH.
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   578
     * If no value is given, a default is provided, based on system properties and other values.
10818
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
    private class ClassPathLocationHandler extends SimpleLocationHandler {
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   581
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   582
        ClassPathLocationHandler() {
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   583
            super(StandardLocation.CLASS_PATH,
11314
b612aaca08d0 7120736: refactor javac option handling
jjg
parents: 10819
diff changeset
   584
                    Option.CLASSPATH, Option.CP);
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   585
        }
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   586
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   587
        @Override
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   588
        Collection<Path> getPaths() {
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   589
            lazy();
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   590
            return searchPath;
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   591
        }
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   592
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   593
        @Override
27118
3c8314271af7 8060043: Rename Locations.Path to Locations.SearchPath
jjg
parents: 25874
diff changeset
   594
        protected SearchPath computePath(String value) {
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   595
            String cp = value;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   596
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   597
            // CLASSPATH environment variable when run from `javac'.
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   598
            if (cp == null) {
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   599
                cp = System.getProperty("env.class.path");
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   600
            }
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   601
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   602
            // If invoked via a java VM (not the javac launcher), use the
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   603
            // platform class path
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   604
            if (cp == null && System.getProperty("application.home") == null) {
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   605
                cp = System.getProperty("java.class.path");
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   606
            }
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   607
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   608
            // Default to current working directory.
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   609
            if (cp == null) {
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   610
                cp = ".";
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   611
            }
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   612
14360
2a8304e421ed 6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents: 14259
diff changeset
   613
            return createPath().addFiles(cp);
2a8304e421ed 6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents: 14259
diff changeset
   614
        }
2a8304e421ed 6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents: 14259
diff changeset
   615
2a8304e421ed 6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents: 14259
diff changeset
   616
        @Override
27118
3c8314271af7 8060043: Rename Locations.Path to Locations.SearchPath
jjg
parents: 25874
diff changeset
   617
        protected SearchPath createPath() {
3c8314271af7 8060043: Rename Locations.Path to Locations.SearchPath
jjg
parents: 25874
diff changeset
   618
            return new SearchPath()
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   619
                    .expandJarClassPaths(true) // Only search user jars for Class-Paths
37944
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 37848
diff changeset
   620
                    .emptyPathDefault(getPath("."));  // Empty path elt ==> current directory
14360
2a8304e421ed 6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents: 14259
diff changeset
   621
        }
10818
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
        private void lazy() {
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   624
            if (searchPath == null) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   625
                setPaths(null);
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   626
            }
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   627
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   628
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   629
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   630
    /**
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   631
     * Custom subtype of LocationHandler for PLATFORM_CLASS_PATH.
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   632
     * Various options are supported for different components of the
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   633
     * platform class path.
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   634
     * Setting a value with setLocation overrides all existing option values.
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   635
     * Setting any option overrides any value set with setLocation, and
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   636
     * reverts to using default values for options that have not been set.
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   637
     * Setting -bootclasspath or -Xbootclasspath overrides any existing
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   638
     * value for -Xbootclasspath/p: and -Xbootclasspath/a:.
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   639
     */
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   640
    private class BootClassPathLocationHandler extends BasicLocationHandler {
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   641
27852
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
   642
        private Collection<Path> searchPath;
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22153
diff changeset
   643
        final Map<Option, String> optionValues = new EnumMap<>(Option.class);
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   644
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   645
        /**
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   646
         * Is the bootclasspath the default?
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   647
         */
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   648
        private boolean isDefault;
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
        BootClassPathLocationHandler() {
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   651
            super(StandardLocation.PLATFORM_CLASS_PATH,
11314
b612aaca08d0 7120736: refactor javac option handling
jjg
parents: 10819
diff changeset
   652
                    Option.BOOTCLASSPATH, Option.XBOOTCLASSPATH,
b612aaca08d0 7120736: refactor javac option handling
jjg
parents: 10819
diff changeset
   653
                    Option.XBOOTCLASSPATH_PREPEND,
b612aaca08d0 7120736: refactor javac option handling
jjg
parents: 10819
diff changeset
   654
                    Option.XBOOTCLASSPATH_APPEND,
b612aaca08d0 7120736: refactor javac option handling
jjg
parents: 10819
diff changeset
   655
                    Option.ENDORSEDDIRS, Option.DJAVA_ENDORSED_DIRS,
b612aaca08d0 7120736: refactor javac option handling
jjg
parents: 10819
diff changeset
   656
                    Option.EXTDIRS, Option.DJAVA_EXT_DIRS);
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   657
        }
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   658
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   659
        boolean isDefault() {
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   660
            lazy();
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   661
            return isDefault;
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   662
        }
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   663
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   664
        @Override
11314
b612aaca08d0 7120736: refactor javac option handling
jjg
parents: 10819
diff changeset
   665
        boolean handleOption(Option option, String value) {
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   666
            if (!options.contains(option)) {
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   667
                return false;
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   668
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   669
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   670
            option = canonicalize(option);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   671
            optionValues.put(option, value);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   672
            if (option == BOOTCLASSPATH) {
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   673
                optionValues.remove(XBOOTCLASSPATH_PREPEND);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   674
                optionValues.remove(XBOOTCLASSPATH_APPEND);
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
            searchPath = null;  // reset to "uninitialized"
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   677
            return true;
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   678
        }
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   679
        // where
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   680
        // TODO: would be better if option aliasing was handled at a higher
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   681
        // level
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   682
        private Option canonicalize(Option option) {
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   683
            switch (option) {
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   684
                case XBOOTCLASSPATH:
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   685
                    return Option.BOOTCLASSPATH;
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   686
                case DJAVA_ENDORSED_DIRS:
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   687
                    return Option.ENDORSEDDIRS;
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   688
                case DJAVA_EXT_DIRS:
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   689
                    return Option.EXTDIRS;
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   690
                default:
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   691
                    return option;
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   692
            }
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   693
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   694
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   695
        @Override
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   696
        Collection<Path> getPaths() {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   697
            lazy();
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   698
            return searchPath;
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
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   701
        @Override
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   702
        void setPaths(Iterable<? extends Path> files) {
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   703
            if (files == null) {
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   704
                searchPath = null;  // reset to "uninitialized"
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   705
            } else {
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   706
                isDefault = false;
27118
3c8314271af7 8060043: Rename Locations.Path to Locations.SearchPath
jjg
parents: 25874
diff changeset
   707
                SearchPath p = new SearchPath().addFiles(files, false);
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   708
                searchPath = Collections.unmodifiableCollection(p);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   709
                optionValues.clear();
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   710
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   711
        }
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   712
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   713
        SearchPath computePath() throws IOException {
27118
3c8314271af7 8060043: Rename Locations.Path to Locations.SearchPath
jjg
parents: 25874
diff changeset
   714
            SearchPath path = new SearchPath();
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   715
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   716
            String bootclasspathOpt = optionValues.get(BOOTCLASSPATH);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   717
            String endorseddirsOpt = optionValues.get(ENDORSEDDIRS);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   718
            String extdirsOpt = optionValues.get(EXTDIRS);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   719
            String xbootclasspathPrependOpt = optionValues.get(XBOOTCLASSPATH_PREPEND);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   720
            String xbootclasspathAppendOpt = optionValues.get(XBOOTCLASSPATH_APPEND);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   721
            path.addFiles(xbootclasspathPrependOpt);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   722
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   723
            if (endorseddirsOpt != null) {
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   724
                path.addDirectories(endorseddirsOpt);
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   725
            } else {
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   726
                path.addDirectories(System.getProperty("java.endorsed.dirs"), false);
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   727
            }
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   728
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   729
            if (bootclasspathOpt != null) {
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   730
                path.addFiles(bootclasspathOpt);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   731
            } else {
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   732
                // Standard system classes for this compiler's release.
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   733
                Collection<Path> systemClasses = systemClasses();
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   734
                if (systemClasses != null) {
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   735
                    path.addFiles(systemClasses, false);
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   736
                } else {
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   737
                    // fallback to the value of sun.boot.class.path
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   738
                    String files = System.getProperty("sun.boot.class.path");
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   739
                    path.addFiles(files, false);
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   740
                }
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   741
            }
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   742
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   743
            path.addFiles(xbootclasspathAppendOpt);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   744
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   745
            // Strictly speaking, standard extensions are not bootstrap
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   746
            // classes, but we treat them identically, so we'll pretend
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   747
            // that they are.
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   748
            if (extdirsOpt != null) {
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   749
                path.addDirectories(extdirsOpt);
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   750
            } else {
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   751
                // Add lib/jfxrt.jar to the search path
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   752
               Path jfxrt = javaHome.resolve("lib/jfxrt.jar");
27858
chegar
parents: 27579 27852
diff changeset
   753
                if (Files.exists(jfxrt)) {
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   754
                    path.addFile(jfxrt, false);
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   755
                }
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   756
                path.addDirectories(System.getProperty("java.ext.dirs"), false);
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   757
            }
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   758
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   759
            isDefault =
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   760
                       (xbootclasspathPrependOpt == null)
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   761
                    && (bootclasspathOpt == null)
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   762
                    && (xbootclasspathAppendOpt == null);
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   763
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   764
            return path;
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   765
        }
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   766
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   767
        /**
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   768
         * Return a collection of files containing system classes.
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   769
         * Returns {@code null} if not running on a modular image.
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   770
         *
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   771
         * @throws UncheckedIOException if an I/O errors occurs
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   772
         */
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   773
        private Collection<Path> systemClasses() throws IOException {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   774
            // Return "modules" jimage file if available
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   775
            if (Files.isRegularFile(thisSystemModules)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   776
                return addAdditionalBootEntries(Collections.singleton(thisSystemModules));
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   777
            }
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   778
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   779
            // Exploded module image
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   780
            Path modules = javaHome.resolve("modules");
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   781
            if (Files.isDirectory(modules.resolve("java.base"))) {
29053
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents: 28707
diff changeset
   782
                try (Stream<Path> listedModules = Files.list(modules)) {
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents: 28707
diff changeset
   783
                    return addAdditionalBootEntries(listedModules.collect(Collectors.toList()));
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents: 28707
diff changeset
   784
                }
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   785
            }
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   786
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   787
            // not a modular image that we know about
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   788
            return null;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   789
        }
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   790
29053
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents: 28707
diff changeset
   791
        //ensure bootclasspath prepends/appends are reflected in the systemClasses
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents: 28707
diff changeset
   792
        private Collection<Path> addAdditionalBootEntries(Collection<Path> modules) throws IOException {
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents: 28707
diff changeset
   793
            String files = System.getProperty("sun.boot.class.path");
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents: 28707
diff changeset
   794
            if (files == null)
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents: 28707
diff changeset
   795
                return modules;
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents: 28707
diff changeset
   796
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents: 28707
diff changeset
   797
            Set<Path> paths = new LinkedHashSet<>();
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents: 28707
diff changeset
   798
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   799
            // The JVM no longer supports -Xbootclasspath/p:, so any interesting
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   800
            // entries should be appended to the set of modules.
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   801
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   802
            paths.addAll(modules);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   803
29053
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents: 28707
diff changeset
   804
            for (String s : files.split(Pattern.quote(File.pathSeparator))) {
37944
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 37848
diff changeset
   805
                paths.add(getPath(s));
29053
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents: 28707
diff changeset
   806
            }
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents: 28707
diff changeset
   807
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents: 28707
diff changeset
   808
            return paths;
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents: 28707
diff changeset
   809
        }
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents: 28707
diff changeset
   810
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   811
        private void lazy() {
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   812
            if (searchPath == null) {
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   813
                try {
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   814
                searchPath = Collections.unmodifiableCollection(computePath());
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   815
                } catch (IOException e) {
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   816
                    // TODO: need better handling here, e.g. javac Abort?
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   817
                    throw new UncheckedIOException(e);
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   818
                }
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   819
            }
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   820
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   821
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   822
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   823
    /**
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   824
     * A LocationHander to represent modules found from a module-oriented
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   825
     * location such as MODULE_SOURCE_PATH, UPGRADE_MODULE_PATH,
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   826
     * SYSTEM_MODULES and MODULE_PATH.
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   827
     *
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   828
     * The Location can be specified to accept overriding classes from the
37848
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36526
diff changeset
   829
     * {@code -Xpatch:<module>=<path> } parameter.
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   830
     */
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   831
    private class ModuleLocationHandler extends LocationHandler implements Location {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   832
        protected final String name;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   833
        protected final String moduleName;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   834
        protected final Collection<Path> searchPath;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   835
        protected final Collection<Path> searchPathWithOverrides;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   836
        protected final boolean output;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   837
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   838
        ModuleLocationHandler(String name, String moduleName, Collection<Path> searchPath,
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   839
                boolean output, boolean allowOverrides) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   840
            this.name = name;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   841
            this.moduleName = moduleName;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   842
            this.searchPath = searchPath;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   843
            this.output = output;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   844
37848
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36526
diff changeset
   845
            if (allowOverrides && patchMap != null) {
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36526
diff changeset
   846
                SearchPath mPatch = patchMap.get(moduleName);
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36526
diff changeset
   847
                if (mPatch != null) {
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36526
diff changeset
   848
                    SearchPath sp = new SearchPath();
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36526
diff changeset
   849
                    sp.addAll(mPatch);
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36526
diff changeset
   850
                    sp.addAll(searchPath);
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36526
diff changeset
   851
                    searchPathWithOverrides = sp;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   852
                } else {
37848
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36526
diff changeset
   853
                    searchPathWithOverrides = searchPath;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   854
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   855
            } else {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   856
                searchPathWithOverrides = searchPath;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   857
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   858
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   859
37848
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36526
diff changeset
   860
        @Override @DefinedBy(Api.COMPILER)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   861
        public String getName() {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   862
            return name;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   863
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   864
37848
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36526
diff changeset
   865
        @Override @DefinedBy(Api.COMPILER)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   866
        public boolean isOutputLocation() {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   867
            return output;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   868
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   869
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   870
        @Override // defined by LocationHandler
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   871
        boolean handleOption(Option option, String value) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   872
            throw new UnsupportedOperationException();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   873
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   874
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   875
        @Override // defined by LocationHandler
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   876
        Collection<Path> getPaths() {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   877
            // For now, we always return searchPathWithOverrides. This may differ from the
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   878
            // JVM behavior if there is a module-info.class to be found in the overriding
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   879
            // classes.
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   880
            return searchPathWithOverrides;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   881
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   882
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   883
        @Override // defined by LocationHandler
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   884
        void setPaths(Iterable<? extends Path> files) throws IOException {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   885
            throw new UnsupportedOperationException();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   886
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   887
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   888
        @Override // defined by LocationHandler
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   889
        String inferModuleName() {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   890
            return moduleName;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   891
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   892
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   893
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   894
    /**
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   895
     * A LocationHandler for simple module-oriented search paths,
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   896
     * like UPGRADE_MODULE_PATH and MODULE_PATH.
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   897
     */
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   898
    private class ModulePathLocationHandler extends SimpleLocationHandler {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   899
        ModulePathLocationHandler(Location location, Option... options) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   900
            super(location, options);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   901
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   902
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   903
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   904
        public boolean handleOption(Option option, String value) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   905
            if (!options.contains(option)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   906
                return false;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   907
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   908
            setPaths(value == null ? null : getPathEntries(value));
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   909
            return true;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   910
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   911
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   912
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   913
        Iterable<Set<Location>> listModuleLocations() {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   914
            if (searchPath == null)
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   915
                return Collections.emptyList();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   916
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   917
            return () -> new ModulePathIterator();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   918
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   919
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   920
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   921
        void setPaths(Iterable<? extends Path> paths) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   922
            if (paths != null) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   923
                for (Path p: paths) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   924
                    checkValidModulePathEntry(p);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   925
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   926
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   927
            super.setPaths(paths);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   928
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   929
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   930
        private void checkValidModulePathEntry(Path p) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   931
            if (Files.isDirectory(p)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   932
                // either an exploded module or a directory of modules
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   933
                return;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   934
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   935
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   936
            String name = p.getFileName().toString();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   937
            int lastDot = name.lastIndexOf(".");
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   938
            if (lastDot > 0) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   939
                switch (name.substring(lastDot)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   940
                    case ".jar":
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   941
                    case ".jmod":
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   942
                        return;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   943
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   944
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   945
            throw new IllegalArgumentException(p.toString());
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   946
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   947
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   948
        class ModulePathIterator implements Iterator<Set<Location>> {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   949
            Iterator<Path> pathIter = searchPath.iterator();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   950
            int pathIndex = 0;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   951
            Set<Location> next = null;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   952
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   953
            @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   954
            public boolean hasNext() {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   955
                if (next != null)
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   956
                    return true;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   957
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   958
                while (next == null) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   959
                    if (pathIter.hasNext()) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   960
                        Path path = pathIter.next();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   961
                        if (Files.isDirectory(path)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   962
                            next = scanDirectory(path);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   963
                        } else {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   964
                            next = scanFile(path);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   965
                        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   966
                        pathIndex++;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   967
                    } else
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   968
                        return false;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   969
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   970
                return true;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   971
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   972
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   973
            @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   974
            public Set<Location> next() {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   975
                hasNext();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   976
                if (next != null) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   977
                    Set<Location> result = next;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   978
                    next = null;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   979
                    return result;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   980
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   981
                throw new NoSuchElementException();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   982
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   983
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   984
            private Set<Location> scanDirectory(Path path) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   985
                Set<Path> paths = new LinkedHashSet<>();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   986
                Path moduleInfoClass = null;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   987
                try (DirectoryStream<Path> stream = Files.newDirectoryStream(path)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   988
                    for (Path entry: stream) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   989
                        if (entry.endsWith("module-info.class")) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   990
                            moduleInfoClass = entry;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   991
                            break;  // no need to continue scanning
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   992
                        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   993
                        paths.add(entry);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   994
                    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   995
                } catch (DirectoryIteratorException | IOException ignore) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   996
                    log.error(Errors.LocnCantReadDirectory(path));
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   997
                    return Collections.emptySet();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   998
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   999
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1000
                if (moduleInfoClass != null) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1001
                    // It's an exploded module directly on the module path.
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1002
                    // We can't infer module name from the directory name, so have to
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1003
                    // read module-info.class.
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1004
                    try {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1005
                        String moduleName = readModuleName(moduleInfoClass);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1006
                        String name = location.getName()
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1007
                                + "[" + pathIndex + ":" + moduleName + "]";
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1008
                        ModuleLocationHandler l = new ModuleLocationHandler(name, moduleName,
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1009
                                Collections.singleton(path), false, true);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1010
                        return Collections.singleton(l);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1011
                    } catch (ModuleNameReader.BadClassFile e) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1012
                        log.error(Errors.LocnBadModuleInfo(path));
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1013
                        return Collections.emptySet();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1014
                    } catch (IOException e) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1015
                        log.error(Errors.LocnCantReadFile(path));
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1016
                        return Collections.emptySet();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1017
                    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1018
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1019
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1020
                // A directory of modules
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1021
                Set<Location> result = new LinkedHashSet<>();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1022
                int index = 0;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1023
                for (Path entry : paths) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1024
                    Pair<String,Path> module = inferModuleName(entry);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1025
                    if (module == null) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1026
                        // diagnostic reported if necessary; skip to next
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1027
                        continue;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1028
                    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1029
                    String moduleName = module.fst;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1030
                    Path modulePath = module.snd;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1031
                    String name = location.getName()
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1032
                            + "[" + pathIndex + "." + (index++) + ":" + moduleName + "]";
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1033
                    ModuleLocationHandler l = new ModuleLocationHandler(name, moduleName,
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1034
                            Collections.singleton(modulePath), false, true);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1035
                    result.add(l);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1036
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1037
                return result;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1038
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1039
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1040
            private Set<Location> scanFile(Path path) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1041
                Pair<String,Path> module = inferModuleName(path);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1042
                if (module == null) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1043
                    // diagnostic reported if necessary
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1044
                    return Collections.emptySet();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1045
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1046
                String moduleName = module.fst;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1047
                Path modulePath = module.snd;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1048
                String name = location.getName()
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1049
                        + "[" + pathIndex + ":" + moduleName + "]";
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1050
                ModuleLocationHandler l = new ModuleLocationHandler(name, moduleName,
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1051
                        Collections.singleton(modulePath), false, true);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1052
                return Collections.singleton(l);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1053
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1054
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1055
            private Pair<String,Path> inferModuleName(Path p) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1056
                if (Files.isDirectory(p)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1057
                    if (Files.exists(p.resolve("module-info.class"))) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1058
                        String name = p.getFileName().toString();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1059
                        if (SourceVersion.isName(name))
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1060
                            return new Pair<>(name, p);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1061
                    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1062
                    return null;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1063
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1064
38536
42569f7fe4e6 8154824: Compiler should handle java.nio.file.FileSystemNotFoundException gracefully and not abort
sadayapalam
parents: 38519
diff changeset
  1065
                if (p.getFileName().toString().endsWith(".jar") && fsInfo.exists(p)) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1066
                    try (FileSystem fs = FileSystems.newFileSystem(p, null)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1067
                        Path moduleInfoClass = fs.getPath("module-info.class");
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1068
                        if (Files.exists(moduleInfoClass)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1069
                            String moduleName = readModuleName(moduleInfoClass);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1070
                            return new Pair<>(moduleName, p);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1071
                        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1072
                    } catch (ModuleNameReader.BadClassFile e) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1073
                        log.error(Errors.LocnBadModuleInfo(p));
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1074
                        return null;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1075
                    } catch (IOException e) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1076
                        log.error(Errors.LocnCantReadFile(p));
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1077
                        return null;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1078
                    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1079
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1080
                    //automatic module:
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1081
                    String fn = p.getFileName().toString();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1082
                    //from ModulePath.deriveModuleDescriptor:
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1083
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1084
                    // drop .jar
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1085
                    String mn = fn.substring(0, fn.length()-4);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1086
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1087
                    // find first occurrence of -${NUMBER}. or -${NUMBER}$
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1088
                    Matcher matcher = Pattern.compile("-(\\d+(\\.|$))").matcher(mn);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1089
                    if (matcher.find()) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1090
                        int start = matcher.start();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1091
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1092
                        mn = mn.substring(0, start);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1093
                    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1094
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1095
                    // finally clean up the module name
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1096
                    mn =  mn.replaceAll("[^A-Za-z0-9]", ".")  // replace non-alphanumeric
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1097
                            .replaceAll("(\\.)(\\1)+", ".")   // collapse repeating dots
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1098
                            .replaceAll("^\\.", "")           // drop leading dots
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1099
                            .replaceAll("\\.$", "");          // drop trailing dots
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1100
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1101
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1102
                    if (!mn.isEmpty()) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1103
                        return new Pair<>(mn, p);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1104
                    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1105
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1106
                    log.error(Errors.LocnCantGetModuleNameForJar(p));
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1107
                    return null;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1108
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1109
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1110
                if (p.getFileName().toString().endsWith(".jmod")) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1111
                    try {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1112
                        FileSystem fs = fileSystems.get(p);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1113
                        if (fs == null) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1114
                            URI uri = URI.create("jar:" + p.toUri());
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1115
                            fs = FileSystems.newFileSystem(uri, Collections.emptyMap(), null);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1116
                            try {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1117
                                Path moduleInfoClass = fs.getPath("classes/module-info.class");
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1118
                                String moduleName = readModuleName(moduleInfoClass);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1119
                                Path modulePath = fs.getPath("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1120
                                fileSystems.put(p, fs);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1121
                                closeables.add(fs);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1122
                                fs = null; // prevent fs being closed in the finally clause
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1123
                                return new Pair<>(moduleName, modulePath);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1124
                            } finally {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1125
                                if (fs != null)
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1126
                                    fs.close();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1127
                            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1128
                        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1129
                    } catch (ProviderNotFoundException e) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1130
                        // will be thrown if the file is not a valid zip file
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1131
                        log.error(Errors.LocnCantReadFile(p));
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1132
                        return null;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1133
                    } catch (ModuleNameReader.BadClassFile e) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1134
                        log.error(Errors.LocnBadModuleInfo(p));
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1135
                    } catch (IOException e) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1136
                        log.error(Errors.LocnCantReadFile(p));
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1137
                        return null;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1138
                    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1139
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1140
38519
d70d50ec27bb 8154997: Add examples for jigsaw diagnostics
sadayapalam
parents: 37944
diff changeset
  1141
                if (warn && false) {  // temp disable, when enabled, massage examples.not-yet.txt suitably.
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1142
                    log.warning(Warnings.LocnUnknownFileOnModulePath(p));
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1143
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1144
                return null;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1145
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1146
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1147
            private String readModuleName(Path path) throws IOException, ModuleNameReader.BadClassFile {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1148
                if (moduleNameReader == null)
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1149
                    moduleNameReader = new ModuleNameReader();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1150
                return moduleNameReader.readModuleName(path);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1151
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1152
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1153
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1154
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1155
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1156
    private class ModuleSourcePathLocationHandler extends BasicLocationHandler {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1157
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1158
        private Map<String, Location> moduleLocations;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1159
        private Map<Path, Location> pathLocations;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1160
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1161
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1162
        ModuleSourcePathLocationHandler() {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1163
            super(StandardLocation.MODULE_SOURCE_PATH,
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1164
                    Option.MODULESOURCEPATH);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1165
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1166
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1167
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1168
        boolean handleOption(Option option, String value) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1169
            init(value);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1170
            return true;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1171
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1172
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1173
        void init(String value) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1174
            Collection<String> segments = new ArrayList<>();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1175
            for (String s: value.split(File.pathSeparator)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1176
                expandBraces(s, segments);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1177
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1178
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1179
            Map<String, Collection<Path>> map = new LinkedHashMap<>();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1180
            final String MARKER = "*";
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1181
            for (String seg: segments) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1182
                int markStart = seg.indexOf(MARKER);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1183
                if (markStart == -1) {
37944
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 37848
diff changeset
  1184
                    add(map, getPath(seg), null);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1185
                } else {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1186
                    if (markStart == 0 || !isSeparator(seg.charAt(markStart - 1))) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1187
                        throw new IllegalArgumentException("illegal use of " + MARKER + " in " + seg);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1188
                    }
37944
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 37848
diff changeset
  1189
                    Path prefix = getPath(seg.substring(0, markStart - 1));
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1190
                    Path suffix;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1191
                    int markEnd = markStart + MARKER.length();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1192
                    if (markEnd == seg.length()) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1193
                        suffix = null;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1194
                    } else if (!isSeparator(seg.charAt(markEnd))
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1195
                            || seg.indexOf(MARKER, markEnd) != -1) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1196
                        throw new IllegalArgumentException("illegal use of " + MARKER + " in " + seg);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1197
                    } else {
37944
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 37848
diff changeset
  1198
                        suffix = getPath(seg.substring(markEnd + 1));
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1199
                    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1200
                    add(map, prefix, suffix);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1201
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1202
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1203
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1204
            moduleLocations = new LinkedHashMap<>();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1205
            pathLocations = new LinkedHashMap<>();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1206
            map.forEach((k, v) -> {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1207
                String name = location.getName() + "[" + k + "]";
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1208
                ModuleLocationHandler h = new ModuleLocationHandler(name, k, v, false, false);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1209
                moduleLocations.put(k, h);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1210
                v.forEach(p -> pathLocations.put(normalize(p), h));
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1211
            });
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1212
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1213
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1214
        private boolean isSeparator(char ch) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1215
            // allow both separators on Windows
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1216
            return (ch == File.separatorChar) || (ch == '/');
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1217
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1218
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1219
        void add(Map<String, Collection<Path>> map, Path prefix, Path suffix) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1220
            if (!Files.isDirectory(prefix)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1221
                if (warn) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1222
                    String key = Files.exists(prefix)
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1223
                            ? "dir.path.element.not.directory"
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1224
                            : "dir.path.element.not.found";
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1225
                    log.warning(Lint.LintCategory.PATH, key, prefix);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1226
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1227
                return;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1228
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1229
            try (DirectoryStream<Path> stream = Files.newDirectoryStream(prefix, path -> Files.isDirectory(path))) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1230
                for (Path entry: stream) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1231
                    Path path = (suffix == null) ? entry : entry.resolve(suffix);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1232
                    if (Files.isDirectory(path)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1233
                        String name = entry.getFileName().toString();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1234
                        Collection<Path> paths = map.get(name);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1235
                        if (paths == null)
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1236
                            map.put(name, paths = new ArrayList<>());
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1237
                        paths.add(path);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1238
                    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1239
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1240
            } catch (IOException e) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1241
                // TODO? What to do?
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1242
                System.err.println(e);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1243
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1244
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1245
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1246
        private void expandBraces(String value, Collection<String> results) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1247
            int depth = 0;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1248
            int start = -1;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1249
            String prefix = null;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1250
            String suffix = null;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1251
            for (int i = 0; i < value.length(); i++) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1252
                switch (value.charAt(i)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1253
                    case '{':
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1254
                        depth++;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1255
                        if (depth == 1) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1256
                            prefix = value.substring(0, i);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1257
                            suffix = value.substring(getMatchingBrace(value, i) + 1);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1258
                            start = i + 1;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1259
                        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1260
                        break;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1261
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1262
                    case ',':
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1263
                        if (depth == 1) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1264
                            String elem = value.substring(start, i);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1265
                            expandBraces(prefix + elem + suffix, results);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1266
                            start = i + 1;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1267
                        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1268
                        break;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1269
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1270
                    case '}':
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1271
                        switch (depth) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1272
                            case 0:
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1273
                                throw new IllegalArgumentException("mismatched braces");
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1274
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1275
                            case 1:
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1276
                                String elem = value.substring(start, i);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1277
                                expandBraces(prefix + elem + suffix, results);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1278
                                return;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1279
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1280
                            default:
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1281
                                depth--;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1282
                        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1283
                        break;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1284
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1285
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1286
            if (depth > 0)
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1287
                throw new IllegalArgumentException("mismatched braces");
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1288
            results.add(value);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1289
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1290
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1291
        int getMatchingBrace(String value, int offset) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1292
            int depth = 1;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1293
            for (int i = offset + 1; i < value.length(); i++) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1294
                switch (value.charAt(i)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1295
                    case '{':
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1296
                        depth++;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1297
                        break;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1298
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1299
                    case '}':
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1300
                        if (--depth == 0)
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1301
                            return i;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1302
                        break;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1303
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1304
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1305
            throw new IllegalArgumentException("mismatched braces");
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1306
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1307
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1308
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1309
        boolean isSet() {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1310
            return (moduleLocations != null);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1311
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1312
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1313
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1314
        Collection<Path> getPaths() {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1315
            throw new UnsupportedOperationException();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1316
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1317
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1318
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1319
        void setPaths(Iterable<? extends Path> files) throws IOException {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1320
            throw new UnsupportedOperationException();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1321
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1322
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1323
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1324
        Location getModuleLocation(String name) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1325
            return (moduleLocations == null) ? null : moduleLocations.get(name);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1326
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1327
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1328
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1329
        Location getModuleLocation(Path dir) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1330
            return (pathLocations == null) ? null : pathLocations.get(dir);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1331
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1332
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1333
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1334
        Iterable<Set<Location>> listModuleLocations() {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1335
            if (moduleLocations == null)
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1336
                return Collections.emptySet();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1337
            Set<Location> locns = new LinkedHashSet<>();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1338
            moduleLocations.forEach((k, v) -> locns.add(v));
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1339
            return Collections.singleton(locns);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1340
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1341
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1342
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1343
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1344
    private class SystemModulesLocationHandler extends BasicLocationHandler {
37944
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 37848
diff changeset
  1345
        private Path systemJavaHome;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1346
        private Path modules;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1347
        private Map<String, ModuleLocationHandler> systemModules;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1348
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1349
        SystemModulesLocationHandler() {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1350
            super(StandardLocation.SYSTEM_MODULES, Option.SYSTEM);
37944
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 37848
diff changeset
  1351
            systemJavaHome = Locations.javaHome;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1352
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1353
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1354
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1355
        boolean handleOption(Option option, String value) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1356
            if (!options.contains(option)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1357
                return false;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1358
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1359
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1360
            if (value == null) {
37944
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 37848
diff changeset
  1361
                systemJavaHome = Locations.javaHome;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1362
            } else if (value.equals("none")) {
37944
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 37848
diff changeset
  1363
                systemJavaHome = null;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1364
            } else {
37944
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 37848
diff changeset
  1365
                update(getPath(value));
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1366
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1367
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1368
            modules = null;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1369
            return true;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1370
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1371
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1372
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1373
        Collection<Path> getPaths() {
37944
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 37848
diff changeset
  1374
            return (systemJavaHome == null) ? null : Collections.singleton(systemJavaHome);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1375
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1376
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1377
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1378
        void setPaths(Iterable<? extends Path> files) throws IOException {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1379
            if (files == null) {
37944
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 37848
diff changeset
  1380
                systemJavaHome = null;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1381
            } else {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1382
                Iterator<? extends Path> pathIter = files.iterator();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1383
                if (!pathIter.hasNext()) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1384
                    throw new IllegalArgumentException("empty path for directory"); // TODO: FIXME
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1385
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1386
                Path dir = pathIter.next();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1387
                if (pathIter.hasNext()) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1388
                    throw new IllegalArgumentException("path too long for directory"); // TODO: FIXME
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1389
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1390
                if (!Files.exists(dir)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1391
                    throw new FileNotFoundException(dir + ": does not exist");
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1392
                } else if (!Files.isDirectory(dir)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1393
                    throw new IOException(dir + ": not a directory");
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1394
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1395
                update(dir);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1396
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1397
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1398
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1399
        private void update(Path p) {
37944
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 37848
diff changeset
  1400
            if (!isCurrentPlatform(p) && !Files.exists(p.resolve("jrt-fs.jar")) && !Files.exists(systemJavaHome.resolve("modules")))
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1401
                throw new IllegalArgumentException(p.toString());
37944
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 37848
diff changeset
  1402
            systemJavaHome = p;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1403
            modules = null;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1404
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1405
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1406
        private boolean isCurrentPlatform(Path p) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1407
            try {
37944
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 37848
diff changeset
  1408
                return Files.isSameFile(p, Locations.javaHome);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1409
            } catch (IOException ex) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1410
                throw new IllegalArgumentException(p.toString(), ex);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1411
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1412
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1413
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1414
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1415
        Location getModuleLocation(String name) throws IOException {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1416
            initSystemModules();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1417
            return systemModules.get(name);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1418
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1419
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1420
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1421
        Iterable<Set<Location>> listModuleLocations() throws IOException {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1422
            initSystemModules();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1423
            Set<Location> locns = new LinkedHashSet<>();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1424
            for (Location l: systemModules.values())
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1425
                locns.add(l);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1426
            return Collections.singleton(locns);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1427
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1428
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1429
        private void initSystemModules() throws IOException {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1430
            if (systemModules != null) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1431
                return;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1432
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1433
37944
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 37848
diff changeset
  1434
            if (systemJavaHome == null) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1435
                systemModules = Collections.emptyMap();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1436
                return;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1437
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1438
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1439
            if (modules == null) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1440
                try {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1441
                    URI jrtURI = URI.create("jrt:/");
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1442
                    FileSystem jrtfs;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1443
37944
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 37848
diff changeset
  1444
                    if (isCurrentPlatform(systemJavaHome)) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1445
                        jrtfs = FileSystems.getFileSystem(jrtURI);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1446
                    } else {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1447
                        try {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1448
                            Map<String, String> attrMap =
37944
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 37848
diff changeset
  1449
                                    Collections.singletonMap("java.home", systemJavaHome.toString());
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1450
                            jrtfs = FileSystems.newFileSystem(jrtURI, attrMap);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1451
                        } catch (ProviderNotFoundException ex) {
37944
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 37848
diff changeset
  1452
                            URL javaHomeURL = systemJavaHome.resolve("jrt-fs.jar").toUri().toURL();
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1453
                            ClassLoader currentLoader = Locations.class.getClassLoader();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1454
                            URLClassLoader fsLoader =
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1455
                                    new URLClassLoader(new URL[] {javaHomeURL}, currentLoader);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1456
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1457
                            jrtfs = FileSystems.newFileSystem(jrtURI, Collections.emptyMap(), fsLoader);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1458
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1459
                            closeables.add(fsLoader);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1460
                        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1461
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1462
                        closeables.add(jrtfs);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1463
                    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1464
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1465
                    modules = jrtfs.getPath("/modules");
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1466
                } catch (FileSystemNotFoundException | ProviderNotFoundException e) {
37944
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 37848
diff changeset
  1467
                    modules = systemJavaHome.resolve("modules");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1468
                    if (!Files.exists(modules))
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1469
                        throw new IOException("can't find system classes", e);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1470
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1471
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1472
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1473
            systemModules = new LinkedHashMap<>();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1474
            try (DirectoryStream<Path> stream = Files.newDirectoryStream(modules, Files::isDirectory)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1475
                for (Path entry : stream) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1476
                    String moduleName = entry.getFileName().toString();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1477
                    String name = location.getName() + "[" + moduleName + "]";
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1478
                    ModuleLocationHandler h = new ModuleLocationHandler(name, moduleName,
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1479
                            Collections.singleton(entry), false, true);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1480
                    systemModules.put(moduleName, h);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1481
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1482
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1483
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1484
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1485
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
  1486
    Map<Location, LocationHandler> handlersForLocation;
11314
b612aaca08d0 7120736: refactor javac option handling
jjg
parents: 10819
diff changeset
  1487
    Map<Option, LocationHandler> handlersForOption;
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
  1488
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
  1489
    void initHandlers() {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22153
diff changeset
  1490
        handlersForLocation = new HashMap<>();
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22153
diff changeset
  1491
        handlersForOption = new EnumMap<>(Option.class);
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
  1492
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1493
        BasicLocationHandler[] handlers = {
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
  1494
            new BootClassPathLocationHandler(),
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
  1495
            new ClassPathLocationHandler(),
11314
b612aaca08d0 7120736: refactor javac option handling
jjg
parents: 10819
diff changeset
  1496
            new SimpleLocationHandler(StandardLocation.SOURCE_PATH, Option.SOURCEPATH),
b612aaca08d0 7120736: refactor javac option handling
jjg
parents: 10819
diff changeset
  1497
            new SimpleLocationHandler(StandardLocation.ANNOTATION_PROCESSOR_PATH, Option.PROCESSORPATH),
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1498
            new SimpleLocationHandler(StandardLocation.ANNOTATION_PROCESSOR_MODULE_PATH, Option.PROCESSORMODULEPATH),
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1499
            new OutputLocationHandler(StandardLocation.CLASS_OUTPUT, Option.D),
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1500
            new OutputLocationHandler(StandardLocation.SOURCE_OUTPUT, Option.S),
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1501
            new OutputLocationHandler(StandardLocation.NATIVE_HEADER_OUTPUT, Option.H),
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1502
            new ModuleSourcePathLocationHandler(),
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1503
            // TODO: should UPGRADE_MODULE_PATH be merged with SYSTEM_MODULES?
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1504
            new ModulePathLocationHandler(StandardLocation.UPGRADE_MODULE_PATH, Option.UPGRADEMODULEPATH),
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1505
            new ModulePathLocationHandler(StandardLocation.MODULE_PATH, Option.MODULEPATH, Option.MP),
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1506
            new SystemModulesLocationHandler(),
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
  1507
        };
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1508
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1509
        for (BasicLocationHandler h : handlers) {
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
  1510
            handlersForLocation.put(h.location, h);
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
  1511
            for (Option o : h.options) {
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
  1512
                handlersForOption.put(o, h);
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
  1513
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1514
        }
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
  1515
    }
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
  1516
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1517
    private Map<String, SearchPath> patchMap;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1518
29780
8f8e54a1fa20 8076420: Consolidate javac file handling in javac.file package
jjg
parents: 29291
diff changeset
  1519
    boolean handleOption(Option option, String value) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1520
        switch (option) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1521
            case XPATCH:
37848
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36526
diff changeset
  1522
                Map<String, SearchPath> map = new LinkedHashMap<>();
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36526
diff changeset
  1523
                int eq = value.indexOf('=');
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36526
diff changeset
  1524
                if (eq > 0) {
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36526
diff changeset
  1525
                    String mName = value.substring(0, eq);
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36526
diff changeset
  1526
                    SearchPath mPatchPath = new SearchPath()
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36526
diff changeset
  1527
                            .addFiles(value.substring(eq + 1));
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36526
diff changeset
  1528
                    boolean ok = true;
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36526
diff changeset
  1529
                    for (Path p: mPatchPath) {
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36526
diff changeset
  1530
                        Path mi = p.resolve("module-info.class");
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36526
diff changeset
  1531
                        if (Files.exists(mi)) {
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36526
diff changeset
  1532
                            log.error(Errors.LocnModuleInfoNotAllowedOnPatchPath(mi));
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36526
diff changeset
  1533
                            ok = false;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1534
                        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1535
                    }
37848
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36526
diff changeset
  1536
                    if (ok && !mPatchPath.isEmpty()) {
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36526
diff changeset
  1537
                        map.computeIfAbsent(mName, (_x) -> new SearchPath())
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36526
diff changeset
  1538
                                .addAll(mPatchPath);
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36526
diff changeset
  1539
                    }
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1540
                } else {
37848
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36526
diff changeset
  1541
                    log.error(Errors.LocnInvalidArgForXpatch(value));
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1542
                }
37848
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36526
diff changeset
  1543
                patchMap = map;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1544
                return true;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1545
            default:
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1546
                LocationHandler h = handlersForOption.get(option);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1547
                return (h == null ? false : h.handleOption(option, value));
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1548
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1549
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1550
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1551
    boolean hasLocation(Location location) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1552
        LocationHandler h = getHandler(location);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1553
        return (h == null ? false : h.isSet());
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
  1554
    }
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
  1555
27852
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
  1556
    Collection<Path> getLocation(Location location) {
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
  1557
        LocationHandler h = getHandler(location);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1558
        return (h == null ? null : h.getPaths());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1559
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1560
27852
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
  1561
    Path getOutputLocation(Location location) {
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
  1562
        if (!location.isOutputLocation()) {
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
  1563
            throw new IllegalArgumentException();
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
  1564
        }
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
  1565
        LocationHandler h = getHandler(location);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
  1566
        return ((OutputLocationHandler) h).outputDir;
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
  1567
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1568
27852
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
  1569
    void setLocation(Location location, Iterable<? extends Path> files) throws IOException {
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
  1570
        LocationHandler h = getHandler(location);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
  1571
        if (h == null) {
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
  1572
            if (location.isOutputLocation()) {
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
  1573
                h = new OutputLocationHandler(location);
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
  1574
            } else {
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
  1575
                h = new SimpleLocationHandler(location);
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
  1576
            }
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
  1577
            handlersForLocation.put(location, h);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
  1578
        }
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1579
        h.setPaths(files);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1580
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1581
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1582
    Location getModuleLocation(Location location, String name) throws IOException {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1583
        LocationHandler h = getHandler(location);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1584
        return (h == null ? null : h.getModuleLocation(name));
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1585
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1586
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1587
    Location getModuleLocation(Location location, Path dir) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1588
        LocationHandler h = getHandler(location);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1589
        return (h == null ? null : h.getModuleLocation(dir));
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1590
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1591
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1592
    String inferModuleName(Location location) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1593
        LocationHandler h = getHandler(location);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1594
        return (h == null ? null : h.inferModuleName());
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1595
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1596
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1597
    Iterable<Set<Location>> listModuleLocations(Location location) throws IOException {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1598
        LocationHandler h = getHandler(location);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1599
        return (h == null ? null : h.listModuleLocations());
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
  1600
    }
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
  1601
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
  1602
    protected LocationHandler getHandler(Location location) {
29291
076c277565f7 8073550: java* tools: replace obj.getClass hacks with Assert.checkNonNull or Objects.requireNonNull
mcimadamore
parents: 29053
diff changeset
  1603
        Objects.requireNonNull(location);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1604
        return (location instanceof LocationHandler)
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1605
                ? (LocationHandler) location
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1606
                : handlersForLocation.get(location);
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
  1607
    }
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
  1608
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
  1609
    /**
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
  1610
     * Is this the name of an archive file?
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
  1611
     */
27852
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
  1612
    private boolean isArchive(Path file) {
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
  1613
        String n = StringUtils.toLowerCase(file.getFileName().toString());
1208
5072b0dd3d52 6743107: clean up use of static caches in file manager
jjg
parents: 735
diff changeset
  1614
        return fsInfo.isFile(file)
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
  1615
                && (n.endsWith(".jar") || n.endsWith(".zip"));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1616
    }
4937
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
  1617
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1618
    static Path normalize(Path p) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1619
        try {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1620
            return p.toRealPath();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1621
        } catch (IOException e) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1622
            return p.toAbsolutePath().normalize();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1623
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1624
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1625
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1626
}