Skip to content

Commit

Permalink
Change abbreviation characters
Browse files Browse the repository at this point in the history
While ... is valid in Windows, .NET does not recognize this as a valid path.  As a result, tools like msbuild will fail.  After abbreviation, change ... to --- to avoid issues

Also fix tests on Windows
Windows has \ as the path separator character, and a significantly shorter MAX_PATH.  Set the cached path length long enough that a test that doesn't want the path to be shortened passes.
Also replace / with \ on Windows (and vice versa for non-Windows platforms) when comparing paths.
  • Loading branch information
mmitche committed Sep 23, 2016
1 parent 3773583 commit 1920cb6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ public FilePath locate(TopLevelItem item, Node node) {
if (usabeSpace > BUILD_PATH_LENGTH) return null; // There is plenty of room

String itemName = StringUtils.abbreviate(item.getName(), 0, 16);
// Replace the ellipsis with dashes to avoid problems with certain build systems
itemName = itemName.replace("...", "---");
final String digest = Util.getDigestOf(item.getFullName()).substring(0, 8);
FilePath newPath = slave.getWorkspaceRoot().child(itemName + digest);

Expand Down
18 changes: 15 additions & 3 deletions src/test/java/org/jenkinsci/plugins/shortwspath/LocatorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,19 @@
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.MockFolder;
import hudson.Functions;

public class LocatorTest {

@Rule public JenkinsRule j = new JenkinsRule();
private String formatPath(String inputPath) {
if(Functions.isWindows()) {
return inputPath.replace("/", "\\");
}
else {
return inputPath.replace("\\", "/");
}
}

@Test
public void doNothingIfThereIsEnoughRoom() throws Exception {
Expand All @@ -54,8 +63,11 @@ public void doNothingIfThereIsEnoughRoom() throws Exception {
FreeStyleProject p = f.createProject(FreeStyleProject.class, "and_a_project_in_it");
p.setAssignedNode(s);

// Not enough for anything.
setMaxPathLength(s, 4096);

FreeStyleBuild b = p.scheduleBuild2(0).get();
assertThat(b.getWorkspace().getRemote(), equalTo(s.getRootPath() + "/workspace/" + p.getFullName()));
assertThat(b.getWorkspace().getRemote(), equalTo(formatPath(s.getRootPath() + "/workspace/" + p.getFullName())));
}

@Test
Expand All @@ -70,7 +82,7 @@ public void doNothingIfItWillNotShortenThePath() throws Exception {
setMaxPathLength(s, 1);

FreeStyleBuild b = p.scheduleBuild2(0).get();
assertThat(b.getWorkspace().getRemote(), equalTo(s.getRootPath() + "/workspace/" + p.getFullName()));
assertThat(b.getWorkspace().getRemote(), equalTo(formatPath(s.getRootPath() + "/workspace/" + p.getFullName())));
}

@Test
Expand All @@ -86,7 +98,7 @@ public void unwrapFolders() throws Exception {

FreeStyleBuild b = p.scheduleBuild2(0).get();
String buildWs = b.getWorkspace().getRemote();
String wsDir = s.getRootPath() + "/workspace/";
String wsDir = formatPath(s.getRootPath() + "/workspace/");
assertThat(buildWs, startsWith(wsDir + "and_a_pro"));
assertThat(buildWs, buildWs.length(), equalTo(wsDir.length() + 24));
}
Expand Down

0 comments on commit 1920cb6

Please sign in to comment.