Skip to content
Permalink
Browse files
[FIXED JENKINS-10431]
  • Loading branch information
jacob_robertson committed Jul 22, 2011
1 parent dc128ff commit 3beb554dc5b92c537feb1adadbcf33755098abb4
@@ -45,6 +45,7 @@ public String getDisplayName() {
}

public ExtensionList<Slicer> getAxes() {
// TODO alphabetize
return Hudson.getInstance().getExtensionList(Slicer.class);
}

@@ -10,6 +10,8 @@
import java.util.List;
import java.util.Set;

import org.apache.commons.lang.StringUtils;

import configurationslicing.UnorderedStringSlicer;

/**
@@ -70,7 +72,11 @@ public boolean setValues(AbstractProject<?, ?> item, Set<String> set) {
if (DISABLED.equals(ws)) {
ws = null;
}
project.setCustomWorkspace(ws);
String old = project.getCustomWorkspace();
// check for equal - we don't want to trigger a change for no reason
if (!StringUtils.equals(ws, old)) {
project.setCustomWorkspace(ws);
}
}
return true;
} catch (IOException ioe) {
@@ -1,16 +1,19 @@
package configurationslicing.jdk;

import hudson.Extension;
import hudson.model.AbstractProject;
import hudson.model.Hudson;
import hudson.model.JDK;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import hudson.Extension;
import hudson.model.AbstractProject;
import hudson.model.Hudson;
import hudson.model.JDK;
import org.apache.commons.lang.ObjectUtils;
import org.apache.commons.lang.StringUtils;

import configurationslicing.UnorderedStringSlicer;
import configurationslicing.UnorderedStringSlicer.UnorderedStringSlicerSpec;

@Extension
public class JdkSlicer extends UnorderedStringSlicer<AbstractProject<?, ?>> {
@@ -54,14 +57,34 @@ public boolean setValues(AbstractProject<?, ?> item, Set<String> set) {
jdk = hudson.getJDK(val);
if(jdk!=null) break;
}
try {
item.setJDK(jdk);
return true;
} catch (IOException e) {
e.printStackTrace();
return false;
JDK oldJdk = item.getJDK();
if (!equals(oldJdk, jdk)) {
try {
item.setJDK(jdk);
return true;
} catch (IOException e) {
e.printStackTrace();
return false;
}
} else {
return false;
}
}
public static boolean equals(JDK j1, JDK j2) {
if (ObjectUtils.equals(j1, j2)) {
return true;
}
if (j1 == null || j2 == null) {
return false;
}
if (!StringUtils.equals(j1.getHome(), j2.getHome())) {
return false;
}
if (!StringUtils.equals(j1.getName(), j2.getName())) {
return false;
}
return true;
}

}

@@ -92,17 +92,36 @@ public boolean setValues(AbstractProject<?, ?> item, Set<String> set) {
if(disabled) days = -1;

LogRotator newlogrotator = new LogRotator(days,builds);
item.setLogRotator(newlogrotator);
try {
item.save();
} catch (IOException e) {
e.printStackTrace();
return false;

if (!LogRotationSlicer.equals(newlogrotator, logrotator)) {
item.setLogRotator(newlogrotator);
try {
item.save();
} catch (IOException e) {
e.printStackTrace();
return false;
}
return true;
} else {
return false;
}
return true;
}
}

public static boolean equals(LogRotator r1, LogRotator r2) {
if (r1 == r2) {
return true;
}
if (r1 == null || r2 == null) {
return false;
}
if (r1.getDaysToKeep() != r2.getDaysToKeep()) {
return false;
}
if (r1.getNumToKeep() != r2.getNumToKeep()) {
return false;
}
return true;
}
public static class LogRotationBuildsSliceSpec implements UnorderedStringSlicerSpec<AbstractProject<?,?>> {

private static final String DISABLED = "(Disabled)";
@@ -166,14 +185,18 @@ public boolean setValues(AbstractProject<?, ?> item, Set<String> set) {
if(disabled) builds = -1;

LogRotator newlogrotator = new LogRotator(days,builds);
item.setLogRotator(newlogrotator);
try {
item.save();
} catch (IOException e) {
e.printStackTrace();
return false;
if (!LogRotationSlicer.equals(newlogrotator, logrotator)) {
item.setLogRotator(newlogrotator);
try {
item.save();
} catch (IOException e) {
e.printStackTrace();
return false;
}
return true;
} else {
return false;
}
return true;
}
}
}
@@ -58,9 +58,17 @@ public boolean setValues(AbstractProject<?, ?> item, Set<String> set) {

List<String> list = new ArrayList<String>(set);
String spec = joinChronSpec(list);
boolean disabled = DISABLED.equals(spec);

Trigger oldTrigger = item.getTrigger(triggerClass);
boolean disabled = DISABLED.equals(spec);

// see if there are any changes
if (oldTrigger != null) {
String oldSpec = oldTrigger.getSpec();
if (oldSpec.equals(spec)) {
return false;
}
}

// now do the transformation
try {
@@ -0,0 +1,34 @@
package configurationslicing;

import configurationslicing.jdk.JdkSlicer;
import hudson.model.JDK;
import junit.framework.TestCase;

public class JdkSlicerTest extends TestCase {

public void testJdkEquals() {
doTestJdkEquals("h1", "h2", "n1", "n2", false);
doTestJdkEquals("h1", "h1", "n1", "n2", false);
doTestJdkEquals("h1", "h2", "n1", "n1", false);
doTestJdkEquals("h1", "h1", "n1", "n1", true);

doTestJdkEquals(null, null, null, null, true);
doTestJdkEquals("h1", null, null, null, false);
doTestJdkEquals(null, null, "n1", null, false);
}
private void doTestJdkEquals(String h1, String h2, String n1, String n2, boolean expect) {
JDK j1 = new JDK(n1, h1);
JDK j2 = new JDK(n2, h2);
assertEquals(expect, JdkSlicer.JdkSlicerSpec.equals(j1, j2));

assertTrue(JdkSlicer.JdkSlicerSpec.equals(j1, j1));
assertTrue(JdkSlicer.JdkSlicerSpec.equals(j2, j2));
assertTrue(JdkSlicer.JdkSlicerSpec.equals(null, null));

assertFalse(JdkSlicer.JdkSlicerSpec.equals(j1, null));
assertFalse(JdkSlicer.JdkSlicerSpec.equals(j2, null));
assertFalse(JdkSlicer.JdkSlicerSpec.equals(null, j1));
assertFalse(JdkSlicer.JdkSlicerSpec.equals(null, j2));
}

}
@@ -0,0 +1,39 @@
package configurationslicing;

import configurationslicing.logrotator.LogRotationSlicer;
import hudson.tasks.LogRotator;
import junit.framework.TestCase;

public class LogRotationSlicerTest extends TestCase {

public void testLogRotatorEquals() {
doTestLogRotatorEquals(0, 0, 0, 0, true);
doTestLogRotatorEquals(-1, -1, -1, -1, true);

doTestLogRotatorEquals(1, 1, 1, 1, true);
doTestLogRotatorEquals(1, 1, 2, 2, true);

doTestLogRotatorEquals(1, -1, -1, -1, false);
doTestLogRotatorEquals(-1, 1, -1, -1, false);
doTestLogRotatorEquals(-1, -1, 1, -1, false);
doTestLogRotatorEquals(-1, -1, -1, 1, false);

doTestLogRotatorEquals(1, 1, 2, 3, false);
doTestLogRotatorEquals(2, 3, 1, 1, false);
}
private void doTestLogRotatorEquals(int d1, int d2, int n1, int n2, boolean expect) {
LogRotator r1 = new LogRotator(d1, n1);
LogRotator r2 = new LogRotator(d2, n2);
boolean equals = LogRotationSlicer.equals(r1, r2);
assertEquals(expect, equals);
assertFalse(LogRotationSlicer.equals(r1, null));
assertFalse(LogRotationSlicer.equals(null, r1));
assertFalse(LogRotationSlicer.equals(r2, null));
assertFalse(LogRotationSlicer.equals(null, r2));

assertTrue(LogRotationSlicer.equals(null, null));
assertTrue(LogRotationSlicer.equals(r1, r1));
assertTrue(LogRotationSlicer.equals(r2, r2));
}

}

0 comments on commit 3beb554

Please sign in to comment.