Skip to content
Permalink
Browse files

Merge pull request #15 from ikedam/feature/JENKINS-36894_Shortcuts

[JENKINS-36894] Introduce MatrixCombinationShortcut to generalize shortcut links
  • Loading branch information
ikedam committed Aug 27, 2016
2 parents 8cfa902 + cff3c22 commit 7bc42586da7945d3cf60438f3dd2a215fc36fd8e
Showing with 2,009 additions and 165 deletions.
  1. +69 −3 ...ain/java/hudson/plugins/matrix_configuration_parameter/MatrixCombinationsParameterDefinition.java
  2. +130 −0 src/main/java/hudson/plugins/matrix_configuration_parameter/shortcut/CombinationFilterShortcut.java
  3. +230 −0 src/main/java/hudson/plugins/matrix_configuration_parameter/shortcut/MatrixCombinationsShortcut.java
  4. +43 −0 .../hudson/plugins/matrix_configuration_parameter/shortcut/MatrixCombinationsShortcutDescriptor.java
  5. +105 −0 src/main/java/hudson/plugins/matrix_configuration_parameter/shortcut/PreviousShortcut.java
  6. +165 −0 src/main/java/hudson/plugins/matrix_configuration_parameter/shortcut/ResultShortcut.java
  7. +6 −0 .../hudson/plugins/matrix_configuration_parameter/MatrixCombinationsParameterDefinition/config.jelly
  8. +5 −0 ...ugins/matrix_configuration_parameter/MatrixCombinationsParameterDefinition/help-shortcutList.html
  9. +18 −54 .../hudson/plugins/matrix_configuration_parameter/MatrixCombinationsParameterDefinition/index.groovy
  10. +21 −7 ...ces/hudson/plugins/matrix_configuration_parameter/MatrixCombinationsParameterValue/rebuild.groovy
  11. +9 −5 ...urces/hudson/plugins/matrix_configuration_parameter/MatrixCombinationsParameterValue/value.groovy
  12. +32 −0 ...ces/hudson/plugins/matrix_configuration_parameter/shortcut/CombinationFilterShortcut/config.jelly
  13. +3 −0 ...ins/matrix_configuration_parameter/shortcut/CombinationFilterShortcut/help-combinationFilter.html
  14. +3 −0 ...s/hudson/plugins/matrix_configuration_parameter/shortcut/CombinationFilterShortcut/help-name.html
  15. +3 −0 ...ources/hudson/plugins/matrix_configuration_parameter/shortcut/CombinationFilterShortcut/help.html
  16. +3 −0 ...s/hudson/plugins/matrix_configuration_parameter/shortcut/MatrixCombinationsShortcut/All/help.html
  17. +3 −0 .../hudson/plugins/matrix_configuration_parameter/shortcut/MatrixCombinationsShortcut/None/help.html
  18. +26 −0 src/main/resources/hudson/plugins/matrix_configuration_parameter/shortcut/Messages.properties
  19. +3 −0 src/main/resources/hudson/plugins/matrix_configuration_parameter/shortcut/PreviousShortcut/help.html
  20. +43 −0 ...ain/resources/hudson/plugins/matrix_configuration_parameter/shortcut/ResultShortcut/config.groovy
  21. +3 −0 ...n/resources/hudson/plugins/matrix_configuration_parameter/shortcut/ResultShortcut/help-exact.html
  22. +3 −0 ...in/resources/hudson/plugins/matrix_configuration_parameter/shortcut/ResultShortcut/help-name.html
  23. +3 −0 ...es/hudson/plugins/matrix_configuration_parameter/shortcut/ResultShortcut/help-resultsToCheck.html
  24. +3 −0 src/main/resources/hudson/plugins/matrix_configuration_parameter/shortcut/ResultShortcut/help.html
  25. +3 −3 src/main/resources/hudson/plugins/matrix_configuration_parameter/taglib/matrix.jelly
  26. +59 −0 src/main/resources/hudson/plugins/matrix_configuration_parameter/taglib/shortcut.jelly
  27. +20 −0 src/main/resources/hudson/plugins/matrix_configuration_parameter/taglib/shortcut/shortcut.css
  28. +42 −0 src/main/resources/hudson/plugins/matrix_configuration_parameter/taglib/shortcut/shortcut.js
  29. +98 −0 src/test/java/hudson/plugins/matrix_configuration_parameter/ConditionalUnstablePublisher.java
  30. +48 −0 src/test/java/hudson/plugins/matrix_configuration_parameter/MatrixCombinationsJenkinsRule.java
  31. +170 −79 ...java/hudson/plugins/matrix_configuration_parameter/MatrixCombinationsParameterDefinitionTest.java
  32. +8 −12 ...test/java/hudson/plugins/matrix_configuration_parameter/MatrixCombinationsParameterValueTest.java
  33. +43 −2 ...hudson/plugins/matrix_configuration_parameter/MatrixCombinationsRebuildParameterProviderTest.java
  34. +132 −0 ...st/java/hudson/plugins/matrix_configuration_parameter/shortcut/CombinationFilterShortcutTest.java
  35. +187 −0 src/test/java/hudson/plugins/matrix_configuration_parameter/shortcut/PreviousShortcutTest.java
  36. +267 −0 src/test/java/hudson/plugins/matrix_configuration_parameter/shortcut/ResultShortcutTest.java
@@ -26,18 +26,30 @@
import hudson.Extension;
import hudson.model.ParameterDefinition;
import hudson.model.ParameterValue;

import hudson.model.Result;
import hudson.plugins.matrix_configuration_parameter.shortcut.MatrixCombinationsShortcut;
import hudson.plugins.matrix_configuration_parameter.shortcut.MatrixCombinationsShortcutDescriptor;
import hudson.plugins.matrix_configuration_parameter.shortcut.ResultShortcut;
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;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;


public class MatrixCombinationsParameterDefinition extends ParameterDefinition {

private static final long serialVersionUID = 1L;
private final String defaultCombinationFilter;
@SuppressFBWarnings(value="SE_BAD_FIELD")
private final List<MatrixCombinationsShortcut> shortcutList;

/**
* @return groovy expression to specify default checked combinations
@@ -46,16 +58,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 ResultShortcut("Successful", false, Result.SUCCESS),
new ResultShortcut("Failed", false, Result.FAILURE),
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 +153,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,0 +1,130 @@
/*
* The MIT License
*
* Copyright (c) 2016 IKEDA Yasuyuki
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package hudson.plugins.matrix_configuration_parameter.shortcut;

import java.util.Collection;

import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;

import org.kohsuke.stapler.DataBoundConstructor;

import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.collect.Collections2;

import hudson.Extension;
import hudson.Util;
import hudson.matrix.Combination;
import hudson.matrix.MatrixBuild;
import hudson.matrix.MatrixConfiguration;
import hudson.matrix.MatrixProject;

/**
* Shortcuts to select combinations with a filter expression
*/
public class CombinationFilterShortcut extends MatrixCombinationsShortcut {
private final String name;
private final String combinationFilter;

/**
* ctor
*
* @param name display name of the link
* @param combinationFilter filter expression
*/
@DataBoundConstructor
public CombinationFilterShortcut(String name, String combinationFilter) {
this.name = Util.fixNull(name);
this.combinationFilter = Util.fixNull(combinationFilter);
}

/**
* @return filter expression
*/
@Nonnull
public String getCombinationFilter() {
return combinationFilter;
}

/**
* {@inheritDoc}
*/
@Nonnull
@Override
public Collection<Combination> getCombinations(
@Nonnull final MatrixProject project,
@CheckForNull MatrixBuild build
) {
return Collections2.filter(
Collections2.transform(
project.getActiveConfigurations(),
new Function<MatrixConfiguration, Combination>() {
public Combination apply(MatrixConfiguration c) {
return c.getCombination();
}
}
),
new Predicate<Combination>() {
public boolean apply(Combination c) {
return c.evalGroovyExpression(project.getAxes(), getCombinationFilter());
}
}
);
}

/**
* {@inheritDoc}
*/
@Override
public String getName() {
return name;
}

/**
* {@inheritDoc}
*/
@Override
public String getId() {
return String.format(
"filter-%s",
getName().replaceAll("[^A-Za-z0-9]+", "-")
);
}

/**
* Descriptor for {@link CombinationFilterShortcut}
*/
@Extension
public static class DescriptorImpl extends MatrixCombinationsShortcutDescriptor {
/**
* {@inheritDoc}
*/
@Override
public String getDisplayName() {
return Messages.CombinationFilterShortcut_DisplayName();
}
}
}

0 comments on commit 7bc4258

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