Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import static org.eclipse.core.runtime.IPath.fromPath;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -74,6 +76,30 @@ static boolean isJavaProtoTarget(TargetIdeInfo target) {
|| target.getKind().equals(GenericBlazeRules.RuleTypes.PROTO_LIBRARY.getKind()));
}

/**
* Sanitizes a file path for use in a Bazel label by URL-decoding any percent-encoded characters. This is needed
* because external repository paths may contain URL-encoded characters (e.g., %40 for @) which are not valid in
* Bazel target names.
*
* @param path
* the potentially URL-encoded path
* @return the decoded path safe for use in a Bazel label
*/
private static String sanitizePathForLabel(String path) {
try {
// Decode URL-encoded characters (e.g., %40 -> @, %2F -> /)
return URLDecoder.decode(path, "UTF-8");
} catch (UnsupportedEncodingException e) {
// UTF-8 is always supported, but handle the exception just in case
LOG.warn("Failed to URL-decode path '{}', using original path", path, e);
return path;
} catch (IllegalArgumentException e) {
// Handle invalid escape sequences
LOG.warn("Path '{}' contains invalid URL encoding, using original path", path, e);
return path;
}
}

final ParsedBepOutput aspectsBuildResult;
final IntellijAspects intellijAspects;

Expand Down Expand Up @@ -168,7 +194,7 @@ public JavaAspectsInfo(ParsedBepOutput aspectsBuildResult, BazelWorkspace bazelW
"Unable to compute target label for runtime jar '{}'. Please check if the rule producing the jar is adding the Target-Label to the jar manifest!",
classJar);
}
targetLabel = Label.create(format("@_unknown_jar_//:%s", classJar.getRelativePath()));
targetLabel = Label.create(format("@_unknown_jar_//:%s", sanitizePathForLabel(classJar.getRelativePath())));
} else if (!targetLabel.isExternal()
&& !bazelWorkspace.getBazelPackage(new BazelLabel(targetLabel)).exists()) {
// possibly an external jar produced within an external repo
Expand All @@ -179,7 +205,7 @@ public JavaAspectsInfo(ParsedBepOutput aspectsBuildResult, BazelWorkspace bazelW
targetLabel,
classJar);
}
targetLabel = Label.create(format("@_unknown_jar_//:%s", classJar.getRelativePath()));
targetLabel = Label.create(format("@_unknown_jar_//:%s", sanitizePathForLabel(classJar.getRelativePath())));
}

var builder = LibraryArtifact.builder();
Expand Down
Loading