Skip to content

Commit

Permalink
[JENKINS-17096] Convert OS specific separators upfront in ConfigSpec
Browse files Browse the repository at this point in the history
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 89001f3
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/main/java/hudson/plugins/clearcase/ConfigSpec.java
Expand Up @@ -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;
}

Expand All @@ -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();
Expand Down
57 changes: 57 additions & 0 deletions src/test/java/hudson/plugins/clearcase/ConfigSpecTest.java
@@ -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
5 changes: 5 additions & 0 deletions src/test/resources/hudson/plugins/clearcase/ct-catcs-2-LF.log
@@ -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.