Skip to content
Permalink
Browse files

[JENKINS-36894] Introduce ResultShortcut

  • Loading branch information
ikedam committed Aug 4, 2016
1 parent d3c99b9 commit 7cdea26d52dbb55e34fc4a8478465094ca264acc
@@ -26,8 +26,10 @@
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;
@@ -68,8 +70,8 @@ public String getDefaultCombinationFilter() {
*/
public static List<MatrixCombinationsShortcut> getDefaultShortcutList() {
return Arrays.asList(
new MatrixCombinationsShortcut.Successful(),
new MatrixCombinationsShortcut.Failed(),
new ResultShortcut("Successful", false, Result.SUCCESS),
new ResultShortcut("Failed", false, Result.FAILURE),
new MatrixCombinationsShortcut.All(),
new MatrixCombinationsShortcut.None()
);
@@ -34,7 +34,6 @@
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;
@@ -43,9 +42,7 @@
import hudson.matrix.MatrixBuild;
import hudson.matrix.MatrixConfiguration;
import hudson.matrix.MatrixProject;
import hudson.matrix.MatrixRun;
import hudson.model.AbstractDescribableImpl;
import hudson.model.Result;

/**
* Defines shortcut link to select a set of axes combinations.
@@ -93,16 +90,14 @@ public String apply(Combination c) {
/**
* @return name used for the link text.
*/
public String getName() {
return getDescriptor().getDisplayName();
}
@Nonnull
public abstract String getName();

/**
* @return name used to distinguish links.
*/
public String getLinkId() {
return getDescriptor().getId().replace('.', '-').replace('$', '-');
}
@Nonnull
public abstract String getId();

/**
* {@inheritDoc}
@@ -113,14 +108,14 @@ public MatrixCombinationsShortcutDescriptor getDescriptor() {
}

/**
* Checks all combinations with successful builds.
* Checks all combinations.
*/
public static class Successful extends MatrixCombinationsShortcut {
public static class All extends MatrixCombinationsShortcut {
/**
* ctor
*/
@DataBoundConstructor
public Successful() {
public All() {
}

/**
@@ -131,108 +126,56 @@ public Successful() {
@Nonnull MatrixProject project,
@CheckForNull MatrixBuild build
) {
if (build == null) {
return Collections.emptyList();
}
return Collections2.transform(
Collections2.filter(
build.getRuns(),
new Predicate<MatrixRun>() {
public boolean apply(MatrixRun r) {
Result result = r.getResult();
return (result != null)
&& result.isBetterOrEqualTo(Result.SUCCESS);
}
}
),
new Function<MatrixRun, Combination>() {
public Combination apply(MatrixRun r) {
return r.getParent().getCombination();
project.getActiveConfigurations(),
new Function<MatrixConfiguration, Combination>() {
public Combination apply(MatrixConfiguration c) {
return c.getCombination();
}
}
);
}

/**
* Descriptor for {@link Successful}
*/
@Extension(ordinal=140) // Top Most
public static class DescriptorImpl extends MatrixCombinationsShortcutDescriptor {
/**
* {@inheritDoc}
*/
@Override
public String getDisplayName() {
return "Successful";
}
}
}

/**
* Checks all combinations with unstable or more worse builds.
*/
public static class Failed extends MatrixCombinationsShortcut {
/**
* ctor
* {@inheritDoc}
*/
@DataBoundConstructor
public Failed() {
@Override
public String getName() {
return getDescriptor().getDisplayName();
}

/**
* {@inheritDoc}
*/
@Override
public Collection<Combination> getCombinations(
@Nonnull MatrixProject project,
@CheckForNull MatrixBuild build
) {
if (build == null) {
return Collections.emptyList();
}
return Collections2.transform(
Collections2.filter(
build.getRuns(),
new Predicate<MatrixRun>() {
public boolean apply(MatrixRun r) {
Result result = r.getResult();
return (result != null)
&& result.isWorseThan(Result.UNSTABLE);
}
}
),
new Function<MatrixRun, Combination>() {
public Combination apply(MatrixRun r) {
return r.getParent().getCombination();
}
}
);
public String getId() {
return "All";
}

/**
* Descriptor for {@link Failed}
* Descriptor for {@link All}
*/
@Extension(ordinal=130) // Next to Successful
@Extension(ordinal=120) // Top most
public static class DescriptorImpl extends MatrixCombinationsShortcutDescriptor {
/**
* {@inheritDoc}
*/
@Override
public String getDisplayName() {
return "Failed";
return "All";
}
}
}

/**
* Checks all combinations.
* Uncheck all
*/
public static class All extends MatrixCombinationsShortcut {
public static class None extends MatrixCombinationsShortcut {
/**
* ctor
*/
@DataBoundConstructor
public All() {
public None() {
}

/**
@@ -243,51 +186,23 @@ public All() {
@Nonnull MatrixProject project,
@CheckForNull MatrixBuild build
) {
return Collections2.transform(
project.getActiveConfigurations(),
new Function<MatrixConfiguration, Combination>() {
public Combination apply(MatrixConfiguration c) {
return c.getCombination();
}
}
);
}

/**
* Descriptor for {@link All}
*/
@Extension(ordinal=120) // Next to Failed
public static class DescriptorImpl extends MatrixCombinationsShortcutDescriptor {
/**
* {@inheritDoc}
*/
@Override
public String getDisplayName() {
return "All";
}
return Collections.emptyList();
}
}

/**
* Uncheck all
*/
public static class None extends MatrixCombinationsShortcut {
/**
* ctor
* {@inheritDoc}
*/
@DataBoundConstructor
public None() {
@Override
public String getName() {
return getDescriptor().getDisplayName();
}

/**
* {@inheritDoc}
*/
@Override
public Collection<Combination> getCombinations(
@Nonnull MatrixProject project,
@CheckForNull MatrixBuild build
) {
return Collections.emptyList();
public String getId() {
return "None";
}

/**

0 comments on commit 7cdea26

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