forked from eclipse-lemminx/lemminx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide more server/build info on startup
Signed-off-by: Fred Bricon <[email protected]>
- Loading branch information
Showing
6 changed files
with
216 additions
and
71 deletions.
There are no files selected for viewing
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
114 changes: 114 additions & 0 deletions
114
org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/utils/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,114 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2020 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 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat Inc. - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.lemminx.utils; | ||
|
||
import static java.lang.System.lineSeparator; | ||
|
||
import java.util.Properties; | ||
import java.util.ResourceBundle; | ||
|
||
public class ServerInfo { | ||
private Properties sysProps; | ||
|
||
static final String MASTER = "master"; | ||
|
||
private ResourceBundle rb = ResourceBundle.getBundle("git"); | ||
|
||
public ServerInfo() { | ||
this(null); | ||
} | ||
|
||
//For testing purposes | ||
ServerInfo(Properties props) { | ||
this.sysProps = new Properties(props == null?System.getProperties():props); | ||
} | ||
|
||
/** | ||
* @return the server version | ||
*/ | ||
public String getVersion() { | ||
return rb.getString("git.build.version"); | ||
} | ||
|
||
/** | ||
* @return the git commit id, used to build the server | ||
*/ | ||
public String getShortCommitId() { | ||
return rb.getString("git.commit.id.abbrev"); | ||
} | ||
|
||
/** | ||
* @return the git commit message, used to build the server | ||
*/ | ||
public String getCommitMessage() { | ||
return rb.getString("git.commit.message.short"); | ||
} | ||
|
||
/** | ||
* @return the Java Home used to launch the server | ||
*/ | ||
public String getJava() { | ||
return sysProps.getProperty("java.home", "unknown"); | ||
} | ||
|
||
/** | ||
* @return the git branch used to build the server | ||
*/ | ||
public String getBranch() { | ||
return rb.getString("git.branch"); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return getVersion(); | ||
} | ||
|
||
/** | ||
* Returns the server details, using the format:<br/> | ||
* <pre> | ||
* LemMinX Server info: | ||
* - Version : (build version) | ||
* - Java : (path to java.home]) | ||
* - Git : ([Branch] short commit id - commit message) | ||
* </pre> | ||
* | ||
* @return the formatted server details | ||
*/ | ||
public String details() { | ||
StringBuilder details = new StringBuilder(); | ||
details.append("LemMinX Server info:"); | ||
append(details, "Version", getVersion()); | ||
append(details, "Java", getJava()); | ||
append(details, "Git", null); | ||
String branch = getBranch(); | ||
if (!MASTER.equals(branch)) { | ||
details.append(" [Branch ") | ||
.append(branch) | ||
.append("]"); | ||
} | ||
details.append(" ") | ||
.append(getShortCommitId()) | ||
.append(" - ") | ||
.append(getCommitMessage()); | ||
return details.toString(); | ||
} | ||
|
||
private void append(StringBuilder sb, String key, String value){ | ||
sb.append(lineSeparator()) | ||
.append(" - ") | ||
.append(key); | ||
if (value != null) { | ||
sb.append(" : ") | ||
.append(value); | ||
} | ||
} | ||
} |
38 changes: 0 additions & 38 deletions
38
org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/utils/VersionHelper.java
This file was deleted.
Oops, something went wrong.
75 changes: 75 additions & 0 deletions
75
org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/utils/ServerInfoTest.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,75 @@ | ||
/** | ||
* Copyright (c) 2018-2020 Red Hat, Inc. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Fred Bricon <[email protected]>, Red Hat Inc. - initial API and implementation | ||
*/ | ||
package org.eclipse.lemminx.utils; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.util.Properties; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class ServerInfoTest { | ||
private static final String JAVA_HOME = "/foo/bar/java/"; | ||
|
||
private ServerInfo serverInfo; | ||
|
||
@BeforeEach | ||
public void setup() { | ||
Properties sysProps = new Properties(); | ||
sysProps.setProperty("java.home", JAVA_HOME); | ||
serverInfo = new ServerInfo(sysProps); | ||
} | ||
|
||
@Test | ||
public void testVersion() { | ||
String version = serverInfo.getVersion(); | ||
Pattern pattern = Pattern.compile("^(\\d+\\.\\d+\\.\\d+)(-.*)$"); | ||
Matcher matcher = pattern.matcher(version); | ||
assertTrue(matcher.matches(), "Unexpected format for :" + version); | ||
} | ||
|
||
@Test | ||
public void testJavaHome() { | ||
assertEquals( JAVA_HOME, serverInfo.getJava(),"Unexpected Java home"); | ||
} | ||
|
||
@Test | ||
public void testGitInfos() { | ||
assertNotNull(serverInfo.getBranch(), "Branch was not set"); | ||
assertNotNull(serverInfo.getCommitMessage(), "Commit message was not set"); | ||
assertNotNull(serverInfo.getShortCommitId(), "Commit id was not set"); | ||
} | ||
|
||
@Test | ||
public void testDetails() { | ||
String details = serverInfo.details(); | ||
//Check we didn't miss any info: | ||
assertTrue(details.contains(serverInfo.getVersion()), "version is missing from the details"); | ||
assertTrue(details.contains(serverInfo.getJava()), "Java is missing from the details"); | ||
assertTrue(details.contains(serverInfo.getCommitMessage()), "commit message is missing from the details"); | ||
assertTrue(details.contains(serverInfo.getShortCommitId()), "commit id is missing from the details"); | ||
|
||
String branch = serverInfo.getBranch(); | ||
if (ServerInfo.MASTER.equals(branch)) { | ||
assertFalse(details.contains(branch), "master branch should not be in the details"); | ||
} else { | ||
assertTrue(details.contains(branch), branch + " branch is missing from the details"); | ||
} | ||
} | ||
} |
31 changes: 0 additions & 31 deletions
31
org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/utils/VersionHelperTest.java
This file was deleted.
Oops, something went wrong.