in maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractRewritePomsPhase.java [467:588]
private void rewriteArtifactVersions(
Collection<MavenCoordinate> elements,
Model projectModel,
Properties properties,
ReleaseResult result,
ReleaseDescriptor releaseDescriptor,
boolean simulate)
throws ReleaseExecutionException, ReleaseFailureException {
if (elements == null) {
return;
}
String projectId = ArtifactUtils.versionlessKey(projectModel.getGroupId(), projectModel.getArtifactId());
for (MavenCoordinate coordinate : elements) {
String rawVersion = coordinate.getVersion();
if (rawVersion == null) {
// managed dependency or unversioned plugin
continue;
}
String rawGroupId = coordinate.getGroupId();
if (rawGroupId == null) {
if ("plugin".equals(coordinate.getName())) {
rawGroupId = "org.apache.maven.plugins";
} else {
// incomplete dependency
continue;
}
}
String groupId = ReleaseUtil.interpolate(rawGroupId, projectModel);
String rawArtifactId = coordinate.getArtifactId();
if (rawArtifactId == null) {
// incomplete element
continue;
}
String artifactId = ReleaseUtil.interpolate(rawArtifactId, projectModel);
String key = ArtifactUtils.versionlessKey(groupId, artifactId);
String resolvedSnapshotVersion = getResolvedSnapshotVersion(key, releaseDescriptor);
String mappedVersion = getNextVersion(releaseDescriptor, key);
String originalVersion = getOriginalVersion(releaseDescriptor, key, simulate);
if (originalVersion == null) {
originalVersion = getOriginalResolvedSnapshotVersion(key, releaseDescriptor);
}
// MRELEASE-220
if (mappedVersion != null
&& mappedVersion.endsWith(Artifact.SNAPSHOT_VERSION)
&& !rawVersion.endsWith(Artifact.SNAPSHOT_VERSION)
&& !releaseDescriptor.isUpdateDependencies()) {
continue;
}
if (mappedVersion != null) {
if (rawVersion.equals(originalVersion)) {
logInfo(result, " Updating " + artifactId + " to " + mappedVersion);
coordinate.setVersion(mappedVersion);
} else if (rawVersion.matches("\\$\\{.+\\}")) {
String expression = rawVersion.substring(2, rawVersion.length() - 1);
if (expression.startsWith("project.")
|| expression.startsWith("pom.")
|| "version".equals(expression)) {
if (!mappedVersion.equals(getNextVersion(releaseDescriptor, projectId))) {
logInfo(result, " Updating " + artifactId + " to " + mappedVersion);
coordinate.setVersion(mappedVersion);
} else {
logInfo(result, " Ignoring artifact version update for expression " + rawVersion);
}
} else if (properties != null) {
// version is an expression, check for properties to update instead
String propertyValue = properties.getProperty(expression);
if (propertyValue != null) {
if (propertyValue.equals(originalVersion)) {
logInfo(result, " Updating " + rawVersion + " to " + mappedVersion);
// change the property only if the property is the same as what's in the reactor
properties.setProperty(expression, mappedVersion);
} else if (mappedVersion.equals(propertyValue)) {
// this property may have been updated during processing a sibling.
logInfo(
result,
" Ignoring artifact version update for expression " + rawVersion
+ " because it is already updated");
} else if (!mappedVersion.equals(rawVersion)) {
// WARNING: ${pom.*} prefix support and ${version} is about to be dropped in mvn4!
// https://issues.apache.org/jira/browse/MNG-7404
// https://issues.apache.org/jira/browse/MNG-7244
if (mappedVersion.matches("\\$\\{project.+\\}")
|| mappedVersion.matches("\\$\\{pom.+\\}")
|| "${version}".equals(mappedVersion)) {
logInfo(
result,
" Ignoring artifact version update for expression " + mappedVersion);
// ignore... we cannot update this expression
} else {
// the value of the expression conflicts with what the user wanted to release
throw new ReleaseFailureException("The artifact (" + key + ") requires a "
+ "different version (" + mappedVersion + ") than what is found ("
+ propertyValue + ") for the expression (" + expression + ") in the "
+ "project (" + projectId + ").");
}
}
} else {
// the expression used to define the version of this artifact may be inherited
// TODO needs a better error message, what pom? what dependency?
throw new ReleaseFailureException("The version could not be updated: " + rawVersion);
}
}
} else {
// different/previous version not related to current release
}
} else if (resolvedSnapshotVersion != null) {
logInfo(result, " Updating " + artifactId + " to " + resolvedSnapshotVersion);
coordinate.setVersion(resolvedSnapshotVersion);
} else {
// artifact not related to current release
}
}
}