Skip to content

Commit

Permalink
Introduce Apache Camel LSP support (eclipse-che#8648)
Browse files Browse the repository at this point in the history
* Provide Camel Language Server Agent

Signed-off-by: Aurélien Pupier <apupier@redhat.com>
  • Loading branch information
benoitf authored Feb 7, 2018
1 parent 9bd0d1c commit 307ee4f
Show file tree
Hide file tree
Showing 12 changed files with 351 additions and 0 deletions.
23 changes: 23 additions & 0 deletions agents/ls-camel/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2012-2018 Red Hat, Inc.
All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Public License v1.0
which accompanies this distribution, and is available at
http://www.eclipse.org/legal/epl-v10.html
Contributors:
Red Hat, Inc. - initial API and implementation
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>che-agents-parent</artifactId>
<groupId>org.eclipse.che</groupId>
<version>6.1.0-SNAPSHOT</version>
</parent>
<artifactId>ls-camel-agent</artifactId>
<name>Language Server Apache Camel Agent</name>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"id": "org.eclipse.che.ls.camel",
"version": "1.0.0",
"name": "Apache Camel language server",
"description": "Apache Camel intellisense",
"dependencies": [],
"properties": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#
# Copyright (c) 2012-2018 Red Hat, Inc.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html
#
# Contributors:
# Red Hat, Inc. - initial API and implementation
#


is_current_user_root() {
test "$(id -u)" = 0
}

is_current_user_sudoer() {
sudo -n true > /dev/null 2>&1
}

set_sudo_command() {
if is_current_user_sudoer && ! is_current_user_root; then SUDO="sudo -E"; else unset SUDO; fi
}

set_sudo_command
unset PACKAGES
command -v tar >/dev/null 2>&1 || { PACKAGES=${PACKAGES}" tar"; }
command -v curl >/dev/null 2>&1 || { PACKAGES=${PACKAGES}" curl"; }

AGENT_BINARIES_URI=https://github.com/lhein/camel-language-server/releases/download/untagged-d42064681113e838bd59/camel-lsp-server-1.0.0-SNAPSHOT.jar
CHE_DIR=$HOME/che
LS_DIR=${CHE_DIR}/ls-camel
LS_LAUNCHER=${LS_DIR}/launch.sh

if [ -f /etc/centos-release ]; then
FILE="/etc/centos-release"
LINUX_TYPE=$(cat $FILE | awk '{print $1}')
elif [ -f /etc/redhat-release ]; then
FILE="/etc/redhat-release"
LINUX_TYPE=$(cat $FILE | cut -c 1-8)
else
FILE="/etc/os-release"
LINUX_TYPE=$(cat $FILE | grep ^ID= | tr '[:upper:]' '[:lower:]')
LINUX_VERSION=$(cat $FILE | grep ^VERSION_ID=)
fi

MACHINE_TYPE=$(uname -m)

mkdir -p ${CHE_DIR}
mkdir -p ${LS_DIR}


###############################
### Install Apache Camel LS ###
###############################

curl -L -s ${AGENT_BINARIES_URI} -o ${LS_DIR}/camel-lsp-server.jar

touch ${LS_LAUNCHER}
chmod +x ${LS_LAUNCHER}
echo "java -jar ${LS_DIR}/camel-lsp-server.jar" > ${LS_LAUNCHER}
1 change: 1 addition & 0 deletions agents/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@
<module>ls-csharp</module>
<module>test-ls</module>
<module>ls-yaml</module>
<module>ls-camel</module>
</modules>
</project>
4 changes: 4 additions & 0 deletions assembly/assembly-wsagent-war/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
<groupId>org.eclipse.che.plugin</groupId>
<artifactId>che-plugin-activity-server</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.plugin</groupId>
<artifactId>che-plugin-camel-server</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.plugin</groupId>
<artifactId>che-plugin-composer-server</artifactId>
Expand Down
4 changes: 4 additions & 0 deletions assembly/assembly-wsmaster-war/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@
<groupId>org.eclipse.che</groupId>
<artifactId>git-credentials-agent</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che</groupId>
<artifactId>ls-camel-agent</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che</groupId>
<artifactId>ls-csharp-agent</artifactId>
Expand Down
64 changes: 64 additions & 0 deletions plugins/plugin-camel/che-plugin-camel-server/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2012-2018 Red Hat, Inc.
All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Public License v1.0
which accompanies this distribution, and is available at
http://www.eclipse.org/legal/epl-v10.html
Contributors:
Red Hat, Inc. - initial API and implementation
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>che-plugin-camel-parent</artifactId>
<groupId>org.eclipse.che.plugin</groupId>
<version>6.1.0-SNAPSHOT</version>
</parent>
<artifactId>che-plugin-camel-server</artifactId>
<name>Che Plugin :: Apache Camel :: Server</name>
<properties>
<findbugs.failonerror>false</findbugs.failonerror>
</properties>
<dependencies>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
</dependency>
<dependency>
<groupId>com.google.inject.extensions</groupId>
<artifactId>guice-multibindings</artifactId>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-core</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-languageserver</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-languageserver-shared</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-commons-inject</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.lsp4j</groupId>
<artifactId>org.eclipse.lsp4j</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.lsp4j</groupId>
<artifactId>org.eclipse.lsp4j.jsonrpc</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (c) 2012-2018 Red Hat, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.che.plugin.camel.server.inject;

import static java.util.Arrays.asList;

import com.google.inject.AbstractModule;
import com.google.inject.multibindings.Multibinder;
import org.eclipse.che.api.languageserver.launcher.LanguageServerLauncher;
import org.eclipse.che.api.languageserver.shared.model.LanguageDescription;
import org.eclipse.che.inject.DynaModule;
import org.eclipse.che.plugin.camel.server.languageserver.CamelLanguageServerLauncher;

/** Apache Camel module for server side of Camel Language Server */
@DynaModule
public class CamelModule extends AbstractModule {
public static final String LANGUAGE_ID = "LANGUAGE_ID_APACHE_CAMEL";
private static final String[] EXTENSIONS = new String[] {"xml"};
private static final String MIME_TYPE = "text/xml";

@Override
protected void configure() {
Multibinder.newSetBinder(binder(), LanguageServerLauncher.class)
.addBinding()
.to(CamelLanguageServerLauncher.class);
LanguageDescription description = new LanguageDescription();
description.setFileExtensions(asList(EXTENSIONS));
description.setLanguageId(LANGUAGE_ID);
description.setMimeType(MIME_TYPE);
Multibinder.newSetBinder(binder(), LanguageDescription.class)
.addBinding()
.toInstance(description);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*
* Copyright (c) 2012-2018 Red Hat, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.che.plugin.camel.server.languageserver;

import com.google.inject.Inject;
import com.google.inject.Singleton;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import javax.inject.Named;
import org.eclipse.che.api.core.rest.HttpJsonRequestFactory;
import org.eclipse.che.api.languageserver.exception.LanguageServerException;
import org.eclipse.che.api.languageserver.launcher.LanguageServerLauncher;
import org.eclipse.che.api.languageserver.launcher.LanguageServerLauncherTemplate;
import org.eclipse.che.api.languageserver.registry.DocumentFilter;
import org.eclipse.che.api.languageserver.registry.LanguageServerDescription;
import org.eclipse.che.api.languageserver.registry.ServerInitializerObserver;
import org.eclipse.che.plugin.camel.server.inject.CamelModule;
import org.eclipse.lsp4j.ServerCapabilities;
import org.eclipse.lsp4j.jsonrpc.Launcher;
import org.eclipse.lsp4j.services.LanguageClient;
import org.eclipse.lsp4j.services.LanguageServer;

/** Launcher for Apache Camel Language Server */
@Singleton
public class CamelLanguageServerLauncher extends LanguageServerLauncherTemplate
implements ServerInitializerObserver {

private static final String REGEX = ".*\\.(xml)";
private static final LanguageServerDescription DESCRIPTION = createServerDescription();
private static LanguageServer camelLanguageServer;
private final Path launchScript;

@Inject
public CamelLanguageServerLauncher(
@Named("che.api") String apiUrl, HttpJsonRequestFactory requestFactory) {
launchScript = Paths.get(System.getenv("HOME"), "che/ls-camel/launch.sh");
}

@Override
public boolean isAbleToLaunch() {
return Files.exists(launchScript);
}

protected LanguageServer connectToLanguageServer(
final Process languageServerProcess, LanguageClient client) {
Launcher<LanguageServer> launcher =
Launcher.createLauncher(
client,
LanguageServer.class,
languageServerProcess.getInputStream(),
languageServerProcess.getOutputStream());
launcher.startListening();
setCamelLanguageServer(launcher.getRemoteProxy());
return launcher.getRemoteProxy();
}

protected Process startLanguageServerProcess(String projectPath) throws LanguageServerException {
ProcessBuilder processBuilder = new ProcessBuilder(launchScript.toString());
processBuilder.redirectInput(ProcessBuilder.Redirect.PIPE);
processBuilder.redirectOutput(ProcessBuilder.Redirect.PIPE);
try {
return processBuilder.start();
} catch (IOException e) {
throw new LanguageServerException("Can't start Apache Camel language server", e);
}
}

protected static LanguageServer getCamelLanguageServer() {
return camelLanguageServer;
}

protected static void setCamelLanguageServer(LanguageServer camelLanguageServer) {
CamelLanguageServerLauncher.camelLanguageServer = camelLanguageServer;
}

public LanguageServerDescription getDescription() {
return DESCRIPTION;
}

private static LanguageServerDescription createServerDescription() {
LanguageServerDescription description =
new LanguageServerDescription(
"org.eclipse.che.plugin.camel.server.languageserver",
null,
Arrays.asList(new DocumentFilter(CamelModule.LANGUAGE_ID, REGEX, null)));
return description;
}

@Override
public void onServerInitialized(
LanguageServerLauncher arg0, LanguageServer arg1, ServerCapabilities arg2, String arg3) {
// nothing to do
}
}
28 changes: 28 additions & 0 deletions plugins/plugin-camel/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2012-2018 Red Hat, Inc.
All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Public License v1.0
which accompanies this distribution, and is available at
http://www.eclipse.org/legal/epl-v10.html
Contributors:
Red Hat, Inc. - initial API and implementation
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>che-plugin-parent</artifactId>
<groupId>org.eclipse.che.plugin</groupId>
<version>6.1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>che-plugin-camel-parent</artifactId>
<packaging>pom</packaging>
<name>Che Plugin :: Apache Camel :: Parent</name>
<modules>
<module>che-plugin-camel-server</module>
</modules>
</project>
1 change: 1 addition & 0 deletions plugins/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,6 @@
<module>plugin-testing-php</module>
<module>plugin-pullrequest-parent</module>
<module>plugin-yaml</module>
<module>plugin-camel</module>
</modules>
</project>
10 changes: 10 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@
<artifactId>git-credentials-agent</artifactId>
<version>${che.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.che</groupId>
<artifactId>ls-camel-agent</artifactId>
<version>${che.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.che</groupId>
<artifactId>ls-csharp-agent</artifactId>
Expand Down Expand Up @@ -1013,6 +1018,11 @@
<artifactId>che-plugin-activity-wsmaster</artifactId>
<version>${che.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.che.plugin</groupId>
<artifactId>che-plugin-camel-server</artifactId>
<version>${che.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.che.plugin</groupId>
<artifactId>che-plugin-composer-ide</artifactId>
Expand Down

0 comments on commit 307ee4f

Please sign in to comment.