private void computeChangeLog(GitClient git, Revision revToBuild, TaskListener listener, BuildData previousBuildData, FilePath changelogFile, BuildChooserContext context) throws IOException, InterruptedException {
Writer out = new OutputStreamWriter(changelogFile.write(),"UTF-8");
boolean executed = false;
ChangelogCommand changelog = git.changelog();
changelog.includes(revToBuild.getSha1());
try {
boolean exclusion = false;
ChangelogToBranch changelogToBranch = getExtensions().get(ChangelogToBranch.class);
if (changelogToBranch != null) {
listener.getLogger().println("Using 'Changelog to branch' strategy.");
changelog.excludes(changelogToBranch.getOptions().getRef());
exclusion = true;
} else {
for (Branch b : revToBuild.getBranches()) {
Build lastRevWas = getBuildChooser().prevBuildForChangelog(b.getName(), previousBuildData, git, context);
if (lastRevWas != null && git.isCommitInRepo(lastRevWas.getSHA1())) {
changelog.excludes(lastRevWas.getSHA1());
exclusion = true;
}
}
}
if (!exclusion) {
listener.getLogger().println("First time build. Skipping changelog.");
} else {
changelog.to(out).max(MAX_CHANGELOG).execute();
executed = true;
}
} catch (GitException ge) {
ge.printStackTrace(listener.error("Unable to retrieve changeset"));
} finally {
if (!executed) changelog.abort();
IOUtils.closeQuietly(out);
}
}