Skip to content
Permalink
Browse files

[FIXED JENKINS-13764] Use same location as workspace for post build rlog

  • Loading branch information
Michael Clarke
Michael Clarke committed Oct 20, 2013
1 parent 78bb5fb commit 2c0d618f097f845d82b7aa8b7edf5a6c96a8e40d
@@ -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
@@ -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);

@@ -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
@@ -629,10 +629,10 @@ protected PollingResult compareRemoteRevisionWith(final AbstractProject<?, ?> pr
*/
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) {
@@ -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
@@ -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();
@@ -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
@@ -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);
}
@@ -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.
@@ -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));
}

0 comments on commit 2c0d618

Please sign in to comment.
You can’t perform that action at this time.