public void execute() throws MojoExecutionException, MojoFailureException {
getLog().debug("Looking for previous release of " + project.getGroupId() + ":" + project.getArtifactId() + ":"
+ project.getVersion());
Artifact projectArtifact = artifactFactory
.createProjectArtifact(project.getGroupId(), project.getArtifactId(), project.getVersion());
ArtifactVersion projectVersion = new DefaultArtifactVersion(project.getVersion());
ArtifactVersion latest = null;
try {
List<ArtifactVersion> artifactVersions = artifactMetadataSource
.retrieveAvailableVersions(projectArtifact, localRepository,
project.getRemoteArtifactRepositories());
for (ArtifactVersion version : artifactVersions) {
if (SNAPSHOT_PATTERN.matcher(version.toString()).find() || projectVersion.compareTo(version) <= 0) {
continue;
}
if (latest == null || latest.compareTo(version) < 0) {
latest = version;
}
}
} catch (ArtifactMetadataRetrievalException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
getLog().debug("Previous release = " + latest);
Map<GroupArtifactId, String> addedDeps = new LinkedHashMap<GroupArtifactId, String>();
Map<GroupArtifactId, String> removedDeps = new LinkedHashMap<GroupArtifactId, String>();
Map<GroupArtifactId, Map.Entry<String, String>> updatedDeps =
new LinkedHashMap<GroupArtifactId, Map.Entry<String, String>>();
for (Dependency dep : project.getDependencies()) {
addedDeps.put(new GroupArtifactId(dep), dep.getVersion());
}
String startTag = null;
String endTag = null;
if (latest != null) {
Artifact latestArtifact = artifactFactory
.createProjectArtifact(project.getGroupId(), project.getArtifactId(), latest.toString());
try {
artifactResolver.resolve(latestArtifact, project.getRemoteArtifactRepositories(), localRepository);
} catch (ArtifactResolutionException e) {
throw new MojoExecutionException(e.getMessage(), e);
} catch (ArtifactNotFoundException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
ProjectBuildingRequest request = new DefaultProjectBuildingRequest();
request.setProcessPlugins(true);
request.setProfiles(request.getProfiles());
request.setActiveProfileIds(session.getRequest().getActiveProfiles());
request.setInactiveProfileIds(session.getRequest().getInactiveProfiles());
request.setRemoteRepositories(session.getRequest().getRemoteRepositories());
request.setSystemProperties(session.getSystemProperties());
request.setUserProperties(session.getUserProperties());
request.setRemoteRepositories(session.getRequest().getRemoteRepositories());
request.setPluginArtifactRepositories(session.getRequest().getPluginArtifactRepositories());
request.setRepositorySession(session.getRepositorySession());
request.setLocalRepository(localRepository);
request.setBuildStartTime(session.getRequest().getStartTime());
request.setResolveDependencies(true);
request.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_STRICT);
MavenProject latestProject;
try {
latestProject = projectBuilder.build(latestArtifact.getFile(), request).getProject();
} catch (ProjectBuildingException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
for (Dependency dep : latestProject.getDependencies()) {
GroupArtifactId key = new GroupArtifactId(dep);
if (addedDeps.containsKey(key)) {
String v = addedDeps.get(key);
addedDeps.remove(key);
if (!v.equals(dep.getVersion())) {
updatedDeps.put(key, new AbstractMap.SimpleImmutableEntry<String, String>(dep.getVersion(), v));
}
} else if (updatedDeps.containsKey(key)) {
String v = updatedDeps.get(key).getValue();
if (!v.equals(dep.getVersion())) {
updatedDeps.remove(key);
addedDeps.put(key, v);
} else {
updatedDeps.put(key, new AbstractMap.SimpleImmutableEntry<String, String>(dep.getVersion(), v));
}
} else {
removedDeps.put(key, dep.getVersion());
}
}
String tagNameFormat = getTagNameFormat(latestProject);
getLog().debug("Start Tag name format = " + tagNameFormat);
Interpolator interpolator = new StringSearchInterpolator("@{", "}");
List<String> possiblePrefixes = java.util.Arrays.asList("project", "pom");
Properties values = new Properties();
values.setProperty("artifactId", project.getArtifactId());
values.setProperty("groupId", project.getGroupId());
values.setProperty("version", latest.toString());
interpolator.addValueSource(new PrefixedPropertiesValueSource(possiblePrefixes, values, true));
RecursionInterceptor recursionInterceptor = new PrefixAwareRecursionInterceptor(possiblePrefixes);
try {
startTag = interpolator.interpolate(tagNameFormat, recursionInterceptor);
} catch (InterpolationException e) {