src/jdk.compiler/share/classes/com/sun/tools/javac/file/Locations.java
author jjg
Thu, 04 Jan 2018 10:14:50 -0800
changeset 48433 04d8d293e458
parent 47703 dbfac941197a
child 48721 ef3557eb4306
permissions -rw-r--r--
8194141: Remove JDK9Wrappers Reviewed-by: erikj, alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
48433
04d8d293e458 8194141: Remove JDK9Wrappers
jjg
parents: 47703
diff changeset
     2
 * Copyright (c) 2003, 2018, 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;
45682
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44822
diff changeset
    32
import java.io.InputStream;
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
    33
import java.io.UncheckedIOException;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
    34
import java.net.URI;
4937
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
    35
import java.net.URL;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
    36
import java.net.URLClassLoader;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
    37
import java.nio.file.DirectoryIteratorException;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
    38
import java.nio.file.DirectoryStream;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
    39
import java.nio.file.FileSystem;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
    40
import java.nio.file.FileSystemNotFoundException;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
    41
import java.nio.file.FileSystems;
27852
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
    42
import java.nio.file.Files;
41861
8c58faf4f03b 8132562: javac fails with CLASSPATH with double-quotes as an environment variable
vromero
parents: 41637
diff changeset
    43
import java.nio.file.InvalidPathException;
27852
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
    44
import java.nio.file.Path;
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
    45
import java.nio.file.Paths;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
    46
import java.nio.file.ProviderNotFoundException;
43574
042e694725f7 8166675: Latent bug in jar file handling during module path processing.
jjg
parents: 43267
diff changeset
    47
import java.nio.file.spi.FileSystemProvider;
27852
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
    48
import java.util.ArrayList;
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
    49
import java.util.Arrays;
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
    50
import java.util.Collection;
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
    51
import java.util.Collections;
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
    52
import java.util.EnumMap;
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
    53
import java.util.EnumSet;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
import java.util.HashMap;
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
import java.util.HashSet;
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
    56
import java.util.Iterator;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
    57
import java.util.LinkedHashMap;
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
    58
import java.util.LinkedHashSet;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
    59
import java.util.List;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
import java.util.Map;
29291
076c277565f7 8073550: java* tools: replace obj.getClass hacks with Assert.checkNonNull or Objects.requireNonNull
mcimadamore
parents: 29053
diff changeset
    61
import java.util.Objects;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
    62
import java.util.NoSuchElementException;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
import java.util.Set;
44063
5f0cf4126949 8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents: 44021
diff changeset
    64
import java.util.function.Predicate;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
    65
import java.util.regex.Matcher;
27852
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
    66
import java.util.regex.Pattern;
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
    67
import java.util.stream.Collectors;
27852
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
    68
import java.util.stream.Stream;
45682
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44822
diff changeset
    69
import java.util.jar.Attributes;
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44822
diff changeset
    70
import java.util.jar.Manifest;
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
    71
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
    72
import javax.lang.model.SourceVersion;
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
    73
import javax.tools.JavaFileManager;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
import javax.tools.JavaFileManager.Location;
41861
8c58faf4f03b 8132562: javac fails with CLASSPATH with double-quotes as an environment variable
vromero
parents: 41637
diff changeset
    75
import javax.tools.JavaFileObject;
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
    76
import javax.tools.StandardJavaFileManager;
37944
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 37848
diff changeset
    77
import javax.tools.StandardJavaFileManager.PathFactory;
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
    78
import javax.tools.StandardLocation;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
48433
04d8d293e458 8194141: Remove JDK9Wrappers
jjg
parents: 47703
diff changeset
    80
import jdk.internal.jmod.JmodFile;
04d8d293e458 8194141: Remove JDK9Wrappers
jjg
parents: 47703
diff changeset
    81
731
1dd22bdb9ca5 6714364: refactor javac File handling code into new javac.file package
jjg
parents: 171
diff changeset
    82
import com.sun.tools.javac.code.Lint;
42837
03ee805ba348 8169005: tools/javac/T8132562/ClassPathWithDoubleQuotesTest.java fails after fix to JDK-8132562
vromero
parents: 42827
diff changeset
    83
import com.sun.tools.javac.code.Lint.LintCategory;
11314
b612aaca08d0 7120736: refactor javac option handling
jjg
parents: 10819
diff changeset
    84
import com.sun.tools.javac.main.Option;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
    85
import com.sun.tools.javac.resources.CompilerProperties.Errors;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
    86
import com.sun.tools.javac.resources.CompilerProperties.Warnings;
37848
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36526
diff changeset
    87
import com.sun.tools.javac.util.DefinedBy;
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36526
diff changeset
    88
import com.sun.tools.javac.util.DefinedBy.Api;
1486
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
    89
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
    90
import com.sun.tools.javac.util.Log;
41254
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 41155
diff changeset
    91
import com.sun.tools.javac.jvm.ModuleNameReader;
47363
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
    92
import com.sun.tools.javac.util.Iterators;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
    93
import com.sun.tools.javac.util.Pair;
22153
f9f06fcca59d 8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents: 14360
diff changeset
    94
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
    95
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
    96
import static javax.tools.StandardLocation.PLATFORM_CLASS_PATH;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 40302
diff changeset
    98
import static com.sun.tools.javac.main.Option.BOOT_CLASS_PATH;
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
    99
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
   100
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
   101
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
   102
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
   103
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
   104
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
   105
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
   106
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   107
/**
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   108
 * 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
   109
 * 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
   110
 * path (in {@code Collection<String>} form).
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
 *
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   112
 * <p>
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   113
 * <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
   114
 * 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
   115
 * notice.</b>
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
 */
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   117
public class Locations {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   119
    /**
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   120
     * The log to use for warning output
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   121
     */
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
    private Log log;
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   124
    /**
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   125
     * Access to (possibly cached) file info
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   126
     */
1208
5072b0dd3d52 6743107: clean up use of static caches in file manager
jjg
parents: 735
diff changeset
   127
    private FSInfo fsInfo;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   129
    /**
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   130
     * Whether to warn about non-existent path elements
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   131
     */
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   132
    private boolean warn;
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   133
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   134
    private ModuleNameReader moduleNameReader;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   135
37944
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 37848
diff changeset
   136
    private PathFactory pathFactory = Paths::get;
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 37848
diff changeset
   137
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 37848
diff changeset
   138
    static final Path javaHome = FileSystems.getDefault().getPath(System.getProperty("java.home"));
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   139
    static final Path thisSystemModules = javaHome.resolve("lib").resolve("modules");
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   140
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   141
    Map<Path, FileSystem> fileSystems = new LinkedHashMap<>();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   142
    List<Closeable> closeables = new ArrayList<>();
41155
93dad90c22c1 8156568: Update javac to support compiling against a modular JAR that is a multi-release JAR
sadayapalam
parents: 40762
diff changeset
   143
    private Map<String,String> fsEnv = Collections.emptyMap();
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   144
29780
8f8e54a1fa20 8076420: Consolidate javac file handling in javac.file package
jjg
parents: 29291
diff changeset
   145
    Locations() {
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   146
        initHandlers();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
37944
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 37848
diff changeset
   149
    Path getPath(String first, String... more) {
41861
8c58faf4f03b 8132562: javac fails with CLASSPATH with double-quotes as an environment variable
vromero
parents: 41637
diff changeset
   150
        try {
8c58faf4f03b 8132562: javac fails with CLASSPATH with double-quotes as an environment variable
vromero
parents: 41637
diff changeset
   151
            return pathFactory.getPath(first, more);
8c58faf4f03b 8132562: javac fails with CLASSPATH with double-quotes as an environment variable
vromero
parents: 41637
diff changeset
   152
        } catch (InvalidPathException ipe) {
8c58faf4f03b 8132562: javac fails with CLASSPATH with double-quotes as an environment variable
vromero
parents: 41637
diff changeset
   153
            throw new IllegalArgumentException(ipe);
8c58faf4f03b 8132562: javac fails with CLASSPATH with double-quotes as an environment variable
vromero
parents: 41637
diff changeset
   154
        }
37944
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 37848
diff changeset
   155
    }
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 37848
diff changeset
   156
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   157
    public void close() throws IOException {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   158
        ListBuffer<IOException> list = new ListBuffer<>();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   159
        closeables.forEach(closeable -> {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   160
            try {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   161
                closeable.close();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   162
            } catch (IOException ex) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   163
                list.add(ex);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   164
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   165
        });
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   166
        if (list.nonEmpty()) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   167
            IOException ex = new IOException();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   168
            for (IOException e: list)
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   169
                ex.addSuppressed(e);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   170
            throw ex;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   171
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   172
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   173
41637
7b24b4c32ee6 8145471: javac changes for enhanced deprecation
jjg
parents: 41440
diff changeset
   174
    void update(Log log, boolean warn, FSInfo fsInfo) {
10813
95b39a692cd0 7101146: Paths should more directly managed by BaseFileManager
jjg
parents: 8424
diff changeset
   175
        this.log = log;
41637
7b24b4c32ee6 8145471: javac changes for enhanced deprecation
jjg
parents: 41440
diff changeset
   176
        this.warn = warn;
10813
95b39a692cd0 7101146: Paths should more directly managed by BaseFileManager
jjg
parents: 8424
diff changeset
   177
        this.fsInfo = fsInfo;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
37944
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 37848
diff changeset
   180
    void setPathFactory(PathFactory f) {
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 37848
diff changeset
   181
        pathFactory = f;
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 37848
diff changeset
   182
    }
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 37848
diff changeset
   183
29780
8f8e54a1fa20 8076420: Consolidate javac file handling in javac.file package
jjg
parents: 29291
diff changeset
   184
    boolean isDefaultBootClassPath() {
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   185
        BootClassPathLocationHandler h
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   186
                = (BootClassPathLocationHandler) getHandler(PLATFORM_CLASS_PATH);
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   187
        return h.isDefault();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
1486
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   190
    /**
27852
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
   191
     * 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
   192
     *
27852
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
   193
     * @param searchPath The search path to be split
1486
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   194
     * @return The elements of the path
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   195
     */
37944
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 37848
diff changeset
   196
    private Iterable<Path> getPathEntries(String searchPath) {
27852
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
   197
        return getPathEntries(searchPath, null);
1486
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   198
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
1486
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   200
    /**
27852
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
   201
     * 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
   202
     * 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
   203
     * emptyPathDefault.
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   204
     *
27852
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
   205
     * @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
   206
     * @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
   207
     * empty path elements
1486
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   208
     * @return The elements of the path
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   209
     */
37944
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 37848
diff changeset
   210
    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
   211
        ListBuffer<Path> entries = new ListBuffer<>();
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
   212
        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
   213
            if (s.isEmpty()) {
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
   214
                if (emptyPathDefault != null) {
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
   215
                    entries.add(emptyPathDefault);
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
   216
                }
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
   217
            } else {
42837
03ee805ba348 8169005: tools/javac/T8132562/ClassPathWithDoubleQuotesTest.java fails after fix to JDK-8132562
vromero
parents: 42827
diff changeset
   218
                try {
03ee805ba348 8169005: tools/javac/T8132562/ClassPathWithDoubleQuotesTest.java fails after fix to JDK-8132562
vromero
parents: 42827
diff changeset
   219
                    entries.add(getPath(s));
03ee805ba348 8169005: tools/javac/T8132562/ClassPathWithDoubleQuotesTest.java fails after fix to JDK-8132562
vromero
parents: 42827
diff changeset
   220
                } catch (IllegalArgumentException e) {
03ee805ba348 8169005: tools/javac/T8132562/ClassPathWithDoubleQuotesTest.java fails after fix to JDK-8132562
vromero
parents: 42827
diff changeset
   221
                    if (warn) {
45504
ea7475564d07 8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents: 44822
diff changeset
   222
                        log.warning(LintCategory.PATH, Warnings.InvalidPath(s));
42837
03ee805ba348 8169005: tools/javac/T8132562/ClassPathWithDoubleQuotesTest.java fails after fix to JDK-8132562
vromero
parents: 42827
diff changeset
   223
                    }
03ee805ba348 8169005: tools/javac/T8132562/ClassPathWithDoubleQuotesTest.java fails after fix to JDK-8132562
vromero
parents: 42827
diff changeset
   224
                }
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   225
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
        }
1486
a7d1338ca96e 6759996: ignore empty entries on paths
jjg
parents: 1208
diff changeset
   227
        return entries;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   228
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
41155
93dad90c22c1 8156568: Update javac to support compiling against a modular JAR that is a multi-release JAR
sadayapalam
parents: 40762
diff changeset
   230
    public void setMultiReleaseValue(String multiReleaseValue) {
93dad90c22c1 8156568: Update javac to support compiling against a modular JAR that is a multi-release JAR
sadayapalam
parents: 40762
diff changeset
   231
        fsEnv = Collections.singletonMap("multi-release", multiReleaseValue);
93dad90c22c1 8156568: Update javac to support compiling against a modular JAR that is a multi-release JAR
sadayapalam
parents: 40762
diff changeset
   232
    }
93dad90c22c1 8156568: Update javac to support compiling against a modular JAR that is a multi-release JAR
sadayapalam
parents: 40762
diff changeset
   233
44822
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
   234
    private boolean contains(Collection<Path> searchPath, Path file) throws IOException {
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
   235
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
   236
        if (searchPath == null) {
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
   237
            return false;
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
   238
        }
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
   239
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
   240
        Path enclosingJar = null;
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
   241
        if (file.getFileSystem().provider() == fsInfo.getJarFSProvider()) {
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
   242
            URI uri = file.toUri();
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
   243
            if (uri.getScheme().equals("jar")) {
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
   244
                String ssp = uri.getSchemeSpecificPart();
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
   245
                int sep = ssp.lastIndexOf("!");
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
   246
                if (ssp.startsWith("file:") && sep > 0) {
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
   247
                    enclosingJar = Paths.get(URI.create(ssp.substring(0, sep)));
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
   248
                }
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
   249
            }
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
   250
        }
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
   251
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
   252
        Path nf = normalize(file);
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
   253
        for (Path p : searchPath) {
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
   254
            Path np = normalize(p);
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
   255
            if (np.getFileSystem() == nf.getFileSystem()
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
   256
                    && Files.isDirectory(np)
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
   257
                    && nf.startsWith(np)) {
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
   258
                return true;
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
   259
            }
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
   260
            if (enclosingJar != null
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
   261
                    && Files.isSameFile(enclosingJar, np)) {
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
   262
                return true;
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
   263
            }
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
   264
        }
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
   265
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
   266
        return false;
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
   267
    }
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
   268
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   269
    /**
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   270
     * 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
   271
     * can be expanded.
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   272
     */
27852
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
   273
    private class SearchPath extends LinkedHashSet<Path> {
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   274
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   275
        private static final long serialVersionUID = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   276
06bc494ca11e Initial load
duke
parents:
diff changeset
   277
        private boolean expandJarClassPaths = false;
27852
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
   278
        private final Set<Path> canonicalValues = new HashSet<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
27118
3c8314271af7 8060043: Rename Locations.Path to Locations.SearchPath
jjg
parents: 25874
diff changeset
   280
        public SearchPath expandJarClassPaths(boolean x) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   281
            expandJarClassPaths = x;
06bc494ca11e Initial load
duke
parents:
diff changeset
   282
            return this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   283
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   284
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   285
        /**
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   286
         * 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
   287
         */
27852
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
   288
        private Path emptyPathDefault = null;
10
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 emptyPathDefault(Path x) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   291
            emptyPathDefault = x;
06bc494ca11e Initial load
duke
parents:
diff changeset
   292
            return this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   293
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   294
27118
3c8314271af7 8060043: Rename Locations.Path to Locations.SearchPath
jjg
parents: 25874
diff changeset
   295
        public SearchPath addDirectories(String dirs, boolean warn) {
8424
5e31b2eb5aa3 6485027: javac incorrectly handles relative paths in manifest classpath
jjg
parents: 8034
diff changeset
   296
            boolean prev = expandJarClassPaths;
5e31b2eb5aa3 6485027: javac incorrectly handles relative paths in manifest classpath
jjg
parents: 8034
diff changeset
   297
            expandJarClassPaths = true;
5e31b2eb5aa3 6485027: javac incorrectly handles relative paths in manifest classpath
jjg
parents: 8034
diff changeset
   298
            try {
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   299
                if (dirs != null) {
27852
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
   300
                    for (Path dir : getPathEntries(dirs)) {
8424
5e31b2eb5aa3 6485027: javac incorrectly handles relative paths in manifest classpath
jjg
parents: 8034
diff changeset
   301
                        addDirectory(dir, warn);
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   302
                    }
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   303
                }
8424
5e31b2eb5aa3 6485027: javac incorrectly handles relative paths in manifest classpath
jjg
parents: 8034
diff changeset
   304
                return this;
5e31b2eb5aa3 6485027: javac incorrectly handles relative paths in manifest classpath
jjg
parents: 8034
diff changeset
   305
            } finally {
5e31b2eb5aa3 6485027: javac incorrectly handles relative paths in manifest classpath
jjg
parents: 8034
diff changeset
   306
                expandJarClassPaths = prev;
5e31b2eb5aa3 6485027: javac incorrectly handles relative paths in manifest classpath
jjg
parents: 8034
diff changeset
   307
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   308
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   309
27118
3c8314271af7 8060043: Rename Locations.Path to Locations.SearchPath
jjg
parents: 25874
diff changeset
   310
        public SearchPath addDirectories(String dirs) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   311
            return addDirectories(dirs, warn);
06bc494ca11e Initial load
duke
parents:
diff changeset
   312
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   313
27852
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
   314
        private void addDirectory(Path dir, boolean warn) {
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
   315
            if (!Files.isDirectory(dir)) {
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   316
                if (warn) {
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   317
                    log.warning(Lint.LintCategory.PATH,
45504
ea7475564d07 8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents: 44822
diff changeset
   318
                                Warnings.DirPathElementNotFound(dir));
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   319
                }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   320
                return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   321
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   322
27852
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
   323
            try (Stream<Path> s = Files.list(dir)) {
42827
36468b5fa7f4 8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents: 42814
diff changeset
   324
                s.filter(Locations.this::isArchive)
27852
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
   325
                        .forEach(dirEntry -> addFile(dirEntry, warn));
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
   326
            } catch (IOException ignore) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   327
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   328
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   329
27118
3c8314271af7 8060043: Rename Locations.Path to Locations.SearchPath
jjg
parents: 25874
diff changeset
   330
        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
   331
            if (files != null) {
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   332
                addFiles(getPathEntries(files, emptyPathDefault), warn);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   333
            }
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   334
            return this;
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   335
        }
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   336
27118
3c8314271af7 8060043: Rename Locations.Path to Locations.SearchPath
jjg
parents: 25874
diff changeset
   337
        public SearchPath addFiles(String files) {
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   338
            return addFiles(files, warn);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   339
        }
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   340
27852
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
   341
        public SearchPath addFiles(Iterable<? extends Path> files, boolean warn) {
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   342
            if (files != null) {
27852
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
   343
                for (Path file : files) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   344
                    addFile(file, warn);
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   345
                }
7335
8b390fd27190 6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents: 6151
diff changeset
   346
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   347
            return this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   348
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   349
27852
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
   350
        public SearchPath addFiles(Iterable<? extends Path> files) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   351
            return addFiles(files, warn);
06bc494ca11e Initial load
duke
parents:
diff changeset
   352
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   353
27852
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
   354
        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
   355
            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
   356
                // discard duplicates
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   357
                return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   358
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   359
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   360
            if (!fsInfo.exists(file)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   361
                /* No such file or directory exists */
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   362
                if (warn) {
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   363
                    log.warning(Lint.LintCategory.PATH,
45504
ea7475564d07 8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents: 44822
diff changeset
   364
                                Warnings.PathElementNotFound(file));
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   365
                }
7839
a1ca72d05b20 6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents: 7336
diff changeset
   366
                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
   367
                return;
a1ca72d05b20 6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents: 7336
diff changeset
   368
            }
a1ca72d05b20 6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents: 7336
diff changeset
   369
27852
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
   370
            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
   371
            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
   372
                /* 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
   373
                return;
a1ca72d05b20 6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents: 7336
diff changeset
   374
            }
a1ca72d05b20 6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents: 7336
diff changeset
   375
a1ca72d05b20 6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents: 7336
diff changeset
   376
            if (fsInfo.isFile(file)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   377
                /* File is an ordinary file. */
40513
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents: 40308
diff changeset
   378
                if (   !file.getFileName().toString().endsWith(".jmod")
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents: 40308
diff changeset
   379
                    && !file.endsWith("modules")) {
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents: 40308
diff changeset
   380
                    if (!isArchive(file)) {
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents: 40308
diff changeset
   381
                        /* Not a recognized extension; open it to see if
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents: 40308
diff changeset
   382
                         it looks like a valid zip file. */
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents: 40308
diff changeset
   383
                        try {
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents: 40308
diff changeset
   384
                            FileSystems.newFileSystem(file, null).close();
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents: 40308
diff changeset
   385
                            if (warn) {
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents: 40308
diff changeset
   386
                                log.warning(Lint.LintCategory.PATH,
45504
ea7475564d07 8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents: 44822
diff changeset
   387
                                            Warnings.UnexpectedArchiveFile(file));
40513
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents: 40308
diff changeset
   388
                            }
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents: 40308
diff changeset
   389
                        } catch (IOException | ProviderNotFoundException e) {
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents: 40308
diff changeset
   390
                            // FIXME: include e.getLocalizedMessage in warning
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents: 40308
diff changeset
   391
                            if (warn) {
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents: 40308
diff changeset
   392
                                log.warning(Lint.LintCategory.PATH,
45504
ea7475564d07 8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents: 44822
diff changeset
   393
                                            Warnings.InvalidArchiveFile(file));
40513
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents: 40308
diff changeset
   394
                            }
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents: 40308
diff changeset
   395
                            return;
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   396
                        }
40513
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents: 40308
diff changeset
   397
                    } else {
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents: 40308
diff changeset
   398
                        if (fsInfo.getJarFSProvider() == null) {
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents: 40308
diff changeset
   399
                            log.error(Errors.NoZipfsForArchive(file));
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents: 40308
diff changeset
   400
                            return ;
6151
dd513881e71d 6957438: improve code for generating warning messages containing option names
jjg
parents: 5847
diff changeset
   401
                        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   402
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   403
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   404
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   405
06bc494ca11e Initial load
duke
parents:
diff changeset
   406
            /* 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
   407
             conforming to archive naming convention */
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   408
            super.add(file);
1208
5072b0dd3d52 6743107: clean up use of static caches in file manager
jjg
parents: 735
diff changeset
   409
            canonicalValues.add(canonFile);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   410
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   411
            if (expandJarClassPaths && fsInfo.isFile(file) && !file.endsWith("modules")) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   412
                addJarClassPath(file, warn);
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   413
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   414
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   415
06bc494ca11e Initial load
duke
parents:
diff changeset
   416
        // Adds referenced classpath elements from a jar's Class-Path
06bc494ca11e Initial load
duke
parents:
diff changeset
   417
        // Manifest entry.  In some future release, we may want to
06bc494ca11e Initial load
duke
parents:
diff changeset
   418
        // update this code to recognize URLs rather than simple
06bc494ca11e Initial load
duke
parents:
diff changeset
   419
        // 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
   420
        private void addJarClassPath(Path jarFile, boolean warn) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   421
            try {
27852
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
   422
                for (Path f : fsInfo.getJarClassPath(jarFile)) {
1208
5072b0dd3d52 6743107: clean up use of static caches in file manager
jjg
parents: 735
diff changeset
   423
                    addFile(f, warn);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   424
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   425
            } catch (IOException e) {
45504
ea7475564d07 8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents: 44822
diff changeset
   426
                log.error(Errors.ErrorReadingFile(jarFile, JavacFileManager.getMessage(e)));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   427
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   428
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   429
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   430
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   431
    /**
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   432
     * Base class for handling support for the representation of Locations.
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   433
     *
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   434
     * Locations are (by design) opaque handles that can easily be implemented
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   435
     * by enums like StandardLocation. Within JavacFileManager, each Location
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   436
     * has an associated LocationHandler, which provides much of the appropriate
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   437
     * functionality for the corresponding Location.
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   438
     *
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   439
     * @see #initHandlers
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   440
     * @see #getHandler
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   441
     */
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   442
    protected static abstract class LocationHandler {
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   443
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   444
        /**
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   445
         * @see JavaFileManager#handleOption
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   446
         */
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   447
        abstract boolean handleOption(Option option, String value);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   448
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   449
        /**
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   450
         * @see StandardJavaFileManager#hasLocation
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   451
         */
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   452
        boolean isSet() {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   453
            return (getPaths() != null);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   454
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   455
47702
cf8310446245 8139607: -release option forces StandardJavaFileManager
jlahoda
parents: 47363
diff changeset
   456
        abstract boolean isExplicit();
cf8310446245 8139607: -release option forces StandardJavaFileManager
jlahoda
parents: 47363
diff changeset
   457
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   458
        /**
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   459
         * @see StandardJavaFileManager#getLocation
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   460
         */
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   461
        abstract Collection<Path> getPaths();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   462
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   463
        /**
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   464
         * @see StandardJavaFileManager#setLocation
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   465
         */
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   466
        abstract void setPaths(Iterable<? extends Path> paths) throws IOException;
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   467
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   468
        /**
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   469
         * @see StandardJavaFileManager#setLocationForModule
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   470
         */
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   471
        abstract void setPathsForModule(String moduleName, Iterable<? extends Path> paths)
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   472
                throws IOException;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   473
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   474
        /**
42261
bb52b5514ad5 8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents: 41861
diff changeset
   475
         * @see JavaFileManager#getLocationForModule(Location, String)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   476
         */
42261
bb52b5514ad5 8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents: 41861
diff changeset
   477
        Location getLocationForModule(String moduleName) throws IOException {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   478
            return null;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   479
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   480
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   481
        /**
42261
bb52b5514ad5 8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents: 41861
diff changeset
   482
         * @see JavaFileManager#getLocationForModule(Location, JavaFileObject, String)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   483
         */
44063
5f0cf4126949 8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents: 44021
diff changeset
   484
        Location getLocationForModule(Path file) throws IOException  {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   485
            return null;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   486
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   487
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   488
        /**
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   489
         * @see JavaFileManager#inferModuleName
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   490
         */
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   491
        String inferModuleName() {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   492
            return null;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   493
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   494
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   495
        /**
42261
bb52b5514ad5 8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents: 41861
diff changeset
   496
         * @see JavaFileManager#listLocationsForModules
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   497
         */
42261
bb52b5514ad5 8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents: 41861
diff changeset
   498
        Iterable<Set<Location>> listLocationsForModules() throws IOException {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   499
            return null;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   500
        }
44822
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
   501
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
   502
        /**
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
   503
         * @see JavaFileManager#contains
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
   504
         */
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
   505
        abstract boolean contains(Path file) throws IOException;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   506
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   507
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   508
    /**
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   509
     * A LocationHandler for a given Location, and associated set of options.
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   510
     */
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   511
    private static abstract class BasicLocationHandler extends LocationHandler {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   512
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   513
        final Location location;
11314
b612aaca08d0 7120736: refactor javac option handling
jjg
parents: 10819
diff changeset
   514
        final Set<Option> options;
7335
8b390fd27190 6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents: 6151
diff changeset
   515
47702
cf8310446245 8139607: -release option forces StandardJavaFileManager
jlahoda
parents: 47363
diff changeset
   516
        boolean explicit;
cf8310446245 8139607: -release option forces StandardJavaFileManager
jlahoda
parents: 47363
diff changeset
   517
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   518
        /**
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   519
         * 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
   520
         * option to the corresponding handler.
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   521
         *
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   522
         * @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
   523
         * @param options the options affecting this location
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   524
         * @see #initHandlers
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   525
         */
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   526
        protected BasicLocationHandler(Location location, Option... options) {
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   527
            this.location = location;
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   528
            this.options = options.length == 0
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   529
                    ? EnumSet.noneOf(Option.class)
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   530
                    : EnumSet.copyOf(Arrays.asList(options));
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   531
        }
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   532
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   533
        @Override
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   534
        void setPathsForModule(String moduleName, Iterable<? extends Path> files) throws IOException {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   535
            // should not happen: protected by check in JavacFileManager
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   536
            throw new UnsupportedOperationException("not supported for " + location);
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   537
        }
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   538
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   539
        protected Path checkSingletonDirectory(Iterable<? extends Path> paths) throws IOException {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   540
            Iterator<? extends Path> pathIter = paths.iterator();
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   541
            if (!pathIter.hasNext()) {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   542
                throw new IllegalArgumentException("empty path for directory");
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   543
            }
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   544
            Path path = pathIter.next();
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   545
            if (pathIter.hasNext()) {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   546
                throw new IllegalArgumentException("path too long for directory");
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   547
            }
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   548
            checkDirectory(path);
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   549
            return path;
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   550
        }
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   551
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   552
        protected Path checkDirectory(Path path) throws IOException {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   553
            Objects.requireNonNull(path);
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   554
            if (!Files.exists(path)) {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   555
                throw new FileNotFoundException(path + ": does not exist");
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   556
            }
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   557
            if (!Files.isDirectory(path)) {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   558
                throw new IOException(path + ": not a directory");
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   559
            }
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   560
            return path;
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   561
        }
47702
cf8310446245 8139607: -release option forces StandardJavaFileManager
jlahoda
parents: 47363
diff changeset
   562
cf8310446245 8139607: -release option forces StandardJavaFileManager
jlahoda
parents: 47363
diff changeset
   563
        @Override
cf8310446245 8139607: -release option forces StandardJavaFileManager
jlahoda
parents: 47363
diff changeset
   564
        boolean isExplicit() {
cf8310446245 8139607: -release option forces StandardJavaFileManager
jlahoda
parents: 47363
diff changeset
   565
            return explicit;
cf8310446245 8139607: -release option forces StandardJavaFileManager
jlahoda
parents: 47363
diff changeset
   566
        }
cf8310446245 8139607: -release option forces StandardJavaFileManager
jlahoda
parents: 47363
diff changeset
   567
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   568
    }
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   569
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   570
    /**
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   571
     * General purpose implementation for output locations, such as -d/CLASS_OUTPUT and
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   572
     * -s/SOURCE_OUTPUT. All options are treated as equivalent (i.e. aliases.)
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   573
     * The value is a single file, possibly null.
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   574
     */
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   575
    private class OutputLocationHandler extends BasicLocationHandler {
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   576
27852
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
   577
        private Path outputDir;
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   578
        private ModuleTable moduleTable;
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   579
11314
b612aaca08d0 7120736: refactor javac option handling
jjg
parents: 10819
diff changeset
   580
        OutputLocationHandler(Location location, Option... options) {
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   581
            super(location, options);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   582
        }
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   583
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   584
        @Override
11314
b612aaca08d0 7120736: refactor javac option handling
jjg
parents: 10819
diff changeset
   585
        boolean handleOption(Option option, String value) {
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   586
            if (!options.contains(option)) {
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   587
                return false;
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   588
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   589
47702
cf8310446245 8139607: -release option forces StandardJavaFileManager
jlahoda
parents: 47363
diff changeset
   590
            explicit = true;
cf8310446245 8139607: -release option forces StandardJavaFileManager
jlahoda
parents: 47363
diff changeset
   591
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   592
            // TODO: could/should validate outputDir exists and is a directory
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   593
            // need to decide how best to report issue for benefit of
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   594
            // direct API call on JavaFileManager.handleOption(specifies IAE)
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   595
            // vs. command line decoding.
37944
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 37848
diff changeset
   596
            outputDir = (value == null) ? null : getPath(value);
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   597
            return true;
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   598
        }
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   599
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   600
        @Override
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   601
        Collection<Path> getPaths() {
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   602
            return (outputDir == null) ? null : Collections.singleton(outputDir);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   603
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   604
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   605
        @Override
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   606
        void setPaths(Iterable<? extends Path> paths) throws IOException {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   607
            if (paths == null) {
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   608
                outputDir = null;
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   609
            } else {
47702
cf8310446245 8139607: -release option forces StandardJavaFileManager
jlahoda
parents: 47363
diff changeset
   610
                explicit = true;
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   611
                outputDir = checkSingletonDirectory(paths);
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   612
            }
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   613
            moduleTable = null;
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   614
            listed = false;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   615
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   616
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   617
        @Override
42261
bb52b5514ad5 8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents: 41861
diff changeset
   618
        Location getLocationForModule(String name) {
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   619
            if (moduleTable == null) {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   620
                moduleTable = new ModuleTable();
42814
058fc03646d9 8171005: Fix JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName) to work with location == CLASS_OUTPUT
jlahoda
parents: 42414
diff changeset
   621
            }
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   622
            ModuleLocationHandler l = moduleTable.get(name);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   623
            if (l == null) {
42814
058fc03646d9 8171005: Fix JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName) to work with location == CLASS_OUTPUT
jlahoda
parents: 42414
diff changeset
   624
                Path out = outputDir.resolve(name);
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   625
                l = new ModuleLocationHandler(this, location.getName() + "[" + name + "]",
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   626
                        name, Collections.singletonList(out), true);
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   627
                moduleTable.add(l);
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   628
            }
42814
058fc03646d9 8171005: Fix JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName) to work with location == CLASS_OUTPUT
jlahoda
parents: 42414
diff changeset
   629
            return l;
058fc03646d9 8171005: Fix JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName) to work with location == CLASS_OUTPUT
jlahoda
parents: 42414
diff changeset
   630
        }
058fc03646d9 8171005: Fix JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName) to work with location == CLASS_OUTPUT
jlahoda
parents: 42414
diff changeset
   631
058fc03646d9 8171005: Fix JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName) to work with location == CLASS_OUTPUT
jlahoda
parents: 42414
diff changeset
   632
        @Override
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   633
        void setPathsForModule(String name, Iterable<? extends Path> paths) throws IOException {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   634
            Path out = checkSingletonDirectory(paths);
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   635
            if (moduleTable == null) {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   636
                moduleTable = new ModuleTable();
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   637
            }
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   638
            ModuleLocationHandler l = moduleTable.get(name);
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   639
            if (l == null) {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   640
                l = new ModuleLocationHandler(this, location.getName() + "[" + name + "]",
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   641
                        name, Collections.singletonList(out), true);
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   642
                moduleTable.add(l);
47702
cf8310446245 8139607: -release option forces StandardJavaFileManager
jlahoda
parents: 47363
diff changeset
   643
            } else {
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   644
                l.searchPath = Collections.singletonList(out);
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   645
                moduleTable.updatePaths(l);
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   646
            }
47702
cf8310446245 8139607: -release option forces StandardJavaFileManager
jlahoda
parents: 47363
diff changeset
   647
            explicit = true;
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   648
        }
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   649
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   650
        @Override
44063
5f0cf4126949 8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents: 44021
diff changeset
   651
        Location getLocationForModule(Path file) {
5f0cf4126949 8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents: 44021
diff changeset
   652
            return (moduleTable == null) ? null : moduleTable.get(file);
42814
058fc03646d9 8171005: Fix JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName) to work with location == CLASS_OUTPUT
jlahoda
parents: 42414
diff changeset
   653
        }
058fc03646d9 8171005: Fix JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName) to work with location == CLASS_OUTPUT
jlahoda
parents: 42414
diff changeset
   654
058fc03646d9 8171005: Fix JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName) to work with location == CLASS_OUTPUT
jlahoda
parents: 42414
diff changeset
   655
        private boolean listed;
058fc03646d9 8171005: Fix JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName) to work with location == CLASS_OUTPUT
jlahoda
parents: 42414
diff changeset
   656
058fc03646d9 8171005: Fix JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName) to work with location == CLASS_OUTPUT
jlahoda
parents: 42414
diff changeset
   657
        @Override
058fc03646d9 8171005: Fix JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName) to work with location == CLASS_OUTPUT
jlahoda
parents: 42414
diff changeset
   658
        Iterable<Set<Location>> listLocationsForModules() throws IOException {
058fc03646d9 8171005: Fix JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName) to work with location == CLASS_OUTPUT
jlahoda
parents: 42414
diff changeset
   659
            if (!listed && outputDir != null) {
058fc03646d9 8171005: Fix JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName) to work with location == CLASS_OUTPUT
jlahoda
parents: 42414
diff changeset
   660
                try (DirectoryStream<Path> stream = Files.newDirectoryStream(outputDir)) {
058fc03646d9 8171005: Fix JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName) to work with location == CLASS_OUTPUT
jlahoda
parents: 42414
diff changeset
   661
                    for (Path p : stream) {
058fc03646d9 8171005: Fix JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName) to work with location == CLASS_OUTPUT
jlahoda
parents: 42414
diff changeset
   662
                        getLocationForModule(p.getFileName().toString());
058fc03646d9 8171005: Fix JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName) to work with location == CLASS_OUTPUT
jlahoda
parents: 42414
diff changeset
   663
                    }
058fc03646d9 8171005: Fix JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName) to work with location == CLASS_OUTPUT
jlahoda
parents: 42414
diff changeset
   664
                }
058fc03646d9 8171005: Fix JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName) to work with location == CLASS_OUTPUT
jlahoda
parents: 42414
diff changeset
   665
                listed = true;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   666
            }
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   667
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   668
            if (moduleTable == null || moduleTable.isEmpty())
42814
058fc03646d9 8171005: Fix JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName) to work with location == CLASS_OUTPUT
jlahoda
parents: 42414
diff changeset
   669
                return Collections.emptySet();
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   670
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   671
            return Collections.singleton(moduleTable.locations());
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   672
        }
44822
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
   673
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
   674
        @Override
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
   675
        boolean contains(Path file) throws IOException {
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
   676
            if (moduleTable != null) {
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
   677
                return moduleTable.contains(file);
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
   678
            } else {
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
   679
                return (outputDir) != null && normalize(file).startsWith(normalize(outputDir));
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
   680
            }
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
   681
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   682
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   683
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   684
    /**
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   685
     * General purpose implementation for search path locations,
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   686
     * such as -sourcepath/SOURCE_PATH and -processorPath/ANNOTATION_PROCESSOR_PATH.
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   687
     * All options are treated as equivalent (i.e. aliases.)
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   688
     * The value is an ordered set of files and/or directories.
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   689
     */
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   690
    private class SimpleLocationHandler extends BasicLocationHandler {
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   691
27852
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
   692
        protected Collection<Path> searchPath;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   693
11314
b612aaca08d0 7120736: refactor javac option handling
jjg
parents: 10819
diff changeset
   694
        SimpleLocationHandler(Location location, Option... options) {
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   695
            super(location, options);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   696
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   697
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   698
        @Override
11314
b612aaca08d0 7120736: refactor javac option handling
jjg
parents: 10819
diff changeset
   699
        boolean handleOption(Option option, String value) {
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   700
            if (!options.contains(option)) {
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   701
                return false;
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   702
            }
47702
cf8310446245 8139607: -release option forces StandardJavaFileManager
jlahoda
parents: 47363
diff changeset
   703
cf8310446245 8139607: -release option forces StandardJavaFileManager
jlahoda
parents: 47363
diff changeset
   704
            explicit = true;
cf8310446245 8139607: -release option forces StandardJavaFileManager
jlahoda
parents: 47363
diff changeset
   705
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   706
            searchPath = value == null ? null
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   707
                    : Collections.unmodifiableCollection(createPath().addFiles(value));
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   708
            return true;
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   709
        }
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   710
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   711
        @Override
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   712
        Collection<Path> getPaths() {
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   713
            return searchPath;
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   714
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   715
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   716
        @Override
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   717
        void setPaths(Iterable<? extends Path> files) {
27118
3c8314271af7 8060043: Rename Locations.Path to Locations.SearchPath
jjg
parents: 25874
diff changeset
   718
            SearchPath p;
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   719
            if (files == null) {
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   720
                p = computePath(null);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   721
            } else {
47702
cf8310446245 8139607: -release option forces StandardJavaFileManager
jlahoda
parents: 47363
diff changeset
   722
                explicit = true;
14360
2a8304e421ed 6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents: 14259
diff changeset
   723
                p = createPath().addFiles(files);
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   724
            }
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   725
            searchPath = Collections.unmodifiableCollection(p);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   726
        }
14360
2a8304e421ed 6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents: 14259
diff changeset
   727
27118
3c8314271af7 8060043: Rename Locations.Path to Locations.SearchPath
jjg
parents: 25874
diff changeset
   728
        protected SearchPath computePath(String value) {
14360
2a8304e421ed 6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents: 14259
diff changeset
   729
            return createPath().addFiles(value);
2a8304e421ed 6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents: 14259
diff changeset
   730
        }
2a8304e421ed 6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents: 14259
diff changeset
   731
27118
3c8314271af7 8060043: Rename Locations.Path to Locations.SearchPath
jjg
parents: 25874
diff changeset
   732
        protected SearchPath createPath() {
3c8314271af7 8060043: Rename Locations.Path to Locations.SearchPath
jjg
parents: 25874
diff changeset
   733
            return new SearchPath();
14360
2a8304e421ed 6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents: 14259
diff changeset
   734
        }
44822
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
   735
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
   736
        @Override
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
   737
        boolean contains(Path file) throws IOException {
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
   738
            return Locations.this.contains(searchPath, file);
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
   739
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   740
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   741
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   742
    /**
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   743
     * Subtype of SimpleLocationHandler for -classpath/CLASS_PATH.
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   744
     * 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
   745
     */
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   746
    private class ClassPathLocationHandler extends SimpleLocationHandler {
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   747
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   748
        ClassPathLocationHandler() {
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 40302
diff changeset
   749
            super(StandardLocation.CLASS_PATH, Option.CLASS_PATH);
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   750
        }
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   751
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   752
        @Override
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   753
        Collection<Path> getPaths() {
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   754
            lazy();
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   755
            return searchPath;
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   756
        }
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   757
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   758
        @Override
27118
3c8314271af7 8060043: Rename Locations.Path to Locations.SearchPath
jjg
parents: 25874
diff changeset
   759
        protected SearchPath computePath(String value) {
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   760
            String cp = value;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   761
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   762
            // CLASSPATH environment variable when run from `javac'.
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   763
            if (cp == null) {
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   764
                cp = System.getProperty("env.class.path");
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   765
            }
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   766
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   767
            // If invoked via a java VM (not the javac launcher), use the
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   768
            // platform class path
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   769
            if (cp == null && System.getProperty("application.home") == null) {
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   770
                cp = System.getProperty("java.class.path");
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   771
            }
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   772
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   773
            // Default to current working directory.
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   774
            if (cp == null) {
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   775
                cp = ".";
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   776
            }
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   777
14360
2a8304e421ed 6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents: 14259
diff changeset
   778
            return createPath().addFiles(cp);
2a8304e421ed 6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents: 14259
diff changeset
   779
        }
2a8304e421ed 6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents: 14259
diff changeset
   780
2a8304e421ed 6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents: 14259
diff changeset
   781
        @Override
27118
3c8314271af7 8060043: Rename Locations.Path to Locations.SearchPath
jjg
parents: 25874
diff changeset
   782
        protected SearchPath createPath() {
3c8314271af7 8060043: Rename Locations.Path to Locations.SearchPath
jjg
parents: 25874
diff changeset
   783
            return new SearchPath()
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   784
                    .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
   785
                    .emptyPathDefault(getPath("."));  // Empty path elt ==> current directory
14360
2a8304e421ed 6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents: 14259
diff changeset
   786
        }
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   787
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   788
        private void lazy() {
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   789
            if (searchPath == null) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   790
                setPaths(null);
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   791
            }
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   792
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   793
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   794
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   795
    /**
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   796
     * Custom subtype of LocationHandler for PLATFORM_CLASS_PATH.
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   797
     * Various options are supported for different components of the
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   798
     * platform class path.
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   799
     * Setting a value with setLocation overrides all existing option values.
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   800
     * Setting any option overrides any value set with setLocation, and
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   801
     * reverts to using default values for options that have not been set.
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   802
     * Setting -bootclasspath or -Xbootclasspath overrides any existing
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   803
     * value for -Xbootclasspath/p: and -Xbootclasspath/a:.
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   804
     */
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   805
    private class BootClassPathLocationHandler extends BasicLocationHandler {
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   806
27852
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
   807
        private Collection<Path> searchPath;
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22153
diff changeset
   808
        final Map<Option, String> optionValues = new EnumMap<>(Option.class);
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   809
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   810
        /**
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   811
         * Is the bootclasspath the default?
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   812
         */
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   813
        private boolean isDefault;
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   814
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   815
        BootClassPathLocationHandler() {
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   816
            super(StandardLocation.PLATFORM_CLASS_PATH,
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 40302
diff changeset
   817
                    Option.BOOT_CLASS_PATH, Option.XBOOTCLASSPATH,
11314
b612aaca08d0 7120736: refactor javac option handling
jjg
parents: 10819
diff changeset
   818
                    Option.XBOOTCLASSPATH_PREPEND,
b612aaca08d0 7120736: refactor javac option handling
jjg
parents: 10819
diff changeset
   819
                    Option.XBOOTCLASSPATH_APPEND,
b612aaca08d0 7120736: refactor javac option handling
jjg
parents: 10819
diff changeset
   820
                    Option.ENDORSEDDIRS, Option.DJAVA_ENDORSED_DIRS,
b612aaca08d0 7120736: refactor javac option handling
jjg
parents: 10819
diff changeset
   821
                    Option.EXTDIRS, Option.DJAVA_EXT_DIRS);
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   822
        }
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   823
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   824
        boolean isDefault() {
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   825
            lazy();
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   826
            return isDefault;
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   827
        }
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   828
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   829
        @Override
11314
b612aaca08d0 7120736: refactor javac option handling
jjg
parents: 10819
diff changeset
   830
        boolean handleOption(Option option, String value) {
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   831
            if (!options.contains(option)) {
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   832
                return false;
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   833
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   834
47702
cf8310446245 8139607: -release option forces StandardJavaFileManager
jlahoda
parents: 47363
diff changeset
   835
            explicit = true;
cf8310446245 8139607: -release option forces StandardJavaFileManager
jlahoda
parents: 47363
diff changeset
   836
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   837
            option = canonicalize(option);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   838
            optionValues.put(option, value);
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 40302
diff changeset
   839
            if (option == BOOT_CLASS_PATH) {
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   840
                optionValues.remove(XBOOTCLASSPATH_PREPEND);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   841
                optionValues.remove(XBOOTCLASSPATH_APPEND);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   842
            }
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   843
            searchPath = null;  // reset to "uninitialized"
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   844
            return true;
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   845
        }
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   846
        // where
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   847
        // 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
   848
        // level
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   849
        private Option canonicalize(Option option) {
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   850
            switch (option) {
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   851
                case XBOOTCLASSPATH:
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 40302
diff changeset
   852
                    return Option.BOOT_CLASS_PATH;
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   853
                case DJAVA_ENDORSED_DIRS:
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   854
                    return Option.ENDORSEDDIRS;
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   855
                case DJAVA_EXT_DIRS:
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   856
                    return Option.EXTDIRS;
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   857
                default:
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   858
                    return option;
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   859
            }
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   860
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   861
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   862
        @Override
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   863
        Collection<Path> getPaths() {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   864
            lazy();
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   865
            return searchPath;
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   866
        }
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   867
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   868
        @Override
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   869
        void setPaths(Iterable<? extends Path> files) {
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   870
            if (files == null) {
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   871
                searchPath = null;  // reset to "uninitialized"
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   872
            } else {
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   873
                isDefault = false;
47702
cf8310446245 8139607: -release option forces StandardJavaFileManager
jlahoda
parents: 47363
diff changeset
   874
                explicit = true;
27118
3c8314271af7 8060043: Rename Locations.Path to Locations.SearchPath
jjg
parents: 25874
diff changeset
   875
                SearchPath p = new SearchPath().addFiles(files, false);
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   876
                searchPath = Collections.unmodifiableCollection(p);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   877
                optionValues.clear();
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   878
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   879
        }
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   880
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   881
        SearchPath computePath() throws IOException {
27118
3c8314271af7 8060043: Rename Locations.Path to Locations.SearchPath
jjg
parents: 25874
diff changeset
   882
            SearchPath path = new SearchPath();
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   883
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 40302
diff changeset
   884
            String bootclasspathOpt = optionValues.get(BOOT_CLASS_PATH);
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   885
            String endorseddirsOpt = optionValues.get(ENDORSEDDIRS);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   886
            String extdirsOpt = optionValues.get(EXTDIRS);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   887
            String xbootclasspathPrependOpt = optionValues.get(XBOOTCLASSPATH_PREPEND);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   888
            String xbootclasspathAppendOpt = optionValues.get(XBOOTCLASSPATH_APPEND);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   889
            path.addFiles(xbootclasspathPrependOpt);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   890
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   891
            if (endorseddirsOpt != null) {
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   892
                path.addDirectories(endorseddirsOpt);
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   893
            } else {
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   894
                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
   895
            }
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   896
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   897
            if (bootclasspathOpt != null) {
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   898
                path.addFiles(bootclasspathOpt);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   899
            } else {
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   900
                // Standard system classes for this compiler's release.
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   901
                Collection<Path> systemClasses = systemClasses();
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   902
                if (systemClasses != null) {
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   903
                    path.addFiles(systemClasses, false);
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   904
                } else {
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   905
                    // fallback to the value of sun.boot.class.path
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   906
                    String files = System.getProperty("sun.boot.class.path");
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   907
                    path.addFiles(files, false);
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   908
                }
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   909
            }
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   910
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   911
            path.addFiles(xbootclasspathAppendOpt);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   912
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   913
            // Strictly speaking, standard extensions are not bootstrap
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   914
            // classes, but we treat them identically, so we'll pretend
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   915
            // that they are.
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   916
            if (extdirsOpt != null) {
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   917
                path.addDirectories(extdirsOpt);
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   918
            } else {
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   919
                // Add lib/jfxrt.jar to the search path
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   920
               Path jfxrt = javaHome.resolve("lib/jfxrt.jar");
27858
chegar
parents: 27579 27852
diff changeset
   921
                if (Files.exists(jfxrt)) {
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   922
                    path.addFile(jfxrt, false);
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   923
                }
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   924
                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
   925
            }
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   926
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   927
            isDefault =
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   928
                       (xbootclasspathPrependOpt == null)
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   929
                    && (bootclasspathOpt == null)
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   930
                    && (xbootclasspathAppendOpt == null);
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   931
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   932
            return path;
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   933
        }
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   934
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   935
        /**
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   936
         * Return a collection of files containing system classes.
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   937
         * Returns {@code null} if not running on a modular image.
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   938
         *
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   939
         * @throws UncheckedIOException if an I/O errors occurs
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   940
         */
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   941
        private Collection<Path> systemClasses() throws IOException {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   942
            // Return "modules" jimage file if available
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   943
            if (Files.isRegularFile(thisSystemModules)) {
40302
8c0d8d2c3519 8143048: Re-examine dependency on property sun.boot.class.path
jlahoda
parents: 38536
diff changeset
   944
                return Collections.singleton(thisSystemModules);
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   945
            }
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   946
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   947
            // Exploded module image
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   948
            Path modules = javaHome.resolve("modules");
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   949
            if (Files.isDirectory(modules.resolve("java.base"))) {
29053
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents: 28707
diff changeset
   950
                try (Stream<Path> listedModules = Files.list(modules)) {
40302
8c0d8d2c3519 8143048: Re-examine dependency on property sun.boot.class.path
jlahoda
parents: 38536
diff changeset
   951
                    return listedModules.collect(Collectors.toList());
29053
5c1f1d6b40f6 8067445: New modular image-based file manager skips boot classes
jlahoda
parents: 28707
diff changeset
   952
                }
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   953
            }
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   954
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   955
            // not a modular image that we know about
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   956
            return null;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   957
        }
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   958
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   959
        private void lazy() {
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   960
            if (searchPath == null) {
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   961
                try {
44822
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
   962
                    searchPath = Collections.unmodifiableCollection(computePath());
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   963
                } catch (IOException e) {
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   964
                    // TODO: need better handling here, e.g. javac Abort?
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   965
                    throw new UncheckedIOException(e);
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27226
diff changeset
   966
                }
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
   967
            }
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
   968
        }
44822
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
   969
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
   970
        @Override
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
   971
        boolean contains(Path file) throws IOException {
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
   972
            return Locations.this.contains(searchPath, file);
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
   973
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   974
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   975
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   976
    /**
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   977
     * A LocationHander to represent modules found from a module-oriented
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   978
     * location such as MODULE_SOURCE_PATH, UPGRADE_MODULE_PATH,
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   979
     * SYSTEM_MODULES and MODULE_PATH.
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   980
     *
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   981
     * The Location can be specified to accept overriding classes from the
40762
f8883aa0053c 8160851: Remove old launcher module-related options
mchung
parents: 40513
diff changeset
   982
     * {@code --patch-module <module>=<path> } parameter.
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   983
     */
44822
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
   984
    private class ModuleLocationHandler extends LocationHandler implements Location {
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   985
        private final LocationHandler parent;
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   986
        private final String name;
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   987
        private final String moduleName;
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   988
        private final boolean output;
47363
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
   989
        boolean explicit;
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   990
        Collection<Path> searchPath;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   991
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   992
        ModuleLocationHandler(LocationHandler parent, String name, String moduleName,
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   993
                Collection<Path> searchPath, boolean output) {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
   994
            this.parent = parent;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   995
            this.name = name;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   996
            this.moduleName = moduleName;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   997
            this.searchPath = searchPath;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   998
            this.output = output;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
   999
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1000
37848
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36526
diff changeset
  1001
        @Override @DefinedBy(Api.COMPILER)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1002
        public String getName() {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1003
            return name;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1004
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1005
37848
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36526
diff changeset
  1006
        @Override @DefinedBy(Api.COMPILER)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1007
        public boolean isOutputLocation() {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1008
            return output;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1009
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1010
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1011
        @Override // defined by LocationHandler
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1012
        boolean handleOption(Option option, String value) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1013
            throw new UnsupportedOperationException();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1014
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1015
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1016
        @Override // defined by LocationHandler
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1017
        Collection<Path> getPaths() {
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1018
            return Collections.unmodifiableCollection(searchPath);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1019
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1020
47702
cf8310446245 8139607: -release option forces StandardJavaFileManager
jlahoda
parents: 47363
diff changeset
  1021
        @Override
cf8310446245 8139607: -release option forces StandardJavaFileManager
jlahoda
parents: 47363
diff changeset
  1022
        boolean isExplicit() {
cf8310446245 8139607: -release option forces StandardJavaFileManager
jlahoda
parents: 47363
diff changeset
  1023
            return true;
cf8310446245 8139607: -release option forces StandardJavaFileManager
jlahoda
parents: 47363
diff changeset
  1024
        }
cf8310446245 8139607: -release option forces StandardJavaFileManager
jlahoda
parents: 47363
diff changeset
  1025
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1026
        @Override // defined by LocationHandler
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1027
        void setPaths(Iterable<? extends Path> paths) throws IOException {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1028
            // defer to the parent to determine if this is acceptable
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1029
            parent.setPathsForModule(moduleName, paths);
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1030
        }
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1031
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1032
        @Override // defined by LocationHandler
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1033
        void setPathsForModule(String moduleName, Iterable<? extends Path> paths) {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1034
            throw new UnsupportedOperationException("not supported for " + name);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1035
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1036
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1037
        @Override // defined by LocationHandler
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1038
        String inferModuleName() {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1039
            return moduleName;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1040
        }
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1041
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1042
        @Override
44822
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
  1043
        boolean contains(Path file) throws IOException {
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
  1044
            return Locations.this.contains(searchPath, file);
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
  1045
        }
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
  1046
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
  1047
        @Override
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1048
        public String toString() {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1049
            return name;
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1050
        }
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1051
    }
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1052
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1053
    /**
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1054
     * A table of module location handlers, indexed by name and path.
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1055
     */
44822
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
  1056
    private class ModuleTable {
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1057
        private final Map<String, ModuleLocationHandler> nameMap = new LinkedHashMap<>();
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1058
        private final Map<Path, ModuleLocationHandler> pathMap = new LinkedHashMap<>();
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1059
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1060
        void add(ModuleLocationHandler h) {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1061
            nameMap.put(h.moduleName, h);
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1062
            for (Path p : h.searchPath) {
44021
3ea5514d9fbe 8175990: Javac fails to find module-info.java if module source path contains symlinks
ksrini
parents: 44019
diff changeset
  1063
                pathMap.put(normalize(p), h);
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1064
            }
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1065
        }
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1066
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1067
        void updatePaths(ModuleLocationHandler h) {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1068
            // use iterator, to be able to remove old entries
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1069
            for (Iterator<Map.Entry<Path, ModuleLocationHandler>> iter = pathMap.entrySet().iterator();
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1070
                    iter.hasNext(); ) {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1071
                Map.Entry<Path, ModuleLocationHandler> e = iter.next();
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1072
                if (e.getValue() == h) {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1073
                    iter.remove();
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1074
                }
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1075
            }
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1076
            for (Path p : h.searchPath) {
44021
3ea5514d9fbe 8175990: Javac fails to find module-info.java if module source path contains symlinks
ksrini
parents: 44019
diff changeset
  1077
                pathMap.put(normalize(p), h);
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1078
            }
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1079
        }
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1080
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1081
        ModuleLocationHandler get(String name) {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1082
            return nameMap.get(name);
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1083
        }
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1084
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1085
        ModuleLocationHandler get(Path path) {
44063
5f0cf4126949 8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents: 44021
diff changeset
  1086
            while (path != null) {
5f0cf4126949 8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents: 44021
diff changeset
  1087
                ModuleLocationHandler l = pathMap.get(path);
5f0cf4126949 8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents: 44021
diff changeset
  1088
5f0cf4126949 8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents: 44021
diff changeset
  1089
                if (l != null)
5f0cf4126949 8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents: 44021
diff changeset
  1090
                    return l;
5f0cf4126949 8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents: 44021
diff changeset
  1091
5f0cf4126949 8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents: 44021
diff changeset
  1092
                path = path.getParent();
5f0cf4126949 8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents: 44021
diff changeset
  1093
            }
5f0cf4126949 8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents: 44021
diff changeset
  1094
5f0cf4126949 8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents: 44021
diff changeset
  1095
            return null;
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1096
        }
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1097
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1098
        void clear() {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1099
            nameMap.clear();
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1100
            pathMap.clear();
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1101
        }
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1102
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1103
        boolean isEmpty() {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1104
            return nameMap.isEmpty();
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1105
        }
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1106
44822
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
  1107
        boolean contains(Path file) throws IOException {
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
  1108
            return Locations.this.contains(pathMap.keySet(), file);
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
  1109
        }
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
  1110
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1111
        Set<Location> locations() {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1112
            return Collections.unmodifiableSet(nameMap.values().stream().collect(Collectors.toSet()));
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1113
        }
47363
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
  1114
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
  1115
        Set<Location> explicitLocations() {
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
  1116
            return Collections.unmodifiableSet(nameMap.entrySet()
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
  1117
                                                      .stream()
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
  1118
                                                      .filter(e -> e.getValue().explicit)
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
  1119
                                                      .map(e -> e.getValue())
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
  1120
                                                      .collect(Collectors.toSet()));
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
  1121
        }
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1122
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1123
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1124
    /**
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1125
     * A LocationHandler for simple module-oriented search paths,
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1126
     * like UPGRADE_MODULE_PATH and MODULE_PATH.
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1127
     */
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1128
    private class ModulePathLocationHandler extends SimpleLocationHandler {
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1129
        private ModuleTable moduleTable;
42414
0ae183c295a0 8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents: 42408
diff changeset
  1130
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1131
        ModulePathLocationHandler(Location location, Option... options) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1132
            super(location, options);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1133
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1134
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1135
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1136
        public boolean handleOption(Option option, String value) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1137
            if (!options.contains(option)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1138
                return false;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1139
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1140
            setPaths(value == null ? null : getPathEntries(value));
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1141
            return true;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1142
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1143
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1144
        @Override
42414
0ae183c295a0 8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents: 42408
diff changeset
  1145
        public Location getLocationForModule(String moduleName) {
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1146
            initModuleLocations();
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1147
            return moduleTable.get(moduleName);
42414
0ae183c295a0 8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents: 42408
diff changeset
  1148
        }
0ae183c295a0 8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents: 42408
diff changeset
  1149
0ae183c295a0 8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents: 42408
diff changeset
  1150
        @Override
44822
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
  1151
        public Location getLocationForModule(Path file) {
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
  1152
            initModuleLocations();
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
  1153
            return moduleTable.get(file);
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
  1154
        }
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
  1155
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
  1156
        @Override
42261
bb52b5514ad5 8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents: 41861
diff changeset
  1157
        Iterable<Set<Location>> listLocationsForModules() {
47363
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
  1158
            Set<Location> explicitLocations = moduleTable != null ?
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
  1159
                    moduleTable.explicitLocations() : Collections.emptySet();
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
  1160
            Iterable<Set<Location>> explicitLocationsList = !explicitLocations.isEmpty()
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
  1161
                    ? Collections.singletonList(explicitLocations)
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
  1162
                    : Collections.emptyList();
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
  1163
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1164
            if (searchPath == null)
47363
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
  1165
                return explicitLocationsList;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1166
47363
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
  1167
            Iterable<Set<Location>> searchPathLocations =
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
  1168
                    () -> new ModulePathIterator();
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
  1169
            return () -> Iterators.createCompoundIterator(Arrays.asList(explicitLocationsList,
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
  1170
                                                                        searchPathLocations),
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
  1171
                                                          Iterable::iterator);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1172
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1173
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1174
        @Override
44822
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
  1175
        boolean contains(Path file) throws IOException {
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
  1176
            if (moduleTable == null) {
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
  1177
                initModuleLocations();
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
  1178
            }
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
  1179
            return moduleTable.contains(file);
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
  1180
        }
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
  1181
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
  1182
        @Override
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1183
        void setPaths(Iterable<? extends Path> paths) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1184
            if (paths != null) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1185
                for (Path p: paths) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1186
                    checkValidModulePathEntry(p);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1187
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1188
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1189
            super.setPaths(paths);
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1190
            moduleTable = null;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1191
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1192
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1193
        @Override
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1194
        void setPathsForModule(String name, Iterable<? extends Path> paths) throws IOException {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1195
            List<Path> checkedPaths = checkPaths(paths);
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1196
            // how far should we go to validate the paths provide a module?
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1197
            // e.g. contain module-info with the correct name?
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1198
            initModuleLocations();
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1199
            ModuleLocationHandler l = moduleTable.get(name);
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1200
            if (l == null) {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1201
                l = new ModuleLocationHandler(this, location.getName() + "[" + name + "]",
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1202
                        name, checkedPaths, true);
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1203
                moduleTable.add(l);
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1204
           } else {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1205
                l.searchPath = checkedPaths;
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1206
                moduleTable.updatePaths(l);
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1207
            }
47363
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
  1208
            l.explicit = true;
47702
cf8310446245 8139607: -release option forces StandardJavaFileManager
jlahoda
parents: 47363
diff changeset
  1209
            explicit = true;
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1210
        }
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1211
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1212
        private List<Path> checkPaths(Iterable<? extends Path> paths) throws IOException {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1213
            Objects.requireNonNull(paths);
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1214
            List<Path> validPaths = new ArrayList<>();
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1215
            for (Path p : paths) {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1216
                validPaths.add(checkDirectory(p));
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1217
            }
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1218
            return validPaths;
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1219
        }
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1220
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1221
        private void initModuleLocations() {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1222
            if (moduleTable != null) {
42414
0ae183c295a0 8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents: 42408
diff changeset
  1223
                return;
0ae183c295a0 8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents: 42408
diff changeset
  1224
            }
0ae183c295a0 8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents: 42408
diff changeset
  1225
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1226
            moduleTable = new ModuleTable();
42414
0ae183c295a0 8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents: 42408
diff changeset
  1227
0ae183c295a0 8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents: 42408
diff changeset
  1228
            for (Set<Location> set : listLocationsForModules()) {
0ae183c295a0 8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents: 42408
diff changeset
  1229
                for (Location locn : set) {
0ae183c295a0 8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents: 42408
diff changeset
  1230
                    if (locn instanceof ModuleLocationHandler) {
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1231
                        ModuleLocationHandler l = (ModuleLocationHandler) locn;
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1232
                        if (!moduleTable.nameMap.containsKey(l.moduleName)) {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1233
                            moduleTable.add(l);
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1234
                        }
42414
0ae183c295a0 8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents: 42408
diff changeset
  1235
                    }
0ae183c295a0 8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents: 42408
diff changeset
  1236
                }
0ae183c295a0 8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents: 42408
diff changeset
  1237
            }
0ae183c295a0 8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents: 42408
diff changeset
  1238
        }
0ae183c295a0 8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents: 42408
diff changeset
  1239
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1240
        private void checkValidModulePathEntry(Path p) {
43771
25ddac537bb5 8174104: Compiler does not allow non-existent module path entry
jjg
parents: 43574
diff changeset
  1241
            if (!Files.exists(p)) {
25ddac537bb5 8174104: Compiler does not allow non-existent module path entry
jjg
parents: 43574
diff changeset
  1242
                // warning may be generated later
25ddac537bb5 8174104: Compiler does not allow non-existent module path entry
jjg
parents: 43574
diff changeset
  1243
                return;
25ddac537bb5 8174104: Compiler does not allow non-existent module path entry
jjg
parents: 43574
diff changeset
  1244
            }
25ddac537bb5 8174104: Compiler does not allow non-existent module path entry
jjg
parents: 43574
diff changeset
  1245
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1246
            if (Files.isDirectory(p)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1247
                // either an exploded module or a directory of modules
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1248
                return;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1249
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1250
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1251
            String name = p.getFileName().toString();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1252
            int lastDot = name.lastIndexOf(".");
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1253
            if (lastDot > 0) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1254
                switch (name.substring(lastDot)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1255
                    case ".jar":
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1256
                    case ".jmod":
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1257
                        return;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1258
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1259
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1260
            throw new IllegalArgumentException(p.toString());
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1261
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1262
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1263
        class ModulePathIterator implements Iterator<Set<Location>> {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1264
            Iterator<Path> pathIter = searchPath.iterator();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1265
            int pathIndex = 0;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1266
            Set<Location> next = null;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1267
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1268
            @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1269
            public boolean hasNext() {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1270
                if (next != null)
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1271
                    return true;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1272
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1273
                while (next == null) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1274
                    if (pathIter.hasNext()) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1275
                        Path path = pathIter.next();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1276
                        if (Files.isDirectory(path)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1277
                            next = scanDirectory(path);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1278
                        } else {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1279
                            next = scanFile(path);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1280
                        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1281
                        pathIndex++;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1282
                    } else
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1283
                        return false;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1284
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1285
                return true;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1286
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1287
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1288
            @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1289
            public Set<Location> next() {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1290
                hasNext();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1291
                if (next != null) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1292
                    Set<Location> result = next;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1293
                    next = null;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1294
                    return result;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1295
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1296
                throw new NoSuchElementException();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1297
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1298
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1299
            private Set<Location> scanDirectory(Path path) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1300
                Set<Path> paths = new LinkedHashSet<>();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1301
                Path moduleInfoClass = null;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1302
                try (DirectoryStream<Path> stream = Files.newDirectoryStream(path)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1303
                    for (Path entry: stream) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1304
                        if (entry.endsWith("module-info.class")) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1305
                            moduleInfoClass = entry;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1306
                            break;  // no need to continue scanning
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1307
                        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1308
                        paths.add(entry);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1309
                    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1310
                } catch (DirectoryIteratorException | IOException ignore) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1311
                    log.error(Errors.LocnCantReadDirectory(path));
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1312
                    return Collections.emptySet();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1313
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1314
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1315
                if (moduleInfoClass != null) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1316
                    // It's an exploded module directly on the module path.
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1317
                    // We can't infer module name from the directory name, so have to
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1318
                    // read module-info.class.
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1319
                    try {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1320
                        String moduleName = readModuleName(moduleInfoClass);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1321
                        String name = location.getName()
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1322
                                + "[" + pathIndex + ":" + moduleName + "]";
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1323
                        ModuleLocationHandler l = new ModuleLocationHandler(
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1324
                                ModulePathLocationHandler.this, name, moduleName,
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1325
                                Collections.singletonList(path), false);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1326
                        return Collections.singleton(l);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1327
                    } catch (ModuleNameReader.BadClassFile e) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1328
                        log.error(Errors.LocnBadModuleInfo(path));
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1329
                        return Collections.emptySet();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1330
                    } catch (IOException e) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1331
                        log.error(Errors.LocnCantReadFile(path));
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1332
                        return Collections.emptySet();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1333
                    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1334
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1335
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1336
                // A directory of modules
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1337
                Set<Location> result = new LinkedHashSet<>();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1338
                int index = 0;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1339
                for (Path entry : paths) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1340
                    Pair<String,Path> module = inferModuleName(entry);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1341
                    if (module == null) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1342
                        // diagnostic reported if necessary; skip to next
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1343
                        continue;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1344
                    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1345
                    String moduleName = module.fst;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1346
                    Path modulePath = module.snd;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1347
                    String name = location.getName()
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1348
                            + "[" + pathIndex + "." + (index++) + ":" + moduleName + "]";
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1349
                    ModuleLocationHandler l = new ModuleLocationHandler(
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1350
                            ModulePathLocationHandler.this, name, moduleName,
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1351
                            Collections.singletonList(modulePath), false);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1352
                    result.add(l);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1353
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1354
                return result;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1355
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1356
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1357
            private Set<Location> scanFile(Path path) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1358
                Pair<String,Path> module = inferModuleName(path);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1359
                if (module == null) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1360
                    // diagnostic reported if necessary
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1361
                    return Collections.emptySet();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1362
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1363
                String moduleName = module.fst;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1364
                Path modulePath = module.snd;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1365
                String name = location.getName()
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1366
                        + "[" + pathIndex + ":" + moduleName + "]";
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1367
                ModuleLocationHandler l = new ModuleLocationHandler(
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1368
                        ModulePathLocationHandler.this, name, moduleName,
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1369
                        Collections.singletonList(modulePath), false);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1370
                return Collections.singleton(l);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1371
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1372
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1373
            private Pair<String,Path> inferModuleName(Path p) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1374
                if (Files.isDirectory(p)) {
47703
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents: 47702
diff changeset
  1375
                    if (Files.exists(p.resolve("module-info.class")) ||
dbfac941197a 8180744: Update ct.sym for JDK 10
jlahoda
parents: 47702
diff changeset
  1376
                        Files.exists(p.resolve("module-info.sig"))) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1377
                        String name = p.getFileName().toString();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1378
                        if (SourceVersion.isName(name))
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1379
                            return new Pair<>(name, p);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1380
                    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1381
                    return null;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1382
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1383
38536
42569f7fe4e6 8154824: Compiler should handle java.nio.file.FileSystemNotFoundException gracefully and not abort
sadayapalam
parents: 38519
diff changeset
  1384
                if (p.getFileName().toString().endsWith(".jar") && fsInfo.exists(p)) {
43574
042e694725f7 8166675: Latent bug in jar file handling during module path processing.
jjg
parents: 43267
diff changeset
  1385
                    FileSystemProvider jarFSProvider = fsInfo.getJarFSProvider();
042e694725f7 8166675: Latent bug in jar file handling during module path processing.
jjg
parents: 43267
diff changeset
  1386
                    if (jarFSProvider == null) {
042e694725f7 8166675: Latent bug in jar file handling during module path processing.
jjg
parents: 43267
diff changeset
  1387
                        log.error(Errors.NoZipfsForArchive(p));
042e694725f7 8166675: Latent bug in jar file handling during module path processing.
jjg
parents: 43267
diff changeset
  1388
                        return null;
042e694725f7 8166675: Latent bug in jar file handling during module path processing.
jjg
parents: 43267
diff changeset
  1389
                    }
042e694725f7 8166675: Latent bug in jar file handling during module path processing.
jjg
parents: 43267
diff changeset
  1390
                    try (FileSystem fs = jarFSProvider.newFileSystem(p, fsEnv)) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1391
                        Path moduleInfoClass = fs.getPath("module-info.class");
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1392
                        if (Files.exists(moduleInfoClass)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1393
                            String moduleName = readModuleName(moduleInfoClass);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1394
                            return new Pair<>(moduleName, p);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1395
                        }
45682
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44822
diff changeset
  1396
                        Path mf = fs.getPath("META-INF/MANIFEST.MF");
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44822
diff changeset
  1397
                        if (Files.exists(mf)) {
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44822
diff changeset
  1398
                            try (InputStream in = Files.newInputStream(mf)) {
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44822
diff changeset
  1399
                                Manifest man = new Manifest(in);
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44822
diff changeset
  1400
                                Attributes attrs = man.getMainAttributes();
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44822
diff changeset
  1401
                                if (attrs != null) {
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44822
diff changeset
  1402
                                    String moduleName = attrs.getValue(new Attributes.Name("Automatic-Module-Name"));
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44822
diff changeset
  1403
                                    if (moduleName != null) {
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44822
diff changeset
  1404
                                        if (isModuleName(moduleName)) {
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44822
diff changeset
  1405
                                            return new Pair<>(moduleName, p);
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44822
diff changeset
  1406
                                        } else {
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44822
diff changeset
  1407
                                            log.error(Errors.LocnCantGetModuleNameForJar(p));
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44822
diff changeset
  1408
                                            return null;
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44822
diff changeset
  1409
                                        }
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44822
diff changeset
  1410
                                    }
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44822
diff changeset
  1411
                                }
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44822
diff changeset
  1412
                            }
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44822
diff changeset
  1413
                        }
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1414
                    } catch (ModuleNameReader.BadClassFile e) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1415
                        log.error(Errors.LocnBadModuleInfo(p));
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1416
                        return null;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1417
                    } catch (IOException e) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1418
                        log.error(Errors.LocnCantReadFile(p));
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1419
                        return null;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1420
                    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1421
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1422
                    //automatic module:
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1423
                    String fn = p.getFileName().toString();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1424
                    //from ModulePath.deriveModuleDescriptor:
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1425
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1426
                    // drop .jar
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1427
                    String mn = fn.substring(0, fn.length()-4);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1428
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1429
                    // find first occurrence of -${NUMBER}. or -${NUMBER}$
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1430
                    Matcher matcher = Pattern.compile("-(\\d+(\\.|$))").matcher(mn);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1431
                    if (matcher.find()) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1432
                        int start = matcher.start();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1433
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1434
                        mn = mn.substring(0, start);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1435
                    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1436
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1437
                    // finally clean up the module name
44573
245bb4e6f983 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44063
diff changeset
  1438
                    mn =  mn.replaceAll("[^A-Za-z0-9]", ".")  // replace non-alphanumeric
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1439
                            .replaceAll("(\\.)(\\1)+", ".")   // collapse repeating dots
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1440
                            .replaceAll("^\\.", "")           // drop leading dots
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1441
                            .replaceAll("\\.$", "");          // drop trailing dots
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1442
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1443
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1444
                    if (!mn.isEmpty()) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1445
                        return new Pair<>(mn, p);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1446
                    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1447
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1448
                    log.error(Errors.LocnCantGetModuleNameForJar(p));
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1449
                    return null;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1450
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1451
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1452
                if (p.getFileName().toString().endsWith(".jmod")) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1453
                    try {
41440
abd777fa486c 8166860: Add magic number to jmod file
mchung
parents: 41254
diff changeset
  1454
                        // check if the JMOD file is valid
48433
04d8d293e458 8194141: Remove JDK9Wrappers
jjg
parents: 47703
diff changeset
  1455
                        JmodFile.checkMagic(p);
41440
abd777fa486c 8166860: Add magic number to jmod file
mchung
parents: 41254
diff changeset
  1456
abd777fa486c 8166860: Add magic number to jmod file
mchung
parents: 41254
diff changeset
  1457
                        // No JMOD file system.  Use JarFileSystem to
abd777fa486c 8166860: Add magic number to jmod file
mchung
parents: 41254
diff changeset
  1458
                        // workaround for now
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1459
                        FileSystem fs = fileSystems.get(p);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1460
                        if (fs == null) {
43574
042e694725f7 8166675: Latent bug in jar file handling during module path processing.
jjg
parents: 43267
diff changeset
  1461
                            FileSystemProvider jarFSProvider = fsInfo.getJarFSProvider();
042e694725f7 8166675: Latent bug in jar file handling during module path processing.
jjg
parents: 43267
diff changeset
  1462
                            if (jarFSProvider == null) {
042e694725f7 8166675: Latent bug in jar file handling during module path processing.
jjg
parents: 43267
diff changeset
  1463
                                log.error(Errors.LocnCantReadFile(p));
042e694725f7 8166675: Latent bug in jar file handling during module path processing.
jjg
parents: 43267
diff changeset
  1464
                                return null;
042e694725f7 8166675: Latent bug in jar file handling during module path processing.
jjg
parents: 43267
diff changeset
  1465
                            }
042e694725f7 8166675: Latent bug in jar file handling during module path processing.
jjg
parents: 43267
diff changeset
  1466
                            fs = jarFSProvider.newFileSystem(p, Collections.emptyMap());
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1467
                            try {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1468
                                Path moduleInfoClass = fs.getPath("classes/module-info.class");
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1469
                                String moduleName = readModuleName(moduleInfoClass);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1470
                                Path modulePath = fs.getPath("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1471
                                fileSystems.put(p, fs);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1472
                                closeables.add(fs);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1473
                                fs = null; // prevent fs being closed in the finally clause
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1474
                                return new Pair<>(moduleName, modulePath);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1475
                            } finally {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1476
                                if (fs != null)
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1477
                                    fs.close();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1478
                            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1479
                        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1480
                    } catch (ModuleNameReader.BadClassFile e) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1481
                        log.error(Errors.LocnBadModuleInfo(p));
43574
042e694725f7 8166675: Latent bug in jar file handling during module path processing.
jjg
parents: 43267
diff changeset
  1482
                    } catch (IOException e) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1483
                        log.error(Errors.LocnCantReadFile(p));
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1484
                        return null;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1485
                    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1486
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1487
38519
d70d50ec27bb 8154997: Add examples for jigsaw diagnostics
sadayapalam
parents: 37944
diff changeset
  1488
                if (warn && false) {  // temp disable, when enabled, massage examples.not-yet.txt suitably.
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1489
                    log.warning(Warnings.LocnUnknownFileOnModulePath(p));
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1490
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1491
                return null;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1492
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1493
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1494
            private String readModuleName(Path path) throws IOException, ModuleNameReader.BadClassFile {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1495
                if (moduleNameReader == null)
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1496
                    moduleNameReader = new ModuleNameReader();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1497
                return moduleNameReader.readModuleName(path);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1498
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1499
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1500
45682
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44822
diff changeset
  1501
        //from jdk.internal.module.Checks:
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44822
diff changeset
  1502
        /**
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44822
diff changeset
  1503
         * Returns {@code true} if the given name is a legal module name.
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44822
diff changeset
  1504
         */
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44822
diff changeset
  1505
        private boolean isModuleName(String name) {
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44822
diff changeset
  1506
            int next;
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44822
diff changeset
  1507
            int off = 0;
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44822
diff changeset
  1508
            while ((next = name.indexOf('.', off)) != -1) {
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44822
diff changeset
  1509
                String id = name.substring(off, next);
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44822
diff changeset
  1510
                if (!SourceVersion.isName(id))
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44822
diff changeset
  1511
                    return false;
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44822
diff changeset
  1512
                off = next+1;
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44822
diff changeset
  1513
            }
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44822
diff changeset
  1514
            String last = name.substring(off);
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44822
diff changeset
  1515
            return SourceVersion.isName(last);
fc3b228b9e2a 8181087: Module system implementation refresh (6/2017)
alanb
parents: 44822
diff changeset
  1516
        }
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1517
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1518
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1519
    private class ModuleSourcePathLocationHandler extends BasicLocationHandler {
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1520
        private ModuleTable moduleTable;
44690
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 44573
diff changeset
  1521
        private List<Path> paths;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1522
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1523
        ModuleSourcePathLocationHandler() {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1524
            super(StandardLocation.MODULE_SOURCE_PATH,
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 40302
diff changeset
  1525
                    Option.MODULE_SOURCE_PATH);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1526
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1527
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1528
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1529
        boolean handleOption(Option option, String value) {
47702
cf8310446245 8139607: -release option forces StandardJavaFileManager
jlahoda
parents: 47363
diff changeset
  1530
            explicit = true;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1531
            init(value);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1532
            return true;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1533
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1534
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1535
        void init(String value) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1536
            Collection<String> segments = new ArrayList<>();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1537
            for (String s: value.split(File.pathSeparator)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1538
                expandBraces(s, segments);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1539
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1540
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1541
            Map<String, List<Path>> map = new LinkedHashMap<>();
44690
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 44573
diff changeset
  1542
            List<Path> noSuffixPaths = new ArrayList<>();
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 44573
diff changeset
  1543
            boolean anySuffix = false;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1544
            final String MARKER = "*";
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1545
            for (String seg: segments) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1546
                int markStart = seg.indexOf(MARKER);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1547
                if (markStart == -1) {
44690
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 44573
diff changeset
  1548
                    Path p = getPath(seg);
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 44573
diff changeset
  1549
                    add(map, p, null);
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 44573
diff changeset
  1550
                    noSuffixPaths.add(p);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1551
                } else {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1552
                    if (markStart == 0 || !isSeparator(seg.charAt(markStart - 1))) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1553
                        throw new IllegalArgumentException("illegal use of " + MARKER + " in " + seg);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1554
                    }
37944
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 37848
diff changeset
  1555
                    Path prefix = getPath(seg.substring(0, markStart - 1));
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1556
                    Path suffix;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1557
                    int markEnd = markStart + MARKER.length();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1558
                    if (markEnd == seg.length()) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1559
                        suffix = null;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1560
                    } else if (!isSeparator(seg.charAt(markEnd))
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1561
                            || seg.indexOf(MARKER, markEnd) != -1) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1562
                        throw new IllegalArgumentException("illegal use of " + MARKER + " in " + seg);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1563
                    } else {
37944
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 37848
diff changeset
  1564
                        suffix = getPath(seg.substring(markEnd + 1));
44690
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 44573
diff changeset
  1565
                        anySuffix = true;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1566
                    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1567
                    add(map, prefix, suffix);
44690
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 44573
diff changeset
  1568
                    if (suffix == null) {
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 44573
diff changeset
  1569
                        noSuffixPaths.add(prefix);
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 44573
diff changeset
  1570
                    }
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1571
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1572
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1573
44690
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 44573
diff changeset
  1574
            initModuleTable(map);
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 44573
diff changeset
  1575
            paths = anySuffix ? null : noSuffixPaths;
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 44573
diff changeset
  1576
        }
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 44573
diff changeset
  1577
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 44573
diff changeset
  1578
        private void initModuleTable(Map<String, List<Path>> map) {
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1579
            moduleTable = new ModuleTable();
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1580
            map.forEach((modName, modPath) -> {
44063
5f0cf4126949 8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents: 44021
diff changeset
  1581
                boolean hasModuleInfo = modPath.stream().anyMatch(checkModuleInfo);
5f0cf4126949 8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents: 44021
diff changeset
  1582
                if (hasModuleInfo) {
5f0cf4126949 8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents: 44021
diff changeset
  1583
                    String locnName = location.getName() + "[" + modName + "]";
5f0cf4126949 8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents: 44021
diff changeset
  1584
                    ModuleLocationHandler l = new ModuleLocationHandler(this, locnName, modName,
5f0cf4126949 8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents: 44021
diff changeset
  1585
                            modPath, false);
5f0cf4126949 8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents: 44021
diff changeset
  1586
                    moduleTable.add(l);
5f0cf4126949 8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents: 44021
diff changeset
  1587
                }
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1588
            });
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1589
        }
44063
5f0cf4126949 8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents: 44021
diff changeset
  1590
        //where:
5f0cf4126949 8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents: 44021
diff changeset
  1591
            private final Predicate<Path> checkModuleInfo =
5f0cf4126949 8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents: 44021
diff changeset
  1592
                    p -> Files.exists(p.resolve("module-info.java"));
5f0cf4126949 8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents: 44021
diff changeset
  1593
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1594
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1595
        private boolean isSeparator(char ch) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1596
            // allow both separators on Windows
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1597
            return (ch == File.separatorChar) || (ch == '/');
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1598
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1599
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1600
        void add(Map<String, List<Path>> map, Path prefix, Path suffix) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1601
            if (!Files.isDirectory(prefix)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1602
                if (warn) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1603
                    String key = Files.exists(prefix)
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1604
                            ? "dir.path.element.not.directory"
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1605
                            : "dir.path.element.not.found";
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1606
                    log.warning(Lint.LintCategory.PATH, key, prefix);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1607
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1608
                return;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1609
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1610
            try (DirectoryStream<Path> stream = Files.newDirectoryStream(prefix, path -> Files.isDirectory(path))) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1611
                for (Path entry: stream) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1612
                    Path path = (suffix == null) ? entry : entry.resolve(suffix);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1613
                    if (Files.isDirectory(path)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1614
                        String name = entry.getFileName().toString();
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1615
                        List<Path> paths = map.get(name);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1616
                        if (paths == null)
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1617
                            map.put(name, paths = new ArrayList<>());
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1618
                        paths.add(path);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1619
                    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1620
                }
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
                // TODO? What to do?
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1623
                System.err.println(e);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1624
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1625
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1626
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1627
        private void expandBraces(String value, Collection<String> results) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1628
            int depth = 0;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1629
            int start = -1;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1630
            String prefix = null;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1631
            String suffix = null;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1632
            for (int i = 0; i < value.length(); i++) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1633
                switch (value.charAt(i)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1634
                    case '{':
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1635
                        depth++;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1636
                        if (depth == 1) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1637
                            prefix = value.substring(0, i);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1638
                            suffix = value.substring(getMatchingBrace(value, i) + 1);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1639
                            start = i + 1;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1640
                        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1641
                        break;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1642
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1643
                    case ',':
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1644
                        if (depth == 1) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1645
                            String elem = value.substring(start, i);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1646
                            expandBraces(prefix + elem + suffix, results);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1647
                            start = i + 1;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1648
                        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1649
                        break;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1650
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1651
                    case '}':
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1652
                        switch (depth) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1653
                            case 0:
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1654
                                throw new IllegalArgumentException("mismatched braces");
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1655
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1656
                            case 1:
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1657
                                String elem = value.substring(start, i);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1658
                                expandBraces(prefix + elem + suffix, results);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1659
                                return;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1660
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1661
                            default:
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1662
                                depth--;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1663
                        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1664
                        break;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1665
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1666
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1667
            if (depth > 0)
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1668
                throw new IllegalArgumentException("mismatched braces");
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1669
            results.add(value);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1670
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1671
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1672
        int getMatchingBrace(String value, int offset) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1673
            int depth = 1;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1674
            for (int i = offset + 1; i < value.length(); i++) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1675
                switch (value.charAt(i)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1676
                    case '{':
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1677
                        depth++;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1678
                        break;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1679
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1680
                    case '}':
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1681
                        if (--depth == 0)
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1682
                            return i;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1683
                        break;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1684
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1685
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1686
            throw new IllegalArgumentException("mismatched braces");
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1687
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1688
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1689
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1690
        boolean isSet() {
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1691
            return (moduleTable != null);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1692
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1693
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1694
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1695
        Collection<Path> getPaths() {
44690
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 44573
diff changeset
  1696
            if (paths == null) {
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 44573
diff changeset
  1697
                // This may occur for a complex setting with --module-source-path option
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 44573
diff changeset
  1698
                // i.e. one that cannot be represented by a simple series of paths.
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 44573
diff changeset
  1699
                throw new IllegalStateException("paths not available");
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 44573
diff changeset
  1700
            }
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 44573
diff changeset
  1701
            return paths;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1702
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1703
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1704
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1705
        void setPaths(Iterable<? extends Path> files) throws IOException {
44690
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 44573
diff changeset
  1706
            Map<String, List<Path>> map = new LinkedHashMap<>();
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 44573
diff changeset
  1707
            List<Path> newPaths = new ArrayList<>();
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 44573
diff changeset
  1708
            for (Path file : files) {
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 44573
diff changeset
  1709
                add(map, file, null);
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 44573
diff changeset
  1710
                newPaths.add(file);
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 44573
diff changeset
  1711
            }
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 44573
diff changeset
  1712
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 44573
diff changeset
  1713
            initModuleTable(map);
47702
cf8310446245 8139607: -release option forces StandardJavaFileManager
jlahoda
parents: 47363
diff changeset
  1714
            explicit = true;
44690
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 44573
diff changeset
  1715
            paths = Collections.unmodifiableList(newPaths);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1716
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1717
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1718
        @Override
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1719
        void setPathsForModule(String name, Iterable<? extends Path> paths) throws IOException {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1720
            List<Path> validPaths = checkPaths(paths);
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1721
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1722
            if (moduleTable == null)
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1723
                moduleTable = new ModuleTable();
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1724
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1725
            ModuleLocationHandler l = moduleTable.get(name);
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1726
            if (l == null) {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1727
                l = new ModuleLocationHandler(this,
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1728
                        location.getName() + "[" + name + "]",
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1729
                        name,
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1730
                        validPaths,
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1731
                        true);
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1732
                moduleTable.add(l);
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1733
           } else {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1734
                l.searchPath = validPaths;
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1735
                moduleTable.updatePaths(l);
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1736
            }
47702
cf8310446245 8139607: -release option forces StandardJavaFileManager
jlahoda
parents: 47363
diff changeset
  1737
            explicit = true;
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1738
        }
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1739
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1740
        private List<Path> checkPaths(Iterable<? extends Path> paths) throws IOException {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1741
            Objects.requireNonNull(paths);
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1742
            List<Path> validPaths = new ArrayList<>();
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1743
            for (Path p : paths) {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1744
                validPaths.add(checkDirectory(p));
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1745
            }
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1746
            return validPaths;
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1747
        }
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1748
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1749
        @Override
42261
bb52b5514ad5 8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents: 41861
diff changeset
  1750
        Location getLocationForModule(String name) {
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1751
            return (moduleTable == null) ? null : moduleTable.get(name);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1752
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1753
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1754
        @Override
44063
5f0cf4126949 8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents: 44021
diff changeset
  1755
        Location getLocationForModule(Path file) {
5f0cf4126949 8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents: 44021
diff changeset
  1756
            return (moduleTable == null) ? null : moduleTable.get(file);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1757
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1758
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1759
        @Override
42261
bb52b5514ad5 8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents: 41861
diff changeset
  1760
        Iterable<Set<Location>> listLocationsForModules() {
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1761
            if (moduleTable == null)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1762
                return Collections.emptySet();
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1763
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1764
            return Collections.singleton(moduleTable.locations());
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1765
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1766
44822
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
  1767
        @Override
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
  1768
        boolean contains(Path file) throws IOException {
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
  1769
            return (moduleTable == null) ? false : moduleTable.contains(file);
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
  1770
        }
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
  1771
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1772
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1773
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1774
    private class SystemModulesLocationHandler extends BasicLocationHandler {
37944
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 37848
diff changeset
  1775
        private Path systemJavaHome;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1776
        private Path modules;
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1777
        private ModuleTable moduleTable;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1778
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1779
        SystemModulesLocationHandler() {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1780
            super(StandardLocation.SYSTEM_MODULES, Option.SYSTEM);
37944
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 37848
diff changeset
  1781
            systemJavaHome = Locations.javaHome;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1782
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1783
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1784
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1785
        boolean handleOption(Option option, String value) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1786
            if (!options.contains(option)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1787
                return false;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1788
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1789
47702
cf8310446245 8139607: -release option forces StandardJavaFileManager
jlahoda
parents: 47363
diff changeset
  1790
            explicit = true;
cf8310446245 8139607: -release option forces StandardJavaFileManager
jlahoda
parents: 47363
diff changeset
  1791
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1792
            if (value == null) {
37944
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 37848
diff changeset
  1793
                systemJavaHome = Locations.javaHome;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1794
            } else if (value.equals("none")) {
37944
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 37848
diff changeset
  1795
                systemJavaHome = null;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1796
            } else {
37944
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 37848
diff changeset
  1797
                update(getPath(value));
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1798
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1799
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1800
            modules = null;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1801
            return true;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1802
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1803
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1804
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1805
        Collection<Path> getPaths() {
37944
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 37848
diff changeset
  1806
            return (systemJavaHome == null) ? null : Collections.singleton(systemJavaHome);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1807
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1808
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1809
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1810
        void setPaths(Iterable<? extends Path> files) throws IOException {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1811
            if (files == null) {
37944
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 37848
diff changeset
  1812
                systemJavaHome = null;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1813
            } else {
47702
cf8310446245 8139607: -release option forces StandardJavaFileManager
jlahoda
parents: 47363
diff changeset
  1814
                explicit = true;
cf8310446245 8139607: -release option forces StandardJavaFileManager
jlahoda
parents: 47363
diff changeset
  1815
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1816
                Path dir = checkSingletonDirectory(files);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1817
                update(dir);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1818
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1819
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1820
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1821
        @Override
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1822
        void setPathsForModule(String name, Iterable<? extends Path> paths) throws IOException {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1823
            List<Path> checkedPaths = checkPaths(paths);
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1824
            initSystemModules();
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1825
            ModuleLocationHandler l = moduleTable.get(name);
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1826
            if (l == null) {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1827
                l = new ModuleLocationHandler(this,
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1828
                        location.getName() + "[" + name + "]",
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1829
                        name,
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1830
                        checkedPaths,
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1831
                        true);
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1832
                moduleTable.add(l);
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1833
           } else {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1834
                l.searchPath = checkedPaths;
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1835
                moduleTable.updatePaths(l);
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1836
            }
47702
cf8310446245 8139607: -release option forces StandardJavaFileManager
jlahoda
parents: 47363
diff changeset
  1837
            explicit = true;
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1838
        }
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1839
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1840
        private List<Path> checkPaths(Iterable<? extends Path> paths) throws IOException {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1841
            Objects.requireNonNull(paths);
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1842
            List<Path> validPaths = new ArrayList<>();
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1843
            for (Path p : paths) {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1844
                validPaths.add(checkDirectory(p));
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1845
            }
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1846
            return validPaths;
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1847
        }
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1848
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1849
        private void update(Path p) {
42404
c4a34c2a656c 8169816: Move src.zip and jrt-fs.jar under the lib directory
mchung
parents: 42261
diff changeset
  1850
            if (!isCurrentPlatform(p) && !Files.exists(p.resolve("lib").resolve("jrt-fs.jar")) &&
c4a34c2a656c 8169816: Move src.zip and jrt-fs.jar under the lib directory
mchung
parents: 42261
diff changeset
  1851
                    !Files.exists(systemJavaHome.resolve("modules")))
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1852
                throw new IllegalArgumentException(p.toString());
37944
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 37848
diff changeset
  1853
            systemJavaHome = p;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1854
            modules = null;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1855
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1856
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1857
        private boolean isCurrentPlatform(Path p) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1858
            try {
37944
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 37848
diff changeset
  1859
                return Files.isSameFile(p, Locations.javaHome);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1860
            } catch (IOException ex) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1861
                throw new IllegalArgumentException(p.toString(), ex);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1862
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1863
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1864
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1865
        @Override
42261
bb52b5514ad5 8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents: 41861
diff changeset
  1866
        Location getLocationForModule(String name) throws IOException {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1867
            initSystemModules();
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1868
            return moduleTable.get(name);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1869
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1870
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1871
        @Override
44063
5f0cf4126949 8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents: 44021
diff changeset
  1872
        Location getLocationForModule(Path file) throws IOException {
43772
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 43771
diff changeset
  1873
            initSystemModules();
44063
5f0cf4126949 8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents: 44021
diff changeset
  1874
            return moduleTable.get(file);
43772
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 43771
diff changeset
  1875
        }
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 43771
diff changeset
  1876
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 43771
diff changeset
  1877
        @Override
42261
bb52b5514ad5 8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents: 41861
diff changeset
  1878
        Iterable<Set<Location>> listLocationsForModules() throws IOException {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1879
            initSystemModules();
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1880
            return Collections.singleton(moduleTable.locations());
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1881
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1882
44822
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
  1883
        @Override
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
  1884
        boolean contains(Path file) throws IOException {
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
  1885
            initSystemModules();
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
  1886
            return moduleTable.contains(file);
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
  1887
        }
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
  1888
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1889
        private void initSystemModules() throws IOException {
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1890
            if (moduleTable != null)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1891
                return;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1892
37944
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 37848
diff changeset
  1893
            if (systemJavaHome == null) {
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1894
                moduleTable = new ModuleTable();
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1895
                return;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1896
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1897
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1898
            if (modules == null) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1899
                try {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1900
                    URI jrtURI = URI.create("jrt:/");
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1901
                    FileSystem jrtfs;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1902
37944
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 37848
diff changeset
  1903
                    if (isCurrentPlatform(systemJavaHome)) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1904
                        jrtfs = FileSystems.getFileSystem(jrtURI);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1905
                    } else {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1906
                        try {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1907
                            Map<String, String> attrMap =
37944
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 37848
diff changeset
  1908
                                    Collections.singletonMap("java.home", systemJavaHome.toString());
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1909
                            jrtfs = FileSystems.newFileSystem(jrtURI, attrMap);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1910
                        } catch (ProviderNotFoundException ex) {
37944
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 37848
diff changeset
  1911
                            URL javaHomeURL = systemJavaHome.resolve("jrt-fs.jar").toUri().toURL();
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1912
                            ClassLoader currentLoader = Locations.class.getClassLoader();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1913
                            URLClassLoader fsLoader =
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1914
                                    new URLClassLoader(new URL[] {javaHomeURL}, currentLoader);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1915
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1916
                            jrtfs = FileSystems.newFileSystem(jrtURI, Collections.emptyMap(), fsLoader);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1917
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1918
                            closeables.add(fsLoader);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1919
                        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1920
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1921
                        closeables.add(jrtfs);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1922
                    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1923
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1924
                    modules = jrtfs.getPath("/modules");
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1925
                } catch (FileSystemNotFoundException | ProviderNotFoundException e) {
37944
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 37848
diff changeset
  1926
                    modules = systemJavaHome.resolve("modules");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1927
                    if (!Files.exists(modules))
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1928
                        throw new IOException("can't find system classes", e);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1929
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1930
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1931
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1932
            moduleTable = new ModuleTable();
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1933
            try (DirectoryStream<Path> stream = Files.newDirectoryStream(modules, Files::isDirectory)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1934
                for (Path entry : stream) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1935
                    String moduleName = entry.getFileName().toString();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1936
                    String name = location.getName() + "[" + moduleName + "]";
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1937
                    ModuleLocationHandler h = new ModuleLocationHandler(this,
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1938
                            name, moduleName, Collections.singletonList(entry), false);
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1939
                    moduleTable.add(h);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1940
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1941
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1942
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1943
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  1944
43772
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 43771
diff changeset
  1945
    private class PatchModulesLocationHandler extends BasicLocationHandler {
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1946
        private final ModuleTable moduleTable = new ModuleTable();
43772
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 43771
diff changeset
  1947
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 43771
diff changeset
  1948
        PatchModulesLocationHandler() {
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 43771
diff changeset
  1949
            super(StandardLocation.PATCH_MODULE_PATH, Option.PATCH_MODULE);
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 43771
diff changeset
  1950
        }
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 43771
diff changeset
  1951
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 43771
diff changeset
  1952
        @Override
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 43771
diff changeset
  1953
        boolean handleOption(Option option, String value) {
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 43771
diff changeset
  1954
            if (!options.contains(option)) {
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 43771
diff changeset
  1955
                return false;
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 43771
diff changeset
  1956
            }
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 43771
diff changeset
  1957
47702
cf8310446245 8139607: -release option forces StandardJavaFileManager
jlahoda
parents: 47363
diff changeset
  1958
            explicit = true;
cf8310446245 8139607: -release option forces StandardJavaFileManager
jlahoda
parents: 47363
diff changeset
  1959
44063
5f0cf4126949 8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents: 44021
diff changeset
  1960
            moduleTable.clear();
5f0cf4126949 8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents: 44021
diff changeset
  1961
43772
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 43771
diff changeset
  1962
            // Allow an extended syntax for --patch-module consisting of a series
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 43771
diff changeset
  1963
            // of values separated by NULL characters. This is to facilitate
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 43771
diff changeset
  1964
            // supporting deferred file manager options on the command line.
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 43771
diff changeset
  1965
            // See Option.PATCH_MODULE for the code that composes these multiple
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 43771
diff changeset
  1966
            // values.
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 43771
diff changeset
  1967
            for (String v : value.split("\0")) {
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 43771
diff changeset
  1968
                int eq = v.indexOf('=');
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 43771
diff changeset
  1969
                if (eq > 0) {
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 43771
diff changeset
  1970
                    String moduleName = v.substring(0, eq);
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 43771
diff changeset
  1971
                    SearchPath mPatchPath = new SearchPath()
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 43771
diff changeset
  1972
                            .addFiles(v.substring(eq + 1));
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 43771
diff changeset
  1973
                    String name = location.getName() + "[" + moduleName + "]";
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1974
                    ModuleLocationHandler h = new ModuleLocationHandler(this, name,
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1975
                            moduleName, mPatchPath, false);
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1976
                    moduleTable.add(h);
43772
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 43771
diff changeset
  1977
                } else {
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 43771
diff changeset
  1978
                    // Should not be able to get here;
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 43771
diff changeset
  1979
                    // this should be caught and handled in Option.PATCH_MODULE
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 43771
diff changeset
  1980
                    log.error(Errors.LocnInvalidArgForXpatch(value));
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 43771
diff changeset
  1981
                }
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 43771
diff changeset
  1982
            }
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 43771
diff changeset
  1983
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 43771
diff changeset
  1984
            return true;
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 43771
diff changeset
  1985
        }
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 43771
diff changeset
  1986
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 43771
diff changeset
  1987
        @Override
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 43771
diff changeset
  1988
        boolean isSet() {
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  1989
            return !moduleTable.isEmpty();
43772
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 43771
diff changeset
  1990
        }
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 43771
diff changeset
  1991
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 43771
diff changeset
  1992
        @Override
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 43771
diff changeset
  1993
        Collection<Path> getPaths() {
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 43771
diff changeset
  1994
            throw new UnsupportedOperationException();
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 43771
diff changeset
  1995
        }
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 43771
diff changeset
  1996
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 43771
diff changeset
  1997
        @Override
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 43771
diff changeset
  1998
        void setPaths(Iterable<? extends Path> files) throws IOException {
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 43771
diff changeset
  1999
            throw new UnsupportedOperationException();
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 43771
diff changeset
  2000
        }
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 43771
diff changeset
  2001
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  2002
        @Override // defined by LocationHandler
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  2003
        void setPathsForModule(String moduleName, Iterable<? extends Path> files) throws IOException {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  2004
            throw new UnsupportedOperationException(); // not yet
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  2005
        }
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  2006
43772
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 43771
diff changeset
  2007
        @Override
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 43771
diff changeset
  2008
        Location getLocationForModule(String name) throws IOException {
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  2009
            return moduleTable.get(name);
43772
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 43771
diff changeset
  2010
        }
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 43771
diff changeset
  2011
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 43771
diff changeset
  2012
        @Override
44063
5f0cf4126949 8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents: 44021
diff changeset
  2013
        Location getLocationForModule(Path file) throws IOException {
5f0cf4126949 8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents: 44021
diff changeset
  2014
            return moduleTable.get(file);
43772
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 43771
diff changeset
  2015
        }
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 43771
diff changeset
  2016
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 43771
diff changeset
  2017
        @Override
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 43771
diff changeset
  2018
        Iterable<Set<Location>> listLocationsForModules() throws IOException {
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  2019
            return Collections.singleton(moduleTable.locations());
43772
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 43771
diff changeset
  2020
        }
44822
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
  2021
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
  2022
        @Override
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
  2023
        boolean contains(Path file) throws IOException {
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
  2024
            return moduleTable.contains(file);
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
  2025
        }
43772
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 43771
diff changeset
  2026
    }
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 43771
diff changeset
  2027
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
  2028
    Map<Location, LocationHandler> handlersForLocation;
11314
b612aaca08d0 7120736: refactor javac option handling
jjg
parents: 10819
diff changeset
  2029
    Map<Option, LocationHandler> handlersForOption;
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
  2030
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
  2031
    void initHandlers() {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22153
diff changeset
  2032
        handlersForLocation = new HashMap<>();
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22153
diff changeset
  2033
        handlersForOption = new EnumMap<>(Option.class);
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
  2034
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  2035
        BasicLocationHandler[] handlers = {
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
  2036
            new BootClassPathLocationHandler(),
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
  2037
            new ClassPathLocationHandler(),
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 40302
diff changeset
  2038
            new SimpleLocationHandler(StandardLocation.SOURCE_PATH, Option.SOURCE_PATH),
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 40302
diff changeset
  2039
            new SimpleLocationHandler(StandardLocation.ANNOTATION_PROCESSOR_PATH, Option.PROCESSOR_PATH),
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 40302
diff changeset
  2040
            new SimpleLocationHandler(StandardLocation.ANNOTATION_PROCESSOR_MODULE_PATH, Option.PROCESSOR_MODULE_PATH),
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  2041
            new OutputLocationHandler(StandardLocation.CLASS_OUTPUT, Option.D),
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  2042
            new OutputLocationHandler(StandardLocation.SOURCE_OUTPUT, Option.S),
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  2043
            new OutputLocationHandler(StandardLocation.NATIVE_HEADER_OUTPUT, Option.H),
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  2044
            new ModuleSourcePathLocationHandler(),
43772
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 43771
diff changeset
  2045
            new PatchModulesLocationHandler(),
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 40302
diff changeset
  2046
            new ModulePathLocationHandler(StandardLocation.UPGRADE_MODULE_PATH, Option.UPGRADE_MODULE_PATH),
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 40302
diff changeset
  2047
            new ModulePathLocationHandler(StandardLocation.MODULE_PATH, Option.MODULE_PATH),
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  2048
            new SystemModulesLocationHandler(),
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
  2049
        };
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2050
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  2051
        for (BasicLocationHandler h : handlers) {
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
  2052
            handlersForLocation.put(h.location, h);
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
  2053
            for (Option o : h.options) {
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
  2054
                handlersForOption.put(o, h);
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
  2055
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2056
        }
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
  2057
    }
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
  2058
29780
8f8e54a1fa20 8076420: Consolidate javac file handling in javac.file package
jjg
parents: 29291
diff changeset
  2059
    boolean handleOption(Option option, String value) {
43772
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 43771
diff changeset
  2060
        LocationHandler h = handlersForOption.get(option);
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 43771
diff changeset
  2061
        return (h == null ? false : h.handleOption(option, value));
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  2062
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  2063
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  2064
    boolean hasLocation(Location location) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  2065
        LocationHandler h = getHandler(location);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  2066
        return (h == null ? false : h.isSet());
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
  2067
    }
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
  2068
47702
cf8310446245 8139607: -release option forces StandardJavaFileManager
jlahoda
parents: 47363
diff changeset
  2069
    boolean hasExplicitLocation(Location location) {
cf8310446245 8139607: -release option forces StandardJavaFileManager
jlahoda
parents: 47363
diff changeset
  2070
        LocationHandler h = getHandler(location);
cf8310446245 8139607: -release option forces StandardJavaFileManager
jlahoda
parents: 47363
diff changeset
  2071
        return (h == null ? false : h.isExplicit());
cf8310446245 8139607: -release option forces StandardJavaFileManager
jlahoda
parents: 47363
diff changeset
  2072
    }
cf8310446245 8139607: -release option forces StandardJavaFileManager
jlahoda
parents: 47363
diff changeset
  2073
27852
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
  2074
    Collection<Path> getLocation(Location location) {
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
  2075
        LocationHandler h = getHandler(location);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  2076
        return (h == null ? null : h.getPaths());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2077
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2078
27852
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
  2079
    Path getOutputLocation(Location location) {
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
  2080
        if (!location.isOutputLocation()) {
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
  2081
            throw new IllegalArgumentException();
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
  2082
        }
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
  2083
        LocationHandler h = getHandler(location);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
  2084
        return ((OutputLocationHandler) h).outputDir;
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
  2085
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2086
27852
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
  2087
    void setLocation(Location location, Iterable<? extends Path> files) throws IOException {
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
  2088
        LocationHandler h = getHandler(location);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
  2089
        if (h == null) {
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
  2090
            if (location.isOutputLocation()) {
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
  2091
                h = new OutputLocationHandler(location);
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
  2092
            } else {
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
  2093
                h = new SimpleLocationHandler(location);
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
  2094
            }
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
  2095
            handlersForLocation.put(location, h);
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
  2096
        }
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  2097
        h.setPaths(files);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  2098
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  2099
42261
bb52b5514ad5 8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents: 41861
diff changeset
  2100
    Location getLocationForModule(Location location, String name) throws IOException {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  2101
        LocationHandler h = getHandler(location);
42261
bb52b5514ad5 8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents: 41861
diff changeset
  2102
        return (h == null ? null : h.getLocationForModule(name));
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  2103
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  2104
44063
5f0cf4126949 8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents: 44021
diff changeset
  2105
    Location getLocationForModule(Location location, Path file) throws IOException {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  2106
        LocationHandler h = getHandler(location);
44063
5f0cf4126949 8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents: 44021
diff changeset
  2107
        return (h == null ? null : h.getLocationForModule(file));
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  2108
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  2109
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  2110
    void setLocationForModule(Location location, String moduleName,
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  2111
            Iterable<? extends Path> files) throws IOException {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  2112
        LocationHandler h = getHandler(location);
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  2113
        if (h == null) {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  2114
            if (location.isOutputLocation()) {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  2115
                h = new OutputLocationHandler(location);
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  2116
            } else {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  2117
                h = new ModulePathLocationHandler(location);
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  2118
            }
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  2119
            handlersForLocation.put(location, h);
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  2120
        }
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  2121
        h.setPathsForModule(moduleName, files);
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  2122
    }
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 43772
diff changeset
  2123
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  2124
    String inferModuleName(Location location) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  2125
        LocationHandler h = getHandler(location);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  2126
        return (h == null ? null : h.inferModuleName());
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  2127
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  2128
42261
bb52b5514ad5 8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents: 41861
diff changeset
  2129
    Iterable<Set<Location>> listLocationsForModules(Location location) throws IOException {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  2130
        LocationHandler h = getHandler(location);
42261
bb52b5514ad5 8163190: Clarify JavaFileManager use of \"module location\"
jjg
parents: 41861
diff changeset
  2131
        return (h == null ? null : h.listLocationsForModules());
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
  2132
    }
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
  2133
44822
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
  2134
    boolean contains(Location location, Path file) throws IOException {
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
  2135
        LocationHandler h = getHandler(location);
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
  2136
        if (h == null)
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
  2137
            throw new IllegalArgumentException("unknown location");
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
  2138
        return h.contains(file);
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
  2139
    }
2f24758e7ae0 8176327: javac produces wrong module-info
jjg
parents: 44690
diff changeset
  2140
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
  2141
    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
  2142
        Objects.requireNonNull(location);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  2143
        return (location instanceof LocationHandler)
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  2144
                ? (LocationHandler) location
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  2145
                : handlersForLocation.get(location);
10818
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
  2146
    }
e95eb04c68cc 7104039: refactor/cleanup javac Paths class
jjg
parents: 10813
diff changeset
  2147
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
  2148
    /**
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
  2149
     * Is this the name of an archive file?
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
  2150
     */
27852
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
  2151
    private boolean isArchive(Path file) {
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27226
diff changeset
  2152
        String n = StringUtils.toLowerCase(file.getFileName().toString());
1208
5072b0dd3d52 6743107: clean up use of static caches in file manager
jjg
parents: 735
diff changeset
  2153
        return fsInfo.isFile(file)
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 22163
diff changeset
  2154
                && (n.endsWith(".jar") || n.endsWith(".zip"));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2155
    }
4937
2fc03fb01efa 6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents: 4548
diff changeset
  2156
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  2157
    static Path normalize(Path p) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  2158
        try {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  2159
            return p.toRealPath();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  2160
        } catch (IOException e) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  2161
            return p.toAbsolutePath().normalize();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  2162
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34752
diff changeset
  2163
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2164
}