Skip to content

Conversation

@jonpryor
Copy link
Contributor

Context: #29 (comment)

Refactor out the underlying functionality of the
<JdkInfo/> task so that it is more easily usable.

@jonpryor jonpryor added the do-not-merge Do not merge this PR label Jul 24, 2018
@jonpryor
Copy link
Contributor Author

Current example usage:

$ csharp -r:bin/Debug/Xamarin.Android.Tools.AndroidSdk.dll 
Mono C# Shell, type "help;" for help

Enter statements below.
csharp> var info = new Xamarin.Android.Tools.JdkInfo ("/Library/Java/JavaVirtualMachines/jdk1.8.0_77.jdk/Contents/Home");
csharp> info;
JdkInfo(Version=1.8.0.77, Vendor="Oracle Corporation", HomePath="/Library/Java/JavaVirtualMachines/jdk1.8.0_77.jdk/Contents/Home")
csharp> info.JarPath;
"/Library/Java/JavaVirtualMachines/jdk1.8.0_77.jdk/Contents/Home/bin/jar"
csharp> info.ReleaseProperties
{
  { "JAVA_VERSION", "1.8.0_77" },
  { "OS_NAME", "Darwin" },
  { "OS_VERSION", "11.2" },
  { "OS_ARCH", "x86_64" },
  { "SOURCE", " .:3fbef9f4cddf corba:e8dc6eb11c76 deploy:d84f06512943 hotspot:223b64a19e94 hotspot/make/closed:477ad98b429e hotspot/src/closed:59776a84c75d hotspot/test/closed:960f70129730 install:9e94ca99871e jaxp:1c71899e8566 jaxws:c6f67bea4466 jdk:e29d2956631e jdk/make/closed:9dbc2900ee6c jdk/src/closed:3912d596b196 jdk/test/closed:0d90cb7caa56 langtools:094308b2ca1c nashorn:b6ee21a35619 pubs:116f6084ae4a sponsors:1ec3827eadc4" },
  { "BUILD_TYPE", "commercial" },
}
csharp> info.JavaProperties
{
  { "awt.toolkit", { "sun.lwawt.macosx.LWCToolkit" } },
  { "file.encoding", { "UTF-8" } },
  { "file.encoding.pkg", { "sun.io" } },
  { "file.separator", { "/" } },
  { "ftp.nonProxyHosts", { "local|*.local|169.254/16|*.169.254/16" } },
  { "gopherProxySet", { "false" } },
  { "http.nonProxyHosts", { "local|*.local|169.254/16|*.169.254/16" } },
  { "java.awt.graphicsenv", { "sun.awt.CGraphicsEnvironment" } },
  { "java.awt.printerjob", { "sun.lwawt.macosx.CPrinterJob" } },
  { "java.class.path", { "." } },
  { "java.class.version", { "52.0" } },
  { "java.endorsed.dirs", { "/Library/Java/JavaVirtualMachines/jdk1.8.0_77.jdk/Contents/Home/jre/lib/endorsed" } },
  { "java.ext.dirs", {
    "/Users/jon/Library/Java/Extensions",
    "/Library/Java/JavaVirtualMachines/jdk1.8.0_77.jdk/Contents/Home/jre/lib/ext",
    "/Library/Java/Extensions",
    "/Network/Library/Java/Extensions",
    "/System/Library/Java/Extensions",
    "/usr/lib/java" } },
  { "java.home", { "/Library/Java/JavaVirtualMachines/jdk1.8.0_77.jdk/Contents/Home/jre" } },
  { "java.io.tmpdir", { "/var/folders/1y/wwmg3hv5685ft661f5q2w2100000gn/T/" } },
  { "java.library.path", {
    "/Users/jon/Library/Java/Extensions",
    "/Library/Java/Extensions",
    "/Network/Library/Java/Extensions",
    "/System/Library/Java/Extensions",
    "/usr/lib/java",
    "." } },
  { "java.runtime.name", { "Java(TM) SE Runtime Environment" } },
  { "java.runtime.version", { "1.8.0_77-b03" } },
  { "java.specification.name", { "Java Platform API Specification" } },
  { "java.specification.vendor", { "Oracle Corporation" } },
  { "java.specification.version", { "1.8" } },
  { "java.vendor", { "Oracle Corporation" } },
  { "java.vendor.url", { "http://java.oracle.com/" } },
  { "java.vendor.url.bug", { "http://bugreport.sun.com/bugreport/" } },
  { "java.version", { "1.8.0_77" } },
  { "java.vm.info", { "mixed mode" } },
  { "java.vm.name", { "Java HotSpot(TM) 64-Bit Server VM" } },
  { "java.vm.specification.name", { "Java Virtual Machine Specification" } },
  { "java.vm.specification.vendor", { "Oracle Corporation" } },
  { "java.vm.specification.version", { "1.8" } },
  { "java.vm.vendor", { "Oracle Corporation" } },
  { "java.vm.version", { "25.77-b03" } },
  { "line.separator", { "\n " } },
  { "os.arch", { "x86_64" } },
  { "os.name", { "Mac OS X" } },
  { "os.version", { "10.13.5" } },
  { "path.separator", { ":" } },
  { "socksNonProxyHosts", { "local|*.local|169.254/16|*.169.254/16" } },
  { "sun.arch.data.model", { "64" } },
  { "sun.boot.class.path", {
    "/Library/Java/JavaVirtualMachines/jdk1.8.0_77.jdk/Contents/Home/jre/lib/resources.jar",
    "/Library/Java/JavaVirtualMachines/jdk1.8.0_77.jdk/Contents/Home/jre/lib/rt.jar",
    "/Library/Java/JavaVirtualMachines/jdk1.8.0_77.jdk/Contents/Home/jre/lib/sunrsasign.jar",
    "/Library/Java/JavaVirtualMachines/jdk1.8.0_77.jdk/Contents/Home/jre/lib/jsse.jar",
    "/Library/Java/JavaVirtualMachines/jdk1.8.0_77.jdk/Contents/Home/jre/lib/jce.jar",
    "/Library/Java/JavaVirtualMachines/jdk1.8.0_77.jdk/Contents/Home/jre/lib/charsets.jar",
    "/Library/Java/JavaVirtualMachines/jdk1.8.0_77.jdk/Contents/Home/jre/lib/jfr.jar",
    "/Library/Java/JavaVirtualMachines/jdk1.8.0_77.jdk/Contents/Home/jre/classes" } },
  { "sun.boot.library.path", { "/Library/Java/JavaVirtualMachines/jdk1.8.0_77.jdk/Contents/Home/jre/lib" } },
  { "sun.cpu.endian", { "little" } },
  { "sun.cpu.isalist", { "" } },
  { "sun.io.unicode.encoding", { "UnicodeBig" } },
  { "sun.java.launcher", { "SUN_STANDARD" } },
  { "sun.jnu.encoding", { "UTF-8" } },
  { "sun.management.compiler", { "HotSpot 64-Bit Tiered Compilers" } },
  { "sun.os.patch.level", { "unknown" } },
  { "user.country", { "US" } },
  { "user.dir", { "/Volumes/Seagate4TB/work/xamarin-android/external/xamarin-android-tools" } },
  { "user.home", { "/Users/jon" } },
  { "user.language", { "en" } },
  { "user.name", { "jon" } },
  { "user.timezone", { "" } },
}

@jonpryor
Copy link
Contributor Author

@grendello: I'm not sold on the name JdkInfo.JavaProperties (for java -XshowSettings:properties output) or the type as Dictionary<string, List<string>>. It's useful in that it's obvious, e.g. sun.boot.class.path, but for most properties it just adds an extra array indirection.

@grendello
Copy link
Contributor

@jonpryor yeah... This type should be named JavaInformation, but not sure how well that plays with JdkInfo (sounds kinda weird); or perhaps JavaConfiguration which it also sorta/kinda is. As for Dictionary<string, List<string>> - I'd say keep it, it is close to the original structure of the information and that makes translation between formats as simple as possible. Or, to get rid of the unnecessary List<string> for the simple types, you could create something like this (in moments like that I wish C# had union):

enum ValueKind
{
    Simple,
    List,
}

abstract class InfoValueBase
{
    public abstract ValueKind { get; }
    //...
}

class InfoValue<T> : InfoValueBase
{
    public T Value <T> { get; set; }
}

And use Dictionary<string, InfoValueBase> to store the info. With a couple of parameterized getter methods on the JavaProperties type the implementation ugliness can be hidden from the user.

if (IsMac)
NativeLibraryFormat = "lib{0}.dylib";
if (!IsWindows && !IsMac)
NativeLibraryFormat = "lib{0}.so";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want to special-case Linux here as well. In theory the code can run on e.g. the *BSD family of Unix systems (other than macOS) and if you know you're running on Linux then you can check what distribution you're on and use that distribution's mechanisms to detect Java instances (e.g. on Debian + family you can use /usr/sbin/update-java-alternatives -l but you can't use it, say, on Manjaro)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't special-case systems I'm not running. :-)

BSD contributions welcome. In the meantime, there is support for $JAVA_HOME and $PATH already.

@jonpryor jonpryor requested a review from tondat July 24, 2018 20:07
@jonpryor jonpryor removed the do-not-merge Do not merge this PR label Jul 24, 2018
@jonpryor jonpryor force-pushed the jonp-JdkInfo branch 4 times, most recently from 5c7107e to fbbf15a Compare July 25, 2018 00:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants