Skip to content

Commit

Permalink
[#6721] Don't set ExternalWorkspace.repoName() to null when unchang…
Browse files Browse the repository at this point in the history
…ed (#6722)
  • Loading branch information
mtoader authored Sep 4, 2024
1 parent 50d87bf commit 04de8bc
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import javax.annotation.Nullable;


public final class ExternalWorkspaceData implements ProtoWrapper<ProjectData.ExternalWorkspaceData> {
public ImmutableMap<String, ExternalWorkspace> workspaces;

Expand All @@ -25,14 +24,15 @@ public static ExternalWorkspaceData create(ImmutableList<ExternalWorkspace> work
.stream()
.collect(
ImmutableMap.toImmutableMap(
ExternalWorkspace::repositoryName,
ExternalWorkspace::repoName,
Functions.identity()))
);
}

@Override
public ProjectData.ExternalWorkspaceData toProto() {
ProjectData.ExternalWorkspaceData.Builder builder = ProjectData.ExternalWorkspaceData.newBuilder();
ProjectData.ExternalWorkspaceData.Builder builder =
ProjectData.ExternalWorkspaceData.newBuilder();

for (ExternalWorkspace externalWorkspace : workspaces.values()) {
builder = builder.addWorkspaces(externalWorkspace.toProto());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,25 @@ public abstract class ExternalWorkspace implements ProtoWrapper<ProjectData.Exte

public abstract String name();

@Nullable
protected abstract String repoName();

public String repositoryName() {
return repoName() != null ? repoName() : name();
}
public abstract String repoName();

public static ExternalWorkspace fromProto(ProjectData.ExternalWorkspace proto) {
return create(proto.getName(), proto.getRepoName());
}

@Override
public ProjectData.ExternalWorkspace toProto() {
return
ProjectData.ExternalWorkspace.newBuilder()
.setName(name())
.setRepoName(repoName())
.build();
return ProjectData.ExternalWorkspace.newBuilder()
.setName(name())
.setRepoName(repoName())
.build();
}

public static ExternalWorkspace create(String name, String repoName) {
ExternalWorkspace.Builder builder = ExternalWorkspace.builder().setName(name);
if (repoName != null && !repoName.isEmpty() && repoName.compareTo(name) != 0) {
builder = builder.setRepoName(repoName);
}
return builder.build();
return ExternalWorkspace.builder()
.setName(name)
.setRepoName(repoName)
.build();
}

public static ExternalWorkspace.Builder builder() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.google.common.collect.ImmutableList;
import com.google.idea.blaze.base.ExternalWorkspaceFixture;
import com.google.idea.blaze.base.lang.buildfile.BuildFileIntegrationTestCase;
import com.google.idea.blaze.base.lang.buildfile.psi.BuildFile;
import com.google.idea.blaze.base.model.ExternalWorkspaceData;
import com.google.idea.blaze.base.model.primitives.ExternalWorkspace;
import com.google.idea.blaze.base.model.primitives.Label;
Expand Down Expand Up @@ -36,7 +35,7 @@ protected ExternalWorkspaceData mockExternalWorkspaceData() {
ExternalWorkspace.create("workspace_two", "com_workspace_two"), fileSystem);

return ExternalWorkspaceData.create(
ImmutableList.of(workspaceOne.w, workspaceTwoMapped.w));
ImmutableList.of(workspaceOne.workspace, workspaceTwoMapped.workspace));
}

@Before
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
import static org.junit.Assert.assertNotNull;

public class ExternalWorkspaceFixture {
public final ExternalWorkspace w;
public final ExternalWorkspace workspace;

final TestFileSystem fileSystem;
WorkspaceFileSystem workspaceFileSystem;

public ExternalWorkspaceFixture(ExternalWorkspace w, TestFileSystem fileSystem) {
this.w = w;
public ExternalWorkspaceFixture(ExternalWorkspace workspace, TestFileSystem fileSystem) {
this.workspace = workspace;
this.fileSystem = fileSystem;
}

Expand All @@ -44,7 +44,7 @@ WorkspaceFileSystem getWorkspaceFileSystem() {

WorkspaceRoot workspaceRoot = new WorkspaceRoot(Paths.get(
blazeProjectData.getBlazeInfo().getOutputBase().getAbsolutePath(),
"external", w.name()).normalize().toFile());
"external", workspace.name()).normalize().toFile());

File workspaceRootFile = workspaceRoot.directory();
assertThat(workspaceRootFile).isNotNull();
Expand All @@ -55,6 +55,6 @@ WorkspaceFileSystem getWorkspaceFileSystem() {
}

public Label createLabel(WorkspacePath packagePath, TargetName targetName) {
return Label.create(w.repositoryName(), packagePath, targetName);
return Label.create(workspace.repoName(), packagePath, targetName);
}
}
}

0 comments on commit 04de8bc

Please sign in to comment.