nz.ac.auckland.groupapps.maven.gitlog.render.LoggerRender.groovy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of uoa-gitlog-plugin Show documentation
Show all versions of uoa-gitlog-plugin Show documentation
Generates a release note based on commits to a git repository in text format
showing the changes that are included in each version.
A possible use of this is to push these changelogs to a remote server when
releasing the maven project so that the remote server can lookup and update
JIRA ticket based on an accurate list of commits that the current package includes.
package nz.ac.auckland.groupapps.maven.gitlog.render
import groovy.transform.CompileStatic
import nz.ac.auckland.groupapps.maven.gitlog.PluginConstant
import nz.ac.auckland.groupapps.maven.gitlog.commit.CommitBundle
import org.apache.maven.plugin.logging.Log
import org.apache.maven.plugin.logging.SystemStreamLog
import java.text.DateFormat
import java.text.SimpleDateFormat
/**
*
* @author Kefeng Deng (kden022, [email protected])
*/
@CompileStatic
class LoggerRender {
private final List revCommitList
private final Log log
public LoggerRender(List commitList, Log log) {
if (!log) {
log = new SystemStreamLog()
}
this.revCommitList = commitList
this.log = log
}
protected void renderEmptyLine() {
log.info('')
}
protected void renderSeparator() {
log.info('=============================================================')
}
public void render() {
renderSeparator()
renderEmptyLine()
revCommitList.each { CommitBundle revCommit ->
log.info(convertCommitToString(revCommit))
}
renderEmptyLine()
log.info("Total ${revCommitList.size()} commits")
renderSeparator()
}
public static String convertCommitToString(CommitBundle commit) {
return "[${formatTimestamp(commit.commitTime)}][Version ${commit.version}] - ${commit.message} (${commit.committerName},${commit.committerEmail})"
}
public static String formatTimestamp(long timeStamp) {
return PluginConstant.DATE_FORMAT.format(new Date(timeStamp))
}
}