From a92b6bfe17b169b8e05dac16cfd4961387875bd8 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Wed, 17 Oct 2012 22:51:43 -0400 Subject: [PATCH 001/702] debian: Fill in gecos field for jenkins user Otherwise when Jenkins runs git, git will complain that the identity is not set up correctly and will fail. --- debian/debian/jenkins.postinst | 1 + 1 file changed, 1 insertion(+) diff --git a/debian/debian/jenkins.postinst b/debian/debian/jenkins.postinst index c114ab5fca..000499bd6e 100644 --- a/debian/debian/jenkins.postinst +++ b/debian/debian/jenkins.postinst @@ -30,6 +30,7 @@ case "$1" in if ! id $JENKINS_USER > /dev/null 2>&1 ; then adduser --system --home /var/lib/jenkins --no-create-home \ --ingroup nogroup --disabled-password --shell /bin/bash \ + --gecos 'Jenkins' \ $JENKINS_USER fi From e598bfb04d58090c3165839156f839c6ead42927 Mon Sep 17 00:00:00 2001 From: Samuel Moritz Date: Sun, 9 Dec 2012 14:51:49 +0100 Subject: [PATCH 002/702] JENKINS-15380. Add some length checking before trying to substring. --- .../java/hudson/tasks/junit/ClassResult.java | 11 ++--- .../hudson/tasks/junit/ClassResultTest.java | 41 +++++++++++++++++++ 2 files changed, 47 insertions(+), 5 deletions(-) create mode 100644 core/src/test/java/hudson/tasks/junit/ClassResultTest.java diff --git a/core/src/main/java/hudson/tasks/junit/ClassResult.java b/core/src/main/java/hudson/tasks/junit/ClassResult.java index 86f2bf549c..bb2d8b0ef8 100644 --- a/core/src/main/java/hudson/tasks/junit/ClassResult.java +++ b/core/src/main/java/hudson/tasks/junit/ClassResult.java @@ -80,14 +80,15 @@ public final class ClassResult extends TabulatedResult implements Comparable 0) { int caseNameStart = base + myID.length() + 1; - caseName = id.substring(caseNameStart); - } else { - caseName = id; - } + int caseNameLength = id.length() - caseNameStart; + if (caseNameLength > 0) { + caseName = id.substring(caseNameStart); + } + } CaseResult child = getCaseResult(caseName); if (child != null) { diff --git a/core/src/test/java/hudson/tasks/junit/ClassResultTest.java b/core/src/test/java/hudson/tasks/junit/ClassResultTest.java new file mode 100644 index 0000000000..96e5b1dbf1 --- /dev/null +++ b/core/src/test/java/hudson/tasks/junit/ClassResultTest.java @@ -0,0 +1,41 @@ +package hudson.tasks.junit; + +import hudson.tasks.test.TestResult; +import junit.framework.TestCase; + +public class ClassResultTest extends TestCase { + + public void testFindCorrespondingResult() { + ClassResult classResult = new ClassResult(null, "com.example.ExampleTest"); + + CaseResult caseResult = new CaseResult(null, "testCase", null); + + classResult.add(caseResult); + + TestResult result = classResult.findCorrespondingResult("extraprefix.com.example.ExampleTest.testCase"); + assertEquals(caseResult, result); + } + + public void testFindCorrespondingResultWhereClassResultNameIsNotSubstring() { + ClassResult classResult = new ClassResult(null, "aaaa"); + + CaseResult caseResult = new CaseResult(null, "tc_bbbb", null); + + classResult.add(caseResult); + + TestResult result = classResult.findCorrespondingResult("tc_bbbb"); + assertEquals(caseResult, result); + } + + public void testFindCorrespondingResultWhereClassResultNameIsLastInCaseResultName() { + ClassResult classResult = new ClassResult(null, "aaaa"); + + CaseResult caseResult = new CaseResult(null, "tc_aaaa", null); + + classResult.add(caseResult); + + TestResult result = classResult.findCorrespondingResult("tc_aaaa"); + assertEquals(caseResult, result); + } + +} From 65c98e0afc121b23a5a6dde606e3a522f760ef5e Mon Sep 17 00:00:00 2001 From: Samuel Moritz Date: Mon, 7 Jan 2013 20:23:20 +0100 Subject: [PATCH 003/702] Compare string length directly in if to get a shorter method. --- core/src/main/java/hudson/tasks/junit/ClassResult.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/core/src/main/java/hudson/tasks/junit/ClassResult.java b/core/src/main/java/hudson/tasks/junit/ClassResult.java index bb2d8b0ef8..3301cd794a 100644 --- a/core/src/main/java/hudson/tasks/junit/ClassResult.java +++ b/core/src/main/java/hudson/tasks/junit/ClassResult.java @@ -84,17 +84,14 @@ public final class ClassResult extends TabulatedResult implements Comparable 0) { int caseNameStart = base + myID.length() + 1; - int caseNameLength = id.length() - caseNameStart; - if (caseNameLength > 0) { + if (id.length() > caseNameStart) { caseName = id.substring(caseNameStart); } } - CaseResult child = getCaseResult(caseName); if (child != null) { return child; } - return null; } From a13864be74b0bc8ce722f96c60a696342d72c5a5 Mon Sep 17 00:00:00 2001 From: Harald Albers Date: Thu, 14 Mar 2013 18:30:44 +0100 Subject: [PATCH 004/702] German translation for permission descriptions --- .../main/resources/hudson/Messages.properties | 2 +- .../resources/hudson/Messages_de.properties | 5 ++++ .../hudson/model/Messages.properties | 1 + .../hudson/model/Messages_de.properties | 23 +++++++++++++++++++ 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/core/src/main/resources/hudson/Messages.properties b/core/src/main/resources/hudson/Messages.properties index a90a3255d9..ccca534e2b 100644 --- a/core/src/main/resources/hudson/Messages.properties +++ b/core/src/main/resources/hudson/Messages.properties @@ -59,7 +59,7 @@ PluginManager.UploadPluginsPermission.Description=\ The "upload plugin" permission allows a user to upload arbitrary plugins. PluginManager.ConfigureUpdateCenterPermission.Description=\ The "configure update center" permission allows a user to \ -configure update sites and proxy settings. + configure update sites and proxy settings. AboutJenkins.DisplayName=About Jenkins AboutJenkins.Description=See the version and license information. diff --git a/core/src/main/resources/hudson/Messages_de.properties b/core/src/main/resources/hudson/Messages_de.properties index 42cf768def..ec3cd004be 100644 --- a/core/src/main/resources/hudson/Messages_de.properties +++ b/core/src/main/resources/hudson/Messages_de.properties @@ -49,5 +49,10 @@ Util.year ={0} {0,choice,0#Jahre|1#Jahr|1 Date: Tue, 19 Mar 2013 19:23:47 +0100 Subject: [PATCH 005/702] updated comment --- core/src/main/resources/hudson/model/Messages.properties | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/src/main/resources/hudson/model/Messages.properties b/core/src/main/resources/hudson/model/Messages.properties index 68538f6b0a..76df28d6cb 100644 --- a/core/src/main/resources/hudson/model/Messages.properties +++ b/core/src/main/resources/hudson/model/Messages.properties @@ -61,7 +61,8 @@ AbstractProject.DiscoverPermission.Description=\ This permission grants discover access to jobs. Lower than read permissions, it allows you to \ redirect anonymous users to the login page when they try to access a job url. \ Without it they would get a 404 error and wouldn't be able to discover project names. -# WipeOutPermission is only visible in security configuration if hudson.security.WipeOutPermission=true +# WipeOutPermission is only visible in the security configuration if the system property +# hudson.security.WipeOutPermission is set to true AbstractProject.WipeOutPermission.Description=\ This permission grants the ability to wipe out the contents of a workspace. AbstractProject.CancelPermission.Description=\ From 095ef2d7eec206c630aeb1354227298501fe11a2 Mon Sep 17 00:00:00 2001 From: lvotypko Date: Fri, 12 Apr 2013 07:53:53 +0200 Subject: [PATCH 006/702] Keep consistence in pendings when exception is thrown during method pop() --- core/src/main/java/hudson/model/Queue.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/core/src/main/java/hudson/model/Queue.java b/core/src/main/java/hudson/model/Queue.java index 4706bbd333..a00c160986 100644 --- a/core/src/main/java/hudson/model/Queue.java +++ b/core/src/main/java/hudson/model/Queue.java @@ -828,6 +828,13 @@ public class Queue extends ResourceController implements Saveable { if (offer != null && offer.workUnit != null) { // we are already assigned a project, but now we can't handle it. offer.workUnit.context.abort(new AbortException()); + if(offer.workUnit.context.item!=null && pendings.contains(offer.workUnit.context.item)){ + //we are already assigned a project and moved it into pendings, but something wrong had happened before an executor could take it. + pendings.remove(offer.workUnit.context.item); + //return it into queue, it does not have to cause this problem, it can be caused by another item. + buildables.add(offer.workUnit.context.item); + } + } // since this executor might have been chosen for From d4459d9d0f99b951974f6ab1bedf6a580aad9248 Mon Sep 17 00:00:00 2001 From: redlab Date: Mon, 15 Apr 2013 20:59:06 +0200 Subject: [PATCH 007/702] As this is my first look inside Jenkins codebase I not sure it's correct but perhaps artifacts for modulebuilds should be deleted just as logs are deleted. see https://issues.jenkins-ci.org/browse/JENKINS-17508 I did not fully test it yet, all unit tests ran fine, but didn't succeed to run jobs inside Jenkins, due to classloader issues while running Jenkins in Jetty, to verify deletion --- .../src/main/java/hudson/maven/MavenModuleSetBuild.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/maven-plugin/src/main/java/hudson/maven/MavenModuleSetBuild.java b/maven-plugin/src/main/java/hudson/maven/MavenModuleSetBuild.java index c5874d3d61..6d34187435 100644 --- a/maven-plugin/src/main/java/hudson/maven/MavenModuleSetBuild.java +++ b/maven-plugin/src/main/java/hudson/maven/MavenModuleSetBuild.java @@ -397,6 +397,14 @@ public class MavenModuleSetBuild extends AbstractMavenBuild list : getModuleBuilds().values()) + for (MavenBuild build : list) + build.deleteArtifacts(); + } + @Override public Object getDynamic(String token, StaplerRequest req, StaplerResponse rsp) { // map corresponding module build under this object From c8f73d0015365ab13a17c18ef8cd750cdcda2506 Mon Sep 17 00:00:00 2001 From: redlab Date: Wed, 17 Apr 2013 12:21:09 +0200 Subject: [PATCH 008/702] adds test that looks in jobs archive with 2 builds when LogRotator set as build discarder with settings to keep only 1 build with artifacts, test searches for jars in archive for build one and build two expecting no jars in build 1 and expecting jars in build 2 --- ...enMultiModuleLogRotatorCleanArtifacts.java | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 test/src/test/java/hudson/maven/MavenMultiModuleLogRotatorCleanArtifacts.java diff --git a/test/src/test/java/hudson/maven/MavenMultiModuleLogRotatorCleanArtifacts.java b/test/src/test/java/hudson/maven/MavenMultiModuleLogRotatorCleanArtifacts.java new file mode 100644 index 0000000000..952efc8894 --- /dev/null +++ b/test/src/test/java/hudson/maven/MavenMultiModuleLogRotatorCleanArtifacts.java @@ -0,0 +1,78 @@ +/** + * + */ +package hudson.maven; + +import hudson.FilePath; +import hudson.Launcher; +import hudson.maven.reporters.MavenFingerprinter; +import hudson.model.BuildListener; +import hudson.tasks.LogRotator; +import hudson.tasks.Maven.MavenInstallation; + +import java.io.File; +import java.io.IOException; +import java.net.URI; +import java.util.Collection; + +import org.apache.commons.io.FileUtils; +import org.apache.commons.io.filefilter.IOFileFilter; +import org.apache.commons.io.filefilter.PrefixFileFilter; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.jvnet.hudson.test.ExtractResourceWithChangesSCM; +import org.jvnet.hudson.test.HudsonTestCase; + +/** + * @author redlab + * + */ +public class MavenMultiModuleLogRotatorCleanArtifacts extends HudsonTestCase { + + private MavenModuleSet m; + private FilePath jobs; + + private static class TestReporter extends MavenReporter { + @Override + public boolean end(MavenBuild build, Launcher launcher, + BuildListener listener) throws InterruptedException, + IOException { + assertNotNull(build.getProject().getWorkspace()); + assertNotNull(build.getWorkspace()); + return true; + } + } + @Override + protected void setUp() throws Exception { + super.setUp(); + configureDefaultMaven("apache-maven-2.2.1", MavenInstallation.MAVEN_21); + m = createMavenProject(); + m.setBuildDiscarder(new LogRotator("-1", "-1", "-1", "1")); + m.getReporters().add(new TestReporter()); + m.getReporters().add(new MavenFingerprinter()); + m.setScm(new ExtractResourceWithChangesSCM(getClass().getResource( + "maven-multimod.zip"), getClass().getResource( + "maven-multimod-changes.zip"))); + buildAndAssertSuccess(m); + // Now run a second build with the changes. + m.setIncrementalBuild(false); + buildAndAssertSuccess(m); + FilePath workspace = m.getWorkspace(); + URI uri = workspace.toURI(); + FilePath parent = workspace.getParent().getParent(); + jobs = new FilePath(parent, "jobs"); + } + + public void testArtifactsAreDeletedInBuildOneWhenBuildDiscarderRun() throws Exception { + File directory = new File(new FilePath(jobs, "test0/builds/1").toURI()); + System.out.println(directory); + Collection files = FileUtils.listFiles(directory, new String [] {"jar"}, true); + Assert.assertTrue("Found jars in previous build, that should not happen", files.isEmpty()); + Collection files2= FileUtils.listFiles(new File(new FilePath(jobs, "test0/builds/2").toURI()), new String [] {"jar"}, true); + Assert.assertFalse("No jars in last build ALERT!", files2.isEmpty()); + } + + + + +} From 2a0bd7eebd1ee70aa6099197f48810235ddc9ab0 Mon Sep 17 00:00:00 2001 From: redlab Date: Wed, 17 Apr 2013 14:02:46 +0200 Subject: [PATCH 009/702] add documentation to testcase. --- ...enMultiModuleLogRotatorCleanArtifacts.java | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/test/src/test/java/hudson/maven/MavenMultiModuleLogRotatorCleanArtifacts.java b/test/src/test/java/hudson/maven/MavenMultiModuleLogRotatorCleanArtifacts.java index 952efc8894..dbc7b8f5a2 100644 --- a/test/src/test/java/hudson/maven/MavenMultiModuleLogRotatorCleanArtifacts.java +++ b/test/src/test/java/hudson/maven/MavenMultiModuleLogRotatorCleanArtifacts.java @@ -20,10 +20,17 @@ import org.apache.commons.io.filefilter.IOFileFilter; import org.apache.commons.io.filefilter.PrefixFileFilter; import org.junit.Assert; import org.junit.BeforeClass; +import org.jvnet.hudson.test.Bug; import org.jvnet.hudson.test.ExtractResourceWithChangesSCM; import org.jvnet.hudson.test.HudsonTestCase; /** + * Testing https://issues.jenkins-ci.org/browse/JENKINS-17508
+ * test that looks in jobs archive with 2 builds when LogRotator set as build + * discarder with settings to keep only 1 build with artifacts, test searches + * for jars in archive for build one and build two, expecting no jars in build 1 + * and expecting jars in build 2 + * * @author redlab * */ @@ -42,6 +49,7 @@ public class MavenMultiModuleLogRotatorCleanArtifacts extends HudsonTestCase { return true; } } + @Override protected void setUp() throws Exception { super.setUp(); @@ -63,16 +71,18 @@ public class MavenMultiModuleLogRotatorCleanArtifacts extends HudsonTestCase { jobs = new FilePath(parent, "jobs"); } - public void testArtifactsAreDeletedInBuildOneWhenBuildDiscarderRun() throws Exception { + public void testArtifactsAreDeletedInBuildOneWhenBuildDiscarderRun() + throws Exception { File directory = new File(new FilePath(jobs, "test0/builds/1").toURI()); System.out.println(directory); - Collection files = FileUtils.listFiles(directory, new String [] {"jar"}, true); - Assert.assertTrue("Found jars in previous build, that should not happen", files.isEmpty()); - Collection files2= FileUtils.listFiles(new File(new FilePath(jobs, "test0/builds/2").toURI()), new String [] {"jar"}, true); + Collection files = FileUtils.listFiles(directory, + new String[] { "jar" }, true); + Assert.assertTrue( + "Found jars in previous build, that should not happen", + files.isEmpty()); + Collection files2 = FileUtils.listFiles(new File(new FilePath( + jobs, "test0/builds/2").toURI()), new String[] { "jar" }, true); Assert.assertFalse("No jars in last build ALERT!", files2.isEmpty()); } - - - } From ca7f4e682c8faa024053130d672d28684c010067 Mon Sep 17 00:00:00 2001 From: redlab Date: Thu, 18 Apr 2013 08:58:30 +0200 Subject: [PATCH 010/702] also testing the removal of build if LogRotator is configured to discard old builds and not only artifacts (Not needed for the issue, but an extra test is not a luxury ) --- ...enMultiModuleLogRotatorCleanArtifacts.java | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/test/src/test/java/hudson/maven/MavenMultiModuleLogRotatorCleanArtifacts.java b/test/src/test/java/hudson/maven/MavenMultiModuleLogRotatorCleanArtifacts.java index dbc7b8f5a2..6c8e877a1a 100644 --- a/test/src/test/java/hudson/maven/MavenMultiModuleLogRotatorCleanArtifacts.java +++ b/test/src/test/java/hudson/maven/MavenMultiModuleLogRotatorCleanArtifacts.java @@ -12,15 +12,10 @@ import hudson.tasks.Maven.MavenInstallation; import java.io.File; import java.io.IOException; -import java.net.URI; import java.util.Collection; import org.apache.commons.io.FileUtils; -import org.apache.commons.io.filefilter.IOFileFilter; -import org.apache.commons.io.filefilter.PrefixFileFilter; import org.junit.Assert; -import org.junit.BeforeClass; -import org.jvnet.hudson.test.Bug; import org.jvnet.hudson.test.ExtractResourceWithChangesSCM; import org.jvnet.hudson.test.HudsonTestCase; @@ -31,7 +26,6 @@ import org.jvnet.hudson.test.HudsonTestCase; * for jars in archive for build one and build two, expecting no jars in build 1 * and expecting jars in build 2 * - * @author redlab * */ public class MavenMultiModuleLogRotatorCleanArtifacts extends HudsonTestCase { @@ -55,7 +49,7 @@ public class MavenMultiModuleLogRotatorCleanArtifacts extends HudsonTestCase { super.setUp(); configureDefaultMaven("apache-maven-2.2.1", MavenInstallation.MAVEN_21); m = createMavenProject(); - m.setBuildDiscarder(new LogRotator("-1", "-1", "-1", "1")); + m.setBuildDiscarder(new LogRotator("-1", "2", "-1", "1")); m.getReporters().add(new TestReporter()); m.getReporters().add(new MavenFingerprinter()); m.setScm(new ExtractResourceWithChangesSCM(getClass().getResource( @@ -66,15 +60,14 @@ public class MavenMultiModuleLogRotatorCleanArtifacts extends HudsonTestCase { m.setIncrementalBuild(false); buildAndAssertSuccess(m); FilePath workspace = m.getWorkspace(); - URI uri = workspace.toURI(); FilePath parent = workspace.getParent().getParent(); jobs = new FilePath(parent, "jobs"); } + @SuppressWarnings("unchecked") public void testArtifactsAreDeletedInBuildOneWhenBuildDiscarderRun() throws Exception { File directory = new File(new FilePath(jobs, "test0/builds/1").toURI()); - System.out.println(directory); Collection files = FileUtils.listFiles(directory, new String[] { "jar" }, true); Assert.assertTrue( @@ -85,4 +78,16 @@ public class MavenMultiModuleLogRotatorCleanArtifacts extends HudsonTestCase { Assert.assertFalse("No jars in last build ALERT!", files2.isEmpty()); } + /** + * Performs a third build and expecting build one to be deleted + * @throws Exception + */ + @SuppressWarnings("unchecked") + public void testArtifactsOldBuildsDeletedWhenBuildDiscarderRun() + throws Exception { + buildAndAssertSuccess(m); + File directory = new File(new FilePath(jobs, "test0/builds/1").toURI()); + Assert.assertFalse("oops the build should have been deleted", directory.exists()); + } + } From aa1d28b04014c18838e87b3a8b1707cc5eb28b14 Mon Sep 17 00:00:00 2001 From: redlab Date: Tue, 23 Apr 2013 21:09:24 +0200 Subject: [PATCH 011/702] JENKINS-17508 updated the test to use @Rule and no longer extend from the old HudsonTestCase (shouldn't that one be marked deprecated?), add @ Bug and @ For as jesse suggested --- ...tiModuleLogRotatorCleanArtifactsTest.java} | 43 +++++++++++++------ 1 file changed, 29 insertions(+), 14 deletions(-) rename test/src/test/java/hudson/maven/{MavenMultiModuleLogRotatorCleanArtifacts.java => MavenMultiModuleLogRotatorCleanArtifactsTest.java} (76%) diff --git a/test/src/test/java/hudson/maven/MavenMultiModuleLogRotatorCleanArtifacts.java b/test/src/test/java/hudson/maven/MavenMultiModuleLogRotatorCleanArtifactsTest.java similarity index 76% rename from test/src/test/java/hudson/maven/MavenMultiModuleLogRotatorCleanArtifacts.java rename to test/src/test/java/hudson/maven/MavenMultiModuleLogRotatorCleanArtifactsTest.java index 6c8e877a1a..4842ee3f63 100644 --- a/test/src/test/java/hudson/maven/MavenMultiModuleLogRotatorCleanArtifacts.java +++ b/test/src/test/java/hudson/maven/MavenMultiModuleLogRotatorCleanArtifactsTest.java @@ -16,8 +16,13 @@ import java.util.Collection; import org.apache.commons.io.FileUtils; import org.junit.Assert; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.jvnet.hudson.test.Bug; import org.jvnet.hudson.test.ExtractResourceWithChangesSCM; -import org.jvnet.hudson.test.HudsonTestCase; +import org.jvnet.hudson.test.For; +import org.jvnet.hudson.test.JenkinsRule; /** * Testing https://issues.jenkins-ci.org/browse/JENKINS-17508
@@ -28,42 +33,52 @@ import org.jvnet.hudson.test.HudsonTestCase; * * */ -public class MavenMultiModuleLogRotatorCleanArtifacts extends HudsonTestCase { +public class MavenMultiModuleLogRotatorCleanArtifactsTest { + + @Rule + public JenkinsRule j = new JenkinsRule(); private MavenModuleSet m; private FilePath jobs; private static class TestReporter extends MavenReporter { + /** + * + */ + private static final long serialVersionUID = 1L; + @Override public boolean end(MavenBuild build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException { - assertNotNull(build.getProject().getWorkspace()); - assertNotNull(build.getWorkspace()); + Assert.assertNotNull(build.getProject().getWorkspace()); + Assert.assertNotNull(build.getWorkspace()); return true; } } - @Override - protected void setUp() throws Exception { - super.setUp(); - configureDefaultMaven("apache-maven-2.2.1", MavenInstallation.MAVEN_21); - m = createMavenProject(); + @Before + public void setUp() throws Exception { + j.configureDefaultMaven("apache-maven-2.2.1", MavenInstallation.MAVEN_21); + m = j.createMavenProject(); m.setBuildDiscarder(new LogRotator("-1", "2", "-1", "1")); m.getReporters().add(new TestReporter()); m.getReporters().add(new MavenFingerprinter()); m.setScm(new ExtractResourceWithChangesSCM(getClass().getResource( "maven-multimod.zip"), getClass().getResource( "maven-multimod-changes.zip"))); - buildAndAssertSuccess(m); + j.buildAndAssertSuccess(m); // Now run a second build with the changes. m.setIncrementalBuild(false); - buildAndAssertSuccess(m); + j.buildAndAssertSuccess(m); FilePath workspace = m.getWorkspace(); FilePath parent = workspace.getParent().getParent(); jobs = new FilePath(parent, "jobs"); } - + + @Test + @Bug(17508) + @For(MavenModuleSetBuild.class) @SuppressWarnings("unchecked") public void testArtifactsAreDeletedInBuildOneWhenBuildDiscarderRun() throws Exception { @@ -82,10 +97,10 @@ public class MavenMultiModuleLogRotatorCleanArtifacts extends HudsonTestCase { * Performs a third build and expecting build one to be deleted * @throws Exception */ - @SuppressWarnings("unchecked") + @Test public void testArtifactsOldBuildsDeletedWhenBuildDiscarderRun() throws Exception { - buildAndAssertSuccess(m); + j.buildAndAssertSuccess(m); File directory = new File(new FilePath(jobs, "test0/builds/1").toURI()); Assert.assertFalse("oops the build should have been deleted", directory.exists()); } From f9ce6558c93d7f7ff0f8df12fb80f9ecc868ff99 Mon Sep 17 00:00:00 2001 From: redlab Date: Wed, 24 Apr 2013 10:54:42 +0200 Subject: [PATCH 012/702] JENKINS-17508 removed usage of deprecated elements in test --- ...avenMultiModuleLogRotatorCleanArtifactsTest.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/test/src/test/java/hudson/maven/MavenMultiModuleLogRotatorCleanArtifactsTest.java b/test/src/test/java/hudson/maven/MavenMultiModuleLogRotatorCleanArtifactsTest.java index 4842ee3f63..8b4b943935 100644 --- a/test/src/test/java/hudson/maven/MavenMultiModuleLogRotatorCleanArtifactsTest.java +++ b/test/src/test/java/hudson/maven/MavenMultiModuleLogRotatorCleanArtifactsTest.java @@ -25,11 +25,11 @@ import org.jvnet.hudson.test.For; import org.jvnet.hudson.test.JenkinsRule; /** - * Testing https://issues.jenkins-ci.org/browse/JENKINS-17508
- * test that looks in jobs archive with 2 builds when LogRotator set as build + * + * Test that looks in jobs archive with 2 builds. When LogRotator set as build * discarder with settings to keep only 1 build with artifacts, test searches * for jars in archive for build one and build two, expecting no jars in build 1 - * and expecting jars in build 2 + * and expecting jars in build 2. * * */ @@ -51,7 +51,7 @@ public class MavenMultiModuleLogRotatorCleanArtifactsTest { public boolean end(MavenBuild build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException { - Assert.assertNotNull(build.getProject().getWorkspace()); + Assert.assertNotNull(build.getProject().getSomeWorkspace()); Assert.assertNotNull(build.getWorkspace()); return true; } @@ -71,14 +71,14 @@ public class MavenMultiModuleLogRotatorCleanArtifactsTest { // Now run a second build with the changes. m.setIncrementalBuild(false); j.buildAndAssertSuccess(m); - FilePath workspace = m.getWorkspace(); + FilePath workspace = m.getSomeWorkspace(); FilePath parent = workspace.getParent().getParent(); jobs = new FilePath(parent, "jobs"); } @Test @Bug(17508) - @For(MavenModuleSetBuild.class) + @For({MavenModuleSetBuild.class, LogRotator.class}) @SuppressWarnings("unchecked") public void testArtifactsAreDeletedInBuildOneWhenBuildDiscarderRun() throws Exception { @@ -97,6 +97,7 @@ public class MavenMultiModuleLogRotatorCleanArtifactsTest { * Performs a third build and expecting build one to be deleted * @throws Exception */ + @For({MavenModuleSetBuild.class, LogRotator.class}) @Test public void testArtifactsOldBuildsDeletedWhenBuildDiscarderRun() throws Exception { From 1dc289e2eee34a291284779f82127a14b9bf52c8 Mon Sep 17 00:00:00 2001 From: Vincent Latombe Date: Thu, 25 Apr 2013 11:15:18 +0530 Subject: [PATCH 013/702] Prevent ClassCastException when encountering ItemGroup of non-TopLevelItem. This is the case for instance when encountering a MavenModuleSet which is ItemGroup --- core/src/main/java/hudson/model/ListView.java | 20 ++++++--- .../test/java/hudson/model/ListViewTest.java | 45 +++++++++++++++++++ 2 files changed, 60 insertions(+), 5 deletions(-) create mode 100644 core/src/test/java/hudson/model/ListViewTest.java diff --git a/core/src/main/java/hudson/model/ListView.java b/core/src/main/java/hudson/model/ListView.java index 0fd9978c9b..e4df9ffc3a 100644 --- a/core/src/main/java/hudson/model/ListView.java +++ b/core/src/main/java/hudson/model/ListView.java @@ -186,15 +186,18 @@ public class ListView extends View implements Saveable { includeItems(parent, parent, names); } - private void includeItems(ItemGroup root, ItemGroup parent, SortedSet names) { + private void includeItems(ItemGroup root, ItemGroup parent, SortedSet names) { if (includePattern != null) { for (Item item : parent.getItems()) { if (recurse && item instanceof ItemGroup) { - includeItems(root, (ItemGroup)item, names); + ItemGroup ig = (ItemGroup) item; + includeItems(root, ig, names); } - String itemName = item.getRelativeNameFrom(root); - if (includePattern.matcher(itemName).matches()) { - names.add(itemName); + if (item instanceof TopLevelItem) { + String itemName = item.getRelativeNameFrom(root); + if (includePattern.matcher(itemName).matches()) { + names.add(itemName); + } } } } @@ -226,6 +229,13 @@ public class ListView extends View implements Saveable { public boolean isRecurse() { return recurse; } + + /* + * For testing purposes + */ + void setRecurse(boolean recurse) { + this.recurse = recurse; + } /** * Filter by enabled/disabled status of jobs. diff --git a/core/src/test/java/hudson/model/ListViewTest.java b/core/src/test/java/hudson/model/ListViewTest.java new file mode 100644 index 0000000000..3a6f731671 --- /dev/null +++ b/core/src/test/java/hudson/model/ListViewTest.java @@ -0,0 +1,45 @@ +package hudson.model; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; +import static org.powermock.api.mockito.PowerMockito.mockStatic; +import hudson.views.ListViewColumn; + +import java.io.IOException; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +public class ListViewTest { + + private interface ItemGroupOfNonTopLevelItem extends TopLevelItem, ItemGroup {} + + @Test + @PrepareForTest({ListViewColumn.class,Items.class}) + public void listItemRecurseWorksWithNonTopLevelItems() throws IOException{ + mockStatic(Items.class); + mockStatic(ListViewColumn.class); + List columns = Collections.emptyList(); + when(ListViewColumn.createDefaultInitialColumnList()).thenReturn(columns); + ViewGroup owner = mock(ViewGroup.class); + ItemGroup itemGroupOwner = mock(ItemGroup.class); + when(owner.getItemGroup()).thenReturn(itemGroupOwner); + ListView lv = new ListView("test", owner); + ItemGroupOfNonTopLevelItem ig = Mockito.mock(ItemGroupOfNonTopLevelItem.class); + when(Items.getAllItems(eq(itemGroupOwner), eq(TopLevelItem.class))).thenReturn(Arrays.asList((TopLevelItem) ig)); + when(ig.getRelativeNameFrom(any(ItemGroup.class))).thenReturn("test-item"); + lv.setRecurse(true); + lv.add(ig); + assertEquals(1, lv.getItems().size()); + } +} From b8adcb43dd73f8bcc3ff00558e0f7e587929cec6 Mon Sep 17 00:00:00 2001 From: imod Date: Tue, 30 Apr 2013 20:38:35 +0200 Subject: [PATCH 014/702] add global maven config to define default settings providers --- core/src/main/java/hudson/tasks/Maven.java | 22 +++++++-- .../java/jenkins/mvn/GlobalMavenConfig.java | 47 +++++++++++++++++++ .../mvn/GlobalMavenConfig/config.groovy | 8 ++++ .../java/hudson/maven/MavenModuleSet.java | 14 ++++-- 4 files changed, 81 insertions(+), 10 deletions(-) create mode 100644 core/src/main/java/jenkins/mvn/GlobalMavenConfig.java create mode 100644 core/src/main/resources/jenkins/mvn/GlobalMavenConfig/config.groovy diff --git a/core/src/main/java/hudson/tasks/Maven.java b/core/src/main/java/hudson/tasks/Maven.java index b7c3a2119b..cf77905fa3 100644 --- a/core/src/main/java/hudson/tasks/Maven.java +++ b/core/src/main/java/hudson/tasks/Maven.java @@ -40,6 +40,7 @@ import hudson.model.Node; import jenkins.model.Jenkins; import jenkins.mvn.DefaultGlobalSettingsProvider; import jenkins.mvn.DefaultSettingsProvider; +import jenkins.mvn.GlobalMavenConfig; import jenkins.mvn.GlobalSettingsProvider; import jenkins.mvn.SettingsProvider; import hudson.model.TaskListener; @@ -163,8 +164,8 @@ public class Maven extends Builder { this.properties = Util.fixEmptyAndTrim(properties); this.jvmOptions = Util.fixEmptyAndTrim(jvmOptions); this.usePrivateRepository = usePrivateRepository; - this.settings = settings != null ? settings : new DefaultSettingsProvider(); - this.globalSettings = globalSettings != null ? globalSettings : new DefaultGlobalSettingsProvider(); + this.settings = settings; + this.globalSettings = globalSettings; } public String getTargets() { @@ -175,14 +176,22 @@ public class Maven extends Builder { * @since 1.491 */ public SettingsProvider getSettings() { - return settings != null ? settings : new DefaultSettingsProvider(); + return settings != null ? settings : GlobalMavenConfig.get().getSettingsProvider(); + } + + protected void setSettings(SettingsProvider settings) { + this.settings = settings; } /** * @since 1.491 */ public GlobalSettingsProvider getGlobalSettings() { - return globalSettings != null ? globalSettings : new DefaultGlobalSettingsProvider(); + return globalSettings != null ? globalSettings : GlobalMavenConfig.get().getGlobalSettingsProvider(); + } + + protected void setGlobalSettings(GlobalSettingsProvider globalSettings) { + this.globalSettings = globalSettings; } public void setUsePrivateRepository(boolean usePrivateRepository) { @@ -420,7 +429,10 @@ public class Maven extends Builder { @Override public Builder newInstance(StaplerRequest req, JSONObject formData) throws FormException { - return req.bindJSON(Maven.class,formData); + Maven m = req.bindJSON(Maven.class,formData); + m.setSettings(GlobalMavenConfig.get().getSettingsProvider()); + m.setGlobalSettings(GlobalMavenConfig.get().getGlobalSettingsProvider()); + return m; } } diff --git a/core/src/main/java/jenkins/mvn/GlobalMavenConfig.java b/core/src/main/java/jenkins/mvn/GlobalMavenConfig.java new file mode 100644 index 0000000000..67ace424e8 --- /dev/null +++ b/core/src/main/java/jenkins/mvn/GlobalMavenConfig.java @@ -0,0 +1,47 @@ +package jenkins.mvn; + +import hudson.Extension; +import jenkins.model.GlobalConfiguration; +import net.sf.json.JSONObject; + +import org.kohsuke.stapler.StaplerRequest; + +//as close as it gets to the global Maven Project configuration +@Extension(ordinal = 50) +public class GlobalMavenConfig extends GlobalConfiguration { + private SettingsProvider settingsProvider; + private GlobalSettingsProvider globalSettingsProvider; + + public GlobalMavenConfig() { + load(); + } + + @Override + public boolean configure(StaplerRequest req, JSONObject json) throws FormException { + req.bindJSON(this, json); + return true; + } + + public void setGlobalSettingsProvider(GlobalSettingsProvider globalSettingsProvider) { + this.globalSettingsProvider = globalSettingsProvider; + save(); + } + + public void setSettingsProvider(SettingsProvider settingsProvider) { + this.settingsProvider = settingsProvider; + save(); + } + + public GlobalSettingsProvider getGlobalSettingsProvider() { + return globalSettingsProvider != null ? globalSettingsProvider : new DefaultGlobalSettingsProvider(); + } + + public SettingsProvider getSettingsProvider() { + return settingsProvider != null ? settingsProvider : new DefaultSettingsProvider(); + } + + public static GlobalMavenConfig get() { + return GlobalConfiguration.all().get(GlobalMavenConfig.class); + } + +} diff --git a/core/src/main/resources/jenkins/mvn/GlobalMavenConfig/config.groovy b/core/src/main/resources/jenkins/mvn/GlobalMavenConfig/config.groovy new file mode 100644 index 0000000000..79e427df0f --- /dev/null +++ b/core/src/main/resources/jenkins/mvn/GlobalMavenConfig/config.groovy @@ -0,0 +1,8 @@ +package jenkins.mvn.GlobalMavenConfig; + +def f = namespace(lib.FormTagLib) + +f.section(title:_("Maven Configuration")) { + f.dropdownDescriptorSelector(title:_("Default settings provider"), field:"settingsProvider") + f.dropdownDescriptorSelector(title:_("Default global settings provider"), field:"globalSettingsProvider") +} diff --git a/maven-plugin/src/main/java/hudson/maven/MavenModuleSet.java b/maven-plugin/src/main/java/hudson/maven/MavenModuleSet.java index d17b8be66a..90b0097265 100644 --- a/maven-plugin/src/main/java/hudson/maven/MavenModuleSet.java +++ b/maven-plugin/src/main/java/hudson/maven/MavenModuleSet.java @@ -94,6 +94,7 @@ import jenkins.model.ModelObjectWithChildren; import jenkins.mvn.DefaultGlobalSettingsProvider; import jenkins.mvn.DefaultSettingsProvider; import jenkins.mvn.FilePathSettingsProvider; +import jenkins.mvn.GlobalMavenConfig; import jenkins.mvn.GlobalSettingsProvider; import jenkins.mvn.GlobalSettingsProviderDescriptor; import jenkins.mvn.SettingsProvider; @@ -284,12 +285,12 @@ public class MavenModuleSet extends AbstractMavenProject Date: Wed, 1 May 2013 11:06:19 +0200 Subject: [PATCH 015/702] changed the filepath#toUri call to #getRemote as per comment of @jglick --- .../maven/MavenMultiModuleLogRotatorCleanArtifactsTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/src/test/java/hudson/maven/MavenMultiModuleLogRotatorCleanArtifactsTest.java b/test/src/test/java/hudson/maven/MavenMultiModuleLogRotatorCleanArtifactsTest.java index 8b4b943935..114c783552 100644 --- a/test/src/test/java/hudson/maven/MavenMultiModuleLogRotatorCleanArtifactsTest.java +++ b/test/src/test/java/hudson/maven/MavenMultiModuleLogRotatorCleanArtifactsTest.java @@ -82,14 +82,14 @@ public class MavenMultiModuleLogRotatorCleanArtifactsTest { @SuppressWarnings("unchecked") public void testArtifactsAreDeletedInBuildOneWhenBuildDiscarderRun() throws Exception { - File directory = new File(new FilePath(jobs, "test0/builds/1").toURI()); + File directory = new File(new FilePath(jobs, "test0/builds/1").getRemote()); Collection files = FileUtils.listFiles(directory, new String[] { "jar" }, true); Assert.assertTrue( "Found jars in previous build, that should not happen", files.isEmpty()); Collection files2 = FileUtils.listFiles(new File(new FilePath( - jobs, "test0/builds/2").toURI()), new String[] { "jar" }, true); + jobs, "test0/builds/2").getRemote()), new String[] { "jar" }, true); Assert.assertFalse("No jars in last build ALERT!", files2.isEmpty()); } @@ -102,7 +102,7 @@ public class MavenMultiModuleLogRotatorCleanArtifactsTest { public void testArtifactsOldBuildsDeletedWhenBuildDiscarderRun() throws Exception { j.buildAndAssertSuccess(m); - File directory = new File(new FilePath(jobs, "test0/builds/1").toURI()); + File directory = new File(new FilePath(jobs, "test0/builds/1").getRemote()); Assert.assertFalse("oops the build should have been deleted", directory.exists()); } From 2c240bdc876e74fe7a4a1ebeb5e3707e2d8f7bf3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20Gond=C5=BEa?= Date: Fri, 1 Mar 2013 08:00:52 +0100 Subject: [PATCH 016/702] [FIXED JENKINS-17030] Enable word breaking for job names --- core/src/main/java/hudson/Functions.java | 16 +++++++++ .../hudson/matrix/MatrixProject/index.jelly | 2 +- .../resources/hudson/model/Job/index.jelly | 2 +- .../hudson/views/JobColumn/column.jelly | 4 +-- .../resources/lib/hudson/buildListTable.jelly | 2 +- .../main/resources/lib/hudson/executors.jelly | 2 +- .../main/resources/lib/hudson/jobLink.jelly | 2 +- .../src/main/resources/lib/hudson/queue.jelly | 2 +- .../main/resources/lib/layout/breakable.jelly | 33 +++++++++++++++++++ core/src/test/java/hudson/FunctionsTest.java | 7 ++++ 10 files changed, 64 insertions(+), 8 deletions(-) create mode 100644 core/src/main/resources/lib/layout/breakable.jelly diff --git a/core/src/main/java/hudson/Functions.java b/core/src/main/java/hudson/Functions.java index cdb19d5bae..be9c3b526e 100644 --- a/core/src/main/java/hudson/Functions.java +++ b/core/src/main/java/hudson/Functions.java @@ -1716,4 +1716,20 @@ public class Functions { DecimalFormat format = new DecimalFormat("#0.00"); return format.format(number) + " " + measure; } + + /** + * Get a string that can be safely broken to several lines when necessary. + * + * This implementation inserts <wbr> tags into string. It allows browsers + * to wrap line before any sequence of punctuation characters or anywhere + * in the middle of prolonged sequences of word characters. + * + * @since 1.516 + */ + public static String breakableString(final String plain) { + + return plain.replaceAll("(\\p{Punct}+\\w)", "$1") + .replaceAll("(\\w{10})(?=\\w{3})", "$1") + ; + } } diff --git a/core/src/main/resources/hudson/matrix/MatrixProject/index.jelly b/core/src/main/resources/hudson/matrix/MatrixProject/index.jelly index 7dbf81516f..de39e50e3a 100644 --- a/core/src/main/resources/hudson/matrix/MatrixProject/index.jelly +++ b/core/src/main/resources/hudson/matrix/MatrixProject/index.jelly @@ -27,7 +27,7 @@ THE SOFTWARE. -

${%Project} ${it.displayName}

+

${%Project}

${%Project name}: ${it.fullName} diff --git a/core/src/main/resources/hudson/model/Job/index.jelly b/core/src/main/resources/hudson/model/Job/index.jelly index 651b2dd732..9e3c5becd4 100644 --- a/core/src/main/resources/hudson/model/Job/index.jelly +++ b/core/src/main/resources/hudson/model/Job/index.jelly @@ -27,7 +27,7 @@ THE SOFTWARE. -

${it.pronoun} ${it.displayName}

+

${it.pronoun}

${%Project name}: ${it.fullName} diff --git a/core/src/main/resources/hudson/views/JobColumn/column.jelly b/core/src/main/resources/hudson/views/JobColumn/column.jelly index 116ca8d108..347d4260d2 100644 --- a/core/src/main/resources/hudson/views/JobColumn/column.jelly +++ b/core/src/main/resources/hudson/views/JobColumn/column.jelly @@ -25,6 +25,6 @@ THE SOFTWARE. - ${h.getRelativeDisplayNameFrom(job,currentView.owner.itemGroup)} + - \ No newline at end of file + diff --git a/core/src/main/resources/lib/hudson/buildListTable.jelly b/core/src/main/resources/lib/hudson/buildListTable.jelly index 36d859fa6c..cf2b131db2 100644 --- a/core/src/main/resources/lib/hudson/buildListTable.jelly +++ b/core/src/main/resources/lib/hudson/buildListTable.jelly @@ -53,7 +53,7 @@ THE SOFTWARE. - ${b.parent.fullDisplayName} + ${b.displayName} diff --git a/core/src/main/resources/lib/hudson/executors.jelly b/core/src/main/resources/lib/hudson/executors.jelly index 9ad0e67fab..8bab2b1bd9 100644 --- a/core/src/main/resources/lib/hudson/executors.jelly +++ b/core/src/main/resources/lib/hudson/executors.jelly @@ -79,7 +79,7 @@ THE SOFTWARE. - ${exeparent.fullDisplayName} #${exe.number} +  #${exe.number} diff --git a/core/src/main/resources/lib/hudson/jobLink.jelly b/core/src/main/resources/lib/hudson/jobLink.jelly index dc5d6677dd..fcd234154a 100644 --- a/core/src/main/resources/lib/hudson/jobLink.jelly +++ b/core/src/main/resources/lib/hudson/jobLink.jelly @@ -32,5 +32,5 @@ THE SOFTWARE. ${job.iconColor.description} -${job.fullDisplayName} + diff --git a/core/src/main/resources/lib/hudson/queue.jelly b/core/src/main/resources/lib/hudson/queue.jelly index 7f5488444d..846fccb59a 100644 --- a/core/src/main/resources/lib/hudson/queue.jelly +++ b/core/src/main/resources/lib/hudson/queue.jelly @@ -63,7 +63,7 @@ THE SOFTWARE. - ${item.task.fullDisplayName} + diff --git a/core/src/main/resources/lib/layout/breakable.jelly b/core/src/main/resources/lib/layout/breakable.jelly new file mode 100644 index 0000000000..984b4485d6 --- /dev/null +++ b/core/src/main/resources/lib/layout/breakable.jelly @@ -0,0 +1,33 @@ + + + + + Send escaped value to output decorated to be safely broken into lines when necessary + + Unescaped value to output + + + ${h.breakableString(h.escape(value))} + diff --git a/core/src/test/java/hudson/FunctionsTest.java b/core/src/test/java/hudson/FunctionsTest.java index 8b703dce22..3ef3014d64 100644 --- a/core/src/test/java/hudson/FunctionsTest.java +++ b/core/src/test/java/hudson/FunctionsTest.java @@ -264,4 +264,11 @@ public class FunctionsTest { } } + @Test + public void testBreakableString() { + + assertEquals("Hello world!", Functions.breakableString("Hello world!")); + assertEquals("H,e.l/l:o-w_o=+|d", Functions.breakableString("H,e.l/l:o-w_o=+|d")); + assertEquals("ALongStringThatCanNotBeBrokenByDefault", Functions.breakableString("ALongStringThatCanNotBeBrokenByDefault")); + } } From 9b75fe5c9e9fcb6c1a5862f93be334eb8f5764e5 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Mon, 29 Apr 2013 10:17:04 -0700 Subject: [PATCH 017/702] Hopefully this helps us reduce the screen glitch --- war/src/main/webapp/scripts/hudson-behavior.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/war/src/main/webapp/scripts/hudson-behavior.js b/war/src/main/webapp/scripts/hudson-behavior.js index cba3b04d48..18309bdb9c 100644 --- a/war/src/main/webapp/scripts/hudson-behavior.js +++ b/war/src/main/webapp/scripts/hudson-behavior.js @@ -1430,14 +1430,12 @@ function refreshPart(id,url) { var hist = $(id); if (hist==null) console.log("There's no element that has ID of "+id) var p = hist.up(); - var next = hist.next(); - p.removeChild(hist); var div = document.createElement('div'); div.innerHTML = rsp.responseText; var node = $(div).firstDescendant(); - p.insertBefore(node, next); + p.replaceChild(node, hist); Behaviour.applySubtree(node); layoutUpdateCallback.call(); From d482fc50fb59e561b93a0e336680938ffac7fd22 Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Wed, 24 Apr 2013 16:33:29 -0400 Subject: [PATCH 018/702] [FIXED SECURITY-67] Forbid CSS links in markup to be on the safe side.(cherry picked from commit 1e19eb3ecece1931b5363a797fd2b30f8edc6180) --- core/src/main/java/hudson/markup/MyspacePolicy.java | 1 - core/src/test/java/hudson/markup/MyspacePolicyTest.java | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/core/src/main/java/hudson/markup/MyspacePolicy.java b/core/src/main/java/hudson/markup/MyspacePolicy.java index f0543f9538..46d0c31e22 100644 --- a/core/src/main/java/hudson/markup/MyspacePolicy.java +++ b/core/src/main/java/hudson/markup/MyspacePolicy.java @@ -67,7 +67,6 @@ public class MyspacePolicy { tag("img", "src",ONSITE_OR_OFFSITE_URL, "hspace","vspace"); tag("iframe", "src"); - tag("link", "type","rel"); tag("ul,ol,li,dd,dl,dt,thead,tbody,tfoot"); tag("table", "noresize"); tag("td,th,tr"); diff --git a/core/src/test/java/hudson/markup/MyspacePolicyTest.java b/core/src/test/java/hudson/markup/MyspacePolicyTest.java index cb1a63e2bb..75ac37b28c 100644 --- a/core/src/test/java/hudson/markup/MyspacePolicyTest.java +++ b/core/src/test/java/hudson/markup/MyspacePolicyTest.java @@ -43,7 +43,7 @@ public class MyspacePolicyTest extends Assert { assertReject("script",""); assertIntact(""); - assertIntact(""); + assertReject("link", ""); assertIntact("
inline CSS
"); assertIntact("

"); From 04403edc5863a848ee706e82995aba4675f55968 Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Wed, 24 Apr 2013 18:02:49 -0400 Subject: [PATCH 019/702] [SECURITY-63] Require POST for running Groovy scripts.(cherry picked from commit 3bbb65df3a5cb2cedb1d8080d6b70697c826a4a9) --- core/src/main/java/hudson/model/Computer.java | 17 +-------- core/src/main/java/jenkins/model/Jenkins.java | 17 ++++++--- .../java/hudson/maven/MavenProbeAction.java | 16 +-------- .../test/java/jenkins/model/JenkinsTest.java | 36 +++++++++++++++++++ 4 files changed, 50 insertions(+), 36 deletions(-) diff --git a/core/src/main/java/hudson/model/Computer.java b/core/src/main/java/hudson/model/Computer.java index cc0edeb367..0778741435 100644 --- a/core/src/main/java/hudson/model/Computer.java +++ b/core/src/main/java/hudson/model/Computer.java @@ -51,8 +51,6 @@ import hudson.slaves.RetentionStrategy; import hudson.slaves.WorkspaceList; import hudson.slaves.OfflineCause; import hudson.slaves.OfflineCause.ByCLI; -import hudson.tasks.BuildWrapper; -import hudson.tasks.Publisher; import hudson.util.DaemonThreadFactory; import hudson.util.EditDistance; import hudson.util.ExceptionCatchingThreadFactory; @@ -1157,20 +1155,7 @@ public /*transient*/ abstract class Computer extends Actionable implements Acces } protected void _doScript( StaplerRequest req, StaplerResponse rsp, String view) throws IOException, ServletException { - // ability to run arbitrary script is dangerous - checkPermission(Jenkins.RUN_SCRIPTS); - - String text = req.getParameter("script"); - if(text!=null) { - try { - req.setAttribute("output", - RemotingDiagnostics.executeGroovy(text,getChannel())); - } catch (InterruptedException e) { - throw new ServletException(e); - } - } - - req.getView(this,view).forward(req, rsp); + Jenkins._doScript(req, rsp, req.getView(this, view), getChannel(), getACL()); } /** diff --git a/core/src/main/java/jenkins/model/Jenkins.java b/core/src/main/java/jenkins/model/Jenkins.java index 7ed3304bac..6fd22fd149 100755 --- a/core/src/main/java/jenkins/model/Jenkins.java +++ b/core/src/main/java/jenkins/model/Jenkins.java @@ -261,6 +261,7 @@ import java.io.InputStream; import java.io.PrintWriter; import java.io.StringWriter; import java.net.BindException; +import java.net.HttpURLConnection; import java.net.URL; import java.nio.charset.Charset; import java.security.SecureRandom; @@ -3357,25 +3358,31 @@ public class Jenkins extends AbstractCIBase implements ModifiableTopLevelItemGro * Run arbitrary Groovy script. */ public void doScript(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException { - doScript(req, rsp, req.getView(this, "_script.jelly")); + _doScript(req, rsp, req.getView(this, "_script.jelly"), MasterComputer.localChannel, getACL()); } /** * Run arbitrary Groovy script and return result as plain text. */ public void doScriptText(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException { - doScript(req, rsp, req.getView(this, "_scriptText.jelly")); + _doScript(req, rsp, req.getView(this, "_scriptText.jelly"), MasterComputer.localChannel, getACL()); } - private void doScript(StaplerRequest req, StaplerResponse rsp, RequestDispatcher view) throws IOException, ServletException { + /** + * @since 1.509.1 + */ + public static void _doScript(StaplerRequest req, StaplerResponse rsp, RequestDispatcher view, VirtualChannel channel, ACL acl) throws IOException, ServletException { // ability to run arbitrary script is dangerous - checkPermission(RUN_SCRIPTS); + acl.checkPermission(RUN_SCRIPTS); String text = req.getParameter("script"); if (text != null) { + if (!"POST".equals(req.getMethod())) { + throw HttpResponses.error(HttpURLConnection.HTTP_BAD_METHOD, "requires POST"); + } try { req.setAttribute("output", - RemotingDiagnostics.executeGroovy(text, MasterComputer.localChannel)); + RemotingDiagnostics.executeGroovy(text, channel)); } catch (InterruptedException e) { throw new ServletException(e); } diff --git a/maven-plugin/src/main/java/hudson/maven/MavenProbeAction.java b/maven-plugin/src/main/java/hudson/maven/MavenProbeAction.java index dbf4acf2bb..5efe9ee56c 100644 --- a/maven-plugin/src/main/java/hudson/maven/MavenProbeAction.java +++ b/maven-plugin/src/main/java/hudson/maven/MavenProbeAction.java @@ -97,21 +97,7 @@ public final class MavenProbeAction implements Action { } public void doScript( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException { - // ability to run arbitrary script is dangerous, - // so tie it to the admin access - owner.checkPermission(Jenkins.RUN_SCRIPTS); - - String text = req.getParameter("script"); - if(text!=null) { - try { - req.setAttribute("output", - RemotingDiagnostics.executeGroovy(text,channel)); - } catch (InterruptedException e) { - throw new ServletException(e); - } - } - - req.getView(this,"_script.jelly").forward(req,rsp); + Jenkins._doScript(req, rsp, req.getView(this, "_script.jelly"), channel, owner.getACL()); } /** diff --git a/test/src/test/java/jenkins/model/JenkinsTest.java b/test/src/test/java/jenkins/model/JenkinsTest.java index 46700d5195..6859e83b58 100644 --- a/test/src/test/java/jenkins/model/JenkinsTest.java +++ b/test/src/test/java/jenkins/model/JenkinsTest.java @@ -23,6 +23,8 @@ */ package jenkins.model; +import com.gargoylesoftware.htmlunit.HttpMethod; +import com.gargoylesoftware.htmlunit.WebRequestSettings; import com.gargoylesoftware.htmlunit.html.HtmlForm; import hudson.maven.MavenModuleSet; import hudson.maven.MavenModuleSetBuild; @@ -32,6 +34,9 @@ import hudson.security.FullControlOnceLoggedInAuthorizationStrategy; import hudson.util.HttpResponses; import junit.framework.Assert; import hudson.model.FreeStyleProject; +import hudson.security.GlobalMatrixAuthorizationStrategy; +import hudson.security.LegacySecurityRealm; +import hudson.security.Permission; import hudson.util.FormValidation; import org.junit.Test; @@ -41,6 +46,7 @@ import org.jvnet.hudson.test.HudsonTestCase; import org.jvnet.hudson.test.TestExtension; import org.kohsuke.stapler.HttpResponse; import java.net.HttpURLConnection; +import java.net.URL; /** * @author kingfai @@ -237,6 +243,36 @@ public class JenkinsTest extends HudsonTestCase { assertEquals(3,jenkins.getExtensionList(RootAction.class).get(RootActionImpl.class).count); } + public void testDoScript() throws Exception { + jenkins.setSecurityRealm(new LegacySecurityRealm()); + GlobalMatrixAuthorizationStrategy gmas = new GlobalMatrixAuthorizationStrategy() { + @Override public boolean hasPermission(String sid, Permission p) { + return p == Jenkins.RUN_SCRIPTS ? hasExplicitPermission(sid, p) : super.hasPermission(sid, p); + } + }; + gmas.add(Jenkins.ADMINISTER, "alice"); + gmas.add(Jenkins.RUN_SCRIPTS, "alice"); + gmas.add(Jenkins.READ, "bob"); + gmas.add(Jenkins.ADMINISTER, "charlie"); + jenkins.setAuthorizationStrategy(gmas); + WebClient wc = createWebClient(); + wc.login("alice"); + wc.goTo("script"); + wc.assertFails("script?script=System.setProperty('hack','me')", HttpURLConnection.HTTP_BAD_METHOD); + assertNull(System.getProperty("hack")); + WebRequestSettings req = new WebRequestSettings(new URL(wc.getContextPath() + "script?script=System.setProperty('hack','me')"), HttpMethod.POST); + wc.getPage(wc.addCrumb(req)); + assertEquals("me", System.getProperty("hack")); + wc.assertFails("scriptText?script=System.setProperty('hack','me')", HttpURLConnection.HTTP_BAD_METHOD); + req = new WebRequestSettings(new URL(wc.getContextPath() + "scriptText?script=System.setProperty('huck','you')"), HttpMethod.POST); + wc.getPage(wc.addCrumb(req)); + assertEquals("you", System.getProperty("huck")); + wc.login("bob"); + wc.assertFails("script", HttpURLConnection.HTTP_FORBIDDEN); + wc.login("charlie"); + wc.assertFails("script", HttpURLConnection.HTTP_FORBIDDEN); + } + @TestExtension("testUnprotectedRootAction") public static class RootActionImpl implements UnprotectedRootAction { private int count; From 1e51b62298d37753f6b2d2f70eb179ab950d1456 Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Wed, 24 Apr 2013 18:32:01 -0400 Subject: [PATCH 020/702] [SECURITY-63] Check RUN_SCRIPTS for /eval.(cherry picked from commit 3d03990abc68f39e7a92ed9594abb658879a6d7b) --- core/src/main/java/jenkins/model/Jenkins.java | 2 +- .../test/java/jenkins/model/JenkinsTest.java | 40 +++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/jenkins/model/Jenkins.java b/core/src/main/java/jenkins/model/Jenkins.java index 6fd22fd149..b2efe0caa5 100755 --- a/core/src/main/java/jenkins/model/Jenkins.java +++ b/core/src/main/java/jenkins/model/Jenkins.java @@ -3398,7 +3398,7 @@ public class Jenkins extends AbstractCIBase implements ModifiableTopLevelItemGro */ @RequirePOST public void doEval(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException { - checkPermission(ADMINISTER); + checkPermission(RUN_SCRIPTS); try { MetaClass mc = WebApp.getCurrent().getMetaClass(getClass()); diff --git a/test/src/test/java/jenkins/model/JenkinsTest.java b/test/src/test/java/jenkins/model/JenkinsTest.java index 6859e83b58..250d9591f5 100644 --- a/test/src/test/java/jenkins/model/JenkinsTest.java +++ b/test/src/test/java/jenkins/model/JenkinsTest.java @@ -23,6 +23,7 @@ */ package jenkins.model; +import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException; import com.gargoylesoftware.htmlunit.HttpMethod; import com.gargoylesoftware.htmlunit.WebRequestSettings; import com.gargoylesoftware.htmlunit.html.HtmlForm; @@ -273,6 +274,45 @@ public class JenkinsTest extends HudsonTestCase { wc.assertFails("script", HttpURLConnection.HTTP_FORBIDDEN); } + public void testDoEval() throws Exception { + jenkins.setSecurityRealm(new LegacySecurityRealm()); + GlobalMatrixAuthorizationStrategy gmas = new GlobalMatrixAuthorizationStrategy() { + @Override public boolean hasPermission(String sid, Permission p) { + return p == Jenkins.RUN_SCRIPTS ? hasExplicitPermission(sid, p) : super.hasPermission(sid, p); + } + }; + gmas.add(Jenkins.ADMINISTER, "alice"); + gmas.add(Jenkins.RUN_SCRIPTS, "alice"); + gmas.add(Jenkins.READ, "bob"); + gmas.add(Jenkins.ADMINISTER, "charlie"); + jenkins.setAuthorizationStrategy(gmas); + // Otherwise get "RuntimeException: Trying to set the request parameters, but the request body has already been specified;the two are mutually exclusive!" from WebRequestSettings.setRequestParameters when POSTing content: + jenkins.setCrumbIssuer(null); + WebClient wc = createWebClient(); + wc.login("alice"); + wc.assertFails("eval", HttpURLConnection.HTTP_INTERNAL_ERROR); + assertEquals("3", eval(wc)); + wc.login("bob"); + try { + eval(wc); + fail("bob has only READ"); + } catch (FailingHttpStatusCodeException e) { + assertEquals(HttpURLConnection.HTTP_FORBIDDEN, e.getStatusCode()); + } + wc.login("charlie"); + try { + eval(wc); + fail("charlie has ADMINISTER but not RUN_SCRIPTS"); + } catch (FailingHttpStatusCodeException e) { + assertEquals(HttpURLConnection.HTTP_FORBIDDEN, e.getStatusCode()); + } + } + private String eval(WebClient wc) throws Exception { + WebRequestSettings req = new WebRequestSettings(new URL(wc.getContextPath() + "eval"), HttpMethod.POST); + req.setRequestBody("${1+2}"); + return wc.getPage(/*wc.addCrumb(*/req/*)*/).getWebResponse().getContentAsString(); + } + @TestExtension("testUnprotectedRootAction") public static class RootActionImpl implements UnprotectedRootAction { private int count; From 8063a27abbe3fbe28b11ef6f6a6af70f43f32e91 Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Wed, 24 Apr 2013 18:50:47 -0400 Subject: [PATCH 021/702] [FIXED SECURITY-69] Require POST to redeploy artifacts.(cherry picked from commit 3e56c3fc1884c8cdbfe9da55c689d26461592f55) --- .../hudson/maven/reporters/MavenAbstractArtifactRecord.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/maven-plugin/src/main/java/hudson/maven/reporters/MavenAbstractArtifactRecord.java b/maven-plugin/src/main/java/hudson/maven/reporters/MavenAbstractArtifactRecord.java index 482fc70c48..95681e5eb6 100644 --- a/maven-plugin/src/main/java/hudson/maven/reporters/MavenAbstractArtifactRecord.java +++ b/maven-plugin/src/main/java/hudson/maven/reporters/MavenAbstractArtifactRecord.java @@ -65,6 +65,7 @@ import org.kohsuke.stapler.StaplerRequest; import org.kohsuke.stapler.StaplerResponse; import org.kohsuke.stapler.export.Exported; import org.kohsuke.stapler.export.ExportedBean; +import org.kohsuke.stapler.interceptor.RequirePOST; /** * UI to redeploy artifacts after the fact. @@ -208,6 +209,7 @@ public abstract class MavenAbstractArtifactRecord> /** * Performs a redeployment. */ + @RequirePOST public final HttpResponse doRedeploy( @QueryParameter("_.id") final String id, @QueryParameter("_.url") final String repositoryUrl, From f7e266efb611a323229028ecaa238dde43570cd5 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Wed, 24 Apr 2013 18:04:03 -0700 Subject: [PATCH 022/702] [FIXED SECURITY-71] (cherry picked from commit 4f0200a06d1a57a908a37428cfb25ebc7f61fe69) --- core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/pom.xml b/core/pom.xml index 636d453829..b5bf91e598 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -164,7 +164,7 @@ THE SOFTWARE. org.kohsuke.stapler stapler-adjunct-zeroclipboard - 1.0.7-2 + 1.1.7-1 org.kohsuke.stapler From 499fcaa1892fd9b486a6980c60e91a8286b57c9b Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Wed, 1 May 2013 14:23:06 -0700 Subject: [PATCH 023/702] recording fixes --- changelog.html | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/changelog.html b/changelog.html index 52c5b53d5a..bae88f79b2 100644 --- a/changelog.html +++ b/changelog.html @@ -94,6 +94,15 @@ Upcoming changes
  • Breadcrumb is reworked to show descendants to provide additional navigational shortcuts. (discussion) +
  • + Fixed CSRF vulnerabilities + (SECURITY-63,SECURITY-69) +
  • + Fixed an XSS vulnerability via stylesheet + (SECURITY-67) +
  • + Fixed an XSS vulnerability to copy arbitrary text into clipboard + (SECURITY-71/CVE-2013-1808)

    What's new in 1.512 (2013/04/21)