diff --git a/.gitignore b/.gitignore index 663d475d..111013ba 100644 --- a/.gitignore +++ b/.gitignore @@ -57,6 +57,10 @@ typings/ # dotenv environment variables file .env +# java compiled output +target/ +server/*.jar + out/ .DS_Store diff --git a/.vscode/launch.json b/.vscode/launch.json index 4930ffe4..1bfbd23e 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -18,6 +18,13 @@ ], "preLaunchTask": "npm: watch" }, + { + "type": "java", + "name": "Attach to Plugin", + "request": "attach", + "hostName": "localhost", + "port": 1044 + }, { "name": "Extension Tests", "type": "extensionHost", diff --git a/jdtls.ext/.mvn/wrapper/maven-wrapper.jar b/jdtls.ext/.mvn/wrapper/maven-wrapper.jar new file mode 100644 index 00000000..41c70a7e Binary files /dev/null and b/jdtls.ext/.mvn/wrapper/maven-wrapper.jar differ diff --git a/jdtls.ext/.mvn/wrapper/maven-wrapper.properties b/jdtls.ext/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 00000000..56bb0164 --- /dev/null +++ b/jdtls.ext/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1 @@ +distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip \ No newline at end of file diff --git a/jdtls.ext/com.microsoft.jdtls.daemon.core/.classpath b/jdtls.ext/com.microsoft.jdtls.daemon.core/.classpath new file mode 100644 index 00000000..bc57d238 --- /dev/null +++ b/jdtls.ext/com.microsoft.jdtls.daemon.core/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/jdtls.ext/com.microsoft.jdtls.daemon.core/.project b/jdtls.ext/com.microsoft.jdtls.daemon.core/.project new file mode 100644 index 00000000..e98018e5 --- /dev/null +++ b/jdtls.ext/com.microsoft.jdtls.daemon.core/.project @@ -0,0 +1,45 @@ + + + com.microsoft.jdtls.daemon.core + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1665551209562 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/jdtls.ext/com.microsoft.jdtls.daemon.core/.settings/org.eclipse.core.resources.prefs b/jdtls.ext/com.microsoft.jdtls.daemon.core/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 00000000..99f26c02 --- /dev/null +++ b/jdtls.ext/com.microsoft.jdtls.daemon.core/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/jdtls.ext/com.microsoft.jdtls.daemon.core/.settings/org.eclipse.jdt.core.prefs b/jdtls.ext/com.microsoft.jdtls.daemon.core/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000..3a85c5a5 --- /dev/null +++ b/jdtls.ext/com.microsoft.jdtls.daemon.core/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=11 +org.eclipse.jdt.core.compiler.compliance=11 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.release=disabled +org.eclipse.jdt.core.compiler.source=11 diff --git a/jdtls.ext/com.microsoft.jdtls.daemon.core/.settings/org.eclipse.m2e.core.prefs b/jdtls.ext/com.microsoft.jdtls.daemon.core/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 00000000..f897a7f1 --- /dev/null +++ b/jdtls.ext/com.microsoft.jdtls.daemon.core/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/jdtls.ext/com.microsoft.jdtls.daemon.core/META-INF/MANIFEST.MF b/jdtls.ext/com.microsoft.jdtls.daemon.core/META-INF/MANIFEST.MF new file mode 100644 index 00000000..6754ef95 --- /dev/null +++ b/jdtls.ext/com.microsoft.jdtls.daemon.core/META-INF/MANIFEST.MF @@ -0,0 +1,11 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: JDTLS Daemon Core +Bundle-SymbolicName: com.microsoft.jdtls.daemon.core;singleton:=true +Bundle-Version: 0.1.0 +Bundle-Activator: com.microsoft.jdtls.daemon.core.Activator +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Import-Package: org.osgi.framework;version="1.3.0" +Require-Bundle: org.eclipse.core.runtime, + org.eclipse.jdt.ls.core +Bundle-ClassPath: . diff --git a/jdtls.ext/com.microsoft.jdtls.daemon.core/build.properties b/jdtls.ext/com.microsoft.jdtls.daemon.core/build.properties new file mode 100644 index 00000000..e9863e28 --- /dev/null +++ b/jdtls.ext/com.microsoft.jdtls.daemon.core/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/jdtls.ext/com.microsoft.jdtls.daemon.core/plugin.xml b/jdtls.ext/com.microsoft.jdtls.daemon.core/plugin.xml new file mode 100644 index 00000000..f422d55d --- /dev/null +++ b/jdtls.ext/com.microsoft.jdtls.daemon.core/plugin.xml @@ -0,0 +1,4 @@ + + + + diff --git a/jdtls.ext/com.microsoft.jdtls.daemon.core/pom.xml b/jdtls.ext/com.microsoft.jdtls.daemon.core/pom.xml new file mode 100644 index 00000000..59204a21 --- /dev/null +++ b/jdtls.ext/com.microsoft.jdtls.daemon.core/pom.xml @@ -0,0 +1,15 @@ + + + 4.0.0 + + com.microsoft.jdtls.daemon + jdtls-daemon-parent + 0.1.0 + + com.microsoft.jdtls.daemon.core + eclipse-plugin + ${base.name} :: JDTLS Daemon Plugin + + + diff --git a/jdtls.ext/com.microsoft.jdtls.daemon.core/src/com/microsoft/jdtls/daemon/core/Activator.java b/jdtls.ext/com.microsoft.jdtls.daemon.core/src/com/microsoft/jdtls/daemon/core/Activator.java new file mode 100644 index 00000000..2899c171 --- /dev/null +++ b/jdtls.ext/com.microsoft.jdtls.daemon.core/src/com/microsoft/jdtls/daemon/core/Activator.java @@ -0,0 +1,81 @@ +/******************************************************************************* + * Copyright (c) 2023 Microsoft Corporation and others. + * 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: + * Microsoft Corporation - initial API and implementation + *******************************************************************************/ +package com.microsoft.jdtls.daemon.core; + +import java.lang.management.GarbageCollectorMXBean; +import java.lang.management.ManagementFactory; +import java.util.List; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; + +import org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin; +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; + +import com.sun.management.OperatingSystemMXBean; + +import com.microsoft.jdtls.daemon.core.model.JvmReport; + +public class Activator implements BundleActivator { + + long startTime; + + private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); + + @Override + public void start(BundleContext bundleContext) throws Exception { + startTime = System.nanoTime(); + final Runnable gcSampling = new GcSampling(); + scheduler.scheduleAtFixedRate(gcSampling, 1, 1, TimeUnit.MINUTES); + } + + @Override + public void stop(BundleContext bundleContext) throws Exception { + scheduler.shutdownNow(); + } + + private final class GcSampling implements Runnable { + private long lastGcTime = 0; + private long lastCpuTime = 0; + + @Override + public void run() { + List gcBeans = ManagementFactory.getGarbageCollectorMXBeans(); + long totalGcTime = gcBeans.stream().collect(Collectors.summingLong(GarbageCollectorMXBean::getCollectionTime)); + long gcTime = totalGcTime - lastGcTime; + lastGcTime = totalGcTime; + + OperatingSystemMXBean osBean = ManagementFactory.getPlatformMXBean( + OperatingSystemMXBean.class); + + // get cpu time for process. + long totalCpuTime = osBean.getProcessCpuTime(); + long cpuTime; + if (totalCpuTime < 0) { + cpuTime = -1; + } else { + cpuTime = totalCpuTime - lastCpuTime; + lastCpuTime = totalCpuTime; + } + cpuTime = TimeUnit.NANOSECONDS.toMillis(cpuTime); + + // get swap load + double swapSize = (double) osBean.getTotalSwapSpaceSize(); + int swapLoad = (int) (swapSize > 0 ? (1 - osBean.getFreeSwapSpaceSize() / swapSize) * 100 : 0); + + JvmReport report = new JvmReport(gcTime, cpuTime, swapLoad); + JavaLanguageServerPlugin.getInstance() + .getClientConnection().executeClientCommand("_jdtls.daemon.jvmReport", report); + } + } +} \ No newline at end of file diff --git a/jdtls.ext/com.microsoft.jdtls.daemon.core/src/com/microsoft/jdtls/daemon/core/model/JvmReport.java b/jdtls.ext/com.microsoft.jdtls.daemon.core/src/com/microsoft/jdtls/daemon/core/model/JvmReport.java new file mode 100644 index 00000000..a4bbf8fa --- /dev/null +++ b/jdtls.ext/com.microsoft.jdtls.daemon.core/src/com/microsoft/jdtls/daemon/core/model/JvmReport.java @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (c) 2023 Microsoft Corporation and others. + * 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: + * Microsoft Corporation - initial API and implementation + *******************************************************************************/ +package com.microsoft.jdtls.daemon.core.model; + +/** + * Basic statistics about JVM status. + */ +public class JvmReport { + /** + * Milliseconds used for GC in one time window. + */ + private long gcTime; + + /** + * Milliseconds used for the process CPU time in one time window. + */ + private long cpuTime; + /** + * Swap load + */ + private int swapLoad; + + public JvmReport(long gcTime, long cpuTime, int swapLoad) { + this.gcTime = gcTime; + this.cpuTime = cpuTime; + this.swapLoad = swapLoad; + } + + public long getGcTime() { + return gcTime; + } + + public void setGcTime(long gcTime) { + this.gcTime = gcTime; + } + + public long getCpuTime() { + return cpuTime; + } + + public void setCpuTime(long cpuTime) { + this.cpuTime = cpuTime; + } + + public int getSwapLoad() { + return swapLoad; + } + + public void setSwapLoad(int swapLoad) { + this.swapLoad = swapLoad; + } + + @Override + public String toString() { + return "JvmReport [thisGcTime=" + gcTime + ", thisCpuTime=" + cpuTime + ", swapLoad=" + swapLoad + "]"; + } +} diff --git a/jdtls.ext/com.microsoft.jdtls.daemon.target/com.microsoft.jdtls.daemon.tp.target b/jdtls.ext/com.microsoft.jdtls.daemon.target/com.microsoft.jdtls.daemon.tp.target new file mode 100644 index 00000000..ad9d88b6 --- /dev/null +++ b/jdtls.ext/com.microsoft.jdtls.daemon.target/com.microsoft.jdtls.daemon.tp.target @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/jdtls.ext/com.microsoft.jdtls.daemon.target/pom.xml b/jdtls.ext/com.microsoft.jdtls.daemon.target/pom.xml new file mode 100644 index 00000000..27fcfacd --- /dev/null +++ b/jdtls.ext/com.microsoft.jdtls.daemon.target/pom.xml @@ -0,0 +1,12 @@ + + 4.0.0 + + com.microsoft.jdtls.daemon + jdtls-daemon-parent + 0.1.0 + + com.microsoft.jdtls.daemon.tp + ${base.name} :: Target Platform + eclipse-target-definition + diff --git a/jdtls.ext/mvnw b/jdtls.ext/mvnw new file mode 100644 index 00000000..e96ccd5f --- /dev/null +++ b/jdtls.ext/mvnw @@ -0,0 +1,227 @@ +#!/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 + +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 "$@" diff --git a/jdtls.ext/mvnw.cmd b/jdtls.ext/mvnw.cmd new file mode 100644 index 00000000..019bd74d --- /dev/null +++ b/jdtls.ext/mvnw.cmd @@ -0,0 +1,143 @@ +@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 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 + +%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% diff --git a/jdtls.ext/pom.xml b/jdtls.ext/pom.xml new file mode 100644 index 00000000..a9db28e9 --- /dev/null +++ b/jdtls.ext/pom.xml @@ -0,0 +1,101 @@ + + 4.0.0 + com.microsoft.jdtls.daemon + jdtls-daemon-parent + ${base.name} :: Parent + 0.1.0 + pom + + JDT.LS Daemon + UTF-8 + 2.7.2 + ${basedir} + + + + com.microsoft.jdtls.daemon.core + com.microsoft.jdtls.daemon.target + + + + + + org.apache.maven.plugins + maven-failsafe-plugin + 2.15 + + + + integration-tests + + integration-test + verify + + + + ${failsafeArgLine} + + ${skip.integration.tests} + + + + + + org.eclipse.tycho + target-platform-configuration + ${tycho-version} + + p2 + + + com.microsoft.jdtls.daemon + com.microsoft.jdtls.daemon.tp + ${project.version} + + + + + linux + gtk + x86_64 + + + win32 + win32 + x86_64 + + + macosx + cocoa + x86_64 + + + + + + + + + + + org.eclipse.tycho + tycho-maven-plugin + ${tycho-version} + true + + + + + + oss.sonatype.org + https://oss.sonatype.org/content/repositories/snapshots/ + + true + + + + diff --git a/package.json b/package.json index 2cf6fa06..a538661c 100644 --- a/package.json +++ b/package.json @@ -71,6 +71,9 @@ "onWalkthrough:javaWelcome" ], "contributes": { + "javaExtensions": [ + "./server/com.microsoft.jdtls.daemon.core-0.1.0.jar" + ], "walkthroughs": [ { "id": "javaWelcome", @@ -314,7 +317,8 @@ "compile": "webpack --config webpack.config.js", "watch": "webpack --config webpack.config.js --watch", "build": "webpack --config webpack.config.js --mode=\"production\"", - "update-tpn": "node scripts/update-third-party-notice.js" + "update-tpn": "node scripts/update-third-party-notice.js", + "build-server": "node scripts/buildBundle.js" }, "devDependencies": { "@types/bytes": "^3.1.1", diff --git a/scripts/buildBundle.js b/scripts/buildBundle.js new file mode 100644 index 00000000..60c4200e --- /dev/null +++ b/scripts/buildBundle.js @@ -0,0 +1,29 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. + +const cp = require('child_process'); +const fse = require('fs-extra'); +const path = require('path'); + +const server_dir = path.resolve('jdtls.ext'); + +cp.execSync(mvnw()+ ' clean package', {cwd:server_dir, stdio:[0,1,2]} ); +copy(path.join(server_dir, 'com.microsoft.jdtls.daemon.core/target'), path.resolve('server'), (file) => { + return /^com.microsoft.jdtls.daemon.core.*.jar$/.test(file); +}); + +function copy(sourceFolder, targetFolder, fileFilter) { + const jars = fse.readdirSync(sourceFolder).filter(file => fileFilter(file)); + fse.ensureDirSync(targetFolder); + for (const jar of jars) { + fse.copyFileSync(path.join(sourceFolder, jar), path.join(targetFolder, path.basename(jar))); + } +} + +function isWin() { + return /^win/.test(process.platform); +} + +function mvnw() { + return isWin()?"mvnw.cmd":"./mvnw"; +} \ No newline at end of file diff --git a/src/commands/index.ts b/src/commands/index.ts index 04ec75c0..fe5799a0 100644 --- a/src/commands/index.ts +++ b/src/commands/index.ts @@ -13,6 +13,7 @@ import { overviewCmdHandler } from "../overview"; import { webviewCmdLinkHandler } from "../utils"; import { showWelcomeWebview, showWelcomeWebviewBeside } from "../welcome"; import { createMavenProjectCmdHandler, createMicroProfileStarterProjectCmdHandler, createQuarkusProjectCmdHandler, createSpringBootProjectCmdHandler, installExtensionCmdHandler, openUrlCmdHandler, showExtensionCmdHandler, showReleaseNotesHandler, toggleAwtDevelopmentHandler } from "./handler"; +import { sendJvmReport } from "../daemon"; export function initialize(context: vscode.ExtensionContext) { registerCommandHandler(context, "java.overview", overviewCmdHandler); @@ -36,6 +37,7 @@ export function initialize(context: vscode.ExtensionContext) { registerCommandHandler(context, "java.installJdk", showInstallJdkWebviewBeside); registerCommandHandler(context, "java.installJdk.fromWalkthrough", showInstallJdkWebview); registerCommandHandler(context, "java.toggleAwtDevelopment", toggleAwtDevelopmentHandler); + vscode.commands.registerCommand("_jdtls.daemon.jvmReport", sendJvmReport); } type CommandHandler = (context: vscode.ExtensionContext, operationId: string, ...args: any[]) => any; diff --git a/src/daemon/index.ts b/src/daemon/index.ts index 1a8bcaf1..c846f20a 100644 --- a/src/daemon/index.ts +++ b/src/daemon/index.ts @@ -196,3 +196,10 @@ function resolveActualCause(callstack: any): string | undefined { return; } + +export function sendJvmReport(report: any) { + sendInfo("", { + name: "jvmReport", + ...report, + }); +}