jdk/test/tools/jlink/asmplugin/AsmPluginTestBase.java
author sundar
Mon, 16 May 2016 14:47:27 +0530
changeset 38320 e24c7029e8ba
parent 36511 9d0388c6b336
permissions -rw-r--r--
8156914: jlink API minor cleanups Reviewed-by: mchung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/*
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     4
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     8
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    13
 * accompanied this code).
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    14
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    18
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    21
 * questions.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    22
 */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    23
import java.io.IOException;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    24
import java.net.URI;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    25
import java.nio.file.FileSystem;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    26
import java.nio.file.FileSystems;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    27
import java.nio.file.Files;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    28
import java.nio.file.Path;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    29
import java.nio.file.Paths;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    30
import java.util.ArrayList;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    31
import java.util.Collection;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    32
import java.util.Collections;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    33
import java.util.HashMap;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    34
import java.util.Iterator;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    35
import java.util.List;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    36
import java.util.Map;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    37
import java.util.Set;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    38
import java.util.function.Predicate;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    39
import java.util.stream.Collectors;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    40
import java.util.stream.Stream;
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
    41
import jdk.tools.jlink.internal.ModulePoolImpl;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    42
import jdk.tools.jlink.internal.StringTable;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    43
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    44
import jdk.tools.jlink.internal.plugins.asm.AsmPlugin;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    45
import jdk.tools.jlink.internal.plugins.asm.AsmPools;
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
    46
import jdk.tools.jlink.plugin.ModuleEntry;
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
    47
import jdk.tools.jlink.plugin.ModulePool;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    48
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    49
public abstract class AsmPluginTestBase {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    50
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    51
    protected static final String TEST_MODULE = "jlink.test";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    52
    protected static final Map<String, List<String>> MODULES;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    53
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
    54
    private static final Predicate<ModuleEntry> isClass = r -> r.getPath().endsWith(".class");
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    55
    private final List<String> classes;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    56
    private final List<String> resources;
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
    57
    private final ModulePool pool;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    58
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    59
    static {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    60
        Map<String, List<String>> map = new HashMap<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    61
        map.put("jdk.localedata", new ArrayList<>());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    62
        map.put("java.base", new ArrayList<>());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    63
        map.put(TEST_MODULE, new ArrayList<>());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    64
        MODULES = Collections.unmodifiableMap(map);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    65
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    66
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    67
    public static boolean isImageBuild() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    68
        Path javaHome = Paths.get(System.getProperty("test.jdk"));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    69
        Path jmods = javaHome.resolve("jmods");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    70
        return Files.exists(jmods);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    71
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    72
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    73
    public AsmPluginTestBase() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    74
        try {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    75
            List<String> classes = new ArrayList<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    76
            List<String> resources = new ArrayList<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    77
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
    78
            pool = new ModulePoolImpl();
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    79
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    80
            FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/"));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    81
            Path root = fs.getPath("/modules");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    82
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    83
            List<byte[]> moduleInfos = new ArrayList<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    84
            try (Stream<Path> stream = Files.walk(root)) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    85
                for (Iterator<Path> iterator = stream.iterator(); iterator.hasNext(); ) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    86
                    Path p = iterator.next();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    87
                    if (Files.isRegularFile(p)) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    88
                        String module = p.toString().substring("/modules/".length());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    89
                        module = module.substring(0, module.indexOf("/"));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    90
                        if (MODULES.keySet().contains(module)) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    91
                            try {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    92
                                boolean isModuleInfo = p.endsWith("module-info.class");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    93
                                if (isModuleInfo) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    94
                                    moduleInfos.add(Files.readAllBytes(p));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    95
                                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    96
                                byte[] content = Files.readAllBytes(p);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    97
                                if (p.toString().endsWith(".class") && !isModuleInfo) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    98
                                    classes.add(toClassName(p));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    99
                                } else if (!isModuleInfo) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   100
                                    MODULES.get(module).add(toResourceFile(p));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   101
                                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   102
                                resources.add(toPath(p.toString()));
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   103
                                ModuleEntry res = ModuleEntry.create(toPath(p.toString()), content);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   104
                                pool.add(res);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   105
                            } catch (Exception ex) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   106
                                throw new RuntimeException(ex);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   107
                            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   108
                        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   109
                    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   110
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   111
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   112
            // There is more than 10 classes in java.base...
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   113
            if (classes.size() < 10 || pool.getEntryCount() < 10) {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   114
                throw new AssertionError("Not expected resource or class number");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   115
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   116
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   117
            //Add a fake resource file
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   118
            String content = "java.lang.Object";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   119
            String path = "META-INF/services/com.foo.BarProvider";
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   120
            ModuleEntry resFile = ModuleEntry.create("/" + TEST_MODULE + "/" +
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   121
                    path, content.getBytes());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   122
            pool.add(resFile);
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   123
            ModuleEntry fakeInfoFile = ModuleEntry.create("/" + TEST_MODULE
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   124
                    + "/module-info.class", moduleInfos.get(0));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   125
            pool.add(fakeInfoFile);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   126
            MODULES.get(TEST_MODULE).add(path);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   127
            for(Map.Entry<String, List<String>> entry : MODULES.entrySet()) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   128
                if (entry.getValue().isEmpty()) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   129
                    throw new AssertionError("No resource file for " + entry.getKey());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   130
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   131
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   132
            this.classes = Collections.unmodifiableList(classes);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   133
            this.resources = Collections.unmodifiableList(resources);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   134
        } catch (Exception e) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   135
            throw new ExceptionInInitializerError(e);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   136
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   137
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   138
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   139
    public List<String> getClasses() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   140
        return classes;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   141
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   142
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   143
    public List<String> getResources() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   144
        return resources;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   145
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   146
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   147
    public ModulePool getPool() {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   148
        return pool;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   149
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   150
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   151
    public abstract void test() throws Exception;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   152
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   153
    public Collection<ModuleEntry> extractClasses(ModulePool pool) {
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   154
        return pool.entries()
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   155
                .filter(isClass)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   156
                .collect(Collectors.toSet());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   157
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   158
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   159
    public Collection<ModuleEntry> extractResources(ModulePool pool) {
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   160
        return pool.entries()
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   161
                .filter(isClass.negate())
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   162
                .collect(Collectors.toSet());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   163
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   164
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   165
    public String getModule(String path) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   166
        int index = path.indexOf("/", 1);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   167
        return path.substring(1, index);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   168
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   169
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   170
    public String removeModule(String path) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   171
        int index = path.indexOf("/", 1);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   172
        return path.substring(index + 1);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   173
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   174
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   175
    private String toPath(String p) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   176
        return p.substring("/modules".length());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   177
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   178
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   179
    private String toClassName(Path p) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   180
        String path = p.toString();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   181
        path = path.substring("/modules/".length());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   182
        // remove module
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   183
        if (!path.endsWith("module-info.class")) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   184
            path = path.substring(path.indexOf("/") + 1);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   185
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   186
        path = path.substring(0, path.length() - ".class".length());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   187
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   188
        return path;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   189
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   190
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   191
    private String toResourceFile(Path p) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   192
        String path = p.toString();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   193
        path = path.substring("/modules/".length());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   194
        // remove module
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   195
        path = path.substring(path.indexOf("/") + 1);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   196
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   197
        return path;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   198
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   199
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   200
    public abstract class TestPlugin extends AsmPlugin {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   201
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   202
        private AsmPools pools;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   203
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   204
        public AsmPools getPools() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   205
            return pools;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   206
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   207
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   208
        public boolean isVisitCalled() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   209
            return pools != null;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   210
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   211
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   212
        public ModulePool visit(ModulePool inResources) throws IOException {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   213
            try {
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   214
                ModulePool outResources = new ModulePoolImpl(inResources.getByteOrder(), new StringTable() {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   215
                    @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   216
                    public int addString(String str) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   217
                        return -1;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   218
                    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   219
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   220
                    @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   221
                    public String getString(int id) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   222
                        return null;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   223
                    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   224
                });
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   225
                visit(inResources, outResources);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   226
                return outResources;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   227
            } catch (Exception e) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   228
                throw new IOException(e);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   229
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   230
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   231
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   232
        @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   233
        public void visit(AsmPools pools) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   234
            if (isVisitCalled()) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   235
                throw new AssertionError("Visit was called twice");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   236
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   237
            this.pools = pools;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   238
            visit();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   239
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   240
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   241
        public abstract void visit();
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   242
        public abstract void test(ModulePool inResources, ModulePool outResources) throws Exception;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   243
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   244
        @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   245
        public String getName() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   246
            return "test-plugin";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   247
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   248
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   249
}