All Downloads are FREE. Search and download functionalities are using the official Maven repository.

hudson.model.ParametersAction Maven / Gradle / Ivy

The newest version!
/*******************************************************************************
 *
 * Copyright (c) 2004-2010 Oracle Corporation.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *
 *    Kohsuke Kawaguchi, Jean-Baptiste Quenot, Seiji Sogabe, Tom Huybrechts
 *
 *
 *******************************************************************************/ 

package hudson.model;

import hudson.Util;
import hudson.EnvVars;
import hudson.diagnosis.OldDataMonitor;
import hudson.model.Queue.QueueAction;
import hudson.model.labels.LabelAssignmentAction;
import hudson.model.queue.SubTask;
import hudson.tasks.BuildStep;
import hudson.tasks.BuildWrapper;
import hudson.util.VariableResolver;
import org.kohsuke.stapler.export.Exported;
import org.kohsuke.stapler.export.ExportedBean;

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

/**
 * Records the parameter values used for a build.
 *
 * 

This object is associated with the build record so that we remember what * parameters were used for what build. It is also attached to the queue item to * remember parameter that were specified when scheduling. */ @ExportedBean public class ParametersAction implements Action, Iterable, QueueAction, EnvironmentContributingAction, LabelAssignmentAction { private final List parameters; /** * @deprecated since 1.283; kept to avoid warnings loading old build data, * but now transient. */ private transient AbstractBuild build; public ParametersAction(List parameters) { this.parameters = parameters; } public ParametersAction(ParameterValue... parameters) { this(Arrays.asList(parameters)); } public void createBuildWrappers(AbstractBuild build, Collection result) { for (ParameterValue p : parameters) { BuildWrapper w = p.createBuildWrapper(build); if (w != null) { result.add(w); } } } public void buildEnvVars(AbstractBuild build, EnvVars env) { for (ParameterValue p : parameters) { p.buildEnvVars(build, env); } } /** * Performs a variable subsitution to the given text and return it. */ public String substitute(AbstractBuild build, String text) { return Util.replaceMacro(text, createVariableResolver(build)); } /** * Creates an {@link VariableResolver} that aggregates all the parameters. * *

If you are a {@link BuildStep}, most likely you should call * {@link AbstractBuild#getBuildVariableResolver()}. */ public VariableResolver createVariableResolver(AbstractBuild build) { VariableResolver[] resolvers = new VariableResolver[parameters.size() + 1]; int i = 0; for (ParameterValue p : parameters) { resolvers[i++] = p.createVariableResolver(build); } resolvers[i] = build.getBuildVariableResolver(); return new VariableResolver.Union(resolvers); } public Iterator iterator() { return parameters.iterator(); } @Exported(visibility = 2) public List getParameters() { return Collections.unmodifiableList(parameters); } public ParameterValue getParameter(String name) { for (ParameterValue p : parameters) { if (p.getName().equals(name)) { return p; } } return null; } @Override public Label getAssignedLabel(SubTask task) { for (ParameterValue p : parameters) { Label l = p.getAssignedLabel(task); if (l != null) { return l; } } return null; } public String getDisplayName() { return Messages.ParameterAction_DisplayName(); } public String getIconFileName() { return "document-properties.png"; } public String getUrlName() { return "parameters"; } /** * Allow an other build of the same project to be scheduled, if it has other * parameters. */ public boolean shouldSchedule(List actions) { List others = Util.filter(actions, ParametersAction.class); if (others.isEmpty()) { return !parameters.isEmpty(); } else { // I don't think we need multiple ParametersActions, but let's be defensive Set params = new HashSet(); for (ParametersAction other : others) { params.addAll(other.parameters); } return !params.equals(new HashSet(this.parameters)); } } private Object readResolve() { if (build != null) { OldDataMonitor.report(build, "1.283"); } return this; } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy