Skip to content

Commit 09c7bb3

Browse files
committed
Automatic server installation
Fixes #40 Check README.md changes for more details.
1 parent c4321da commit 09c7bb3

File tree

10 files changed

+720
-57
lines changed

10 files changed

+720
-57
lines changed

.travis.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ install:
2222
- cask install
2323
script:
2424
- cask build
25-
- mkdir -p ~/.emacs.d/eclipse.jdt.ls/server/
26-
- wget http://download.eclipse.org/jdtls/snapshots/jdt-language-server-latest.tar.gz -O /tmp/jdt-latest.tar
27-
- tar xf /tmp/jdt-latest.tar -C ~/.emacs.d/eclipse.jdt.ls/server/
2825
- cask exec ecukes --timeout 60
2926

3027
notifications:

README.md

Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
[![MELPA](https://melpa.org/packages/lsp-java-badge.svg)](https://melpa.org/#/lsp-java)
22
[![Build Status](https://travis-ci.com/emacs-lsp/lsp-java.svg?branch=master)](https://travis-ci.com/emacs-lsp/lsp-java)
3-
[![Spacemacs](https://cdn.rawgit.com/syl20bnr/spacemacs/442d025779da2f62fc86c2082703697714db6514/assets/spacemacs-badge.svg)](http://spacemacs.org)
43

54
Java support for lsp-mode using the [Eclipse JDT Language Server](https://projects.eclipse.org/projects/eclipse.jdt.ls).
65

@@ -21,30 +20,14 @@ LSP java mode supports the following JDT Features:
2120
* Test runner - [dap-mode](https://github.com/yyoncho/dap-mode/)
2221

2322
## Installation
24-
### Install [Eclipse JDT Language Server](https://projects.eclipse.org/projects/eclipse.jdt.ls)
25-
Download either [latest](http://download.eclipse.org/jdtls/snapshots/jdt-language-server-latest.tar.gz) or [a specific version](http://download.eclipse.org/jdtls/snapshots/?d) of Eclipse JDT Language Server distribution to `~/.emacs.d/eclipse.jdt.ls/server/`
26-
27-
If you choose to have the server installed in a different directory, set `lsp-java-server-install-dir`.
28-
29-
On Linux/MacOS you could install/update [Eclipse JDT Language Server](https://projects.eclipse.org/projects/eclipse.jdt.ls) via running the following commands:
30-
31-
```bash
32-
rm -rf ~/.emacs.d/eclipse.jdt.ls/server/
33-
mkdir -p ~/.emacs.d/eclipse.jdt.ls/server/
34-
wget http://download.eclipse.org/jdtls/snapshots/jdt-language-server-latest.tar.gz -O /tmp/jdt-latest.tar
35-
tar xf /tmp/jdt-latest.tar -C ~/.emacs.d/eclipse.jdt.ls/server/
36-
```
3723
### Spacemacs
3824
[lsp-java](https://github.com/emacs-lsp/lsp-java) is included in spacemacs (for now only on the dev branch). If you are using the development version of
3925
spacemacs you can simply add `(java :variables java-backend 'lsp)` to `dotspacemacs-configuration-layers`.
4026

41-
### Install LSP Java
27+
### Install via melpa
4228
The recommended way to install LSP Java is via `package.el` - the built-in package
43-
manager in Emacs.
44-
LSP Java is available on the two major `package.el` community
45-
maintained repos -
46-
[MELPA Stable](http://stable.melpa.org)
47-
and [MELPA](http://melpa.org).
29+
manager in Emacs. LSP Java is available on the two major `package.el` community
30+
maintained repos - [MELPA Stable](http://stable.melpa.org) and [MELPA](http://melpa.org).
4831

4932
<kbd>M-x</kbd> `package-install` <kbd>[RET]</kbd> `lsp-java` <kbd>[RET]</kbd>
5033

@@ -58,6 +41,10 @@ Then add the following lines to your `.emacs` and open a file from the any of th
5841
"/path/to/project2"
5942
...))
6043
```
44+
### [Eclipse JDT Language Server](https://projects.eclipse.org/projects/eclipse.jdt.ls)
45+
46+
[lsp-java](https://github.com/emacs-lsp/lsp-java) will automatically detect when the server is missing and it will download [Eclipse JDT Language Server](https://projects.eclipse.org/projects/eclipse.jdt.ls) before the first startup. The server installation will be in `lsp-java-server-install-dir`. It will detect whether [dap-mode](https://github.com/yyoncho/dap-mode/) is present and it will download the required server side plugins/components. If you want to update the server you can run `lsp-java-update-server`. To run specific version of [Eclipse JDT Language Server](https://projects.eclipse.org/projects/eclipse.jdt.ls) use `lsp-java-server-install-dir`.
47+
6148
#### Quick start
6249
Minimal configuration with [company-lsp](https://github.com/tigersoldier/company-lsp) and [lsp-ui](https://github.com/emacs-lsp/lsp-ui). Make sure you have replaced the XXX placeholder with the list of the projects you want to import.
6350
```elisp
@@ -110,7 +97,7 @@ Minimal configuration with [company-lsp](https://github.com/tigersoldier/company
11097
```
11198
## Supported commands
11299
### LSP Mode commands
113-
| Command name | Description |
100+
| Command name | Description |
114101
|-----------------------------|--------------------------------------------------------------|
115102
| lsp-execute-code-action | Execute code action. |
116103
| lsp-rename | Rename symbol at point |
@@ -127,23 +114,24 @@ Minimal configuration with [company-lsp](https://github.com/tigersoldier/company
127114
| lsp-java-organize-imports | Organize imports |
128115
| lsp-java-build-project | Perform partial or full build for the projects |
129116
| lsp-java-update-project-configuration | Update project configuration |
130-
| lsp-java-actionable-notifications | Resolve actionble notifications |
117+
| lsp-java-actionable-notifications | Resolve actionable notifications |
131118
| lsp-java-update-user-settings | Update user settings (Check the options in the table bellow.) |
119+
| lsp-java-update-server | Update server instalation. |
132120
#### Refactoring
133121

134122
LSP Java provides rich set of refactorings via [Eclipse JDT Language
135123
Server](https://projects.eclipse.org/projects/eclipse.jdt.ls) code actions and
136124
some of them are bound to Emacs commands:
137125

138-
| Command name | Description |
139-
|-----------------------------------|------------------------------|
140-
| lsp-java-extract-to-constant | Extract constant refactoring |
141-
| lsp-java-add-unimplmented-methods | Extract constant refactoring |
142-
| lsp-java-create-parameter | Create parameter refactoring |
143-
| lsp-java-create-field | Create field refactoring |
144-
| lsp-java-create-local | Create local refactoring |
145-
| lsp-java-extract-method | Extract method refactoring |
146-
| lsp-java-add-import | Add missing import |
126+
| Command name | Description |
127+
|------------------------------------|------------------------------|
128+
| lsp-java-extract-to-constant | Extract constant refactoring |
129+
| lsp-java-add-unimplemented-methods | Extract constant refactoring |
130+
| lsp-java-create-parameter | Create parameter refactoring |
131+
| lsp-java-create-field | Create field refactoring |
132+
| lsp-java-create-local | Create local refactoring |
133+
| lsp-java-extract-method | Extract method refactoring |
134+
| lsp-java-add-import | Add missing import |
147135
## Supported settings
148136
| Setting | Description |
149137
|---------------------------------------|-----------------------------------------------------------------------------------------------------------------|

features/InvalidJavaServer.feature

Lines changed: 0 additions & 13 deletions
This file was deleted.

features/support/env.el

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
(require 'lsp-java)
2828
(require 'lsp-mode))
2929

30-
(Setup)
30+
(Setup
31+
(lsp-java-update-server))
3132

3233
(Before
3334
(require 'lsp-java)
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/*
2+
Licensed to the Apache Software Foundation (ASF) under one
3+
or more contributor license agreements. See the NOTICE file
4+
distributed with this work for additional information
5+
regarding copyright ownership. The ASF licenses this file
6+
to you under the Apache License, Version 2.0 (the
7+
"License"); you may not use this file except in compliance
8+
with the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing,
13+
software distributed under the License is distributed on an
14+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
KIND, either express or implied. See the License for the
16+
specific language governing permissions and limitations
17+
under the License.
18+
*/
19+
20+
import java.net.*;
21+
import java.io.*;
22+
import java.nio.channels.*;
23+
import java.util.Properties;
24+
25+
public class MavenWrapperDownloader {
26+
27+
/**
28+
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
29+
*/
30+
private static final String DEFAULT_DOWNLOAD_URL =
31+
"https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.0/maven-wrapper-0.4.0.jar";
32+
33+
/**
34+
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
35+
* use instead of the default one.
36+
*/
37+
private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
38+
".mvn/wrapper/maven-wrapper.properties";
39+
40+
/**
41+
* Path where the maven-wrapper.jar will be saved to.
42+
*/
43+
private static final String MAVEN_WRAPPER_JAR_PATH =
44+
".mvn/wrapper/maven-wrapper.jar";
45+
46+
/**
47+
* Name of the property which should be used to override the default download url for the wrapper.
48+
*/
49+
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
50+
51+
public static void main(String args[]) {
52+
System.out.println("- Downloader started");
53+
File baseDirectory = new File(args[0]);
54+
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
55+
56+
// If the maven-wrapper.properties exists, read it and check if it contains a custom
57+
// wrapperUrl parameter.
58+
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
59+
String url = DEFAULT_DOWNLOAD_URL;
60+
if(mavenWrapperPropertyFile.exists()) {
61+
FileInputStream mavenWrapperPropertyFileInputStream = null;
62+
try {
63+
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
64+
Properties mavenWrapperProperties = new Properties();
65+
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
66+
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
67+
} catch (IOException e) {
68+
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
69+
} finally {
70+
try {
71+
if(mavenWrapperPropertyFileInputStream != null) {
72+
mavenWrapperPropertyFileInputStream.close();
73+
}
74+
} catch (IOException e) {
75+
// Ignore ...
76+
}
77+
}
78+
}
79+
System.out.println("- Downloading from : " + url);
80+
81+
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
82+
if(!outputFile.getParentFile().exists()) {
83+
if(!outputFile.getParentFile().mkdirs()) {
84+
System.out.println(
85+
"- ERROR creating output direcrory '" + outputFile.getParentFile().getAbsolutePath() + "'");
86+
}
87+
}
88+
System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
89+
try {
90+
downloadFileFromURL(url, outputFile);
91+
System.out.println("Done");
92+
System.exit(0);
93+
} catch (Throwable e) {
94+
System.out.println("- Error downloading");
95+
e.printStackTrace();
96+
System.exit(1);
97+
}
98+
}
99+
100+
private static void downloadFileFromURL(String urlString, File destination) throws Exception {
101+
URL website = new URL(urlString);
102+
ReadableByteChannel rbc;
103+
rbc = Channels.newChannel(website.openStream());
104+
FileOutputStream fos = new FileOutputStream(destination);
105+
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
106+
fos.close();
107+
rbc.close();
108+
}
109+
110+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.5.4/apache-maven-3.5.4-bin.zip

0 commit comments

Comments
 (0)