I was able to solve both problems (getting the Last Changed Rev and creating my Maven Plugin)! I won't be needing the maven plugin, but I may come in handy later on (i.e if the Jenkins Subversion Plugin later changes the ${SVN_REVISION}
variable to the repository revision).
Getting the Last Changed Rev.
For the first problem, I misread the Jenkins Subversion Plugin documentation. The ${SVN_REVISION}
environment variable does return the Last Changed Rev number, not the repository revision one. So, I was able to do this in my pom:
pom.xml
<properties>
<!-- this default revision number will be changed by Jenkins -->
<svn.revision>REV</svn.revision>
<!-- other properties -->
</properties>
Then, in the Jenkins build task, I call maven using package -Dsvn.revision=${SVN_REVISION}
, which will then change the svn.revision parameter in Maven.
Maven Plugin
In order to set the parameters in my Maven plugin, I've use the class MavenProject
, which gives me the project pom properties:
@Mojo(name = "svn-info", defaultPhase = LifecyclePhase.PROCESS_SOURCES)
@Execute(phase = LifecyclePhase.PROCESS_SOURCES)
public class SvnInfoMojo extends AbstractMojo {
@Component
private MavenProject project;
@Parameter(property="project.scm.url", defaultValue = "${project.scm.url}", required = true)
private String url;
private String svnLastRevision;
private String svnLastChangedDate;
public void execute() throws MojoExecutionException, MojoFailureException {
SVNController controller = new SVNController(url);
info = controller.getInfo();
this.svnLastRevision = Long.toString(info.getCommittedRevision().getNumber());
// Sets the property ${last-rev} in the project pom
project.getProperties().setProperty("last-rev", this.svnLastRevision);
// uses DateFormat to parse the date
this.svnLastChangedDate = parseDate(info.getCommittedDate());
// Sets the property ${last-changed} in the project pom
project.getProperties().setProperty("last-changed", this.svnLastChangedDate);
}
}