Remove LANGUAGE_SERVER_VERSION constants...
... instead assume that language server version matches Eclipse bundle version. Also streamline code for finding server jar locations so it is no longer duplicated across every language server bundle.
This commit is contained in:
@@ -14,12 +14,19 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
|
||||
import org.eclipse.core.runtime.FileLocator;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.core.runtime.jobs.Job;
|
||||
import org.eclipse.lsp4e.server.ProcessStreamConnectionProvider;
|
||||
import org.osgi.framework.Bundle;
|
||||
import org.osgi.framework.Version;
|
||||
import org.springframework.tooling.ls.eclipse.commons.console.ConsoleUtil.Console;
|
||||
import org.springframework.tooling.ls.eclipse.commons.console.LanguageServerConsoles;
|
||||
import org.springframework.tooling.ls.eclipse.commons.preferences.LanguageServerConsolePreferenceConstants.ServerInfo;
|
||||
@@ -28,12 +35,14 @@ import org.springsource.ide.eclipse.commons.core.util.IOUtil;
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.base.Supplier;
|
||||
|
||||
public class STS4LanguageServerProcessStreamConnector extends ProcessStreamConnectionProvider {
|
||||
public abstract class STS4LanguageServerProcessStreamConnector extends ProcessStreamConnectionProvider {
|
||||
|
||||
private static LanguageServerProcessReaper processReaper = new LanguageServerProcessReaper();
|
||||
|
||||
private Supplier<Console> consoles = null;
|
||||
|
||||
private Bundle bundle;
|
||||
|
||||
public STS4LanguageServerProcessStreamConnector(ServerInfo server) {
|
||||
this.consoles = LanguageServerConsoles.getConsoleFactory(server);
|
||||
}
|
||||
@@ -132,4 +141,69 @@ public class STS4LanguageServerProcessStreamConnector extends ProcessStreamConne
|
||||
return System.getProperty("user.dir");
|
||||
}
|
||||
|
||||
final protected String getLanguageServerJARLocation() {
|
||||
String languageServer = getLanguageServerArtifactId() +"-" + getLanguageServerArtifactVersion() +".jar";
|
||||
Bundle bundle = getBundle();
|
||||
String bundleVersion = bundle.getVersion().toString();
|
||||
String languageServerLocalCopy = bundleVersion + "-" + languageServer;
|
||||
File dataFile = bundle.getDataFile(languageServerLocalCopy);
|
||||
|
||||
Exception error = null;
|
||||
if (!dataFile.exists() || bundleVersion.endsWith("qualifier")) { // qualifier check to get the language server always copied in dev mode
|
||||
try {
|
||||
copyLanguageServerJAR(languageServer, languageServerLocalCopy);
|
||||
}
|
||||
catch (Exception e) {
|
||||
error = e;
|
||||
}
|
||||
}
|
||||
|
||||
if (bundleVersion.endsWith("qualifier")) {
|
||||
File userHome = new File(System.getProperty("user.home"));
|
||||
File locallyBuiltJar = new File(
|
||||
userHome
|
||||
,
|
||||
"git/sts4/headless-services/"
|
||||
+ getLanguageServerArtifactId()
|
||||
+ "/target/"
|
||||
+ getLanguageServerArtifactId()
|
||||
+ "-"
|
||||
+ getLanguageServerArtifactVersion()
|
||||
);
|
||||
if (locallyBuiltJar.exists()) {
|
||||
return locallyBuiltJar.getAbsolutePath();
|
||||
}
|
||||
if (error!=null) {
|
||||
error.printStackTrace();
|
||||
}
|
||||
}
|
||||
return dataFile.getAbsolutePath();
|
||||
}
|
||||
|
||||
protected String getLanguageServerArtifactVersion() {
|
||||
Version bv = getBundle().getVersion();
|
||||
//Example of what it should look like:
|
||||
// "1.6.0-SNAPSHOT"
|
||||
return bv.getMajor()+"."+bv.getMinor()+"."+bv.getMicro()+"-SNAPSHOT";
|
||||
}
|
||||
|
||||
protected Bundle getBundle() {
|
||||
if (bundle==null) {
|
||||
this.bundle = Platform.getBundle(getPluginId());
|
||||
}
|
||||
return bundle;
|
||||
}
|
||||
|
||||
protected abstract String getLanguageServerArtifactId();
|
||||
|
||||
protected final void copyLanguageServerJAR(String languageServerJarName, String languageServerLocalCopy) throws Exception {
|
||||
Bundle bundle = Platform.getBundle(getPluginId());
|
||||
InputStream stream = FileLocator.openStream( bundle, new Path("servers/" + languageServerJarName), false );
|
||||
|
||||
File dataFile = bundle.getDataFile(languageServerLocalCopy);
|
||||
Files.copy(stream, dataFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||||
}
|
||||
|
||||
protected abstract String getPluginId();
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user