Skip to content

Commit

Permalink
Introduce gson to simplify the object parsing (microsoft#1509)
Browse files Browse the repository at this point in the history
Signed-off-by: Sheng Chen <sheche@microsoft.com>
  • Loading branch information
jdneo authored and Jiaaming committed Jul 15, 2024
1 parent 65e9b8f commit 1bcf29c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Require-Bundle: org.eclipse.core.runtime,
org.eclipse.lsp4j.jsonrpc,
org.eclipse.core.resources,
org.eclipse.jdt.launching,
org.apache.commons.lang3
org.apache.commons.lang3,
com.google.gson
Bundle-ClassPath: lib/bsp4j-2.1.0-M4.jar,
.
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package com.microsoft.gradle.bs.importer;

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

import java.io.File;
import java.net.URI;
import java.net.URISyntaxException;
Expand Down Expand Up @@ -40,6 +37,7 @@
import org.eclipse.jdt.internal.core.ClasspathEntry;
import org.eclipse.jdt.launching.IVMInstall;
import org.eclipse.jdt.launching.JavaRuntime;
import org.eclipse.jdt.ls.core.internal.JSONUtility;
import org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin;
import org.eclipse.jdt.ls.core.internal.ProjectUtils;
import org.eclipse.jdt.ls.core.internal.ResourceUtils;
Expand All @@ -60,6 +58,8 @@
import ch.epfl.scala.bsp4j.JavacOptionsItem;
import ch.epfl.scala.bsp4j.JavacOptionsParams;
import ch.epfl.scala.bsp4j.JavacOptionsResult;
import ch.epfl.scala.bsp4j.MavenDependencyModule;
import ch.epfl.scala.bsp4j.MavenDependencyModuleArtifact;
import ch.epfl.scala.bsp4j.OutputPathItem;
import ch.epfl.scala.bsp4j.OutputPathsItem;
import ch.epfl.scala.bsp4j.OutputPathsParams;
Expand Down Expand Up @@ -533,17 +533,17 @@ private JvmBuildTargetEx getJvmTarget(List<BuildTarget> buildTargets) throws Cor
continue;
}

String javaHome = getString((Map) buildTarget.getData(), JAVA_HOME);
if (StringUtils.isNotBlank(javaHome) && StringUtils.isBlank(jvmTarget.getJavaHome())) {
jvmTarget.setJavaHome(javaHome);
JvmBuildTargetEx rawJvmTarget = JSONUtility.toModel(buildTarget.getData(), JvmBuildTargetEx.class);
if (StringUtils.isNotBlank(rawJvmTarget.getJavaHome()) && StringUtils.isBlank(jvmTarget.getJavaHome())) {
jvmTarget.setJavaHome(rawJvmTarget.getJavaHome());
}

String gradleVersion = getString((Map) buildTarget.getData(), GRADLE_VERSION);
String gradleVersion = rawJvmTarget.getGradleVersion();
if (StringUtils.isNotBlank(gradleVersion) && StringUtils.isBlank(jvmTarget.getGradleVersion())) {
jvmTarget.setGradleVersion(gradleVersion);
}

String sourceCompatibility = getString((Map) buildTarget.getData(), SOURCE_COMPATIBILITY);
String sourceCompatibility = rawJvmTarget.getSourceCompatibility();
if (StringUtils.isNotBlank(sourceCompatibility)) {
sourceCompatibility = getEclipseCompatibleVersion(sourceCompatibility);
if (StringUtils.isBlank(jvmTarget.getSourceCompatibility())
Expand All @@ -552,7 +552,7 @@ private JvmBuildTargetEx getJvmTarget(List<BuildTarget> buildTargets) throws Cor
}
}

String targetCompatibility = getString((Map) buildTarget.getData(), TARGET_COMPATIBILITY);
String targetCompatibility = rawJvmTarget.getTargetCompatibility();
if (StringUtils.isNotBlank(targetCompatibility)) {
targetCompatibility = getEclipseCompatibleVersion(targetCompatibility);
if (StringUtils.isBlank(jvmTarget.getTargetCompatibility())
Expand Down Expand Up @@ -592,19 +592,21 @@ private List<IClasspathEntry> getDependencyJars(DependencyModulesResult dependen
if (!"maven".equals(module.getDataKind())) {
continue;
}
List<Map> artifacts = (List<Map>) getValue((Map) module.getData(), "artifacts");
MavenDependencyModule mavenDependencyModule =
JSONUtility.toModel(module.getData(), MavenDependencyModule.class);
List<MavenDependencyModuleArtifact> artifacts = mavenDependencyModule.getArtifacts();
if (artifacts == null) {
continue;
}

File artifact = null;
File sourceArtifact = null;
for (Map artifactData : artifacts) {
String uri = (String) getValue(artifactData, "uri");
for (MavenDependencyModuleArtifact artifactData : artifacts) {
String uri = artifactData.getUri();
if (uri == null) {
continue;
}
String classifier = (String) getValue(artifactData, "classifier");
String classifier = artifactData.getClassifier();
try {
File jarFile = new File(new URI(uri));
if (classifier == null) {
Expand All @@ -614,7 +616,6 @@ private List<IClasspathEntry> getDependencyJars(DependencyModulesResult dependen
}
} catch (URISyntaxException e) {
JavaLanguageServerPlugin.logException(e);
continue;
}
}

Expand Down

0 comments on commit 1bcf29c

Please sign in to comment.