aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorakozak2011-11-21 06:27:25 (EST)
committerWinston Prakash2011-12-01 20:46:49 (EST)
commita353adfb005ccdb7d97c53efa37d4ac365e8d095 (patch)
treec6b44f2996f6227c064e924b4790aaff43676277
parentc0853d3df8d06128e8143a527d1a27bff0d86fe3 (diff)
downloadorg.eclipse.hudson.core-a353adfb005ccdb7d97c53efa37d4ac365e8d095.zip
org.eclipse.hudson.core-a353adfb005ccdb7d97c53efa37d4ac365e8d095.tar.gz
org.eclipse.hudson.core-a353adfb005ccdb7d97c53efa37d4ac365e8d095.tar.bz2
Updated LogRotator, added tests.
Signed-off-by: Winston Prakash <winston.prakash@gmail.com>
-rw-r--r--hudson-core/src/main/java/hudson/model/Job.java23
-rw-r--r--hudson-core/src/main/java/hudson/tasks/LogRotator.java40
-rw-r--r--hudson-core/src/test/java/hudson/model/FreeStyleProjectTest.java81
3 files changed, 141 insertions, 3 deletions
diff --git a/hudson-core/src/main/java/hudson/model/Job.java b/hudson-core/src/main/java/hudson/model/Job.java
index 3ae40dd..c57ff54 100644
--- a/hudson-core/src/main/java/hudson/model/Job.java
+++ b/hudson-core/src/main/java/hudson/model/Job.java
@@ -19,6 +19,7 @@ package hudson.model;
import hudson.Functions;
import hudson.util.graph.GraphSeries;
import hudson.widgets.Widget;
+import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import com.google.common.collect.Sets;
import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
@@ -346,11 +347,20 @@ public abstract class Job<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, R
* Returns the log rotator for this job, or null if none.
*/
public LogRotator getLogRotator() {
- return logRotator;
+ return logRotator!= null ? logRotator : (hasParentTemplate()? getTemplate().getLogRotator() : null);
}
+ /**
+ * Sets log rotator.
+ *
+ * @param logRotator log rotator.
+ */
public void setLogRotator(LogRotator logRotator) {
- this.logRotator = logRotator;
+ if (!(hasParentTemplate() && ObjectUtils.equals(getTemplate().getLogRotator(), logRotator))) {
+ this.logRotator = logRotator;
+ } else {
+ this.logRotator = null;
+ }
}
/**
@@ -1237,6 +1247,15 @@ public abstract class Job<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, R
}
/**
+ * For the unit tests only. Sets template for the job.
+ *
+ * @param template parent job
+ */
+ void setTemplate(JobT template) {
+ this.template = template;
+ }
+
+ /**
* Checks whether current job is inherited from other project.
* @return boolean.
*/
diff --git a/hudson-core/src/main/java/hudson/tasks/LogRotator.java b/hudson-core/src/main/java/hudson/tasks/LogRotator.java
index fb6c4fc..efcac5d 100644
--- a/hudson-core/src/main/java/hudson/tasks/LogRotator.java
+++ b/hudson-core/src/main/java/hudson/tasks/LogRotator.java
@@ -41,6 +41,8 @@ import static java.util.logging.Level.FINER;
*/
public class LogRotator implements Describable<LogRotator> {
+ private static final Logger LOGGER = Logger.getLogger(LogRotator.class.getName());
+
/**
* If not -1, history is only kept up to this days.
*/
@@ -291,5 +293,41 @@ public class LogRotator implements Describable<LogRotator> {
}
}
- private static final Logger LOGGER = Logger.getLogger(LogRotator.class.getName());
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+
+ LogRotator that = (LogRotator) o;
+
+ if (daysToKeep != that.daysToKeep) {
+ return false;
+ }
+ if (numToKeep != that.numToKeep) {
+ return false;
+ }
+ if (artifactDaysToKeep != null ? !artifactDaysToKeep.equals(that.artifactDaysToKeep)
+ : that.artifactDaysToKeep != null) {
+ return false;
+ }
+ if (artifactNumToKeep != null ? !artifactNumToKeep.equals(that.artifactNumToKeep)
+ : that.artifactNumToKeep != null) {
+ return false;
+ }
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = daysToKeep;
+ result = 31 * result + numToKeep;
+ result = 31 * result + (artifactDaysToKeep != null ? artifactDaysToKeep.hashCode() : 0);
+ result = 31 * result + (artifactNumToKeep != null ? artifactNumToKeep.hashCode() : 0);
+ return result;
+ }
}
diff --git a/hudson-core/src/test/java/hudson/model/FreeStyleProjectTest.java b/hudson-core/src/test/java/hudson/model/FreeStyleProjectTest.java
index db148a8..657f571 100644
--- a/hudson-core/src/test/java/hudson/model/FreeStyleProjectTest.java
+++ b/hudson-core/src/test/java/hudson/model/FreeStyleProjectTest.java
@@ -21,6 +21,7 @@ import hudson.security.AuthorizationMatrixProperty;
import hudson.security.AuthorizationStrategy;
import hudson.security.GlobalMatrixAuthorizationStrategy;
import hudson.security.ProjectMatrixAuthorizationStrategy;
+import hudson.tasks.LogRotator;
import java.util.List;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -215,4 +216,84 @@ public class FreeStyleProjectTest {
List properties = freeStyleProject.getAllProperties();
assertEquals(properties.size(), 0);
}
+
+
+ @Test
+ public void testGetLogRotatorFromParent(){
+ MatrixProject matrixProjectProject = new MatrixProject("matrixProject");
+ FreeStyleProject parentProject = new FreeStyleProject(matrixProjectProject, "parent"){
+ @Override
+ protected void updateTransientActions() {
+ }
+ };
+ parentProject.setLogRotator(new LogRotator(10,11,12,13));
+
+ FreeStyleProject childProject1 = new FreeStyleProject(matrixProjectProject, "child1"){
+ @Override
+ protected void updateTransientActions() {
+ }
+ };
+ childProject1.setTemplate(parentProject);
+ LogRotator result = childProject1.getLogRotator();
+ assertNotNull(result);
+ assertEquals(result.getDaysToKeep(), 10);
+ }
+
+ @Test
+ public void testGetLogRotatorFromChild(){
+ MatrixProject matrixProjectProject = new MatrixProject("matrixProject");
+ FreeStyleProject parentProject = new FreeStyleProject(matrixProjectProject, "parent"){
+ @Override
+ protected void updateTransientActions() {
+ }
+ };
+ parentProject.setLogRotator(new LogRotator(10,10,10,10));
+
+ FreeStyleProject childProject1 = new FreeStyleProject(matrixProjectProject, "child1"){
+ @Override
+ protected void updateTransientActions() {
+ }
+ };
+ childProject1.setLogRotator(new LogRotator(20,20,20,20));
+ childProject1.setTemplate(parentProject);
+ LogRotator result = childProject1.getLogRotator();
+ assertNotNull(result);
+ assertEquals(result.getDaysToKeep(), 20);
+ }
+
+ @Test
+ public void testSetLogRotatorValueEqualsWithParent(){
+ MatrixProject matrixProjectProject = new MatrixProject("matrixProject");
+ FreeStyleProject parentProject = new FreeStyleProject(matrixProjectProject, "parent"){
+ @Override
+ protected void updateTransientActions() {
+ }
+ };
+ parentProject.setLogRotator(new LogRotator(10,11,12,13));
+
+ FreeStyleProject childProject1 = new FreeStyleProject(matrixProjectProject, "child1"){
+ @Override
+ protected void updateTransientActions() {
+ }
+ };
+ childProject1.setTemplate(parentProject);
+ childProject1.setLogRotator(new LogRotator(10,11,12,13));
+ childProject1.setTemplate(null); // else log rotator will be taken from parent
+ assertNull(childProject1.getLogRotator());
+ }
+
+ @Test
+ public void testSetLogRotatorParentNull(){
+ MatrixProject matrixProjectProject = new MatrixProject("matrixProject");
+
+ FreeStyleProject childProject1 = new FreeStyleProject(matrixProjectProject, "child1"){
+ @Override
+ protected void updateTransientActions() {
+ }
+ };
+ childProject1.setLogRotator(new LogRotator(10,11,12,13));
+ assertNotNull(childProject1.getLogRotator());
+ }
+
}
+