-
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
fe2ec42
commit 3b04a53
Showing
10 changed files
with
281 additions
and
29 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
54 changes: 54 additions & 0 deletions
54
org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/telemetry/ServerInfo.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,54 @@ | ||
/******************************************************************************* | ||
* 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.telemetry; | ||
|
||
import org.eclipse.lsp4xml.Platform; | ||
import org.eclipse.lsp4xml.Platform.JVM; | ||
import org.eclipse.lsp4xml.Platform.OS; | ||
import org.eclipse.lsp4xml.utils.VersionHelper; | ||
|
||
/** | ||
* Telemetry data to collect. | ||
* | ||
* <ul> | ||
* <li>Server Version</li> | ||
* <li>JVM information</li> | ||
* <li>Memory information</li> | ||
* </ul> | ||
* | ||
* @author Angelo ZERR | ||
* | ||
*/ | ||
public class ServerInfo { | ||
|
||
private final String version; | ||
|
||
private OS os; | ||
|
||
private JVM jvm; | ||
|
||
public ServerInfo() { | ||
this.version = VersionHelper.getVersion(); | ||
this.os = Platform.getOS(); | ||
this.jvm = new JVM(); | ||
} | ||
|
||
public String getVersion() { | ||
return version; | ||
} | ||
|
||
public OS getOs() { | ||
return os; | ||
} | ||
|
||
public JVM getJvm() { | ||
return jvm; | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/telemetry/TelemetryManager.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,46 @@ | ||
/******************************************************************************* | ||
* 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.telemetry; | ||
|
||
import org.eclipse.lsp4j.InitializedParams; | ||
import org.eclipse.lsp4j.services.LanguageClient; | ||
|
||
/** | ||
* Telemetry manager. | ||
* | ||
* @author Angelo ZERRs | ||
* | ||
*/ | ||
public class TelemetryManager { | ||
|
||
private final LanguageClient languageClient; | ||
|
||
public TelemetryManager(LanguageClient languageClient) { | ||
this.languageClient = languageClient; | ||
} | ||
|
||
/** | ||
* Send a telemetry event on start of the LSP server | ||
* | ||
* @param params | ||
*/ | ||
public void initialized(InitializedParams params) { | ||
telemetryEvent(new ServerInfo()); | ||
} | ||
|
||
/** | ||
* The telemetry notification is sent from the server to the client to ask the | ||
* client to log a telemetry event. | ||
*/ | ||
public void telemetryEvent(Object object) { | ||
languageClient.telemetryEvent(object); | ||
} | ||
|
||
} |
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
22 changes: 0 additions & 22 deletions
22
org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/utils/OSUtils.java
This file was deleted.
Oops, something went wrong.
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