Skip to content
Permalink
Browse files

[FIXED JENKINS-12113] local module directory is not expanded with Env…

…Vars
  • Loading branch information
kutzi
kutzi committed Feb 12, 2012
1 parent 15a2394 commit c96f849400174ca476650f2e1b13cd3993027c3b
Showing with 98 additions and 1 deletion.
  1. +64 −1 src/main/java/hudson/scm/SubversionSCM.java
  2. +34 −0 src/test/java/hudson/scm/SubversionSCMUnitTest.java
@@ -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;
@@ -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.
@@ -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();
@@ -1388,6 +1416,41 @@ public FilePath getModuleRoot(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("/");
@@ -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.
You can’t perform that action at this time.