From 279e11b0821d2d326c0010b302aa271318afced9 Mon Sep 17 00:00:00 2001 From: srice01 Date: Fri, 28 Mar 2014 11:05:30 +0000 Subject: [PATCH] [FIXED JENKINS-6746] --- src/main/java/hudson/scm/SubversionSCM.java | 5 ++++ .../hudson/scm/SubversionSCMUnitTest.java | 26 ++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/main/java/hudson/scm/SubversionSCM.java b/src/main/java/hudson/scm/SubversionSCM.java index 938b39bf1..f01b5416a 100755 --- a/src/main/java/hudson/scm/SubversionSCM.java +++ b/src/main/java/hudson/scm/SubversionSCM.java @@ -716,6 +716,11 @@ public void buildEnvVars(AbstractBuild build, Map env) { } } + // get the maximum revision which attempts to resolve JENKINS-6746 + Long maxrev = new Long(0); + for (Long rev : revisions.values()) if (rev>maxrev) maxrev=rev; + env.put("SVN_MAX_REVISION",maxrev.toString()); + } catch (IOException e) { LOGGER.log(WARNING, "error building environment variables", e); } diff --git a/src/test/java/hudson/scm/SubversionSCMUnitTest.java b/src/test/java/hudson/scm/SubversionSCMUnitTest.java index 92b092928..cf455ba15 100644 --- a/src/test/java/hudson/scm/SubversionSCMUnitTest.java +++ b/src/test/java/hudson/scm/SubversionSCMUnitTest.java @@ -102,7 +102,31 @@ public void shouldSetEnvironmentVariablesWithMultipleSvnModules() throws IOExcep assertThat(envVars.get("SVN_URL_2"), is("/remotepath2")); assertThat(envVars.get("SVN_REVISION_2"), is("42")); } - + + @SuppressWarnings("deprecation") + @Test + public void shouldSetEnvironmentVariablesMaximumRevision() throws IOException { + // GIVEN an scm with a 2 module locations + SubversionSCM scm = mockSCMForBuildEnvVars(); + + ModuleLocation[] singleLocation = new ModuleLocation[] {new ModuleLocation("/remotepath", "")}; + when(scm.getLocations(any(EnvVars.class), any(AbstractBuild.class))).thenReturn(singleLocation); + + Map revisions = new HashMap(); + revisions.put("/remotepath", 4711L); + revisions.put("/remotepath2", 42L); + revisions.put("/remotepath3", 9920L); + when(scm.parseSvnRevisionFile(any(AbstractBuild.class))).thenReturn(revisions); + + // WHEN envVars are build + AbstractBuild build = mock(AbstractBuild.class); + Map envVars = new HashMap(); + scm.buildEnvVars(build, envVars); + + // THEN: we have the SVN_MAX_REVISION var + assertThat(envVars.get("SVN_MAX_REVISION"), is("9920")); + } + private SubversionSCM mockSCMForBuildEnvVars() { SubversionSCM scm = mock(SubversionSCM.class); doCallRealMethod().when(scm).buildEnvVars(any(AbstractBuild.class), anyMapOf(String.class, String.class));