From e7e1bf87f39d47e993c16e78a7d8eeece3cc822f Mon Sep 17 00:00:00 2001 From: Daniel Beck Date: Tue, 23 Dec 2014 11:44:01 +0100 Subject: [PATCH 001/285] [FIXED JENKINS-26208] Do not skip polling while quieting down --- core/src/main/java/hudson/triggers/SCMTrigger.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/core/src/main/java/hudson/triggers/SCMTrigger.java b/core/src/main/java/hudson/triggers/SCMTrigger.java index 6289c759a5..b07eb95f55 100644 --- a/core/src/main/java/hudson/triggers/SCMTrigger.java +++ b/core/src/main/java/hudson/triggers/SCMTrigger.java @@ -128,11 +128,6 @@ public class SCMTrigger extends Trigger { * @since 1.375 */ public void run(Action[] additionalActions) { - if (Jenkins.getInstance().isQuietingDown()) { - LOGGER.log(INFO, "Skipping polling for {0} since Jenkins is in quiet mode", job.getFullName()); - return; - } - DescriptorImpl d = getDescriptor(); LOGGER.fine("Scheduling a polling for "+job); From 77bc6ad835fc0fc54e4fed16395deb24332a2b49 Mon Sep 17 00:00:00 2001 From: Alex Bertram Date: Mon, 26 Jan 2015 14:14:16 +0100 Subject: [PATCH 002/285] JENKINS-26604 Removes try-catch from GlobalSettingsProvider unhelpfully which swallows exceptions If there is a problem providing the Maven global settings file configured by the user, the build should end in error. This is the behavior of SettingsProvider but not of GlobalSettingsProvider, which was swallowing the exception and printing only a warning, without details of the exception. --- core/src/main/java/jenkins/mvn/GlobalSettingsProvider.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/core/src/main/java/jenkins/mvn/GlobalSettingsProvider.java b/core/src/main/java/jenkins/mvn/GlobalSettingsProvider.java index 6438cfad1e..aa7285eed9 100644 --- a/core/src/main/java/jenkins/mvn/GlobalSettingsProvider.java +++ b/core/src/main/java/jenkins/mvn/GlobalSettingsProvider.java @@ -51,11 +51,7 @@ public abstract class GlobalSettingsProvider extends AbstractDescribableImpl build, TaskListener listener) { FilePath settingsPath = null; if (settings != null) { - try { - settingsPath = settings.supplySettings(build, listener); - } catch (Exception e) { - listener.getLogger().print("failed to get the path to the alternate global settings.xml"); - } + settingsPath = settings.supplySettings(build, listener); } return settingsPath; } From 8881703f7c7351695c5d5b2662faefae60de68e8 Mon Sep 17 00:00:00 2001 From: Nicolas De Loof Date: Wed, 4 Feb 2015 18:14:01 +0100 Subject: [PATCH 003/285] [JENKINS-26781] lookup descriptor by ID, then by class if explicitly set to match some specific use cases. --- core/src/main/java/hudson/model/Descriptor.java | 15 ++++++++++----- .../src/main/resources/lib/form/class-entry.jelly | 7 +++---- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/core/src/main/java/hudson/model/Descriptor.java b/core/src/main/java/hudson/model/Descriptor.java index 2b5bcef0cf..28e4a95ecc 100644 --- a/core/src/main/java/hudson/model/Descriptor.java +++ b/core/src/main/java/hudson/model/Descriptor.java @@ -909,14 +909,19 @@ public abstract class Descriptor> implements Saveable { if (formData!=null) { for (Object o : JSONArray.fromObject(formData)) { JSONObject jo = (JSONObject)o; - String kind = jo.optString("$class", null); - if (kind == null) { - // Legacy: Remove once plugins have been staged onto $class - kind = jo.getString("kind"); + Descriptor d = null; + String kind = jo.optString("kind", null); + if (kind != null) { + d = find(descriptors, kind); + } + if (d == null) { + kind = jo.getString("$class"); + d = find(descriptors, kind); } - Descriptor d = find(descriptors, kind); if (d != null) { items.add(d.newInstance(req, jo)); + } else { + LOGGER.warning("Received unexpected formData for descriptor " + kind); } } } diff --git a/core/src/main/resources/lib/form/class-entry.jelly b/core/src/main/resources/lib/form/class-entry.jelly index e03af3a754..371f5137d8 100644 --- a/core/src/main/resources/lib/form/class-entry.jelly +++ b/core/src/main/resources/lib/form/class-entry.jelly @@ -36,12 +36,11 @@ THE SOFTWARE. - - - + + - \ No newline at end of file + From 6a8ce6ca099cc9b51db6e1417e507973978a9271 Mon Sep 17 00:00:00 2001 From: Nicolas De Loof Date: Thu, 5 Feb 2015 17:00:49 +0100 Subject: [PATCH 004/285] deprecated find(string) and introduce explicit methods to lookup descriptor by id or by Describable class name --- .../main/java/hudson/model/Descriptor.java | 36 ++++++++++++++----- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/core/src/main/java/hudson/model/Descriptor.java b/core/src/main/java/hudson/model/Descriptor.java index 28e4a95ecc..a043d6b2fa 100644 --- a/core/src/main/java/hudson/model/Descriptor.java +++ b/core/src/main/java/hudson/model/Descriptor.java @@ -912,11 +912,11 @@ public abstract class Descriptor> implements Saveable { Descriptor d = null; String kind = jo.optString("kind", null); if (kind != null) { - d = find(descriptors, kind); + d = findById(descriptors, kind); } if (d == null) { kind = jo.getString("$class"); - d = find(descriptors, kind); + d = findByClassName(descriptors, kind); } if (d != null) { items.add(d.newInstance(req, jo)); @@ -930,20 +930,38 @@ public abstract class Descriptor> implements Saveable { } /** - * Finds a descriptor from a collection by its class name. + * Finds a descriptor from a collection by its id. */ - public static @CheckForNull T find(Collection list, String className) { + public static @CheckForNull T findById(Collection list, String id) { + for (T d : list) { + if(d.getId().equals(id)) + return d; + } + return null; + } + + /** + * Finds a descriptor from a collection by its class name. + * @deprecated Since we introduced {@link Descriptor#getId()}, it is a preferred method of identifying descriptor by a string. + */ + public static @CheckForNull T findByClassName(Collection list, String className) { for (T d : list) { if(d.getClass().getName().equals(className)) return d; } - // Since we introduced Descriptor.getId(), it is a preferred method of identifying descriptor by a string. - // To make that migration easier without breaking compatibility, let's also match up with the id. - for (T d : list) { - if(d.getId().equals(className)) + return null; + } + + /** + * Finds a descriptor from a collection by its class name or ID. + * @deprecated choose between {@link #findById(java.util.Collection, String)} or {@link #findByClassName(java.util.Collection, String)} + */ + public static @CheckForNull T find(Collection list, String string) { + T d = findByClassName(list, string); + if (d != null) { return d; } - return null; + return findById(list, string); } public static @CheckForNull Descriptor find(String className) { From 901194ae77358b49016a32e6c97e74a70cbbb261 Mon Sep 17 00:00:00 2001 From: Nicolas De Loof Date: Fri, 6 Feb 2015 17:09:12 +0100 Subject: [PATCH 005/285] make $class and kind mutually exclusive Use kind when descriptor.id != descriptor.clazz.name and $clazz otherwise. --- core/src/main/java/hudson/model/Descriptor.java | 14 +++++++++++++- .../hudson/tools/DownloadFromUrlInstaller.java | 6 +++--- .../main/resources/lib/form/class-entry.jelly | 16 ++++++++++------ 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/core/src/main/java/hudson/model/Descriptor.java b/core/src/main/java/hudson/model/Descriptor.java index a043d6b2fa..e68517ce74 100644 --- a/core/src/main/java/hudson/model/Descriptor.java +++ b/core/src/main/java/hudson/model/Descriptor.java @@ -916,7 +916,8 @@ public abstract class Descriptor> implements Saveable { } if (d == null) { kind = jo.getString("$class"); - d = findByClassName(descriptors, kind); + d = findByDescribableClassName(descriptors, kind); + if (d == null) d = findByClassName(descriptors, kind); } if (d != null) { items.add(d.newInstance(req, jo)); @@ -952,6 +953,17 @@ public abstract class Descriptor> implements Saveable { return null; } + /** + * Finds a descriptor from a collection by the class name of the Describable it describes. + */ + public static @CheckForNull T findByDescribableClassName(Collection list, String className) { + for (T d : list) { + if(d.clazz.getName().equals(className)) + return d; + } + return null; + } + /** * Finds a descriptor from a collection by its class name or ID. * @deprecated choose between {@link #findById(java.util.Collection, String)} or {@link #findByClassName(java.util.Collection, String)} diff --git a/core/src/main/java/hudson/tools/DownloadFromUrlInstaller.java b/core/src/main/java/hudson/tools/DownloadFromUrlInstaller.java index 938325f668..418f7fd1e7 100644 --- a/core/src/main/java/hudson/tools/DownloadFromUrlInstaller.java +++ b/core/src/main/java/hudson/tools/DownloadFromUrlInstaller.java @@ -122,7 +122,7 @@ public abstract class DownloadFromUrlInstaller extends ToolInstaller { } protected Downloadable createDownloadable() { - return new Downloadable(getId()); + return new Downloadable(getDownloadableId()); } /** @@ -130,7 +130,7 @@ public abstract class DownloadFromUrlInstaller extends ToolInstaller { *

* By default we use the fully-qualified class name of the {@link DownloadFromUrlInstaller} subtype. */ - public String getId() { + public String getDownloadableId() { return clazz.getName().replace('$','.'); } @@ -144,7 +144,7 @@ public abstract class DownloadFromUrlInstaller extends ToolInstaller { * @return never null. */ public List getInstallables() throws IOException { - JSONObject d = Downloadable.get(getId()).getData(); + JSONObject d = Downloadable.get(getDownloadableId()).getData(); if(d==null) return Collections.emptyList(); return Arrays.asList(((InstallableList)JSONObject.toBean(d,InstallableList.class)).list); } diff --git a/core/src/main/resources/lib/form/class-entry.jelly b/core/src/main/resources/lib/form/class-entry.jelly index 371f5137d8..89a1076798 100644 --- a/core/src/main/resources/lib/form/class-entry.jelly +++ b/core/src/main/resources/lib/form/class-entry.jelly @@ -36,11 +36,15 @@ THE SOFTWARE. - - - - - - + + + + + + + + + + From 5f7629bb8b7d4dc853134a3d831ab4d4d411780a Mon Sep 17 00:00:00 2001 From: Nicolas De Loof Date: Thu, 12 Feb 2015 22:24:25 +0100 Subject: [PATCH 006/285] =?UTF-8?q?prevent=20removing=20artifact=20when=20?= =?UTF-8?q?build=20isn=E2=80=99t=20completed=20yet?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/src/main/java/hudson/tasks/LogRotator.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/src/main/java/hudson/tasks/LogRotator.java b/core/src/main/java/hudson/tasks/LogRotator.java index bc7a2d9738..8797a334db 100644 --- a/core/src/main/java/hudson/tasks/LogRotator.java +++ b/core/src/main/java/hudson/tasks/LogRotator.java @@ -187,6 +187,10 @@ public class LogRotator extends BuildDiscarder { LOGGER.log(FINER, "{0} is not to be removed or purged of artifacts because it’s the last stable build", r); return true; } + if (r.isBuilding()) { + LOGGER.log(FINER, "{0} is not to be removed or purged of artifacts because it’s still building", r); + return true; + } return false; } From 7a2dc32cc3b309a4391ada820732a550d9d4badc Mon Sep 17 00:00:00 2001 From: christ66 Date: Sun, 15 Feb 2015 23:29:21 -0800 Subject: [PATCH 007/285] [JENKINS-26391] Prevent lazy loading operation when obtaining label information. --- core/src/main/java/hudson/model/Label.java | 4 +-- test/src/test/java/hudson/model/NodeTest.java | 25 +++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/hudson/model/Label.java b/core/src/main/java/hudson/model/Label.java index cdfcfb5e86..da779f845e 100644 --- a/core/src/main/java/hudson/model/Label.java +++ b/core/src/main/java/hudson/model/Label.java @@ -374,7 +374,7 @@ public abstract class Label extends Actionable implements Comparable

"
-            + Functions.printThrowable(e) +
+            + Util.escape(Functions.printThrowable(e)) +
             "
",kind ); } From 25bf232c0d1abf20ab5a27c6cc808c53d46ea1c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20Gond=C5=BEa?= Date: Sat, 7 Mar 2015 20:02:02 +0100 Subject: [PATCH 019/285] [SECURITY-180] Test --- test/src/test/java/hudson/model/UserTest.java | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/test/src/test/java/hudson/model/UserTest.java b/test/src/test/java/hudson/model/UserTest.java index a8f37057a4..65dda3e978 100644 --- a/test/src/test/java/hudson/model/UserTest.java +++ b/test/src/test/java/hudson/model/UserTest.java @@ -28,19 +28,27 @@ import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException; import com.gargoylesoftware.htmlunit.WebAssert; import com.gargoylesoftware.htmlunit.html.HtmlForm; import com.gargoylesoftware.htmlunit.html.HtmlPage; + import hudson.security.AccessDeniedException2; import hudson.security.GlobalMatrixAuthorizationStrategy; import hudson.security.HudsonPrivateSecurityRealm; import hudson.security.Permission; import hudson.tasks.MailAddressResolver; + import java.io.IOException; import java.io.PrintStream; import java.util.Collections; + import jenkins.model.Jenkins; +import jenkins.security.ApiTokenProperty; + +import org.acegisecurity.AccessDeniedException; import org.acegisecurity.Authentication; import org.acegisecurity.context.SecurityContext; import org.acegisecurity.context.SecurityContextHolder; + import static org.junit.Assert.*; + import org.junit.Rule; import org.junit.Test; import org.jvnet.hudson.test.Bug; @@ -419,6 +427,42 @@ public class UserTest { assertTrue("User should be able to delete.", user.canDelete()); } + @Test + // @Issue("SECURITY-180") + public void security180() throws Exception { + final GlobalMatrixAuthorizationStrategy auth = new GlobalMatrixAuthorizationStrategy(); + j.jenkins.setAuthorizationStrategy(auth); + j.jenkins.setSecurityRealm(new HudsonPrivateSecurityRealm(false)); + + User alice = User.get("alice"); + User bob = User.get("bob"); + User anonymous = User.get("anonymous"); + User admin = User.get("admin"); + + auth.add(Jenkins.READ, alice.getId()); + auth.add(Jenkins.READ, bob.getId()); + auth.add(Jenkins.ADMINISTER, admin.getId()); + + SecurityContextHolder.getContext().setAuthentication(admin.impersonate()); + // Change token by admin + admin.getProperty(ApiTokenProperty.class).changeApiToken(); + alice.getProperty(ApiTokenProperty.class).changeApiToken(); + + SecurityContextHolder.getContext().setAuthentication(bob.impersonate()); + // Change own token + bob.getProperty(ApiTokenProperty.class).changeApiToken(); + + try { + alice.getProperty(ApiTokenProperty.class).changeApiToken(); + fail("Bob should not be authorized to change alice's token"); + } catch (AccessDeniedException expected) { } + + try { + anonymous.getProperty(ApiTokenProperty.class).changeApiToken(); + fail("Anonymous should not be authorized to change alice's token"); + } catch (AccessDeniedException expected) { } + } + @Test public void testGetDynamic() { From f880d8d2cd9d46987ee3630fa04f77b17784f4e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20Gond=C5=BEa?= Date: Sat, 7 Mar 2015 20:32:17 +0100 Subject: [PATCH 020/285] [SECURITY-171] test --- core/src/test/java/hudson/util/FormValidationTest.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/core/src/test/java/hudson/util/FormValidationTest.java b/core/src/test/java/hudson/util/FormValidationTest.java index 281a11f152..1840a54e3f 100644 --- a/core/src/test/java/hudson/util/FormValidationTest.java +++ b/core/src/test/java/hudson/util/FormValidationTest.java @@ -23,6 +23,10 @@ */ package hudson.util; +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.MatcherAssert.assertThat; + import junit.framework.TestCase; /** @@ -51,4 +55,9 @@ public class FormValidationTest extends TestCase { public void testMessage() { assertEquals("test msg", FormValidation.errorWithMarkup("test msg").getMessage()); } + + public void testFormValidationException() { + FormValidation fv = FormValidation.error(new Exception(" Date: Mon, 23 Feb 2015 13:18:15 +0100 Subject: [PATCH 021/285] JENKINS-24433 Searchbox doesn't work properly inside a folder --- core/src/main/java/hudson/search/Search.java | 2 +- .../java/hudson/search/SuggestedItem.java | 2 +- .../test/java/hudson/search/SearchTest.java | 123 ++++++++++++++++++ 3 files changed, 125 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/hudson/search/Search.java b/core/src/main/java/hudson/search/Search.java index f6f5d1051a..c817a26dbd 100644 --- a/core/src/main/java/hudson/search/Search.java +++ b/core/src/main/java/hudson/search/Search.java @@ -76,7 +76,7 @@ public class Search { SuggestedItem target = find(index, query, smo); if(target!=null) { // found - rsp.sendRedirect2(a.getUrl()+target.getUrl()); + rsp.sendRedirect2(req.getContextPath()+target.getUrl()); return; } } diff --git a/core/src/main/java/hudson/search/SuggestedItem.java b/core/src/main/java/hudson/search/SuggestedItem.java index 1dbcad9c3d..31e5956ce4 100644 --- a/core/src/main/java/hudson/search/SuggestedItem.java +++ b/core/src/main/java/hudson/search/SuggestedItem.java @@ -81,7 +81,7 @@ public class SuggestedItem { private static SuggestedItem build(SearchableModelObject searchContext, Item top) { ItemGroup parent = top.getParent(); - if (parent instanceof Item && parent != searchContext) { + if (parent instanceof Item) { Item parentItem = (Item)parent; return new SuggestedItem(build(searchContext, parentItem), top); } diff --git a/test/src/test/java/hudson/search/SearchTest.java b/test/src/test/java/hudson/search/SearchTest.java index c90858e388..fc5a353661 100644 --- a/test/src/test/java/hudson/search/SearchTest.java +++ b/test/src/test/java/hudson/search/SearchTest.java @@ -105,6 +105,40 @@ public class SearchTest { assertTrue(contents.contains(String.format("%s [Jenkins]", projectName))); } + @Issue("JENKINS-24433") + @Test + public void testSearchByProjectNameBehindAFolder() throws Exception { + final String projectName = "testSearchByProjectName"; + j.createFreeStyleProject(projectName); + j.createFolder("my-folder-1").createProject(FreeStyleProject.class, "my-job-1"); + + Page result = j.createWebClient().goTo("job/my-folder-1/search?q="+ projectName); + + assertNotNull(result); + j.assertGoodStatus(result); + + // make sure we've fetched the testSearchByDisplayName project page + String contents = result.getWebResponse().getContentAsString(); + assertTrue(contents.contains(String.format("%s [Jenkins]", projectName))); + } + + @Issue("JENKINS-24433") + @Test + public void testSearchByProjectNameInAFolder() throws Exception { + final String projectName = "testSearchByProjectName"; + j.createFreeStyleProject(projectName); + j.createFolder("my-folder-1").createProject(FreeStyleProject.class, "my-job-1"); + + Page result = j.createWebClient().goTo("job/my-folder-1/search?q="+ "my-folder-1/my-job-1"); + + assertNotNull(result); + j.assertGoodStatus(result); + + // make sure we've fetched the testSearchByDisplayName project page + String contents = result.getWebResponse().getContentAsString(); + assertTrue(contents.contains(String.format("%s [Jenkins]", "my-job-1 [my-folder-1]"))); + } + @Test public void testSearchByDisplayName() throws Exception { final String displayName = "displayName9999999"; @@ -225,6 +259,95 @@ public class SearchTest { assertTrue(foundDispayName); } + @Issue("JENKINS-24433") + @Test + public void testProjectNameBehindAFolderDisplayName() throws Exception { + final String projectName1 = "job-1"; + final String displayName1 = "job-1"; + + final String projectName2 = "job-2"; + final String displayName2 = "job-2"; + + FreeStyleProject project1 = j.createFreeStyleProject(projectName1); + project1.setDisplayName(displayName1); + + FreeStyleProject project2 = j.createFolder("my-folder-1").createProject(FreeStyleProject.class, projectName2); + project2.setDisplayName(displayName2); + + WebClient wc = j.createWebClient(); + Page result = wc.goTo("job/my-folder-1/search/suggest?query=" + projectName1, "application/json"); + assertNotNull(result); + j.assertGoodStatus(result); + + String content = result.getWebResponse().getContentAsString(); + JSONObject jsonContent = (JSONObject)JSONSerializer.toJSON(content); + assertNotNull(jsonContent); + JSONArray jsonArray = jsonContent.getJSONArray("suggestions"); + assertNotNull(jsonArray); + + assertEquals(1, jsonArray.size()); + + boolean foundProjectName = false; + boolean foundDisplayName = false; + for(Object suggestion : jsonArray) { + JSONObject jsonSuggestion = (JSONObject)suggestion; + + String name = (String)jsonSuggestion.get("name"); + if(projectName1.equals(name)) { + foundProjectName = true; + } + if(displayName1.equals(name)) { + foundDisplayName = true; + } + } + + assertTrue(foundProjectName); + assertTrue(foundDisplayName); + } + + @Issue("JENKINS-24433") + @Test + public void testProjectNameInAFolderDisplayName() throws Exception { + final String projectName1 = "job-1"; + final String displayName1 = "job-1"; + + final String projectName2 = "job-2"; + final String displayName2 = "my-folder-1 job-2"; + + FreeStyleProject project1 = j.createFreeStyleProject(projectName1); + project1.setDisplayName(displayName1); + + FreeStyleProject project2 = j.createFolder("my-folder-1").createProject(FreeStyleProject.class, projectName2); + project2.setDisplayName(displayName2); + + + WebClient wc = j.createWebClient(); + Page result = wc.goTo("job/my-folder-1/search/suggest?query=" + projectName2, "application/json"); + assertNotNull(result); + j.assertGoodStatus(result); + + String content = result.getWebResponse().getContentAsString(); + JSONObject jsonContent = (JSONObject)JSONSerializer.toJSON(content); + assertNotNull(jsonContent); + JSONArray jsonArray = jsonContent.getJSONArray("suggestions"); + assertNotNull(jsonArray); + + assertEquals(1, jsonArray.size()); + + boolean foundDisplayName = false; + for(Object suggestion : jsonArray) { + JSONObject jsonSuggestion = (JSONObject)suggestion; + + String name = (String)jsonSuggestion.get("name"); + + if(displayName2.equals(name)) { + foundDisplayName = true; + } + } + + assertTrue(foundDisplayName); + } + /** * Disable/enable status shouldn't affect the search */ From fb5540e38c935676d7f58e9d2ce7a84275bb898f Mon Sep 17 00:00:00 2001 From: Felix Belzunce Arcos Date: Mon, 9 Mar 2015 11:45:00 +0100 Subject: [PATCH 022/285] JENKINS-27183 Avoid deadlock when using build-monitor-plugin --- core/src/main/java/hudson/model/AbstractItem.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/hudson/model/AbstractItem.java b/core/src/main/java/hudson/model/AbstractItem.java index 5f298eb3d5..980da8ed44 100644 --- a/core/src/main/java/hudson/model/AbstractItem.java +++ b/core/src/main/java/hudson/model/AbstractItem.java @@ -216,6 +216,8 @@ public abstract class AbstractItem extends Actionable implements Item, HttpDelet protected void renameTo(final String newName) throws IOException { // always synchronize from bigger objects first final ItemGroup parent = getParent(); + String oldName = this.name; + String oldFullName = getFullName(); synchronized (parent) { synchronized (this) { // sanity check @@ -248,9 +250,6 @@ public abstract class AbstractItem extends Actionable implements Item, HttpDelet } }); - - String oldName = this.name; - String oldFullName = getFullName(); File oldRoot = this.getRootDir(); doSetName(newName); @@ -324,10 +323,9 @@ public abstract class AbstractItem extends Actionable implements Item, HttpDelet } catch (AbstractMethodError _) { // ignore } - - ItemListener.fireLocationChange(this, oldFullName); } } + ItemListener.fireLocationChange(this, oldFullName); } From 80e9f3f50c3425c9b9b2bfdb58b03a1f1bd10aa3 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Thu, 12 Mar 2015 09:37:02 +0000 Subject: [PATCH 023/285] [FIXED JENKINS-22346] The original motivation for the fix (to prevent users from logging in once he's removed from the backend identity database) is legitimate, but it affected too many users. So as an escape hatch / non-promoted feature switch, I'm adding this option to bring back the old behaviour. --- changelog.html | 3 +++ core/src/main/java/hudson/model/User.java | 13 ++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/changelog.html b/changelog.html index f9713fda7c..06e69f3ff4 100644 --- a/changelog.html +++ b/changelog.html @@ -79,6 +79,9 @@ Upcoming changes
  • Show displayName in build remote API. (issue 26723) +
  • + Added a switch (-Dhudson.model.User.allowNonExistentUserToLogin=true) to let users login even when the record is not found in the backend security realm. + (issue 22346)

    What's new in 1.601 (2015/03/03)

      diff --git a/core/src/main/java/hudson/model/User.java b/core/src/main/java/hudson/model/User.java index d39b9b6f9d..1ef3af9989 100644 --- a/core/src/main/java/hudson/model/User.java +++ b/core/src/main/java/hudson/model/User.java @@ -304,7 +304,8 @@ public class User extends AbstractModelObject implements AccessControlled, Descr // backend can't load information about other users. so use the stored information if available } catch (UsernameNotFoundException e) { // if the user no longer exists in the backend, we need to refuse impersonating this user - throw e; + if (!ALLOW_NON_EXISTENT_USER_TO_LOGIN) + throw e; } catch (DataAccessException e) { // seems like it's in the same boat as UserMayOrMayNotExistException } @@ -976,5 +977,15 @@ public class User extends AbstractModelObject implements AccessControlled, Descr } } + /** + * Jenkins now refuses to let the user login if he/she doesn't exist in {@link SecurityRealm}, + * which was necessary to make sure users removed from the backend will get removed from the frontend. + *

      + * Unfortunately this infringed some legitimate use cases of creating Jenkins-local users for + * automation purposes. This escape hatch switch can be enabled to resurrect that behaviour. + * + * JENKINS-22346. + */ + public static boolean ALLOW_NON_EXISTENT_USER_TO_LOGIN = Boolean.getBoolean(User.class.getName()+".allowNonExistentUserToLogin"); } From ad9d191cbcee8928744d375bc13c629bd470329b Mon Sep 17 00:00:00 2001 From: tfennelly Date: Thu, 12 Mar 2015 19:15:48 +0000 Subject: [PATCH 024/285] [FIXED JENKINS-27256] Added functional test for stapler fix to handle dispatcher methods for getX(long) model methods --- core/pom.xml | 2 +- .../src/test/java/hudson/model/QueueTest.java | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/core/pom.xml b/core/pom.xml index 69bf03a480..bcff744f07 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -39,7 +39,7 @@ THE SOFTWARE. true - 1.234 + 1.235-20150312.163208-1 2.5.6.SEC03 1.8.9 diff --git a/test/src/test/java/hudson/model/QueueTest.java b/test/src/test/java/hudson/model/QueueTest.java index 264bc69e52..e65b5e7115 100644 --- a/test/src/test/java/hudson/model/QueueTest.java +++ b/test/src/test/java/hudson/model/QueueTest.java @@ -26,6 +26,7 @@ package hudson.model; import com.gargoylesoftware.htmlunit.html.HtmlFileInput; import com.gargoylesoftware.htmlunit.html.HtmlForm; import com.gargoylesoftware.htmlunit.html.HtmlPage; +import com.gargoylesoftware.htmlunit.xml.XmlPage; import hudson.Launcher; import hudson.XmlFile; import hudson.matrix.AxisList; @@ -421,6 +422,27 @@ public class QueueTest { assert task.exec instanceof OneOffExecutor : task.exec; } + @Issue("JENKINS-27256") + @Test public void inQueueTaskLookupByAPI() throws Exception { + FreeStyleProject p = r.createFreeStyleProject(); + Label label = Label.get("unknown-slave"); + + // Give the project an "unknown-slave" label, forcing it to + // stay in the queue after we schedule it, allowing us to query it. + p.setAssignedLabel(label); + p.scheduleBuild2(0); + + JenkinsRule.WebClient webclient = r.createWebClient(); + + XmlPage queueItems = webclient.goToXml("queue/api/xml"); + String queueTaskId = queueItems.getXmlDocument().getElementsByTagName("id").item(0).getTextContent(); + assertNotNull(queueTaskId); + XmlPage queueItem = webclient.goToXml("queue/item/" + queueTaskId + "/api/xml"); + assertNotNull(queueItem); + String tagName = queueItem.getDocumentElement().getTagName(); + assertTrue(tagName.equals("blockedItem") || tagName.equals("buildableItem")); + } + private static class TestFlyweightTask extends TestTask implements Queue.FlyweightTask { Executor exec; private final Label assignedLabel; From 50a83a1f6693b70edf5d41d78e0439970fb3da19 Mon Sep 17 00:00:00 2001 From: Daniel Beck Date: Thu, 12 Mar 2015 20:46:51 +0100 Subject: [PATCH 025/285] Remove two fixes that were backported to RC --- changelog.html | 6 ------ 1 file changed, 6 deletions(-) diff --git a/changelog.html b/changelog.html index 06e69f3ff4..6af9acba4f 100644 --- a/changelog.html +++ b/changelog.html @@ -70,12 +70,6 @@ Upcoming changes

      What's new in 1.602 (2015/03/08)

        -
      • - Regression with environment variables in 1.600. - (issue 27188) -
      • - Errors with concurrent matrix builds since 1.597. - (issue 26739)
      • Show displayName in build remote API. (issue 26723) From 84800166b075118cec1845e49aa230ef8a23799c Mon Sep 17 00:00:00 2001 From: Daniel Beck Date: Thu, 12 Mar 2015 23:44:34 +0100 Subject: [PATCH 026/285] Noting #1593, #1579, move JENKINS-22346, #1558 --- changelog.html | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/changelog.html b/changelog.html index 6af9acba4f..daec92ca2b 100644 --- a/changelog.html +++ b/changelog.html @@ -55,7 +55,9 @@ Upcoming changes @@ -66,16 +68,16 @@ Upcoming changes
      • As security hardening, mark "remember me" cookie as HTTP only (issue 27277) +
      • + Show displayName in build remote API. + (issue 26723)

      What's new in 1.602 (2015/03/08)

      • - Show displayName in build remote API. - (issue 26723) -
      • - Added a switch (-Dhudson.model.User.allowNonExistentUserToLogin=true) to let users login even when the record is not found in the backend security realm. - (issue 22346) + Show Check Now button also on Available and Updates tabs of plugin manager. + (PR 1593)

      What's new in 1.601 (2015/03/03)

        @@ -88,6 +90,9 @@ Upcoming changes
      • Errors in Dashboard View plugin since 1.597. (issue 26690) +
      • + Robustness improvement when setting up Archive Artifacts programmatically. + (issue 25779)
      • Map Queue.Item.id onto Run (issue 27096) From 2e13ebdf389f7bd9daa3e91ea68654ba4c061039 Mon Sep 17 00:00:00 2001 From: tfennelly Date: Thu, 12 Mar 2015 23:02:43 +0000 Subject: [PATCH 027/285] Fixed snapshot dep in effort to help CI build pass. --- core/pom.xml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/core/pom.xml b/core/pom.xml index bcff744f07..b449ce5589 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -39,7 +39,7 @@ THE SOFTWARE. true - 1.235-20150312.163208-1 + 1.234 2.5.6.SEC03 1.8.9 @@ -115,6 +115,12 @@ THE SOFTWARE. trilead-ssh2 build217-jenkins-8 + + + org.kohsuke.stapler + stapler + 1.235-20150312.230034-2 + org.kohsuke.stapler stapler-groovy From 94af3a4a8a73bd3bdb3c58ee8e7a193b21d6fb70 Mon Sep 17 00:00:00 2001 From: Grogdunn Date: Fri, 13 Mar 2015 10:41:46 +0100 Subject: [PATCH 028/285] Fix: bump stapler version Bump stapler to lastest. --- core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/pom.xml b/core/pom.xml index d54566244e..1e4e861c3b 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -39,7 +39,7 @@ THE SOFTWARE. true - 1.234 + 1.236-SNAPSHOT 2.5.6.SEC03 1.8.9 From 1b75b38d4cce187cceb5cb56a2810073fc54f990 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20Gond=C5=BEa?= Date: Fri, 13 Mar 2015 12:43:37 +0100 Subject: [PATCH 029/285] Noting #1597 --- changelog.html | 3 +++ 1 file changed, 3 insertions(+) diff --git a/changelog.html b/changelog.html index daec92ca2b..5628660775 100644 --- a/changelog.html +++ b/changelog.html @@ -58,6 +58,9 @@ Upcoming changes
      • Added a switch (-Dhudson.model.User.allowNonExistentUserToLogin=true) to let users login even when the record is not found in the backend security realm. (issue 22346) +
      • + Avoid deadlock when using build-monitor-plugin. + (issue 27183)
      From 12e55e4645ee9703cbaba115694c3ea79b762669 Mon Sep 17 00:00:00 2001 From: Daniel Beck Date: Fri, 13 Mar 2015 14:49:20 +0100 Subject: [PATCH 030/285] [JENKINS-27414] Don't offer to restart if unsupported --- .../jenkins/model/Jenkins/_restart.jelly | 15 +++++++++++---- .../jenkins/model/Jenkins/_safeRestart.jelly | 15 +++++++++++---- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/core/src/main/resources/jenkins/model/Jenkins/_restart.jelly b/core/src/main/resources/jenkins/model/Jenkins/_restart.jelly index 7816f469c5..cfead03b2d 100644 --- a/core/src/main/resources/jenkins/model/Jenkins/_restart.jelly +++ b/core/src/main/resources/jenkins/model/Jenkins/_restart.jelly @@ -28,10 +28,17 @@ THE SOFTWARE. -
      - ${%Are you sure about restarting Jenkins?} - - + + +
      + ${%Are you sure about restarting Jenkins?} + + +
      + + ${%Jenkins cannot restart itself as currently configured.} + +
      \ No newline at end of file diff --git a/core/src/main/resources/jenkins/model/Jenkins/_safeRestart.jelly b/core/src/main/resources/jenkins/model/Jenkins/_safeRestart.jelly index 3a76e6af82..e37bf2ece0 100644 --- a/core/src/main/resources/jenkins/model/Jenkins/_safeRestart.jelly +++ b/core/src/main/resources/jenkins/model/Jenkins/_safeRestart.jelly @@ -28,10 +28,17 @@ THE SOFTWARE. -
      - ${%Are you sure about restarting Jenkins? Jenkins will restart once all running jobs are finished.} - - + + +
      + ${%Are you sure about restarting Jenkins? Jenkins will restart once all running jobs are finished.} + + +
      + + ${%Jenkins cannot restart itself as currently configured.} + +
      \ No newline at end of file From 9a69d6191ab3259709ed7fba0411b652a32bbab9 Mon Sep 17 00:00:00 2001 From: Matt Legrand Date: Fri, 13 Mar 2015 12:07:41 -0700 Subject: [PATCH 031/285] JENKINS-23197: add datestamp to node-offline message --- core/src/main/java/hudson/slaves/OfflineCause.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/hudson/slaves/OfflineCause.java b/core/src/main/java/hudson/slaves/OfflineCause.java index e603135f53..3ec9a24ba1 100644 --- a/core/src/main/java/hudson/slaves/OfflineCause.java +++ b/core/src/main/java/hudson/slaves/OfflineCause.java @@ -33,6 +33,7 @@ import org.acegisecurity.Authentication; import org.jvnet.localizer.Localizable; import org.kohsuke.stapler.export.ExportedBean; import org.kohsuke.stapler.export.Exported; +import java.util.Date; /** * Represents a cause that puts a {@linkplain Computer#isOffline() computer offline}. @@ -113,7 +114,7 @@ public abstract class OfflineCause { public UserCause(User user, String message) { super(hudson.slaves.Messages._SlaveComputer_DisconnectedBy( user!=null ? user.getId() : Jenkins.ANONYMOUS.getName(), - message != null ? " : " + message : "" + " [ " + new Date() + " ] " + (message != null ? " : " + message : "") )); this.user = user; } From 37534fa359ea9f11a579157feee68b7e959a7c3b Mon Sep 17 00:00:00 2001 From: Matt Legrand Date: Fri, 13 Mar 2015 17:09:23 -0700 Subject: [PATCH 032/285] alternative and more general solution suggested by D. Beck --- core/src/main/java/hudson/slaves/OfflineCause.java | 6 ++++-- test/src/test/java/hudson/model/NodeTest.java | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/hudson/slaves/OfflineCause.java b/core/src/main/java/hudson/slaves/OfflineCause.java index 3ec9a24ba1..b427b71331 100644 --- a/core/src/main/java/hudson/slaves/OfflineCause.java +++ b/core/src/main/java/hudson/slaves/OfflineCause.java @@ -55,17 +55,19 @@ public abstract class OfflineCause { */ public static class SimpleOfflineCause extends OfflineCause { public final Localizable description; + public final Date timestamp; /** * @since 1.571 */ protected SimpleOfflineCause(Localizable description) { this.description = description; + this.timestamp = new Date(); } @Exported(name="description") @Override public String toString() { - return description.toString(); + return "[" + timestamp.toString() + "] " + description.toString(); } } @@ -114,7 +116,7 @@ public abstract class OfflineCause { public UserCause(User user, String message) { super(hudson.slaves.Messages._SlaveComputer_DisconnectedBy( user!=null ? user.getId() : Jenkins.ANONYMOUS.getName(), - " [ " + new Date() + " ] " + (message != null ? " : " + message : "") + message != null ? " : " + message : "" )); this.user = user; } diff --git a/test/src/test/java/hudson/model/NodeTest.java b/test/src/test/java/hudson/model/NodeTest.java index 63eac12117..781d305d43 100644 --- a/test/src/test/java/hudson/model/NodeTest.java +++ b/test/src/test/java/hudson/model/NodeTest.java @@ -102,7 +102,7 @@ public class NodeTest { computer.doToggleOffline("original message"); cause = (UserCause) computer.getOfflineCause(); - assertEquals("Disconnected by someone@somewhere.com : original message", cause.toString()); + assertTrue(cause.toString(), cause.toString().matches("^.*?Disconnected by someone@somewhere.com : original message")); assertEquals(someone, cause.getUser()); final User root = User.get("root@localhost"); From 0ed1fb97ba7a1cc20179bb9a641b50116438ab41 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Sun, 15 Mar 2015 10:32:26 -0700 Subject: [PATCH 033/285] [maven-release-plugin] prepare release jenkins-1.604 --- cli/pom.xml | 2 +- core/pom.xml | 2 +- plugins/pom.xml | 10 +++++----- pom.xml | 4 ++-- test/pom.xml | 2 +- war/pom.xml | 2 +- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/cli/pom.xml b/cli/pom.xml index 32f957698e..024e590484 100644 --- a/cli/pom.xml +++ b/cli/pom.xml @@ -5,7 +5,7 @@ org.jenkins-ci.main pom - 1.604-SNAPSHOT + 1.604 cli diff --git a/core/pom.xml b/core/pom.xml index 69bf03a480..2d3afee2f2 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -29,7 +29,7 @@ THE SOFTWARE. org.jenkins-ci.main pom - 1.604-SNAPSHOT + 1.604 jenkins-core diff --git a/plugins/pom.xml b/plugins/pom.xml index 31de880d3e..d14ab90fc2 100644 --- a/plugins/pom.xml +++ b/plugins/pom.xml @@ -12,7 +12,7 @@ org.jenkins-ci.plugins plugin Jenkins plugin POM - 1.604-SNAPSHOT + 1.604 pom +

      What's new in 1.604 (2015/03/15)

      • Added a switch (-Dhudson.model.User.allowNonExistentUserToLogin=true) to let users login even when the record is not found in the backend security realm. @@ -61,13 +66,6 @@ Upcoming changes
      • Avoid deadlock when using build-monitor-plugin. (issue 27183) -
      - - - -

      What's new in 1.602 (2015/03/08)

      • From 9d52e5772de250377f5f38d0d083b0e0272a7585 Mon Sep 17 00:00:00 2001 From: tfennelly Date: Mon, 16 Mar 2015 09:05:23 +0000 Subject: [PATCH 037/285] Updated stapler dep to 1.235 --- core/pom.xml | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index b449ce5589..0db9b59f28 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -39,7 +39,7 @@ THE SOFTWARE. true - 1.234 + 1.235 2.5.6.SEC03 1.8.9 @@ -115,12 +115,6 @@ THE SOFTWARE. trilead-ssh2 build217-jenkins-8 - - - org.kohsuke.stapler - stapler - 1.235-20150312.230034-2 - org.kohsuke.stapler stapler-groovy From e6fdc19cf9174390386a98935ff1d7cf81dbe82f Mon Sep 17 00:00:00 2001 From: Stephen Connolly Date: Mon, 16 Mar 2015 12:36:04 +0000 Subject: [PATCH 038/285] [JENKINS-27058] Clarify that remoteFS can be relative if you know what you are doing - Get the absolute path on connect and use that while the connection is on-line (which is ok as when the connection is not online a null was returned from getRootPath() anyway) --- core/src/main/java/hudson/model/Slave.java | 50 ++++++++++------ .../java/hudson/slaves/CommandLauncher.java | 23 ++++---- .../java/hudson/slaves/SlaveComputer.java | 59 ++++++++++++++----- .../hudson/model/Messages.properties | 4 +- 4 files changed, 90 insertions(+), 46 deletions(-) diff --git a/core/src/main/java/hudson/model/Slave.java b/core/src/main/java/hudson/model/Slave.java index 92ac16518d..6d32b29e94 100644 --- a/core/src/main/java/hudson/model/Slave.java +++ b/core/src/main/java/hudson/model/Slave.java @@ -1,19 +1,19 @@ /* * The MIT License - * + * * Copyright (c) 2004-2011, Sun Microsystems, Inc., Kohsuke Kawaguchi, * Erik Ramfelt, Martin Eigenbrodt, Stephen Connolly, Tom Huybrechts - * + * * 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 @@ -63,6 +63,7 @@ import jenkins.security.MasterToSlaveCallable; import jenkins.slaves.WorkspaceLocator; import org.apache.commons.io.IOUtils; +import org.apache.commons.lang.StringUtils; import org.kohsuke.stapler.HttpResponse; import org.kohsuke.stapler.QueryParameter; import org.kohsuke.stapler.StaplerRequest; @@ -92,8 +93,12 @@ public abstract class Slave extends Node implements Serializable { private final String description; /** - * Absolute path to the root of the workspace - * from the view point of this node, such as "/hudson" + * Path to the root of the workspace from the view point of this node, such as "/hudson", this need not + * be absolute provided that the launcher establishes a consistent working directory, such as "./.jenkins-slave" + * when used with an SSH launcher. + * + * NOTE: if the administrator is using a relative path they are responsible for ensuring that the launcher used + * provides a consistent working directory */ protected final String remoteFS; @@ -121,14 +126,14 @@ public abstract class Slave extends Node implements Serializable { * Whitespace-separated labels. */ private String label=""; - + private /*almost final*/ DescribableList,NodePropertyDescriptor> nodeProperties = new DescribableList,NodePropertyDescriptor>(Jenkins.getInstance()); /** * Lazily computed set of labels from {@link #label}. */ private transient volatile Set