use of hudson.plugins.violations.ViolationsReport.TypeReport in project violations-plugin by jenkinsci.
the class RatchetingTest method testThatMinIsUpdatedIfMaxIsLessThenMinCanBeUpdated.
@Test
public void testThatMinIsUpdatedIfMaxIsLessThenMinCanBeUpdated() {
BuildListener listener = mock(BuildListener.class);
when(listener.getLogger()).thenReturn(out);
Collection<TypeReport> typeReports = newArrayList(type(CHECKSTYLE, 7));
ViolationsConfig config = new ViolationsConfig();
config.setAutoUpdateMax(TRUE);
config.getTypeConfigs().get(CHECKSTYLE).setMax(15);
config.getTypeConfigs().get(CHECKSTYLE).setMin(9);
handleRatcheting(SUCCESS, typeReports, listener, config);
assertEquals("Expected ratcheting to have been updated", 8, config.getTypeConfigs().get(CHECKSTYLE).getMax());
assertEquals("Expected ratcheting to have been updated", 7, config.getTypeConfigs().get(CHECKSTYLE).getMin());
}
use of hudson.plugins.violations.ViolationsReport.TypeReport in project violations-plugin by jenkinsci.
the class RatchetingTest method testThatUnstableLimitCanBeUpdated.
@Test
public void testThatUnstableLimitCanBeUpdated() {
BuildListener listener = mock(BuildListener.class);
when(listener.getLogger()).thenReturn(out);
Collection<TypeReport> typeReports = newArrayList(type(CHECKSTYLE, 1));
ViolationsConfig config = new ViolationsConfig();
config.setAutoUpdateUnstable(TRUE);
config.getTypeConfigs().get(CHECKSTYLE).setUnstable(4);
handleRatcheting(SUCCESS, typeReports, listener, config);
assertEquals("Expected ratcheting to have been updated", 2, config.getTypeConfigs().get(CHECKSTYLE).getUnstable().intValue());
}
use of hudson.plugins.violations.ViolationsReport.TypeReport in project violations-plugin by jenkinsci.
the class RatchetingTest method testThatMaxCanBeUpdated.
@Test
public void testThatMaxCanBeUpdated() {
BuildListener listener = mock(BuildListener.class);
when(listener.getLogger()).thenReturn(out);
Collection<TypeReport> typeReports = newArrayList(type(CHECKSTYLE, 7));
ViolationsConfig config = new ViolationsConfig();
config.setAutoUpdateMax(TRUE);
config.getTypeConfigs().get(CHECKSTYLE).setMax(15);
handleRatcheting(SUCCESS, typeReports, listener, config);
assertEquals("Expected ratcheting to have been updated", 8, config.getTypeConfigs().get(CHECKSTYLE).getMax());
}
use of hudson.plugins.violations.ViolationsReport.TypeReport in project violations-plugin by jenkinsci.
the class ViolationsPublisher method handleRatcheting.
/**
* Perform ratcheting if enabled, i.e. lower the thresholds if the build is
* stable and the current value is lower than the current threshold.
*/
static void handleRatcheting(Result result, Collection<TypeReport> typeReports, BuildListener listener, ViolationsConfig config) {
if (!shouldDoRatcheting(config, result)) {
return;
}
// adjust the single configs (if needed)
for (TypeReport typeReport : typeReports) {
TypeConfig typeConfig = config.getTypeConfigs().get(typeReport.getType());
int thresholdCount = typeReport.getNumber() + 1;
if (config.isAutoUpdateUnstable() && thresholdCount < typeConfig.getUnstable()) {
listener.getLogger().println("Setting unstable value for " + typeConfig.getType() + " to " + thresholdCount);
typeConfig.setUnstable(thresholdCount);
}
if (config.isAutoUpdateMax() && thresholdCount < typeConfig.getMax()) {
listener.getLogger().println("Setting max/stormy value for " + typeConfig.getType() + " to " + thresholdCount);
typeConfig.setMax(thresholdCount);
// (and not min)
if (typeConfig.getMin() >= typeConfig.getMax()) {
typeConfig.setMin(typeConfig.getMax() - 1);
}
}
}
}
Aggregations