Commit 8f0cf40a authored by hequnying's avatar hequnying

lsp-java

parents
(source gnu)
(source melpa)
(package-file "lsp-java.el")
(files "*.el")
(depends-on "markdown-mode")
(development
(depends-on "spinner")
(depends-on "ecukes")
(depends-on "espuds"))
This diff is collapsed.
SHELL=/usr/bin/env bash
EMACS ?= emacs
CASK ?= cask
INIT="(progn \
(require 'package) \
(push '(\"melpa\" . \"https://melpa.org/packages/\") package-archives) \
(package-initialize) \
(package-refresh-contents))"
LINT="(progn \
(unless (package-installed-p 'package-lint) \
(package-install 'package-lint)) \
(require 'package-lint) \
(package-lint-batch-and-exit))"
build:
cask install
test: build compile checkdoc lint
compile:
@echo "Compiling..."
@$(CASK) $(EMACS) -Q --batch \
-L . \
--eval '(setq byte-compile-error-on-warn t)' \
-f batch-byte-compile \
*.el
lint:
@echo "package linting..."
@$(CASK) $(EMACS) -Q --batch \
-L . \
--eval $(INIT) \
--eval $(LINT) \
*.el
clean:
rm -rf .cask
.PHONY: build test compile checkdoc lint
This diff is collapsed.
:root {
--md-primary-fg-color: #337699;
--md-accent-fg-color: #ED8B00;
--md-default-fg-color--light: #007396;
}
.md-footer {
--md-default-fg-color: #337699;
}
.md-grid {
max-width: 70rem;
}
.md-typeset a {
color: #007396;
}
Feature: Browse classpaths
@Classpath
Scenario: Organize imports
Given I have maven project "m" in "tmp"
And I add project "m" folder "tmp" to the list of workspace folders
And I have a java file "tmp/m/src/main/java/temp/App.java"
And I clear the buffer
And I insert:
"""
package temp;
import java.util.HashMap;
class App {
ArrayList<String> al = new ArrayList<>();
}
"""
And I call "save-buffer"
And I start lsp-java
And The server status must become "LSP::Started"
When I call "lsp-java-classpath-browse" and see:
"""
org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER
"""
Feature: Formatting
Scenario: Changing formatter
Given I have maven project "m" in "tmp"
And I have a java file "tmp/m/src/main/java/temp/App.java"
And I add project "m" folder "tmp" to the list of workspace folders
And I clear the buffer
And I insert:
"""
package temp; import java.util.ArrayList; class App {ArrayList<String> al = new ArrayList<>();}
"""
And I call "save-buffer"
And I use formatter profile "profileName" from "testFormatter.xml"
And I start lsp-java
And The server status must become "LSP::Started"
When I indent buffer
And I call "save-buffer"
Then I should see:
"""
package temp;
import java.util.ArrayList;
class App
{
ArrayList<String> al = new ArrayList<>();
}
"""
Feature: Importing projects
Scenario: Maven projects
Given I have maven project "m" in "tmp"
And I have a java file "tmp/m/src/main/java/temp/App.java"
And I clear the buffer
And I add project "m" folder "tmp" to the list of workspace folders
And I start lsp-java
Then The server status must become "LSP::Started"
This diff is collapsed.
;;; lsp-java-steps.el --- Step definitions for lsp-java -*- lexical-binding: t; -*-
;; Copyright (C) 2018 Ivan Yonchovski
;; Author: Ivan Yonchovski <ivan.yonchovski@tick42.com>
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
;;; Code:
(require 'f)
(require 's)
(require 'lsp-java)
(defun lsp-java-steps-async-wait (pred callback)
"Call CALLBACK when PRED becomes true."
(let (timer
(retry-count 0))
(setq timer (run-with-timer
1
1
(lambda (&rest rest)
(if (funcall pred)
(progn
(cancel-timer timer)
(funcall callback))
(setq retry-count (1+ retry-count))
(message "The function failed, attempt %s" retry-count)))))))
(Given "^I have maven project \"\\([^\"]+\\)\" in \"\\([^\"]+\\)\"$"
(lambda (project-name dir-name)
(setq default-directory lsp-java-test-root)
;; delete old directory
(when (file-exists-p dir-name)
(delete-directory dir-name t))
;; create directory structure
(mkdir (expand-file-name
(f-join dir-name project-name "src" "main" "java" "temp")) t)
;; add pom.xml
(with-temp-file (expand-file-name "pom.xml" (f-join dir-name project-name))
(insert "
<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>
<groupId>test</groupId>
<artifactId>test-project</artifactId>
<packaging>jar</packaging>
<version>1</version>
<name>test-project</name>
<url>http://maven.apache.org</url>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
</project>"))))
(And "^I have a java file \"\\([^\"]+\\)\"$"
(lambda (file-name)
(setq default-directory lsp-java-test-root)
(find-file file-name)
(save-buffer)))
(And "^I add project \"\\([^\"]+\\)\" folder \"\\([^\"]+\\)\" to the list of workspace folders$"
(lambda (project dir-name)
(mkdir lsp-java-workspace-dir t)
(lsp-workspace-folders-add (f-join lsp-java-test-root dir-name project))))
(And "^I start lsp-java$"
(lambda () (lsp)))
(Then "^The server status must become \"\\([^\"]+\\)\"$"
(lambda (status callback)
(lsp-java-steps-async-wait
(lambda ()
(--some? (equal (lsp--workspace-status-string it) "::Started")
(lsp--session-workspaces (lsp-session))))
callback)))
(And "^I use formatter profile \"\\([^\"]+\\)\" from \"\\([^\"]+\\)\"$"
(lambda (formatter-name formatter-file)
(setq lsp-java-format-settings-url (lsp--path-to-uri
(f-join lsp-java-root-path "features/fixtures" formatter-file)))
(setq lsp-java-format-settings-profile formatter-name)))
(And "^There must be \"\\([^\"]+\\)\" actionable notification$"
(lambda (count callback)
(lsp-java-steps-async-wait
(lambda ()
(= (string-to-number count)
(hash-table-count (lsp-workspace-get-metadata "actionable-notifications"))))
callback)))
(When "^I indent buffer$"
(lambda ()
(indent-region (point-min) (point-marker))))
(When "^I invoke \"\\([^\"]+\\)\" I should see error message \"\\([^\"]+\\)\"$"
(lambda (command message)
(condition-case err
(funcall (intern command))
(error (cl-assert (string= message (error-message-string err)) t (error-message-string err))))))
(When "^I call \"\\([^\"]+\\)\" and see:$"
(lambda (command text callback)
(lsp-java-steps-async-wait
(lambda ()
(save-window-excursion
(funcall (intern command))
(s-contains? text (buffer-string) t)))
callback)))
(provide 'lsp-java-steps)
;;; lsp-java-steps.el ends here
(require 'f)
(let* ((features-directory
(file-name-directory
(directory-file-name (file-name-directory load-file-name))))
(project-directory
(file-name-directory
(directory-file-name features-directory))))
(defvar lsp-java-root-path project-directory)
(defvar lsp-java-test-root (f-join temporary-file-directory "tests")))
(defvar lsp-java-support-path
(f-dirname load-file-name))
(defvar lsp-java-features-path
(f-parent lsp-java-support-path))
(defvar lsp-java-root-path
(f-parent lsp-java-features-path))
(add-to-list 'load-path lsp-java-root-path)
;; Ensure that we don't load old byte-compiled versions
(let ((load-prefer-newer t))
(require 'espuds)
(require 'ert)
(require 'lsp-java))
(Setup
(unless (file-directory-p (expand-file-name "plugins" lsp-java-server-install-dir))
(lsp-java-update-server)))
(Before
(require 'lsp-java)
(setq lsp-java-workspace-dir (f-join lsp-java-test-root "workspace")
lsp-java-pop-buffer-function 'pop-to-buffer
lsp-print-io t
lsp-inhibit-message nil
lsp-java-workspace-cache-dir (f-join lsp-java-test-root "workspace-cache")
lsp-java-server-install-dir (locate-user-emacs-file "eclipse.jdt.ls/server/")
lsp-response-timeout 30)
(when (file-exists-p lsp-java-test-root)
(delete-directory lsp-java-test-root t))
(setq lsp--session (make-lsp-session)))
(After
(mapc 'kill-buffer
(seq-filter
(lambda (b)
(with-current-buffer b
(equal 'java-mode major-mode)))
(buffer-list))))
(Teardown
;; After when everything has been run
)
images/run.png

365 Bytes

/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
import java.net.*;
import java.io.*;
import java.nio.channels.*;
import java.util.Properties;
public class MavenWrapperDownloader {
/**
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
*/
private static final String DEFAULT_DOWNLOAD_URL =
"https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.0/maven-wrapper-0.4.0.jar";
/**
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
* use instead of the default one.
*/
private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
".mvn/wrapper/maven-wrapper.properties";
/**
* Path where the maven-wrapper.jar will be saved to.
*/
private static final String MAVEN_WRAPPER_JAR_PATH =
".mvn/wrapper/maven-wrapper.jar";
/**
* Name of the property which should be used to override the default download url for the wrapper.
*/
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
public static void main(String args[]) {
System.out.println("- Downloader started");
File baseDirectory = new File(args[0]);
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
// If the maven-wrapper.properties exists, read it and check if it contains a custom
// wrapperUrl parameter.
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
String url = DEFAULT_DOWNLOAD_URL;
if(mavenWrapperPropertyFile.exists()) {
FileInputStream mavenWrapperPropertyFileInputStream = null;
try {
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
Properties mavenWrapperProperties = new Properties();
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
} catch (IOException e) {
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
} finally {
try {
if(mavenWrapperPropertyFileInputStream != null) {
mavenWrapperPropertyFileInputStream.close();
}
} catch (IOException e) {
// Ignore ...
}
}
}
System.out.println("- Downloading from : " + url);
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
if(!outputFile.getParentFile().exists()) {
if(!outputFile.getParentFile().mkdirs()) {
System.out.println(
"- ERROR creating output direcrory '" + outputFile.getParentFile().getAbsolutePath() + "'");
}
}
System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
try {
downloadFileFromURL(url, outputFile);
System.out.println("Done");
System.exit(0);
} catch (Throwable e) {
System.out.println("- Error downloading");
e.printStackTrace();
System.exit(1);
}
}
private static void downloadFileFromURL(String urlString, File destination) throws Exception {
URL website = new URL(urlString);
ReadableByteChannel rbc;
rbc = Channels.newChannel(website.openStream());
FileOutputStream fos = new FileOutputStream(destination);
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
fos.close();
rbc.close();
}
}
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.5.4/apache-maven-3.5.4-bin.zip
\ No newline at end of file
#!/bin/sh
# ----------------------------------------------------------------------------
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# ----------------------------------------------------------------------------
# ----------------------------------------------------------------------------
# Maven2 Start Up Batch script
#
# Required ENV vars:
# ------------------
# JAVA_HOME - location of a JDK home dir
#
# Optional ENV vars
# -----------------
# M2_HOME - location of maven2's installed home dir
# MAVEN_OPTS - parameters passed to the Java VM when running Maven
# e.g. to debug Maven itself, use
# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
# MAVEN_SKIP_RC - flag to disable loading of mavenrc files
# ----------------------------------------------------------------------------
if [ -z "$MAVEN_SKIP_RC" ] ; then
if [ -f /etc/mavenrc ] ; then
. /etc/mavenrc
fi
if [ -f "$HOME/.mavenrc" ] ; then
. "$HOME/.mavenrc"
fi
fi
# OS specific support. $var _must_ be set to either true or false.
cygwin=false;
darwin=false;
mingw=false
case "`uname`" in
CYGWIN*) cygwin=true ;;
MINGW*) mingw=true;;
Darwin*) darwin=true
# Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home
# See https://developer.apple.com/library/mac/qa/qa1170/_index.html
if [ -z "$JAVA_HOME" ]; then
if [ -x "/usr/libexec/java_home" ]; then
export JAVA_HOME="`/usr/libexec/java_home`"
else
export JAVA_HOME="/Library/Java/Home"
fi
fi
;;
esac
if [ -z "$JAVA_HOME" ] ; then
if [ -r /etc/gentoo-release ] ; then
JAVA_HOME=`java-config --jre-home`
fi
fi
if [ -z "$M2_HOME" ] ; then
## resolve links - $0 may be a link to maven's home
PRG="$0"
# need this for relative symlinks
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG="`dirname "$PRG"`/$link"
fi
done
saveddir=`pwd`
M2_HOME=`dirname "$PRG"`/..
# make it fully qualified
M2_HOME=`cd "$M2_HOME" && pwd`
cd "$saveddir"
# echo Using m2 at $M2_HOME
fi
# For Cygwin, ensure paths are in UNIX format before anything is touched
if $cygwin ; then
[ -n "$M2_HOME" ] &&
M2_HOME=`cygpath --unix "$M2_HOME"`
[ -n "$JAVA_HOME" ] &&
JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
[ -n "$CLASSPATH" ] &&
CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
fi
# For Mingw, ensure paths are in UNIX format before anything is touched
if $mingw ; then
[ -n "$M2_HOME" ] &&
M2_HOME="`(cd "$M2_HOME"; pwd)`"
[ -n "$JAVA_HOME" ] &&
JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
# TODO classpath?
fi
if [ -z "$JAVA_HOME" ]; then
javaExecutable="`which javac`"
if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
# readlink(1) is not available as standard on Solaris 10.
readLink=`which readlink`
if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
if $darwin ; then
javaHome="`dirname \"$javaExecutable\"`"
javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
else
javaExecutable="`readlink -f \"$javaExecutable\"`"
fi
javaHome="`dirname \"$javaExecutable\"`"
javaHome=`expr "$javaHome" : '\(.*\)/bin'`
JAVA_HOME="$javaHome"
export JAVA_HOME
fi
fi
fi
if [ -z "$JAVACMD" ] ; then
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
else
JAVACMD="`which java`"
fi
fi
if [ ! -x "$JAVACMD" ] ; then
echo "Error: JAVA_HOME is not defined correctly." >&2
echo " We cannot execute $JAVACMD" >&2
exit 1
fi
if [ -z "$JAVA_HOME" ] ; then
echo "Warning: JAVA_HOME environment variable is not set."
fi
CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
# traverses directory structure from process work directory to filesystem root
# first directory with .mvn subdirectory is considered project base directory
find_maven_basedir() {
if [ -z "$1" ]
then
echo "Path not specified to find_maven_basedir"
return 1
fi
basedir="$1"
wdir="$1"
while [ "$wdir" != '/' ] ; do
if [ -d "$wdir"/.mvn ] ; then
basedir=$wdir
break
fi
# workaround for JBEAP-8937 (on Solaris 10/Sparc)
if [ -d "${wdir}" ]; then
wdir=`cd "$wdir/.."; pwd`
fi
# end of workaround
done
echo "${basedir}"
}
# concatenates all lines of a file
concat_lines() {
if [ -f "$1" ]; then
echo "$(tr -s '\n' ' ' < "$1")"
fi
}
BASE_DIR=`find_maven_basedir "$(pwd)"`
if [ -z "$BASE_DIR" ]; then
exit 1;
fi
##########################################################################################
# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
# This allows using the maven wrapper in projects that prohibit checking in binary data.
##########################################################################################
if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then
if [ "$MVNW_VERBOSE" = true ]; then
echo "Found .mvn/wrapper/maven-wrapper.jar"
fi
else
if [ "$MVNW_VERBOSE" = true ]; then
echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..."
fi
jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.0/maven-wrapper-0.4.0.jar"
while IFS="=" read key value; do
case "$key" in (wrapperUrl) jarUrl="$value"; break ;;
esac
done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties"
if [ "$MVNW_VERBOSE" = true ]; then
echo "Downloading from: $jarUrl"
fi
wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar"
if command -v wget > /dev/null; then
if [ "$MVNW_VERBOSE" = true ]; then
echo "Found wget ... using wget"
fi
wget "$jarUrl" -O "$wrapperJarPath"
elif command -v curl > /dev/null; then
if [ "$MVNW_VERBOSE" = true ]; then
echo "Found curl ... using curl"
fi
curl -o "$wrapperJarPath" "$jarUrl"
else
if [ "$MVNW_VERBOSE" = true ]; then
echo "Falling back to using Java to download"
fi
javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java"
if [ -e "$javaClass" ]; then
if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
if [ "$MVNW_VERBOSE" = true ]; then
echo " - Compiling MavenWrapperDownloader.java ..."
fi
# Compiling the Java class
("$JAVA_HOME/bin/javac" "$javaClass")
fi
if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
# Running the downloader
if [ "$MVNW_VERBOSE" = true ]; then
echo " - Running MavenWrapperDownloader.java ..."
fi
("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR")
fi
fi
fi
fi
##########################################################################################
# End of extension
##########################################################################################
export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
if [ "$MVNW_VERBOSE" = true ]; then
echo $MAVEN_PROJECTBASEDIR
fi
MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
# For Cygwin, switch paths to Windows format before running java
if $cygwin; then
[ -n "$M2_HOME" ] &&
M2_HOME=`cygpath --path --windows "$M2_HOME"`
[ -n "$JAVA_HOME" ] &&
JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
[ -n "$CLASSPATH" ] &&
CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
[ -n "$MAVEN_PROJECTBASEDIR" ] &&
MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
fi
WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
exec "$JAVACMD" \
$MAVEN_OPTS \
-classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
"-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"
@REM ----------------------------------------------------------------------------
@REM Licensed to the Apache Software Foundation (ASF) under one
@REM or more contributor license agreements. See the NOTICE file
@REM distributed with this work for additional information
@REM regarding copyright ownership. The ASF licenses this file
@REM to you under the Apache License, Version 2.0 (the
@REM "License"); you may not use this file except in compliance
@REM with the License. You may obtain a copy of the License at
@REM
@REM http://www.apache.org/licenses/LICENSE-2.0
@REM
@REM Unless required by applicable law or agreed to in writing,
@REM software distributed under the License is distributed on an
@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@REM KIND, either express or implied. See the License for the
@REM specific language governing permissions and limitations
@REM under the License.
@REM ----------------------------------------------------------------------------
@REM ----------------------------------------------------------------------------
@REM Maven2 Start Up Batch script
@REM
@REM Required ENV vars:
@REM JAVA_HOME - location of a JDK home dir
@REM
@REM Optional ENV vars
@REM M2_HOME - location of maven2's installed home dir
@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending
@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
@REM e.g. to debug Maven itself, use
@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
@REM ----------------------------------------------------------------------------
@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
@echo off
@REM set title of command window
title %0
@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on'
@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
@REM set %HOME% to equivalent of $HOME
if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
@REM Execute a user defined script before this one
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
@REM check for pre script, once with legacy .bat ending and once with .cmd ending
if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat"
if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd"
:skipRcPre
@setlocal
set ERROR_CODE=0
@REM To isolate internal variables from possible post scripts, we use another setlocal
@setlocal
@REM ==== START VALIDATION ====
if not "%JAVA_HOME%" == "" goto OkJHome
echo.
echo Error: JAVA_HOME not found in your environment. >&2
echo Please set the JAVA_HOME variable in your environment to match the >&2
echo location of your Java installation. >&2
echo.
goto error
:OkJHome
if exist "%JAVA_HOME%\bin\java.exe" goto init
echo.
echo Error: JAVA_HOME is set to an invalid directory. >&2
echo JAVA_HOME = "%JAVA_HOME%" >&2
echo Please set the JAVA_HOME variable in your environment to match the >&2
echo location of your Java installation. >&2
echo.
goto error
@REM ==== END VALIDATION ====
:init
@REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
@REM Fallback to current working directory if not found.
set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
set EXEC_DIR=%CD%
set WDIR=%EXEC_DIR%
:findBaseDir
IF EXIST "%WDIR%"\.mvn goto baseDirFound
cd ..
IF "%WDIR%"=="%CD%" goto baseDirNotFound
set WDIR=%CD%
goto findBaseDir
:baseDirFound
set MAVEN_PROJECTBASEDIR=%WDIR%
cd "%EXEC_DIR%"
goto endDetectBaseDir
:baseDirNotFound
set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
cd "%EXEC_DIR%"
:endDetectBaseDir
IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
@setlocal EnableExtensions EnableDelayedExpansion
for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
:endReadAdditionalConfig
SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar"
FOR /F "tokens=1,2 delims==" %%A IN (%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties) DO (
IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B
)
@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
@REM This allows using the maven wrapper in projects that prohibit checking in binary data.
if exist %WRAPPER_JAR% (
echo Found %WRAPPER_JAR%
) else (
echo Couldn't find %WRAPPER_JAR%, downloading it ...
echo Downloading from: %DOWNLOAD_URL%
powershell -Command "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; (New-Object Net.WebClient).DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"
echo Finished downloading %WRAPPER_JAR%
)
@REM End of extension
%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
if ERRORLEVEL 1 goto error
goto end
:error
set ERROR_CODE=1
:end
@endlocal & set ERROR_CODE=%ERROR_CODE%
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost
@REM check for post script, once with legacy .bat ending and once with .cmd ending
if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat"
if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd"
:skipRcPost
@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
if "%MAVEN_BATCH_PAUSE%" == "on" pause
if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE%
exit /B %ERROR_CODE%
<?xml version="1.0" encoding="UTF-8"?>
<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>
<groupId>lsp-java</groupId>
<artifactId>lsp-java</artifactId>
<version>1.0.0-SNAPSHOT</version>
<properties>
<root.install.dir>${user.home}/.emacs.d/eclipse.jdt.ls</root.install.dir>
</properties>
<packaging>pom</packaging>
<build>
<plugins>
<plugin>
<groupId>com.googlecode.maven-download-plugin</groupId>
<artifactId>download-maven-plugin</artifactId>
<version>1.3.0</version>
<executions>
<execution>
<phase>process-resources</phase>
<id>download-server</id>
<goals>
<goal>wget</goal>
</goals>
<configuration>
<url>${jdt.download.url}</url>
<outputFileName>jdt-language-server-latest.tar.gz</outputFileName>
<skipCache>true</skipCache>
<outputDirectory>${project.build.directory}</outputDirectory>
</configuration>
</execution>
<execution>
<phase>process-resources</phase>
<id>download-spring-boot</id>
<goals>
<goal>wget</goal>
</goals>
<configuration>
<url>https://github.com/emacs-lsp/lsp-java/releases/download/2.2/Pivotal.vscode-spring-boot-1.6.0.vsix</url>
<outputFileName>vscode-extension.zip</outputFileName>
<outputDirectory>${project.build.directory}</outputDirectory>
</configuration>
</execution>
<execution>
<phase>process-resources</phase>
<id>download-java-dependency</id>
<goals>
<goal>wget</goal>
</goals>
<configuration>
<url>https://github.com/emacs-lsp/lsp-java/releases/download/2.2/vscjava.vscode-java-dependency-0.5.1.vsix</url>
<outputFileName>java-dependency.zip</outputFileName>
<outputDirectory>${project.build.directory}</outputDirectory>
</configuration>
</execution>
<execution>
<phase>process-resources</phase>
<id>download-java-di</id>
<goals>
<goal>wget</goal>
</goals>
<configuration>
<url>https://github.com/emacs-lsp/lsp-java/releases/download/2.2/dgileadi.java-decompiler-0.0.2.vsix</url>
<outputFileName>java-decompiler.zip</outputFileName>
<outputDirectory>${project.build.directory}</outputDirectory>
</configuration>
</execution>
<execution>
<phase>process-resources</phase>
<id>download-java-test-dependency</id>
<goals>
<goal>wget</goal>
</goals>
<configuration>
<url>https://github.com/emacs-lsp/lsp-java/releases/download/2.2/vscode-java-test.zip</url>
<outputFileName>vscode-java-test.zip</outputFileName>
<outputDirectory>${project.build.directory}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>prepare</id>
<phase>process-resources</phase>
<configuration>
<tasks>
<untar src="${project.build.directory}/jdt-language-server-latest.tar.gz" compression="gzip" dest="${jdt.js.server.root}" />
<unzip src="${project.build.directory}/vscode-extension.zip" dest="${project.build.directory}/vscode-extension-extracted" />
<unzip src="${project.build.directory}/java-dependency.zip" dest="${project.build.directory}/java-dependency" />
<unzip src="${project.build.directory}/vscode-java-test.zip" dest="${jdt.js.server.root}/java-test" />
<unzip src="${project.build.directory}/java-decompiler.zip" dest="${jdt.js.server.root}/java-decompiler" />
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.microsoft.java</groupId>
<artifactId>com.microsoft.java.debug.plugin</artifactId>
<version>0.24.0</version>
<outputDirectory>${java.debug.root}</outputDirectory>
<destFileName>java.debug.plugin.jar</destFileName>
</artifactItem>
<artifactItem>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-console-standalone</artifactId>
<version>1.6.2</version>
<outputDirectory>${junit.runner.root}</outputDirectory>
<destFileName>${junit.runner.fileName}</destFileName>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>copy-boot-server</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${jdt.js.server.root}/boot-server/</outputDirectory>
<resources>
<resource>
<directory>${project.build.directory}/vscode-extension-extracted/extension/jars/</directory>
<includes>
<include>spring-boot-language-server-*.jar</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
<execution>
<id>copy-bundles</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${jdt.js.server.root}/bundles/</outputDirectory>
<resources>
<resource>
<directory>${project.build.directory}/vscode-extension-extracted/extension/jars/</directory>
<includes>
<include>jdt-ls-extension.jar</include>
<include>jdt-ls-commons.jar</include>
<include>org.reactivestreams.reactive-streams.jar</include>
<include>io.projectreactor.reactor-core.jar</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
<execution>
<id>copy-decompiler </id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${jdt.js.server.root}/bundles/</outputDirectory>
<resources>
<resource>
<directory>${jdt.js.server.root}/java-decompiler/extension/server</directory>
<includes>
<include>dg.jdt.ls.decompiler.*.jar</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
<execution>
<id>copy-test-bundle</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${jdt.js.server.root}/bundles/</outputDirectory>
<resources>
<resource>
<directory>${jdt.js.server.root}/java-test/server/</directory>
<includes>
<include>com.microsoft.java.test.plugin-0.19.0.jar</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
<execution>
<id>copy-test-data</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${jdt.js.server.root}/bundles/</outputDirectory>
<resources>
<resource>
<directory>${project.build.directory}/java-dependency/extension/server/</directory>
<includes>
<include>com.microsoft.jdtls.ext.core-0.5.1.jar</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
;;; lsp-java-boot.el --- Spring boot support for lsp-java -*- lexical-binding: t; -*-
;; Version: 2.0
;; Package-Requires: ((emacs "25.1") (lsp-mode "6.0") (markdown-mode "2.3") (dash "2.14.1") (f "0.20.0") (ht "2.0") (dash-functional "1.2.0") (request "0.3.0"))
;; Keywords: languague, tools
;; URL: https://github.com/emacs-lsp/lsp-java
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; LSP Java support for Spring Boot.
;;; Code:
(require 'dash)
(require 'cl-lib)
(require 'lsp-mode)
(require 'lsp-java)
(defcustom lsp-java-boot-enabled t
"If non-nil start the boot server when opening java files."
:group 'lsp-java-boot
:type 'boolean)
(defcustom lsp-java-boot-java-tools-jar nil
"Path to tools jar. If it is not specified it will be calculated using `JAVA_HOME'."
:group 'lsp-java-boot
:type 'file)
(defvar lsp-java-boot--callback nil)
(defun lsp-java-boot--find-tools-jar ()
"Calculate the path to tools.jar."
(let ((tools-jar (or lsp-java-boot-java-tools-jar
(f-join (getenv "JAVA_HOME") "lib/tools.jar"))))
(unless (f-exists? tools-jar)
(error "Please configure either JAVA_HOME or lsp-java-boot-java-tools-jar"))
tools-jar))
(defun lsp-java-boot--sts-javadoc-hover-link (_workspace params)
"Handler with PARAMS data for java doc hover."
(with-lsp-workspace (lsp-find-workspace 'jdtls nil)
(lsp-request "workspace/executeCommand"
(list :command "sts.java.addClasspathListener"
:arguments (gethash "callbackCommandId" params))
:no-wait t)))
(defun lsp-java-boot--sts-add-classpath-listener (_workspace params)
"Add classpath listener for WORKSPACE with PARAMS data."
(ignore
(with-lsp-workspace (lsp-find-workspace 'jdtls nil)
(lsp-request "workspace/executeCommand"
(list :command "sts.java.addClasspathListener"
:arguments (gethash "callbackCommandId" params))
:no-wait t))))
(defun lsp-java-boot--lens-backend (_ callback)
"Boot backend.
Store CALLBACK to use it `sts/highlight'."
(setq-local lsp-java-boot--callback callback))
;;;###autoload
(define-minor-mode lsp-java-boot-lens-mode
"Toggle code-lens overlays."
:group 'lsp-java-boot
:global nil
:init-value nil
:lighter "BLens"
(cond
(lsp-java-boot-lens-mode
(setq-local lsp-lens-backends (cl-pushnew 'lsp-java-boot--lens-backend lsp-lens-backends))
(lsp-lens-refresh t))
(t (setq-local lsp-lens-backends (delete 'lsp-java-boot--lens-backend lsp-lens-backends))
(setq-local lsp-java-boot--callback nil))))
(cl-defmethod lsp-execute-command
(_server (_command (eql sts.open.url)) params)
"Execute open url command from PARAMS data."
(browse-url (lsp-seq-first params)))
(cl-defmethod lsp-execute-command
(_server (_command (eql sts.showHoverAtPosition)) params)
"Execute show hover at position command with PARAMS data."
(goto-char (lsp--position-to-point (lsp-seq-first params)))
(lsp-describe-thing-at-point))
(defun lsp-java-boot--sts-hightlight (workspace params)
"WORKSPACE PARAMS."
(with-lsp-workspace workspace
(-let (((&hash "doc" (&hash "uri" "version") "codeLenses" code-lenses) params))
(when-let (buf (find-buffer-visiting (lsp--uri-to-path uri)))
(with-current-buffer buf
(when (and lsp-java-boot--callback lsp-java-boot-lens-mode)
(funcall lsp-java-boot--callback code-lenses version)))))))
(defun lsp-java-boot--server-jar ()
"Return the spring boot jar."
(or (-> lsp-java-server-install-dir
(expand-file-name)
(f-join "boot-server")
f-files
cl-first)
(lsp-log "Unable to find spring boot server jar.")))
(defun lsp-java-boot--ls-command (port)
"Create LS command for PORT."
(-filter 'identity
(list lsp-java-java-path
(unless (lsp-java--java-9-plus-p)
(format "-Dloader.path=%s" (lsp-java-boot--find-tools-jar)))
(format "-Dspring.lsp.client-port=%s" port)
(format "-Dserver.port=%s" port)
;; "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=1044,quiet=y"
"-Dsts.lsp.client=vscode"
(concat "-Dsts.log.file=" (make-temp-file "sts-log-file" nil ".log"))
(concat "-Dlogging.file=" (make-temp-file "logging-file" nil ".log"))
"-jar"
(lsp-java-boot--server-jar))))
(lsp-register-client
(make-lsp-client :new-connection
(lsp-tcp-server #'lsp-java-boot--ls-command)
:activation-fn (lambda (_filename mode)
(and lsp-java-boot-enabled
(memq mode '(java-mode conf-javaprop-mode yaml-mode))
(lsp-java-boot--server-jar)))
:request-handlers (ht ("sts/addClasspathListener" #'lsp-java-boot--sts-add-classpath-listener)
("sts/javadocHoverLink" #'lsp-java-boot--sts-javadoc-hover-link))
:notification-handlers (ht ("sts/highlight" #'lsp-java-boot--sts-hightlight)
("sts/progress" #'ignore))
:initialized-fn (lambda (workspace)
(puthash
"triggerCharacters"
'("." "@" "#" "*")
(gethash "completionProvider" (lsp--workspace-server-capabilities workspace))))
:multi-root t
:add-on? t
:server-id 'boot-ls
:completion-in-comments? t))
(provide 'lsp-java-boot)
;;; lsp-java-boot.el ends here
This diff is collapsed.
This diff is collapsed.
site_name: LSP Java
site_url: https://emacs-lsp.github.io/lsp-java
nav:
- Home: README.md
- LSP Mode:
- LSP Mode: https://emacs-lsp.github.io/lsp-mode
extra_css:
- stylesheets/extra.css
theme:
name: material
logo: images/logo.png
favicon: images/logo.png
icon:
repo: fontawesome/brands/github
features:
- tabs
extra:
social:
- icon: fontawesome/brands/github-alt
link: https://github.com/emacs-lsp
- icon: fontawesome/brands/twitter
link: https://twitter.com/yonchovski
- icon: fontawesome/brands/gitter
link: https://gitter.im/emacs-lsp/lsp-mode
repo_name: emacs-lsp/lsp-java
repo_url: https://github.com/emacs-lsp/lsp-java
markdown_extensions:
- pymdownx.superfences
- pymdownx.emoji:
emoji_index: !!python/name:materialx.emoji.twemoji
emoji_generator: !!python/name:materialx.emoji.to_svg
- codehilite
- toc:
permalink: '#'
plugins:
- search
- awesome-pages
- git-revision-date-localized
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment