8163320: JAVA_VERSION in release file should come from java.base module
Reviewed-by: mchung
This commit is contained in:
parent
2cca4bcc0a
commit
0fd0cd0d3b
@ -55,6 +55,7 @@ import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import jdk.tools.jlink.internal.BasicImageWriter;
|
||||
import jdk.tools.jlink.internal.plugins.FileCopierPlugin.SymImageFile;
|
||||
import jdk.tools.jlink.internal.ExecutableImage;
|
||||
@ -159,7 +160,7 @@ public final class DefaultImageBuilder implements ImageBuilder {
|
||||
}
|
||||
i++;
|
||||
}
|
||||
props.setProperty("MODULES", builder.toString());
|
||||
props.setProperty("MODULES", quote(builder.toString()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -217,19 +218,38 @@ public final class DefaultImageBuilder implements ImageBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
// Parse version string and return a string that includes only version part
|
||||
// leaving "pre", "build" information. See also: java.lang.Runtime.Version.
|
||||
private static String parseVersion(String str) {
|
||||
return Runtime.Version.parse(str).
|
||||
version().
|
||||
stream().
|
||||
map(Object::toString).
|
||||
collect(Collectors.joining("."));
|
||||
}
|
||||
|
||||
private static String quote(String str) {
|
||||
return "\"" + str + "\"";
|
||||
}
|
||||
|
||||
private Properties releaseProperties(ResourcePool pool) throws IOException {
|
||||
Properties props = new Properties();
|
||||
Optional<ResourcePoolModule> javaBase = pool.moduleView().findModule("java.base");
|
||||
javaBase.ifPresent(mod -> {
|
||||
// fill release information available from transformed "java.base" module!
|
||||
ModuleDescriptor desc = mod.descriptor();
|
||||
desc.osName().ifPresent(s -> props.setProperty("OS_NAME", s));
|
||||
desc.osVersion().ifPresent(s -> props.setProperty("OS_VERSION", s));
|
||||
desc.osArch().ifPresent(s -> props.setProperty("OS_ARCH", s));
|
||||
props.setProperty("JAVA_VERSION", System.getProperty("java.version"));
|
||||
desc.osName().ifPresent(s -> {
|
||||
props.setProperty("OS_NAME", quote(s));
|
||||
this.targetOsName = s;
|
||||
});
|
||||
desc.osVersion().ifPresent(s -> props.setProperty("OS_VERSION", quote(s)));
|
||||
desc.osArch().ifPresent(s -> props.setProperty("OS_ARCH", quote(s)));
|
||||
desc.version().ifPresent(s -> props.setProperty("JAVA_VERSION",
|
||||
quote(parseVersion(s.toString()))));
|
||||
desc.version().ifPresent(s -> props.setProperty("JAVA_FULL_VERSION",
|
||||
quote(s.toString())));
|
||||
});
|
||||
|
||||
this.targetOsName = props.getProperty("OS_NAME");
|
||||
if (this.targetOsName == null) {
|
||||
throw new PluginException("TargetPlatform attribute is missing for java.base module");
|
||||
}
|
||||
|
@ -210,25 +210,29 @@ public class IntegrationTest {
|
||||
props.load(reader);
|
||||
}
|
||||
|
||||
if (props.getProperty("JAVA_VERSION") == null) {
|
||||
throw new AssertionError("release file does not contain JAVA_VERSION");
|
||||
}
|
||||
|
||||
if (props.getProperty("OS_NAME") == null) {
|
||||
throw new AssertionError("release file does not contain OS_NAME");
|
||||
}
|
||||
|
||||
if (props.getProperty("OS_ARCH") == null) {
|
||||
throw new AssertionError("release file does not contain OS_ARCH");
|
||||
}
|
||||
|
||||
if (props.getProperty("OS_VERSION") == null) {
|
||||
throw new AssertionError("release file does not contain OS_VERSION");
|
||||
}
|
||||
checkReleaseProperty(props, "JAVA_VERSION");
|
||||
checkReleaseProperty(props, "JAVA_FULL_VERSION");
|
||||
checkReleaseProperty(props, "OS_NAME");
|
||||
checkReleaseProperty(props, "OS_ARCH");
|
||||
checkReleaseProperty(props, "OS_VERSION");
|
||||
|
||||
if (!Files.exists(output.resolve("toto.txt"))) {
|
||||
throw new AssertionError("Post processing not called");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void checkReleaseProperty(Properties props, String name) {
|
||||
if (! props.containsKey(name)) {
|
||||
throw new AssertionError("release file does not contain property : " + name);
|
||||
}
|
||||
|
||||
// property value is of min. length 3 and double quoted at the ends.
|
||||
String value = props.getProperty(name);
|
||||
if (value.length() < 3 ||
|
||||
value.charAt(0) != '"' ||
|
||||
value.charAt(value.length() - 1) != '"') {
|
||||
throw new AssertionError("release property " + name + " is not quoted property");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user