Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FIXED JENKINS-13764] Use same location as workspace for post build rlog
  • Loading branch information
Michael Clarke committed Oct 20, 2013
1 parent 78bb5fb commit 2c0d618
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 40 deletions.
73 changes: 43 additions & 30 deletions src/main/java/hudson/scm/AbstractCvs.java
Expand Up @@ -455,8 +455,8 @@ public SCMRevisionState calcRevisionsFromBuild(final AbstractBuild<?, ?> build,


protected PollingResult compareRemoteRevisionWith(final AbstractProject<?, ?> project, final Launcher launcher,
final TaskListener listener, final SCMRevisionState baseline,
final CvsRepository[] repositories)
final FilePath workspace, final TaskListener listener,
final SCMRevisionState baseline, final CvsRepository[] repositories)
throws IOException, InterruptedException {

// No previous build? everything has changed
Expand Down Expand Up @@ -502,7 +502,7 @@ protected PollingResult compareRemoteRevisionWith(final AbstractProject<?, ?> pr

// get the list of current changed files in this repository
final List<CvsFile> changes = calculateRepositoryState(project.getLastCompletedBuild().getTime(),
currentPollDate, repository, listener, envVars);
currentPollDate, repository, listener, envVars, workspace);

final List<CvsFile> remoteFiles = remoteState.get(repository);

Expand Down Expand Up @@ -592,13 +592,13 @@ protected PollingResult compareRemoteRevisionWith(final AbstractProject<?, ?> pr
*/
protected List<CvsFile> calculateRepositoryState(final Date startTime, final Date endTime,
final CvsRepository repository, final TaskListener listener,
final EnvVars envVars) throws IOException {
final EnvVars envVars, final FilePath workspace) throws IOException, InterruptedException {
final List<CvsFile> files = new ArrayList<CvsFile>();

for (final CvsRepositoryItem item : repository.getRepositoryItems()) {
for (final CvsModule module : item.getModules()) {

CvsLog logContents = getRemoteLogForModule(repository, item, module, startTime, endTime, envVars, listener);
CvsLog logContents = getRemoteLogForModule(repository, item, module, startTime, endTime, envVars, listener, workspace);

// use the parser to build up a list of changed files and add it to
// the list we've been creating
Expand Down Expand Up @@ -629,10 +629,10 @@ protected List<CvsFile> calculateRepositoryState(final Date startTime, final Dat
*/
private CvsLog getRemoteLogForModule(final CvsRepository repository, final CvsRepositoryItem item, final CvsModule module,
final Date startTime, final Date endTime,
final EnvVars envVars, final TaskListener listener) throws IOException {
final EnvVars envVars, final TaskListener listener, FilePath workspace) throws IOException, InterruptedException {
final Client cvsClient = getCvsClient(repository, envVars, listener);

RlogCommand rlogCommand = new RlogCommand();
final RlogCommand rlogCommand = new RlogCommand();

// we have to synchronize since we're dealing with DateFormat.format()
synchronized (DATE_FORMATTER) {
Expand Down Expand Up @@ -662,26 +662,18 @@ private CvsLog getRemoteLogForModule(final CvsRepository repository, final CvsRe
listener.getLogger().println("cvs " + rlogCommand.getCVSCommand());

// send the command to be run, we can't continue of the task fails
try {
if (!cvsClient.executeCommand(rlogCommand, getGlobalOptions(repository, envVars))) {
cleanupLog(logStream, tmpRlogSpill);
throw new RuntimeException("Error while trying to run CVS rlog");
}
} catch (CommandAbortedException e) {
cleanupLog(logStream, tmpRlogSpill);
throw new RuntimeException("CVS rlog command aborted", e);
} catch (CommandException e) {
cleanupLog(logStream, tmpRlogSpill);
throw new RuntimeException("CVS rlog command failed", e);
} catch (AuthenticationException e) {
cleanupLog(logStream, tmpRlogSpill);
throw new RuntimeException("CVS authentication failure while running rlog command", e);
} finally {
try {
cvsClient.getConnection().close();
} catch(IOException ex) {
listener.getLogger().println("Could not close client connection: " + ex.getMessage());
}

if (workspace == null) {
executeRlog(cvsClient, rlogCommand, repository, envVars, logStream, tmpRlogSpill);
}
else {
workspace.act(new FilePath.FileCallable<Void>() {
@Override
public Void invoke(File file, VirtualChannel virtualChannel) throws IOException, InterruptedException {
executeRlog(cvsClient, rlogCommand, repository, envVars, logStream, tmpRlogSpill);
return null;
}
});
}

// flush the output so we have it all available for parsing
Expand All @@ -707,6 +699,27 @@ public void dispose() {
};
}

private void executeRlog(Client cvsClient, RlogCommand rlogCommand, CvsRepository repository, EnvVars envVars,
PrintStream logStream, File tmpRlogSpill) throws IOException {
try {
if (!cvsClient.executeCommand(rlogCommand, getGlobalOptions(repository, envVars))) {
cleanupLog(logStream, tmpRlogSpill);
throw new RuntimeException("Error while trying to run CVS rlog");
}
} catch (CommandAbortedException e) {
cleanupLog(logStream, tmpRlogSpill);
throw new RuntimeException("CVS rlog command aborted", e);
} catch (CommandException e) {
cleanupLog(logStream, tmpRlogSpill);
throw new RuntimeException("CVS rlog command failed", e);
} catch (AuthenticationException e) {
cleanupLog(logStream, tmpRlogSpill);
throw new RuntimeException("CVS authentication failure while running rlog command", e);
} finally {
cvsClient.getConnection().close();
}
}

private void cleanupLog(PrintStream logStream, File tmpRlogSpill)
{
logStream.close();
Expand Down Expand Up @@ -742,15 +755,15 @@ private void cleanupLog(PrintStream logStream, File tmpRlogSpill)
*/
protected List<CVSChangeLogSet.CVSChangeLog> calculateChangeLog(final Date startTime, final Date endTime,
final CvsRepository repository,
final TaskListener listener, final EnvVars envVars)
final TaskListener listener, final EnvVars envVars, FilePath workspace)
throws IOException, InterruptedException {

final List<CVSChangeLogSet.CVSChangeLog> changes = new ArrayList<CVSChangeLogSet.CVSChangeLog>();

for (final CvsRepositoryItem item : repository.getRepositoryItems()) {
for (final CvsModule module : item.getModules()) {

CvsLog logContents = getRemoteLogForModule(repository, item, module, startTime, endTime, envVars, listener);
CvsLog logContents = getRemoteLogForModule(repository, item, module, startTime, endTime, envVars, listener, workspace);

// use the parser to build up a list of changes and add it to the
// list we've been creating
Expand All @@ -770,7 +783,7 @@ protected void postCheckout(AbstractBuild<?, ?> build, File changelogFile, CvsRe
final List<CVSChangeLogSet.CVSChangeLog> changes = new ArrayList<CVSChangeLogSet.CVSChangeLog>();
for (CvsRepository location : repositories) {
changes.addAll(calculateChangeLog(lastCompleteBuild.getTime(), build.getTime(), location,
listener, build.getEnvironment(listener)));
listener, build.getEnvironment(listener), workspace));
}
new CVSChangeLogSet(build,changes).toFile(changelogFile);
}
Expand Down
10 changes: 1 addition & 9 deletions src/main/java/hudson/scm/CVSSCM.java
Expand Up @@ -221,17 +221,9 @@ protected PollingResult compareRemoteRevisionWith(final AbstractProject<?, ?> pr
final FilePath workspace, final TaskListener listener, final SCMRevisionState baseline)
throws IOException, InterruptedException {

return super.compareRemoteRevisionWith(project, launcher, listener, baseline, getRepositories());
return super.compareRemoteRevisionWith(project, launcher, workspace, listener, baseline, getRepositories());
}









/**
* If there are multiple modules, return the module directory of the first
* one.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/hudson/scm/CvsProjectset.java
Expand Up @@ -102,7 +102,7 @@ protected PollingResult compareRemoteRevisionWith(AbstractProject<?, ?> project,
FilePath workspace, TaskListener listener,
SCMRevisionState baseline)
throws IOException, InterruptedException {
return super.compareRemoteRevisionWith(project, launcher,
return super.compareRemoteRevisionWith(project, launcher, workspace,
listener, baseline, getAllRepositories(workspace));
}

Expand Down

0 comments on commit 2c0d618

Please sign in to comment.