author | alanb |
Thu, 01 Dec 2016 08:57:53 +0000 | |
changeset 42338 | a60f280f803c |
parent 41352 | f9844bad9052 |
child 42471 | 86b1da05a4b0 |
permissions | -rw-r--r-- |
36511 | 1 |
/* |
2 |
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
|
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; |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41352
diff
changeset
|
38 |
import jdk.internal.loader.ResourceHelper; |
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
|
39 |
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
|
40 |
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
|
41 |
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
|
42 |
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
|
43 |
import jdk.tools.jlink.plugin.ResourcePoolModuleView; |
38320 | 44 |
import jdk.tools.jlink.plugin.PluginException; |
36511 | 45 |
|
46 |
/** |
|
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
|
47 |
* A manager for pool of resources. |
36511 | 48 |
*/ |
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
|
49 |
public class ResourcePoolManager { |
39894
cd4f403f9618
8162782: jlink ResourcePool.releaseProperties should be removed
sundar
parents:
39834
diff
changeset
|
50 |
// utility to read ModuleDescriptor of the given ResourcePoolModule |
cd4f403f9618
8162782: jlink ResourcePool.releaseProperties should be removed
sundar
parents:
39834
diff
changeset
|
51 |
static ModuleDescriptor readModuleDescriptor(ResourcePoolModule mod) { |
cd4f403f9618
8162782: jlink ResourcePool.releaseProperties should be removed
sundar
parents:
39834
diff
changeset
|
52 |
String p = "/" + mod.name() + "/module-info.class"; |
cd4f403f9618
8162782: jlink ResourcePool.releaseProperties should be removed
sundar
parents:
39834
diff
changeset
|
53 |
Optional<ResourcePoolEntry> content = mod.findEntry(p); |
cd4f403f9618
8162782: jlink ResourcePool.releaseProperties should be removed
sundar
parents:
39834
diff
changeset
|
54 |
if (!content.isPresent()) { |
cd4f403f9618
8162782: jlink ResourcePool.releaseProperties should be removed
sundar
parents:
39834
diff
changeset
|
55 |
throw new PluginException("No module-info for " + mod.name() |
cd4f403f9618
8162782: jlink ResourcePool.releaseProperties should be removed
sundar
parents:
39834
diff
changeset
|
56 |
+ " module"); |
cd4f403f9618
8162782: jlink ResourcePool.releaseProperties should be removed
sundar
parents:
39834
diff
changeset
|
57 |
} |
cd4f403f9618
8162782: jlink ResourcePool.releaseProperties should be removed
sundar
parents:
39834
diff
changeset
|
58 |
ByteBuffer bb = ByteBuffer.wrap(content.get().contentBytes()); |
cd4f403f9618
8162782: jlink ResourcePool.releaseProperties should be removed
sundar
parents:
39834
diff
changeset
|
59 |
return ModuleDescriptor.read(bb); |
cd4f403f9618
8162782: jlink ResourcePool.releaseProperties should be removed
sundar
parents:
39834
diff
changeset
|
60 |
} |
38320 | 61 |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41352
diff
changeset
|
62 |
/** |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41352
diff
changeset
|
63 |
* Returns true if a resource has an effective package. |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41352
diff
changeset
|
64 |
*/ |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41352
diff
changeset
|
65 |
public static boolean isNamedPackageResource(String path) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41352
diff
changeset
|
66 |
return (path.endsWith(".class") && !path.endsWith("module-info.class")) || |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41352
diff
changeset
|
67 |
!ResourceHelper.isSimpleResource(path); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41352
diff
changeset
|
68 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41352
diff
changeset
|
69 |
|
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
|
70 |
class ResourcePoolModuleImpl implements ResourcePoolModule { |
36511 | 71 |
|
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
|
72 |
final Map<String, ResourcePoolEntry> moduleContent = new LinkedHashMap<>(); |
39894
cd4f403f9618
8162782: jlink ResourcePool.releaseProperties should be removed
sundar
parents:
39834
diff
changeset
|
73 |
// lazily initialized |
38320 | 74 |
private ModuleDescriptor descriptor; |
75 |
final String name; |
|
36511 | 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 |
private ResourcePoolModuleImpl(String name) { |
38320 | 78 |
this.name = name; |
79 |
} |
|
36511 | 80 |
|
38320 | 81 |
@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
|
82 |
public String name() { |
38320 | 83 |
return name; |
36511 | 84 |
} |
85 |
||
38320 | 86 |
@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
|
87 |
public Optional<ResourcePoolEntry> findEntry(String path) { |
38320 | 88 |
if (!path.startsWith("/")) { |
89 |
path = "/" + path; |
|
90 |
} |
|
40209
68e8944f4424
8163382: ResourcePoolManager.findEntry has a bug in startsWith call
sundar
parents:
40121
diff
changeset
|
91 |
if (!path.startsWith("/" + name + "/")) { |
68e8944f4424
8163382: ResourcePoolManager.findEntry has a bug in startsWith call
sundar
parents:
40121
diff
changeset
|
92 |
path = "/" + name + path; // path already starts with '/' |
38320 | 93 |
} |
94 |
return Optional.ofNullable(moduleContent.get(path)); |
|
95 |
} |
|
96 |
||
97 |
@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
|
98 |
public ModuleDescriptor descriptor() { |
38320 | 99 |
if (descriptor == null) { |
39894
cd4f403f9618
8162782: jlink ResourcePool.releaseProperties should be removed
sundar
parents:
39834
diff
changeset
|
100 |
descriptor = readModuleDescriptor(this); |
38320 | 101 |
} |
102 |
return descriptor; |
|
36511 | 103 |
} |
104 |
||
105 |
@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
|
106 |
public Set<String> packages() { |
38320 | 107 |
Set<String> pkgs = new HashSet<>(); |
41352 | 108 |
moduleContent.values().stream() |
109 |
.filter(m -> m.type() == ResourcePoolEntry.Type.CLASS_OR_RESOURCE) |
|
110 |
.forEach(res -> { |
|
111 |
String name = ImageFileCreator.resourceName(res.path()); |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41352
diff
changeset
|
112 |
if (isNamedPackageResource(name)) { |
41352 | 113 |
String pkg = ImageFileCreator.toPackage(name); |
114 |
if (!pkg.isEmpty()) { |
|
115 |
pkgs.add(pkg); |
|
116 |
} |
|
38320 | 117 |
} |
41352 | 118 |
}); |
38320 | 119 |
return pkgs; |
120 |
} |
|
121 |
||
122 |
@Override |
|
123 |
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
|
124 |
return name(); |
38320 | 125 |
} |
126 |
||
127 |
@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
|
128 |
public Stream<ResourcePoolEntry> entries() { |
38320 | 129 |
return moduleContent.values().stream(); |
130 |
} |
|
131 |
||
132 |
@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
|
133 |
public int entryCount() { |
38320 | 134 |
return moduleContent.values().size(); |
36511 | 135 |
} |
136 |
} |
|
137 |
||
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
|
138 |
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
|
139 |
@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
|
140 |
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
|
141 |
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
|
142 |
} |
53a6fb443c20
8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents:
39635
diff
changeset
|
143 |
|
53a6fb443c20
8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents:
39635
diff
changeset
|
144 |
@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
|
145 |
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
|
146 |
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
|
147 |
} |
53a6fb443c20
8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents:
39635
diff
changeset
|
148 |
|
53a6fb443c20
8162538: plugin 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 |
@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
|
150 |
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
|
151 |
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
|
152 |
} |
53a6fb443c20
8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents:
39635
diff
changeset
|
153 |
|
53a6fb443c20
8162538: plugin 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 |
@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
|
155 |
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
|
156 |
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
|
157 |
} |
53a6fb443c20
8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents:
39635
diff
changeset
|
158 |
|
53a6fb443c20
8162538: plugin 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 |
@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
|
160 |
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
|
161 |
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
|
162 |
} |
53a6fb443c20
8162538: plugin 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 |
@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
|
165 |
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
|
166 |
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
|
167 |
} |
53a6fb443c20
8162538: plugin 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 |
@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
|
170 |
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
|
171 |
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
|
172 |
} |
53a6fb443c20
8162538: plugin 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 |
@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
|
175 |
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
|
176 |
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
|
177 |
} |
53a6fb443c20
8162538: plugin 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 |
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
|
180 |
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
|
181 |
} |
53a6fb443c20
8162538: plugin 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 |
} |
53a6fb443c20
8162538: plugin 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 |
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
|
185 |
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
|
186 |
|
53a6fb443c20
8162538: plugin 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 |
@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
|
188 |
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
|
189 |
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
|
190 |
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
|
191 |
} |
53a6fb443c20
8162538: plugin 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 |
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
|
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 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
|
197 |
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
|
198 |
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
|
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 |
} |
53a6fb443c20
8162538: plugin 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 |
|
53a6fb443c20
8162538: plugin 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 |
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
|
203 |
@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
|
204 |
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
|
205 |
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
|
206 |
} |
53a6fb443c20
8162538: plugin 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 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
|
210 |
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
|
211 |
} |
53a6fb443c20
8162538: plugin 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 |
@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
|
214 |
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
|
215 |
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
|
216 |
} |
53a6fb443c20
8162538: plugin 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 |
} |
53a6fb443c20
8162538: plugin 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 |
|
53a6fb443c20
8162538: plugin 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 |
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
|
220 |
private final Map<String, ResourcePoolModule> modules = new LinkedHashMap<>(); |
38320 | 221 |
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
|
222 |
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
|
223 |
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
|
224 |
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
|
225 |
private final ResourcePoolModuleView moduleViewImpl; |
38320 | 226 |
|
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
|
227 |
public ResourcePoolManager() { |
38320 | 228 |
this(ByteOrder.nativeOrder()); |
229 |
} |
|
230 |
||
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
|
231 |
public ResourcePoolManager(ByteOrder order) { |
38320 | 232 |
this(order, new StringTable() { |
36511 | 233 |
|
234 |
@Override |
|
235 |
public int addString(String str) { |
|
236 |
return -1; |
|
237 |
} |
|
38320 | 238 |
|
36511 | 239 |
@Override |
240 |
public String getString(int id) { |
|
241 |
return null; |
|
242 |
} |
|
243 |
}); |
|
244 |
} |
|
245 |
||
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
|
246 |
public ResourcePoolManager(ByteOrder order, StringTable table) { |
39308 | 247 |
this.order = Objects.requireNonNull(order); |
248 |
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
|
249 |
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
|
250 |
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
|
251 |
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
|
252 |
} |
53a6fb443c20
8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents:
39635
diff
changeset
|
253 |
|
53a6fb443c20
8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents:
39635
diff
changeset
|
254 |
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
|
255 |
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
|
256 |
} |
53a6fb443c20
8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents:
39635
diff
changeset
|
257 |
|
53a6fb443c20
8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents:
39635
diff
changeset
|
258 |
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
|
259 |
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
|
260 |
} |
53a6fb443c20
8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents:
39635
diff
changeset
|
261 |
|
53a6fb443c20
8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents:
39635
diff
changeset
|
262 |
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
|
263 |
return moduleViewImpl; |
38320 | 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 |
* Add a ResourcePoolEntry. |
38320 | 268 |
* |
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
|
269 |
* @param data The ResourcePoolEntry to add. |
38320 | 270 |
*/ |
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
|
271 |
public void add(ResourcePoolEntry data) { |
38320 | 272 |
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
|
273 |
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
|
274 |
throw new PluginException("Resource " + data.path() |
38320 | 275 |
+ " already present"); |
276 |
} |
|
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
|
277 |
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
|
278 |
ResourcePoolModuleImpl m = (ResourcePoolModuleImpl)modules.get(modulename); |
38320 | 279 |
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
|
280 |
m = new ResourcePoolModuleImpl(modulename); |
38320 | 281 |
modules.put(modulename, m); |
282 |
} |
|
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
|
283 |
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
|
284 |
m.moduleContent.put(data.path(), data); |
38320 | 285 |
} |
286 |
||
287 |
/** |
|
288 |
* Retrieves the module for the provided name. |
|
289 |
* |
|
290 |
* @param name The module name |
|
291 |
* @return the module of matching name, if found |
|
292 |
*/ |
|
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
|
293 |
public Optional<ResourcePoolModule> findModule(String name) { |
38320 | 294 |
Objects.requireNonNull(name); |
295 |
return Optional.ofNullable(modules.get(name)); |
|
296 |
} |
|
297 |
||
298 |
/** |
|
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
|
299 |
* The stream of modules contained in this ResourcePool. |
38320 | 300 |
* |
301 |
* @return The stream of modules. |
|
302 |
*/ |
|
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
|
303 |
public Stream<ResourcePoolModule> modules() { |
38320 | 304 |
return modules.values().stream(); |
305 |
} |
|
306 |
||
307 |
/** |
|
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
|
308 |
* Return the number of ResourcePoolModule count in this ResourcePool. |
38320 | 309 |
* |
310 |
* @return the module count. |
|
311 |
*/ |
|
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
|
312 |
public int moduleCount() { |
38320 | 313 |
return modules.size(); |
314 |
} |
|
36511 | 315 |
|
38320 | 316 |
/** |
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
|
317 |
* Get all ResourcePoolEntry contained in this ResourcePool instance. |
38320 | 318 |
* |
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
|
319 |
* @return The stream of ResourcePoolModuleEntries. |
38320 | 320 |
*/ |
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
|
321 |
public Stream<ResourcePoolEntry> entries() { |
38320 | 322 |
return resources.values().stream(); |
323 |
} |
|
324 |
||
325 |
/** |
|
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
|
326 |
* Return the number of ResourcePoolEntry count in this ResourcePool. |
38320 | 327 |
* |
328 |
* @return the entry count. |
|
329 |
*/ |
|
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
|
330 |
public int entryCount() { |
38320 | 331 |
return resources.values().size(); |
332 |
} |
|
333 |
||
334 |
/** |
|
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
|
335 |
* Get the ResourcePoolEntry for the passed path. |
38320 | 336 |
* |
337 |
* @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
|
338 |
* @return A ResourcePoolEntry instance or null if the data is not found |
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 |
public Optional<ResourcePoolEntry> findEntry(String path) { |
38320 | 341 |
Objects.requireNonNull(path); |
342 |
return Optional.ofNullable(resources.get(path)); |
|
343 |
} |
|
344 |
||
345 |
/** |
|
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
|
346 |
* 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
|
347 |
* |
07c4b195280d
8161067: jlink: Enable plugins to use the module pool for class lookup
jlaskey
parents:
39308
diff
changeset
|
348 |
* @param path A data path |
07c4b195280d
8161067: jlink: Enable plugins to use the module pool for class lookup
jlaskey
parents:
39308
diff
changeset
|
349 |
* @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
|
350 |
* @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
|
351 |
*/ |
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
|
352 |
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
|
353 |
Objects.requireNonNull(path); |
07c4b195280d
8161067: jlink: Enable plugins to use the module pool for class lookup
jlaskey
parents:
39308
diff
changeset
|
354 |
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
|
355 |
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
|
356 |
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
|
357 |
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
|
358 |
// 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
|
359 |
// 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
|
360 |
return entry; |
07c4b195280d
8161067: jlink: Enable plugins to use the module pool for class lookup
jlaskey
parents:
39308
diff
changeset
|
361 |
} |
07c4b195280d
8161067: jlink: Enable plugins to use the module pool for class lookup
jlaskey
parents:
39308
diff
changeset
|
362 |
|
07c4b195280d
8161067: jlink: Enable plugins to use the module pool for class lookup
jlaskey
parents:
39308
diff
changeset
|
363 |
/** |
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
|
364 |
* Check if the ResourcePool contains the given ResourcePoolEntry. |
38320 | 365 |
* |
366 |
* @param data The module data to check existence for. |
|
367 |
* @return The module data or null if not found. |
|
368 |
*/ |
|
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
|
369 |
public boolean contains(ResourcePoolEntry data) { |
38320 | 370 |
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
|
371 |
return findEntry(data.path()).isPresent(); |
38320 | 372 |
} |
373 |
||
374 |
/** |
|
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
|
375 |
* Check if the ResourcePool contains some content at all. |
38320 | 376 |
* |
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
|
377 |
* @return True, no content, false otherwise. |
38320 | 378 |
*/ |
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
|
379 |
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
|
380 |
return resources.isEmpty(); |
36511 | 381 |
} |
382 |
||
38320 | 383 |
/** |
384 |
* The ByteOrder currently in use when generating the jimage file. |
|
385 |
* |
|
386 |
* @return The ByteOrder. |
|
387 |
*/ |
|
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
|
388 |
public ByteOrder byteOrder() { |
38320 | 389 |
return order; |
390 |
} |
|
391 |
||
36511 | 392 |
public StringTable getStringTable() { |
393 |
return table; |
|
394 |
} |
|
395 |
||
396 |
/** |
|
38320 | 397 |
* A resource that has been compressed. |
398 |
*/ |
|
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
|
399 |
public static final class CompressedModuleData extends ByteArrayResourcePoolEntry { |
38320 | 400 |
|
401 |
final long uncompressed_size; |
|
402 |
||
403 |
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
|
404 |
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
|
405 |
super(module, path, ResourcePoolEntry.Type.CLASS_OR_RESOURCE, content); |
38320 | 406 |
this.uncompressed_size = uncompressed_size; |
407 |
} |
|
408 |
||
409 |
public long getUncompressedSize() { |
|
410 |
return uncompressed_size; |
|
411 |
} |
|
412 |
||
413 |
@Override |
|
414 |
public boolean equals(Object other) { |
|
415 |
if (!(other instanceof CompressedModuleData)) { |
|
416 |
return false; |
|
417 |
} |
|
418 |
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
|
419 |
return f.path().equals(path()); |
38320 | 420 |
} |
421 |
||
422 |
@Override |
|
423 |
public int hashCode() { |
|
424 |
return super.hashCode(); |
|
425 |
} |
|
426 |
} |
|
427 |
||
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
|
428 |
public static CompressedModuleData newCompressedResource(ResourcePoolEntry original, |
36511 | 429 |
ByteBuffer compressed, |
430 |
String plugin, String pluginConfig, StringTable strings, |
|
431 |
ByteOrder order) { |
|
432 |
Objects.requireNonNull(original); |
|
433 |
Objects.requireNonNull(compressed); |
|
434 |
Objects.requireNonNull(plugin); |
|
435 |
||
436 |
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
|
437 |
long uncompressed_size = original.contentLength(); |
36511 | 438 |
if (original instanceof CompressedModuleData) { |
439 |
CompressedModuleData comp = (CompressedModuleData) original; |
|
440 |
uncompressed_size = comp.getUncompressedSize(); |
|
441 |
} |
|
442 |
int nameOffset = strings.addString(plugin); |
|
443 |
int configOffset = -1; |
|
444 |
if (pluginConfig != null) { |
|
445 |
configOffset = strings.addString(plugin); |
|
446 |
} |
|
447 |
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
|
448 |
= new CompressedResourceHeader(compressed.limit(), original.contentLength(), |
36511 | 449 |
nameOffset, configOffset, isTerminal); |
450 |
// Merge header with content; |
|
451 |
byte[] h = rh.getBytes(order); |
|
452 |
ByteBuffer bb = ByteBuffer.allocate(compressed.limit() + h.length); |
|
453 |
bb.order(order); |
|
454 |
bb.put(h); |
|
455 |
bb.put(compressed); |
|
456 |
byte[] contentWithHeader = bb.array(); |
|
457 |
||
458 |
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
|
459 |
= 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
|
460 |
contentWithHeader, uncompressed_size); |
36511 | 461 |
return compressedResource; |
462 |
} |
|
463 |
} |