Skip to content

Commit 12397ef

Browse files
committed
Fix configuring external libraries on Windows
1 parent e04071b commit 12397ef

File tree

3 files changed

+53
-6
lines changed

3 files changed

+53
-6
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,14 @@ private String getExpectedOutput(Map<String, String> infoResult, BazelInfoKey ke
231231
}
232232

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

237244
public Stream<BazelRuleAttributes> getExternalRepositoriesByRuleClass(Predicate<String> ruleClassPredicate)

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)