Skip to content

Commit

Permalink
[GR-20435] Only major version is used from JAVA_VERSION release file …
Browse files Browse the repository at this point in the history
…entry.

PullRequest: graal/5171
  • Loading branch information
sdedic committed Jan 7, 2020
2 parents a4decb2 + 8b601d7 commit 4c4c075
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,7 @@ public class CommonConstants {

public static final String ENV_DELETE_LIST = "GU_POST_DELETE_LIST"; // NOI18N
public static final String ENV_COPY_CONTENTS = "GU_POST_COPY_CONTENTS"; // NOI18N

public static final String ARCH_X8664 = "x86_64"; // NOI18N
public static final String ARCH_AMD64 = "amd64"; // NOI18N
}
Original file line number Diff line number Diff line change
Expand Up @@ -395,20 +395,29 @@ public static String parseURLParameters(String s, Map<String, String> params) th
}

public static int getJavaMajorVersion(CommandInput cmd) {
String v = cmd.getParameter(CommonConstants.SYSPROP_JAVA_VERSION, true); // NOI18N
String v = cmd.getLocalRegistry() != null ? cmd.getLocalRegistry().getJavaVersion() : null;
if (v == null) {
cmd.getParameter(CommonConstants.SYSPROP_JAVA_VERSION, true);
} // NOI18N
if (v != null) {
return interpretMajorVersion(v);
return interpretJavaMajorVersion(v);
} else {
return getJavaMajorVersion();
}
}

public static int getJavaMajorVersion() {
String v = System.getProperty(CommonConstants.SYSPROP_JAVA_VERSION); // NOI18N
return interpretMajorVersion(v);
return interpretJavaMajorVersion(v);
}

private static int interpretMajorVersion(String v) {
/**
* Interprets String as a java version, returning the major version number.
*
* @param v the version string
* @return the major version number, or zero if unknown
*/
public static int interpretJavaMajorVersion(String v) {
String s;
if (v.startsWith("1.")) { // NOI18N
s = v.substring(2);
Expand Down Expand Up @@ -576,4 +585,22 @@ public static String fingerPrint(byte[] digest) {
return sb.toString();
}

/**
* Normalizes architecture string.
*
* @param os OS name
* @param arch arch name
* @return normalized arch name, or {@code null}.
*/
public static String normalizeArchitecture(String os, String arch) {
if (arch == null) {
return null;
}
switch (arch) {
case CommonConstants.ARCH_X8664:
return CommonConstants.ARCH_AMD64;
default:
return arch;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,13 @@
import java.util.Map;
import java.util.MissingResourceException;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.graalvm.component.installer.CommonConstants;
import org.graalvm.component.installer.ComponentCollection;
import org.graalvm.component.installer.FailedOperationException;
import org.graalvm.component.installer.Feedback;
import org.graalvm.component.installer.SystemUtils;
import org.graalvm.component.installer.Version;

/**
Expand Down Expand Up @@ -155,11 +158,38 @@ private String findAbbreviatedId(String id) {
return candidate;
}

/**
* Regexp to extract specification version. Optional {@code "1."} in front, optional
* {@code ".micro_patchlevel"} suffix.
*/
private static final Pattern JAVA_VERSION_PATTERN = Pattern.compile("((?:1\\.)?[0-9]+)([._].*)?"); // NOI18N

public Map<String, String> getGraalCapabilities() {
if (graalAttributes != null) {
return graalAttributes;
}
graalAttributes = storage.loadGraalVersionInfo();
Map<String, String> m = new HashMap<>(storage.loadGraalVersionInfo());
String v = m.get(CommonConstants.CAP_JAVA_VERSION);
if (v != null) {
Matcher rm = JAVA_VERSION_PATTERN.matcher(v);
if (rm.matches()) {
v = rm.group(1);
}
int mv = SystemUtils.interpretJavaMajorVersion(v);
if (mv < 1) {
m.remove(CommonConstants.CAP_JAVA_VERSION);
} else {
m.put(CommonConstants.CAP_JAVA_VERSION, "" + mv); // NOI18N
}
graalAttributes = m;
}
// On JDK11, amd64 architecture name changed to x86_64.
v = SystemUtils.normalizeArchitecture(
m.get(CommonConstants.CAP_OS_NAME),
m.get(CommonConstants.CAP_OS_ARCH));
if (v != null) {
m.put(CommonConstants.CAP_OS_ARCH, v);
}
return graalAttributes;
}

Expand Down

0 comments on commit 4c4c075

Please sign in to comment.