/* * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/ package tests;
try (OutputStream out = Files.newOutputStream(jarfile);
JarOutputStream jos = new JarOutputStream(out)) { for (Path entry : entries) { // map the file path to a name in the JAR file
Path normalized = entry.normalize();
String name = normalized
.subpath(0, normalized.getNameCount()) // drop root
.toString()
.replace(File.separatorChar, '/');
publicstatic Set<String> getModuleContent(Path module) {
Result result = JImageGenerator.getJModTask()
.jmod(module)
.list();
result.assertSuccess(); return Stream.of(result.getMessage().split("\r?\n"))
.collect(Collectors.toSet());
}
publicstaticvoid checkModule(Path module, Set<String> expected) throws IOException {
Set<String> actual = getModuleContent(module); if (!Objects.equals(actual, expected)) {
Set<String> unexpected = new HashSet<>(actual);
unexpected.removeAll(expected);
Set<String> notFound = new HashSet<>(expected);
notFound.removeAll(actual);
System.err.println("Unexpected files:");
unexpected.forEach(s -> System.err.println("\t" + s));
System.err.println("Not found files:");
notFound.forEach(s -> System.err.println("\t" + s)); thrownew AssertionError("Module check failed.");
}
}
publicstaticclass JModTask { staticfinal java.util.spi.ToolProvider JMOD_TOOL =
java.util.spi.ToolProvider.findFirst("jmod").orElseThrow(() -> new RuntimeException("jmod tool not found")
);
privatefinal List<Path> classpath = new ArrayList<>(); privatefinal List<Path> libs = new ArrayList<>(); privatefinal List<Path> cmds = new ArrayList<>(); privatefinal List<Path> config = new ArrayList<>(); privatefinal List<Path> jars = new ArrayList<>(); privatefinal List<Path> jmods = new ArrayList<>(); privatefinal List<String> options = new ArrayList<>(); private Path output; private String hashModules; private String mainClass; private String moduleVersion;
public JModTask addNativeLibraries(Path cp) { this.libs.add(cp); returnthis;
}
public JModTask hashModules(String hash) { this.hashModules = hash; returnthis;
}
public JModTask addCmds(Path cp) { this.cmds.add(cp); returnthis;
}
public JModTask addClassPath(Path cp) { this.classpath.add(cp); returnthis;
}
public JModTask addConfig(Path cp) { this.config.add(cp); returnthis;
}
public JModTask addJars(Path jars) { this.jars.add(jars); returnthis;
}
public JModTask addJmods(Path jmods) { this.jmods.add(jmods); returnthis;
}
public JModTask jmod(Path output) { this.output = output; returnthis;
}
public JModTask moduleVersion(String moduleVersion) { this.moduleVersion = moduleVersion; returnthis;
}
public JModTask mainClass(String mainClass) { this.mainClass = mainClass; returnthis;
}
public JModTask option(String o) { this.options.add(o); returnthis;
}
private String modulePath() { // This is expect FIRST jmods THEN jars, if you change this, some tests could fail
String jmods = toPath(this.jmods);
String jars = toPath(this.jars); return jmods + File.pathSeparator + jars;
}
private Result cmd(String cmd, Path returnPath) {
String[] args = optionsJImage(cmd);
System.err.println("jimage options: " + optionsPrettyPrint(args));
StringWriter writer = new StringWriter(); int exitCode = jdk.tools.jimage.Main.run(args, new PrintWriter(writer)); returnnew Result(exitCode, writer.toString(), returnPath);
}
public Result extract() { return cmd("extract", dir);
}
}
publicstaticclass JLinkTask { staticfinal java.util.spi.ToolProvider JLINK_TOOL =
java.util.spi.ToolProvider.findFirst("jlink").orElseThrow(() -> new RuntimeException("jlink tool not found")
);
privatefinal List<Path> jars = new ArrayList<>(); privatefinal List<Path> jmods = new ArrayList<>(); privatefinal List<Path> pluginModulePath = new ArrayList<>(); privatefinal List<String> addMods = new ArrayList<>(); privatefinal List<String> limitMods = new ArrayList<>(); privatefinal List<String> options = new ArrayList<>(); private String modulePath; // if you want to specifiy repeated --module-path option private String repeatedModulePath; // if you want to specifiy repeated --limit-modules option private String repeatedLimitMods; private Path output; private Path existing; private String launcher; // optional
public JLinkTask modulePath(String modulePath) { this.modulePath = modulePath; returnthis;
}
public JLinkTask launcher(String cmd) {
launcher = Objects.requireNonNull(cmd); returnthis;
}
public JLinkTask repeatedModulePath(String modulePath) { this.repeatedModulePath = modulePath; returnthis;
}
public JLinkTask addJars(Path jars) { this.jars.add(jars); returnthis;
}
public JLinkTask addJmods(Path jmods) { this.jmods.add(jmods); returnthis;
}
public JLinkTask pluginModulePath(Path p) { this.pluginModulePath.add(p); returnthis;
}
public JLinkTask addMods(String moduleName) { this.addMods.add(moduleName); returnthis;
}
public JLinkTask limitMods(String moduleName) { this.limitMods.add(moduleName); returnthis;
}
public JLinkTask repeatedLimitMods(String modules) { this.repeatedLimitMods = modules; returnthis;
}
public JLinkTask output(Path output) { this.output = output; returnthis;
}
public JLinkTask existing(Path existing) { this.existing = existing; returnthis;
}
public JLinkTask option(String o) { this.options.add(o); returnthis;
}
private String modulePath() { // This is expect FIRST jmods THEN jars, if you change this, some tests could fail
String jmods = toPath(this.jmods);
String jars = toPath(this.jars); return jmods + File.pathSeparator + jars;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.