Skip to content
Merged
Show file tree
Hide file tree
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
14 changes: 7 additions & 7 deletions src/main/java/com/bazel_diff/BazelClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.Arrays;

interface BazelClient {
List<BazelTarget> queryAllTargets() throws IOException;
Set<BazelSourceFileTarget> queryAllSourcefileTargets() throws IOException, NoSuchAlgorithmException;
Map<String, BazelSourceFileTarget> queryAllSourcefileTargets() throws IOException, NoSuchAlgorithmException;
}

class BazelClientImpl implements BazelClient {
Expand Down Expand Up @@ -54,12 +54,12 @@ public List<BazelTarget> queryAllTargets() throws IOException {
}

@Override
public Set<BazelSourceFileTarget> queryAllSourcefileTargets() throws IOException, NoSuchAlgorithmException {
public Map<String, BazelSourceFileTarget> queryAllSourcefileTargets() throws IOException, NoSuchAlgorithmException {
return processBazelSourcefileTargets(performBazelQuery("kind('source file', deps(//...))"), true);
}

private Set<BazelSourceFileTarget> processBazelSourcefileTargets(List<Build.Target> targets, Boolean readSourcefileTargets) throws IOException, NoSuchAlgorithmException {
Set<BazelSourceFileTarget> sourceTargets = new HashSet<>();
private Map<String, BazelSourceFileTarget> processBazelSourcefileTargets(List<Build.Target> targets, Boolean readSourcefileTargets) throws IOException, NoSuchAlgorithmException {
Map<String, BazelSourceFileTarget> sourceTargets = new HashMap<>();
for (Build.Target target : targets) {
Build.SourceFile sourceFile = target.getSourceFile();
if (sourceFile != null) {
Expand All @@ -73,7 +73,7 @@ private Set<BazelSourceFileTarget> processBazelSourcefileTargets(List<Build.Targ
digest.digest().clone(),
readSourcefileTargets ? workingDirectory : null
);
sourceTargets.add(sourceFileTarget);
sourceTargets.put(sourceFileTarget.getName(), sourceFileTarget);
}
}
return sourceTargets;
Expand Down
18 changes: 7 additions & 11 deletions src/main/java/com/bazel_diff/TargetHashingClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class TargetHashingClientImpl implements TargetHashingClient {

@Override
public Map<String, String> hashAllBazelTargetsAndSourcefiles(Set<Path> seedFilepaths) throws IOException, NoSuchAlgorithmException {
Set<BazelSourceFileTarget> bazelSourcefileTargets = bazelClient.queryAllSourcefileTargets();
Map<String, BazelSourceFileTarget> bazelSourcefileTargets = bazelClient.queryAllSourcefileTargets();
return hashAllTargets(createSeedForFilepaths(seedFilepaths), bazelSourcefileTargets);
}

Expand All @@ -47,7 +47,7 @@ public Set<String> getImpactedTargets(
private byte[] createDigestForTarget(
BazelTarget target,
Map<String, BazelRule> allRulesMap,
Set<BazelSourceFileTarget> bazelSourcefileTargets,
Map<String, BazelSourceFileTarget> bazelSourcefileTargets,
Map<String, byte[]> ruleHashes,
byte[] seedHash
) throws NoSuchAlgorithmException {
Expand All @@ -73,7 +73,7 @@ private byte[] createDigestForRule(
BazelRule rule,
Map<String, BazelRule> allRulesMap,
Map<String, byte[]> ruleHashes,
Set<BazelSourceFileTarget> bazelSourcefileTargets,
Map<String, BazelSourceFileTarget> bazelSourcefileTargets,
byte[] seedHash
) throws NoSuchAlgorithmException {
byte[] existingByteArray = ruleHashes.get(rule.getName());
Expand Down Expand Up @@ -122,14 +122,10 @@ private byte[] createSeedForFilepaths(Set<Path> seedFilepaths) throws IOExceptio

private byte[] getDigestForSourceTargetName(
String sourceTargetName,
Set<BazelSourceFileTarget> bazelSourcefileTargets
Map<String, BazelSourceFileTarget> bazelSourcefileTargets
) throws NoSuchAlgorithmException {
for (BazelSourceFileTarget sourceFileTarget : bazelSourcefileTargets) {
if (sourceFileTarget.getName().equals(sourceTargetName)) {
return sourceFileTarget.getDigest();
}
}
return null;
BazelSourceFileTarget target = bazelSourcefileTargets.get(sourceTargetName);
return target != null ? target.getDigest() : null;
}

private String convertByteArrayToString(byte[] bytes) {
Expand All @@ -150,7 +146,7 @@ private String getNameForTarget(BazelTarget target) {
return null;
}

private Map<String, String> hashAllTargets(byte[] seedHash, Set<BazelSourceFileTarget> bazelSourcefileTargets) throws IOException, NoSuchAlgorithmException {
private Map<String, String> hashAllTargets(byte[] seedHash, Map<String, BazelSourceFileTarget> bazelSourcefileTargets) throws IOException, NoSuchAlgorithmException {
List<BazelTarget> allTargets = bazelClient.queryAllTargets();
Map<String, String> targetHashes = new HashMap<>();
Map<String, byte[]> ruleHashes = new HashMap<>();
Expand Down