From 01b90e8499ac2a4839e72998b0bc138468806e73 Mon Sep 17 00:00:00 2001 From: Snjezana Peco Date: Tue, 25 Nov 2025 21:05:20 +0100 Subject: [PATCH] Fix configuring external libraries on Windows --- .../core/model/BazelWorkspaceInfo.java | 9 +++- .../JavaClasspathJarLocationResolver.java | 45 ++++++++++++++++--- .../ArtifactLocationDecoderImpl.java | 5 +++ 3 files changed, 53 insertions(+), 6 deletions(-) diff --git a/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/model/BazelWorkspaceInfo.java b/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/model/BazelWorkspaceInfo.java index 98b746979..be976211f 100644 --- a/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/model/BazelWorkspaceInfo.java +++ b/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/model/BazelWorkspaceInfo.java @@ -231,7 +231,14 @@ private String getExpectedOutput(Map infoResult, BazelInfoKey ke } private IPath getExpectedOutputAsPath(Map infoResult, BazelInfoKey key) throws CoreException { - return new org.eclipse.core.runtime.Path(getExpectedOutput(infoResult, key)); + var expectedOutput = getExpectedOutput(infoResult, key); + try { + var out = Path.of(expectedOutput).toRealPath(); + expectedOutput = out.toString(); + } catch (IOException e) { + LOG.error(e.getMessage(), e); + } + return org.eclipse.core.runtime.Path.fromOSString(expectedOutput); } public Stream getExternalRepositoriesByRuleClass(Predicate ruleClassPredicate) diff --git a/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/model/discovery/JavaClasspathJarLocationResolver.java b/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/model/discovery/JavaClasspathJarLocationResolver.java index 01cbe0d53..1e0de7783 100644 --- a/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/model/discovery/JavaClasspathJarLocationResolver.java +++ b/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/model/discovery/JavaClasspathJarLocationResolver.java @@ -3,11 +3,13 @@ import static java.lang.String.format; import static org.eclipse.core.runtime.IPath.forPosix; +import java.io.File; import java.io.IOException; import java.nio.file.Path; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Platform; import org.eclipse.jdt.core.IClasspathEntry; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -101,6 +103,15 @@ public ArtifactLocationDecoder getLocationDecoder() { return locationDecoder; } + private IPath getPath(String path) throws IOException { + if (Platform.OS_WIN32.equals(Platform.getOS())) { + var file = new File(path); + var canonicalPath = file.getCanonicalPath(); + return org.eclipse.core.runtime.Path.fromOSString(canonicalPath); + } + return forPosix(path); + } + public WorkspaceRoot getWorkspaceRoot() { return workspaceRoot; } @@ -129,7 +140,13 @@ public ClasspathEntry resolveJar(LibraryArtifact jar) { // prefer the class jar because this is much better in Eclipse when debugging/stepping through code/code navigation/etc. var jarArtifactForIde = jar.getClassJar() != null ? jar.getClassJar() : jar.jarForIntellijLibrary(); if (jarArtifactForIde.isMainWorkspaceSourceArtifact()) { - var jarPath = forPosix(locationDecoder.resolveSource(jarArtifactForIde).toString()); + IPath jarPath; + try { + jarPath = getPath(locationDecoder.resolveSource(jarArtifactForIde).toString()); + } catch (IOException e) { + LOG.error(e.getMessage(), e); + return null; + } var sourceJar = jar.getSourceJars().stream().findFirst(); if (!sourceJar.isPresent()) { if (LOG.isDebugEnabled()) { @@ -140,8 +157,13 @@ public ClasspathEntry resolveJar(LibraryArtifact jar) { } return ClasspathEntry.newLibraryEntry(jarPath, null, null, false /* test only */); } - - var srcJarPath = forPosix(locationDecoder.resolveSource(sourceJar.get()).toString()); + IPath srcJarPath; + try { + srcJarPath = getPath(locationDecoder.resolveSource(sourceJar.get()).toString()); + } catch (IOException e) { + LOG.error(e.getMessage(), e); + srcJarPath = null; + } if (LOG.isDebugEnabled()) { LOG.debug( "Found jar for '{}': {} (source {})", @@ -153,7 +175,13 @@ public ClasspathEntry resolveJar(LibraryArtifact jar) { } var jarArtifact = locationDecoder.resolveOutput(jarArtifactForIde); if (jarArtifact instanceof LocalFileArtifact localJar) { - var jarPath = forPosix(localJar.getPath().toString()); + IPath jarPath; + try { + jarPath = getPath(localJar.getPath().toString()); + } catch (IOException e) { + LOG.error(e.getMessage(), e); + return null; + } var sourceJar = jar.getSourceJars().stream().findFirst(); if (!sourceJar.isPresent()) { if (LOG.isDebugEnabled()) { @@ -163,7 +191,14 @@ public ClasspathEntry resolveJar(LibraryArtifact jar) { } var srcJarArtifact = locationDecoder.resolveOutput(sourceJar.get()); if (srcJarArtifact instanceof LocalFileArtifact localSrcJar) { - var srcJarPath = forPosix(localSrcJar.getPath().toString()); + var pathStr = org.eclipse.core.runtime.Path.fromOSString(localSrcJar.getPath().toString()).toString(); + IPath srcJarPath; + try { + srcJarPath = getPath(localSrcJar.getPath().toString()); + } catch (IOException e) { + LOG.error(e.getMessage(), e); + srcJarPath = null; + } if (LOG.isDebugEnabled()) { LOG.debug( "Found jar for '{}': {} (source {})", diff --git a/bundles/com.salesforce.bazel.importedsource/src-intellij-plugin/com/google/idea/blaze/base/sync/workspace/ArtifactLocationDecoderImpl.java b/bundles/com.salesforce.bazel.importedsource/src-intellij-plugin/com/google/idea/blaze/base/sync/workspace/ArtifactLocationDecoderImpl.java index 407ef522c..f1b7690c3 100644 --- a/bundles/com.salesforce.bazel.importedsource/src-intellij-plugin/com/google/idea/blaze/base/sync/workspace/ArtifactLocationDecoderImpl.java +++ b/bundles/com.salesforce.bazel.importedsource/src-intellij-plugin/com/google/idea/blaze/base/sync/workspace/ArtifactLocationDecoderImpl.java @@ -15,6 +15,8 @@ import java.nio.file.Path; import java.util.Objects; +import org.eclipse.core.runtime.Platform; + import com.google.idea.blaze.base.command.buildresult.BlazeArtifact; import com.google.idea.blaze.base.command.buildresult.LocalFileOutputArtifact; import com.google.idea.blaze.base.command.buildresult.SourceArtifact; @@ -74,6 +76,9 @@ public int hashCode() { private BlazeArtifact outputArtifactFromExecRoot(ArtifactLocation location) { // exec-root-relative path of the form 'blaze-out/mnemonic/genfiles/path' var execRootPath = location.getExecutionRootRelativePath(); + if (Platform.OS_WIN32.equals(Platform.getOS())) { + execRootPath = org.eclipse.core.runtime.Path.fromOSString(execRootPath).toString(); + } var ix1 = execRootPath.indexOf('/'); var ix2 = execRootPath.indexOf('/', ix1 + 1); if (ix2 == -1) {