本文整理汇总了Java中jdk.tools.jlink.plugin.Plugin.transform方法的典型用法代码示例。如果您正苦于以下问题:Java Plugin.transform方法的具体用法?Java Plugin.transform怎么用?Java Plugin.transform使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jdk.tools.jlink.plugin.Plugin
的用法示例。
在下文中一共展示了Plugin.transform方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: stripDebug
import jdk.tools.jlink.plugin.Plugin; //导入方法依赖的package包/类
private ResourcePoolEntry stripDebug(Plugin debug, ResourcePoolEntry classResource,
String path, String infoPath, byte[] moduleInfo) throws Exception {
ResourcePoolManager resources = new ResourcePoolManager();
resources.add(classResource);
if (!path.endsWith("module-info.class")) {
ResourcePoolEntry res2 = ResourcePoolEntry.create(infoPath, moduleInfo);
resources.add(res2);
}
ResourcePoolManager results = new ResourcePoolManager();
ResourcePool resPool = debug.transform(resources.resourcePool(),
results.resourcePoolBuilder());
System.out.println(classResource.path());
return resPool.findEntry(classResource.path()).get();
}
示例2: applyCompressor
import jdk.tools.jlink.plugin.Plugin; //导入方法依赖的package包/类
private ResourcePool applyCompressor(Plugin plugin,
ResourcePoolManager inputResources,
ResourcePoolEntry res,
List<Pattern> includesPatterns) {
ResourcePoolManager resMgr = new ResourcePoolManager(ByteOrder.nativeOrder(),
inputResources.getStringTable());
ResourcePool compressedResourcePool = plugin.transform(inputResources.resourcePool(),
resMgr.resourcePoolBuilder());
String path = res.path();
ResourcePoolEntry compressed = compressedResourcePool.findEntry(path).get();
CompressedResourceHeader header
= CompressedResourceHeader.readFromResource(ByteOrder.nativeOrder(), compressed.contentBytes());
if (isIncluded(includesPatterns, path)) {
if (header == null) {
throw new AssertionError("Path should be compressed: " + path);
}
if (header.getDecompressorNameOffset() == 0) {
throw new AssertionError("Invalid plugin offset "
+ header.getDecompressorNameOffset());
}
if (header.getResourceSize() <= 0) {
throw new AssertionError("Invalid compressed size "
+ header.getResourceSize());
}
} else if (header != null) {
throw new AssertionError("Path should not be compressed: " + path);
}
return compressedResourcePool;
}
示例3: doCheckVM
import jdk.tools.jlink.plugin.Plugin; //导入方法依赖的package包/类
private void doCheckVM(String vm, String[] input, String jvmcfg, String[] expectedOutput, String expectdJvmCfg) throws Exception {
// Create a pool with jvm.cfg and the input paths.
byte[] jvmcfgContent = jvmcfg.getBytes();
ResourcePoolManager poolMgr = new ResourcePoolManager();
poolMgr.add(
ResourcePoolEntry.create("/java.base/lib/jvm.cfg",
ResourcePoolEntry.Type.NATIVE_LIB, jvmcfgContent));
// java.base/module-info.class is used by exclude vm plugin
// to get current osName(). We read it from jrt-fs and add a
// ResourcePoolEntry
poolMgr.add(
ResourcePoolEntry.create("/java.base/module-info.class",
ResourcePoolEntry.Type.CLASS_OR_RESOURCE, getJavaBaseModuleInfo()));
for (String in : input) {
poolMgr.add(ResourcePoolEntry.create(in,
ResourcePoolEntry.Type.NATIVE_LIB, new byte[0]));
}
ResourcePoolManager outMgr = new ResourcePoolManager();
Plugin p = new ExcludeVMPlugin();
Map<String, String> config = new HashMap<>();
if (vm != null) {
config.put(ExcludeVMPlugin.NAME, vm);
}
p.configure(config);
ResourcePool out = p.transform(poolMgr.resourcePool(), outMgr.resourcePoolBuilder());
String newContent = new String(out.findEntry("/java.base/lib/jvm.cfg").get().contentBytes());
if (!expectdJvmCfg.equals(newContent)) {
throw new Exception("Got content " + newContent + " expected " + expectdJvmCfg);
}
// Apart from native resources, we should find jvm.cfg and
// java.base/module-info.class. So, we add 2 here to the
// expected count!
if (out.entryCount() != (expectedOutput.length + 2)) {
out.entries().forEach(m -> {
System.err.println(m.path());
});
throw new Exception("Invalid output size " + out.entryCount() + " expected " + (expectedOutput.length + 2));
}
out.entries().forEach(md -> {
if (md.path().equals("/java.base/lib/jvm.cfg") ||
md.path().equals("/java.base/module-info.class")) {
return;
}
boolean contained = false;
for (String o : expectedOutput) {
if (md.path().equals(o)) {
contained = true;
break;
}
}
if (!contained) {
throw new RuntimeException(md.path() + " not expected");
}
});
}