jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ResourcePoolManager.java
author alanb
Thu, 04 May 2017 07:26:55 +0000
changeset 45004 ea3137042a61
parent 44359 c6761862ca0b
permissions -rw-r--r--
8178380: Module system implementation refresh (5/2017) Reviewed-by: mchung, alanb, sspitsyn Contributed-by: alan.bateman@oracle.com, mandy.chung@oracle.com, chris.hegarty@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/*
45004
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44359
diff changeset
     2
 * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
36511
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.  Oracle designates this
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    10
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    15
 * accompanied this code).
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    16
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    20
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    23
 * questions.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    24
 */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    25
package jdk.tools.jlink.internal;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    26
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
    27
import java.lang.module.ModuleDescriptor;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    28
import java.nio.ByteBuffer;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    29
import java.nio.ByteOrder;
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
    30
import java.util.HashSet;
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
    31
import java.util.LinkedHashMap;
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
    32
import java.util.Map;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    33
import java.util.Objects;
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
    34
import java.util.Optional;
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
    35
import java.util.Set;
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
    36
import java.util.stream.Stream;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    37
import jdk.internal.jimage.decompressor.CompressedResourceHeader;
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 42670
diff changeset
    38
import jdk.internal.module.Resources;
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 42670
diff changeset
    39
import jdk.internal.module.ModuleInfo;
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 42670
diff changeset
    40
import jdk.internal.module.ModuleInfo.Attributes;
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 42670
diff changeset
    41
import jdk.internal.module.ModuleTarget;
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: 39635
diff changeset
    42
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: 39635
diff changeset
    43
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: 39635
diff changeset
    44
import jdk.tools.jlink.plugin.ResourcePoolEntry;
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
    45
import jdk.tools.jlink.plugin.ResourcePoolModule;
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
    46
import jdk.tools.jlink.plugin.ResourcePoolModuleView;
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
    47
import jdk.tools.jlink.plugin.PluginException;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    48
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    49
/**
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: 39635
diff changeset
    50
 * A manager for pool of resources.
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    51
 */
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: 39635
diff changeset
    52
public class ResourcePoolManager {
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 42670
diff changeset
    53
    // utility to read Module Attributes of the given ResourcePoolModule
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 42670
diff changeset
    54
    static Attributes readModuleAttributes(ResourcePoolModule mod) {
39894
cd4f403f9618 8162782: jlink ResourcePool.releaseProperties should be removed
sundar
parents: 39834
diff changeset
    55
        String p = "/" + mod.name() + "/module-info.class";
cd4f403f9618 8162782: jlink ResourcePool.releaseProperties should be removed
sundar
parents: 39834
diff changeset
    56
        Optional<ResourcePoolEntry> content = mod.findEntry(p);
cd4f403f9618 8162782: jlink ResourcePool.releaseProperties should be removed
sundar
parents: 39834
diff changeset
    57
        if (!content.isPresent()) {
42670
d833113eb7d7 8169925: Organize licenses by module in source, JMOD file, and run-time image
mchung
parents: 42471
diff changeset
    58
              throw new PluginException("module-info.class not found for " +
d833113eb7d7 8169925: Organize licenses by module in source, JMOD file, and run-time image
mchung
parents: 42471
diff changeset
    59
                  mod.name() + " module");
39894
cd4f403f9618 8162782: jlink ResourcePool.releaseProperties should be removed
sundar
parents: 39834
diff changeset
    60
        }
cd4f403f9618 8162782: jlink ResourcePool.releaseProperties should be removed
sundar
parents: 39834
diff changeset
    61
        ByteBuffer bb = ByteBuffer.wrap(content.get().contentBytes());
42471
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents: 42338
diff changeset
    62
        try {
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 42670
diff changeset
    63
            return ModuleInfo.read(bb, null);
42471
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents: 42338
diff changeset
    64
        } catch (RuntimeException re) {
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 42670
diff changeset
    65
            throw new RuntimeException("module info cannot be read for " + mod.name(), re);
42471
86b1da05a4b0 8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents: 42338
diff changeset
    66
        }
39894
cd4f403f9618 8162782: jlink ResourcePool.releaseProperties should be removed
sundar
parents: 39834
diff changeset
    67
    }
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
    68
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41352
diff changeset
    69
    /**
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41352
diff changeset
    70
     * Returns true if a resource has an effective package.
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41352
diff changeset
    71
     */
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41352
diff changeset
    72
    public static boolean isNamedPackageResource(String path) {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41352
diff changeset
    73
        return (path.endsWith(".class") && !path.endsWith("module-info.class")) ||
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 42670
diff changeset
    74
                Resources.canEncapsulate(path);
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41352
diff changeset
    75
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41352
diff changeset
    76
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: 39635
diff changeset
    77
    class ResourcePoolModuleImpl implements ResourcePoolModule {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    78
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: 39635
diff changeset
    79
        final Map<String, ResourcePoolEntry> moduleContent = new LinkedHashMap<>();
39894
cd4f403f9618 8162782: jlink ResourcePool.releaseProperties should be removed
sundar
parents: 39834
diff changeset
    80
        // lazily initialized
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
    81
        private ModuleDescriptor descriptor;
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 42670
diff changeset
    82
        private ModuleTarget target;
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 42670
diff changeset
    83
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
    84
        final String name;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    85
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: 39635
diff changeset
    86
        private ResourcePoolModuleImpl(String name) {
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
    87
            this.name = name;
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
    88
        }
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    89
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
    90
        @Override
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: 39635
diff changeset
    91
        public String name() {
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
    92
            return name;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    93
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    94
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
    95
        @Override
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: 39635
diff changeset
    96
        public Optional<ResourcePoolEntry> findEntry(String path) {
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
    97
            if (!path.startsWith("/")) {
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
    98
                path = "/" + path;
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
    99
            }
40209
68e8944f4424 8163382: ResourcePoolManager.findEntry has a bug in startsWith call
sundar
parents: 40121
diff changeset
   100
            if (!path.startsWith("/" + name + "/")) {
68e8944f4424 8163382: ResourcePoolManager.findEntry has a bug in startsWith call
sundar
parents: 40121
diff changeset
   101
                path = "/" + name + path; // path already starts with '/'
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   102
            }
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   103
            return Optional.ofNullable(moduleContent.get(path));
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   104
        }
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   105
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   106
        @Override
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: 39635
diff changeset
   107
        public ModuleDescriptor descriptor() {
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 42670
diff changeset
   108
            initModuleAttributes();
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 42670
diff changeset
   109
            return descriptor;
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 42670
diff changeset
   110
        }
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 42670
diff changeset
   111
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 42670
diff changeset
   112
        @Override
45004
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44359
diff changeset
   113
        public String targetPlatform() {
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 42670
diff changeset
   114
            initModuleAttributes();
45004
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44359
diff changeset
   115
            return target != null? target.targetPlatform() : null;
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 42670
diff changeset
   116
        }
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 42670
diff changeset
   117
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 42670
diff changeset
   118
        private void initModuleAttributes() {
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 42670
diff changeset
   119
            if (this.descriptor == null) {
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 42670
diff changeset
   120
                Attributes attr = readModuleAttributes(this);
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 42670
diff changeset
   121
                this.descriptor = attr.descriptor();
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 42670
diff changeset
   122
                this.target = attr.target();
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   123
            }
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   124
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   125
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   126
        @Override
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: 39635
diff changeset
   127
        public Set<String> packages() {
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   128
            Set<String> pkgs = new HashSet<>();
41352
f9844bad9052 8166860: Add magic number to jmod file
mchung
parents: 40209
diff changeset
   129
            moduleContent.values().stream()
f9844bad9052 8166860: Add magic number to jmod file
mchung
parents: 40209
diff changeset
   130
                .filter(m -> m.type() == ResourcePoolEntry.Type.CLASS_OR_RESOURCE)
f9844bad9052 8166860: Add magic number to jmod file
mchung
parents: 40209
diff changeset
   131
                .forEach(res -> {
f9844bad9052 8166860: Add magic number to jmod file
mchung
parents: 40209
diff changeset
   132
                    String name = ImageFileCreator.resourceName(res.path());
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41352
diff changeset
   133
                    if (isNamedPackageResource(name)) {
41352
f9844bad9052 8166860: Add magic number to jmod file
mchung
parents: 40209
diff changeset
   134
                        String pkg = ImageFileCreator.toPackage(name);
f9844bad9052 8166860: Add magic number to jmod file
mchung
parents: 40209
diff changeset
   135
                        if (!pkg.isEmpty()) {
f9844bad9052 8166860: Add magic number to jmod file
mchung
parents: 40209
diff changeset
   136
                            pkgs.add(pkg);
f9844bad9052 8166860: Add magic number to jmod file
mchung
parents: 40209
diff changeset
   137
                        }
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   138
                    }
41352
f9844bad9052 8166860: Add magic number to jmod file
mchung
parents: 40209
diff changeset
   139
                });
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   140
            return pkgs;
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   141
        }
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   142
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   143
        @Override
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   144
        public String toString() {
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: 39635
diff changeset
   145
            return name();
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   146
        }
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   147
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   148
        @Override
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: 39635
diff changeset
   149
        public Stream<ResourcePoolEntry> entries() {
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   150
            return moduleContent.values().stream();
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   151
        }
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   152
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   153
        @Override
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: 39635
diff changeset
   154
        public int entryCount() {
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   155
            return moduleContent.values().size();
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   156
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   157
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   158
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: 39635
diff changeset
   159
    public class ResourcePoolImpl implements 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: 39635
diff changeset
   160
        @Override
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   161
        public ResourcePoolModuleView moduleView() {
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   162
            return ResourcePoolManager.this.moduleView();
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   163
        }
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   164
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   165
        @Override
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   166
        public Stream<ResourcePoolEntry> entries() {
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   167
            return ResourcePoolManager.this.entries();
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   168
        }
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   169
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   170
        @Override
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   171
        public int entryCount() {
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   172
            return ResourcePoolManager.this.entryCount();
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   173
        }
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   174
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   175
        @Override
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   176
        public Optional<ResourcePoolEntry> findEntry(String path) {
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   177
            return ResourcePoolManager.this.findEntry(path);
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   178
        }
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   179
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   180
        @Override
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   181
        public Optional<ResourcePoolEntry> findEntryInContext(String path, ResourcePoolEntry context) {
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   182
            return ResourcePoolManager.this.findEntryInContext(path, context);
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   183
        }
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   184
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   185
        @Override
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   186
        public boolean contains(ResourcePoolEntry data) {
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   187
            return ResourcePoolManager.this.contains(data);
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   188
        }
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   189
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   190
        @Override
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   191
        public boolean isEmpty() {
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   192
            return ResourcePoolManager.this.isEmpty();
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   193
        }
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   194
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   195
        @Override
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   196
        public ByteOrder byteOrder() {
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   197
            return ResourcePoolManager.this.byteOrder();
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   198
        }
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   199
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   200
        public StringTable getStringTable() {
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   201
            return ResourcePoolManager.this.getStringTable();
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   202
        }
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   203
    }
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   204
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   205
    class ResourcePoolBuilderImpl implements 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: 39635
diff changeset
   206
        private boolean built;
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   207
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   208
        @Override
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   209
        public void add(ResourcePoolEntry data) {
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   210
            if (built) {
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   211
                throw new IllegalStateException("resource pool already built!");
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   212
            }
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   213
            ResourcePoolManager.this.add(data);
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   214
        }
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   215
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   216
        @Override
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   217
        public ResourcePool build() {
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   218
            built = true;
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   219
            return ResourcePoolManager.this.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: 39635
diff changeset
   220
        }
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   221
    }
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   222
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   223
    class ResourcePoolModuleViewImpl implements ResourcePoolModuleView {
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   224
        @Override
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   225
        public Optional<ResourcePoolModule> findModule(String name) {
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   226
            return ResourcePoolManager.this.findModule(name);
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   227
        }
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   228
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   229
        @Override
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   230
        public Stream<ResourcePoolModule> modules() {
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   231
            return ResourcePoolManager.this.modules();
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   232
        }
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   233
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   234
        @Override
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   235
        public int moduleCount() {
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   236
            return ResourcePoolManager.this.moduleCount();
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   237
        }
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   238
    }
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   239
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   240
    private final Map<String, ResourcePoolEntry> resources = new LinkedHashMap<>();
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   241
    private final Map<String, ResourcePoolModule> modules = new LinkedHashMap<>();
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   242
    private final ByteOrder order;
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: 39635
diff changeset
   243
    private final StringTable table;
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   244
    private final ResourcePool poolImpl;
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   245
    private final ResourcePoolBuilder poolBuilderImpl;
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   246
    private final ResourcePoolModuleView moduleViewImpl;
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   247
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: 39635
diff changeset
   248
    public ResourcePoolManager() {
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   249
        this(ByteOrder.nativeOrder());
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   250
    }
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   251
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: 39635
diff changeset
   252
    public ResourcePoolManager(ByteOrder order) {
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   253
        this(order, new StringTable() {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   254
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   255
            @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   256
            public int addString(String str) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   257
                return -1;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   258
            }
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   259
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   260
            @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   261
            public String getString(int id) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   262
                return null;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   263
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   264
        });
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   265
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   266
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: 39635
diff changeset
   267
    public ResourcePoolManager(ByteOrder order, StringTable table) {
39308
f6517755057f 8160459: jlink minor code clean up
jlaskey
parents: 39151
diff changeset
   268
        this.order = Objects.requireNonNull(order);
f6517755057f 8160459: jlink minor code clean up
jlaskey
parents: 39151
diff changeset
   269
        this.table = Objects.requireNonNull(table);
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: 39635
diff changeset
   270
        this.poolImpl = new ResourcePoolImpl();
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   271
        this.poolBuilderImpl = new ResourcePoolBuilderImpl();
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   272
        this.moduleViewImpl = new ResourcePoolModuleViewImpl();
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   273
    }
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   274
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   275
    public ResourcePool 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: 39635
diff changeset
   276
        return poolImpl;
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   277
    }
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   278
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   279
    public ResourcePoolBuilder 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: 39635
diff changeset
   280
        return poolBuilderImpl;
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   281
    }
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   282
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   283
    public ResourcePoolModuleView moduleView() {
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   284
        return moduleViewImpl;
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   285
    }
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   286
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   287
    /**
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: 39635
diff changeset
   288
     * Add a ResourcePoolEntry.
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   289
     *
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: 39635
diff changeset
   290
     * @param data The ResourcePoolEntry to add.
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   291
     */
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: 39635
diff changeset
   292
    public void add(ResourcePoolEntry data) {
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   293
        Objects.requireNonNull(data);
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: 39635
diff changeset
   294
        if (resources.get(data.path()) != null) {
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   295
            throw new PluginException("Resource " + data.path()
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   296
                    + " already present");
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   297
        }
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: 39635
diff changeset
   298
        String modulename = data.moduleName();
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   299
        ResourcePoolModuleImpl m = (ResourcePoolModuleImpl)modules.get(modulename);
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   300
        if (m == null) {
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: 39635
diff changeset
   301
            m = new ResourcePoolModuleImpl(modulename);
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   302
            modules.put(modulename, m);
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   303
        }
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: 39635
diff changeset
   304
        resources.put(data.path(), data);
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   305
        m.moduleContent.put(data.path(), data);
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   306
    }
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   307
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   308
    /**
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   309
     * Retrieves the module for the provided name.
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   310
     *
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   311
     * @param name The module name
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   312
     * @return the module of matching name, if found
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   313
     */
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: 39635
diff changeset
   314
    public Optional<ResourcePoolModule> findModule(String name) {
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   315
        Objects.requireNonNull(name);
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   316
        return Optional.ofNullable(modules.get(name));
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   317
    }
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   318
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   319
    /**
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: 39635
diff changeset
   320
     * The stream of modules contained in this ResourcePool.
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   321
     *
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   322
     * @return The stream of modules.
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   323
     */
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: 39635
diff changeset
   324
    public Stream<ResourcePoolModule> modules() {
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   325
        return modules.values().stream();
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   326
    }
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   327
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   328
    /**
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: 39635
diff changeset
   329
     * Return the number of ResourcePoolModule count in this ResourcePool.
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   330
     *
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   331
     * @return the module count.
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   332
     */
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: 39635
diff changeset
   333
    public int moduleCount() {
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   334
        return modules.size();
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   335
    }
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   336
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   337
    /**
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: 39635
diff changeset
   338
     * Get all ResourcePoolEntry contained in this ResourcePool instance.
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   339
     *
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: 39635
diff changeset
   340
     * @return The stream of ResourcePoolModuleEntries.
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   341
     */
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: 39635
diff changeset
   342
    public Stream<ResourcePoolEntry> entries() {
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   343
        return resources.values().stream();
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   344
    }
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   345
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   346
    /**
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: 39635
diff changeset
   347
     * Return the number of ResourcePoolEntry count in this ResourcePool.
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   348
     *
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   349
     * @return the entry count.
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   350
     */
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: 39635
diff changeset
   351
    public int entryCount() {
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   352
        return resources.values().size();
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   353
    }
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   354
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   355
    /**
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: 39635
diff changeset
   356
     * Get the ResourcePoolEntry for the passed path.
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   357
     *
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   358
     * @param path A data path
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: 39635
diff changeset
   359
     * @return A ResourcePoolEntry instance or null if the data is not found
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   360
     */
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: 39635
diff changeset
   361
    public Optional<ResourcePoolEntry> findEntry(String path) {
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   362
        Objects.requireNonNull(path);
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   363
        return Optional.ofNullable(resources.get(path));
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   364
    }
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   365
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   366
    /**
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: 39635
diff changeset
   367
     * Get the ResourcePoolEntry for the passed path restricted to supplied context.
39635
07c4b195280d 8161067: jlink: Enable plugins to use the module pool for class lookup
jlaskey
parents: 39308
diff changeset
   368
     *
07c4b195280d 8161067: jlink: Enable plugins to use the module pool for class lookup
jlaskey
parents: 39308
diff changeset
   369
     * @param path A data path
07c4b195280d 8161067: jlink: Enable plugins to use the module pool for class lookup
jlaskey
parents: 39308
diff changeset
   370
     * @param context A context of the search
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: 39635
diff changeset
   371
     * @return A ResourcePoolEntry instance or null if the data is not found
39635
07c4b195280d 8161067: jlink: Enable plugins to use the module pool for class lookup
jlaskey
parents: 39308
diff changeset
   372
     */
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: 39635
diff changeset
   373
    public Optional<ResourcePoolEntry> findEntryInContext(String path, ResourcePoolEntry context) {
39635
07c4b195280d 8161067: jlink: Enable plugins to use the module pool for class lookup
jlaskey
parents: 39308
diff changeset
   374
        Objects.requireNonNull(path);
07c4b195280d 8161067: jlink: Enable plugins to use the module pool for class lookup
jlaskey
parents: 39308
diff changeset
   375
        Objects.requireNonNull(context);
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: 39635
diff changeset
   376
        ResourcePoolModule module = modules.get(context.moduleName());
39635
07c4b195280d 8161067: jlink: Enable plugins to use the module pool for class lookup
jlaskey
parents: 39308
diff changeset
   377
        Objects.requireNonNull(module);
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: 39635
diff changeset
   378
        Optional<ResourcePoolEntry> entry = module.findEntry(path);
39635
07c4b195280d 8161067: jlink: Enable plugins to use the module pool for class lookup
jlaskey
parents: 39308
diff changeset
   379
        // Navigating other modules via requires and exports is problematic
07c4b195280d 8161067: jlink: Enable plugins to use the module pool for class lookup
jlaskey
parents: 39308
diff changeset
   380
        // since we cannot construct the runtime model of loaders and layers.
07c4b195280d 8161067: jlink: Enable plugins to use the module pool for class lookup
jlaskey
parents: 39308
diff changeset
   381
        return entry;
07c4b195280d 8161067: jlink: Enable plugins to use the module pool for class lookup
jlaskey
parents: 39308
diff changeset
   382
     }
07c4b195280d 8161067: jlink: Enable plugins to use the module pool for class lookup
jlaskey
parents: 39308
diff changeset
   383
07c4b195280d 8161067: jlink: Enable plugins to use the module pool for class lookup
jlaskey
parents: 39308
diff changeset
   384
    /**
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: 39635
diff changeset
   385
     * Check if the ResourcePool contains the given ResourcePoolEntry.
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   386
     *
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   387
     * @param data The module data to check existence for.
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   388
     * @return The module data or null if not found.
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   389
     */
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: 39635
diff changeset
   390
    public boolean contains(ResourcePoolEntry data) {
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   391
        Objects.requireNonNull(data);
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: 39635
diff changeset
   392
        return findEntry(data.path()).isPresent();
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   393
    }
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   394
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   395
    /**
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: 39635
diff changeset
   396
     * Check if the ResourcePool contains some content at all.
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   397
     *
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: 39635
diff changeset
   398
     * @return True, no content, false otherwise.
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   399
     */
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: 39635
diff changeset
   400
    public boolean isEmpty() {
53a6fb443c20 8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents: 39635
diff changeset
   401
        return resources.isEmpty();
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   402
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   403
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   404
    /**
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   405
     * The ByteOrder currently in use when generating the jimage file.
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   406
     *
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   407
     * @return The ByteOrder.
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   408
     */
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: 39635
diff changeset
   409
    public ByteOrder byteOrder() {
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   410
        return order;
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   411
    }
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   412
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   413
    public StringTable getStringTable() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   414
        return table;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   415
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   416
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   417
    /**
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   418
     * A resource that has been compressed.
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   419
     */
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: 39635
diff changeset
   420
    public static final class CompressedModuleData extends ByteArrayResourcePoolEntry {
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   421
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   422
        final long uncompressed_size;
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   423
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   424
        private CompressedModuleData(String module, String path,
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: 38320
diff changeset
   425
                byte[] content, long uncompressed_size) {
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: 39635
diff changeset
   426
            super(module, path, ResourcePoolEntry.Type.CLASS_OR_RESOURCE, content);
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   427
            this.uncompressed_size = uncompressed_size;
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   428
        }
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   429
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   430
        public long getUncompressedSize() {
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   431
            return uncompressed_size;
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   432
        }
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   433
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   434
        @Override
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   435
        public boolean equals(Object other) {
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   436
            if (!(other instanceof CompressedModuleData)) {
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   437
                return false;
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   438
            }
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   439
            CompressedModuleData f = (CompressedModuleData) other;
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: 39635
diff changeset
   440
            return f.path().equals(path());
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   441
        }
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   442
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   443
        @Override
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   444
        public int hashCode() {
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   445
            return super.hashCode();
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   446
        }
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   447
    }
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 36511
diff changeset
   448
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: 39635
diff changeset
   449
    public static CompressedModuleData newCompressedResource(ResourcePoolEntry original,
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   450
            ByteBuffer compressed,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   451
            String plugin, String pluginConfig, StringTable strings,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   452
            ByteOrder order) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   453
        Objects.requireNonNull(original);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   454
        Objects.requireNonNull(compressed);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   455
        Objects.requireNonNull(plugin);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   456
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   457
        boolean isTerminal = !(original instanceof CompressedModuleData);
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: 39635
diff changeset
   458
        long uncompressed_size = original.contentLength();
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   459
        if (original instanceof CompressedModuleData) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   460
            CompressedModuleData comp = (CompressedModuleData) original;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   461
            uncompressed_size = comp.getUncompressedSize();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   462
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   463
        int nameOffset = strings.addString(plugin);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   464
        int configOffset = -1;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   465
        if (pluginConfig != null) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   466
            configOffset = strings.addString(plugin);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   467
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   468
        CompressedResourceHeader rh
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: 39635
diff changeset
   469
                = new CompressedResourceHeader(compressed.limit(), original.contentLength(),
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   470
                        nameOffset, configOffset, isTerminal);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   471
        // Merge header with content;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   472
        byte[] h = rh.getBytes(order);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   473
        ByteBuffer bb = ByteBuffer.allocate(compressed.limit() + h.length);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   474
        bb.order(order);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   475
        bb.put(h);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   476
        bb.put(compressed);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   477
        byte[] contentWithHeader = bb.array();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   478
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   479
        CompressedModuleData compressedResource
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: 39635
diff changeset
   480
                = new CompressedModuleData(original.moduleName(), original.path(),
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: 38320
diff changeset
   481
                        contentWithHeader, uncompressed_size);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   482
        return compressedResource;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   483
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   484
}