Revisited the abstraction. Allowing this method to return a mutable list, following the trend in the core to expose intelligent collection (as opposed to have the parent define CRUD methods.)

This commit is contained in:
Kohsuke Kawaguchi committed 2011-12-15 09:47:04 -08:00
1 parent 88de1669df
commit d373141fa2
2 files changed
+28 -14

No files matched your search

@@ -844,27 +844,26 @@ public abstract class AbstractBuild<P extends AbstractProject<P,R>,R extends Abs
/**
* During the build, expose the environments contributed by {@link BuildWrapper}s and others.
*
*
* <p>
* Since 1.444, executor thread that's doing the build can access mutable underlying list,
* which allows the caller to add/remove environments. The recommended way of adding
* environment is through {@link BuildWrapper}, but this might be handy for build steps
* who wants to expose additional environment variables to the rest of the build.
*
* @return can be empty list, but never null. Immutable.
* @since 1.437
*/
public EnvironmentList getEnvironments() {
Executor e = Executor.currentExecutor();
if (e!=null && e.getCurrentExecutable()==this) {
if (buildEnvironments==null) buildEnvironments = new ArrayList<Environment>();
return new EnvironmentList(buildEnvironments);
}
return new EnvironmentList(buildEnvironments==null ? Collections.<Environment>emptyList() : ImmutableList.copyOf(buildEnvironments));
}
/**
* Allows you to contribute an environment without going through {@link BuildWrapper}.
* <p>
* For concurrency, this method is only designed to be called from the executor that's doing a build,
* during the build.
*
* @since 1.444
*/
public void addEnvironment(Environment env) {
if (env!=null)
buildEnvironments.add(env);
}
public Calendar due() {
return getTimestamp();
}
@@ -56,4 +56,19 @@ public final class EnvironmentList extends AbstractList<Environment> {
}
return null;
}
@Override
public Environment set(int index, Environment element) {
return base.set(index, element);
}
@Override
public void add(int index, Environment element) {
base.add(index, element);
}
@Override
public Environment remove(int index) {
return base.remove(index);
}
}