Skip to content

Commit

Permalink
Merge branch 'develop' into dependabot/npm_and_yarn/npm-package/grpc/…
Browse files Browse the repository at this point in the history
…grpc-js-1.8.22
  • Loading branch information
jdneo authored Oct 24, 2024
2 parents 45dc96a + 4104198 commit 98d46a5
Show file tree
Hide file tree
Showing 10 changed files with 120 additions and 44 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
JAVA_HOME: ""
NODE_OPTIONS: "--max-old-space-size=4096"
- name: Upload lib
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: lib
path: |
Expand Down Expand Up @@ -93,7 +93,7 @@ jobs:
restore-keys: |
${{ runner.os }}-vscode-
- name: Download lib
uses: actions/download-artifact@v2
uses: actions/download-artifact@v4
with:
name: lib
path: extension/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
<unit id="org.mockito.mockito-core" version="0.0.0"/>
<unit id="org.apache.commons.commons-io" version="0.0.0"/>
<unit id="org.eclipse.jdt.apt.pluggable.core" version="0.0.0"/>
<repository location="https://download.eclipse.org/eclipse/updates/4.33-I-builds/I20240613-1800/"/>
<repository location="https://download.eclipse.org/eclipse/updates/4.33/"/>
</location>
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
<unit id="org.eclipse.xtext.xbase.lib" version="0.0.0"/>
<repository location="https://download.eclipse.org/releases/2024-03/"/>
<repository location="https://download.eclipse.org/releases/2024-09/"/>
</location>
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
<unit id="org.eclipse.jdt.ls.core" version="0.0.0"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -513,30 +513,33 @@ private void setProjectJdk(Map<IPath, IClasspathEntry> classpathMap, List<BuildT
javaProject.setOption(JavaCore.COMPILER_COMPLIANCE, targetCompatibility);
}

String highestJavaVersion = getHighestCompatibleJavaVersion(jvmBuildTarget.getGradleVersion());
try {
IVMInstall vm = EclipseVmUtil.findOrRegisterStandardVM(
targetCompatibility, // expectedVersion
sourceCompatibility, // lowestVersion
highestJavaVersion,
new File(new URI(jvmBuildTarget.getJavaHome())) // fallback jdk
);
if (StringUtils.isNotBlank(jvmBuildTarget.getJavaHome())
&& StringUtils.isNotBlank(jvmBuildTarget.getGradleVersion())) {
String highestJavaVersion = getHighestCompatibleJavaVersion(jvmBuildTarget.getGradleVersion());
try {
IVMInstall vm = EclipseVmUtil.findOrRegisterStandardVM(
targetCompatibility, // expectedVersion
sourceCompatibility, // lowestVersion
highestJavaVersion,
new File(new URI(jvmBuildTarget.getJavaHome())) // fallback jdk
);

List<IClasspathAttribute> classpathAttributes = new LinkedList<>();
if (isModular) {
classpathAttributes.add(modularAttribute);
List<IClasspathAttribute> classpathAttributes = new LinkedList<>();
if (isModular) {
classpathAttributes.add(modularAttribute);
}
classpathAttributes.add(buildServerAttribute);
IClasspathEntry jdkEntry = JavaCore.newContainerEntry(
JavaRuntime.newJREContainerPath(vm),
ClasspathEntry.NO_ACCESS_RULES,
classpathAttributes.toArray(new IClasspathAttribute[0]),
false /*isExported*/
);
classpathMap.putIfAbsent(jdkEntry.getPath(), jdkEntry);
} catch (URISyntaxException e) {
throw new CoreException(new Status(IStatus.ERROR, ImporterPlugin.PLUGIN_ID,
"Invalid Java home: " + jvmBuildTarget.getJavaHome(), e));
}
classpathAttributes.add(buildServerAttribute);
IClasspathEntry jdkEntry = JavaCore.newContainerEntry(
JavaRuntime.newJREContainerPath(vm),
ClasspathEntry.NO_ACCESS_RULES,
classpathAttributes.toArray(new IClasspathAttribute[0]),
false /*isExported*/
);
classpathMap.putIfAbsent(jdkEntry.getPath(), jdkEntry);
} catch (URISyntaxException e) {
throw new CoreException(new Status(IStatus.ERROR, ImporterPlugin.PLUGIN_ID,
"Invalid Java home: " + jvmBuildTarget.getJavaHome(), e));
}
}

Expand Down Expand Up @@ -585,8 +588,10 @@ private JvmBuildTargetEx getJvmTarget(List<BuildTarget> buildTargets) throws Cor
}

if (StringUtils.isBlank(jvmTarget.getJavaHome()) || StringUtils.isBlank(jvmTarget.getGradleVersion())) {
throw new CoreException(new Status(IStatus.ERROR, ImporterPlugin.PLUGIN_ID,
"Invalid JVM build target: " + jvmTarget.toString()));
JavaLanguageServerPlugin.logException(
new CoreException(new Status(IStatus.WARNING, ImporterPlugin.PLUGIN_ID,
"Empty Java Home or Gradle Version in JVM target."))
);
}

return jvmTarget;
Expand Down Expand Up @@ -641,7 +646,8 @@ private List<IClasspathEntry> getDependencyJars(DependencyModulesResult dependen
}
String classifier = artifactData.getClassifier();
try {
File jarFile = new File(new URI(uri));
File artifactFile = new File(new URI(uri));
File jarFile = Utils.getJarFile(artifactFile);
if (classifier == null) {
artifact = jarFile;
} else if ("sources".equals(classifier)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,21 @@

import static org.eclipse.jdt.ls.core.internal.handlers.MapFlattener.getString;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

import org.eclipse.core.resources.ICommand;
import org.eclipse.core.resources.IProject;
Expand All @@ -22,6 +29,7 @@
import org.eclipse.core.runtime.URIUtil;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.ls.core.internal.JavaClientConnection.JavaLanguageClient;
import org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin;
import org.eclipse.jdt.ls.core.internal.ProjectUtils;
import org.eclipse.jdt.ls.core.internal.preferences.Preferences;
import org.eclipse.lsp4j.ExecuteCommandParams;
Expand Down Expand Up @@ -214,4 +222,46 @@ public static void sendTelemetry(JavaLanguageClient client, Object message) {
client.sendNotification(new ExecuteCommandParams("_java.gradle.buildServer.sendTelemetry",
Arrays.asList(message)));
}

/**
* Extracts the jar file from the aar file, since JDT.LS is not able to understand
* the structure of aar files.
*/
public static File getJarFile(File file) {

String filepath = file.getAbsolutePath();

if (filepath.endsWith(".aar")) {

// Extracting classes.jar from AAR files
try(ZipInputStream is = new ZipInputStream(new FileInputStream(file))) {

ZipEntry entry;
while ((entry = is.getNextEntry()) != null) {
if (entry.getName().equals("classes.jar")) {
String fileName = file.getName();
fileName = fileName.substring(0, fileName.length() - 4);
fileName = fileName + ".jar";
File outputFile = Path.of(file.getParentFile().getAbsolutePath(), fileName).toFile();
try (FileOutputStream outputStream = new FileOutputStream(outputFile)) {
byte[] buffer = new byte[1024];
int len;
while((len = is.read(buffer)) > 0) {
outputStream.write(buffer, 0, len);
}
return outputFile;
}
}
}

} catch(IOException e) {
JavaLanguageServerPlugin.logException(e);
}

}

return file;

}

}
2 changes: 1 addition & 1 deletion extension/src/stores/RootProjectsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { RootProject } from "../rootProject/RootProject";
import { GRADLE_BUILD_FILE_NAMES } from "../constant";

async function getNestedRootProjectFolders(): Promise<string[]> {
const matchingNestedWrapperFiles = await vscode.workspace.findFiles("**/{gradlew,gradlew.bat}");
const matchingNestedWrapperFiles = await vscode.workspace.findFiles("**/{settings.gradle,settings.gradle.kts}");
return [...new Set(matchingNestedWrapperFiles.map((uri) => path.dirname(uri.fsPath)))];
}

Expand Down
4 changes: 2 additions & 2 deletions extension/src/test/testUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,13 @@ export function stubWorkspaceFolders(workspaceFolders: vscode.WorkspaceFolder[])
const getWorkspaceFolderStub = sinon.stub(vscode.workspace, "getWorkspaceFolder");
const dirnameStub = sinon.stub(path, "dirname");
workspaceFolders.forEach((workspaceFolder) => {
existsSyncStub.withArgs(path.join(workspaceFolder.uri.fsPath, "gradlew")).returns(true);
existsSyncStub.withArgs(path.join(workspaceFolder.uri.fsPath, "settings.gradle")).returns(true);
getWorkspaceFolderStub.withArgs(sinon.match.has("fsPath", workspaceFolder.uri.fsPath)).returns(workspaceFolder);
dirnameStub.withArgs(workspaceFolder.uri.fsPath).returns(workspaceFolder.uri.fsPath);
});
sinon
.stub(vscode.workspace, "findFiles")
.withArgs("**/{gradlew,gradlew.bat}")
.withArgs("**/{settings.gradle,settings.gradle.kts}")
.returns(Promise.resolve(workspaceFolders.map((folder) => folder.uri)));
}

Expand Down
4 changes: 2 additions & 2 deletions extension/src/util/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ export function waitOnTcp(host: string, port: number): Promise<void> {

export function isGradleRootProject(rootProject: RootProject): boolean {
return (
fs.existsSync(path.join(rootProject.getProjectUri().fsPath, "gradlew")) ||
fs.existsSync(path.join(rootProject.getProjectUri().fsPath, "gradlew.bat"))
fs.existsSync(path.join(rootProject.getProjectUri().fsPath, "settings.gradle")) ||
fs.existsSync(path.join(rootProject.getProjectUri().fsPath, "settings.gradle.kts"))
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class DefaultProjectsTreeDataProvider implements vscode.TreeDataProvider<

private async getChildrenForProjectTreeItem(element: ProjectTreeItem): Promise<vscode.TreeItem[]> {
const projectTaskItem = new ProjectTaskTreeItem("Tasks", vscode.TreeItemCollapsibleState.Collapsed, element);
projectTaskItem.setChildren([...element.groups, ...element.tasks]);
projectTaskItem.setChildren([...element.tasks, ...element.groups]);
const results: vscode.TreeItem[] = [projectTaskItem];
const resourceUri = element.resourceUri;
if (!resourceUri) {
Expand All @@ -68,6 +68,6 @@ export class DefaultProjectsTreeDataProvider implements vscode.TreeDataProvider<
path.dirname(resourceUri.fsPath),
typeof element.label === "string" ? element.label : resourceUri.fsPath
);
return [...results, projectDependencyTreeItem];
return [projectDependencyTreeItem, ...results];
}
}
25 changes: 18 additions & 7 deletions extension/src/views/gradleTasks/GradleTasksTreeDataProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,11 @@ export class GradleTasksTreeDataProvider implements vscode.TreeDataProvider<vsco

public async getChildrenForProjectTreeItem(element: ProjectTreeItem): Promise<vscode.TreeItem[]> {
const projectTaskItem = new ProjectTaskTreeItem("Tasks", vscode.TreeItemCollapsibleState.Collapsed, element);
projectTaskItem.setChildren([...element.groups, ...element.tasks]);
projectTaskItem.setChildren([...element.tasks, ...element.groups]);
const results: vscode.TreeItem[] = [projectTaskItem];
const resourceUri = element.resourceUri;
if (!resourceUri) {
return results;
return [...results, ...element.subprojects];
}
const projectDependencyTreeItem: ProjectDependencyTreeItem = new ProjectDependencyTreeItem(
"Dependencies",
Expand All @@ -226,7 +226,7 @@ export class GradleTasksTreeDataProvider implements vscode.TreeDataProvider<vsco
path.dirname(resourceUri.fsPath),
typeof element.label === "string" ? element.label : resourceUri.fsPath
);
return [...results, projectDependencyTreeItem];
return [...results, projectDependencyTreeItem, ...element.subprojects];
}

public static buildItemsTreeFromTasks(
Expand All @@ -253,15 +253,26 @@ export class GradleTasksTreeDataProvider implements vscode.TreeDataProvider<vsco
gradleProjectTreeItemMap.set(definition.projectFolder, gradleProjectTreeItem);
}

let projectTreeItem = projectTreeItemMap.get(definition.buildFile);
const projectPath = definition.script.split(":").slice(0, -1);
const projectMapKey = definition.projectFolder + "_" + projectPath.join(":");
let projectTreeItem = projectTreeItemMap.get(projectMapKey);
if (!projectTreeItem) {
const parentProjectPath = projectPath.length == 0 ? null : projectPath.slice(0, -1);
const parentProject =
parentProjectPath === null
? gradleProjectTreeItem
: projectTreeItemMap.get(definition.projectFolder + "_" + parentProjectPath.join(":"));
projectTreeItem = new ProjectTreeItem(
definition.project,
gradleProjectTreeItem,
parentProject,
vscode.Uri.file(definition.buildFile)
);
gradleProjectTreeItem.addProject(projectTreeItem);
projectTreeItemMap.set(definition.buildFile, projectTreeItem);
if (parentProject instanceof ProjectTreeItem) {
parentProject.addSubproject(projectTreeItem);
} else {
gradleProjectTreeItem.addProject(projectTreeItem);
}
projectTreeItemMap.set(projectMapKey, projectTreeItem);
}

const taskName = definition.script.slice(definition.script.lastIndexOf(":") + 1);
Expand Down
11 changes: 10 additions & 1 deletion extension/src/views/gradleTasks/TreeItemWithTasksOrGroups.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import * as vscode from "vscode";
import { GradleTaskTreeItem } from ".";
import { GradleTaskTreeItem, ProjectTreeItem } from ".";
import { GroupTreeItem } from "..";
import { treeItemSortCompareFunc, gradleTaskTreeItemSortCompareFunc } from "../viewUtil";

export class TreeItemWithTasksOrGroups extends vscode.TreeItem {
private readonly _tasks: GradleTaskTreeItem[] = [];
private readonly _groups: GroupTreeItem[] = [];
private readonly _subprojects: ProjectTreeItem[] = [];
public readonly parentTreeItem?: vscode.TreeItem;
public readonly iconPath = new vscode.ThemeIcon("file-submodule");
public readonly contextValue = "folder";
Expand Down Expand Up @@ -35,4 +36,12 @@ export class TreeItemWithTasksOrGroups extends vscode.TreeItem {
public get groups(): GroupTreeItem[] {
return this._groups.sort(treeItemSortCompareFunc);
}

public get subprojects(): ProjectTreeItem[] {
return this._subprojects;
}

public addSubproject(subproject: ProjectTreeItem): void {
this._subprojects.push(subproject);
}
}

0 comments on commit 98d46a5

Please sign in to comment.