diff --git a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/AbstractProjectImporter.java b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/AbstractProjectImporter.java index 4fa7f59fd3..b10c6fe24c 100644 --- a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/AbstractProjectImporter.java +++ b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/AbstractProjectImporter.java @@ -13,15 +13,18 @@ package org.eclipse.jdt.ls.core.internal; import java.io.File; +import java.util.Collection; import java.util.Objects; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.OperationCanceledException; +import org.eclipse.jdt.ls.core.internal.preferences.Preferences; public abstract class AbstractProjectImporter implements IProjectImporter { protected File rootFolder; + protected Collection directories; @Override public void initialize(File rootFolder) { @@ -34,10 +37,19 @@ public void initialize(File rootFolder) { @Override public abstract boolean applies(IProgressMonitor monitor) throws OperationCanceledException, CoreException; + @Override + public boolean isResolved(File folder) throws OperationCanceledException, CoreException { + return directories != null && directories.contains(folder.toPath()); + }; + @Override public abstract void importToWorkspace(IProgressMonitor monitor) throws OperationCanceledException, CoreException; @Override public abstract void reset(); + protected static Preferences getPreferences() { + return (JavaLanguageServerPlugin.getPreferencesManager() == null || JavaLanguageServerPlugin.getPreferencesManager().getPreferences() == null) ? new Preferences() : JavaLanguageServerPlugin.getPreferencesManager().getPreferences(); + } + } diff --git a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/IProjectImporter.java b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/IProjectImporter.java index 6ce57bdde6..ce80cef6ff 100644 --- a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/IProjectImporter.java +++ b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/IProjectImporter.java @@ -24,6 +24,10 @@ public interface IProjectImporter { boolean applies(IProgressMonitor monitor) throws OperationCanceledException, CoreException; + default boolean isResolved(File folder) throws OperationCanceledException, CoreException { + return false; + }; + void importToWorkspace(IProgressMonitor monitor) throws OperationCanceledException, CoreException; void reset(); diff --git a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/ProjectUtils.java b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/ProjectUtils.java index 21dbd11e25..88ffbfcf28 100644 --- a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/ProjectUtils.java +++ b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/ProjectUtils.java @@ -119,6 +119,15 @@ public static IProject[] getAllProjects() { return ResourcesPlugin.getWorkspace().getRoot().getProjects(); } + public static IProject[] getAllProjects(boolean includeInvisibleProjects) { + IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects(); + if (includeInvisibleProjects) { + return projects; + } else { + return Stream.of(projects).filter(p -> isVisibleProject(p)).collect(Collectors.toList()).toArray(new IProject[0]); + } + } + public static IProject getProject(String projectName) { if (StringUtils.isBlank(projectName)) { return null; diff --git a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/BasicFileDetector.java b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/BasicFileDetector.java index 7320a31ab6..d076e4b843 100644 --- a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/BasicFileDetector.java +++ b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/BasicFileDetector.java @@ -139,7 +139,7 @@ public Collection scan(IProgressMonitor monitor) throws CoreException { } private void scanDir(Path dir, final IProgressMonitor monitor) throws IOException { - FileVisitor visitor = new SimpleFileVisitor() { + FileVisitor visitor = new SimpleFileVisitor<>() { @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { if (monitor.isCanceled()) { diff --git a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/EclipseProjectImporter.java b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/EclipseProjectImporter.java index a8666e5f33..f2d315510e 100644 --- a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/EclipseProjectImporter.java +++ b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/EclipseProjectImporter.java @@ -33,16 +33,19 @@ import org.eclipse.jdt.core.JavaCore; import org.eclipse.jdt.ls.core.internal.AbstractProjectImporter; import org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin; +import org.eclipse.jdt.ls.core.internal.ProjectUtils; public class EclipseProjectImporter extends AbstractProjectImporter { - private Collection directories; - @Override public boolean applies(IProgressMonitor monitor) throws CoreException { if (directories == null) { BasicFileDetector eclipseDetector = new BasicFileDetector(rootFolder.toPath(), DESCRIPTION_FILE_NAME) .addExclusions("**/bin");//default Eclipse build dir + for (IProject project : ProjectUtils.getAllProjects(false)) { + File projectFile = project.getLocation().toFile(); + eclipseDetector.addExclusions(projectFile.getAbsolutePath()); + } directories = eclipseDetector.scan(monitor); } directories = directories.stream().filter(path -> (new File(path.toFile(), IJavaProject.CLASSPATH_FILE_NAME).exists())).collect(Collectors.toList()); diff --git a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/GradleProjectImporter.java b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/GradleProjectImporter.java index bd00247ec2..3af027b37f 100644 --- a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/GradleProjectImporter.java +++ b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/GradleProjectImporter.java @@ -18,7 +18,6 @@ import java.io.FilenameFilter; import java.nio.file.Files; import java.nio.file.Path; -import java.util.Collection; import java.util.List; import java.util.Map; import java.util.Properties; @@ -79,8 +78,6 @@ public class GradleProjectImporter extends AbstractProjectImporter { .replaceAll("\n", System.lineSeparator()); //@formatter:on - private Collection directories; - /* (non-Javadoc) * @see org.eclipse.jdt.ls.core.internal.managers.IProjectImporter#applies(org.eclipse.core.runtime.IProgressMonitor) */ @@ -98,6 +95,12 @@ public boolean applies(IProgressMonitor monitor) throws CoreException { .includeNested(false) .addExclusions("**/build")//default gradle build dir .addExclusions("**/bin"); + for (IProject project : ProjectUtils.getAllProjects()) { + if (!ProjectUtils.isGradleProject(project)) { + String path = project.getLocation().toOSString(); + gradleDetector.addExclusions(path); + } + } directories = gradleDetector.scan(monitor); } return !directories.isEmpty(); @@ -322,8 +325,4 @@ public boolean accept(File dir, String name) { public void reset() { } - private static Preferences getPreferences() { - return (JavaLanguageServerPlugin.getPreferencesManager() == null || JavaLanguageServerPlugin.getPreferencesManager().getPreferences() == null) ? new Preferences() : JavaLanguageServerPlugin.getPreferencesManager().getPreferences(); - } - } diff --git a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/InvisibleProjectImporter.java b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/InvisibleProjectImporter.java index 24d23b4752..e6b4624269 100644 --- a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/InvisibleProjectImporter.java +++ b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/InvisibleProjectImporter.java @@ -250,4 +250,5 @@ public static IPath tryResolveSourceDirectory(IPath javaFile, IPath rootPath, St String packageName = getPackageName(javaFile, rootPath, potentialSrcPrefixes); return inferSourceDirectory(javaFile.toFile().toPath(), packageName); } + } diff --git a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/MavenProjectImporter.java b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/MavenProjectImporter.java index f32a32c23f..580925073b 100644 --- a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/MavenProjectImporter.java +++ b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/MavenProjectImporter.java @@ -84,6 +84,7 @@ public boolean applies(IProgressMonitor monitor) throws OperationCanceledExcepti return false; } Set files = getMavenProjectInfo(monitor); + directories = new ArrayList<>(); if (files != null) { Iterator iter = files.iterator(); while (iter.hasNext()) { @@ -91,6 +92,10 @@ public boolean applies(IProgressMonitor monitor) throws OperationCanceledExcepti File dir = projectInfo.getPomFile() == null ? null : projectInfo.getPomFile().getParentFile(); if (dir != null && exclude(dir.toPath())) { iter.remove(); + continue; + } + if (dir != null) { + directories.add(dir.toPath()); } } } @@ -113,6 +118,19 @@ private boolean exclude(java.nio.file.Path path) { } } } + if (!excluded) { + for (IProject project : ProjectUtils.getAllProjects()) { + if (ProjectUtils.isMavenProject(project)) { + continue; + } + String pattern = project.getLocation().toOSString(); + PathMatcher matcher = FileSystems.getDefault().getPathMatcher("glob:" + pattern); + if (matcher.matches(path)) { + excluded = true; + break; + } + } + } return excluded; } diff --git a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/ProjectsManager.java b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/ProjectsManager.java index 5cd819519b..8a68804817 100644 --- a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/ProjectsManager.java +++ b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/ProjectsManager.java @@ -109,9 +109,14 @@ protected void importProjects(Collection rootPaths, IProgressMonitor moni SubMonitor subMonitor = SubMonitor.convert(monitor, rootPaths.size() * 100); for (IPath rootPath : rootPaths) { File rootFolder = rootPath.toFile(); - IProjectImporter importer = getImporter(rootFolder, subMonitor.split(30)); - if (importer != null) { - importer.importToWorkspace(subMonitor.split(70)); + for (IProjectImporter importer : importers()) { + importer.initialize(rootFolder); + if (importer.applies(subMonitor.split(1))) { + importer.importToWorkspace(subMonitor.split(70)); + if (importer.isResolved(rootFolder)) { + break; + } + } } } } @@ -266,23 +271,11 @@ public boolean isBuildLikeFileName(String fileName) { return buildSupports().filter(bs -> bs.isBuildLikeFileName(fileName)).findAny().isPresent(); } - private IProjectImporter getImporter(File rootFolder, IProgressMonitor monitor) throws OperationCanceledException, CoreException { - Collection importers = importers(); - SubMonitor subMonitor = SubMonitor.convert(monitor, importers.size()); - for (IProjectImporter importer : importers) { - importer.initialize(rootFolder); - if (importer.applies(subMonitor.split(1))) { - return importer; - } - } - return null; - } - public static IProject getDefaultProject() { return getWorkspaceRoot().getProject(DEFAULT_PROJECT_NAME); } - private Collection importers() { + public static Collection importers() { Map importers = new TreeMap<>(); IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(IConstants.PLUGIN_ID, "importers"); IConfigurationElement[] configs = extensionPoint.getConfigurationElements(); diff --git a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/StandardProjectsManager.java b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/StandardProjectsManager.java index 22954fec0b..414df8c294 100644 --- a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/StandardProjectsManager.java +++ b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/StandardProjectsManager.java @@ -315,7 +315,7 @@ public void registerWatchers(boolean runInJob) { @Override public List registerWatchers() { - logInfo(">> registerFeature 'workspace/didChangeWatchedFiles'"); + logInfo(">> registerWatchers'"); if (preferenceManager.getClientPreferences().isWorkspaceChangeWatchedFilesDynamicRegistered()) { Set patterns = new LinkedHashSet<>(basicWatchers); buildSupports().forEach(e -> e.getWatchPatterns().forEach(patterns::add)); diff --git a/org.eclipse.jdt.ls.tests/projects/maven/salut-java14/.project b/org.eclipse.jdt.ls.tests/projects/maven/salut-java14/.project index 37c559f03d..dd6a1a1b3c 100644 --- a/org.eclipse.jdt.ls.tests/projects/maven/salut-java14/.project +++ b/org.eclipse.jdt.ls.tests/projects/maven/salut-java14/.project @@ -1,6 +1,6 @@ - salut-java13 + salut-java14 diff --git a/org.eclipse.jdt.ls.tests/projects/mixed/hello/.classpath b/org.eclipse.jdt.ls.tests/projects/mixed/hello/.classpath new file mode 100644 index 0000000000..6073fcf912 --- /dev/null +++ b/org.eclipse.jdt.ls.tests/projects/mixed/hello/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/org.eclipse.jdt.ls.tests/projects/mixed/hello/.project b/org.eclipse.jdt.ls.tests/projects/mixed/hello/.project new file mode 100644 index 0000000000..6cf7b40efc --- /dev/null +++ b/org.eclipse.jdt.ls.tests/projects/mixed/hello/.project @@ -0,0 +1,17 @@ + + + hello + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/org.eclipse.jdt.ls.tests/projects/mixed/hello/src/.gitignore b/org.eclipse.jdt.ls.tests/projects/mixed/hello/src/.gitignore new file mode 100644 index 0000000000..e69de29bb2 diff --git a/org.eclipse.jdt.ls.tests/projects/mixed/salut/pom.xml b/org.eclipse.jdt.ls.tests/projects/mixed/salut/pom.xml new file mode 100644 index 0000000000..ff1324a920 --- /dev/null +++ b/org.eclipse.jdt.ls.tests/projects/mixed/salut/pom.xml @@ -0,0 +1,26 @@ + + 4.0.0 + foo.bar + salut + 0.0.1-SNAPSHOT + + + + maven-compiler-plugin + 3.5.1 + + 11 + 11 + + + + + + + org.apache.commons + commons-lang3 + 3.5 + + + \ No newline at end of file diff --git a/org.eclipse.jdt.ls.tests/projects/mixed/salut/src/main/java/org/sample/Bar.java b/org.eclipse.jdt.ls.tests/projects/mixed/salut/src/main/java/org/sample/Bar.java new file mode 100644 index 0000000000..d035c9fb2a --- /dev/null +++ b/org.eclipse.jdt.ls.tests/projects/mixed/salut/src/main/java/org/sample/Bar.java @@ -0,0 +1,28 @@ +package org.sample; + +/** + * This is Bar + */ +public class Bar { + + public static void main(String[] args) { + System.out.print( "Hello world! from "+Bar.class); + } + + public static interface MyInterface { + + void foo(); + } + + public static class MyClass { + + void bar() {} + } + + public static final String EMPTY = ""; + + + public enum Foo { + Bar, Zoo + } +} diff --git a/org.eclipse.jdt.ls.tests/projects/mixed/salut/src/main/resources/test.properties b/org.eclipse.jdt.ls.tests/projects/mixed/salut/src/main/resources/test.properties new file mode 100644 index 0000000000..e69de29bb2 diff --git a/org.eclipse.jdt.ls.tests/projects/mixed/simple-gradle/.project b/org.eclipse.jdt.ls.tests/projects/mixed/simple-gradle/.project new file mode 100644 index 0000000000..344b54cb84 --- /dev/null +++ b/org.eclipse.jdt.ls.tests/projects/mixed/simple-gradle/.project @@ -0,0 +1,23 @@ + + + simple-gradle + Project simple-gradle created by Buildship. + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.buildship.core.gradleprojectbuilder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.buildship.core.gradleprojectnature + + diff --git a/org.eclipse.jdt.ls.tests/projects/mixed/simple-gradle/build.gradle b/org.eclipse.jdt.ls.tests/projects/mixed/simple-gradle/build.gradle new file mode 100644 index 0000000000..af05e77698 --- /dev/null +++ b/org.eclipse.jdt.ls.tests/projects/mixed/simple-gradle/build.gradle @@ -0,0 +1,48 @@ +/* + * This build file was auto generated by running the Gradle 'init' task + * by 'fbricon' at '24/10/16 11:28' with Gradle 3.0 + * + * This generated file contains a sample Java project to get you started. + * For more details take a look at the Java Quickstart chapter in the Gradle + * user guide available at https://docs.gradle.org/3.0/userguide/tutorial_java_projects.html + */ + +// Apply the java plugin to add support for Java +apply plugin: 'java' +apply plugin: 'eclipse' + +sourceCompatibility = 1.7 + +// In this section you declare where to find the dependencies of your project +repositories { + // Use 'jcenter' for resolving your dependencies. + // You can declare any Maven/Ivy/file repository here. + jcenter() +} + +// In this section you declare the dependencies for your production and test code +dependencies { + // The production code uses the SLF4J logging API at compile time + compile 'org.slf4j:slf4j-api:1.7.21' + + // Declare the dependency for your favourite test framework you want to use in your tests. + // TestNG is also supported by the Gradle Test task. Just change the + // testCompile dependency to testCompile 'org.testng:testng:6.8.1' and add + // 'test.useTestNG()' to your build script. + testCompile 'junit:junit:4.12' +} + +eclipse { + classpath { + defaultOutputDir = file('target') + file { + whenMerged { + cp -> cp.getEntries().forEach{ + cpEntry -> if(cpEntry.kind=='src') { + cpEntry.output = cpEntry.output.replace('bin/', 'target/') + } + } + } + } + } +} diff --git a/org.eclipse.jdt.ls.tests/projects/mixed/simple-gradle/gradle.properties b/org.eclipse.jdt.ls.tests/projects/mixed/simple-gradle/gradle.properties new file mode 100644 index 0000000000..792d600548 --- /dev/null +++ b/org.eclipse.jdt.ls.tests/projects/mixed/simple-gradle/gradle.properties @@ -0,0 +1 @@ +# diff --git a/org.eclipse.jdt.ls.tests/projects/mixed/simple-gradle/gradle/wrapper/gradle-wrapper.jar b/org.eclipse.jdt.ls.tests/projects/mixed/simple-gradle/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000000..cc4fdc293d Binary files /dev/null and b/org.eclipse.jdt.ls.tests/projects/mixed/simple-gradle/gradle/wrapper/gradle-wrapper.jar differ diff --git a/org.eclipse.jdt.ls.tests/projects/mixed/simple-gradle/gradle/wrapper/gradle-wrapper.properties b/org.eclipse.jdt.ls.tests/projects/mixed/simple-gradle/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000000..a4b4429748 --- /dev/null +++ b/org.eclipse.jdt.ls.tests/projects/mixed/simple-gradle/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/org.eclipse.jdt.ls.tests/projects/mixed/simple-gradle/gradlew b/org.eclipse.jdt.ls.tests/projects/mixed/simple-gradle/gradlew new file mode 100755 index 0000000000..2fe81a7d95 --- /dev/null +++ b/org.eclipse.jdt.ls.tests/projects/mixed/simple-gradle/gradlew @@ -0,0 +1,183 @@ +#!/usr/bin/env sh + +# +# Copyright 2015 the original author or authors. +# +# Licensed 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 +# +# https://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. +# + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +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 +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +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 + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=`expr $i + 1` + done + case $i in + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=`save "$@"` + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +exec "$JAVACMD" "$@" diff --git a/org.eclipse.jdt.ls.tests/projects/mixed/simple-gradle/gradlew.bat b/org.eclipse.jdt.ls.tests/projects/mixed/simple-gradle/gradlew.bat new file mode 100644 index 0000000000..24467a141f --- /dev/null +++ b/org.eclipse.jdt.ls.tests/projects/mixed/simple-gradle/gradlew.bat @@ -0,0 +1,100 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/org.eclipse.jdt.ls.tests/projects/mixed/simple-gradle/settings.gradle b/org.eclipse.jdt.ls.tests/projects/mixed/simple-gradle/settings.gradle new file mode 100644 index 0000000000..505f717597 --- /dev/null +++ b/org.eclipse.jdt.ls.tests/projects/mixed/simple-gradle/settings.gradle @@ -0,0 +1,19 @@ +/* + * This settings file was auto generated by the Gradle buildInit task + * by 'fbricon' at '24/10/16 11:28' with Gradle 3.0 + * + * The settings file is used to specify which projects to include in your build. + * In a single project build this file can be empty or even removed. + * + * Detailed information about configuring a multi-project build in Gradle can be found + * in the user guide at https://docs.gradle.org/3.0/userguide/multi_project_builds.html + */ + +/* +// To declare projects as part of a multi-project build use the 'include' method +include 'shared' +include 'api' +include 'services:webservice' +*/ + +rootProject.name = 'simple-gradle' diff --git a/org.eclipse.jdt.ls.tests/projects/mixed/simple-gradle/src/main/java/Library.java b/org.eclipse.jdt.ls.tests/projects/mixed/simple-gradle/src/main/java/Library.java new file mode 100644 index 0000000000..526aadc25a --- /dev/null +++ b/org.eclipse.jdt.ls.tests/projects/mixed/simple-gradle/src/main/java/Library.java @@ -0,0 +1,11 @@ +/* + * This Java source file was auto generated by running 'gradle buildInit --type java-library' + * by 'fbricon' at '24/10/16 11:28' with Gradle 3.0 + * + * @author fbricon, @date 24/10/16 11:28 + */ +public class Library { + public boolean someLibraryMethod() { + return true; + } +} diff --git a/org.eclipse.jdt.ls.tests/projects/mixed/simple-gradle/src/test/java/LibraryTest.java b/org.eclipse.jdt.ls.tests/projects/mixed/simple-gradle/src/test/java/LibraryTest.java new file mode 100644 index 0000000000..af8df3303c --- /dev/null +++ b/org.eclipse.jdt.ls.tests/projects/mixed/simple-gradle/src/test/java/LibraryTest.java @@ -0,0 +1,15 @@ +import org.junit.Test; +import static org.junit.Assert.*; + +/* + * This Java source file was auto generated by running 'gradle init --type java-library' + * by 'fbricon' at '24/10/16 11:28' with Gradle 3.0 + * + * @author fbricon, @date 24/10/16 11:28 + */ +public class LibraryTest { + @Test public void testSomeLibraryMethod() { + Library classUnderTest = new Library(); + assertTrue("someLibraryMethod should return 'true'", classUnderTest.someLibraryMethod()); + } +} diff --git a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/handlers/ImportNewProjectsTest.java b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/handlers/ImportNewProjectsTest.java index 4118bffb3f..47553b3b6b 100644 --- a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/handlers/ImportNewProjectsTest.java +++ b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/handlers/ImportNewProjectsTest.java @@ -11,6 +11,7 @@ package org.eclipse.jdt.ls.core.internal.handlers; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -158,4 +159,17 @@ public void testImportNewGradleProjects() throws Exception { assertEquals(EventType.ProjectsImported, argument.getValue().getType()); assertEquals(((List) argument.getValue().getData()).size(), projects.length); } + + @Test + public void testImportMixedProjects() throws Exception { + IWorkspaceRoot wsRoot = WorkspaceHelper.getWorkspaceRoot(); + IWorkspace workspace = wsRoot.getWorkspace(); + IProject[] projects = workspace.getRoot().getProjects(); + assertEquals(0, projects.length); + importProjects("mixed"); + assertEquals(4, wsRoot.getProjects().length); + IProject hello = wsRoot.getProject("hello"); + assertNotNull(hello); + assertIsJavaProject(hello); + } }