Skip to content
Permalink
Browse files
Merge pull request #54 from synopsys-arc-oss/jenkins_20344_fix
[FIXED JENKINS-20344] - SVN_REVISION is not exported if server url ends ...
  • Loading branch information
kutzi committed Oct 30, 2013
2 parents a486adf + 6101fd8 commit 3e941d8dc920ab26cb1fdc2eef05f906a95f46ad
Showing with 85 additions and 3 deletions.
  1. +11 −3 src/main/java/hudson/scm/subversion/SvnHelper.java
  2. +74 −0 src/test/java/hudson/scm/SvnHelperTest.java
@@ -8,20 +8,28 @@
* @author kutzi
*/
public class SvnHelper {
private static final String REGEX_END_SLASHES = "\\/*$";

/**
* Cuts off any optional '@revisionnr' from the end of the url string.
* Cuts off any optional '@revisionnr' and slashes from the end of the url string.
*/
public static String getUrlWithoutRevision(String remoteUrlPossiblyWithRevision) {
int idx = remoteUrlPossiblyWithRevision.lastIndexOf('@');
int slashIdx = remoteUrlPossiblyWithRevision.lastIndexOf('/');

// Substitute optional '@revisionnr'
String substititedString = remoteUrlPossiblyWithRevision;
if (idx > 0 && idx > slashIdx) {
String n = remoteUrlPossiblyWithRevision.substring(idx + 1);
SVNRevision r = SVNRevision.parse(n);
if ((r != null) && (r.isValid())) {
return remoteUrlPossiblyWithRevision.substring(0, idx);
substititedString = remoteUrlPossiblyWithRevision.substring(0, idx);
}
}
return remoteUrlPossiblyWithRevision;

// Substitute slashes at the end
substititedString = substititedString.replaceAll(REGEX_END_SLASHES, "");

return substititedString;
}
}
@@ -0,0 +1,74 @@
/*
* The MIT License
*
* Copyright (c) 2013, Synopsys Inc., Oleg Nenashev
*
* 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 hudson.scm;

import hudson.scm.subversion.SvnHelper;
import org.junit.Assert;
import org.junit.Test;
import org.jvnet.hudson.test.Bug;

/**
* Contains tests for {@link SvnHelper}.
* @author Oleg Nenashev <nenashev@synopsys.com>, Synopsys Inc.
* @since TODO
*/
public class SvnHelperTest {

private static final String URL_PREFIX = "http://very/complex/path/to/SVN";

private void testGetUrlWithoutRevision(String serverURL, String expected) {
String value = SvnHelper.getUrlWithoutRevision(serverURL);
Assert.assertEquals("URL w/o revision differs from expected value", expected, value);
}

private void testGetUrlWithoutRevision(String serverUrl) {
testGetUrlWithoutRevision(serverUrl, URL_PREFIX);
}

@Test
public void testGetUrlWithoutRevision_minimal() {
testGetUrlWithoutRevision(URL_PREFIX);
}

@Test
public void testGetUrlWithoutRevision_withSuffix() {
testGetUrlWithoutRevision(URL_PREFIX+"@HEAD");
testGetUrlWithoutRevision(URL_PREFIX+"@100500");
testGetUrlWithoutRevision(URL_PREFIX+"@LABEL",URL_PREFIX+"@LABEL"); // Actually, it is not a revision
}

@Test
public void testGetUrlWithoutRevision_withEndingSlash() {
testGetUrlWithoutRevision(URL_PREFIX+"/");
testGetUrlWithoutRevision(URL_PREFIX+"//");
testGetUrlWithoutRevision(URL_PREFIX+"////////");
}

@Test
@Bug(20344)
public void testGetUrlWithoutRevision_withSlashAndSuffix() {
testGetUrlWithoutRevision(URL_PREFIX+"/@HEAD");
testGetUrlWithoutRevision(URL_PREFIX+"//@HEAD");
}
}

0 comments on commit 3e941d8

Please sign in to comment.