diff --git a/changelog.html b/changelog.html index d254fbd756..7913c076f4 100644 --- a/changelog.html +++ b/changelog.html @@ -68,6 +68,9 @@ Upcoming changes (issue 15733)
  • Support failsafe the same way as surefire in maven2 jobs +
  • + Build records were broken if timezone was changed while running. + (issue 15816)

    What's new in 1.490 (2012/11/12)

    diff --git a/core/src/main/java/hudson/model/Run.java b/core/src/main/java/hudson/model/Run.java index 95f538f7ff..34b0753130 100644 --- a/core/src/main/java/hudson/model/Run.java +++ b/core/src/main/java/hudson/model/Run.java @@ -96,7 +96,6 @@ import javax.servlet.ServletException; import javax.servlet.http.HttpServletResponse; import jenkins.model.Jenkins; -import jenkins.model.lazy.BuildReference; import jenkins.util.io.OnMaster; import net.sf.json.JSONObject; import org.apache.commons.io.input.NullInputStream; @@ -240,11 +239,14 @@ public abstract class Run ,RunT extends Run ID_FORMATTER = new ThreadLocal() { @Override protected SimpleDateFormat initialValue() { - return new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss"); + synchronized (CANONICAL_ID_FORMATTER) { + return (SimpleDateFormat) CANONICAL_ID_FORMATTER.clone(); + } } }; diff --git a/core/src/test/java/hudson/model/RunTest.java b/core/src/test/java/hudson/model/RunTest.java new file mode 100644 index 0000000000..3bf9537ccc --- /dev/null +++ b/core/src/test/java/hudson/model/RunTest.java @@ -0,0 +1,80 @@ +/* + * The MIT License + * + * Copyright 2012 Jesse Glick. + * + * 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.model; + +import java.util.TimeZone; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import static org.junit.Assert.*; +import org.junit.Test; +import org.jvnet.hudson.test.Bug; + +public class RunTest { + + @Bug(15816) + @SuppressWarnings({"unchecked", "rawtypes"}) + @Test public void timezoneOfID() throws Exception { + TimeZone origTZ = TimeZone.getDefault(); + try { + final Run r; + String id; + TimeZone.setDefault(TimeZone.getTimeZone("America/Chicago")); + ExecutorService svc = Executors.newSingleThreadExecutor(); + try { + r = svc.submit(new Callable() { + @Override public Run call() throws Exception { + return new Run(new StubJob(), 1234567890) {}; + } + }).get(); + TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles")); + id = r.getId(); + assertEquals(id, svc.submit(new Callable() { + @Override public String call() throws Exception { + return r.getId(); + } + }).get()); + } finally { + svc.shutdown(); + } + TimeZone.setDefault(TimeZone.getTimeZone("America/New_York")); + svc = Executors.newSingleThreadExecutor(); + try { + assertEquals(id, r.getId()); + assertEquals(id, svc.submit(new Callable() { + @Override + public String call() throws Exception { + return r.getId(); + } + }).get()); + } finally { + svc.shutdown(); + } + } finally { + TimeZone.setDefault(origTZ); + } + } + +} diff --git a/core/src/test/java/hudson/model/StubJob.java b/core/src/test/java/hudson/model/StubJob.java index 7f8173b356..918f2458a8 100644 --- a/core/src/test/java/hudson/model/StubJob.java +++ b/core/src/test/java/hudson/model/StubJob.java @@ -23,6 +23,7 @@ */ package hudson.model; +import java.io.File; import java.util.SortedMap; /** @@ -55,6 +56,10 @@ class StubJob extends Job { // TODO Auto-generated method stub } + + @Override protected File getBuildDir() { + return new File(System.getProperty("java.io.tmpdir")); + } /** * Override save so that nothig happens when setDisplayName() is called