Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FIXED JENKINS-13186] Perform environmental expansion on module name …
…fields
  • Loading branch information
mc1arke committed Sep 4, 2012
1 parent 536e5a9 commit bfc1a2d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
29 changes: 15 additions & 14 deletions src/main/java/hudson/scm/AbstractCvs.java
Expand Up @@ -79,15 +79,15 @@ protected boolean checkout(CvsRepository[] repositories, boolean flatten, FilePa
for (CvsRepositoryItem item : repository.getRepositoryItems()) {

for (CvsModule cvsModule : item.getModules()) {

boolean localSubModule = cvsModule.getCheckoutName().contains("/");
int lastSlash = cvsModule.getCheckoutName().lastIndexOf("/");
final String checkoutName = envVars.expand(cvsModule.getCheckoutName());
boolean localSubModule = checkoutName.contains("/");
int lastSlash = checkoutName.lastIndexOf("/");

final FilePath targetWorkspace = flatten ? workspace.getParent() :
localSubModule ? workspace.child(cvsModule.getCheckoutName().substring(0, lastSlash)) : workspace;
localSubModule ? workspace.child(checkoutName.substring(0, lastSlash)) : workspace;

final String moduleName = flatten ? workspace.getName() :
localSubModule ? cvsModule.getCheckoutName().substring(lastSlash + 1) : cvsModule.getCheckoutName();
localSubModule ? checkoutName.substring(lastSlash + 1) : checkoutName;

final FilePath module = targetWorkspace.child(moduleName);

Expand Down Expand Up @@ -184,7 +184,7 @@ protected boolean checkout(CvsRepository[] repositories, boolean flatten, FilePa
checkoutCommand.setCheckoutDirectory(moduleName);

// and specify which module to load
checkoutCommand.setModule(cvsModule.getRemoteName());
checkoutCommand.setModule(envVars.expand(cvsModule.getRemoteName()));

if (!perform(checkoutCommand, targetWorkspace, listener, repository, moduleName, envVars)) {
return false;
Expand Down Expand Up @@ -548,7 +548,7 @@ private CvsLog getRemoteLogForModule(final CvsRepository repository, final CvsRe
}

// tell CVS which module we're logging
rlogCommand.setModule(module.getRemoteName());
rlogCommand.setModule(envVars.expand(module.getRemoteName()));

// ignore headers for files that aren't in the current change-set
rlogCommand.setSuppressHeader(true);
Expand Down Expand Up @@ -651,7 +651,7 @@ protected List<CVSChangeLogSet.CVSChangeLog> calculateChangeLog(final Date start
}

protected void postCheckout(AbstractBuild<?, ?> build, File changelogFile, CvsRepository[] repositories,
FilePath workspace, BuildListener listener, boolean flatten)
FilePath workspace, BuildListener listener, boolean flatten, EnvVars envVars)
throws IOException, InterruptedException {
// build change log
final AbstractBuild<?, ?> lastCompleteBuild = build.getPreviousBuiltBuild();
Expand All @@ -666,7 +666,7 @@ protected void postCheckout(AbstractBuild<?, ?> build, File changelogFile, CvsRe
}

// add the current workspace state as an action
build.getActions().add(new CvsRevisionState(calculateWorkspaceState(workspace, repositories, flatten)));
build.getActions().add(new CvsRevisionState(calculateWorkspaceState(workspace, repositories, flatten, envVars)));

// add the tag action to the build
build.getActions().add(new CvsTagAction(build, this));
Expand Down Expand Up @@ -718,15 +718,15 @@ private void cleanup(File directory, AdminHandler adminHandler) throws IOExcepti

private Map<CvsRepository, List<CvsFile>> calculateWorkspaceState(final FilePath workspace,
final CvsRepository[] repositories,
final boolean flatten)
final boolean flatten, final EnvVars envVars)
throws IOException, InterruptedException {
Map<CvsRepository, List<CvsFile>> workspaceState = new HashMap<CvsRepository, List<CvsFile>>();

for (CvsRepository repository : repositories) {
List<CvsFile> cvsFiles = new ArrayList<CvsFile>();
for (CvsRepositoryItem item : repository.getRepositoryItems()) {
for (CvsModule module : item.getModules()) {
cvsFiles.addAll(getCvsFiles(workspace, module, flatten));
cvsFiles.addAll(getCvsFiles(workspace, module, flatten, envVars));
}
}
workspaceState.put(repository, cvsFiles);
Expand All @@ -735,13 +735,14 @@ private Map<CvsRepository, List<CvsFile>> calculateWorkspaceState(final FilePath
return workspaceState;
}

private List<CvsFile> getCvsFiles(final FilePath workspace, final CvsModule module, final boolean flatten)
private List<CvsFile> getCvsFiles(final FilePath workspace, final CvsModule module, final boolean flatten,
final EnvVars envVars)
throws IOException, InterruptedException {
FilePath targetWorkspace;
if (flatten) {
targetWorkspace = workspace;
} else {
targetWorkspace = workspace.child(module.getCheckoutName());
targetWorkspace = workspace.child(envVars.expand(module.getCheckoutName()));
}

return targetWorkspace.act(new FilePath.FileCallable<List<CvsFile>>() {
Expand All @@ -757,7 +758,7 @@ public List<CvsFile> invoke(final File moduleLocation, final VirtualChannel chan
* rlog command (which wouldn't be possible if we use the local
* module name on a module that had been checked out as an alias
*/
return buildFileList(moduleLocation, module.getRemoteName());
return buildFileList(moduleLocation, envVars.expand(module.getRemoteName()));
}

public List<CvsFile> buildFileList(final File moduleLocation, final String prefix) throws IOException {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/hudson/scm/CVSSCM.java
Expand Up @@ -320,7 +320,7 @@ public boolean checkout(final AbstractBuild<?, ?> build, final Launcher launcher
return false;
}

postCheckout(build, changelogFile, getRepositories(), workspace, listener, isFlatten());
postCheckout(build, changelogFile, getRepositories(), workspace, listener, isFlatten(), build.getEnvironment(listener));

return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/hudson/scm/CvsProjectset.java
Expand Up @@ -127,7 +127,7 @@ build, dateStamp, isPruneEmptyDirectories(), isCleanOnFailedUpdate(), listener))
return false;
}

postCheckout(build, changelogFile, getAllRepositories(workspace), workspace, listener, isFlatten());
postCheckout(build, changelogFile, getAllRepositories(workspace), workspace, listener, isFlatten(), build.getEnvironment(listener));

return true;
}
Expand Down

0 comments on commit bfc1a2d

Please sign in to comment.