From e598bfb04d58090c3165839156f839c6ead42927 Mon Sep 17 00:00:00 2001 From: Samuel Moritz Date: Sun, 9 Dec 2012 14:51:49 +0100 Subject: [PATCH 001/194] 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 002/194] 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 5457d1e8c34fe08585231ddab71067a7fd441146 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20Gond=C5=BEa?= Date: Thu, 23 May 2013 15:56:56 +0200 Subject: [PATCH 003/194] Unittest hudson.cli.ListJobsCommand --- .../main/java/hudson/cli/ListJobsCommand.java | 2 + .../java/hudson/cli/ListJobsCommandTest.java | 165 ++++++++++++++++++ 2 files changed, 167 insertions(+) create mode 100644 core/src/test/java/hudson/cli/ListJobsCommandTest.java diff --git a/core/src/main/java/hudson/cli/ListJobsCommand.java b/core/src/main/java/hudson/cli/ListJobsCommand.java index 8e52a9f449..9e8bdda4bd 100644 --- a/core/src/main/java/hudson/cli/ListJobsCommand.java +++ b/core/src/main/java/hudson/cli/ListJobsCommand.java @@ -24,7 +24,9 @@ package hudson.cli; import java.util.Collection; + import java.util.Collections; + import hudson.model.Item; import hudson.model.ItemGroup; import hudson.model.TopLevelItem; diff --git a/core/src/test/java/hudson/cli/ListJobsCommandTest.java b/core/src/test/java/hudson/cli/ListJobsCommandTest.java new file mode 100644 index 0000000000..66362fe2d2 --- /dev/null +++ b/core/src/test/java/hudson/cli/ListJobsCommandTest.java @@ -0,0 +1,165 @@ +package hudson.cli; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.powermock.api.mockito.PowerMockito.mock; +import static org.powermock.api.mockito.PowerMockito.mockStatic; +import static org.powermock.api.mockito.PowerMockito.when; +import hudson.model.TopLevelItem; +import hudson.model.ViewGroup; +import hudson.model.View; + +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; + +import jenkins.model.Jenkins; + +import org.hamcrest.BaseMatcher; +import org.hamcrest.Description; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +@PrepareForTest(Jenkins.class) +@SuppressStaticInitializationFor("hudson.cli.CLICommand") +public class ListJobsCommandTest { + + private /*final*/ Jenkins jenkins; + private /*final*/ ListJobsCommand command; + private final ByteArrayOutputStream stdout = new ByteArrayOutputStream(); + private final ByteArrayOutputStream stderr = new ByteArrayOutputStream(); + + @Before + public void setUp() { + + jenkins = mock(Jenkins.class); + mockStatic(Jenkins.class); + when(Jenkins.getInstance()).thenReturn(jenkins); + command = mock(ListJobsCommand.class, Mockito.CALLS_REAL_METHODS); + command.stdout = new PrintStream(stdout); + command.stderr = new PrintStream(stderr); + } + + @Test + public void getNullForNonexistingName() throws Exception { + + when(jenkins.getView(null)).thenReturn(null); + when(jenkins.getItemByFullName(null)).thenReturn(null); + + // TODO: One would expect -1 here + assertThat(runWith("NoSuchViewOrItemGroup"), equalTo(0)); + assertThat(stdout, is(empty())); + assertThat(stderr, is(not(empty()))); + } + + @Test + public void getAllJobsForEmptyName() throws Exception { + + final Collection jenkinsJobs = Arrays.asList( + job("some-job"), job("some-other-job") + ); + + when(jenkins.getItems()).thenReturn((List) jenkinsJobs); + + assertThat(runWith(null), equalTo(0)); + assertThat(stderr, is(empty())); + assertThat(stdout, listsJobs("some-job", "some-other-job")); + } + + @Test + public void getJobsFromView() throws Exception { + + final Collection viewJobs = Arrays.asList( + job("some-job"), job("some-other-job") + ); + + final View customView = mock(View.class); + when(customView.getItems()).thenReturn(viewJobs); + + when(jenkins.getView("CustomView")).thenReturn(customView); + + assertThat(runWith("CustomView"), equalTo(0)); + assertThat(stderr, is(empty())); + assertThat(stdout, listsJobs("some-job", "some-other-job")); + } + + private TopLevelItem job(final String name) { + + final TopLevelItem item = mock(TopLevelItem.class); + + when(item.getDisplayName()).thenReturn(name); + + return item; + } + + private int runWith(final String name) throws Exception { + + command.name = name; + + return command.run(); + } + + private BaseMatcher empty() { + + return new BaseMatcher() { + + @Override + public boolean matches(Object item) { + + if (!(item instanceof ByteArrayOutputStream)) throw new IllegalArgumentException(); + + return ((ByteArrayOutputStream) item).toString().isEmpty(); + } + + @Override + public void describeTo(Description description) { + + description.appendText("Empty output"); + } + }; + } + + private BaseMatcher listsJobs(final String... expected) { + + return new BaseMatcher() { + + @Override + public boolean matches(Object item) { + + if (!(item instanceof ByteArrayOutputStream)) return false; + + final ByteArrayOutputStream actual = (ByteArrayOutputStream) item; + + final HashSet jobs = new HashSet( + Arrays.asList(actual.toString().split("\n")) + ); + + return new HashSet(Arrays.asList(expected)).equals(jobs); + } + + @Override + public void describeTo(Description description) { + + description.appendText("Job listing of " + Arrays.toString(expected)); + } + }; + } + + private abstract static class CompositeView extends View implements ViewGroup { + + protected CompositeView(String name) { + super(name); + } + } +} From bdea18f5ca558ebae1d76458eb6480fb4bc36c29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20Gond=C5=BEa?= Date: Mon, 27 May 2013 21:58:37 +0200 Subject: [PATCH 004/194] List Jobs recursively in hudson.cli.ListJobsCommand --- .../main/java/hudson/cli/ListJobsCommand.java | 20 +++++++- .../java/hudson/cli/ListJobsCommandTest.java | 48 +++++++++++++------ 2 files changed, 52 insertions(+), 16 deletions(-) diff --git a/core/src/main/java/hudson/cli/ListJobsCommand.java b/core/src/main/java/hudson/cli/ListJobsCommand.java index 9e8bdda4bd..809bd328b4 100644 --- a/core/src/main/java/hudson/cli/ListJobsCommand.java +++ b/core/src/main/java/hudson/cli/ListJobsCommand.java @@ -24,12 +24,14 @@ package hudson.cli; import java.util.Collection; +import java.util.LinkedHashSet; import java.util.Collections; import hudson.model.Item; import hudson.model.ItemGroup; import hudson.model.TopLevelItem; +import hudson.model.ViewGroup; import hudson.model.View; import hudson.Extension; import jenkins.model.Jenkins; @@ -59,7 +61,7 @@ public class ListJobsCommand extends CLICommand { View view = h.getView(name); if (view != null) { - jobs = view.getItems(); + jobs = getViewItems(view); } // If no view was found, try with an item group. else { @@ -89,4 +91,20 @@ public class ListJobsCommand extends CLICommand { return 0; } + + private Collection getViewItems(View view) { + + final Collection jobs = new LinkedHashSet( + view.getItems() + ); + + if (view instanceof ViewGroup) { + + for(View subview: ((ViewGroup) view).getViews()) { + + jobs.addAll(getViewItems(subview)); + } + } + return jobs; + } } diff --git a/core/src/test/java/hudson/cli/ListJobsCommandTest.java b/core/src/test/java/hudson/cli/ListJobsCommandTest.java index 66362fe2d2..490de8d94f 100644 --- a/core/src/test/java/hudson/cli/ListJobsCommandTest.java +++ b/core/src/test/java/hudson/cli/ListJobsCommandTest.java @@ -20,8 +20,8 @@ import java.util.List; import jenkins.model.Jenkins; -import org.hamcrest.BaseMatcher; import org.hamcrest.Description; +import org.hamcrest.TypeSafeMatcher; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -94,6 +94,30 @@ public class ListJobsCommandTest { assertThat(stdout, listsJobs("some-job", "some-other-job")); } + @Test + public void getJobsRecursivelyFromViewGroup() throws Exception { + + final CompositeView rootView = mock(CompositeView.class); + final View leftView = mock(View.class); + final View rightView = mock(View.class); + + final TopLevelItem rootJob = job("rootJob"); + final TopLevelItem leftJob = job("leftJob"); + final TopLevelItem rightJob = job("rightJob"); + final TopLevelItem sharedJob = job("sharedJob"); + + when(rootView.getViews()).thenReturn(Arrays.asList(leftView, rightView)); + when(rootView.getItems()).thenReturn(Arrays.asList(rootJob, sharedJob)); + when(leftView.getItems()).thenReturn(Arrays.asList(leftJob, sharedJob)); + when(rightView.getItems()).thenReturn(Arrays.asList(rightJob)); + + when(jenkins.getView("Root")).thenReturn(rootView); + + assertThat(runWith("Root"), equalTo(0)); + assertThat(stderr, is(empty())); + assertThat(stdout, listsJobs("rootJob", "leftJob", "rightJob", "sharedJob")); + } + private TopLevelItem job(final String name) { final TopLevelItem item = mock(TopLevelItem.class); @@ -110,16 +134,14 @@ public class ListJobsCommandTest { return command.run(); } - private BaseMatcher empty() { + private TypeSafeMatcher empty() { - return new BaseMatcher() { + return new TypeSafeMatcher() { @Override - public boolean matches(Object item) { + protected boolean matchesSafely(ByteArrayOutputStream item) { - if (!(item instanceof ByteArrayOutputStream)) throw new IllegalArgumentException(); - - return ((ByteArrayOutputStream) item).toString().isEmpty(); + return item.toString().isEmpty(); } @Override @@ -130,19 +152,15 @@ public class ListJobsCommandTest { }; } - private BaseMatcher listsJobs(final String... expected) { + private TypeSafeMatcher listsJobs(final String... expected) { - return new BaseMatcher() { + return new TypeSafeMatcher() { @Override - public boolean matches(Object item) { - - if (!(item instanceof ByteArrayOutputStream)) return false; - - final ByteArrayOutputStream actual = (ByteArrayOutputStream) item; + protected boolean matchesSafely(ByteArrayOutputStream item) { final HashSet jobs = new HashSet( - Arrays.asList(actual.toString().split("\n")) + Arrays.asList(item.toString().split("\n")) ); return new HashSet(Arrays.asList(expected)).equals(jobs); From 0bfa98a87480992dd015948f03df64f04294730c Mon Sep 17 00:00:00 2001 From: Nicolas De Loof Date: Wed, 29 May 2013 00:06:30 +0200 Subject: [PATCH 005/194] simplify isReadyToRestart --- core/src/main/java/hudson/model/RestartListener.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core/src/main/java/hudson/model/RestartListener.java b/core/src/main/java/hudson/model/RestartListener.java index 0873413e38..9a0911579e 100644 --- a/core/src/main/java/hudson/model/RestartListener.java +++ b/core/src/main/java/hudson/model/RestartListener.java @@ -51,8 +51,7 @@ public abstract class RestartListener implements ExtensionPoint { public static class Default extends RestartListener { @Override public boolean isReadyToRestart() throws IOException, InterruptedException { - Jenkins h = Jenkins.getInstance(); - return h.overallLoad.computeTotalExecutors() <= h.overallLoad.computeIdleExecutors(); + return new ComputerSet().getBusyExecutors() != 0; } } } From 4ec2e08f8ccb2d1e40da45bde9df7f3721ff85c1 Mon Sep 17 00:00:00 2001 From: Francisco Ruiz Date: Fri, 31 May 2013 11:48:33 +0200 Subject: [PATCH 006/194] Fixed confirmPOST JS utility not working with CSRF protection enabled. --- core/src/main/resources/lib/layout/confirmationLink.jelly | 1 + 1 file changed, 1 insertion(+) diff --git a/core/src/main/resources/lib/layout/confirmationLink.jelly b/core/src/main/resources/lib/layout/confirmationLink.jelly index a636ced4db..f03a944145 100644 --- a/core/src/main/resources/lib/layout/confirmationLink.jelly +++ b/core/src/main/resources/lib/layout/confirmationLink.jelly @@ -45,6 +45,7 @@ THE SOFTWARE. var form = document.createElement('form'); form.setAttribute('method', post ? 'POST' : 'GET'); form.setAttribute('action', href); + crumb.appendToForm(form); document.body.appendChild(form); form.submit(); } From 3701a327a75d35e5d0e5795341cc55bb123a2007 Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Mon, 3 Jun 2013 14:20:35 -0400 Subject: [PATCH 007/194] [JENKINS-14362] Switch to jzlib for GZIP streaming. --- cli/pom.xml | 2 +- core/pom.xml | 4 ++-- core/src/main/java/hudson/FilePath.java | 6 +++--- .../main/java/hudson/console/AnnotatedLargeText.java | 4 ++-- core/src/main/java/hudson/console/ConsoleNote.java | 4 ++-- core/src/main/java/hudson/model/Run.java | 2 +- core/src/main/java/hudson/model/UsageStatistics.java | 2 +- .../security/HudsonAuthenticationEntryPoint.java | 1 - core/src/main/java/hudson/util/CompressedFile.java | 4 ++-- maven-plugin/pom.xml | 2 +- plugins/pom.xml | 10 +++++----- pom.xml | 2 +- test/pom.xml | 2 +- ui-samples-plugin/pom.xml | 2 +- war/pom.xml | 2 +- 15 files changed, 24 insertions(+), 25 deletions(-) diff --git a/cli/pom.xml b/cli/pom.xml index 4a8150f132..7628a16e94 100644 --- a/cli/pom.xml +++ b/cli/pom.xml @@ -5,7 +5,7 @@ pom org.jenkins-ci.main - 1.513 + 1.513.JENKINS-14362-jzlib cli diff --git a/core/pom.xml b/core/pom.xml index 9bc3bf8525..3873845939 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -29,7 +29,7 @@ THE SOFTWARE. org.jenkins-ci.main pom - 1.513 + 1.513.JENKINS-14362-jzlib ../pom.xml @@ -42,7 +42,7 @@ THE SOFTWARE. true - 1.207 + 1.207.JENKINS-14362-jzlib 2.5.6.SEC03 diff --git a/core/src/main/java/hudson/FilePath.java b/core/src/main/java/hudson/FilePath.java index 3dabd48108..225f42ed34 100644 --- a/core/src/main/java/hudson/FilePath.java +++ b/core/src/main/java/hudson/FilePath.java @@ -92,8 +92,8 @@ import java.util.regex.Pattern; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; -import java.util.zip.GZIPOutputStream; -import java.util.zip.GZIPInputStream; +import com.jcraft.jzlib.GZIPInputStream; +import com.jcraft.jzlib.GZIPOutputStream; import com.sun.jna.Native; import hudson.os.PosixException; @@ -619,7 +619,7 @@ public final class FilePath implements Serializable { public InputStream extract(InputStream _in) throws IOException { HeadBufferingStream in = new HeadBufferingStream(_in,SIDE_BUFFER_SIZE); try { - return new GZIPInputStream(in,8192); + return new GZIPInputStream(in, 8192, true); } catch (IOException e) { // various people reported "java.io.IOException: Not in GZIP format" here, so diagnose this problem better in.fillSide(); diff --git a/core/src/main/java/hudson/console/AnnotatedLargeText.java b/core/src/main/java/hudson/console/AnnotatedLargeText.java index 1fe28f84e8..298e034bf1 100644 --- a/core/src/main/java/hudson/console/AnnotatedLargeText.java +++ b/core/src/main/java/hudson/console/AnnotatedLargeText.java @@ -51,8 +51,8 @@ import java.io.OutputStream; import java.io.Writer; import java.nio.charset.Charset; import java.security.GeneralSecurityException; -import java.util.zip.GZIPInputStream; -import java.util.zip.GZIPOutputStream; +import com.jcraft.jzlib.GZIPInputStream; +import com.jcraft.jzlib.GZIPOutputStream; import static java.lang.Math.abs; diff --git a/core/src/main/java/hudson/console/ConsoleNote.java b/core/src/main/java/hudson/console/ConsoleNote.java index 4660193f8c..c8ea004643 100644 --- a/core/src/main/java/hudson/console/ConsoleNote.java +++ b/core/src/main/java/hudson/console/ConsoleNote.java @@ -50,8 +50,8 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.List; -import java.util.zip.GZIPInputStream; -import java.util.zip.GZIPOutputStream; +import com.jcraft.jzlib.GZIPInputStream; +import com.jcraft.jzlib.GZIPOutputStream; /** * Data that hangs off from a console output. diff --git a/core/src/main/java/hudson/model/Run.java b/core/src/main/java/hudson/model/Run.java index 5027263828..e1d944f92b 100644 --- a/core/src/main/java/hudson/model/Run.java +++ b/core/src/main/java/hudson/model/Run.java @@ -91,7 +91,7 @@ import java.util.Set; import java.util.HashSet; import java.util.logging.Level; import java.util.logging.Logger; -import java.util.zip.GZIPInputStream; +import com.jcraft.jzlib.GZIPInputStream; import javax.servlet.ServletException; import javax.servlet.http.HttpServletResponse; diff --git a/core/src/main/java/hudson/model/UsageStatistics.java b/core/src/main/java/hudson/model/UsageStatistics.java index 34382a3f44..2d15348670 100644 --- a/core/src/main/java/hudson/model/UsageStatistics.java +++ b/core/src/main/java/hudson/model/UsageStatistics.java @@ -59,7 +59,7 @@ import java.security.interfaces.RSAPublicKey; import java.security.spec.X509EncodedKeySpec; import java.util.ArrayList; import java.util.List; -import java.util.zip.GZIPOutputStream; +import com.jcraft.jzlib.GZIPOutputStream; /** * @author Kohsuke Kawaguchi diff --git a/core/src/main/java/hudson/security/HudsonAuthenticationEntryPoint.java b/core/src/main/java/hudson/security/HudsonAuthenticationEntryPoint.java index 6a3c21efec..f79037f4f7 100644 --- a/core/src/main/java/hudson/security/HudsonAuthenticationEntryPoint.java +++ b/core/src/main/java/hudson/security/HudsonAuthenticationEntryPoint.java @@ -42,7 +42,6 @@ import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.net.URLEncoder; import java.text.MessageFormat; -import java.util.zip.GZIPOutputStream; /** * For anonymous requests to pages that require authentication, diff --git a/core/src/main/java/hudson/util/CompressedFile.java b/core/src/main/java/hudson/util/CompressedFile.java index ce5afe2cb9..93c79a4d8c 100644 --- a/core/src/main/java/hudson/util/CompressedFile.java +++ b/core/src/main/java/hudson/util/CompressedFile.java @@ -40,8 +40,8 @@ import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; import java.util.logging.Level; import java.util.logging.Logger; -import java.util.zip.GZIPInputStream; -import java.util.zip.GZIPOutputStream; +import com.jcraft.jzlib.GZIPInputStream; +import com.jcraft.jzlib.GZIPOutputStream; /** * Represents write-once read-many file that can be optiionally compressed diff --git a/maven-plugin/pom.xml b/maven-plugin/pom.xml index 63e703b332..6b49c05f7a 100644 --- a/maven-plugin/pom.xml +++ b/maven-plugin/pom.xml @@ -29,7 +29,7 @@ THE SOFTWARE. org.jenkins-ci.main pom - 1.513 + 1.513.JENKINS-14362-jzlib maven-plugin diff --git a/plugins/pom.xml b/plugins/pom.xml index 09ec82b8ca..a28b25d780 100644 --- a/plugins/pom.xml +++ b/plugins/pom.xml @@ -38,7 +38,7 @@ org.jenkins-ci.main maven-plugin - 1.513 + 1.513.JENKINS-14362-jzlib @@ -48,25 +48,25 @@ org.jenkins-ci.main jenkins-war war - 1.513 + 1.513.JENKINS-14362-jzlib test org.jenkins-ci.main jenkins-core - 1.513 + 1.513.JENKINS-14362-jzlib provided org.jenkins-ci.main jenkins-test-harness - 1.513 + 1.513.JENKINS-14362-jzlib test org.jenkins-ci.main ui-samples-plugin - 1.513 + 1.513.JENKINS-14362-jzlib test org.jenkins-ci.main maven-plugin - 1.513.JENKINS-14362-jzlib + 1.513 @@ -48,25 +48,25 @@ org.jenkins-ci.main jenkins-war war - 1.513.JENKINS-14362-jzlib + 1.513 test org.jenkins-ci.main jenkins-core - 1.513.JENKINS-14362-jzlib + 1.513 provided org.jenkins-ci.main jenkins-test-harness - 1.513.JENKINS-14362-jzlib + 1.513 test org.jenkins-ci.main ui-samples-plugin - 1.513.JENKINS-14362-jzlib + 1.513 test From e42149faa9bac42d4a7943c7c27e42c8250ed354 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Tue, 11 Jun 2013 16:29:05 +0100 Subject: [PATCH 014/194] Added basic abstraction for authenticating Executors --- .../security/GlobalSecurityConfiguration.java | 2 + .../DefaultExecutorAuthenticator.java | 30 +++++++++++ .../security/ExecutorAuthenticator.java | 39 ++++++++++++++ .../ExecutorAuthenticatorConfiguration.java | 53 +++++++++++++++++++ .../ExecutorAuthenticatorDescriptor.java | 19 +++++++ .../ExecutorAuthenticator/config.groovy | 2 + .../config.groovy | 32 +++++++++++ 7 files changed, 177 insertions(+) create mode 100644 core/src/main/java/jenkins/security/DefaultExecutorAuthenticator.java create mode 100644 core/src/main/java/jenkins/security/ExecutorAuthenticator.java create mode 100644 core/src/main/java/jenkins/security/ExecutorAuthenticatorConfiguration.java create mode 100644 core/src/main/java/jenkins/security/ExecutorAuthenticatorDescriptor.java create mode 100644 core/src/main/resources/jenkins/security/ExecutorAuthenticator/config.groovy create mode 100644 core/src/main/resources/jenkins/security/ExecutorAuthenticatorConfiguration/config.groovy diff --git a/core/src/main/java/hudson/security/GlobalSecurityConfiguration.java b/core/src/main/java/hudson/security/GlobalSecurityConfiguration.java index 31dd6855e3..9ebe8aa81f 100644 --- a/core/src/main/java/hudson/security/GlobalSecurityConfiguration.java +++ b/core/src/main/java/hudson/security/GlobalSecurityConfiguration.java @@ -50,6 +50,8 @@ import org.kohsuke.stapler.StaplerResponse; /** * Security configuration. * + * For historical reasons, most of the actual configuration values are stored in {@link Jenkins}. + * * @author Kohsuke Kawaguchi */ @Extension(ordinal = Integer.MAX_VALUE - 210) diff --git a/core/src/main/java/jenkins/security/DefaultExecutorAuthenticator.java b/core/src/main/java/jenkins/security/DefaultExecutorAuthenticator.java new file mode 100644 index 0000000000..67dfaf57cf --- /dev/null +++ b/core/src/main/java/jenkins/security/DefaultExecutorAuthenticator.java @@ -0,0 +1,30 @@ +package jenkins.security; + +import hudson.Extension; +import hudson.model.Executor; +import hudson.model.Queue.Executable; +import hudson.security.ACL; +import org.acegisecurity.Authentication; +import org.kohsuke.stapler.DataBoundConstructor; + +/** + * @author Kohsuke Kawaguchi + */ +public class DefaultExecutorAuthenticator extends ExecutorAuthenticator { + @DataBoundConstructor + public DefaultExecutorAuthenticator() { + } + + @Override + public Authentication authenticate(Executor executor, Executable executable) { + return ACL.SYSTEM; + } + + @Extension + public static class DescriptorImpl extends ExecutorAuthenticatorDescriptor { + @Override + public String getDisplayName() { + return "Default"; // TODO: fix + } + } +} diff --git a/core/src/main/java/jenkins/security/ExecutorAuthenticator.java b/core/src/main/java/jenkins/security/ExecutorAuthenticator.java new file mode 100644 index 0000000000..f8243792b7 --- /dev/null +++ b/core/src/main/java/jenkins/security/ExecutorAuthenticator.java @@ -0,0 +1,39 @@ +package jenkins.security; + +import hudson.ExtensionPoint; +import hudson.model.AbstractBuild; +import hudson.model.AbstractDescribableImpl; +import hudson.model.Executor; +import hudson.model.Queue; +import org.acegisecurity.Authentication; + +/** + * Extension point to run builds under a specific identity for better access control. + * + * @author Kohsuke Kawaguchi + * @since 1.520 + */ +public abstract class ExecutorAuthenticator extends AbstractDescribableImpl implements ExtensionPoint { + /** + * Determines the identity in which the build will run as. + * + * @param executor + * The executor that's going to run the executable. Never null. + * Provided as an input to the decision making. + * @param executable + * The build that's going to run. {@link AbstractBuild} is a common subtype of + * this interface. + * TODO: check that actions submitted to the queue are visible on this object. + * + * @return + * returning non-null will determine the identity. If null is returned, the next + * configured {@link ExecutorAuthenticator} will be given a chance to authenticate + * the executor. + */ + public abstract Authentication authenticate(Executor executor, Queue.Executable executable); + + @Override + public ExecutorAuthenticatorDescriptor getDescriptor() { + return (ExecutorAuthenticatorDescriptor)super.getDescriptor(); + } +} diff --git a/core/src/main/java/jenkins/security/ExecutorAuthenticatorConfiguration.java b/core/src/main/java/jenkins/security/ExecutorAuthenticatorConfiguration.java new file mode 100644 index 0000000000..4f8647e5d5 --- /dev/null +++ b/core/src/main/java/jenkins/security/ExecutorAuthenticatorConfiguration.java @@ -0,0 +1,53 @@ +package jenkins.security; + +import hudson.DescriptorExtensionList; +import hudson.Extension; +import hudson.util.DescribableList; +import jenkins.model.GlobalConfiguration; +import jenkins.model.GlobalConfigurationCategory; +import net.sf.json.JSONObject; +import org.kohsuke.accmod.Restricted; +import org.kohsuke.accmod.restrictions.NoExternalUse; +import org.kohsuke.stapler.StaplerRequest; + +import java.io.IOException; + +/** + * Show the {@link ExecutorAuthenticator} configurations on the system config page. + * + * @author Kohsuke Kawaguchi + */ +@Extension +public class ExecutorAuthenticatorConfiguration extends GlobalConfiguration { + private final DescribableList authenticators + = new DescribableList(this); + + public ExecutorAuthenticatorConfiguration() { + load(); + } + + @Override + public GlobalConfigurationCategory getCategory() { + return GlobalConfigurationCategory.get(GlobalConfigurationCategory.Security.class); + } + + public DescribableList getAuthenticators() { + return authenticators; + } + + // TODO: get rid of this method by making PersistedList derive from List via the use of bridge-method injector + @Restricted(NoExternalUse.class) + public DescriptorExtensionList getAuthenticatorsDescriptors() { + return ExecutorAuthenticatorDescriptor.all(); + } + + @Override + public boolean configure(StaplerRequest req, JSONObject json) throws FormException { + try { + authenticators.rebuildHetero(req,json,ExecutorAuthenticatorDescriptor.all(),"authenticators"); + return true; + } catch (IOException e) { + throw new FormException(e,"authenticators"); + } + } +} diff --git a/core/src/main/java/jenkins/security/ExecutorAuthenticatorDescriptor.java b/core/src/main/java/jenkins/security/ExecutorAuthenticatorDescriptor.java new file mode 100644 index 0000000000..dba7428dc2 --- /dev/null +++ b/core/src/main/java/jenkins/security/ExecutorAuthenticatorDescriptor.java @@ -0,0 +1,19 @@ +package jenkins.security; + +import hudson.DescriptorExtensionList; +import hudson.model.Descriptor; +import jenkins.model.Jenkins; + +/** + * {@link Descriptor} for {@link ExecutorAuthenticator}. + * + * @author Kohsuke Kawaguchi + * @since 1.520 + */ +public abstract class ExecutorAuthenticatorDescriptor extends Descriptor { + // nothing defined here yet + + public static DescriptorExtensionList all() { + return Jenkins.getInstance().getDescriptorList(ExecutorAuthenticator.class); + } +} diff --git a/core/src/main/resources/jenkins/security/ExecutorAuthenticator/config.groovy b/core/src/main/resources/jenkins/security/ExecutorAuthenticator/config.groovy new file mode 100644 index 0000000000..635dfab25a --- /dev/null +++ b/core/src/main/resources/jenkins/security/ExecutorAuthenticator/config.groovy @@ -0,0 +1,2 @@ +package jenkins.security.ExecutorAuthenticatorConfiguration; +// the default is empty configuration \ No newline at end of file diff --git a/core/src/main/resources/jenkins/security/ExecutorAuthenticatorConfiguration/config.groovy b/core/src/main/resources/jenkins/security/ExecutorAuthenticatorConfiguration/config.groovy new file mode 100644 index 0000000000..6f276db2b9 --- /dev/null +++ b/core/src/main/resources/jenkins/security/ExecutorAuthenticatorConfiguration/config.groovy @@ -0,0 +1,32 @@ +/* + * The MIT License + * + * Copyright (c) 2011, CloudBees, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package jenkins.security.ExecutorAuthenticatorConfiguration; + +f=namespace(lib.FormTagLib) + +f.section(title:_("Access Control of Executors")) { + f.block() { + f.repeatableHeteroProperty(field:"authenticators",hasHeader:true) + } +} From 3c01366e0bc5c3e8de23eb7337e8c3e4dbd7843c Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Tue, 11 Jun 2013 17:48:22 -0400 Subject: [PATCH 015/194] [FIXED JENKINS-16974] Unsafe to define a function in - - - \ No newline at end of file From 4f828a32f7f60dbff585e854f14590c1e648a988 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Fri, 28 Jun 2013 18:22:21 -0700 Subject: [PATCH 152/194] expand the detail reporting --- .../security/AccessDeniedException2.java | 36 +++++++++++++++++++ .../security/AccessDeniedHandlerImpl.java | 13 ++++--- .../HudsonAuthenticationEntryPoint.java | 27 +++++++------- .../security/ExceptionTranslationFilter.java | 2 +- 4 files changed, 57 insertions(+), 21 deletions(-) diff --git a/core/src/main/java/hudson/security/AccessDeniedException2.java b/core/src/main/java/hudson/security/AccessDeniedException2.java index 34324d979f..0f5da052b2 100644 --- a/core/src/main/java/hudson/security/AccessDeniedException2.java +++ b/core/src/main/java/hudson/security/AccessDeniedException2.java @@ -2,6 +2,10 @@ package hudson.security; import org.acegisecurity.AccessDeniedException; import org.acegisecurity.Authentication; +import org.acegisecurity.GrantedAuthority; + +import javax.servlet.http.HttpServletResponse; +import java.io.PrintWriter; /** * {@link AccessDeniedException} with more information. @@ -28,4 +32,36 @@ public class AccessDeniedException2 extends AccessDeniedException { this.authentication = authentication; this.permission = permission; } + + /** + * Reports the details of the access failure in HTTP headers to assist diagnosis. + */ + public void reportAsHeaders(HttpServletResponse rsp) { + rsp.addHeader("X-You-Are-Authenticated-As",authentication.getName()); + for (GrantedAuthority auth : authentication.getAuthorities()) { + rsp.addHeader("X-You-Are-In-Group",auth.getAuthority()); + } + rsp.addHeader("X-Required-Permission", permission.getId()); + for (Permission p=permission.impliedBy; p!=null; p=p.impliedBy) { + rsp.addHeader("X-Permission-Implied-By", p.getId()); + } + } + + /** + * Reports the details of the access failure. + * This method is similar to {@link #reportAsHeaders(HttpServletResponse)} for the intention + * but instead of using HTTP headers, this version is meant to go inside the payload. + */ + public void report(PrintWriter w) { + w.println("You are authenticated as: "+authentication.getName()); + w.println("Groups that you are in:"); + for (GrantedAuthority auth : authentication.getAuthorities()) { + w.println(" "+auth.getAuthority()); + } + + w.println("Permission you need to have (but didn't): "+permission.getId()); + for (Permission p=permission.impliedBy; p!=null; p=p.impliedBy) { + w.println(" ... which is implied by: "+p.getId()); + } + } } diff --git a/core/src/main/java/hudson/security/AccessDeniedHandlerImpl.java b/core/src/main/java/hudson/security/AccessDeniedHandlerImpl.java index eec3dab9cb..94497cf87c 100644 --- a/core/src/main/java/hudson/security/AccessDeniedHandlerImpl.java +++ b/core/src/main/java/hudson/security/AccessDeniedHandlerImpl.java @@ -26,19 +26,14 @@ package hudson.security; import jenkins.model.Jenkins; import org.acegisecurity.AccessDeniedException; import org.acegisecurity.ui.AccessDeniedHandler; -import org.kohsuke.stapler.Stapler; import org.kohsuke.stapler.WebApp; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; -import javax.servlet.ServletConfig; -import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; -import java.util.Enumeration; -import java.util.Vector; /** * Handles {@link AccessDeniedException} happened during request processing. @@ -47,12 +42,16 @@ import java.util.Vector; * @author Kohsuke Kawaguchi */ public class AccessDeniedHandlerImpl implements AccessDeniedHandler { - public void handle(ServletRequest request, ServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException { + public void handle(ServletRequest request, ServletResponse response, AccessDeniedException cause) throws IOException, ServletException { HttpServletRequest req = (HttpServletRequest) request; HttpServletResponse rsp = (HttpServletResponse) response; rsp.setStatus(HttpServletResponse.SC_FORBIDDEN); - req.setAttribute("exception",accessDeniedException); + req.setAttribute("exception",cause); + + if (cause instanceof AccessDeniedException2) { + ((AccessDeniedException2)cause).reportAsHeaders(rsp); + } WebApp.get(Jenkins.getInstance().servletContext).getSomeStapler() .invoke(req,rsp, Jenkins.getInstance(), "/accessDenied"); diff --git a/core/src/main/java/hudson/security/HudsonAuthenticationEntryPoint.java b/core/src/main/java/hudson/security/HudsonAuthenticationEntryPoint.java index bf07ea0543..64aaff2ba0 100644 --- a/core/src/main/java/hudson/security/HudsonAuthenticationEntryPoint.java +++ b/core/src/main/java/hudson/security/HudsonAuthenticationEntryPoint.java @@ -25,7 +25,6 @@ package hudson.security; import com.google.common.base.Strings; import org.acegisecurity.AuthenticationException; -import org.acegisecurity.GrantedAuthority; import org.acegisecurity.InsufficientAuthenticationException; import org.acegisecurity.ui.webapp.AuthenticationProcessingFilterEntryPoint; @@ -82,18 +81,12 @@ public class HudsonAuthenticationEntryPoint extends AuthenticationProcessingFilt rsp.setStatus(SC_FORBIDDEN); rsp.setContentType("text/html;charset=UTF-8"); + AccessDeniedException2 cause = null; // report the diagnosis information if possible if (reason instanceof InsufficientAuthenticationException) { if (reason.getCause() instanceof AccessDeniedException2) { - AccessDeniedException2 cause = (AccessDeniedException2) reason.getCause(); - rsp.addHeader("X-You-Are-Authenticated-As",cause.authentication.getName()); - for (GrantedAuthority auth : cause.authentication.getAuthorities()) { - rsp.addHeader("X-You-Are-In-Group",auth.getAuthority()); - } - rsp.addHeader("X-Required-Permission", cause.permission.getId()); - for (Permission p=cause.permission.impliedBy; p!=null; p=p.impliedBy) { - rsp.addHeader("X-Permission-Implied-By", p.getId()); - } + cause = (AccessDeniedException2) reason.getCause(); + cause.reportAsHeaders(rsp); } } @@ -108,9 +101,17 @@ public class HudsonAuthenticationEntryPoint extends AuthenticationProcessingFilt "" + "" + "" + - "" + - "Authentication required", loginForm - ); + "\n" + + "\n\n"+ + "Authentication required\n"+ + "\n\n"+ + ""); // Turn Off "Show Friendly HTTP Error Messages" Feature on the Server Side. // See http://support.microsoft.com/kb/294807 for (int i=0; i < 10; i++) diff --git a/core/src/main/java/jenkins/security/ExceptionTranslationFilter.java b/core/src/main/java/jenkins/security/ExceptionTranslationFilter.java index 458a2a41ee..f0a785db6d 100644 --- a/core/src/main/java/jenkins/security/ExceptionTranslationFilter.java +++ b/core/src/main/java/jenkins/security/ExceptionTranslationFilter.java @@ -220,7 +220,7 @@ public class ExceptionTranslationFilter implements Filter, InitializingBean { // existing Authentication is no longer considered valid SecurityContextHolder.getContext().setAuthentication(null); - authenticationEntryPoint.commence(httpRequest, (HttpServletResponse) response, reason); + authenticationEntryPoint.commence(httpRequest, response, reason); } public void setAccessDeniedHandler(AccessDeniedHandler accessDeniedHandler) { From 13ae5c793663976587a06d3dca585f7559173efb Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Sat, 29 Jun 2013 23:17:50 +1000 Subject: [PATCH 153/194] [JENKINS-15846] Deadlock during Maven builds Parsing POM step Do not use anymore shaded version of wagon-http as it we can control commons-logging version --- core/pom.xml | 1 - maven-plugin/pom.xml | 29 ++++++++++++++--------------- pom.xml | 5 +++++ 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index d30039e88a..b1e7d81ab1 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -468,7 +468,6 @@ THE SOFTWARE. commons-logging commons-logging - 1.1.1 com.sun.xml.txw2 diff --git a/maven-plugin/pom.xml b/maven-plugin/pom.xml index 6c98bbf356..d2ca22bbfc 100644 --- a/maven-plugin/pom.xml +++ b/maven-plugin/pom.xml @@ -218,21 +218,20 @@ THE SOFTWARE. org.apache.maven.wagon wagon-http ${wagonVersion} - shaded - - - org.apache.maven.wagon - wagon-http-shared4 - - - org.apache.httpcomponents - httpclient - - - org.apache.httpcomponents - httpcore - - + + + org.apache.httpcomponents + httpclient + 4.2.5 + + + org.apache.httpcomponents + httpcore + 4.2.4 + + + commons-logging + commons-logging org.apache.maven.wagon diff --git a/pom.xml b/pom.xml index 68a29a9213..0a9d80646d 100644 --- a/pom.xml +++ b/pom.xml @@ -213,6 +213,11 @@ THE SOFTWARE. jcl-over-slf4j ${slf4jVersion} + + commons-logging + commons-logging + 1.1.3 + From 2995c2869d5bdde84dd83976e5df1b63091acbf0 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Sat, 29 Jun 2013 23:20:14 +1000 Subject: [PATCH 154/194] [JENKINS-15846] add changelog entry --- changelog.html | 3 +++ 1 file changed, 3 insertions(+) diff --git a/changelog.html b/changelog.html index edd8974079..c2ae55a9fb 100644 --- a/changelog.html +++ b/changelog.html @@ -58,6 +58,9 @@ Upcoming changes
  • Node monitoring now happens concurrently across all the slaves, so it'll be affected less by problematic slaves. (issue 18438) +
  • + Deadlock during Maven builds Parsing POM step + (issue 15846) From 0256f0a74e9b3373fa9fa14ba32bf9cb99dd5ec3 Mon Sep 17 00:00:00 2001 From: ssogabe Date: Sun, 30 Jun 2013 21:58:09 +0900 Subject: [PATCH 155/194] fixed a javascript error in job configuration page. see https://github.com/jenkinsci/jenkins/commit/2ffece9d737f4a77ed4059c777948299daf22771#commitcomment-3526425 --- core/src/main/resources/lib/form/textarea/textarea.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/resources/lib/form/textarea/textarea.js b/core/src/main/resources/lib/form/textarea/textarea.js index f26c33f76e..fa9d4aef86 100644 --- a/core/src/main/resources/lib/form/textarea/textarea.js +++ b/core/src/main/resources/lib/form/textarea/textarea.js @@ -15,7 +15,7 @@ Behaviour.specify("TEXTAREA.codemirror", 'textarea', 0, function(e) { scroller.style.height = h+"px"; // the form needs to be populated before the "Apply" button - e.up('form').on("jenkins:apply",function() { + YAHOO.util.Event.on(e.up('form'), "jenkins:apply", function() { e.value = codemirror.getValue() }) }); From 59f0f32ff63d081475e5c691a8c932d98f688101 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Mon, 1 Jul 2013 17:30:48 -0700 Subject: [PATCH 156/194] no longer only about UTF-8 --- core/src/main/java/hudson/util/AtomicFileWriter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/hudson/util/AtomicFileWriter.java b/core/src/main/java/hudson/util/AtomicFileWriter.java index 85db633854..c951a735c6 100644 --- a/core/src/main/java/hudson/util/AtomicFileWriter.java +++ b/core/src/main/java/hudson/util/AtomicFileWriter.java @@ -33,7 +33,7 @@ import java.io.Writer; import java.nio.charset.Charset; /** - * Buffered {@link FileWriter} that uses UTF-8. + * Buffered {@link FileWriter} that supports atomic operations. * *

    * The write operation is atomic when used for overwriting; From 047233eb483de1bea5f1aba93156764373dc1cc8 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Mon, 1 Jul 2013 17:38:29 -0700 Subject: [PATCH 157/194] Don't do memory mapped file unless it's helpful. This will hopefully reduce the file locking problems on Windows. --- .../java/hudson/tasks/junit/SuiteResult.java | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/core/src/main/java/hudson/tasks/junit/SuiteResult.java b/core/src/main/java/hudson/tasks/junit/SuiteResult.java index 0b484cec9f..ed5965789a 100644 --- a/core/src/main/java/hudson/tasks/junit/SuiteResult.java +++ b/core/src/main/java/hudson/tasks/junit/SuiteResult.java @@ -26,6 +26,7 @@ package hudson.tasks.junit; import hudson.tasks.test.TestObject; import hudson.util.IOException2; import hudson.util.io.ParserConfigurator; +import org.apache.commons.io.FileUtils; import org.dom4j.Document; import org.dom4j.DocumentException; import org.dom4j.Element; @@ -209,14 +210,22 @@ public final class SuiteResult implements Serializable { File mavenOutputFile = new File(xmlReport.getParentFile(),m.group(1)+"-output.txt"); if (mavenOutputFile.exists()) { try { - RandomAccessFile raf = new RandomAccessFile(mavenOutputFile, "r"); - try { - ByteBuffer bb = raf.getChannel().map(FileChannel.MapMode.READ_ONLY, 0, mavenOutputFile.length()); - CharBuffer cb = Charset.defaultCharset().decode(bb); - stdout = CaseResult.possiblyTrimStdio(cases, keepLongStdio, cb); - } finally { - raf.close(); + CharSequence out; + long sz = mavenOutputFile.length(); + if (sz<64*1024) { + out = FileUtils.readFileToString(mavenOutputFile); + } else { + // memory mapped files have unpredictable release timing, which blocks file deletion on Windows. + // so don't do this unless there's a clear saving + RandomAccessFile raf = new RandomAccessFile(mavenOutputFile, "r"); + try { + ByteBuffer bb = raf.getChannel().map(FileChannel.MapMode.READ_ONLY, 0, sz); + out = Charset.defaultCharset().decode(bb); + } finally { + raf.close(); + } } + stdout = CaseResult.possiblyTrimStdio(cases, keepLongStdio, out); } catch (IOException e) { throw new IOException2("Failed to read "+mavenOutputFile,e); } From 14d980c4377dc703df8db76f192de19246a0266e Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Mon, 1 Jul 2013 17:57:17 -0700 Subject: [PATCH 158/194] [FIXED JENKINS-15382] Revisiting the fix. Avoid parsing the entire text by only looking at the tail portion. --- changelog.html | 3 + .../java/hudson/tasks/junit/CaseResult.java | 52 +++++++-- .../java/hudson/tasks/junit/SuiteResult.java | 17 +-- .../java/hudson/tasks/junit/TestResult.java | 9 +- core/src/main/java/hudson/util/TextFile.java | 82 ++++++++++++++ .../groovy/hudson/util/TextFileTest.groovy | 102 ++++++++++++++++++ test/src/test/resources/hudson/util/ascii.txt | 54 ++++++++++ 7 files changed, 296 insertions(+), 23 deletions(-) create mode 100644 test/src/test/groovy/hudson/util/TextFileTest.groovy create mode 100644 test/src/test/resources/hudson/util/ascii.txt diff --git a/changelog.html b/changelog.html index c2ae55a9fb..8ac2f7bd82 100644 --- a/changelog.html +++ b/changelog.html @@ -55,6 +55,9 @@ Upcoming changes

    What's new in 1.520 (2013/06/25)

    • From 5a547c91fb47b63a1b59c6466c2ecceb90992369 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Tue, 2 Jul 2013 08:51:45 -0700 Subject: [PATCH 166/194] Fixed an overzealous form validation --- core/src/main/java/hudson/model/Slave.java | 4 +++- test/src/test/groovy/hudson/model/SlaveTest.groovy | 13 +++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/hudson/model/Slave.java b/core/src/main/java/hudson/model/Slave.java index b907542185..fe06eb5807 100644 --- a/core/src/main/java/hudson/model/Slave.java +++ b/core/src/main/java/hudson/model/Slave.java @@ -405,7 +405,9 @@ public abstract class Slave extends Node implements Serializable { if(value.startsWith("\\\\") || value.startsWith("/net/")) return FormValidation.warning(Messages.Slave_Network_Mounted_File_System_Warning()); - if (!value.startsWith("\\") && !value.startsWith("/")) { + if (!value.contains("\\") && !value.startsWith("/")) { + // Unix-looking path that doesn't start with '/' + // TODO: detect Windows-looking relative path return FormValidation.error(Messages.Slave_the_remote_root_must_be_an_absolute_path()); } diff --git a/test/src/test/groovy/hudson/model/SlaveTest.groovy b/test/src/test/groovy/hudson/model/SlaveTest.groovy index 56d912096f..2de7c40f49 100644 --- a/test/src/test/groovy/hudson/model/SlaveTest.groovy +++ b/test/src/test/groovy/hudson/model/SlaveTest.groovy @@ -24,10 +24,14 @@ package hudson.model import hudson.slaves.DumbSlave +import hudson.util.FormValidation import org.jvnet.hudson.test.GroovyHudsonTestCase import org.apache.commons.io.IOUtils import hudson.slaves.JNLPLauncher +import static hudson.util.FormValidation.Kind.ERROR +import static hudson.util.FormValidation.Kind.WARNING + /** * * @@ -78,4 +82,13 @@ public class SlaveTest extends GroovyHudsonTestCase { con.outputStream.close(); IOUtils.copy(con.inputStream,System.out) } + + public void testRemoteFsCheck() { + def d = jenkins.getDescriptorByType(DumbSlave.DescriptorImpl.class) + assert d.doCheckRemoteFS("c:\\")==FormValidation.ok(); + assert d.doCheckRemoteFS("/tmp")==FormValidation.ok(); + assert d.doCheckRemoteFS("relative/path").kind==ERROR; + assert d.doCheckRemoteFS("/net/foo/bar/zot").kind==WARNING; + assert d.doCheckRemoteFS("\\\\machine\\folder\\foo").kind==WARNING; + } } From f014d7ac9c5086e2218ae7adeb3013e8f8119fae Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Tue, 2 Jul 2013 14:25:00 -0700 Subject: [PATCH 167/194] Pushing the dependency computation down to another thread. --- .../main/java/hudson/model/AbstractItem.java | 4 ++-- .../java/hudson/model/AbstractProject.java | 2 +- .../java/hudson/model/ItemGroupMixIn.java | 6 +++--- .../main/java/hudson/tasks/Fingerprinter.java | 2 +- core/src/main/java/jenkins/model/Jenkins.java | 19 +++++++++++++++++++ .../main/java/hudson/maven/MavenModule.java | 2 +- 6 files changed, 27 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/hudson/model/AbstractItem.java b/core/src/main/java/hudson/model/AbstractItem.java index 018049a50b..518234e652 100644 --- a/core/src/main/java/hudson/model/AbstractItem.java +++ b/core/src/main/java/hudson/model/AbstractItem.java @@ -513,7 +513,7 @@ public abstract class AbstractItem extends Actionable implements Item, HttpDelet // ignore } - Jenkins.getInstance().rebuildDependencyGraph(); + Jenkins.getInstance().rebuildDependencyGraphAsync(); } /** @@ -592,7 +592,7 @@ public abstract class AbstractItem extends Actionable implements Item, HttpDelet } finally { Items.updatingByXml.set(false); } - Jenkins.getInstance().rebuildDependencyGraph(); + Jenkins.getInstance().rebuildDependencyGraphAsync(); // if everything went well, commit this new version out.commit(); diff --git a/core/src/main/java/hudson/model/AbstractProject.java b/core/src/main/java/hudson/model/AbstractProject.java index 9de5a1f6f8..20d42e7c19 100644 --- a/core/src/main/java/hudson/model/AbstractProject.java +++ b/core/src/main/java/hudson/model/AbstractProject.java @@ -772,7 +772,7 @@ public abstract class AbstractProject

      ,R extends A Jenkins.getInstance().getQueue().scheduleMaintenance(); // this is to reflect the upstream build adjustments done above - Jenkins.getInstance().rebuildDependencyGraph(); + Jenkins.getInstance().rebuildDependencyGraphAsync(); } /** diff --git a/core/src/main/java/hudson/model/ItemGroupMixIn.java b/core/src/main/java/hudson/model/ItemGroupMixIn.java index 28f2246854..b52b4117a7 100644 --- a/core/src/main/java/hudson/model/ItemGroupMixIn.java +++ b/core/src/main/java/hudson/model/ItemGroupMixIn.java @@ -213,7 +213,7 @@ public abstract class ItemGroupMixIn { add(result); ItemListener.fireOnCopied(src,result); - Hudson.getInstance().rebuildDependencyGraph(); + Jenkins.getInstance().rebuildDependencyGraphAsync(); return result; } @@ -239,7 +239,7 @@ public abstract class ItemGroupMixIn { add(result); ItemListener.fireOnCreated(result); - Jenkins.getInstance().rebuildDependencyGraph(); + Jenkins.getInstance().rebuildDependencyGraphAsync(); return result; } catch (IOException e) { @@ -270,7 +270,7 @@ public abstract class ItemGroupMixIn { } item.save(); add(item); - Jenkins.getInstance().rebuildDependencyGraph(); + Jenkins.getInstance().rebuildDependencyGraphAsync(); if (notify) ItemListener.fireOnCreated(item); diff --git a/core/src/main/java/hudson/tasks/Fingerprinter.java b/core/src/main/java/hudson/tasks/Fingerprinter.java index 21317f5f05..f39828708b 100644 --- a/core/src/main/java/hudson/tasks/Fingerprinter.java +++ b/core/src/main/java/hudson/tasks/Fingerprinter.java @@ -136,7 +136,7 @@ public class Fingerprinter extends Recorder implements Serializable, DependencyD build.getActions().add(new FingerprintAction(build,record)); if (enableFingerprintsInDependencyGraph) { - Jenkins.getInstance().rebuildDependencyGraph(); + Jenkins.getInstance().rebuildDependencyGraphAsync(); } } catch (IOException e) { e.printStackTrace(listener.error(Messages.Fingerprinter_Failed())); diff --git a/core/src/main/java/jenkins/model/Jenkins.java b/core/src/main/java/jenkins/model/Jenkins.java index e155381e24..6e7c388cec 100755 --- a/core/src/main/java/jenkins/model/Jenkins.java +++ b/core/src/main/java/jenkins/model/Jenkins.java @@ -3601,6 +3601,25 @@ public class Jenkins extends AbstractCIBase implements ModifiableTopLevelItemGro dependencyGraph = graph; } + /** + * Rebuilds the dependency map asynchronously. + * + *

      + * This would keep the UI thread more responsive and helps avoid the deadlocks, + * as dependency graph recomputation tends to touch a lot of other things. + * + * @since 1.522 + */ + public Future rebuildDependencyGraphAsync() { + return MasterComputer.threadPoolForRemoting.submit(new java.util.concurrent.Callable() { + @Override + public DependencyGraph call() throws Exception { + rebuildDependencyGraph(); + return dependencyGraph; + } + }); + } + public DependencyGraph getDependencyGraph() { return dependencyGraph; } diff --git a/maven-plugin/src/main/java/hudson/maven/MavenModule.java b/maven-plugin/src/main/java/hudson/maven/MavenModule.java index 190a44ae9e..f29863364a 100644 --- a/maven-plugin/src/main/java/hudson/maven/MavenModule.java +++ b/maven-plugin/src/main/java/hudson/maven/MavenModule.java @@ -649,7 +649,7 @@ public class MavenModule extends AbstractMavenProject im goals = Util.fixEmpty(req.getParameter("goals").trim()); // dependency setting might have been changed by the user, so rebuild. - Jenkins.getInstance().rebuildDependencyGraph(); + Jenkins.getInstance().rebuildDependencyGraphAsync(); } @Override From 7facc7733c7040536d4074a2c5805b75ee1d8f35 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Tue, 2 Jul 2013 15:44:24 -0700 Subject: [PATCH 168/194] [FIXED JENKINS-18589] Use DescribableList to handle the copy-on-write semantics correctly. The vector class just doesn't cut it, and we've been setting a new value to this field, which will violates all sorts of the concurrent programming practice. This change has the nice side effect of removing {{class="vector"}} from the persisted XML. A test is added to make sure we can still read back such an XML. --- changelog.html | 3 ++ .../java/hudson/matrix/MatrixProject.java | 2 +- .../java/hudson/model/AbstractProject.java | 19 +++++---- core/src/main/java/hudson/model/Project.java | 27 +++++++----- .../hudson/maven/AbstractMavenProject.java | 2 +- .../hudson/model/AbstractProjectTest.groovy | 41 +++++++++---------- .../AbstractProjectTest/vectorTriggers.xml | 8 ++++ 7 files changed, 62 insertions(+), 40 deletions(-) create mode 100644 test/src/test/resources/hudson/model/AbstractProjectTest/vectorTriggers.xml diff --git a/changelog.html b/changelog.html index 8ac2f7bd82..d07943c6af 100644 --- a/changelog.html +++ b/changelog.html @@ -55,6 +55,9 @@ Upcoming changes