Skip to content

Commit 7a22bab

Browse files
committed
Fix configuring external libraries on Windows
1 parent 776ee11 commit 7a22bab

3 files changed

Lines changed: 69 additions & 22 deletions

File tree

bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/model/BazelWorkspaceInfo.java

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,14 @@ private String getExpectedOutput(Map<String, String> infoResult, BazelInfoKey ke
229229
}
230230

231231
private IPath getExpectedOutputAsPath(Map<String, String> infoResult, BazelInfoKey key) throws CoreException {
232-
return new org.eclipse.core.runtime.Path(getExpectedOutput(infoResult, key));
232+
var expectedOutput = getExpectedOutput(infoResult, key);
233+
try {
234+
var out = Path.of(expectedOutput).toRealPath();
235+
expectedOutput = out.toString();
236+
} catch (IOException e) {
237+
LOG.error(e.getMessage(), e);
238+
}
239+
return org.eclipse.core.runtime.Path.fromOSString(expectedOutput);
233240
}
234241

235242
public Stream<BazelRuleAttributes> getExternalRepositoriesByRuleClass(Predicate<String> ruleClassPredicate)
@@ -503,6 +510,22 @@ public void load(BazelModelCommandExecutionService executionService) throws Core
503510
}
504511
}
505512

513+
private synchronized Map<String, ExternalWorkspace> loadExternalRepoMappings() throws CoreException {
514+
if (externalWorkspaceByRepoName != null) {
515+
return externalWorkspaceByRepoName;
516+
}
517+
518+
var workspaceRoot = getWorkspaceFile().getParent();
519+
520+
var repoMappingCommand =
521+
new BazelModDumpRepoMappingCommand(workspaceRoot, "", "Reading bzlmod repository mappings");
522+
List<ExternalWorkspace> externalWorkspaces =
523+
bazelWorkspace.getCommandExecutor().runQueryWithoutLock(repoMappingCommand);
524+
525+
return externalWorkspaceByRepoName =
526+
externalWorkspaces.stream().collect(toMap(ExternalWorkspace::repoName, Function.identity())); // index by the "repo name" attribute
527+
}
528+
506529
private synchronized Map<String, BazelRuleAttributes> loadExternalRepositoryRules() throws CoreException {
507530
if (externalRepositoryRuleByName != null) {
508531
return externalRepositoryRuleByName;
@@ -529,20 +552,4 @@ private synchronized Map<String, BazelRuleAttributes> loadExternalRepositoryRule
529552
.map(BazelRuleAttributes::new)
530553
.collect(toMap(BazelRuleAttributes::getName, Function.identity())); // index by the "name" attribute
531554
}
532-
533-
private synchronized Map<String, ExternalWorkspace> loadExternalRepoMappings() throws CoreException {
534-
if (externalWorkspaceByRepoName != null) {
535-
return externalWorkspaceByRepoName;
536-
}
537-
538-
var workspaceRoot = getWorkspaceFile().getParent();
539-
540-
var repoMappingCommand =
541-
new BazelModDumpRepoMappingCommand(workspaceRoot, "", "Reading bzlmod repository mappings");
542-
List<ExternalWorkspace> externalWorkspaces =
543-
bazelWorkspace.getCommandExecutor().runQueryWithoutLock(repoMappingCommand);
544-
545-
return externalWorkspaceByRepoName =
546-
externalWorkspaces.stream().collect(toMap(ExternalWorkspace::repoName, Function.identity())); // index by the "repo name" attribute
547-
}
548555
}

bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/model/discovery/JavaClasspathJarLocationResolver.java

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
import static java.lang.String.format;
44
import static org.eclipse.core.runtime.IPath.forPosix;
55

6+
import java.io.File;
67
import java.io.IOException;
78
import java.nio.file.Path;
89

910
import org.eclipse.core.runtime.CoreException;
1011
import org.eclipse.core.runtime.IPath;
12+
import org.eclipse.core.runtime.Platform;
1113
import org.eclipse.jdt.core.IClasspathEntry;
1214
import org.slf4j.Logger;
1315
import org.slf4j.LoggerFactory;
@@ -101,6 +103,15 @@ public ArtifactLocationDecoder getLocationDecoder() {
101103
return locationDecoder;
102104
}
103105

106+
private IPath getPath(String path) throws IOException {
107+
if (Platform.OS_WIN32.equals(Platform.getOS())) {
108+
var file = new File(path);
109+
var canonicalPath = file.getCanonicalPath();
110+
return org.eclipse.core.runtime.Path.fromOSString(canonicalPath);
111+
}
112+
return forPosix(path);
113+
}
114+
104115
public WorkspaceRoot getWorkspaceRoot() {
105116
return workspaceRoot;
106117
}
@@ -129,7 +140,13 @@ public ClasspathEntry resolveJar(LibraryArtifact jar) {
129140
// prefer the class jar because this is much better in Eclipse when debugging/stepping through code/code navigation/etc.
130141
var jarArtifactForIde = jar.getClassJar() != null ? jar.getClassJar() : jar.jarForIntellijLibrary();
131142
if (jarArtifactForIde.isMainWorkspaceSourceArtifact()) {
132-
var jarPath = forPosix(locationDecoder.resolveSource(jarArtifactForIde).toString());
143+
IPath jarPath;
144+
try {
145+
jarPath = getPath(locationDecoder.resolveSource(jarArtifactForIde).toString());
146+
} catch (IOException e) {
147+
LOG.error(e.getMessage(), e);
148+
return null;
149+
}
133150
var sourceJar = jar.getSourceJars().stream().findFirst();
134151
if (!sourceJar.isPresent()) {
135152
if (LOG.isDebugEnabled()) {
@@ -140,8 +157,13 @@ public ClasspathEntry resolveJar(LibraryArtifact jar) {
140157
}
141158
return ClasspathEntry.newLibraryEntry(jarPath, null, null, false /* test only */);
142159
}
143-
144-
var srcJarPath = forPosix(locationDecoder.resolveSource(sourceJar.get()).toString());
160+
IPath srcJarPath;
161+
try {
162+
srcJarPath = getPath(locationDecoder.resolveSource(sourceJar.get()).toString());
163+
} catch (IOException e) {
164+
LOG.error(e.getMessage(), e);
165+
srcJarPath = null;
166+
}
145167
if (LOG.isDebugEnabled()) {
146168
LOG.debug(
147169
"Found jar for '{}': {} (source {})",
@@ -153,7 +175,13 @@ public ClasspathEntry resolveJar(LibraryArtifact jar) {
153175
}
154176
var jarArtifact = locationDecoder.resolveOutput(jarArtifactForIde);
155177
if (jarArtifact instanceof LocalFileArtifact localJar) {
156-
var jarPath = forPosix(localJar.getPath().toString());
178+
IPath jarPath;
179+
try {
180+
jarPath = getPath(localJar.getPath().toString());
181+
} catch (IOException e) {
182+
LOG.error(e.getMessage(), e);
183+
return null;
184+
}
157185
var sourceJar = jar.getSourceJars().stream().findFirst();
158186
if (!sourceJar.isPresent()) {
159187
if (LOG.isDebugEnabled()) {
@@ -163,7 +191,14 @@ public ClasspathEntry resolveJar(LibraryArtifact jar) {
163191
}
164192
var srcJarArtifact = locationDecoder.resolveOutput(sourceJar.get());
165193
if (srcJarArtifact instanceof LocalFileArtifact localSrcJar) {
166-
var srcJarPath = forPosix(localSrcJar.getPath().toString());
194+
var pathStr = org.eclipse.core.runtime.Path.fromOSString(localSrcJar.getPath().toString()).toString();
195+
IPath srcJarPath;
196+
try {
197+
srcJarPath = getPath(localSrcJar.getPath().toString());
198+
} catch (IOException e) {
199+
LOG.error(e.getMessage(), e);
200+
srcJarPath = null;
201+
}
167202
if (LOG.isDebugEnabled()) {
168203
LOG.debug(
169204
"Found jar for '{}': {} (source {})",

bundles/com.salesforce.bazel.importedsource/src-intellij-plugin/com/google/idea/blaze/base/sync/workspace/ArtifactLocationDecoderImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
import java.nio.file.Path;
1616
import java.util.Objects;
1717

18+
import org.eclipse.core.runtime.Platform;
19+
1820
import com.google.idea.blaze.base.command.buildresult.BlazeArtifact;
1921
import com.google.idea.blaze.base.command.buildresult.LocalFileOutputArtifact;
2022
import com.google.idea.blaze.base.command.buildresult.SourceArtifact;
@@ -74,6 +76,9 @@ public int hashCode() {
7476
private BlazeArtifact outputArtifactFromExecRoot(ArtifactLocation location) {
7577
// exec-root-relative path of the form 'blaze-out/mnemonic/genfiles/path'
7678
var execRootPath = location.getExecutionRootRelativePath();
79+
if (Platform.OS_WIN32.equals(Platform.getOS())) {
80+
execRootPath = org.eclipse.core.runtime.Path.fromOSString(execRootPath).toString();
81+
}
7782
var ix1 = execRootPath.indexOf('/');
7883
var ix2 = execRootPath.indexOf('/', ix1 + 1);
7984
if (ix2 == -1) {

0 commit comments

Comments
 (0)