From d463a30c926331ce4b2b509a9dd5651f8a84c7bf Mon Sep 17 00:00:00 2001 From: Ryan Campbell Date: Thu, 31 Jan 2013 16:08:41 -0600 Subject: [PATCH 01/17] Introduce jenkins.slaves.WorkspaceLocator which allows extensions to override the location of the workspace. --- core/src/main/java/hudson/model/Slave.java | 9 +++++ core/src/main/java/jenkins/model/Jenkins.java | 8 ++++ .../java/jenkins/slaves/WorkspaceLocator.java | 38 +++++++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 core/src/main/java/jenkins/slaves/WorkspaceLocator.java diff --git a/core/src/main/java/hudson/model/Slave.java b/core/src/main/java/hudson/model/Slave.java index 4f9e7827a4..ff5ba010b9 100644 --- a/core/src/main/java/hudson/model/Slave.java +++ b/core/src/main/java/hudson/model/Slave.java @@ -58,6 +58,8 @@ import java.util.Set; import javax.servlet.ServletException; import jenkins.model.Jenkins; +import jenkins.slaves.WorkspaceLocator; + import org.apache.commons.io.IOUtils; import org.kohsuke.stapler.DataBoundConstructor; import org.kohsuke.stapler.HttpResponse; @@ -267,6 +269,13 @@ public abstract class Slave extends Node implements Serializable { } public FilePath getWorkspaceFor(TopLevelItem item) { + for (WorkspaceLocator l : WorkspaceLocator.all()) { + FilePath workspace = l.locate(item, this); + if (workspace != null) { + return workspace; + } + } + FilePath r = getWorkspaceRoot(); if(r==null) return null; // offline return r.child(item.getFullName()); diff --git a/core/src/main/java/jenkins/model/Jenkins.java b/core/src/main/java/jenkins/model/Jenkins.java index deebb958ce..a7ff8d6939 100755 --- a/core/src/main/java/jenkins/model/Jenkins.java +++ b/core/src/main/java/jenkins/model/Jenkins.java @@ -195,6 +195,7 @@ import jenkins.InitReactorRunner; import jenkins.model.ProjectNamingStrategy.DefaultProjectNamingStrategy; import jenkins.security.ConfidentialKey; import jenkins.security.ConfidentialStore; +import jenkins.slaves.WorkspaceLocator; import jenkins.util.io.FileBoolean; import net.sf.json.JSONObject; import org.acegisecurity.AccessDeniedException; @@ -1922,6 +1923,13 @@ public class Jenkins extends AbstractCIBase implements ModifiableTopLevelItemGro } public FilePath getWorkspaceFor(TopLevelItem item) { + for (WorkspaceLocator l : WorkspaceLocator.all()) { + FilePath workspace = l.locate(item, this); + if (workspace != null) { + return workspace; + } + } + return new FilePath(expandVariablesForDirectory(workspaceDir, item)); } diff --git a/core/src/main/java/jenkins/slaves/WorkspaceLocator.java b/core/src/main/java/jenkins/slaves/WorkspaceLocator.java new file mode 100644 index 0000000000..6fe3c06d76 --- /dev/null +++ b/core/src/main/java/jenkins/slaves/WorkspaceLocator.java @@ -0,0 +1,38 @@ +package jenkins.slaves; + +import hudson.ExtensionList; +import hudson.ExtensionPoint; +import hudson.FilePath; +import hudson.model.Node; +import hudson.model.TopLevelItem; +import jenkins.model.Jenkins; + +/** + * Allow extensions to override workspace locations + * on given slaves or projects. + * + * @author ryan.campbell@gmail.com + * @since 1.501 + */ +public abstract class WorkspaceLocator implements ExtensionPoint { + + /** + * Allows extensions to customize the workspace path. The first non-null response + * will determine the path to the workspace on that slave. + * + * @param item The toplevel item + * @param slave The slave + * @return The absolute FilePath to the workspace on the slave. + * Will be created if it doesn't exist. + * + */ + public abstract FilePath locate(TopLevelItem item, Node node); + + + /** + * All registered {@link WorkspaceLocator}s. + */ + public static ExtensionList all() { + return Jenkins.getInstance().getExtensionList(WorkspaceLocator.class); + } +} From 717d19a1e86fb8804b1b603d470ac3a39cc4e76f Mon Sep 17 00:00:00 2001 From: Pei-Tang Huang Date: Mon, 4 Mar 2013 16:59:11 +0800 Subject: [PATCH 02/17] Fix typo. Update translation. --- .../webapp/help/project-config/log-rotation_zh_TW.html | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/war/src/main/webapp/help/project-config/log-rotation_zh_TW.html b/war/src/main/webapp/help/project-config/log-rotation_zh_TW.html index bfdd3e9172..e985c65aa1 100644 --- a/war/src/main/webapp/help/project-config/log-rotation_zh_TW.html +++ b/war/src/main/webapp/help/project-config/log-rotation_zh_TW.html @@ -1,14 +1,14 @@
- 管理要保留的建置記錄 (包含畫面輸出、建置成品等) 數,控制 Jenkins 的磁碟使用量者。 + 管理要保留的建置記錄 (包含畫面輸出、建置成品等) 數,控制 Jenkins 的磁碟使用量。 Jenkins 提供兩種準則:
  1. - 依新舊狀況處理。您可以要 Jenkins 刪除超過指定時間 (例如 7 天) 前的記錄。 + 依新舊狀況處理。您可以要 Jenkins 刪除指定時間 (例如 7 天) 前的記錄。
  2. 依次數處理。您可以讓 Jenkins 只保留最近的 N 筆建置記錄。如果開始新的建置後,最早的記錄就會被刪掉。
- Jenkins 也允許您將單獨的建置標為「永久保存這次建置」,將特定幾次重要建置排除在自動刪除清單外。 + Jenkins 也允許您將某些建置標為「永久保存」,讓特定幾次重要建置不會被自動刪除。 最後一次穩定建置及最後一次成功建置也會一直保留住。 -
\ No newline at end of file + From bf048b8275af2fb37280a635e2fe57da8357c197 Mon Sep 17 00:00:00 2001 From: Pei-Tang Huang Date: Tue, 5 Mar 2013 19:33:26 +0800 Subject: [PATCH 03/17] Complete Traditional Chinese translation on RekeySecretAdminMonitor. --- .../RekeySecretAdminMonitor/message_zh_TW.properties | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/core/src/main/resources/jenkins/security/RekeySecretAdminMonitor/message_zh_TW.properties b/core/src/main/resources/jenkins/security/RekeySecretAdminMonitor/message_zh_TW.properties index 23f1456297..6887c4f899 100644 --- a/core/src/main/resources/jenkins/security/RekeySecretAdminMonitor/message_zh_TW.properties +++ b/core/src/main/resources/jenkins/security/RekeySecretAdminMonitor/message_zh_TW.properties @@ -35,3 +35,8 @@ rekeySuccessful=\ rekeyHadProblems=\ \u91d1\u9470\u91cd\u5957\u5b8c\u6210\uff0c\u4f46\u662f\u9047\u5230\u4e00\u4e9b\u554f\u984c\u3002\u8acb\u67e5\u770b\u8a18\u9304\u3002 + +Re-key\ in\ background\ now=\u99ac\u4e0a\u5728\u80cc\u666f\u91cd\u5957\u91d1\u9470 +Re-keying\ currently\ scheduled\ during\ the\ next\ startup=\u5df2\u7d93\u6392\u5b9a\u5728\u4e0b\u6b21\u555f\u52d5\u5f8c\u91cd\u5957\u91d1\u9470 +Schedule\ a\ re-key\ during\ the\ next\ startup=\u6392\u7a0b\u5728\u4e0b\u6b21\u555f\u52d5\u5f8c\u91cd\u5957\u91d1\u9470 +Dismiss\ this\ message=\u5ffd\u7565\u9019\u500b\u8a0a\u606f From 11f1963491b72b5cd5fbd12aefefa6402e892c1c Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Tue, 5 Mar 2013 16:15:23 -0500 Subject: [PATCH 04/17] Using better Logger overloads. --- core/src/main/java/hudson/security/csrf/CrumbFilter.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/hudson/security/csrf/CrumbFilter.java b/core/src/main/java/hudson/security/csrf/CrumbFilter.java index 167f9786f5..788eaa50ca 100644 --- a/core/src/main/java/hudson/security/csrf/CrumbFilter.java +++ b/core/src/main/java/hudson/security/csrf/CrumbFilter.java @@ -9,6 +9,7 @@ import jenkins.model.Jenkins; import java.io.IOException; import java.util.Enumeration; +import java.util.logging.Level; import java.util.logging.Logger; import javax.servlet.Filter; @@ -76,15 +77,14 @@ public class CrumbFilter implements Filter { if (crumbIssuer.validateCrumb(httpRequest, crumbSalt, crumb)) { valid = true; } else { - LOGGER.warning("Found invalid crumb " + crumb + - ". Will check remaining parameters for a valid one..."); + LOGGER.log(Level.WARNING, "Found invalid crumb {0}. Will check remaining parameters for a valid one...", crumb); } } // Multipart requests need to be handled by each handler. if (valid || isMultipart(httpRequest)) { chain.doFilter(request, response); } else { - LOGGER.warning("No valid crumb was included in request for " + httpRequest.getRequestURI() + ". Returning " + HttpServletResponse.SC_FORBIDDEN + "."); + LOGGER.log(Level.WARNING, "No valid crumb was included in request for {0}. Returning {1}.", new Object[] {httpRequest.getRequestURI(), HttpServletResponse.SC_FORBIDDEN}); httpResponse.sendError(HttpServletResponse.SC_FORBIDDEN,"No valid crumb was included in the request"); } } else { From 470051c2a6f0bfe16052926e7d2004d3a63c028b Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Tue, 5 Mar 2013 16:59:26 -0500 Subject: [PATCH 05/17] Comments. --- war/src/main/webapp/scripts/hudson-behavior.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/war/src/main/webapp/scripts/hudson-behavior.js b/war/src/main/webapp/scripts/hudson-behavior.js index 277ed3bba7..5618b51b7f 100644 --- a/war/src/main/webapp/scripts/hudson-behavior.js +++ b/war/src/main/webapp/scripts/hudson-behavior.js @@ -100,10 +100,12 @@ var crumb = { wrap: function(headers) { if (this.fieldName!=null) { if (headers instanceof Array) + // XXX prototype.js only seems to interpret object headers.push(this.fieldName, this.value); else headers[this.fieldName]=this.value; } + // XXX return value unused return headers; }, From 50f14f28e55bb39dd2959040734964889c70c7cb Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Tue, 5 Mar 2013 17:05:57 -0500 Subject: [PATCH 06/17] [FIXED JENKINS-17085] Bogus requestHeaders value prevented crumb addition. (Ah, the joys of dynamic typing!) --- changelog.html | 6 ++++-- core/src/main/resources/lib/form/textarea/textarea.js | 2 -- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/changelog.html b/changelog.html index e768ac7cbf..1a7a945654 100644 --- a/changelog.html +++ b/changelog.html @@ -55,7 +55,9 @@ Upcoming changes @@ -79,7 +81,7 @@ Upcoming changes Absolute URLs in console output (issue 16368)
  • - Revert ampersand encoding which can cause backwad incompatibility issue + Revert ampersand encoding which can cause backward incompatibility issue (pull 683)
  • Fix dependency graph computation when upstream build trigger is involved diff --git a/core/src/main/resources/lib/form/textarea/textarea.js b/core/src/main/resources/lib/form/textarea/textarea.js index de78308fe6..296b45fd54 100644 --- a/core/src/main/resources/lib/form/textarea/textarea.js +++ b/core/src/main/resources/lib/form/textarea/textarea.js @@ -34,8 +34,6 @@ Behaviour.specify("DIV.textarea-preview-container", 'textarea', 100, function (e }; new Ajax.Request(rootURL + showPreview.getAttribute("previewEndpoint"), { - method: "POST", - requestHeaders: "Content-Type: application/x-www-form-urlencoded", parameters: { text: text }, From ebd8ff1f0d85ee80650fe6730162975f00b81c63 Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Tue, 5 Mar 2013 17:55:28 -0500 Subject: [PATCH 07/17] [FIXED JENKINS-17087] getSortedDescriptorsForGlobalConfigUnclassified needed to avoid clobbering GlobalCrumbIssuerConfiguration in Jenkins.doConfigSubmit. --- changelog.html | 3 +++ core/src/main/java/hudson/Functions.java | 20 +++++++++++++++++++ core/src/main/java/jenkins/model/Jenkins.java | 9 ++++++--- .../jenkins/model/Jenkins/configure.jelly | 2 +- 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/changelog.html b/changelog.html index 1a7a945654..06a27b30a7 100644 --- a/changelog.html +++ b/changelog.html @@ -55,6 +55,9 @@ Upcoming changes From 14fc6de7a1e0c81aaf3cf08800d93a3d84044d52 Mon Sep 17 00:00:00 2001 From: Pei-Tang Huang Date: Wed, 6 Mar 2013 09:23:35 +0800 Subject: [PATCH 09/17] Align to src/main/resources/hudson/model/Messages_zh_TW.properties. Refine sentences. --- .../system-config/master-slave/usage_zh_TW.html | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/war/src/main/webapp/help/system-config/master-slave/usage_zh_TW.html b/war/src/main/webapp/help/system-config/master-slave/usage_zh_TW.html index 71b80b96c5..ca25101e61 100644 --- a/war/src/main/webapp/help/system-config/master-slave/usage_zh_TW.html +++ b/war/src/main/webapp/help/system-config/master-slave/usage_zh_TW.html @@ -3,21 +3,22 @@
    - 盡可能使用這個 Slave + 盡可能使用這個節點
    預設值,也是最常用的設定。 - 這個模式下,Jenkins 會不受限制的使用 Slave。一旦有建置作業可以在這個 Slave 上完成,Jenkins 就會用它。 + 這個模式下,Jenkins 會不受拘束的使用 Slave。一旦有建置作業可以在這個 Slave 上完成,Jenkins 就會用它。
    - 將機器保留給限定的作業 + 只保留給限定節點的作業
    - 這個模式下,Jenkins 只會在這部機器上建置那些指定要在這裡跑的那些專案。 + 這個模式下,Jenkins 只會在這部機器上建置那些明確指定只能在這裡跑的專案。 - 讓 Slave 保留給特定種類的作業。例如讓 Jenkins 持續執行效能測試。 - 您還可以同時將執行程式數設成 1,這樣一次就只執行一項效能測試,這個執行程式也不會被能在別的 Slave 建置的作業擋到。 + 將節點保留給特定種類的作業。 + 例如讓 Jenkins 持續執行效能測試,您還可以同時將執行程式數設成 1,一次只執行一項效能測試。 + 這個執行程式也不會因為要執行能在別的節點建置的作業而塞住。
    - \ No newline at end of file + From eab4bb6a30563a21321e5ab62afaa348247169d6 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Tue, 5 Mar 2013 16:34:41 -0800 Subject: [PATCH 10/17] Integrated json-lib 2.4 I had to tweak UpdateSite code because JSONObject.fromObject(String) became more strict and no longer allows extra garbage after the closing '}' --- core/pom.xml | 2 +- core/src/main/java/hudson/model/UpdateSite.java | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index e19432da08..b91143b56b 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -199,7 +199,7 @@ THE SOFTWARE. org.kohsuke.stapler json-lib - 2.1-rev7 + 2.4-jenkins-1 commons-httpclient diff --git a/core/src/main/java/hudson/model/UpdateSite.java b/core/src/main/java/hudson/model/UpdateSite.java index 147bf3f3b7..77bc130c3f 100644 --- a/core/src/main/java/hudson/model/UpdateSite.java +++ b/core/src/main/java/hudson/model/UpdateSite.java @@ -171,7 +171,11 @@ public class UpdateSite { String uncleanJson = IOUtils.toString(is,"UTF-8"); int jsonStart = uncleanJson.indexOf("{\""); if (jsonStart >= 0) { - return updateData(uncleanJson.substring(jsonStart), signatureCheck); + uncleanJson = uncleanJson.substring(jsonStart); + int end = uncleanJson.lastIndexOf('}'); + if (end>0) + uncleanJson = uncleanJson.substring(0,end+1); + return updateData(uncleanJson, signatureCheck); } else { throw new IOException("Could not find json in content of " + "update center from url: "+src.toExternalForm()); From c8fafe1c8acdd7e5016a8f12f666907eae7d3174 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Tue, 5 Mar 2013 18:34:00 -0800 Subject: [PATCH 11/17] Increase the cache time from 1 day to 365 days These are one time URLs, and this change aligns them from other /static/ links that serve 365 days expiration period. --- changelog.html | 2 ++ core/pom.xml | 2 +- core/src/main/java/jenkins/model/Jenkins.java | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/changelog.html b/changelog.html index 06a27b30a7..fb940c63df 100644 --- a/changelog.html +++ b/changelog.html @@ -61,6 +61,8 @@ Upcoming changes
  • Preview function for textareas using Jenkins markup did not work when CSRF protection was enabled. (issue 17085) +
  • + Improved the duration browsers cache static resources. diff --git a/core/pom.xml b/core/pom.xml index b91143b56b..5edf04b16c 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -42,7 +42,7 @@ THE SOFTWARE. true - 1.199 + 1.204 2.5.6.SEC03 diff --git a/core/src/main/java/jenkins/model/Jenkins.java b/core/src/main/java/jenkins/model/Jenkins.java index 55cef562bc..88adf177be 100755 --- a/core/src/main/java/jenkins/model/Jenkins.java +++ b/core/src/main/java/jenkins/model/Jenkins.java @@ -793,7 +793,7 @@ public class Jenkins extends AbstractCIBase implements ModifiableTopLevelItemGro // JSON binding needs to be able to see all the classes from all the plugins WebApp.get(servletContext).setClassLoader(pluginManager.uberClassLoader); - adjuncts = new AdjunctManager(servletContext, pluginManager.uberClassLoader,"adjuncts/"+SESSION_HASH); + adjuncts = new AdjunctManager(servletContext, pluginManager.uberClassLoader,"adjuncts/"+SESSION_HASH, TimeUnit2.DAYS.toMillis(365)); // initialization consists of ... executeReactor( is, From 937cc8ce6a2b2aa5effc24f3cf7c57c5d25f05f9 Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Wed, 6 Mar 2013 08:47:55 -0500 Subject: [PATCH 12/17] Better to override toString, which is used by getShortDescription anyway. --- core/src/main/java/hudson/model/FileParameterValue.java | 2 +- core/src/main/java/hudson/model/RunParameterValue.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/hudson/model/FileParameterValue.java b/core/src/main/java/hudson/model/FileParameterValue.java index 8505a705b4..2251ea551b 100644 --- a/core/src/main/java/hudson/model/FileParameterValue.java +++ b/core/src/main/java/hudson/model/FileParameterValue.java @@ -171,7 +171,7 @@ public class FileParameterValue extends ParameterValue { } @Override - public String getShortDescription() { + public String toString() { return "(FileParameterValue) " + getName() + "='" + originalFileName + "'"; } diff --git a/core/src/main/java/hudson/model/RunParameterValue.java b/core/src/main/java/hudson/model/RunParameterValue.java index 1b71c189bd..352c262bbd 100644 --- a/core/src/main/java/hudson/model/RunParameterValue.java +++ b/core/src/main/java/hudson/model/RunParameterValue.java @@ -87,7 +87,7 @@ public class RunParameterValue extends ParameterValue { } @Override - public String getShortDescription() { + public String toString() { return "(RunParameterValue) " + getName() + "='" + getRunId() + "'"; } From e8585767e43ffdfb6a9c2ee733b2218e24ec860d Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Wed, 6 Mar 2013 08:53:07 -0500 Subject: [PATCH 13/17] Localization. --- core/src/main/java/hudson/model/UpdateCenter.java | 4 +++- core/src/main/resources/hudson/model/Messages.properties | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/hudson/model/UpdateCenter.java b/core/src/main/java/hudson/model/UpdateCenter.java index 27b46cd827..8154ac74da 100644 --- a/core/src/main/java/hudson/model/UpdateCenter.java +++ b/core/src/main/java/hudson/model/UpdateCenter.java @@ -284,7 +284,9 @@ public class UpdateCenter extends AbstractModelObject implements Saveable, OnMas newestTs = s.getDataTimestamp(); } } - if(newestTs<0) return "N/A"; + if (newestTs < 0) { + return Messages.UpdateCenter_n_a(); + } return Util.getPastTimeString(System.currentTimeMillis()-newestTs); } diff --git a/core/src/main/resources/hudson/model/Messages.properties b/core/src/main/resources/hudson/model/Messages.properties index 1ca5bfb85f..6976e006ea 100644 --- a/core/src/main/resources/hudson/model/Messages.properties +++ b/core/src/main/resources/hudson/model/Messages.properties @@ -245,6 +245,7 @@ Slave.UnixSlave=This is a Unix slave Slave.WindowsSlave=This is a Windows slave UpdateCenter.DownloadButNotActivated=Downloaded Successfully. Will be activated during the next boot +UpdateCenter.n_a=N/A View.Permissions.Title=View View.CreatePermission.Description=\ This permission allows users to create new views. From 508d326361a0416ee1cc4dba868627a647077600 Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Wed, 6 Mar 2013 09:28:07 -0500 Subject: [PATCH 14/17] =?UTF-8?q?/pluginManager/advanced=20would=20sometim?= =?UTF-8?q?es=20claim=20=E2=80=9CUpdate=20information=20obtained:=2043=20y?= =?UTF-8?q?r=20ago=E2=80=9D.=20Due=20to=20a=20confusion=20between=200=20an?= =?UTF-8?q?d=20-1.=20Easier=20and=20clearer=20to=20use=200=20as=20the=20?= =?UTF-8?q?=E2=80=9Cuninitialized=E2=80=9D=20value.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/hudson/model/UpdateCenter.java | 4 ++-- core/src/main/java/hudson/model/UpdateSite.java | 17 ++++++----------- .../hudson/model/UpdateCenter2Test.groovy | 8 ++++++++ 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/core/src/main/java/hudson/model/UpdateCenter.java b/core/src/main/java/hudson/model/UpdateCenter.java index 8154ac74da..7e874ea6de 100644 --- a/core/src/main/java/hudson/model/UpdateCenter.java +++ b/core/src/main/java/hudson/model/UpdateCenter.java @@ -278,13 +278,13 @@ public class UpdateCenter extends AbstractModelObject implements Saveable, OnMas * Will be the newest of all {@link UpdateSite}s. */ public String getLastUpdatedString() { - long newestTs = -1; + long newestTs = 0; for (UpdateSite s : sites) { if (s.getDataTimestamp()>newestTs) { newestTs = s.getDataTimestamp(); } } - if (newestTs < 0) { + if (newestTs == 0) { return Messages.UpdateCenter_n_a(); } return Util.getPastTimeString(System.currentTimeMillis()-newestTs); diff --git a/core/src/main/java/hudson/model/UpdateSite.java b/core/src/main/java/hudson/model/UpdateSite.java index 147bf3f3b7..73b4222054 100644 --- a/core/src/main/java/hudson/model/UpdateSite.java +++ b/core/src/main/java/hudson/model/UpdateSite.java @@ -85,18 +85,20 @@ import static hudson.util.TimeUnit2.*; public class UpdateSite { /** * What's the time stamp of data file? + * 0 means never. */ - private transient long dataTimestamp = -1; + private transient volatile long dataTimestamp; /** * When was the last time we asked a browser to check the data for us? + * 0 means never. * *

    * There's normally some delay between when we send HTML that includes the check code, * until we get the data back, so this variable is used to avoid asking too many browseres * all at once. */ - private transient volatile long lastAttempt = -1; + private transient volatile long lastAttempt; /** * If the attempt to fetch data fails, we progressively use longer time out before retrying, @@ -129,14 +131,6 @@ public class UpdateSite { this.url = url; } - /** - * When read back from XML, initialize them back to -1. - */ - private Object readResolve() { - dataTimestamp = lastAttempt = -1; - return this; - } - /** * Get ID string. */ @@ -147,6 +141,7 @@ public class UpdateSite { @Exported public long getDataTimestamp() { + assert dataTimestamp >= 0; return dataTimestamp; } @@ -239,7 +234,7 @@ public class UpdateSite { */ public boolean isDue() { if(neverUpdate) return false; - if(dataTimestamp==-1) + if(dataTimestamp == 0) dataTimestamp = getDataFile().file.lastModified(); long now = System.currentTimeMillis(); diff --git a/test/src/test/groovy/hudson/model/UpdateCenter2Test.groovy b/test/src/test/groovy/hudson/model/UpdateCenter2Test.groovy index 7ef53871f8..0e4fd4475f 100644 --- a/test/src/test/groovy/hudson/model/UpdateCenter2Test.groovy +++ b/test/src/test/groovy/hudson/model/UpdateCenter2Test.groovy @@ -25,6 +25,7 @@ package hudson.model import org.jvnet.hudson.test.HudsonTestCase import hudson.model.UpdateCenter.DownloadJob.Success +import hudson.model.UpdateSite /** * @@ -42,4 +43,11 @@ public class UpdateCenter2Test extends HudsonTestCase { println job.status; assertTrue(job.status instanceof Success) } + + void testGetLastUpdatedString() { + UpdateSite.neverUpdate = false + assertTrue(jenkins.updateCenter.getById("default").due) + assertEquals(hudson.model.Messages.UpdateCenter_n_a(), jenkins.updateCenter.lastUpdatedString) + } + } From f54a947fd4793a15f120e4be7dfa321a27449dcb Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Wed, 6 Mar 2013 09:34:55 -0500 Subject: [PATCH 15/17] JUnit 4 assumptions are the right way to mark a test as having been skipped. --- .../test/java/hudson/model/UpdateCenterTest.java | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/core/src/test/java/hudson/model/UpdateCenterTest.java b/core/src/test/java/hudson/model/UpdateCenterTest.java index 5d00978abd..380d90b38a 100644 --- a/core/src/test/java/hudson/model/UpdateCenterTest.java +++ b/core/src/test/java/hudson/model/UpdateCenterTest.java @@ -24,35 +24,31 @@ package hudson.model; import com.trilead.ssh2.crypto.Base64; -import hudson.util.FormValidation; -import hudson.util.FormValidation.Kind; import hudson.util.TimeUnit2; -import junit.framework.TestCase; import net.sf.json.JSONObject; import org.apache.commons.io.IOUtils; import java.io.ByteArrayInputStream; import java.io.IOException; import java.net.URL; -import java.security.cert.CertificateExpiredException; import java.security.cert.CertificateFactory; -import java.security.cert.CertificateNotYetValidException; import java.security.cert.X509Certificate; import java.util.Date; +import static org.junit.Assert.*; +import static org.junit.Assume.*; +import org.junit.Test; /** * Quick test for {@link UpdateCenter}. * * @author Kohsuke Kawaguchi */ -public class UpdateCenterTest extends TestCase { - public void testData() throws Exception { - // check if we have the internet connectivity. See HUDSON-2095 +public class UpdateCenterTest { + @Test public void data() throws Exception { try { new URL("http://updates.jenkins-ci.org/").openStream(); } catch (IOException e) { - System.out.println("Skipping this test. No internet connectivity"); - return; + assumeNoException("No internet connectivity", e); // JENKINS-2095 } URL url = new URL("http://updates.jenkins-ci.org/update-center.json?version=build"); From 9514fb1a9fc938226da320e68afb3623cba3dfe9 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Wed, 6 Mar 2013 08:49:06 -0800 Subject: [PATCH 16/17] fixed the test regression caused by json-lib 2.4 --- .../test/java/lib/form/RepeatableTest.java | 49 ++++++++++--------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/test/src/test/java/lib/form/RepeatableTest.java b/test/src/test/java/lib/form/RepeatableTest.java index c2afddf7bd..48ee7bf5e3 100644 --- a/test/src/test/java/lib/form/RepeatableTest.java +++ b/test/src/test/java/lib/form/RepeatableTest.java @@ -40,6 +40,7 @@ import hudson.ExtensionPoint; import hudson.model.Describable; import hudson.model.Descriptor; import jenkins.model.Jenkins; +import net.sf.json.JSONArray; import net.sf.json.JSONObject; import org.jvnet.hudson.test.HudsonTestCase; import org.kohsuke.stapler.DataBoundConstructor; @@ -79,9 +80,9 @@ public class RepeatableTest extends HudsonTestCase { public void testSimple() throws Exception { doTestSimple(); - assertEquals("[{\"bool\":false,\"txt\":\"value one\"}," + assertEqualsJsonArray("[{\"bool\":false,\"txt\":\"value one\"}," + "{\"bool\":false,\"txt\":\"value two\"},{\"bool\":true,\"txt\":\"value three\"}]", - formData.get("foos").toString()); + formData.get("foos")); } // ======================================================================== @@ -102,10 +103,10 @@ public class RepeatableTest extends HudsonTestCase { public void testSimple_ExistingData() throws Exception { addData(); doTestSimple(); - assertEquals("[{\"bool\":true,\"txt\":\"existing one\"}," + assertEqualsJsonArray("[{\"bool\":true,\"txt\":\"existing one\"}," + "{\"bool\":false,\"txt\":\"existing two\"},{\"bool\":true,\"txt\":\"value one\"}," + "{\"bool\":false,\"txt\":\"value two\"},{\"bool\":false,\"txt\":\"value three\"}]", - formData.get("foos").toString()); + formData.get("foos")); } public void testMinimum() throws Exception { @@ -118,9 +119,9 @@ public class RepeatableTest extends HudsonTestCase { try { f.getInputByValue(""); fail("?"); } catch (ElementNotFoundException expected) { } f.getInputsByName("bool").get(2).click(); submit(f); - assertEquals("[{\"bool\":false,\"txt\":\"value one\"}," + assertEqualsJsonArray("[{\"bool\":false,\"txt\":\"value one\"}," + "{\"bool\":false,\"txt\":\"value two\"},{\"bool\":true,\"txt\":\"value three\"}]", - formData.get("foos").toString()); + formData.get("foos")); } public void testMinimum_ExistingData() throws Exception { @@ -132,9 +133,9 @@ public class RepeatableTest extends HudsonTestCase { try { f.getInputByValue(""); fail("?"); } catch (ElementNotFoundException expected) { } f.getInputsByName("bool").get(1).click(); submit(f); - assertEquals("[{\"bool\":true,\"txt\":\"existing one\"}," + assertEqualsJsonArray("[{\"bool\":true,\"txt\":\"existing one\"}," + "{\"bool\":true,\"txt\":\"existing two\"},{\"bool\":false,\"txt\":\"new one\"}]", - formData.get("foos").toString()); + formData.get("foos")); } public void testNoData() throws Exception { @@ -174,8 +175,8 @@ public class RepeatableTest extends HudsonTestCase { addDefaults(); gotoAndSubmitConfig(viewName); assertNotNull(formData.get("list")); - assertEquals("[{\"bool\":true,\"txt\":\"default one\"},{\"bool\":false,\"txt\":\"default two\"}]", - formData.get("list").toString()); + assertEqualsJsonArray("[{\"bool\":true,\"txt\":\"default one\"},{\"bool\":false,\"txt\":\"default two\"}]", + formData.get("list")); } private void assertDefaultsIgnoredIfHaveData(final String viewName) throws Exception { @@ -183,8 +184,8 @@ public class RepeatableTest extends HudsonTestCase { addDefaults(); gotoAndSubmitConfig(viewName); assertNotNull(formData.get("list")); - assertEquals("[{\"bool\":true,\"txt\":\"existing one\"},{\"bool\":false,\"txt\":\"existing two\"}]", - formData.get("list").toString()); + assertEqualsJsonArray("[{\"bool\":true,\"txt\":\"existing one\"},{\"bool\":false,\"txt\":\"existing two\"}]", + formData.get("list")); } private void gotoAndSubmitConfig(final String viewName) throws Exception { @@ -207,9 +208,9 @@ public class RepeatableTest extends HudsonTestCase { f.getInputByValue("").setValueAttribute("txt two"); f.getElementsByAttribute("INPUT", "type", "radio").get(3).click(); submit(f); - assertEquals("[{\"radio\":\"two\",\"txt\":\"txt one\"}," - + "{\"radio\":\"two\",\"txt\":\"txt two\"}]", - formData.get("foos").toString()); + assertEqualsJsonArray("[{\"radio\":\"two\",\"txt\":\"txt one\"}," + + "{\"radio\":\"two\",\"txt\":\"txt two\"}]", + formData.get("foos")); } public static class FooRadio { @@ -227,9 +228,9 @@ public class RepeatableTest extends HudsonTestCase { f.getInputByValue("").setValueAttribute("txt 4"); f.getElementsByAttribute("INPUT", "type", "radio").get(7).click(); submit(f); - assertEquals("[{\"radio\":\"one\",\"txt\":\"1\"},{\"radio\":\"two\",\"txt\":\"2\"}," + assertEqualsJsonArray("[{\"radio\":\"one\",\"txt\":\"1\"},{\"radio\":\"two\",\"txt\":\"2\"}," + "{\"radio\":\"one\",\"txt\":\"three\"},{\"radio\":\"two\",\"txt\":\"txt 4\"}]", - formData.get("foos").toString()); + formData.get("foos")); } // hudson-behavior uniquifies radiobutton names so the browser properly handles each group, @@ -247,9 +248,9 @@ public class RepeatableTest extends HudsonTestCase { f.getElementsByAttribute("INPUT", "type", "radio").get(2).click(); f.getInputByValue("").setValueAttribute("avalue two"); submit(f); - assertEquals("[{\"radio\":{\"b\":\"bvalue\",\"value\":\"two\"},\"txt\":\"txt one\"}," + assertEqualsJsonArray("[{\"radio\":{\"b\":\"bvalue\",\"value\":\"two\"},\"txt\":\"txt one\"}," + "{\"radio\":{\"a\":\"avalue two\",\"value\":\"one\"},\"txt\":\"txt two\"}]", - formData.get("foos").toString()); + formData.get("foos")); } // ======================================================================== @@ -394,9 +395,13 @@ public class RepeatableTest extends HudsonTestCase { throw e; } submit(f); - assertEquals("[{\"moo\":{\"inner\":\"inone\"},\"outer\":\"two\"}," - + "{\"moo\":[{\"inner\":\"intwo\"},{\"inner\":\"inone\"}],\"outer\":\"one\"}]", - formData.get("items").toString()); + assertEqualsJsonArray("[{\"moo\":{\"inner\":\"inone\"},\"outer\":\"two\"}," + + "{\"moo\":[{\"inner\":\"intwo\"},{\"inner\":\"inone\"}],\"outer\":\"one\"}]", + formData.get("items")); + } + + private void assertEqualsJsonArray(String golden, Object jsonArray) { + assertEquals(JSONArray.fromObject(golden),jsonArray); } /** From fba6be7c420bd7d62b9bd20bcf2d7fe7e83994ba Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Wed, 6 Mar 2013 08:54:30 -0800 Subject: [PATCH 17/17] Fixing a test regression. See 010b47d7307a11f0750fc01a00d99b96bbab9234 in stapler/stapler for the actual fix. I first discovered this on my local desktop yesterday as I was verifying the fix for json-lib 2.4. From what I can tell, this has been broken all along and it was working only because Facets are discovered in the lucky order; JellyFacet got a chance to get at it before GroovyFacet did. When I rebuilt from clean the problem stopped appearing, so I assumed that there are some factors that cause JellyFacet to get loaded before GroovyFacet (maybe the order in which Maven iterates dependencies or something like that.) But I'm no longer so sure now that I know J-on-J saw this problem at about the same time. That's just too many coincidences. But let's see if this would make J-on-J happy. --- core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/pom.xml b/core/pom.xml index 5edf04b16c..3fcb04b90b 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -42,7 +42,7 @@ THE SOFTWARE. true - 1.204 + 1.205 2.5.6.SEC03