Skip to content

Commit

Permalink
Undo compatibility breaks of PR#2 & [JENKINS-10383]
Browse files Browse the repository at this point in the history
Prefer compatibility with prior behavior over new names for Windows
operating system versions.  Reverts some of the changes from the fix for
[JENKINS-10383].

The plugin has not been released in 5+ years.  Users have adapted
to the existing behavior and will value retaining existing behavior
more than they will value additional detection of specifically named
Windows versions.

Retain SunOS behavior from platformlabeler 1.1

The code in the 1.1 release accepted os.name as an argument, folded
it to lower case, then compared the result with "SunOS".  Since there
are upper case characters in "SunOS", the comparison would never have
matched.  Since it did not match, the result fell through to return the
lower case form "sunos" rather than "solaris" the code hints was
intended.

Fix [JENKINS-10383] - report bits of platform instead of JRE

[JENKINS-10383] changes behavior on 64 bit Windows and 64 bit Linux
running a 32 bit JRE.  Release 1.1 reported "x86" (32 bit) on a 32 bit
JRE running on a 64 bit operating system.  Release 2.0 and later reports
"amd64" (64 bit) on a 32 bit JRE running on a 64 bit operating system.

Before [JENKINS-10383] the bits of the JRE were reported.
After [JENKINS-10383] the bits of the operating system are reported.

There is no behavioral change for 32 bit machines running a 32 bit JRE.

There is no behavioral change for 64 bit machines running a 64 bit JRE.

There is no behavioral change for machines that are not Windows and not Linux.
  • Loading branch information
MarkEWaite committed Apr 23, 2018
1 parent 6c35df3 commit 798c90f
Showing 1 changed file with 50 additions and 75 deletions.
Expand Up @@ -30,9 +30,10 @@
import org.jenkinsci.remoting.RoleSensitive;
import org.jenkinsci.remoting.RoleChecker;
import hudson.remoting.Callable;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.File;
import java.util.HashSet;

class PlatformDetailsTask implements Callable<HashSet<String>, IOException> {
Expand All @@ -50,99 +51,73 @@ public void checkRoles(RoleChecker checker) throws SecurityException {
*/
@Override
public HashSet<String> call() throws IOException {
String arch = System.getProperty("os.arch").toLowerCase();
String name = System.getProperty("os.name").toLowerCase();
final String arch = System.getProperty("os.arch");
String name = System.getProperty("os.name");
String version = System.getProperty("os.version");
if (name.equals("solaris") || name.equals("SunOS")) {
name = "solaris";
} else if (name.startsWith("windows")) {
name = "windows";
/**
* os.arch is really the JRE bitness, not the OS bitness.
*/
if ("x86".equals(arch)) {
final String env1 = System.getenv("PROCESSOR_ARCHITECTURE").toLowerCase();
String env2 = null;
try {
env2 = System.getenv("PROCESSOR_ARCHITEW6432").toLowerCase();
} catch (Exception e) {
}
return computeLabels(arch, name, version);
}

if ("amd64".equals(env1) || "amd64".equals(env2)) {
arch = "amd64";
}
}
if (name.startsWith("windows 9")) {
if (version.startsWith("4.0")) {
version = "95";
} else if (version.startsWith("4.9")) {
version = "me";
} else {
assert version.startsWith("4.1");
version = "98";
}
} else {
if (version.startsWith("4.0")) {
version = "nt4";
} else if (version.startsWith("5.0")) {
version = "2000";
} else if (version.startsWith("5.1")) {
version = "xp";
} else if (version.startsWith("5.2")) {
if ("amd64".equals(arch)) {
// The 64-bit version of xp is based on 2003
version = "2003+xp";
} else {
version = "2003";
}
} else if (version.startsWith("6.0.6000")) {
version = "vista";
} else if (version.startsWith("6.0")) {
// Server 2008 is based on 6.0.6001
version = "vista+2008";
} else if (version.startsWith("6.1")) {
if ("x86".equals(arch)) {
// 2008 R2 is 64-bit only.
version = "7";
private String checkWindows32Bit(String arch) {
if (!"x86".equalsIgnoreCase(arch)) {
return arch;
}
final String env1 = System.getenv("PROCESSOR_ARCHITECTURE");
final String env2 = System.getenv("PROCESSOR_ARCHITEW6432");
if ("amd64".equalsIgnoreCase(env1) || "amd64".equalsIgnoreCase(env2)) {
arch = "amd64";
}
return arch;
}

private String checkLinux32Bit(String arch) {
try {
Process p = Runtime.getRuntime().exec("/bin/uname -m");
p.waitFor();
try (BufferedReader b = new BufferedReader(new InputStreamReader(p.getInputStream(), "UTF-8"))) {
String line = b.readLine();
if (line != null) {
if ("x86_64".equals(line)) {
arch = "amd64";
} else {
// TODO distinguish windows 7amd64 from 2008R2?
version = "7+2008r2";
arch = line;
}
}
}
} catch (IOException | InterruptedException e) {
}
return arch;
}

protected HashSet<String> computeLabels(String arch, String name, String version) throws IOException {
name = name.toLowerCase();
if (name.equals("solaris")) {
name = "solaris";
} else if (name.startsWith("windows")) {
name = "windows";
arch = checkWindows32Bit(arch);
if (version.startsWith("4.0")) {
version = "nt4";
} else if (version.startsWith("5.0")) {
version = "2000";
} else if (version.startsWith("5.1")) {
version = "xp";
} else if (version.startsWith("5.2")) {
version = "2003";
}
} else if (name.startsWith("linux")) {
String unknown_string = "unknown+check_lsb_release_installed";
Release release = new Release();
name = release.distributorId();
arch = checkLinux32Bit(arch);
if (null == name) {
name = unknown_string;
}
version = release.release();
if (null == version) {
version = unknown_string;
}

if ("x86".equals(arch)) {
Process p = Runtime.getRuntime().exec("/bin/uname -m");
try {
p.waitFor();
try (BufferedReader b = new BufferedReader(new InputStreamReader(p.getInputStream(), "UTF-8"))) {
String line = b.readLine();
if (line != null) {
if ("x86_64".equals(line)) {
arch = "amd64";
} else {
arch = line;
}
}
}
} catch (InterruptedException e) {
}
}
} else if (name.startsWith("mac")) {
name = "mac";
} else {
// Take the System.properties values verbatim.
}
HashSet<String> result = new HashSet<>();
result.add(arch);
Expand Down

0 comments on commit 798c90f

Please sign in to comment.