From f3645e7be2d94a7071ac08f2c18e7235fee4d619 Mon Sep 17 00:00:00 2001 From: Mihai Toader Date: Tue, 27 Aug 2024 17:31:33 -0700 Subject: [PATCH 1/7] [#6664] Add basic model for ExternalWorkspaces - 1/n --- .../base/model/AspectSyncProjectData.java | 12 +++++ .../blaze/base/model/BlazeProjectData.java | 2 + .../base/model/ExternalWorkspaceData.java | 45 +++++++++++++++++ .../model/primitives/ExternalWorkspace.java | 49 +++++++++++++++++++ proto/project_data.proto | 9 ++++ 5 files changed, 117 insertions(+) create mode 100644 base/src/com/google/idea/blaze/base/model/ExternalWorkspaceData.java create mode 100644 base/src/com/google/idea/blaze/base/model/primitives/ExternalWorkspace.java diff --git a/base/src/com/google/idea/blaze/base/model/AspectSyncProjectData.java b/base/src/com/google/idea/blaze/base/model/AspectSyncProjectData.java index ee79653fa05..34e306414ec 100644 --- a/base/src/com/google/idea/blaze/base/model/AspectSyncProjectData.java +++ b/base/src/com/google/idea/blaze/base/model/AspectSyncProjectData.java @@ -52,6 +52,7 @@ public final class AspectSyncProjectData implements BlazeProjectData { private final WorkspacePathResolver workspacePathResolver; private final ArtifactLocationDecoder artifactLocationDecoder; private final WorkspaceLanguageSettings workspaceLanguageSettings; + private final ExternalWorkspaceData externalWorkspaceData; private final SyncState syncState; public AspectSyncProjectData( @@ -61,6 +62,7 @@ public AspectSyncProjectData( WorkspacePathResolver workspacePathResolver, ArtifactLocationDecoder artifactLocationDecoder, WorkspaceLanguageSettings workspaceLanguageSettings, + ExternalWorkspaceData externalWorkspaceData, SyncState syncState) { this.targetData = targetData; this.blazeInfo = blazeInfo; @@ -68,6 +70,7 @@ public AspectSyncProjectData( this.workspacePathResolver = workspacePathResolver; this.artifactLocationDecoder = artifactLocationDecoder; this.workspaceLanguageSettings = workspaceLanguageSettings; + this.externalWorkspaceData = externalWorkspaceData; this.syncState = syncState; } @@ -85,6 +88,7 @@ public static AspectSyncProjectData fromProto( workspacePathResolver, new ArtifactLocationDecoderImpl(blazeInfo, workspacePathResolver, targetData.remoteOutputs), WorkspaceLanguageSettings.fromProto(proto.getWorkspaceLanguageSettings()), + ExternalWorkspaceData.fromProto(proto.getExternalWorkspaceData()), SyncState.fromProto(proto.getSyncState())); } @@ -112,6 +116,7 @@ public ProjectData.BlazeProjectData toProto() { .setWorkspacePathResolver(workspacePathResolver.toProto()) .setWorkspaceLanguageSettings(workspaceLanguageSettings.toProto()) .setSyncState(syncState.toProto()) + .setExternalWorkspaceData(externalWorkspaceData.toProto()) .build(); } @@ -187,6 +192,11 @@ public RemoteOutputArtifacts getRemoteOutputs() { return targetData.remoteOutputs; } + @Override + public ExternalWorkspaceData getExternalWorkspaceData() { + return externalWorkspaceData; + } + @Override public SyncState getSyncState() { return syncState; @@ -222,6 +232,7 @@ public boolean equals(Object o) { AspectSyncProjectData other = (AspectSyncProjectData) o; return Objects.equals(targetData, other.targetData) && Objects.equals(blazeInfo, other.blazeInfo) + && Objects.equals(externalWorkspaceData, other.externalWorkspaceData) && Objects.equals(blazeVersionData, other.blazeVersionData) && Objects.equals(workspacePathResolver, other.workspacePathResolver) && Objects.equals(artifactLocationDecoder, other.artifactLocationDecoder) @@ -238,6 +249,7 @@ public int hashCode() { workspaceLanguageSettings, artifactLocationDecoder, workspaceLanguageSettings, + externalWorkspaceData, syncState); } } diff --git a/base/src/com/google/idea/blaze/base/model/BlazeProjectData.java b/base/src/com/google/idea/blaze/base/model/BlazeProjectData.java index 0a2271bb6e0..399bc669991 100644 --- a/base/src/com/google/idea/blaze/base/model/BlazeProjectData.java +++ b/base/src/com/google/idea/blaze/base/model/BlazeProjectData.java @@ -51,6 +51,8 @@ public interface BlazeProjectData { RemoteOutputArtifacts getRemoteOutputs(); + ExternalWorkspaceData getExternalWorkspaceData(); + SyncState getSyncState(); boolean isQuerySync(); diff --git a/base/src/com/google/idea/blaze/base/model/ExternalWorkspaceData.java b/base/src/com/google/idea/blaze/base/model/ExternalWorkspaceData.java new file mode 100644 index 00000000000..717099db6d9 --- /dev/null +++ b/base/src/com/google/idea/blaze/base/model/ExternalWorkspaceData.java @@ -0,0 +1,45 @@ +package com.google.idea.blaze.base.model; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.devtools.intellij.model.ProjectData; +import com.google.idea.blaze.base.ideinfo.ProtoWrapper; +import com.google.idea.blaze.base.model.primitives.ExternalWorkspace; + +public final class ExternalWorkspaceData implements ProtoWrapper { + public ImmutableMap workspaces; + + public static ExternalWorkspaceData EMPTY = new ExternalWorkspaceData(ImmutableList.of()); + + public static ExternalWorkspaceData create(ImmutableList workspaces) { + return new ExternalWorkspaceData(workspaces); + } + + ExternalWorkspaceData(ImmutableList workspaces) { + this.workspaces = ImmutableMap.copyOf( + workspaces + .stream() + .collect( + ImmutableMap.toImmutableMap( + ExternalWorkspace::name, + e -> e)) + ); + } + + @Override + public ProjectData.ExternalWorkspaceData toProto() { + ImmutableList protoWorkspaces = workspaces + .values() + .stream() + .map(ExternalWorkspace::toProto) + .collect(ImmutableList.toImmutableList()); + + return ProjectData.ExternalWorkspaceData.newBuilder() + .addAllWorkspaces(protoWorkspaces) + .build(); + } + + public static ExternalWorkspaceData fromProto(ProjectData.ExternalWorkspaceData proto) { + return new ExternalWorkspaceData(proto.getWorkspacesList().stream().map(ExternalWorkspace::fromProto).collect(ImmutableList.toImmutableList())); + } +} diff --git a/base/src/com/google/idea/blaze/base/model/primitives/ExternalWorkspace.java b/base/src/com/google/idea/blaze/base/model/primitives/ExternalWorkspace.java new file mode 100644 index 00000000000..72b04198936 --- /dev/null +++ b/base/src/com/google/idea/blaze/base/model/primitives/ExternalWorkspace.java @@ -0,0 +1,49 @@ +package com.google.idea.blaze.base.model.primitives; + +import com.google.devtools.intellij.model.ProjectData; + +import javax.annotation.Nullable; +import com.google.auto.value.AutoValue; +import com.google.idea.blaze.base.ideinfo.ProtoWrapper; + +@AutoValue +public abstract class ExternalWorkspace implements ProtoWrapper { + + public abstract String name(); + + @Nullable + public abstract String repoName(); + + public static ExternalWorkspace fromProto(ProjectData.ExternalWorkspace proto) { + return create(proto.getName(), proto.getRepoName()); + } + + @Override + public ProjectData.ExternalWorkspace toProto() { + ProjectData.ExternalWorkspace.Builder builder = ProjectData.ExternalWorkspace.newBuilder().setName(name()); + if (repoName() != null && !repoName().isEmpty()) { + builder = builder.setRepoName(repoName()); + } + return builder.build(); + } + + public static ExternalWorkspace create(String name, String repoName) { + ExternalWorkspace.Builder builder = ExternalWorkspace.builder().setName(name); + if (repoName != null && !repoName.isEmpty()) { + builder = builder.setRepoName(repoName); + } + return builder.build(); + } + + public static ExternalWorkspace.Builder builder() { + return new AutoValue_ExternalWorkspace.Builder(); + } + + @AutoValue.Builder + public abstract static class Builder { + public abstract Builder setName(String name); + public abstract Builder setRepoName(String repoName); + public abstract ExternalWorkspace build(); + } + +} diff --git a/proto/project_data.proto b/proto/project_data.proto index 377f689cbab..8b091bbb8ba 100644 --- a/proto/project_data.proto +++ b/proto/project_data.proto @@ -240,6 +240,14 @@ message SyncState { RemoteOutputArtifacts remote_output_artifacts = 7 [deprecated = true]; } +message ExternalWorkspace { + string name = 1; + string repo_name = 2; +} +message ExternalWorkspaceData { + repeated ExternalWorkspace workspaces = 1; +} + message BlazeProjectData { reserved 1; TargetMap target_map = 2 [deprecated = true]; @@ -249,4 +257,5 @@ message BlazeProjectData { WorkspaceLanguageSettings workspace_language_settings = 6; SyncState sync_state = 7; TargetData target_data = 8; + ExternalWorkspaceData external_workspace_data = 9; } From 1a543a47d642b5adc8a6f6c405fda6442b3d1ae1 Mon Sep 17 00:00:00 2001 From: Mihai Toader Date: Tue, 27 Aug 2024 17:37:50 -0700 Subject: [PATCH 2/7] Update MockProjectDataBuilder --- .../model/MockBlazeProjectDataBuilder.java | 244 +++++++++--------- 1 file changed, 129 insertions(+), 115 deletions(-) diff --git a/base/tests/utils/unit/com/google/idea/blaze/base/model/MockBlazeProjectDataBuilder.java b/base/tests/utils/unit/com/google/idea/blaze/base/model/MockBlazeProjectDataBuilder.java index 657cb1cc94d..d710be012e0 100644 --- a/base/tests/utils/unit/com/google/idea/blaze/base/model/MockBlazeProjectDataBuilder.java +++ b/base/tests/utils/unit/com/google/idea/blaze/base/model/MockBlazeProjectDataBuilder.java @@ -27,6 +27,7 @@ import com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoderImpl; import com.google.idea.blaze.base.sync.workspace.WorkspacePathResolver; import com.google.idea.blaze.base.sync.workspace.WorkspacePathResolverImpl; + import java.io.File; /** @@ -36,120 +37,133 @@ * objects using whatever data you have supplied if applicable. */ public class MockBlazeProjectDataBuilder { - private final WorkspaceRoot workspaceRoot; - - private TargetMap targetMap; - private String outputBase; - private BlazeInfo blazeInfo; - private BlazeVersionData blazeVersionData; - private WorkspacePathResolver workspacePathResolver; - private ArtifactLocationDecoder artifactLocationDecoder; - private WorkspaceLanguageSettings workspaceLanguageSettings; - private SyncState syncState; - - private MockBlazeProjectDataBuilder(WorkspaceRoot workspaceRoot) { - this.workspaceRoot = workspaceRoot; - } - - public static MockBlazeProjectDataBuilder builder() { - return builder(new WorkspaceRoot(new File("/"))); - } - - public static MockBlazeProjectDataBuilder builder(WorkspaceRoot workspaceRoot) { - return new MockBlazeProjectDataBuilder(workspaceRoot); - } - - @CanIgnoreReturnValue - public MockBlazeProjectDataBuilder setTargetMap(TargetMap targetMap) { - this.targetMap = targetMap; - return this; - } - - @CanIgnoreReturnValue - public MockBlazeProjectDataBuilder setOutputBase(String outputBase) { - this.outputBase = outputBase; - return this; - } - - @CanIgnoreReturnValue - public MockBlazeProjectDataBuilder setBlazeInfo(BlazeInfo blazeInfo) { - this.blazeInfo = blazeInfo; - return this; - } - - @CanIgnoreReturnValue - public MockBlazeProjectDataBuilder setBlazeVersionData(BlazeVersionData blazeVersionData) { - this.blazeVersionData = blazeVersionData; - return this; - } - - @CanIgnoreReturnValue - public MockBlazeProjectDataBuilder setWorkspacePathResolver( - WorkspacePathResolver workspacePathResolver) { - this.workspacePathResolver = workspacePathResolver; - return this; - } - - @CanIgnoreReturnValue - public MockBlazeProjectDataBuilder setArtifactLocationDecoder( - ArtifactLocationDecoder artifactLocationDecoder) { - this.artifactLocationDecoder = artifactLocationDecoder; - return this; - } - - @CanIgnoreReturnValue - public MockBlazeProjectDataBuilder setWorkspaceLanguageSettings( - WorkspaceLanguageSettings workspaceLanguageSettings) { - this.workspaceLanguageSettings = workspaceLanguageSettings; - return this; - } - - @CanIgnoreReturnValue - public MockBlazeProjectDataBuilder setSyncState(SyncState syncState) { - this.syncState = syncState; - return this; - } - - public BlazeProjectData build() { - TargetMap targetMap = - this.targetMap != null ? this.targetMap : new TargetMap(ImmutableMap.of()); - BlazeInfo blazeInfo = this.blazeInfo; - if (blazeInfo == null) { - String outputBase = this.outputBase != null ? this.outputBase : "/usr/workspace/1234"; - blazeInfo = - BlazeInfo.createMockBlazeInfo( - outputBase, - outputBase + "/execroot", - outputBase + "/execroot/bin", - outputBase + "/execroot/gen", - outputBase + "/execroot/testlogs"); + private final WorkspaceRoot workspaceRoot; + + private TargetMap targetMap; + private String outputBase; + private BlazeInfo blazeInfo; + private BlazeVersionData blazeVersionData; + private WorkspacePathResolver workspacePathResolver; + private ArtifactLocationDecoder artifactLocationDecoder; + private WorkspaceLanguageSettings workspaceLanguageSettings; + private ExternalWorkspaceData externalWorkspaceData; + private SyncState syncState; + + private MockBlazeProjectDataBuilder(WorkspaceRoot workspaceRoot) { + this.workspaceRoot = workspaceRoot; + } + + public static MockBlazeProjectDataBuilder builder() { + return builder(new WorkspaceRoot(new File("/"))); + } + + public static MockBlazeProjectDataBuilder builder(WorkspaceRoot workspaceRoot) { + return new MockBlazeProjectDataBuilder(workspaceRoot); + } + + @CanIgnoreReturnValue + public MockBlazeProjectDataBuilder setTargetMap(TargetMap targetMap) { + this.targetMap = targetMap; + return this; + } + + @CanIgnoreReturnValue + public MockBlazeProjectDataBuilder setOutputBase(String outputBase) { + this.outputBase = outputBase; + return this; + } + + @CanIgnoreReturnValue + public MockBlazeProjectDataBuilder setBlazeInfo(BlazeInfo blazeInfo) { + this.blazeInfo = blazeInfo; + return this; + } + + @CanIgnoreReturnValue + public MockBlazeProjectDataBuilder setBlazeVersionData(BlazeVersionData blazeVersionData) { + this.blazeVersionData = blazeVersionData; + return this; + } + + @CanIgnoreReturnValue + public MockBlazeProjectDataBuilder setWorkspacePathResolver( + WorkspacePathResolver workspacePathResolver) { + this.workspacePathResolver = workspacePathResolver; + return this; + } + + @CanIgnoreReturnValue + public MockBlazeProjectDataBuilder setArtifactLocationDecoder( + ArtifactLocationDecoder artifactLocationDecoder) { + this.artifactLocationDecoder = artifactLocationDecoder; + return this; + } + + @CanIgnoreReturnValue + public MockBlazeProjectDataBuilder setWorkspaceLanguageSettings( + WorkspaceLanguageSettings workspaceLanguageSettings) { + this.workspaceLanguageSettings = workspaceLanguageSettings; + return this; + } + + @CanIgnoreReturnValue + public MockBlazeProjectDataBuilder setExternalWorkspaceData(ExternalWorkspaceData externalWorkspaceData) { + this.externalWorkspaceData = externalWorkspaceData; + return this; + } + + @CanIgnoreReturnValue + public MockBlazeProjectDataBuilder setSyncState(SyncState syncState) { + this.syncState = syncState; + return this; + } + + public BlazeProjectData build() { + TargetMap targetMap = + this.targetMap != null ? this.targetMap : new TargetMap(ImmutableMap.of()); + BlazeInfo blazeInfo = this.blazeInfo; + if (blazeInfo == null) { + String outputBase = this.outputBase != null ? this.outputBase : "/usr/workspace/1234"; + blazeInfo = + BlazeInfo.createMockBlazeInfo( + outputBase, + outputBase + "/execroot", + outputBase + "/execroot/bin", + outputBase + "/execroot/gen", + outputBase + "/execroot/testlogs"); + } + BlazeVersionData blazeVersionData = + this.blazeVersionData != null ? this.blazeVersionData : BlazeVersionData.builder().build(); + WorkspacePathResolver workspacePathResolver = + this.workspacePathResolver != null + ? this.workspacePathResolver + : new WorkspacePathResolverImpl(workspaceRoot); + ArtifactLocationDecoder artifactLocationDecoder = + this.artifactLocationDecoder != null + ? this.artifactLocationDecoder + : new ArtifactLocationDecoderImpl( + blazeInfo, workspacePathResolver, RemoteOutputArtifacts.EMPTY); + WorkspaceLanguageSettings workspaceLanguageSettings = + this.workspaceLanguageSettings != null + ? this.workspaceLanguageSettings + : new WorkspaceLanguageSettings(WorkspaceType.JAVA, ImmutableSet.of()); + SyncState syncState = + this.syncState != null ? this.syncState : new SyncState(ImmutableMap.of()); + + ExternalWorkspaceData externalWorkspaceData = + this.externalWorkspaceData != null + ? this.externalWorkspaceData + : ExternalWorkspaceData.EMPTY; + + return new AspectSyncProjectData( + new ProjectTargetData( + targetMap, /* ideInterfaceState= */ null, RemoteOutputArtifacts.EMPTY), + blazeInfo, + blazeVersionData, + workspacePathResolver, + artifactLocationDecoder, + workspaceLanguageSettings, + externalWorkspaceData, + syncState); } - BlazeVersionData blazeVersionData = - this.blazeVersionData != null ? this.blazeVersionData : BlazeVersionData.builder().build(); - WorkspacePathResolver workspacePathResolver = - this.workspacePathResolver != null - ? this.workspacePathResolver - : new WorkspacePathResolverImpl(workspaceRoot); - ArtifactLocationDecoder artifactLocationDecoder = - this.artifactLocationDecoder != null - ? this.artifactLocationDecoder - : new ArtifactLocationDecoderImpl( - blazeInfo, workspacePathResolver, RemoteOutputArtifacts.EMPTY); - WorkspaceLanguageSettings workspaceLanguageSettings = - this.workspaceLanguageSettings != null - ? this.workspaceLanguageSettings - : new WorkspaceLanguageSettings(WorkspaceType.JAVA, ImmutableSet.of()); - SyncState syncState = - this.syncState != null ? this.syncState : new SyncState(ImmutableMap.of()); - - return new AspectSyncProjectData( - new ProjectTargetData( - targetMap, /* ideInterfaceState= */ null, RemoteOutputArtifacts.EMPTY), - blazeInfo, - blazeVersionData, - workspacePathResolver, - artifactLocationDecoder, - workspaceLanguageSettings, - syncState); - } } From e0c239bcfe3b43c634fd69a9fe27b96ca2931908 Mon Sep 17 00:00:00 2001 From: Mihai Toader Date: Tue, 27 Aug 2024 17:40:12 -0700 Subject: [PATCH 3/7] Fix code style --- .../base/model/ExternalWorkspaceData.java | 70 ++--- .../model/primitives/ExternalWorkspace.java | 58 ++-- .../model/MockBlazeProjectDataBuilder.java | 256 +++++++++--------- 3 files changed, 193 insertions(+), 191 deletions(-) diff --git a/base/src/com/google/idea/blaze/base/model/ExternalWorkspaceData.java b/base/src/com/google/idea/blaze/base/model/ExternalWorkspaceData.java index 717099db6d9..d0d4e9127a1 100644 --- a/base/src/com/google/idea/blaze/base/model/ExternalWorkspaceData.java +++ b/base/src/com/google/idea/blaze/base/model/ExternalWorkspaceData.java @@ -7,39 +7,39 @@ import com.google.idea.blaze.base.model.primitives.ExternalWorkspace; public final class ExternalWorkspaceData implements ProtoWrapper { - public ImmutableMap workspaces; - - public static ExternalWorkspaceData EMPTY = new ExternalWorkspaceData(ImmutableList.of()); - - public static ExternalWorkspaceData create(ImmutableList workspaces) { - return new ExternalWorkspaceData(workspaces); - } - - ExternalWorkspaceData(ImmutableList workspaces) { - this.workspaces = ImmutableMap.copyOf( - workspaces - .stream() - .collect( - ImmutableMap.toImmutableMap( - ExternalWorkspace::name, - e -> e)) - ); - } - - @Override - public ProjectData.ExternalWorkspaceData toProto() { - ImmutableList protoWorkspaces = workspaces - .values() - .stream() - .map(ExternalWorkspace::toProto) - .collect(ImmutableList.toImmutableList()); - - return ProjectData.ExternalWorkspaceData.newBuilder() - .addAllWorkspaces(protoWorkspaces) - .build(); - } - - public static ExternalWorkspaceData fromProto(ProjectData.ExternalWorkspaceData proto) { - return new ExternalWorkspaceData(proto.getWorkspacesList().stream().map(ExternalWorkspace::fromProto).collect(ImmutableList.toImmutableList())); - } + public ImmutableMap workspaces; + + public static ExternalWorkspaceData EMPTY = new ExternalWorkspaceData(ImmutableList.of()); + + public static ExternalWorkspaceData create(ImmutableList workspaces) { + return new ExternalWorkspaceData(workspaces); + } + + ExternalWorkspaceData(ImmutableList workspaces) { + this.workspaces = ImmutableMap.copyOf( + workspaces + .stream() + .collect( + ImmutableMap.toImmutableMap( + ExternalWorkspace::name, + e -> e)) + ); + } + + @Override + public ProjectData.ExternalWorkspaceData toProto() { + ImmutableList protoWorkspaces = workspaces + .values() + .stream() + .map(ExternalWorkspace::toProto) + .collect(ImmutableList.toImmutableList()); + + return ProjectData.ExternalWorkspaceData.newBuilder() + .addAllWorkspaces(protoWorkspaces) + .build(); + } + + public static ExternalWorkspaceData fromProto(ProjectData.ExternalWorkspaceData proto) { + return new ExternalWorkspaceData(proto.getWorkspacesList().stream().map(ExternalWorkspace::fromProto).collect(ImmutableList.toImmutableList())); + } } diff --git a/base/src/com/google/idea/blaze/base/model/primitives/ExternalWorkspace.java b/base/src/com/google/idea/blaze/base/model/primitives/ExternalWorkspace.java index 72b04198936..2fec441c34b 100644 --- a/base/src/com/google/idea/blaze/base/model/primitives/ExternalWorkspace.java +++ b/base/src/com/google/idea/blaze/base/model/primitives/ExternalWorkspace.java @@ -3,47 +3,49 @@ import com.google.devtools.intellij.model.ProjectData; import javax.annotation.Nullable; + import com.google.auto.value.AutoValue; import com.google.idea.blaze.base.ideinfo.ProtoWrapper; @AutoValue public abstract class ExternalWorkspace implements ProtoWrapper { - public abstract String name(); + public abstract String name(); - @Nullable - public abstract String repoName(); + @Nullable + public abstract String repoName(); - public static ExternalWorkspace fromProto(ProjectData.ExternalWorkspace proto) { - return create(proto.getName(), proto.getRepoName()); - } + public static ExternalWorkspace fromProto(ProjectData.ExternalWorkspace proto) { + return create(proto.getName(), proto.getRepoName()); + } - @Override - public ProjectData.ExternalWorkspace toProto() { - ProjectData.ExternalWorkspace.Builder builder = ProjectData.ExternalWorkspace.newBuilder().setName(name()); - if (repoName() != null && !repoName().isEmpty()) { - builder = builder.setRepoName(repoName()); - } - return builder.build(); + @Override + public ProjectData.ExternalWorkspace toProto() { + ProjectData.ExternalWorkspace.Builder builder = ProjectData.ExternalWorkspace.newBuilder().setName(name()); + if (repoName() != null && !repoName().isEmpty()) { + builder = builder.setRepoName(repoName()); } + return builder.build(); + } - public static ExternalWorkspace create(String name, String repoName) { - ExternalWorkspace.Builder builder = ExternalWorkspace.builder().setName(name); - if (repoName != null && !repoName.isEmpty()) { - builder = builder.setRepoName(repoName); - } - return builder.build(); + public static ExternalWorkspace create(String name, String repoName) { + ExternalWorkspace.Builder builder = ExternalWorkspace.builder().setName(name); + if (repoName != null && !repoName.isEmpty()) { + builder = builder.setRepoName(repoName); } + return builder.build(); + } - public static ExternalWorkspace.Builder builder() { - return new AutoValue_ExternalWorkspace.Builder(); - } + public static ExternalWorkspace.Builder builder() { + return new AutoValue_ExternalWorkspace.Builder(); + } - @AutoValue.Builder - public abstract static class Builder { - public abstract Builder setName(String name); - public abstract Builder setRepoName(String repoName); - public abstract ExternalWorkspace build(); - } + @AutoValue.Builder + public abstract static class Builder { + public abstract Builder setName(String name); + + public abstract Builder setRepoName(String repoName); + public abstract ExternalWorkspace build(); + } } diff --git a/base/tests/utils/unit/com/google/idea/blaze/base/model/MockBlazeProjectDataBuilder.java b/base/tests/utils/unit/com/google/idea/blaze/base/model/MockBlazeProjectDataBuilder.java index d710be012e0..8095771e1a2 100644 --- a/base/tests/utils/unit/com/google/idea/blaze/base/model/MockBlazeProjectDataBuilder.java +++ b/base/tests/utils/unit/com/google/idea/blaze/base/model/MockBlazeProjectDataBuilder.java @@ -37,133 +37,133 @@ * objects using whatever data you have supplied if applicable. */ public class MockBlazeProjectDataBuilder { - private final WorkspaceRoot workspaceRoot; - - private TargetMap targetMap; - private String outputBase; - private BlazeInfo blazeInfo; - private BlazeVersionData blazeVersionData; - private WorkspacePathResolver workspacePathResolver; - private ArtifactLocationDecoder artifactLocationDecoder; - private WorkspaceLanguageSettings workspaceLanguageSettings; - private ExternalWorkspaceData externalWorkspaceData; - private SyncState syncState; - - private MockBlazeProjectDataBuilder(WorkspaceRoot workspaceRoot) { - this.workspaceRoot = workspaceRoot; - } - - public static MockBlazeProjectDataBuilder builder() { - return builder(new WorkspaceRoot(new File("/"))); - } - - public static MockBlazeProjectDataBuilder builder(WorkspaceRoot workspaceRoot) { - return new MockBlazeProjectDataBuilder(workspaceRoot); - } - - @CanIgnoreReturnValue - public MockBlazeProjectDataBuilder setTargetMap(TargetMap targetMap) { - this.targetMap = targetMap; - return this; - } - - @CanIgnoreReturnValue - public MockBlazeProjectDataBuilder setOutputBase(String outputBase) { - this.outputBase = outputBase; - return this; - } - - @CanIgnoreReturnValue - public MockBlazeProjectDataBuilder setBlazeInfo(BlazeInfo blazeInfo) { - this.blazeInfo = blazeInfo; - return this; - } - - @CanIgnoreReturnValue - public MockBlazeProjectDataBuilder setBlazeVersionData(BlazeVersionData blazeVersionData) { - this.blazeVersionData = blazeVersionData; - return this; - } - - @CanIgnoreReturnValue - public MockBlazeProjectDataBuilder setWorkspacePathResolver( - WorkspacePathResolver workspacePathResolver) { - this.workspacePathResolver = workspacePathResolver; - return this; - } - - @CanIgnoreReturnValue - public MockBlazeProjectDataBuilder setArtifactLocationDecoder( - ArtifactLocationDecoder artifactLocationDecoder) { - this.artifactLocationDecoder = artifactLocationDecoder; - return this; - } - - @CanIgnoreReturnValue - public MockBlazeProjectDataBuilder setWorkspaceLanguageSettings( - WorkspaceLanguageSettings workspaceLanguageSettings) { - this.workspaceLanguageSettings = workspaceLanguageSettings; - return this; - } - - @CanIgnoreReturnValue - public MockBlazeProjectDataBuilder setExternalWorkspaceData(ExternalWorkspaceData externalWorkspaceData) { - this.externalWorkspaceData = externalWorkspaceData; - return this; - } - - @CanIgnoreReturnValue - public MockBlazeProjectDataBuilder setSyncState(SyncState syncState) { - this.syncState = syncState; - return this; - } - - public BlazeProjectData build() { - TargetMap targetMap = - this.targetMap != null ? this.targetMap : new TargetMap(ImmutableMap.of()); - BlazeInfo blazeInfo = this.blazeInfo; - if (blazeInfo == null) { - String outputBase = this.outputBase != null ? this.outputBase : "/usr/workspace/1234"; - blazeInfo = - BlazeInfo.createMockBlazeInfo( - outputBase, - outputBase + "/execroot", - outputBase + "/execroot/bin", - outputBase + "/execroot/gen", - outputBase + "/execroot/testlogs"); - } - BlazeVersionData blazeVersionData = - this.blazeVersionData != null ? this.blazeVersionData : BlazeVersionData.builder().build(); - WorkspacePathResolver workspacePathResolver = - this.workspacePathResolver != null - ? this.workspacePathResolver - : new WorkspacePathResolverImpl(workspaceRoot); - ArtifactLocationDecoder artifactLocationDecoder = - this.artifactLocationDecoder != null - ? this.artifactLocationDecoder - : new ArtifactLocationDecoderImpl( - blazeInfo, workspacePathResolver, RemoteOutputArtifacts.EMPTY); - WorkspaceLanguageSettings workspaceLanguageSettings = - this.workspaceLanguageSettings != null - ? this.workspaceLanguageSettings - : new WorkspaceLanguageSettings(WorkspaceType.JAVA, ImmutableSet.of()); - SyncState syncState = - this.syncState != null ? this.syncState : new SyncState(ImmutableMap.of()); - - ExternalWorkspaceData externalWorkspaceData = - this.externalWorkspaceData != null - ? this.externalWorkspaceData - : ExternalWorkspaceData.EMPTY; - - return new AspectSyncProjectData( - new ProjectTargetData( - targetMap, /* ideInterfaceState= */ null, RemoteOutputArtifacts.EMPTY), - blazeInfo, - blazeVersionData, - workspacePathResolver, - artifactLocationDecoder, - workspaceLanguageSettings, - externalWorkspaceData, - syncState); + private final WorkspaceRoot workspaceRoot; + + private TargetMap targetMap; + private String outputBase; + private BlazeInfo blazeInfo; + private BlazeVersionData blazeVersionData; + private WorkspacePathResolver workspacePathResolver; + private ArtifactLocationDecoder artifactLocationDecoder; + private WorkspaceLanguageSettings workspaceLanguageSettings; + private ExternalWorkspaceData externalWorkspaceData; + private SyncState syncState; + + private MockBlazeProjectDataBuilder(WorkspaceRoot workspaceRoot) { + this.workspaceRoot = workspaceRoot; + } + + public static MockBlazeProjectDataBuilder builder() { + return builder(new WorkspaceRoot(new File("/"))); + } + + public static MockBlazeProjectDataBuilder builder(WorkspaceRoot workspaceRoot) { + return new MockBlazeProjectDataBuilder(workspaceRoot); + } + + @CanIgnoreReturnValue + public MockBlazeProjectDataBuilder setTargetMap(TargetMap targetMap) { + this.targetMap = targetMap; + return this; + } + + @CanIgnoreReturnValue + public MockBlazeProjectDataBuilder setOutputBase(String outputBase) { + this.outputBase = outputBase; + return this; + } + + @CanIgnoreReturnValue + public MockBlazeProjectDataBuilder setBlazeInfo(BlazeInfo blazeInfo) { + this.blazeInfo = blazeInfo; + return this; + } + + @CanIgnoreReturnValue + public MockBlazeProjectDataBuilder setBlazeVersionData(BlazeVersionData blazeVersionData) { + this.blazeVersionData = blazeVersionData; + return this; + } + + @CanIgnoreReturnValue + public MockBlazeProjectDataBuilder setWorkspacePathResolver( + WorkspacePathResolver workspacePathResolver) { + this.workspacePathResolver = workspacePathResolver; + return this; + } + + @CanIgnoreReturnValue + public MockBlazeProjectDataBuilder setArtifactLocationDecoder( + ArtifactLocationDecoder artifactLocationDecoder) { + this.artifactLocationDecoder = artifactLocationDecoder; + return this; + } + + @CanIgnoreReturnValue + public MockBlazeProjectDataBuilder setWorkspaceLanguageSettings( + WorkspaceLanguageSettings workspaceLanguageSettings) { + this.workspaceLanguageSettings = workspaceLanguageSettings; + return this; + } + + @CanIgnoreReturnValue + public MockBlazeProjectDataBuilder setExternalWorkspaceData(ExternalWorkspaceData externalWorkspaceData) { + this.externalWorkspaceData = externalWorkspaceData; + return this; + } + + @CanIgnoreReturnValue + public MockBlazeProjectDataBuilder setSyncState(SyncState syncState) { + this.syncState = syncState; + return this; + } + + public BlazeProjectData build() { + TargetMap targetMap = + this.targetMap != null ? this.targetMap : new TargetMap(ImmutableMap.of()); + BlazeInfo blazeInfo = this.blazeInfo; + if (blazeInfo == null) { + String outputBase = this.outputBase != null ? this.outputBase : "/usr/workspace/1234"; + blazeInfo = + BlazeInfo.createMockBlazeInfo( + outputBase, + outputBase + "/execroot", + outputBase + "/execroot/bin", + outputBase + "/execroot/gen", + outputBase + "/execroot/testlogs"); } + BlazeVersionData blazeVersionData = + this.blazeVersionData != null ? this.blazeVersionData : BlazeVersionData.builder().build(); + WorkspacePathResolver workspacePathResolver = + this.workspacePathResolver != null + ? this.workspacePathResolver + : new WorkspacePathResolverImpl(workspaceRoot); + ArtifactLocationDecoder artifactLocationDecoder = + this.artifactLocationDecoder != null + ? this.artifactLocationDecoder + : new ArtifactLocationDecoderImpl( + blazeInfo, workspacePathResolver, RemoteOutputArtifacts.EMPTY); + WorkspaceLanguageSettings workspaceLanguageSettings = + this.workspaceLanguageSettings != null + ? this.workspaceLanguageSettings + : new WorkspaceLanguageSettings(WorkspaceType.JAVA, ImmutableSet.of()); + SyncState syncState = + this.syncState != null ? this.syncState : new SyncState(ImmutableMap.of()); + + ExternalWorkspaceData externalWorkspaceData = + this.externalWorkspaceData != null + ? this.externalWorkspaceData + : ExternalWorkspaceData.EMPTY; + + return new AspectSyncProjectData( + new ProjectTargetData( + targetMap, /* ideInterfaceState= */ null, RemoteOutputArtifacts.EMPTY), + blazeInfo, + blazeVersionData, + workspacePathResolver, + artifactLocationDecoder, + workspaceLanguageSettings, + externalWorkspaceData, + syncState); + } } From 59f12c5fc11a0903a9529b121841b7ca613dadf2 Mon Sep 17 00:00:00 2001 From: Mihai Toader Date: Tue, 27 Aug 2024 17:44:18 -0700 Subject: [PATCH 4/7] Use `Functions.identity()` --- .../google/idea/blaze/base/model/ExternalWorkspaceData.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/base/src/com/google/idea/blaze/base/model/ExternalWorkspaceData.java b/base/src/com/google/idea/blaze/base/model/ExternalWorkspaceData.java index d0d4e9127a1..888b22c99f6 100644 --- a/base/src/com/google/idea/blaze/base/model/ExternalWorkspaceData.java +++ b/base/src/com/google/idea/blaze/base/model/ExternalWorkspaceData.java @@ -1,5 +1,6 @@ package com.google.idea.blaze.base.model; +import com.google.common.base.Functions; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.devtools.intellij.model.ProjectData; @@ -22,7 +23,7 @@ public static ExternalWorkspaceData create(ImmutableList work .collect( ImmutableMap.toImmutableMap( ExternalWorkspace::name, - e -> e)) + Functions.identity())) ); } From 96df3ab509bf8e053795cbca5494d0835ab7383c Mon Sep 17 00:00:00 2001 From: Mihai Toader Date: Tue, 27 Aug 2024 17:48:56 -0700 Subject: [PATCH 5/7] Add rest of the dependencies --- .../idea/blaze/base/qsync/QuerySyncProjectData.java | 12 +++++++++++- .../idea/blaze/base/sync/ProjectUpdateSyncTask.java | 2 ++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/base/src/com/google/idea/blaze/base/qsync/QuerySyncProjectData.java b/base/src/com/google/idea/blaze/base/qsync/QuerySyncProjectData.java index f0dce652b5f..344edd520a6 100644 --- a/base/src/com/google/idea/blaze/base/qsync/QuerySyncProjectData.java +++ b/base/src/com/google/idea/blaze/base/qsync/QuerySyncProjectData.java @@ -23,6 +23,7 @@ import com.google.idea.blaze.base.ideinfo.TargetMap; import com.google.idea.blaze.base.model.BlazeProjectData; import com.google.idea.blaze.base.model.BlazeVersionData; +import com.google.idea.blaze.base.model.ExternalWorkspaceData; import com.google.idea.blaze.base.model.RemoteOutputArtifacts; import com.google.idea.blaze.base.model.SyncState; import com.google.idea.blaze.base.model.primitives.Label; @@ -34,12 +35,16 @@ import com.google.idea.blaze.qsync.project.ProjectTarget; import com.google.idea.blaze.qsync.project.QuerySyncLanguage; import com.intellij.openapi.diagnostic.Logger; + import java.nio.file.Path; import java.util.Collection; import java.util.Optional; + import org.jetbrains.annotations.Nullable; -/** Implementation of {@link BlazeProjectData} specific to querysync. */ +/** + * Implementation of {@link BlazeProjectData} specific to querysync. + */ public class QuerySyncProjectData implements BlazeProjectData { private static final Logger logger = Logger.getInstance(QuerySyncProjectData.class); @@ -174,6 +179,11 @@ public RemoteOutputArtifacts getRemoteOutputs() { throw new NotSupportedWithQuerySyncException("getRemoteOutputs"); } + @Override + public ExternalWorkspaceData getExternalWorkspaceData() { + throw new NotSupportedWithQuerySyncException("getExternalWorkspaceData"); + } + @Override public SyncState getSyncState() { throw new NotSupportedWithQuerySyncException("getSyncState"); diff --git a/base/src/com/google/idea/blaze/base/sync/ProjectUpdateSyncTask.java b/base/src/com/google/idea/blaze/base/sync/ProjectUpdateSyncTask.java index da54547444b..681e1e0ec47 100644 --- a/base/src/com/google/idea/blaze/base/sync/ProjectUpdateSyncTask.java +++ b/base/src/com/google/idea/blaze/base/sync/ProjectUpdateSyncTask.java @@ -28,6 +28,7 @@ import com.google.idea.blaze.base.model.BlazeLibrary; import com.google.idea.blaze.base.model.BlazeProjectData; import com.google.idea.blaze.base.model.BlazeVersionData; +import com.google.idea.blaze.base.model.ExternalWorkspaceData; import com.google.idea.blaze.base.model.ProjectTargetData; import com.google.idea.blaze.base.model.RemoteOutputArtifacts; import com.google.idea.blaze.base.model.SyncState; @@ -227,6 +228,7 @@ private void run(BlazeContext context) throws SyncCanceledException, SyncFailedE projectState.getWorkspacePathResolver(), artifactLocationDecoder, projectState.getLanguageSettings(), + ExternalWorkspaceData.EMPTY, syncStateBuilder.build()); FileCaches.onSync( From bbfb4a0bc56e80795830ff45d48761f701af0ded Mon Sep 17 00:00:00 2001 From: Mihai Toader Date: Tue, 27 Aug 2024 17:58:42 -0700 Subject: [PATCH 6/7] Avoid some unnecessary changes --- .../google/idea/blaze/base/qsync/QuerySyncProjectData.java | 4 +--- proto/project_data.proto | 1 + 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/base/src/com/google/idea/blaze/base/qsync/QuerySyncProjectData.java b/base/src/com/google/idea/blaze/base/qsync/QuerySyncProjectData.java index 344edd520a6..a846b449019 100644 --- a/base/src/com/google/idea/blaze/base/qsync/QuerySyncProjectData.java +++ b/base/src/com/google/idea/blaze/base/qsync/QuerySyncProjectData.java @@ -42,9 +42,7 @@ import org.jetbrains.annotations.Nullable; -/** - * Implementation of {@link BlazeProjectData} specific to querysync. - */ +/** Implementation of {@link BlazeProjectData} specific to querysync. */ public class QuerySyncProjectData implements BlazeProjectData { private static final Logger logger = Logger.getInstance(QuerySyncProjectData.class); diff --git a/proto/project_data.proto b/proto/project_data.proto index 8b091bbb8ba..bbaf7626a9f 100644 --- a/proto/project_data.proto +++ b/proto/project_data.proto @@ -244,6 +244,7 @@ message ExternalWorkspace { string name = 1; string repo_name = 2; } + message ExternalWorkspaceData { repeated ExternalWorkspace workspaces = 1; } From f1bafd1c3ea5606d0c050799cad3cb1c45d09750 Mon Sep 17 00:00:00 2001 From: Mihai Toader Date: Tue, 27 Aug 2024 18:03:57 -0700 Subject: [PATCH 7/7] Avoid some unnecessary changes --- .../idea/blaze/base/model/MockBlazeProjectDataBuilder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base/tests/utils/unit/com/google/idea/blaze/base/model/MockBlazeProjectDataBuilder.java b/base/tests/utils/unit/com/google/idea/blaze/base/model/MockBlazeProjectDataBuilder.java index 8095771e1a2..1d226a61060 100644 --- a/base/tests/utils/unit/com/google/idea/blaze/base/model/MockBlazeProjectDataBuilder.java +++ b/base/tests/utils/unit/com/google/idea/blaze/base/model/MockBlazeProjectDataBuilder.java @@ -142,7 +142,7 @@ public BlazeProjectData build() { this.artifactLocationDecoder != null ? this.artifactLocationDecoder : new ArtifactLocationDecoderImpl( - blazeInfo, workspacePathResolver, RemoteOutputArtifacts.EMPTY); + blazeInfo, workspacePathResolver, RemoteOutputArtifacts.EMPTY); WorkspaceLanguageSettings workspaceLanguageSettings = this.workspaceLanguageSettings != null ? this.workspaceLanguageSettings