Skip to content

Commit

Permalink
[FIXED JENKINS-12113] local module directory is not expanded with Env…
Browse files Browse the repository at this point in the history
…Vars
  • Loading branch information
kutzi committed Feb 12, 2012
1 parent 15a2394 commit c96f849
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 1 deletion.
65 changes: 64 additions & 1 deletion src/main/java/hudson/scm/SubversionSCM.java
Expand Up @@ -65,6 +65,7 @@
import hudson.scm.subversion.WorkspaceUpdaterDescriptor;
import hudson.util.EditDistance;
import hudson.util.FormValidation;
import hudson.util.LogTaskListener;
import hudson.util.MultipartFormDataParser;
import hudson.util.Scrambler;
import hudson.util.Secret;
Expand Down Expand Up @@ -161,7 +162,6 @@
import com.trilead.ssh2.DebugLogger;
import com.trilead.ssh2.SCPClient;
import com.trilead.ssh2.crypto.Base64;
import org.tmatesoft.svn.core.internal.util.SVNEncodingUtil;

/**
* Subversion SCM.
Expand Down Expand Up @@ -1369,13 +1369,41 @@ public DescriptorImpl getDescriptor() {
return (DescriptorImpl)super.getDescriptor();
}

/**
* @deprecated
*/
@Override
@Deprecated
public FilePath getModuleRoot(FilePath workspace) {
if (getLocations().length > 0)
return workspace.child(getLocations()[0].getLocalDir());
return workspace;
}

@Override
public FilePath getModuleRoot(FilePath workspace, @SuppressWarnings("rawtypes") AbstractBuild build) {
if (build == null) {
return getModuleRoot(workspace);
}

// TODO: can't I get the build listener here?
TaskListener listener = new LogTaskListener(LOGGER, WARNING);
final EnvVars env;
try {
env = build.getEnvironment(listener);
} catch (IOException e) {
throw new RuntimeException(e);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new RuntimeException(e);
}

if (getLocations().length > 0)
return _getModuleRoot(workspace, getLocations()[0].getLocalDir(), env);
return workspace;
}

@Deprecated
@Override
public FilePath[] getModuleRoots(FilePath workspace) {
final ModuleLocation[] moduleLocations = getLocations();
Expand All @@ -1388,6 +1416,41 @@ public FilePath[] getModuleRoots(FilePath workspace) {
}
return new FilePath[] { getModuleRoot(workspace) };
}

@Override
public FilePath[] getModuleRoots(FilePath workspace, @SuppressWarnings("rawtypes") AbstractBuild build) {
if (build == null) {
return getModuleRoots(workspace);
}

// TODO: can't I get the build listener here?
TaskListener listener = new LogTaskListener(LOGGER, WARNING);
final EnvVars env;
try {
env = build.getEnvironment(listener);
} catch (IOException e) {
throw new RuntimeException(e);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new RuntimeException(e);
}

final ModuleLocation[] moduleLocations = getLocations();
if (moduleLocations.length > 0) {
FilePath[] moduleRoots = new FilePath[moduleLocations.length];
for (int i = 0; i < moduleLocations.length; i++) {
moduleRoots[i] = _getModuleRoot(workspace, moduleLocations[i].getLocalDir(), env);
}
return moduleRoots;
}
return new FilePath[] { getModuleRoot(workspace, build) };

}

FilePath _getModuleRoot(FilePath workspace, String localDir, EnvVars env) {
return workspace.child(
env.expand(localDir));
}

private static String getLastPathComponent(String s) {
String[] tokens = s.split("/");
Expand Down
34 changes: 34 additions & 0 deletions src/test/java/hudson/scm/SubversionSCMUnitTest.java
@@ -0,0 +1,34 @@
package hudson.scm;

import hudson.EnvVars;
import hudson.FilePath;
import hudson.remoting.VirtualChannel;

import org.junit.Assert;
import org.junit.Test;
import org.jvnet.hudson.test.Bug;

/**
* Unit tests for {@link SubversionSCM}.
*
* ({@link SubversionSCMTest} ist more an integration test)
*
* @author kutzi
*/
public class SubversionSCMUnitTest {

@Test
@Bug(12113)
public void testLocalDirectoryIsExpandedWithEnvVars() {
FilePath root = new FilePath((VirtualChannel)null, "root");

EnvVars envVars = new EnvVars();
envVars.put("BRANCH", "test");

SubversionSCM scm = new SubversionSCM("dummyUrl");

FilePath resolvedRoot = scm._getModuleRoot(root, "$BRANCH/someMorePath", envVars);

Assert.assertEquals("root/test/someMorePath", resolvedRoot.getRemote());
}
}

0 comments on commit c96f849

Please sign in to comment.