Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for subfolder gradle projects #1336

Merged
merged 3 commits into from
May 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ public CompletableFuture<Either<List<CompletionItem>, CompletionList>> completio
containingCall = call;
}
}
this.libraryResolver.loadGradleClasses();
this.libraryResolver.loadGradleClasses(uri);
boolean javaPluginsIncluded = this.libraryResolver.isJavaPluginsIncluded(uri,
this.completionVisitor.getPlugins(uri));
CompletionHandler handler = new CompletionHandler();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,15 @@ public List<GradleClosure> getExtClosures(String projectPath) {
}

public boolean resolveGradleAPI() {
return resolveGradleAPI(null);
}

public boolean resolveGradleAPI(URI gradleFilePath) {
this.needToLoadClasses = true;
// step 1: find "lib" folder
File libFolder = null;
if (this.gradleWrapperEnabled) {
DistInfo info = getWrapperPropertiesInfo();
DistInfo info = getWrapperPropertiesInfo(gradleFilePath);
if (info == null) {
return false;
}
Expand All @@ -119,20 +123,27 @@ public boolean resolveGradleAPI() {
if (!Utils.isValidFolder(libFolder)) {
return false;
}
this.gradleFilesManager.setGradleLibraries(Utils.listAllFiles(libFolder));
// step 2: find core API jar file
this.coreAPI = findCoreAPI(libFolder);
if (!Utils.isValidFile(this.coreAPI)) {
File newAPI = findCoreAPI(libFolder);
if (!Utils.isValidFile(newAPI)) {
return false;
}
if (this.coreAPI != null && this.coreAPI.equals(newAPI)) {
// same gradle dist so reuse.
this.needToLoadClasses = false;
return false;
}

this.gradleFilesManager.setGradleLibraries(Utils.listAllFiles(libFolder));
// step 2: find core API jar file
this.coreAPI = newAPI;
// step 3: find plugin API jar file
this.pluginAPI = findPluginAPI(this.coreAPI.toPath().getParent().resolve(Paths.get("plugins")).toFile());
return Utils.isValidFile(this.pluginAPI);
}

public void loadGradleClasses() {
public void loadGradleClasses(URI uri) {
boolean isAPIValid = Utils.isValidFile(this.coreAPI) && Utils.isValidFile(this.pluginAPI);
if (!this.needToLoadClasses || (!isAPIValid && !this.resolveGradleAPI())) {
if (!this.needToLoadClasses || (!isAPIValid && !this.resolveGradleAPI(uri))) {
return;
}
try {
Expand All @@ -147,12 +158,18 @@ public void loadGradleClasses() {
}
}

private DistInfo getWrapperPropertiesInfo() {
if (this.workspacePath == null) {
private DistInfo getWrapperPropertiesInfo(URI gradleFilePath) {
if (this.workspacePath == null && gradleFilePath == null) {
return null;
}
Path propertiesRelativePath = Paths.get("gradle", "wrapper", "gradle-wrapper.properties");
Path propertiesPath = this.workspacePath.resolve(propertiesRelativePath);
Path propertiesPath = null;
if (gradleFilePath != null) {
propertiesPath = Paths.get(gradleFilePath).getParent().resolve(propertiesRelativePath);
} else {
propertiesPath = this.workspacePath.resolve(propertiesRelativePath);
}

File propertiesFile = propertiesPath.toFile();
if (!propertiesFile.exists()) {
return null;
Expand Down