jdk/test/tools/jlink/plugins/ExcludePluginTest.java
author sundar
Thu, 28 Jul 2016 19:34:58 +0530
changeset 39834 53a6fb443c20
parent 39151 34455cc82f5e
child 43185 d75d9ff8d4e7
permissions -rw-r--r--
8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify Reviewed-by: jlaskey, psandoz
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
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    24
/*
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    25
 * @test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    26
 * @summary Test exclude plugin
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    27
 * @author Jean-Francois Denise
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    28
 * @modules jdk.jlink/jdk.tools.jlink.internal
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    29
 *          jdk.jlink/jdk.tools.jlink.internal.plugins
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    30
 * @run main ExcludePluginTest
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    31
 */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    32
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    33
import java.io.File;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    34
import java.nio.file.Files;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    35
import java.util.HashMap;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    36
import java.util.Map;
39834
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39151
diff changeset
    37
import jdk.tools.jlink.internal.ResourcePoolManager;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    38
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    39
import jdk.tools.jlink.internal.plugins.ExcludePlugin;
39834
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39151
diff changeset
    40
import jdk.tools.jlink.plugin.ResourcePool;
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39151
diff changeset
    41
import jdk.tools.jlink.plugin.ResourcePoolBuilder;
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39151
diff changeset
    42
import jdk.tools.jlink.plugin.ResourcePoolEntry;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    43
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    44
public class ExcludePluginTest {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    45
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    46
    public static void main(String[] args) throws Exception {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    47
        new ExcludePluginTest().test();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    48
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    49
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    50
    public void test() throws Exception {
39042
52db877f18db 8159206: All jlink or jmod tests failing
jlaskey
parents: 38320
diff changeset
    51
        check("**.jcov", "/num/toto.jcov", true);
39151
34455cc82f5e 8147794: Jlink's ModuleEntry.stream can't be consumed more than once and ModuleEntry content should be read only if needed
sundar
parents: 39042
diff changeset
    52
        check("**.jcov", "/toto.jcov/", true);
39042
52db877f18db 8159206: All jlink or jmod tests failing
jlaskey
parents: 38320
diff changeset
    53
        check("**.jcov", "/toto.jcov/tutu/tata", false);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    54
        check("/java.base/*.jcov", "/java.base/toto.jcov", true);
39151
34455cc82f5e 8147794: Jlink's ModuleEntry.stream can't be consumed more than once and ModuleEntry content should be read only if needed
sundar
parents: 39042
diff changeset
    55
        check("/java.base/toto.jcov", "/tjava.base/iti.jcov", false);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    56
        check("/java.base/*/toto.jcov", "/java.base/toto.jcov", false);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    57
        check("/java.base/*/toto.jcov", "/java.base/tutu/toto.jcov", true);
39042
52db877f18db 8159206: All jlink or jmod tests failing
jlaskey
parents: 38320
diff changeset
    58
        check("**/java.base/*/toto.jcov", "/tutu/java.base/tutu/toto.jcov", true);
52db877f18db 8159206: All jlink or jmod tests failing
jlaskey
parents: 38320
diff changeset
    59
        check("/META-INF/**", "/META-INF/services/  MyProvider ", true);
52db877f18db 8159206: All jlink or jmod tests failing
jlaskey
parents: 38320
diff changeset
    60
        check("/META-INF/**", "/META-INF/services/MyProvider", true);
39151
34455cc82f5e 8147794: Jlink's ModuleEntry.stream can't be consumed more than once and ModuleEntry content should be read only if needed
sundar
parents: 39042
diff changeset
    61
        check("**/META-INF", "/ META-INF/services/MyProvider", false);
39042
52db877f18db 8159206: All jlink or jmod tests failing
jlaskey
parents: 38320
diff changeset
    62
        check("**/META-INF/**", "/java.base//META-INF/services/MyProvider", true);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    63
        check("/java.base/*/Toto$Titi.class", "/java.base/tutu/Toto$Titi.class", true);
39042
52db877f18db 8159206: All jlink or jmod tests failing
jlaskey
parents: 38320
diff changeset
    64
        check("/**$**.class", "/java.base/tutu/Toto$Titi.class", true);
52db877f18db 8159206: All jlink or jmod tests failing
jlaskey
parents: 38320
diff changeset
    65
        check("**$**.class", "/java.base/tutu/Toto$Titi.class", true);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    66
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    67
        // Excluded resource list in a file
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    68
        File order = new File("resources.exc");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    69
        order.createNewFile();
39042
52db877f18db 8159206: All jlink or jmod tests failing
jlaskey
parents: 38320
diff changeset
    70
        Files.write(order.toPath(), "**.jcov".getBytes());
52db877f18db 8159206: All jlink or jmod tests failing
jlaskey
parents: 38320
diff changeset
    71
        check("@" + order.getAbsolutePath(), "/num/toto.jcov", true);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    72
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    73
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    74
    public void check(String s, String sample, boolean exclude) throws Exception {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    75
        Map<String, String> prop = new HashMap<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    76
        prop.put(ExcludePlugin.NAME, s);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    77
        ExcludePlugin excludePlugin = new ExcludePlugin();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    78
        excludePlugin.configure(prop);
39834
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39151
diff changeset
    79
        ResourcePoolManager resourcesMgr = new ResourcePoolManager();
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39151
diff changeset
    80
        ResourcePoolEntry resource = ResourcePoolEntry.create(sample, new byte[0]);
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39151
diff changeset
    81
        resourcesMgr.add(resource);
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39151
diff changeset
    82
        ResourcePoolManager resultMgr = new ResourcePoolManager();
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39151
diff changeset
    83
        ResourcePool resPool = excludePlugin.transform(resourcesMgr.resourcePool(),
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39151
diff changeset
    84
                resultMgr.resourcePoolBuilder());
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    85
        if (exclude) {
39834
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39151
diff changeset
    86
            if (resPool.contains(resource)) {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    87
                throw new AssertionError(sample + " should be excluded by " + s);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    88
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    89
        } else {
39834
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39151
diff changeset
    90
            if (!resPool.contains(resource)) {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    91
                throw new AssertionError(sample + " shouldn't be excluded by " + s);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    92
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    93
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    94
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    95
}