Skip to content
Permalink
Browse files
[JENKINS-17096] Convert OS specific separators upfront in ConfigSpec
Raw config spec may have been defined with different OS separators,
leading to issues when comparing them.
  • Loading branch information
Vlatombe committed Jul 24, 2013
1 parent f369293 commit 89001f301e1983f7ab165fde1c8c4bb64d02ee57
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 2 deletions.
@@ -39,7 +39,7 @@ public class ConfigSpec {

public ConfigSpec(String raw, boolean isUnix) {
Validate.notNull(raw);
this.raw = raw;
this.raw = PathUtil.convertPathForOS(raw, isUnix);
this.isUnix = isUnix;
}

@@ -64,7 +64,7 @@ public boolean equals(Object obj) {

public Set<String> getLoadRules() {
Set<String> rules = new HashSet<String>();
for (String row : raw.split("[\\r\\n]+")) {
for (String row : StringUtils.split(raw, PathUtil.newLineForOS(isUnix))) {
String trimmedRow = row.trim();
if (trimmedRow.startsWith("load")) {
String rule = row.trim().substring("load".length()).trim();
@@ -0,0 +1,57 @@
package hudson.plugins.clearcase;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.io.IOException;
import java.util.Set;

import hudson.util.IOUtils;

import org.junit.Test;

public class ConfigSpecTest {

@Test
public void testConfigSpecDifferentOS() {
ConfigSpec cs1 = new ConfigSpec("element /MyVOB/... .../MyBranch/LATEST", true);
ConfigSpec cs2 = new ConfigSpec("element \\MyVOB\\... ...\\MyBranch\\LATEST", true);
assertEquals(cs1, cs2);
}

@Test
public void testExtractLoadRulesUnix() throws IOException {
String rawCs = IOUtils.toString(getClass().getResourceAsStream("ct-catcs-2-CRLF.log"));
ConfigSpec cs = new ConfigSpec(rawCs, true);
Set<String> loadRules = cs.getLoadRules();
assertEquals(1, loadRules.size());
assertEquals("/a/b", loadRules.iterator().next());
}

@Test
public void testLineEndings() throws IOException {
String rawCs1 = IOUtils.toString(getClass().getResourceAsStream("ct-catcs-2-LF.log"));
String rawCs2 = IOUtils.toString(getClass().getResourceAsStream("ct-catcs-2-CRLF.log"));
ConfigSpec cs1 = new ConfigSpec(rawCs1, true);
ConfigSpec cs2 = new ConfigSpec(rawCs2, true);
assertEquals(cs1, cs2);
}

@Test
public void testExtractLoadRulesWindows() throws IOException {
String rawCs = IOUtils.toString(getClass().getResourceAsStream("ct-catcs-2-CRLF.log"));
ConfigSpec cs = new ConfigSpec(rawCs, false);
Set<String> loadRules = cs.getLoadRules();
assertEquals(1, loadRules.size());
assertEquals("\\a\\b", loadRules.iterator().next());
}

@Test
public void testStripLoadRulesWindows() throws IOException {
String rawCs = IOUtils.toString(getClass().getResourceAsStream("ct-catcs-2-CRLF.log"));
ConfigSpec cs = new ConfigSpec(rawCs, false);
cs = cs.stripLoadRules();
assertTrue(cs.getLoadRules().isEmpty());
}

}
@@ -0,0 +1,5 @@
element * CHECKEDOUT
element * ...\rel2_bugfix\LATEST
element * \main\LATEST -mkbranch rel2_bugfix

load \a\b
@@ -0,0 +1,5 @@
element * CHECKEDOUT
element * .../rel2_bugfix/LATEST
element * /main/LATEST -mkbranch rel2_bugfix

load /a/b

0 comments on commit 89001f3

Please sign in to comment.