Skip to content
Permalink
Browse files

Merge pull request #96 from jenkinsci/JENKINS-14591

[Fixed JENKINS-14591] migrate parameter options to extensible behavior
  • Loading branch information...
dalvizu committed Dec 6, 2016
2 parents aa6458c + 62192c7 commit 2a279e70a8fd7cbfeb25cd935781fa71bca60ba4
Showing with 1,486 additions and 407 deletions.
  1. +4 −5 src/main/java/au/com/centrumsystems/hudson/plugin/buildpipeline/BuildForm.java
  2. +155 −37 src/main/java/au/com/centrumsystems/hudson/plugin/buildpipeline/BuildPipelineView.java
  3. +0 −7 src/main/java/au/com/centrumsystems/hudson/plugin/buildpipeline/PipelineBuild.java
  4. +40 −0 ...ain/java/au/com/centrumsystems/hudson/plugin/buildpipeline/extension/AbstractNameValueHeader.java
  5. +87 −0 src/main/java/au/com/centrumsystems/hudson/plugin/buildpipeline/extension/BuildVariablesHeader.java
  6. +79 −0 src/main/java/au/com/centrumsystems/hudson/plugin/buildpipeline/extension/NullColumnHeader.java
  7. +92 −0 ...main/java/au/com/centrumsystems/hudson/plugin/buildpipeline/extension/ParametersActionHeader.java
  8. +85 −0 ...ain/java/au/com/centrumsystems/hudson/plugin/buildpipeline/extension/PipelineHeaderExtension.java
  9. +79 −0 src/main/java/au/com/centrumsystems/hudson/plugin/buildpipeline/extension/SimpleColumnHeader.java
  10. +79 −0 src/main/java/au/com/centrumsystems/hudson/plugin/buildpipeline/extension/SimpleRowHeader.java
  11. +137 −253 src/main/resources/au/com/centrumsystems/hudson/plugin/buildpipeline/BuildPipelineView/bpp.jelly
  12. +52 −38 ...urces/au/com/centrumsystems/hudson/plugin/buildpipeline/BuildPipelineView/configure-entries.jelly
  13. 0 ...ldPipelineView/{help-showPipelineParametersInHeaders.html → help-headerBoxParameterProvider.html}
  14. 0 ...ine/BuildPipelineView/{help-showPipelineParameters.html → help-revisionBoxParameterProvider.html}
  15. +7 −4 ...urces/au/com/centrumsystems/hudson/plugin/buildpipeline/DownstreamProjectGridBuilder/config.jelly
  16. +27 −0 ...umsystems/hudson/plugin/buildpipeline/extension/AbstractNameValueHeader/projectCardTemplate.jelly
  17. +37 −0 .../com/centrumsystems/hudson/plugin/buildpipeline/extension/AbstractNameValueHeader/rowHeader.jelly
  18. +14 −0 ...ces/au/com/centrumsystems/hudson/plugin/buildpipeline/extension/BuildVariablesHeader/config.jelly
  19. +11 −0 ...s/au/com/centrumsystems/hudson/plugin/buildpipeline/extension/NullColumnHeader/columnHeader.jelly
  20. +13 −0 ...sources/au/com/centrumsystems/hudson/plugin/buildpipeline/extension/NullColumnHeader/config.jelly
  21. +10 −0 ...m/centrumsystems/hudson/plugin/buildpipeline/extension/NullColumnHeader/projectCardTemplate.jelly
  22. +14 −0 ...s/au/com/centrumsystems/hudson/plugin/buildpipeline/extension/ParametersActionHeader/config.jelly
  23. +70 −0 ...m/centrumsystems/hudson/plugin/buildpipeline/extension/PipelineHeaderExtension/columnHeader.jelly
  24. +13 −0 ...urces/au/com/centrumsystems/hudson/plugin/buildpipeline/extension/SimpleColumnHeader/config.jelly
  25. +14 −0 ...centrumsystems/hudson/plugin/buildpipeline/extension/SimpleColumnHeader/projectCardTemplate.jelly
  26. +13 −0 ...esources/au/com/centrumsystems/hudson/plugin/buildpipeline/extension/SimpleRowHeader/config.jelly
  27. +17 −0 ...urces/au/com/centrumsystems/hudson/plugin/buildpipeline/extension/SimpleRowHeader/rowHeader.jelly
  28. +3 −27 ...test/java/au/com/centrumsystems/hudson/plugin/buildpipeline/BuildPipelineViewConstructorTest.java
  29. +5 −1 ...test/java/au/com/centrumsystems/hudson/plugin/buildpipeline/BuildPipelineViewDisplayNameTest.java
  30. +59 −33 src/test/java/au/com/centrumsystems/hudson/plugin/buildpipeline/BuildPipelineViewTest.java
  31. +65 −0 ...st/java/au/com/centrumsystems/hudson/plugin/buildpipeline/extension/BuildVariablesHeaderTest.java
  32. +48 −0 src/test/java/au/com/centrumsystems/hudson/plugin/buildpipeline/extension/NullColumnHeaderTest.java
  33. +83 −0 .../java/au/com/centrumsystems/hudson/plugin/buildpipeline/extension/ParametersActionHeaderTest.java
  34. +72 −0 src/test/java/au/com/centrumsystems/hudson/plugin/buildpipeline/extension/SimpleRowHeaderTest.java
  35. +1 −1 .../java/au/com/centrumsystems/hudson/plugin/buildpipeline/functionaltest/BuildPipelineViewTest.java
  36. +1 −1 ...java/au/com/centrumsystems/hudson/plugin/buildpipeline/testsupport/PipelineWebDriverTestBase.java
@@ -10,7 +10,6 @@
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;

import org.kohsuke.stapler.bind.JavaScriptMethod;
@@ -167,10 +166,6 @@ public boolean isManualTrigger() {
return pipelineBuild.isManualTrigger();
}

public Map<String, String> getParameters() {
return pipelineBuild.getBuildParameters();
}

public ArrayList<String> getParameterList() {
return parameters;
}
@@ -179,4 +174,8 @@ public Integer getProjectId() {
return projectId;
}

public AbstractBuild<?, ?> getCurrentBuild() {
return pipelineBuild.getCurrentBuild();
}

}
@@ -24,6 +24,11 @@
*/
package au.com.centrumsystems.hudson.plugin.buildpipeline;

import au.com.centrumsystems.hudson.plugin.buildpipeline.extension.NullColumnHeader;
import au.com.centrumsystems.hudson.plugin.buildpipeline.extension.PipelineHeaderExtension;
import au.com.centrumsystems.hudson.plugin.buildpipeline.extension.BuildVariablesHeader;
import au.com.centrumsystems.hudson.plugin.buildpipeline.extension.SimpleColumnHeader;
import au.com.centrumsystems.hudson.plugin.buildpipeline.extension.SimpleRowHeader;
import com.google.common.base.Splitter;
import com.google.common.collect.Iterables;

@@ -60,6 +65,7 @@
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
@@ -119,12 +125,32 @@
/** alwaysAllowManualTrigger. */
private boolean alwaysAllowManualTrigger = true;

/** showPipelineParameters. */
/**
* Whether to show pipeline parameter in the revision box
* @deprecated - replaced with revisionBoxParameterProvider, keep in place
* to migrate data
*/
@Deprecated
private boolean showPipelineParameters = true;

/** showPipelineParametersInHeaders */
/**
* What to show as a row header for pipelines
*/
private PipelineHeaderExtension rowHeaders;

/**
* Whether to show pipeline parameters in the header box
* @deprecated - replaced with headerBoxParameterProvider, keep in place
* to migrate data
*/
@Deprecated
private boolean showPipelineParametersInHeaders;

/**
* What to show as a column headers for jobs in the pipeline
*/
private PipelineHeaderExtension columnHeaders;

/**
* @deprecated
*
@@ -141,13 +167,6 @@
/** showPipelineDefinitionHeader. */
private boolean showPipelineDefinitionHeader;

/*
* Keep feature flag properties in one place so that it is easy to refactor them out later.
*/
/* Feature flags - START */

/* Feature flags - END */

/** A Logger object is used to log messages */
private static final Logger LOGGER = Logger.getLogger(BuildPipelineView.class.getName());

@@ -213,27 +232,35 @@ public BuildPipelineView(final String name, final String buildViewTitle,
* URL for the custom CSS file.
* @param selectedJob
* the first job name in the pipeline. it can be set to null when gridBuilder is passed.
* @param columnHeaders
* see {@link #columnHeaders}
* @param rowHeaders
* see {@link #rowHeaders}
*/
@DataBoundConstructor
public BuildPipelineView(final String name, final String buildViewTitle, final ProjectGridBuilder gridBuilder,
final String noOfDisplayedBuilds,
final boolean triggerOnlyLatestJob, final boolean alwaysAllowManualTrigger, final boolean showPipelineParameters,
final boolean showPipelineParametersInHeaders, final boolean showPipelineDefinitionHeader,
final int refreshFrequency, final String cssUrl, final String selectedJob) {
final int refreshFrequency, final String cssUrl, final String selectedJob,
final PipelineHeaderExtension columnHeaders,
final PipelineHeaderExtension rowHeaders) {
this(name, buildViewTitle, gridBuilder, noOfDisplayedBuilds, triggerOnlyLatestJob, cssUrl);
this.alwaysAllowManualTrigger = alwaysAllowManualTrigger;
this.showPipelineParameters = showPipelineParameters;
this.showPipelineParametersInHeaders = showPipelineParametersInHeaders;
this.showPipelineDefinitionHeader = showPipelineDefinitionHeader;
this.selectedJob = selectedJob;
this.columnHeaders = columnHeaders;
this.rowHeaders = rowHeaders;
//not exactly understanding the lifecycle here, but I want a default of 3
//(this is what the class variable is set to 3, if it's 0, set it to default, refresh of 0 does not make sense anyway)
if (refreshFrequency < 1) {
this.refreshFrequency = 3;
} else {
this.refreshFrequency = refreshFrequency;
}

//for remote api support
if (this.gridBuilder == null) {
if (this.selectedJob != null) {
@@ -249,6 +276,12 @@ public BuildPipelineView(final String name, final String buildViewTitle, final P
}

/**
* Migrate old data, set new fields
*
* @see
* <a href="https://wiki.jenkins-ci.org/display/JENKINS/Hint+on+retaining+backward+compatibility">
* Jenkins wiki entry on the subject</a>
*
* @return
* must be always 'this'
*/
@@ -257,7 +290,28 @@ protected Object readResolve() {
if (selectedJob != null) {
gridBuilder = new DownstreamProjectGridBuilder(selectedJob);
}
} else {
// safe to assume an existing install, check if we need to migrate
// header config
if (columnHeaders == null) {
if (!showPipelineDefinitionHeader) {
columnHeaders = new NullColumnHeader();
} else if (showPipelineParametersInHeaders) {
columnHeaders = new BuildVariablesHeader();
} else {
columnHeaders = new SimpleColumnHeader();
}
}
if (rowHeaders == null) {
if (showPipelineParameters) {
rowHeaders = new BuildVariablesHeader();
} else {
rowHeaders = new SimpleRowHeader();
}
}
}


return this;
}

@@ -296,6 +350,22 @@ public boolean isProjectParameterized() {
return getGridBuilder().startsWithParameters(this);
}

public PipelineHeaderExtension getColumnHeaders() {
return columnHeaders;
}

public void setColumnHeaders(PipelineHeaderExtension columnHeaders) {
this.columnHeaders = columnHeaders;
}

public PipelineHeaderExtension getRowHeaders() {
return rowHeaders;
}

public void setRowHeaders(PipelineHeaderExtension rowHeaders) {
this.rowHeaders = rowHeaders;
}

/**
* Checks whether the user has Configure permission for the current project.
*
@@ -492,8 +562,8 @@ private int triggerBuild(final AbstractProject<?, ?> triggerProject, final Abstr
final List<AbstractBuildParameters> configs = retrieveUpstreamProjectTriggerConfig(triggerProject, upstreamBuild);

if (configs == null) {
LOGGER.log(Level.SEVERE, "No upstream trigger found for this project" + triggerProject.getFullDisplayName());
throw new IllegalStateException("No upstream trigger found for this project" + triggerProject.getFullDisplayName());
LOGGER.log(Level.SEVERE, "No upstream trigger found for this project: " + triggerProject.getFullDisplayName());
throw new IllegalStateException("No upstream trigger found for this project: " + triggerProject.getFullDisplayName());
}

for (final AbstractBuildParameters config : configs) {
@@ -535,10 +605,16 @@ private int triggerBuild(final AbstractProject<?, ?> triggerProject, final Abstr

final BuildPipelineTrigger manualTrigger = upstreamProjectPublishersList.get(BuildPipelineTrigger.class);
if (manualTrigger != null) {
LOGGER.fine("Found Manual Trigger (BuildPipelineTrigger) found in upstream project publisher list ");
final Set<String> downstreamProjectsNames =
Sets.newHashSet(Splitter.on(",").trimResults().split(manualTrigger.getDownstreamProjectNames()));
LOGGER.fine("Downstream project names: " + downstreamProjectsNames);
// defect: requires full name in the trigger. But downstream is just fine!
if (downstreamProjectsNames.contains(project.getFullName())) {
configs = manualTrigger.getConfigs();
} else {
LOGGER.warning("Upstream project had a Manual Trigger for projects [" + downstreamProjectsNames
+ "], but that did not include our project [" + project.getFullName() + "]");
}
}

@@ -684,6 +760,52 @@ public ListBoxModel doFillNoOfDisplayedBuildsItems() {
return options;
}

/**
* @param condition
* if true, return it as part of the returned list
* @return
* a filtered and ordered list of descriptors matching the condition
*/
public List<Descriptor<PipelineHeaderExtension>> filter(Function<PipelineHeaderExtension, Boolean> condition) {
final List<Descriptor<PipelineHeaderExtension>> result = new ArrayList<Descriptor<PipelineHeaderExtension>>();
final List<PipelineHeaderExtension> applicableExtensions = new ArrayList<PipelineHeaderExtension>();
for (PipelineHeaderExtension extension : PipelineHeaderExtension.all()) {
if (condition.apply(extension)) {
applicableExtensions.add(extension);
}
}
Collections.sort(applicableExtensions);
for (PipelineHeaderExtension extension : applicableExtensions) {
result.add(extension.getDescriptor());
}
return result;
}

/**
* @return a list of PipelineHeaderExtension descriptors which can be used as a row header
*/
public List<Descriptor<PipelineHeaderExtension>> getRowHeaderDescriptors() {
return filter(new Function<PipelineHeaderExtension, Boolean>() {
@Override
public Boolean apply(PipelineHeaderExtension extension) {
return extension.appliesToRows();
}
});
}

/**
* @return a list of PipelineHeaderExtension descriptors which can be used as column headers
*/
public List<Descriptor<PipelineHeaderExtension>> getColumnHeaderDescriptors() {
return filter(new Function<PipelineHeaderExtension, Boolean>() {

@Override
public Boolean apply(PipelineHeaderExtension extension) {
return extension.appliesToColumns();
}
});
}

/**
* Display Console Output Link Style Items in the Edit View Page
*
@@ -698,6 +820,26 @@ public ListBoxModel doFillConsoleOutputLinkStyleItems() {
}
}

/**
* A function which accepts an argument and returns a result. Necessary to parameterize behavior,
* because we do not require JDK8 yet.
*
* @see <a href="http://docs.oracle.com/javase/8/docs/api/java/util/function/Function.html">
* JDK8 java.lang.Function
* </a>
*/
public interface Function<F, T> {

/**
* Applies this function to the argument
* @param input
* an input
* @return
* a result
*/
T apply(F input);
}

public String getBuildViewTitle() {
return buildViewTitle;
}
@@ -762,30 +904,6 @@ public void setAlwaysAllowManualTrigger(final boolean alwaysAllowManualTrigger)
this.alwaysAllowManualTrigger = alwaysAllowManualTrigger;
}

public boolean isShowPipelineParameters() {
return showPipelineParameters;
}

public String getShowPipelineParameters() {
return Boolean.toString(showPipelineParameters);
}

public void setShowPipelineParameters(final boolean showPipelineParameters) {
this.showPipelineParameters = showPipelineParameters;
}

public boolean isShowPipelineParametersInHeaders() {
return showPipelineParametersInHeaders;
}

public String getShowPipelineParametersInHeaders() {
return Boolean.toString(showPipelineParametersInHeaders);
}

public void setShowPipelineParametersInHeaders(final boolean showPipelineParametersInHeaders) {
this.showPipelineParametersInHeaders = showPipelineParametersInHeaders;
}

public int getRefreshFrequency() {
return refreshFrequency;
}
@@ -36,7 +36,6 @@
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;

import au.com.centrumsystems.hudson.plugin.util.BuildUtil;
@@ -513,12 +512,6 @@ public String getFormattedStartDate() {
return formattedStartTime;
}

/**
* @return a map including build parameters
*/
public Map<String, String> getBuildParameters() {
return BuildUtil.getUnsensitiveParameters(currentBuild);
}

public boolean isProjectDisabled() {
return getProject().isDisabled();
Oops, something went wrong.

0 comments on commit 2a279e7

Please sign in to comment.
You can’t perform that action at this time.