diff --git a/agents/ls-camel/pom.xml b/agents/ls-camel/pom.xml new file mode 100644 index 00000000000..7a218570184 --- /dev/null +++ b/agents/ls-camel/pom.xml @@ -0,0 +1,23 @@ + + + + 4.0.0 + + che-agents-parent + org.eclipse.che + 6.1.0-SNAPSHOT + + ls-camel-agent + Language Server Apache Camel Agent + diff --git a/agents/ls-camel/src/main/resources/installers/1.0.0/org.eclipse.che.ls.camel.json b/agents/ls-camel/src/main/resources/installers/1.0.0/org.eclipse.che.ls.camel.json new file mode 100644 index 00000000000..b3b9bc2133d --- /dev/null +++ b/agents/ls-camel/src/main/resources/installers/1.0.0/org.eclipse.che.ls.camel.json @@ -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": {} +} diff --git a/agents/ls-camel/src/main/resources/installers/1.0.0/org.eclipse.che.ls.camel.script.sh b/agents/ls-camel/src/main/resources/installers/1.0.0/org.eclipse.che.ls.camel.script.sh new file mode 100644 index 00000000000..4056dae6fbb --- /dev/null +++ b/agents/ls-camel/src/main/resources/installers/1.0.0/org.eclipse.che.ls.camel.script.sh @@ -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} diff --git a/agents/pom.xml b/agents/pom.xml index 56b7bad9f92..00d60bc25f6 100644 --- a/agents/pom.xml +++ b/agents/pom.xml @@ -38,5 +38,6 @@ ls-csharp test-ls ls-yaml + ls-camel diff --git a/assembly/assembly-wsagent-war/pom.xml b/assembly/assembly-wsagent-war/pom.xml index 1b115665db8..9b723f203b3 100644 --- a/assembly/assembly-wsagent-war/pom.xml +++ b/assembly/assembly-wsagent-war/pom.xml @@ -35,6 +35,10 @@ org.eclipse.che.plugin che-plugin-activity-server + + org.eclipse.che.plugin + che-plugin-camel-server + org.eclipse.che.plugin che-plugin-composer-server diff --git a/assembly/assembly-wsmaster-war/pom.xml b/assembly/assembly-wsmaster-war/pom.xml index e1d74bd93d2..a0c1007da4e 100644 --- a/assembly/assembly-wsmaster-war/pom.xml +++ b/assembly/assembly-wsmaster-war/pom.xml @@ -84,6 +84,10 @@ org.eclipse.che git-credentials-agent + + org.eclipse.che + ls-camel-agent + org.eclipse.che ls-csharp-agent diff --git a/plugins/plugin-camel/che-plugin-camel-server/pom.xml b/plugins/plugin-camel/che-plugin-camel-server/pom.xml new file mode 100644 index 00000000000..d9b088b1678 --- /dev/null +++ b/plugins/plugin-camel/che-plugin-camel-server/pom.xml @@ -0,0 +1,64 @@ + + + + 4.0.0 + + che-plugin-camel-parent + org.eclipse.che.plugin + 6.1.0-SNAPSHOT + + che-plugin-camel-server + Che Plugin :: Apache Camel :: Server + + false + + + + com.google.inject + guice + + + com.google.inject.extensions + guice-multibindings + + + javax.inject + javax.inject + + + org.eclipse.che.core + che-core-api-core + + + org.eclipse.che.core + che-core-api-languageserver + + + org.eclipse.che.core + che-core-api-languageserver-shared + + + org.eclipse.che.core + che-core-commons-inject + + + org.eclipse.lsp4j + org.eclipse.lsp4j + + + org.eclipse.lsp4j + org.eclipse.lsp4j.jsonrpc + + + diff --git a/plugins/plugin-camel/che-plugin-camel-server/src/main/java/org/eclipse/che/plugin/camel/server/inject/CamelModule.java b/plugins/plugin-camel/che-plugin-camel-server/src/main/java/org/eclipse/che/plugin/camel/server/inject/CamelModule.java new file mode 100644 index 00000000000..ce646eafe1d --- /dev/null +++ b/plugins/plugin-camel/che-plugin-camel-server/src/main/java/org/eclipse/che/plugin/camel/server/inject/CamelModule.java @@ -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); + } +} diff --git a/plugins/plugin-camel/che-plugin-camel-server/src/main/java/org/eclipse/che/plugin/camel/server/languageserver/CamelLanguageServerLauncher.java b/plugins/plugin-camel/che-plugin-camel-server/src/main/java/org/eclipse/che/plugin/camel/server/languageserver/CamelLanguageServerLauncher.java new file mode 100644 index 00000000000..d2cf0883859 --- /dev/null +++ b/plugins/plugin-camel/che-plugin-camel-server/src/main/java/org/eclipse/che/plugin/camel/server/languageserver/CamelLanguageServerLauncher.java @@ -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 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 + } +} diff --git a/plugins/plugin-camel/pom.xml b/plugins/plugin-camel/pom.xml new file mode 100644 index 00000000000..1883cf03a4c --- /dev/null +++ b/plugins/plugin-camel/pom.xml @@ -0,0 +1,28 @@ + + + + 4.0.0 + + che-plugin-parent + org.eclipse.che.plugin + 6.1.0-SNAPSHOT + ../pom.xml + + che-plugin-camel-parent + pom + Che Plugin :: Apache Camel :: Parent + + che-plugin-camel-server + + diff --git a/plugins/pom.xml b/plugins/pom.xml index cae1b7d6436..6cb3eab30bb 100644 --- a/plugins/pom.xml +++ b/plugins/pom.xml @@ -58,5 +58,6 @@ plugin-testing-php plugin-pullrequest-parent plugin-yaml + plugin-camel diff --git a/pom.xml b/pom.xml index a55228190ab..c066dcf1593 100644 --- a/pom.xml +++ b/pom.xml @@ -182,6 +182,11 @@ git-credentials-agent ${che.version} + + org.eclipse.che + ls-camel-agent + ${che.version} + org.eclipse.che ls-csharp-agent @@ -1013,6 +1018,11 @@ che-plugin-activity-wsmaster ${che.version} + + org.eclipse.che.plugin + che-plugin-camel-server + ${che.version} + org.eclipse.che.plugin che-plugin-composer-ide