jdk/test/tools/jmod/hashes/HashesTest.java
author mchung
Wed, 10 Aug 2016 15:51:25 -0700
changeset 40261 86a49ba76f52
parent 37779 7c84df693837
child 41484 834b7539ada3
permissions -rw-r--r--
8136930: Simplify use of module-system options by custom launchers Reviewed-by: alanb, ksrini, henryjen, sundar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
     1
/**
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 37779
diff changeset
     2
 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
     4
 *
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
     8
 *
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    13
 * accompanied this code).
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    14
 *
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    18
 *
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    21
 * questions.
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    22
 */
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    23
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    24
/*
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    25
 * @test
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    26
 * @summary Test the recording and checking of module hashes
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    27
 * @author Andrei Eremeev
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    28
 * @library /lib/testlibrary
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    29
 * @modules java.base/jdk.internal.module
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    30
 *          jdk.jlink/jdk.tools.jlink.internal
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    31
 *          jdk.jlink/jdk.tools.jmod
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    32
 *          jdk.compiler
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    33
 * @build CompilerUtils
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    34
 * @run testng HashesTest
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    35
 */
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    36
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    37
import java.io.IOException;
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    38
import java.io.InputStream;
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    39
import java.lang.module.ModuleDescriptor;
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    40
import java.lang.module.ModuleFinder;
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    41
import java.lang.module.ModuleReader;
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    42
import java.lang.module.ModuleReference;
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    43
import java.lang.reflect.Method;
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    44
import java.nio.file.FileVisitResult;
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    45
import java.nio.file.Files;
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    46
import java.nio.file.Path;
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    47
import java.nio.file.Paths;
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    48
import java.nio.file.SimpleFileVisitor;
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    49
import java.nio.file.attribute.BasicFileAttributes;
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    50
import java.util.ArrayList;
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    51
import java.util.Arrays;
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    52
import java.util.Collections;
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    53
import java.util.List;
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    54
import java.util.Optional;
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    55
import java.util.Set;
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    56
import java.util.stream.Collectors;
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    57
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    58
import jdk.internal.module.ConfigurableModuleFinder;
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    59
import jdk.internal.module.ModuleHashes;
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    60
import org.testng.annotations.BeforeTest;
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    61
import org.testng.annotations.Test;
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    62
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    63
import static org.testng.Assert.*;
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    64
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    65
public class HashesTest {
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    66
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    67
    private final Path testSrc = Paths.get(System.getProperty("test.src"));
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    68
    private final Path modSrc = testSrc.resolve("src");
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    69
    private final Path mods = Paths.get("mods");
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    70
    private final Path jmods = Paths.get("jmods");
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    71
    private final String[] modules = new String[] { "m1", "m2", "m3"};
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    72
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    73
    private static Method hashesMethod;
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    74
    @BeforeTest
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    75
    private void setup() throws Exception {
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    76
        if (Files.exists(jmods)) {
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    77
            deleteDirectory(jmods);
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    78
        }
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    79
        Files.createDirectories(jmods);
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    80
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    81
        // build m2, m3 required by m1
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    82
        compileModule("m2", modSrc);
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    83
        jmod("m2");
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    84
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    85
        compileModule("m3", modSrc);
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    86
        jmod("m3");
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    87
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    88
        // build m1
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    89
        compileModule("m1", modSrc);
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    90
        // no hash is recorded since m1 has outgoing edges
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 37779
diff changeset
    91
        jmod("m1", "--module-path", jmods.toString(), "--hash-modules", ".*");
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    92
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    93
        // compile org.bar and org.foo
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    94
        compileModule("org.bar", modSrc);
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    95
        compileModule("org.foo", modSrc);
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    96
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    97
        try {
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    98
            hashesMethod = ModuleDescriptor.class.getDeclaredMethod("hashes");
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
    99
            hashesMethod.setAccessible(true);
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   100
        } catch (ReflectiveOperationException x) {
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   101
            throw new InternalError(x);
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   102
        }
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   103
    }
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   104
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   105
    @Test
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   106
    public void test() throws Exception {
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   107
        for (String mn : modules) {
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   108
            assertFalse(hashes(mn).isPresent());
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   109
        }
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   110
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   111
        // hash m1 in m2
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 37779
diff changeset
   112
        jmod("m2", "--module-path", jmods.toString(), "--hash-modules", "m1");
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   113
        checkHashes(hashes("m2").get(), "m1");
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   114
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   115
        // hash m1 in m2
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 37779
diff changeset
   116
        jmod("m2", "--module-path", jmods.toString(), "--hash-modules", ".*");
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   117
        checkHashes(hashes("m2").get(), "m1");
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   118
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   119
        // create m2.jmod with no hash
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   120
        jmod("m2");
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   121
        // run jmod hash command to hash m1 in m2 and m3
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 37779
diff changeset
   122
        runJmod(Arrays.asList("hash", "--module-path", jmods.toString(),
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   123
                "--hash-modules", ".*"));
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   124
        checkHashes(hashes("m2").get(), "m1");
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   125
        checkHashes(hashes("m3").get(), "m1");
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   126
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   127
        jmod("org.bar");
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   128
        jmod("org.foo");
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   129
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 37779
diff changeset
   130
        jmod("org.bar", "--module-path", jmods.toString(), "--hash-modules", "org.*");
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   131
        checkHashes(hashes("org.bar").get(), "org.foo");
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   132
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 37779
diff changeset
   133
        jmod("m3", "--module-path", jmods.toString(), "--hash-modules", ".*");
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   134
        checkHashes(hashes("m3").get(), "org.foo", "org.bar", "m1");
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   135
    }
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   136
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   137
    private void checkHashes(ModuleHashes hashes, String... hashModules) {
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   138
        assertTrue(hashes.names().equals(Set.of(hashModules)));
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   139
    }
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   140
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   141
    private Optional<ModuleHashes> hashes(String name) throws Exception {
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   142
        ModuleFinder finder = ModuleFinder.of(jmods.resolve(name + ".jmod"));
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   143
        if (finder instanceof ConfigurableModuleFinder) {
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   144
            ((ConfigurableModuleFinder) finder)
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   145
                .configurePhase(ConfigurableModuleFinder.Phase.LINK_TIME);
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   146
        }
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   147
        ModuleReference mref = finder.find(name).orElseThrow(RuntimeException::new);
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   148
        ModuleReader reader = mref.open();
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   149
        try (InputStream in = reader.open("module-info.class").get()) {
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   150
            ModuleDescriptor md = ModuleDescriptor.read(in);
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   151
            Optional<ModuleHashes> hashes =
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   152
                (Optional<ModuleHashes>) hashesMethod.invoke(md);
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   153
            System.out.format("hashes in module %s %s%n", name,
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   154
                              hashes.isPresent() ? "present" : "absent");
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   155
            if (hashes.isPresent()) {
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   156
                hashes.get().names().stream()
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   157
                    .sorted()
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   158
                    .forEach(n -> System.out.format("  %s %s%n", n, hashes.get().hashFor(n)));
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   159
            }
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   160
            return hashes;
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   161
        } finally {
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   162
            reader.close();
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   163
        }
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   164
    }
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   165
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   166
    private void deleteDirectory(Path dir) throws IOException {
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   167
        Files.walkFileTree(dir, new SimpleFileVisitor<Path>() {
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   168
            @Override
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   169
            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   170
                throws IOException
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   171
            {
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   172
                Files.delete(file);
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   173
                return FileVisitResult.CONTINUE;
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   174
            }
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   175
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   176
            @Override
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   177
            public FileVisitResult postVisitDirectory(Path dir, IOException exc)
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   178
                throws IOException
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   179
            {
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   180
                Files.delete(dir);
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   181
                return FileVisitResult.CONTINUE;
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   182
            }
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   183
        });
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   184
    }
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   185
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   186
    private void compileModule(String moduleName, Path src) throws IOException {
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   187
        Path msrc = src.resolve(moduleName);
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 37779
diff changeset
   188
        assertTrue(CompilerUtils.compile(msrc, mods, "--module-source-path", src.toString()));
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   189
    }
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   190
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   191
    private void jmod(String moduleName, String... options) throws IOException {
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   192
        Path mclasses = mods.resolve(moduleName);
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   193
        Path outfile = jmods.resolve(moduleName + ".jmod");
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   194
        List<String> args = new ArrayList<>();
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   195
        args.add("create");
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   196
        Collections.addAll(args, options);
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   197
        Collections.addAll(args, "--class-path", mclasses.toString(),
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   198
                           outfile.toString());
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   199
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   200
        if (Files.exists(outfile))
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   201
            Files.delete(outfile);
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   202
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   203
        runJmod(args);
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   204
    }
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   205
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   206
    private void runJmod(List<String> args) {
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   207
        int rc = jdk.tools.jmod.Main.run(args.toArray(new String[args.size()]), System.out);
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   208
        System.out.println("jmod options: " + args.stream().collect(Collectors.joining(" ")));
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   209
        if (rc != 0) {
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   210
            throw new AssertionError("Jmod failed: rc = " + rc);
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   211
        }
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   212
    }
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents:
diff changeset
   213
}