Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
150 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> | ||
<classpathentry kind="src" path="src/main/java"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"> | ||
<attributes> | ||
<attribute name="module" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> | ||
<classpathentry kind="src" path="src"/> | ||
<classpathentry kind="output" path="bin"/> | ||
</classpath> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,16 @@ | ||
plugins{ | ||
id 'de.undercouch.download' version '5.4.0' | ||
} | ||
|
||
apply plugin: eclipsebuild.BundlePlugin | ||
dependencies { | ||
api withEclipseBundle("org.eclipse.swt.${ECLIPSE_WS}.${ECLIPSE_OS}.${ECLIPSE_ARCH}") | ||
} | ||
|
||
def copyLibs = tasks.register('downloadLibs', Download) { | ||
src 'https://maven.pkg.github.com/D0zee/language-server-for-KTS-scripts/kts-language-server/server/1.0.0/server-1.0.0-all.jar' | ||
dest file('libs') | ||
// type here own an username and key (classic token from github which allows read packages) | ||
username project.findProperty('gpr.user') | ||
password project.findProperty('gpr.key') | ||
} |
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 |
---|---|---|
@@ -1,6 +1,8 @@ | ||
source.. = src/ | ||
source.. = src/main/java, | ||
output.. = bin/ | ||
bin.includes = .,\ | ||
libs/,\ | ||
plugin.xml,\ | ||
kotlin.tmLanguage.json,\ | ||
META-INF/ | ||
|
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
110 changes: 110 additions & 0 deletions
110
...r/src/main/java/org/eclipse/buildship/kotlindsl/provider/KotlinDSLConnectionProvider.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,110 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 Gradle Inc. and others | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
******************************************************************************/ | ||
package org.eclipse.buildship.kotlindsl.provider; | ||
|
||
import java.io.IOException; | ||
import java.net.URL; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Arrays; | ||
|
||
import org.eclipse.lsp4e.server.ProcessStreamConnectionProvider; | ||
import org.eclipse.lsp4e.server.StreamConnectionProvider; | ||
import org.eclipse.core.runtime.FileLocator; | ||
import org.eclipse.jdt.launching.IVMInstall; | ||
import org.eclipse.jdt.launching.JavaRuntime; | ||
import org.eclipse.jdt.launching.environments.IExecutionEnvironment; | ||
import org.osgi.framework.FrameworkUtil; | ||
import org.osgi.framework.Bundle; | ||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import org.eclipse.swt.SWT; | ||
import org.eclipse.swt.widgets.MessageBox; | ||
import org.eclipse.swt.widgets.Shell; | ||
import org.eclipse.ui.PlatformUI; | ||
|
||
/** | ||
* Is a entry point to launching of a kotlin language server. | ||
* | ||
* @author Nikolai Vladimirov | ||
*/ | ||
|
||
public class KotlinDSLConnectionProvider extends ProcessStreamConnectionProvider | ||
implements StreamConnectionProvider { | ||
|
||
public KotlinDSLConnectionProvider() { | ||
URL localFileURL; | ||
Bundle bundle = FrameworkUtil.getBundle(KotlinDSLConnectionProvider.class); | ||
try { | ||
localFileURL = FileLocator.toFileURL(bundle.getEntry("/")); | ||
URI localFileURI = new URI(localFileURL.toExternalForm()); | ||
Path pathToPlugin = Paths.get(localFileURI.getPath()); | ||
|
||
String pathToServer = pathToPlugin.resolve("libs/server-1.0.0-all.jar").toString(); | ||
|
||
IExecutionEnvironment[] executionEnvironments = JavaRuntime.getExecutionEnvironmentsManager() | ||
.getExecutionEnvironments(); | ||
|
||
IExecutionEnvironment java11Environment = null; | ||
|
||
for (IExecutionEnvironment environment : executionEnvironments) { | ||
if (environment.getId().equals("JavaSE-11")) { | ||
java11Environment = environment; | ||
break; | ||
} | ||
} | ||
|
||
ArrayList<IVMInstall> compatibleJVMs = new ArrayList<>( | ||
Arrays.asList(java11Environment.getCompatibleVMs())); | ||
IVMInstall defaultVMInstall = JavaRuntime.getDefaultVMInstall(); | ||
IVMInstall javaExecutable = null; | ||
|
||
if (!compatibleJVMs.isEmpty()) { | ||
if (compatibleJVMs.contains(defaultVMInstall)) { | ||
javaExecutable = defaultVMInstall; | ||
} else { | ||
javaExecutable = compatibleJVMs.get(0); | ||
} | ||
|
||
String pathToJavaExecutable = javaExecutable.getInstallLocation().toPath().resolve("bin") | ||
.resolve("java") | ||
.toString(); | ||
|
||
List<String> commands = new ArrayList<>( | ||
Arrays.asList(pathToJavaExecutable, "-jar", pathToServer)); | ||
|
||
// add in commands path to bin application of language server | ||
setCommands(commands); | ||
setWorkingDirectory(pathToPlugin.toString()); | ||
|
||
} else { | ||
PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() { | ||
public void run() { | ||
Shell shell = new Shell(); | ||
MessageBox messageBox = new MessageBox(shell, SWT.ICON_WARNING | SWT.OK); | ||
messageBox.setText("Error"); | ||
messageBox.setMessage( | ||
"Compatible version of Java isn't found! Install and rerun application."); | ||
messageBox.open(); | ||
shell.dispose(); | ||
} | ||
}); | ||
} | ||
|
||
|
||
} catch (IOException | URISyntaxException e) { | ||
System.err.println("[GradlePropertiesConnectionProvider]:" + e.toString()); | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
} |