Skip to content

Commit 227e1e3

Browse files
committed
Gradle Project hasn't been updated properly
Signed-off-by: Snjezana Peco <[email protected]>
1 parent cde8d01 commit 227e1e3

File tree

15 files changed

+463
-13
lines changed

15 files changed

+463
-13
lines changed

org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/BasicFileDetector.java

+23-9
Original file line numberDiff line numberDiff line change
@@ -55,21 +55,30 @@ public class BasicFileDetector {
5555
private static final Set<FileVisitOption> FOLLOW_LINKS_OPTION = EnumSet.of(FileVisitOption.FOLLOW_LINKS);
5656
private List<Path> directories;
5757
private Path rootDir;
58-
private String fileName;
58+
private List<String> fileNames;
5959
private int maxDepth = 5;
6060
private boolean includeNested = true;
6161
private Set<String> exclusions = new LinkedHashSet<>(1);
6262

6363
/**
64-
* Constructs a new BasicFileDetector for the given root directory, searching for a fileName.
65-
* By default, the search depth is limited to 5. Sub-directories of a found directory will be walked through.
66-
* The ".metadata" folder is excluded.
67-
* @param rootDir the root directory to search for files
68-
* @param fileName the name of the file to search
64+
* Constructs a new BasicFileDetector for the given root directory, searching
65+
* for fileNames. By default, the search depth is limited to 5. Sub-directories
66+
* of a found directory will be walked through. The ".metadata" folder is
67+
* excluded.
68+
*
69+
* @param rootDir
70+
* the root directory to search for files
71+
* @param fileNames
72+
* the names of the file to search
6973
*/
70-
public BasicFileDetector(Path rootDir, String fileName) {
74+
public BasicFileDetector(Path rootDir, String... fileNames) {
7175
this.rootDir = rootDir;
72-
this.fileName = fileName;
76+
this.fileNames = new ArrayList<>();
77+
if (fileNames != null) {
78+
for (String fileName : fileNames) {
79+
this.fileNames.add(fileName);
80+
}
81+
}
7382
directories = new ArrayList<>();
7483
addExclusions(METADATA_FOLDER);
7584
List<String> javaImportExclusions = JavaLanguageServerPlugin.getPreferencesManager().getPreferences().getJavaImportExclusions();
@@ -190,7 +199,12 @@ private boolean isExcluded(Path dir) {
190199
}
191200

192201
private boolean hasTargetFile(Path dir) {
193-
return Files.isRegularFile(dir.resolve(fileName));
202+
for (String fileName : fileNames) {
203+
if (Files.isRegularFile(dir.resolve(fileName))) {
204+
return true;
205+
}
206+
}
207+
return false;
194208
}
195209

196210
}

org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/GradleBuildSupport.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,11 @@ public void update(IProject project, boolean force, IProgressMonitor monitor) th
7979
BuildConfiguration buildConfiguration = GradleProjectImporter.getBuildConfiguration(Paths.get(projectPath));
8080
gradleBuild = GradleCore.getWorkspace().createBuild(buildConfiguration);
8181
}
82-
if (isRoot) {
82+
File buildFile = project.getFile(GradleProjectImporter.BUILD_GRADLE_DESCRIPTOR).getLocation().toFile();
83+
File settingsFile = project.getFile(GradleProjectImporter.SETTINGS_GRADLE_DESCRIPTOR).getLocation().toFile();
84+
boolean shouldUpdate = (buildFile.exists() && JavaLanguageServerPlugin.getDigestStore().updateDigest(buildFile.toPath()))
85+
|| (settingsFile.exists() && JavaLanguageServerPlugin.getDigestStore().updateDigest(settingsFile.toPath()));
86+
if (force || isRoot || shouldUpdate) {
8387
gradleBuild.synchronize(monitor);
8488
}
8589
}
@@ -89,9 +93,9 @@ private boolean isRoot(IProject project, GradleBuild gradleBuild, IProgressMonit
8993
if (gradleBuild instanceof InternalGradleBuild) {
9094
CancellationTokenSource tokenSource = GradleConnector.newCancellationTokenSource();
9195
Collection<EclipseProject> eclipseProjects = ((InternalGradleBuild) gradleBuild).getModelProvider().fetchModels(EclipseProject.class, FetchStrategy.LOAD_IF_NOT_CACHED, tokenSource, monitor);
96+
File projectDirectory = project.getLocation().toFile();
9297
for (EclipseProject eclipseProject : eclipseProjects) {
9398
File eclipseProjectDirectory = eclipseProject.getProjectDirectory();
94-
File projectDirectory = project.getLocation().toFile();
9599
if (eclipseProjectDirectory.equals(projectDirectory)) {
96100
return eclipseProject.getParent() == null;
97101
}

org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/GradleProjectImporter.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public class GradleProjectImporter extends AbstractProjectImporter {
6262
public static final String GRADLE_USER_HOME = "GRADLE_USER_HOME";
6363

6464
public static final String BUILD_GRADLE_DESCRIPTOR = "build.gradle";
65+
public static final String SETTINGS_GRADLE_DESCRIPTOR = "settings.gradle";
6566

6667
public static final GradleDistribution DEFAULT_DISTRIBUTION = GradleDistribution.forVersion(GradleVersion.current().getVersion());
6768

@@ -91,7 +92,8 @@ public boolean applies(IProgressMonitor monitor) throws CoreException {
9192
return false;
9293
}
9394
if (directories == null) {
94-
BasicFileDetector gradleDetector = new BasicFileDetector(rootFolder.toPath(), BUILD_GRADLE_DESCRIPTOR)
95+
BasicFileDetector gradleDetector = new BasicFileDetector(rootFolder.toPath(), BUILD_GRADLE_DESCRIPTOR,
96+
SETTINGS_GRADLE_DESCRIPTOR)
9597
.includeNested(false)
9698
.addExclusions("**/build")//default gradle build dir
9799
.addExclusions("**/bin");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#
2+
# https://help.github.com/articles/dealing-with-line-endings/
3+
#
4+
# These are explicitly windows files and should use crlf
5+
*.bat text eol=crlf
6+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Ignore Gradle project-specific cache directory
2+
.gradle
3+
4+
# Ignore Gradle build output directory
5+
build
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* This file was generated by the Gradle 'init' task.
3+
*
4+
* This generated file contains a sample Java application project to get you started.
5+
* For more details take a look at the 'Building Java & JVM projects' chapter in the Gradle
6+
* User Manual available at https://docs.gradle.org/6.7.1/userguide/building_java_projects.html
7+
*/
8+
9+
plugins {
10+
// Apply the application plugin to add support for building a CLI application in Java.
11+
id 'application'
12+
}
13+
14+
repositories {
15+
// Use JCenter for resolving dependencies.
16+
jcenter()
17+
}
18+
19+
dependencies {
20+
// Use JUnit Jupiter API for testing.
21+
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.2'
22+
23+
// Use JUnit Jupiter Engine for testing.
24+
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
25+
26+
// This dependency is used by the application.
27+
implementation 'com.google.guava:guava:29.0-jre'
28+
}
29+
30+
application {
31+
// Define the main class for the application.
32+
mainClass = 'sample.App'
33+
}
34+
35+
tasks.named('test') {
36+
// Use junit platform for unit tests.
37+
useJUnitPlatform()
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* This file was generated by the Gradle 'init' task.
3+
*
4+
* This generated file contains a sample Java application project to get you started.
5+
* For more details take a look at the 'Building Java & JVM projects' chapter in the Gradle
6+
* User Manual available at https://docs.gradle.org/6.7.1/userguide/building_java_projects.html
7+
*/
8+
9+
plugins {
10+
// Apply the application plugin to add support for building a CLI application in Java.
11+
id 'application'
12+
}
13+
14+
repositories {
15+
// Use JCenter for resolving dependencies.
16+
jcenter()
17+
}
18+
19+
dependencies {
20+
// Use JUnit Jupiter API for testing.
21+
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.2'
22+
23+
// Use JUnit Jupiter Engine for testing.
24+
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
25+
26+
// This dependency is used by the application.
27+
implementation 'com.google.guava:guava:29.0-jre'
28+
implementation 'org.apache.commons:commons-lang3:3.11'
29+
}
30+
31+
application {
32+
// Define the main class for the application.
33+
mainClass = 'sample.App'
34+
}
35+
36+
tasks.named('test') {
37+
// Use junit platform for unit tests.
38+
useJUnitPlatform()
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* This Java source file was generated by the Gradle 'init' task.
3+
*/
4+
package sample;
5+
6+
public class App {
7+
public String getGreeting() {
8+
return "Hello World!";
9+
}
10+
11+
public static void main(String[] args) {
12+
System.out.println(new App().getGreeting());
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* This Java source file was generated by the Gradle 'init' task.
3+
*/
4+
package sample;
5+
6+
import org.junit.jupiter.api.Test;
7+
import static org.junit.jupiter.api.Assertions.*;
8+
9+
class AppTest {
10+
@Test void appHasAGreeting() {
11+
App classUnderTest = new App();
12+
assertNotNull(classUnderTest.getGreeting(), "app should have a greeting");
13+
}
14+
}
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip
4+
zipStoreBase=GRADLE_USER_HOME
5+
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)