From 01bc27b6f2808998e8602f841e2ef0802e06d5ae Mon Sep 17 00:00:00 2001 From: Pavel Mitrafanau Date: Wed, 1 Apr 2020 16:47:26 +0300 Subject: [PATCH] Add experimental support for Bazel (eclipse#543) Signed-off-by: Pavel Mitrafanau --- org.eclipse.jdt.ls.core/META-INF/MANIFEST.MF | 3 +- org.eclipse.jdt.ls.core/plugin.xml | 6 +- .../managers/BazelProjectImporter.java | 69 +++++++++++++++++++ .../internal/preferences/Preferences.java | 66 ++++++++++++++++++ .../org.eclipse.jdt.ls.tp.target | 6 +- 5 files changed, 147 insertions(+), 3 deletions(-) create mode 100644 org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/BazelProjectImporter.java diff --git a/org.eclipse.jdt.ls.core/META-INF/MANIFEST.MF b/org.eclipse.jdt.ls.core/META-INF/MANIFEST.MF index a2bef4a0a2..bd58adcada 100644 --- a/org.eclipse.jdt.ls.core/META-INF/MANIFEST.MF +++ b/org.eclipse.jdt.ls.core/META-INF/MANIFEST.MF @@ -31,7 +31,8 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="3.12.0", org.eclipse.xtext.xbase.lib, org.eclipse.core.filesystem;bundle-version="1.7.0", org.eclipse.jdt.apt.pluggable.core;bundle-version="1.2.0";resolution:=optional, - org.jboss.tools.maven.apt.core;bundle-version="1.3.0";resolution:=optional + org.jboss.tools.maven.apt.core;bundle-version="1.3.0";resolution:=optional, + com.salesforce.b2eclipse.jdt.ls;bundle-version="0.1.0" Export-Package: org.eclipse.jdt.ls.core.internal;x-friends:="org.eclipse.jdt.ls.tests,org.eclipse.jdt.ls.tests.syntaxserver", org.eclipse.jdt.ls.core.internal.codemanipulation;x-friends:="org.eclipse.jdt.ls.tests", org.eclipse.jdt.ls.core.internal.commands;x-friends:="org.eclipse.jdt.ls.tests", diff --git a/org.eclipse.jdt.ls.core/plugin.xml b/org.eclipse.jdt.ls.core/plugin.xml index cde6fadb5d..854cc0700d 100644 --- a/org.eclipse.jdt.ls.core/plugin.xml +++ b/org.eclipse.jdt.ls.core/plugin.xml @@ -89,11 +89,15 @@ + class = "org.eclipse.jdt.ls.core.internal.managers.GradleProjectImporter"/> + bazelPackagesToImport = workspaceRootPackage.getChildPackageInfos().stream() + .collect(Collectors.toList()); + + WorkProgressMonitor progressMonitor = new EclipseWorkProgressMonitor(null); + + BazelEclipseProjectFactory.setImportBazelSRCPath( + JavaLanguageServerPlugin.getPreferencesManager().getPreferences().getImportBazelSrcPath()); + BazelEclipseProjectFactory.setImportBazelTestPath( + JavaLanguageServerPlugin.getPreferencesManager().getPreferences().getImportBazelTestPath()); + + BazelEclipseProjectFactory.importWorkspace(workspaceRootPackage, bazelPackagesToImport, progressMonitor, + monitor); + } + + @Override + public void reset() { + + } + +} diff --git a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/preferences/Preferences.java b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/preferences/Preferences.java index 6bac113b92..5862f0f583 100644 --- a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/preferences/Preferences.java +++ b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/preferences/Preferences.java @@ -208,6 +208,31 @@ public class Preferences { */ public static final String SELECTIONRANGE_ENABLED_KEY = "java.selectionRange.enabled"; + /** + * Preference key to enable/disable bazel importer. + */ + public static final String IMPORT_BAZEL_ENABLED = "java.import.bazel.enabled"; + + /** + * Preference key to change java classes src path for bazel importer. + */ + public static final String BAZEL_SRC_PATH = "java.import.bazel.src.path"; + + /** + * Preference key to change java classes test path for bazel importer. + */ + public static final String BAZEL_TEST_PATH = "java.import.bazel.test.path"; + + /** + * Default java class src path for bazel importer. + */ + public static final String BAZEL_DEFAULT_SRC_PATH = "/src/main/java"; + + /** + * Default java class test path for bazel importer. + */ + public static final String BAZEL_DEFAULT_TEST_PATH = "/src/test/java"; + /** * A named preference that holds the favorite static members. *

@@ -383,6 +408,9 @@ public class Preferences { private boolean generateToStringListArrayContents; private int generateToStringLimitElements; private List preferredContentProviderIds; + private boolean importBazelEnabled; + private String importBazelSrcPath; + private String importBazelTestPath; private String mavenUserSettings; @@ -566,6 +594,10 @@ public Preferences() { parallelBuildsCount = PreferenceInitializer.PREF_MAX_CONCURRENT_BUILDS_DEFAULT; maxCompletionResults = JAVA_COMPLETION_MAX_RESULTS_DEFAULT; referencedLibraries = JAVA_PROJECT_REFERENCED_LIBRARIES_DEFAULT; + importBazelEnabled = false; + importBazelSrcPath = BAZEL_DEFAULT_SRC_PATH; + importBazelTestPath = BAZEL_DEFAULT_TEST_PATH; + } /** @@ -613,6 +645,13 @@ public static Preferences createFrom(Map configuration) { boolean implementationCodeLensEnabled = getBoolean(configuration, IMPLEMENTATIONS_CODE_LENS_ENABLED_KEY, false); prefs.setImplementationCodelensEnabled(implementationCodeLensEnabled); + boolean importBazelEnabled = getBoolean(configuration, IMPORT_BAZEL_ENABLED, false); + prefs.setImportBazelEnabled(importBazelEnabled); + String importBazelSrcPath = getString(configuration, BAZEL_SRC_PATH, BAZEL_DEFAULT_SRC_PATH); + prefs.setImportBazelSrcPath(importBazelSrcPath); + String importBazelTestPath = getString(configuration, BAZEL_TEST_PATH, BAZEL_DEFAULT_TEST_PATH); + prefs.setImportBazelTestPath(importBazelTestPath); + boolean javaFormatEnabled = getBoolean(configuration, JAVA_FORMAT_ENABLED_KEY, true); prefs.setJavaFormatEnabled(javaFormatEnabled); @@ -896,6 +935,11 @@ public Preferences setImportMavenEnabled(boolean enabled) { return this; } + public Preferences setImportBazelEnabled(boolean enabled) { + this.importBazelEnabled = enabled; + return this; + } + public Preferences setMavenDownloadSources(boolean enabled) { this.mavenDownloadSources = enabled; return this; @@ -1041,6 +1085,24 @@ public Preferences setMaxBuildCount(int maxConcurrentBuilds) { return this; } + public Preferences setImportBazelSrcPath(String importBazelSrcPath) { + this.importBazelSrcPath = importBazelSrcPath; + return this; + } + + public Preferences setImportBazelTestPath(String importBazelTestPath) { + this.importBazelTestPath = importBazelTestPath; + return this; + } + + public String getImportBazelSrcPath() { + return importBazelSrcPath; + } + + public String getImportBazelTestPath() { + return importBazelTestPath; + } + public Severity getIncompleteClasspathSeverity() { return incompleteClasspathSeverity; } @@ -1113,6 +1175,10 @@ public boolean isImportMavenEnabled() { return importMavenEnabled; } + public boolean isImportBazelEnabled() { + return importBazelEnabled; + } + public boolean isMavenDownloadSources() { return mavenDownloadSources; } diff --git a/org.eclipse.jdt.ls.target/org.eclipse.jdt.ls.tp.target b/org.eclipse.jdt.ls.target/org.eclipse.jdt.ls.tp.target index fad13d0dc6..e28f92a941 100644 --- a/org.eclipse.jdt.ls.target/org.eclipse.jdt.ls.tp.target +++ b/org.eclipse.jdt.ls.target/org.eclipse.jdt.ls.tp.target @@ -45,10 +45,14 @@ + + + + - \ No newline at end of file +