-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR fix #430 The OSUtils was renamed to Platform which is more generic (eclipse like name) which contains information about OS, JVM (name, version, memory). Signed-off-by: azerr <[email protected]>
- Loading branch information
1 parent
0c018a2
commit 33f2df3
Showing
13 changed files
with
525 additions
and
18 deletions.
There are no files selected for viewing
171 changes: 171 additions & 0 deletions
171
org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/Platform.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2019 Red Hat Inc. and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* Contributors: | ||
* Red Hat Inc. - initial API and implementation | ||
*******************************************************************************/ | ||
|
||
package org.eclipse.lsp4xml; | ||
|
||
/** | ||
* PLatform information about OS and JVM. | ||
*/ | ||
public class Platform { | ||
|
||
private static final OS os = new OS(); | ||
|
||
public static final boolean isWindows = getOS().isWindows(); | ||
public static String SLASH = isWindows ? "\\" : "/"; | ||
|
||
/** | ||
* OS information | ||
*/ | ||
public static class OS { | ||
|
||
private final String name; | ||
|
||
private final String version; | ||
|
||
private final String arch; | ||
|
||
private final transient boolean isWindows; | ||
|
||
public OS() { | ||
this.name = getSystemProperty("os.name"); | ||
this.version = getSystemProperty("os.version"); | ||
this.arch = getSystemProperty("os.arch"); | ||
isWindows = name != null && name.toLowerCase().indexOf("win") >= 0; | ||
} | ||
|
||
/** | ||
* Returns the OS name. | ||
* | ||
* @return the OS name. | ||
*/ | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
/** | ||
* Returns the OS version. | ||
* | ||
* @return the OS version. | ||
*/ | ||
public String getVersion() { | ||
return version; | ||
} | ||
|
||
/** | ||
* Returns the OS arch. | ||
* | ||
* @return the OS arch. | ||
*/ | ||
public String getArch() { | ||
return arch; | ||
} | ||
|
||
public boolean isWindows() { | ||
return isWindows; | ||
} | ||
} | ||
|
||
/** | ||
* JVM information | ||
* | ||
*/ | ||
public static class JVM { | ||
|
||
/** | ||
* JVM memory information | ||
* | ||
*/ | ||
public static class Memory { | ||
|
||
private final long free; | ||
|
||
private final long total; | ||
|
||
private final long max; | ||
|
||
private Memory() { | ||
super(); | ||
this.free = Runtime.getRuntime().freeMemory(); | ||
this.total = Runtime.getRuntime().totalMemory(); | ||
this.max = Runtime.getRuntime().maxMemory(); | ||
} | ||
|
||
public long getFree() { | ||
return free; | ||
} | ||
|
||
public long getTotal() { | ||
return total; | ||
} | ||
|
||
public long getMax() { | ||
return max; | ||
} | ||
|
||
} | ||
|
||
private final String name; | ||
|
||
private final String version; | ||
|
||
private final Memory memory; | ||
|
||
public JVM() { | ||
this.name = getSystemProperty("java.vm.name"); | ||
this.version = getSystemProperty("java.version"); | ||
this.memory = new Memory(); | ||
} | ||
|
||
/** | ||
* Returns the JVM name | ||
* | ||
* @return the JVM name | ||
*/ | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
/** | ||
* Returns the JVM version | ||
* | ||
* @return the JVM version | ||
*/ | ||
public String getVersion() { | ||
return version; | ||
} | ||
|
||
public Memory getMemory() { | ||
return memory; | ||
} | ||
} | ||
|
||
/** | ||
* Returns the OS information. | ||
* | ||
* @return the OS information. | ||
*/ | ||
public static OS getOS() { | ||
return os; | ||
} | ||
|
||
/** | ||
* Returns the system property from the given key and null otherwise. | ||
* | ||
* @param key the property system key | ||
* @return the system property from the given key and null otherwise. | ||
*/ | ||
private static String getSystemProperty(String key) { | ||
try { | ||
return System.getProperty(key); | ||
} catch (SecurityException e) { | ||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.