author | alanb |
Thu, 04 May 2017 07:26:55 +0000 | |
changeset 45004 | ea3137042a61 |
parent 44359 | c6761862ca0b |
permissions | -rw-r--r-- |
36511 | 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 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
package jdk.tools.jlink.internal; |
|
26 |
||
38320 | 27 |
import java.lang.module.ModuleDescriptor; |
36511 | 28 |
import java.nio.ByteBuffer; |
29 |
import java.nio.ByteOrder; |
|
38320 | 30 |
import java.util.HashSet; |
31 |
import java.util.LinkedHashMap; |
|
32 |
import java.util.Map; |
|
36511 | 33 |
import java.util.Objects; |
38320 | 34 |
import java.util.Optional; |
35 |
import java.util.Set; |
|
36 |
import java.util.stream.Stream; |
|
36511 | 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 | 47 |
import jdk.tools.jlink.plugin.PluginException; |
36511 | 48 |
|
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 | 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 | 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 | 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 | 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 | 84 |
final String name; |
36511 | 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 | 87 |
this.name = name; |
88 |
} |
|
36511 | 89 |
|
38320 | 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 | 92 |
return name; |
36511 | 93 |
} |
94 |
||
38320 | 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 | 97 |
if (!path.startsWith("/")) { |
98 |
path = "/" + path; |
|
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 | 102 |
} |
103 |
return Optional.ofNullable(moduleContent.get(path)); |
|
104 |
} |
|
105 |
||
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 | 123 |
} |
36511 | 124 |
} |
125 |
||
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 | 128 |
Set<String> pkgs = new HashSet<>(); |
41352 | 129 |
moduleContent.values().stream() |
130 |
.filter(m -> m.type() == ResourcePoolEntry.Type.CLASS_OR_RESOURCE) |
|
131 |
.forEach(res -> { |
|
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 | 134 |
String pkg = ImageFileCreator.toPackage(name); |
135 |
if (!pkg.isEmpty()) { |
|
136 |
pkgs.add(pkg); |
|
137 |
} |
|
38320 | 138 |
} |
41352 | 139 |
}); |
38320 | 140 |
return pkgs; |
141 |
} |
|
142 |
||
143 |
@Override |
|
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 | 146 |
} |
147 |
||
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 | 150 |
return moduleContent.values().stream(); |
151 |
} |
|
152 |
||
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 | 155 |
return moduleContent.values().size(); |
36511 | 156 |
} |
157 |
} |
|
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 | 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 | 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 | 249 |
this(ByteOrder.nativeOrder()); |
250 |
} |
|
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 | 253 |
this(order, new StringTable() { |
36511 | 254 |
|
255 |
@Override |
|
256 |
public int addString(String str) { |
|
257 |
return -1; |
|
258 |
} |
|
38320 | 259 |
|
36511 | 260 |
@Override |
261 |
public String getString(int id) { |
|
262 |
return null; |
|
263 |
} |
|
264 |
}); |
|
265 |
} |
|
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 | 268 |
this.order = Objects.requireNonNull(order); |
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 | 285 |
} |
286 |
||
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 | 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 | 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 | 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 | 296 |
+ " already present"); |
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 | 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 | 302 |
modules.put(modulename, m); |
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 | 306 |
} |
307 |
||
308 |
/** |
|
309 |
* Retrieves the module for the provided name. |
|
310 |
* |
|
311 |
* @param name The module name |
|
312 |
* @return the module of matching name, if found |
|
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 | 315 |
Objects.requireNonNull(name); |
316 |
return Optional.ofNullable(modules.get(name)); |
|
317 |
} |
|
318 |
||
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 | 321 |
* |
322 |
* @return The stream of modules. |
|
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 | 325 |
return modules.values().stream(); |
326 |
} |
|
327 |
||
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 | 330 |
* |
331 |
* @return the module count. |
|
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 | 334 |
return modules.size(); |
335 |
} |
|
36511 | 336 |
|
38320 | 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 | 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 | 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 | 343 |
return resources.values().stream(); |
344 |
} |
|
345 |
||
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 | 348 |
* |
349 |
* @return the entry count. |
|
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 | 352 |
return resources.values().size(); |
353 |
} |
|
354 |
||
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 | 357 |
* |
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 | 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 | 362 |
Objects.requireNonNull(path); |
363 |
return Optional.ofNullable(resources.get(path)); |
|
364 |
} |
|
365 |
||
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 | 386 |
* |
387 |
* @param data The module data to check existence for. |
|
388 |
* @return The module data or null if not found. |
|
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 | 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 | 393 |
} |
394 |
||
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 | 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 | 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 | 402 |
} |
403 |
||
38320 | 404 |
/** |
405 |
* The ByteOrder currently in use when generating the jimage file. |
|
406 |
* |
|
407 |
* @return The ByteOrder. |
|
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 | 410 |
return order; |
411 |
} |
|
412 |
||
36511 | 413 |
public StringTable getStringTable() { |
414 |
return table; |
|
415 |
} |
|
416 |
||
417 |
/** |
|
38320 | 418 |
* A resource that has been compressed. |
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 | 421 |
|
422 |
final long uncompressed_size; |
|
423 |
||
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 | 427 |
this.uncompressed_size = uncompressed_size; |
428 |
} |
|
429 |
||
430 |
public long getUncompressedSize() { |
|
431 |
return uncompressed_size; |
|
432 |
} |
|
433 |
||
434 |
@Override |
|
435 |
public boolean equals(Object other) { |
|
436 |
if (!(other instanceof CompressedModuleData)) { |
|
437 |
return false; |
|
438 |
} |
|
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 | 441 |
} |
442 |
||
443 |
@Override |
|
444 |
public int hashCode() { |
|
445 |
return super.hashCode(); |
|
446 |
} |
|
447 |
} |
|
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 | 450 |
ByteBuffer compressed, |
451 |
String plugin, String pluginConfig, StringTable strings, |
|
452 |
ByteOrder order) { |
|
453 |
Objects.requireNonNull(original); |
|
454 |
Objects.requireNonNull(compressed); |
|
455 |
Objects.requireNonNull(plugin); |
|
456 |
||
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 | 459 |
if (original instanceof CompressedModuleData) { |
460 |
CompressedModuleData comp = (CompressedModuleData) original; |
|
461 |
uncompressed_size = comp.getUncompressedSize(); |
|
462 |
} |
|
463 |
int nameOffset = strings.addString(plugin); |
|
464 |
int configOffset = -1; |
|
465 |
if (pluginConfig != null) { |
|
466 |
configOffset = strings.addString(plugin); |
|
467 |
} |
|
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 | 470 |
nameOffset, configOffset, isTerminal); |
471 |
// Merge header with content; |
|
472 |
byte[] h = rh.getBytes(order); |
|
473 |
ByteBuffer bb = ByteBuffer.allocate(compressed.limit() + h.length); |
|
474 |
bb.order(order); |
|
475 |
bb.put(h); |
|
476 |
bb.put(compressed); |
|
477 |
byte[] contentWithHeader = bb.array(); |
|
478 |
||
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 | 482 |
return compressedResource; |
483 |
} |
|
484 |
} |