Skip to content

Commit

Permalink
Provide more server/build info on startup
Browse files Browse the repository at this point in the history
Signed-off-by: Fred Bricon <[email protected]>
  • Loading branch information
fbricon committed Jun 8, 2020
1 parent 3ffb1ff commit ce6def2
Show file tree
Hide file tree
Showing 6 changed files with 216 additions and 71 deletions.
24 changes: 24 additions & 0 deletions org.eclipse.lemminx/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,30 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId>
<version>4.0.0</version>
<executions>
<execution>
<id>get-the-git-infos</id>
<goals>
<goal>revision</goal>
</goals>
</execution>
</executions>
<configuration>
<dotGitDirectory>${project.basedir}/../.git</dotGitDirectory>
<generateGitPropertiesFile>true</generateGitPropertiesFile>
<includeOnlyProperties>
<includeOnlyProperty>^git.commit.id.abbrev$</includeOnlyProperty>
<includeOnlyProperty>^git.commit.message.short$</includeOnlyProperty>
<includeOnlyProperty>^git.branch$</includeOnlyProperty>
<includeOnlyProperty>^git.build.version$</includeOnlyProperty>
</includeOnlyProperties>
<gitDescribe><skip>true</skip></gitDescribe>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
*/
package org.eclipse.lemminx;

import static org.eclipse.lemminx.utils.VersionHelper.getVersion;
import static org.eclipse.lsp4j.jsonrpc.CompletableFutures.computeAsync;

import java.util.concurrent.CompletableFuture;
Expand Down Expand Up @@ -50,6 +49,7 @@
import org.eclipse.lemminx.settings.capabilities.ServerCapabilitiesInitializer;
import org.eclipse.lemminx.settings.capabilities.XMLCapabilityManager;
import org.eclipse.lemminx.utils.FilesUtils;
import org.eclipse.lemminx.utils.ServerInfo;
import org.eclipse.lsp4j.InitializeParams;
import org.eclipse.lsp4j.InitializeResult;
import org.eclipse.lsp4j.InitializedParams;
Expand Down Expand Up @@ -87,7 +87,8 @@ public XMLLanguageServer() {

@Override
public CompletableFuture<InitializeResult> initialize(InitializeParams params) {
LOGGER.info("Initializing XML Language server " + getVersion() + " with " + System.getProperty("java.home"));
LOGGER.info("Initializing XML Language server" + System.lineSeparator() + new ServerInfo().details());

this.parentProcessId = params.getProcessId();

// Update XML language service extensions with InitializeParams
Expand Down
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);
}
}
}

This file was deleted.

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");
}
}
}

This file was deleted.

0 comments on commit ce6def2

Please sign in to comment.