-
Notifications
You must be signed in to change notification settings - Fork 316
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move `ProjectProtoTransform` interface to a top level class. Require transforms to be registered by the code that defined them, rather than creating them directly inside `ProjectLoader`. This allows the transforms be be defined more dynamically. Create a registry class to enable this and pass it into constructors where necessary. This also allows us to remove the equivalent method from `ArtifactTracker`. PiperOrigin-RevId: 605003949
- Loading branch information
1 parent
5263dee
commit 26003e9
Showing
7 changed files
with
99 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
querysync/java/com/google/idea/blaze/qsync/ProjectProtoTransform.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright 2024 The Bazel Authors. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.google.idea.blaze.qsync; | ||
|
||
import com.google.common.collect.Lists; | ||
import com.google.idea.blaze.common.Context; | ||
import com.google.idea.blaze.exception.BuildException; | ||
import com.google.idea.blaze.qsync.project.BuildGraphData; | ||
import com.google.idea.blaze.qsync.project.ProjectProto; | ||
import java.util.List; | ||
|
||
/** Applies a transform to a project proto instance, yielding a new instance. */ | ||
@FunctionalInterface | ||
public interface ProjectProtoTransform { | ||
|
||
/** | ||
* Apply the transform. | ||
* | ||
* @param proto The existing project proto. This is derived from {@code graph} and may have had | ||
* other transforms applied to it. | ||
* @param graph The graph from which {@code proto} was derived from. | ||
* @param context Context. | ||
* @return A project proto instance to replace the existing one. May return {@code proto} | ||
* unchanged if this transform doesn't need to change anything. | ||
*/ | ||
ProjectProto.Project apply(ProjectProto.Project proto, BuildGraphData graph, Context<?> context) | ||
throws BuildException; | ||
|
||
static ProjectProtoTransform compose(Iterable<ProjectProtoTransform> transforms) { | ||
return (proto, graph, context) -> { | ||
for (ProjectProtoTransform transform : transforms) { | ||
proto = transform.apply(proto, graph, context); | ||
} | ||
return proto; | ||
}; | ||
} | ||
|
||
/** | ||
* Simple registry for transforms that also supports returning all transforms combined into one. | ||
*/ | ||
class Registry { | ||
private final List<ProjectProtoTransform> transforms = Lists.newArrayList(); | ||
|
||
public void add(ProjectProtoTransform transform) { | ||
transforms.add(transform); | ||
} | ||
|
||
public ProjectProtoTransform getComposedTransform() { | ||
return compose(transforms); | ||
} | ||
} | ||
} |