Skip to content

Commit

Permalink
#1794 add ability to use test LS
Browse files Browse the repository at this point in the history
Signed-off-by: Yevhen Vydolob <evidolob@codenvy.com>
  • Loading branch information
Yevhen Vydolob committed Aug 1, 2017
1 parent 0ea6a9d commit e1dac3b
Show file tree
Hide file tree
Showing 21 changed files with 781 additions and 45 deletions.
8 changes: 8 additions & 0 deletions agents/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,12 @@
<module>ls-typescript</module>
<module>ls-csharp</module>
</modules>
<profiles>
<profile>
<id>test-ls</id>
<modules>
<module>test-ls</module>
</modules>
</profile>
</profiles>
</project>
41 changes: 41 additions & 0 deletions agents/test-ls/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2012-2017 Codenvy, S.A.
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:
Codenvy, S.A. - 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>5.16.0-SNAPSHOT</version>
</parent>
<artifactId>test-ls-agent</artifactId>
<name>Test Language Server Agent</name>
<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>org.eclipse.che.core</groupId>
<artifactId>che-core-api-agent-shared</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-commons-inject</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*******************************************************************************
* Copyright (c) 2012-2017 Codenvy, S.A.
* 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:
* Codenvy, S.A. - initial API and implementation
*******************************************************************************/

package org.eclipse.che.api.agent; import com.google.inject.Inject;
import com.google.inject.Singleton;

import org.eclipse.che.api.agent.shared.model.Agent;
import org.eclipse.che.api.agent.shared.model.impl.BasicAgent;

import java.io.IOException;

/**
* Test Language server agent.
*
* @see Agent
*
*/
@Singleton
public class TestLSAgent extends BasicAgent {
private static final String AGENT_DESCRIPTOR = "org.eclipse.che.test.ls.json";
private static final String AGENT_SCRIPT = "org.eclipse.che.test.ls.script.sh";

@Inject
public TestLSAgent() throws IOException {
super(AGENT_DESCRIPTOR, AGENT_SCRIPT);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*******************************************************************************
* Copyright (c) 2012-2017 Codenvy, S.A.
* 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:
* Codenvy, S.A. - initial API and implementation
*******************************************************************************/

package org.eclipse.che.api.agent;

import com.google.inject.AbstractModule;
import com.google.inject.multibindings.Multibinder;

import org.eclipse.che.api.agent.shared.model.Agent;
import org.eclipse.che.inject.DynaModule;

/**
*
*/
@DynaModule
public class TestLSModule extends AbstractModule {
@Override
protected void configure() {
Multibinder<Agent> agents = Multibinder.newSetBinder(binder(), Agent.class);
agents.addBinding().to(TestLSAgent.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"id": "org.eclipse.che.test.ls",
"name": "Simple Test language server",
"description": "Test LS",
"dependencies": [],
"properties": {}
}
170 changes: 170 additions & 0 deletions agents/test-ls/src/main/resources/org.eclipse.che.test.ls.script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
#
# Copyright (c) 2012-2017 Codenvy, S.A.
# 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:
# Codenvy, S.A. - initial API and implementation
#

unset PACKAGES
unset SUDO
command -v tar >/dev/null 2>&1 || { PACKAGES=${PACKAGES}" tar"; }
command -v curl >/dev/null 2>&1 || { PACKAGES=${PACKAGES}" curl"; }
test "$(id -u)" = 0 || SUDO="sudo -E"

AGENT_BINARIES_URI=https://codenvy.com/update/repository/public/download/org.eclipse.che.ls.test.binaries
CHE_DIR=$HOME/che
LS_DIR=${CHE_DIR}/test-ls
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 packages ###
########################

# Red Hat Enterprise Linux 7
############################
if echo ${LINUX_TYPE} | grep -qi "rhel"; then
test "${PACKAGES}" = "" || {
${SUDO} yum install ${PACKAGES};
}

command -v nodejs >/dev/null 2>&1 || {
curl --silent --location https://rpm.nodesource.com/setup_6.x | ${SUDO} bash -;
${SUDO} yum -y install nodejs;
}

# Red Hat Enterprise Linux 6
############################
elif echo ${LINUX_TYPE} | grep -qi "Red Hat"; then
test "${PACKAGES}" = "" || {
${SUDO} yum install ${PACKAGES};
}

command -v nodejs >/dev/null 2>&1 || {
curl --silent --location https://rpm.nodesource.com/setup_6.x | ${SUDO} bash -;
${SUDO} yum -y install nodejs;
}


# Ubuntu 14.04 16.04 / Linux Mint 17
####################################
elif echo ${LINUX_TYPE} | grep -qi "ubuntu"; then
test "${PACKAGES}" = "" || {
${SUDO} apt-get update;
${SUDO} apt-get -y install ${PACKAGES};
}

command -v nodejs >/dev/null 2>&1 || {
{
curl -sL https://deb.nodesource.com/setup_6.x | ${SUDO} bash -;
};

${SUDO} apt-get update;
${SUDO} apt-get install -y nodejs;
}


# Debian 8
##########
elif echo ${LINUX_TYPE} | grep -qi "debian"; then
test "${PACKAGES}" = "" || {
${SUDO} apt-get update;
${SUDO} apt-get -y install ${PACKAGES};
}

command -v nodejs >/dev/null 2>&1 || {
{
curl -sL https://deb.nodesource.com/setup_6.x | ${SUDO} bash -;
};

${SUDO} apt-get update;
${SUDO} apt-get install -y nodejs;
}

# Fedora 23
###########
elif echo ${LINUX_TYPE} | grep -qi "fedora"; then
command -v ps >/dev/null 2>&1 || { PACKAGES=${PACKAGES}" procps-ng"; }
test "${PACKAGES}" = "" || {
${SUDO} dnf -y install ${PACKAGES};
}

command -v nodejs >/dev/null 2>&1 || {
curl --silent --location https://rpm.nodesource.com/setup_6.x | ${SUDO} bash -;
${SUDO} dnf -y install nodejs;
}


# CentOS 7.1 & Oracle Linux 7.1
###############################
elif echo ${LINUX_TYPE} | grep -qi "centos"; then
test "${PACKAGES}" = "" || {
${SUDO} yum -y install ${PACKAGES};
}

command -v nodejs >/dev/null 2>&1 || {
curl --silent --location https://rpm.nodesource.com/setup_6.x | ${SUDO} bash -;
${SUDO} yum -y install nodejs;
}

# openSUSE 13.2
###############
elif echo ${LINUX_TYPE} | grep -qi "opensuse"; then
test "${PACKAGES}" = "" || {
${SUDO} zypper install -y ${PACKAGES};
}

command -v nodejs >/dev/null 2>&1 || {
${SUDO} zypper ar http://download.opensuse.org/repositories/devel:/languages:/nodejs/openSUSE_13.1/ Node.js
${SUDO} zypper in nodejs
}

# Alpine 3.3
############
elif echo ${LINUX_TYPE} | grep -qi "alpine"; then
test "${PACKAGES}" = "" || {
${SUDO} apk update
${SUDO} apk add ${PACKAGES};
}

command -v nodejs >/dev/null 2>&1 || {
${SUDO} apk update
${SUDO} apk add nodejs;
}

else
>&2 echo "Unrecognized Linux Type"
>&2 cat $FILE
exit 1
fi


#######################
### Install Test LS ###
#######################

curl -s ${AGENT_BINARIES_URI} | tar xzf - -C ${LS_DIR}

touch ${LS_LAUNCHER}
chmod +x ${LS_LAUNCHER}
echo "${LS_DIR}/test-ls/server.sh" > ${LS_LAUNCHER}
11 changes: 11 additions & 0 deletions assembly/assembly-wsagent-war/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,15 @@
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>test-ls</id>
<dependencies>
<dependency>
<groupId>org.eclipse.che.plugin</groupId>
<artifactId>che-plugin-test-ls-server</artifactId>
</dependency>
</dependencies>
</profile>
</profiles>
</project>
11 changes: 11 additions & 0 deletions assembly/assembly-wsmaster-war/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -340,4 +340,15 @@
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>test-ls</id>
<dependencies>
<dependency>
<groupId>org.eclipse.che</groupId>
<artifactId>test-ls-agent</artifactId>
</dependency>
</dependencies>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.che.api.core.jsonrpc.impl;

import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonNull;
Expand All @@ -33,10 +34,12 @@

public class GsonJsonRpcMarshaller implements JsonRpcMarshaller {
private final JsonParser jsonParser;
private final Gson gson;

@Inject
public GsonJsonRpcMarshaller(JsonParser jsonParser) {
public GsonJsonRpcMarshaller(JsonParser jsonParser, Gson gson) {
this.jsonParser = jsonParser;
this.gson = gson;
}

@Override
Expand Down Expand Up @@ -164,7 +167,7 @@ private JsonElement getJsonElement(Object param) {
try {
return jsonParser.parse(DtoFactory.getInstance().toJson(param));
} catch (IllegalArgumentException e){
return jsonParser.parse(param.toString());
return gson.toJsonTree(param);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
*******************************************************************************/
package org.eclipse.che.api.core.jsonrpc.impl;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonParser;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
Expand All @@ -23,6 +25,7 @@
import org.eclipse.che.api.core.jsonrpc.commons.JsonRpcUnmarshaller;
import org.eclipse.che.api.core.jsonrpc.commons.RequestHandlerConfigurator;
import org.eclipse.che.api.core.jsonrpc.commons.TimeoutActionRunner;
import org.eclipse.che.dto.server.DtoFactory;

import javax.inject.Singleton;

Expand All @@ -46,4 +49,10 @@ protected void configure() {
public JsonParser jsonParser() {
return new JsonParser();
}

@Provides
@Singleton
protected Gson gson() {
return DtoFactory.getInstance().getGson();
}
}
Loading

0 comments on commit e1dac3b

Please sign in to comment.