Skip to content
Permalink
Browse files

[JENKINS-36894] Introduce MatrixCombinationShortcut to generalize sho…

…rtcut links.
  • Loading branch information
ikedam committed Jul 31, 2016
1 parent 8cfa902 commit 4cca271ad51b0c77fb3d84824b0abbaf760950dc
@@ -26,9 +26,15 @@
import hudson.Extension;
import hudson.model.ParameterDefinition;
import hudson.model.ParameterValue;

import hudson.plugins.matrix_configuration_parameter.shortcut.MatrixCombinationsShortcut;
import hudson.plugins.matrix_configuration_parameter.shortcut.MatrixCombinationsShortcutDescriptor;
import net.sf.json.JSONObject;

import java.util.Arrays;
import java.util.List;

import javax.annotation.Nonnull;

import org.apache.commons.lang.StringUtils;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.StaplerRequest;
@@ -38,6 +44,7 @@

private static final long serialVersionUID = 1L;
private final String defaultCombinationFilter;
private final List<MatrixCombinationsShortcut> shortcutList;

/**
* @return groovy expression to specify default checked combinations
@@ -46,16 +53,60 @@ public String getDefaultCombinationFilter() {
return defaultCombinationFilter;
}

/**
* @return list of shortcuts
* @since 1.1.0
*/
@Nonnull
public List<MatrixCombinationsShortcut> getShortcutList() {
return shortcutList;
}

/**
* @return list of shortcuts that should be used as defaults
* @since 1.1.0
*/
public static List<MatrixCombinationsShortcut> getDefaultShortcutList() {
return Arrays.asList(
new MatrixCombinationsShortcut.Successful(),
new MatrixCombinationsShortcut.Failed(),
new MatrixCombinationsShortcut.All(),
new MatrixCombinationsShortcut.None()
);
}

/**
* ctor
*
* @param name the name of the parameter
* @param description the description for the parameter
* @param defaultCombinationFilter combinations filter to used to calculate default checks
* @param shortcutList the list of shortcuts to display
* @since 1.1.0
*/
@DataBoundConstructor
public MatrixCombinationsParameterDefinition(String name, String description, String defaultCombinationFilter) {
public MatrixCombinationsParameterDefinition(String name, String description, String defaultCombinationFilter, List<MatrixCombinationsShortcut> shortcutList) {
super(name, description);
this.defaultCombinationFilter = !StringUtils.isBlank(defaultCombinationFilter)?defaultCombinationFilter:null;
this.shortcutList = (shortcutList != null) ? shortcutList : getDefaultShortcutList();
}

public MatrixCombinationsParameterDefinition(String name, String description, String defaultCombinationFilter) {
this(name, description, defaultCombinationFilter, getDefaultShortcutList());
}

public MatrixCombinationsParameterDefinition(String name, String description) {
this(name, description, null);
}

private Object readResolve() {
if (this.shortcutList == null) {
// the one from < 1.1.0
return new MatrixCombinationsParameterDefinition(getName(), getDescription(), getDefaultCombinationFilter());
}
return this;
}

@Override
public ParameterValue createValue(StaplerRequest req, JSONObject jo) {
MatrixCombinationsParameterValue value = req.bindJSON(MatrixCombinationsParameterValue.class, jo);
@@ -97,7 +148,17 @@ public String getHelpFile() {
return "/plugin/matrix-configuration-parameter/help.html";
}


/**
* @return list of shortcuts that should be used as defaults
* @since 1.1.0
*/
public List<MatrixCombinationsShortcut> getDefaultShortcutList() {
return MatrixCombinationsParameterDefinition.getDefaultShortcutList();
}

public List<MatrixCombinationsShortcutDescriptor> getShortcutDescriptorList() {
return MatrixCombinationsShortcutDescriptor.all();
}
}

}

0 comments on commit 4cca271

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