Add a copy() method for Dependency.Builder.
Part of work on toolchain transitions,
@@ -58,6 +58,10 @@ public abstract class Dependency {
/** Sets the keys of a configuration transition. */
public Builder setTransitionKey(String key) {
+ if (key.isEmpty()) {
+ // Ignore empty keys.
+ return this;
+ }
return setTransitionKeys(ImmutableList.of(key));
}
@@ -77,6 +81,25 @@ public abstract class Dependency {
}
return dependency;
}
+
+ // Added to enable copy, below. Should not be accessible to other classes.
+ protected abstract Label getLabel();
+
+ @Nullable
+ protected abstract BuildConfiguration getConfiguration();
+
+ protected abstract AspectCollection getAspects();
+
+ protected abstract ImmutableList<String> getTransitionKeys();
+
+ /** Returns a copy of this Builder, with the values the same. */
+ public Builder copy() {
+ return Dependency.builder()
+ .setLabel(getLabel())
+ .setConfiguration(getConfiguration())
+ .setAspects(getAspects())
+ .setTransitionKeys(getTransitionKeys());
+ }
}
/** Returns a new {@link Builder} to create {@link Dependency} instances. */
