test/langtools/tools/javac/file/SetLocationForModule.java
author jjg
Fri, 31 Aug 2018 14:54:42 -0700
changeset 51615 afbb33428df7
parent 47702 cf8310446245
permissions -rw-r--r--
8208608: Update --module-source-path to allow explicit source paths for specific modules Reviewed-by: jlahoda
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
     1
/*
51615
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 47702
diff changeset
     2
 * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
     4
 *
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
     8
 *
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    13
 * accompanied this code).
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    14
 *
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    18
 *
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    21
 * questions.
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    22
 */
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    23
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    24
/**
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    25
 * @test
47363
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
    26
 * @bug 8173914 8188035
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    27
 * @summary JavaFileManager.setLocationForModule
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    28
 * @modules jdk.compiler/com.sun.tools.javac.api
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    29
 *          jdk.compiler/com.sun.tools.javac.main
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    30
 * @library /tools/lib
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    31
 * @build toolbox.JavacTask toolbox.TestRunner toolbox.ToolBox SetLocationForModule
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    32
 * @run main SetLocationForModule
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    33
 */
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    34
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    35
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    36
import java.io.FileNotFoundException;
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    37
import java.io.IOException;
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    38
import java.nio.file.Files;
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    39
import java.nio.file.Path;
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    40
import java.nio.file.Paths;
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    41
import java.util.ArrayList;
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    42
import java.util.Collections;
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    43
import java.util.List;
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    44
import java.util.Objects;
47363
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
    45
import java.util.Set;
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    46
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    47
import javax.tools.JavaCompiler;
47363
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
    48
import javax.tools.JavaFileManager;
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    49
import javax.tools.JavaFileManager.Location;
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    50
import javax.tools.StandardJavaFileManager;
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    51
import javax.tools.StandardLocation;
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    52
import javax.tools.ToolProvider;
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    53
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    54
import toolbox.JavacTask;
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    55
import toolbox.TestRunner;
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    56
import toolbox.TestRunner.Test;
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    57
import toolbox.ToolBox;
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    58
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    59
public class SetLocationForModule extends TestRunner {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    60
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    61
    public static void main(String... args) throws Exception {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    62
        new SetLocationForModule().runTests(m -> new Object[] { Paths.get(m.getName()) });
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    63
    }
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    64
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    65
    public SetLocationForModule() {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    66
        super(System.err);
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    67
    }
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    68
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    69
    private final JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    70
    private final ToolBox tb = new ToolBox();
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    71
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    72
    @Test
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    73
    public void testBasic(Path base) throws IOException {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    74
        try (StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null)) {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    75
            Location[] locns = {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    76
                StandardLocation.SOURCE_PATH,
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    77
                StandardLocation.CLASS_PATH,
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    78
                StandardLocation.PLATFORM_CLASS_PATH,
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    79
            };
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    80
            // set a value
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    81
            Path out = Files.createDirectories(base.resolve("out"));
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    82
            for (Location locn : locns) {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    83
                checkException("unsupported for location",
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    84
                        IllegalArgumentException.class,
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    85
                        "location is not an output location or a module-oriented location: " + locn,
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    86
                        () -> fm.setLocationForModule(locn, "m", List.of(out)));
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    87
            }
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    88
        }
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    89
    }
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    90
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    91
    @Test
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    92
    public void testModulePath(Path base) throws IOException {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    93
        try (StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null)) {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    94
            Path src = base.resolve("src");
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    95
            Path src_m = src.resolve("m");
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    96
            tb.writeJavaFiles(src_m, "module m { }");
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    97
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    98
            Location locn = StandardLocation.MODULE_PATH;
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
    99
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   100
            Path modules1 = Files.createDirectories(base.resolve("modules1"));
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   101
            new JavacTask(tb)
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   102
                    .outdir(modules1)
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   103
                    .options("--module-source-path", src.toString())
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   104
                    .files(tb.findJavaFiles(src))
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   105
                    .run();
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   106
            fm.setLocationFromPaths(locn, List.of(modules1));
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   107
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   108
            Location m = fm.getLocationForModule(locn, "m");
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   109
            checkEqual("default setting",
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   110
                    fm.getLocationAsPaths(m), modules1.resolve("m"));
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   111
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   112
            Path override1 = Files.createDirectories(base.resolve("override1"));
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   113
            fm.setLocationForModule(locn, "m", List.of(override1));
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   114
            checkEqual("override setting 1",
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   115
                    fm.getLocationAsPaths(m), override1);
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   116
47363
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
   117
            checkEqual("override setting 1b",
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
   118
                       fm.getLocationAsPaths(fm.listLocationsForModules(locn).iterator().next().iterator().next()),
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
   119
                       override1);
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
   120
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
   121
            try (StandardJavaFileManager fm2 = comp.getStandardFileManager(null, null, null)) {
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
   122
                fm2.setLocationForModule(locn, "m", List.of(override1));
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
   123
                checkEqual("override setting 2",
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
   124
                           fm2.getLocationAsPaths(m), override1);
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
   125
47702
cf8310446245 8139607: -release option forces StandardJavaFileManager
jlahoda
parents: 47363
diff changeset
   126
                Location firstLocation =
cf8310446245 8139607: -release option forces StandardJavaFileManager
jlahoda
parents: 47363
diff changeset
   127
                        fm2.listLocationsForModules(locn).iterator().next().iterator().next();
cf8310446245 8139607: -release option forces StandardJavaFileManager
jlahoda
parents: 47363
diff changeset
   128
47363
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
   129
                checkEqual("override setting 2b",
47702
cf8310446245 8139607: -release option forces StandardJavaFileManager
jlahoda
parents: 47363
diff changeset
   130
                           fm2.getLocationAsPaths(firstLocation),
47363
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
   131
                           override1);
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
   132
            }
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
   133
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   134
            Path override2 = Files.createDirectories(base.resolve("override2"));
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   135
            fm.setLocationFromPaths(m, List.of(override2));
47363
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
   136
            checkEqual("override setting 3",
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   137
                    fm.getLocationAsPaths(m), override2);
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   138
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   139
            Path modules2 = Files.createDirectories(base.resolve("modules2"));
47363
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
   140
            new JavacTask(tb)
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
   141
                    .outdir(modules2)
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
   142
                    .options("--module-source-path", src.toString())
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
   143
                    .files(tb.findJavaFiles(src))
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
   144
                    .run();
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   145
            fm.setLocationFromPaths(locn, List.of(modules2));
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   146
47363
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
   147
            m = fm.getLocationForModule(locn, "m");
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
   148
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   149
            checkEqual("updated setting",
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   150
                    fm.getLocationAsPaths(m), modules2.resolve("m"));
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   151
        }
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   152
    }
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   153
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   154
    @Test
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   155
    public void testModuleSourcePath(Path base) throws IOException {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   156
        try (StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null)) {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   157
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   158
            Location locn = StandardLocation.MODULE_SOURCE_PATH;
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   159
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   160
            Path src1 = Files.createDirectories(base.resolve("src1"));
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   161
            Path src1_m = src1.resolve("m");
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   162
            tb.writeJavaFiles(src1_m, "module m { }");
51615
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 47702
diff changeset
   163
            fm.setLocationFromPaths(locn, List.of(src1));
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   164
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   165
            Location m = fm.getLocationForModule(locn, "m");
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   166
            checkEqual("default setting",
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   167
                    fm.getLocationAsPaths(m), src1.resolve("m"));
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   168
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   169
            Path override1 = Files.createDirectories(base.resolve("override1"));
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   170
            tb.writeJavaFiles(override1, "module m { }");
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   171
            fm.setLocationForModule(locn, "m", List.of(override1));
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   172
            checkEqual("override setting 1",
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   173
                    fm.getLocationAsPaths(m), override1);
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   174
47363
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
   175
            checkEqual("override setting 1b",
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
   176
                       fm.getLocationAsPaths(fm.listLocationsForModules(locn).iterator().next().iterator().next()),
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
   177
                       override1);
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
   178
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   179
            Path override2 = Files.createDirectories(base.resolve("override2"));
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   180
            tb.writeJavaFiles(override2, "module m { }");
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   181
            fm.setLocationFromPaths(m, List.of(override2));
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   182
            checkEqual("override setting 2",
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   183
                    fm.getLocationAsPaths(m), override2);
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   184
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   185
            Path src2 = Files.createDirectories(base.resolve("src2"));
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   186
            Path src2_m = src2.resolve("m");
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   187
            tb.writeJavaFiles(src2_m, "module m { }");
51615
afbb33428df7 8208608: Update --module-source-path to allow explicit source paths for specific modules
jjg
parents: 47702
diff changeset
   188
            fm.setLocationFromPaths(locn, List.of(src2));
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   189
47363
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
   190
            m = fm.getLocationForModule(locn, "m");
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
   191
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   192
            checkEqual("updated setting",
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   193
                    fm.getLocationAsPaths(m), src2.resolve("m"));
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   194
        }
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   195
    }
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   196
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   197
    @Test
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   198
    public void testOutput(Path base) throws IOException {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   199
        try (StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null)) {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   200
            Location locn = StandardLocation.CLASS_OUTPUT;
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   201
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   202
            Path out1 = Files.createDirectories(base.resolve("out1"));
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   203
            fm.setLocationFromPaths(locn, List.of(out1));
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   204
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   205
            Location m = fm.getLocationForModule(locn, "m");
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   206
            checkEqual("default setting",
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   207
                    fm.getLocationAsPaths(m), out1.resolve("m"));
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   208
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   209
            Path override1 = Files.createDirectories(base.resolve("override1"));
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   210
            fm.setLocationForModule(locn, "m", List.of(override1));
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   211
            checkEqual("override setting 1",
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   212
                    fm.getLocationAsPaths(m), override1);
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   213
47363
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
   214
            checkEqual("override setting 1b",
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
   215
                       fm.getLocationAsPaths(fm.listLocationsForModules(locn).iterator().next().iterator().next()),
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
   216
                       override1);
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
   217
47702
cf8310446245 8139607: -release option forces StandardJavaFileManager
jlahoda
parents: 47363
diff changeset
   218
            try (StandardJavaFileManager fm2 = comp.getStandardFileManager(null, null, null)) {
cf8310446245 8139607: -release option forces StandardJavaFileManager
jlahoda
parents: 47363
diff changeset
   219
                fm2.setLocationForModule(locn, "m", List.of(override1));
cf8310446245 8139607: -release option forces StandardJavaFileManager
jlahoda
parents: 47363
diff changeset
   220
                checkEqual("override setting 1",
cf8310446245 8139607: -release option forces StandardJavaFileManager
jlahoda
parents: 47363
diff changeset
   221
                           fm2.getLocationAsPaths(m), override1);
cf8310446245 8139607: -release option forces StandardJavaFileManager
jlahoda
parents: 47363
diff changeset
   222
cf8310446245 8139607: -release option forces StandardJavaFileManager
jlahoda
parents: 47363
diff changeset
   223
                Location firstLocation =
cf8310446245 8139607: -release option forces StandardJavaFileManager
jlahoda
parents: 47363
diff changeset
   224
                        fm2.listLocationsForModules(locn).iterator().next().iterator().next();
cf8310446245 8139607: -release option forces StandardJavaFileManager
jlahoda
parents: 47363
diff changeset
   225
cf8310446245 8139607: -release option forces StandardJavaFileManager
jlahoda
parents: 47363
diff changeset
   226
                checkEqual("override setting 1b",
cf8310446245 8139607: -release option forces StandardJavaFileManager
jlahoda
parents: 47363
diff changeset
   227
                           fm2.getLocationAsPaths(firstLocation),
cf8310446245 8139607: -release option forces StandardJavaFileManager
jlahoda
parents: 47363
diff changeset
   228
                           override1);
cf8310446245 8139607: -release option forces StandardJavaFileManager
jlahoda
parents: 47363
diff changeset
   229
            }
cf8310446245 8139607: -release option forces StandardJavaFileManager
jlahoda
parents: 47363
diff changeset
   230
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   231
            Path override2 = Files.createDirectories(base.resolve("override2"));
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   232
            fm.setLocationFromPaths(m, List.of(override2));
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   233
            checkEqual("override setting 2",
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   234
                    fm.getLocationAsPaths(m), override2);
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   235
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   236
            Path out2 = Files.createDirectories(base.resolve("out2"));
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   237
            fm.setLocationFromPaths(locn, List.of(out2));
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   238
47363
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
   239
            m = fm.getLocationForModule(locn, "m");
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
   240
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   241
            checkEqual("updated setting",
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   242
                    fm.getLocationAsPaths(m), out2.resolve("m"));
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   243
        }
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   244
    }
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   245
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   246
    @Test
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   247
    public void testOutput_invalid(Path base) throws IOException {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   248
        try (StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null)) {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   249
            Location locn = StandardLocation.CLASS_OUTPUT;
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   250
            // set a top default
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   251
            Path out1 = Files.createDirectories(base.resolve("out1"));
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   252
            fm.setLocationFromPaths(locn, List.of(out1));
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   253
            // getLocnForModule
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   254
            Location m = fm.getLocationForModule(locn, "m");
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   255
            checkEqual("default setting",
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   256
                    fm.getLocationAsPaths(m), out1.resolve("m"));
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   257
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   258
            checkException("empty arg list",
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   259
                    IllegalArgumentException.class, "empty path for directory",
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   260
                    () -> fm.setLocationFromPaths(m, Collections.emptyList()));
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   261
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   262
            Path out2 = Files.createDirectories(base.resolve("out2"));
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   263
            checkException("empty arg list",
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   264
                    IllegalArgumentException.class, "path too long for directory",
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   265
                    () -> fm.setLocationFromPaths(m, List.of(out2, out2)));
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   266
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   267
            Path notExist = base.resolve("notExist");
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   268
            checkException("not exist",
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   269
                    FileNotFoundException.class, notExist + ": does not exist",
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   270
                    () -> fm.setLocationFromPaths(m, List.of(notExist)));
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   271
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   272
            Path file = Files.createFile(base.resolve("file.txt"));
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   273
            checkException("not exist",
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   274
                    IOException.class, file + ": not a directory",
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   275
                    () -> fm.setLocationFromPaths(m, List.of(file)));
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   276
        }
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   277
    }
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   278
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   279
    @Test
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   280
    public void testOutput_nested(Path base) throws IOException {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   281
        try (StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null)) {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   282
            Location locn = StandardLocation.CLASS_OUTPUT;
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   283
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   284
            Path out1 = Files.createDirectories(base.resolve("out1"));
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   285
            fm.setLocationForModule(locn, "m", List.of(out1));
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   286
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   287
            Location m = fm.getLocationForModule(locn, "m");
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   288
            checkEqual("initial setting",
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   289
                    fm.getLocationAsPaths(m), out1);
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   290
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   291
            Path out2 = Files.createDirectories(base.resolve("out2"));
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   292
            checkException("create nested module",
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   293
                    UnsupportedOperationException.class, "not supported for CLASS_OUTPUT[m]",
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   294
                    () -> fm.setLocationForModule(m, "x", List.of(out2)));
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   295
        }
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   296
    }
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   297
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   298
    @Test
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   299
    public void testSystemModules(Path base) throws IOException {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   300
        try (StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null)) {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   301
            Location locn = StandardLocation.SYSTEM_MODULES;
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   302
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   303
            Location javaCompiler = fm.getLocationForModule(locn, "java.compiler");
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   304
            // cannot easily verify default setting: could be jrt: or exploded image
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   305
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   306
            Path override1 = Files.createDirectories(base.resolve("override1"));
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   307
            fm.setLocationForModule(locn, "java.compiler", List.of(override1));
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   308
            checkEqual("override setting 1",
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   309
                    fm.getLocationAsPaths(javaCompiler), override1);
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   310
47363
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
   311
            checkEqual("override setting 1b",
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
   312
                       fm.getLocationAsPaths(findLocation(fm, fm.listLocationsForModules(locn), "java.compiler")),
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
   313
                       override1);
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
   314
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   315
            Path override2 = Files.createDirectories(base.resolve("override2"));
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   316
            fm.setLocationFromPaths(javaCompiler, List.of(override2));
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   317
            checkEqual("override setting 2",
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   318
                    fm.getLocationAsPaths(javaCompiler), override2);
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   319
        }
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   320
    }
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   321
47363
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
   322
    private Location findLocation(JavaFileManager fm, Iterable<Set<Location>> locations, String moduleName) {
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
   323
        for (Set<Location> locs : locations) {
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
   324
            for (Location loc : locs) {
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
   325
                try {
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
   326
                    if (moduleName.equals(fm.inferModuleName(loc))) {
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
   327
                        return loc;
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
   328
                    }
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
   329
                } catch (IOException ex) {
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
   330
                    throw new IllegalStateException(ex);
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
   331
                }
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
   332
            }
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
   333
        }
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
   334
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
   335
        throw new IllegalStateException();
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
   336
    }
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
   337
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   338
    @Test
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   339
    public void testTemplate(Path base) {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   340
        // set a top default
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   341
        // getLocnForModule
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   342
        // set a value
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   343
        // getLocnForModule
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   344
        // reset
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   345
        // getLocationForModule
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   346
    }
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   347
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   348
    interface RunnableWithException {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   349
        public void run() throws Exception;
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   350
    }
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   351
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   352
    void checkException(String message,
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   353
            Class<? extends Throwable> expectedException, String expectedMessage,
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   354
            RunnableWithException r) {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   355
        try {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   356
            r.run();
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   357
            error(message + ": expected exception not thrown: " + expectedException);
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   358
        } catch (Exception | Error t) {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   359
            if (expectedException.isAssignableFrom(t.getClass())) {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   360
                checkEqual("exception message",
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   361
                        t.getMessage(), expectedMessage);
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   362
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   363
            } else {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   364
                error(message + ": unexpected exception\n"
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   365
                        + "expect: " + expectedException + "\n"
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   366
                        + " found: " + t);
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   367
            }
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   368
        }
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   369
    }
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   370
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   371
    void checkEqual(String message, Iterable<? extends Path> found, Path... expect) {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   372
        List<Path> fList = asList(found);
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   373
        List<Path> eList = List.of(expect);
47363
77c792d06646 8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule.
jlahoda
parents: 47216
diff changeset
   374
        if (!Objects.equals(fList, eList)) {
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   375
            error(message + ": lists not equal\n"
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   376
                    + "expect: " + eList + "\n"
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   377
                    + " found: " + fList);
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   378
        }
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   379
    }
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   380
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   381
    void checkEqual(String message, String found, String expect) {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   382
        if (!Objects.equals(found, expect)) {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   383
            error(message + ": strings not equal\n"
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   384
                    + "expect: " + expect + "\n"
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   385
                    + " found: " + found);
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   386
        }
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   387
    }
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   388
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   389
    List<Path> asList(Iterable<? extends Path> a) {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   390
        List<Path> list = new ArrayList<>();
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   391
        for (Path p : a) {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   392
            list.add(p);
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   393
        }
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   394
        return list;
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   395
    }
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   396
}
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents:
diff changeset
   397