diff --git a/.gitignore b/.gitignore
index 0e7c2b303..8937ec50e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -10,4 +10,6 @@ target
build
.checkstyle
.DS_Store
-.factorypath
\ No newline at end of file
+.factorypath
+.mvn/
+mvnw
diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/config/ReleaseDescriptorBuilder.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/config/ReleaseDescriptorBuilder.java
index a2afc729d..6a04f2b72 100644
--- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/config/ReleaseDescriptorBuilder.java
+++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/config/ReleaseDescriptorBuilder.java
@@ -34,7 +34,7 @@
* @since 3.0.0-M5
*/
public class ReleaseDescriptorBuilder {
- private static final Pattern PROPERTY_PATTERN = Pattern.compile("\\$\\{[^}]+}");
+ private static final Pattern PROPERTY_PATTERN = Pattern.compile("\\$\\{[^}]+?}");
private final Logger logger;
diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractCheckPomPhase.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractCheckPomPhase.java
index fed385048..7b24d39a4 100644
--- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractCheckPomPhase.java
+++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractCheckPomPhase.java
@@ -31,6 +31,7 @@
import org.apache.maven.shared.release.env.ReleaseEnvironment;
import org.apache.maven.shared.release.scm.ReleaseScmRepositoryException;
import org.apache.maven.shared.release.scm.ScmRepositoryConfigurator;
+import org.apache.maven.shared.release.util.MavenExpression;
import org.codehaus.plexus.util.StringUtils;
import static java.util.Objects.requireNonNull;
@@ -89,7 +90,8 @@ public ReleaseResult execute(
boolean containsSnapshotProjects = false;
for (MavenProject project : reactorProjects) {
- if (ArtifactUtils.isSnapshot(project.getVersion())) {
+ String projectVersion = MavenExpression.evaluate(project.getVersion(), project.getProperties());
+ if (ArtifactUtils.isSnapshot(projectVersion)) {
containsSnapshotProjects = true;
break;
diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractMapVersionsPhase.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractMapVersionsPhase.java
index 57605bfd8..a7559b0e6 100644
--- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractMapVersionsPhase.java
+++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractMapVersionsPhase.java
@@ -35,6 +35,7 @@
import org.apache.maven.shared.release.policy.version.VersionPolicy;
import org.apache.maven.shared.release.policy.version.VersionPolicyRequest;
import org.apache.maven.shared.release.scm.ScmRepositoryConfigurator;
+import org.apache.maven.shared.release.util.CiFriendlyVersion;
import org.apache.maven.shared.release.util.ReleaseUtil;
import org.apache.maven.shared.release.versions.VersionParseException;
import org.codehaus.plexus.components.interactivity.Prompter;
@@ -238,12 +239,12 @@ private String resolveNextVersion(
try {
try {
- suggestedVersion =
- resolveSuggestedVersion(baseVersion, releaseDescriptor, releaseEnvironment);
+ suggestedVersion = resolveSuggestedVersion(
+ project, baseVersion, releaseDescriptor, releaseEnvironment);
} catch (VersionParseException e) {
if (releaseDescriptor.isInteractive()) {
suggestedVersion =
- resolveSuggestedVersion("1.0", releaseDescriptor, releaseEnvironment);
+ resolveSuggestedVersion(project, "1.0", releaseDescriptor, releaseEnvironment);
} else {
throw new ReleaseExecutionException(
"Error parsing version, cannot determine next " + "version: " + e.getMessage(),
@@ -292,7 +293,10 @@ private String getContextString(ReleaseDescriptor releaseDescriptor) {
}
private String resolveSuggestedVersion(
- String baseVersion, ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment)
+ MavenProject project,
+ String baseVersion,
+ ReleaseDescriptor releaseDescriptor,
+ ReleaseEnvironment releaseEnvironment)
throws PolicyException, VersionParseException {
String policyId = releaseDescriptor.getProjectVersionPolicyId();
VersionPolicy policy = versionPolicies.get(policyId);
@@ -307,6 +311,11 @@ private String resolveSuggestedVersion(
}
request.setWorkingDirectory(releaseDescriptor.getWorkingDirectory());
+ if (CiFriendlyVersion.isCiFriendlyVersion(getOriginalVersion(project))) {
+ String sha1 = CiFriendlyVersion.resolveSha1Property(project.getProperties(), releaseDescriptor);
+ request.setVersion(baseVersion.replace(sha1, ""));
+ }
+
if (scmRepositoryConfigurator != null && releaseDescriptor.getScmSourceUrl() != null) {
try {
ScmRepository repository = scmRepositoryConfigurator.getConfiguredRepository(
@@ -332,6 +341,15 @@ private String resolveSuggestedVersion(
: policy.getReleaseVersion(request).getVersion();
}
+ private static String getOriginalVersion(MavenProject project) {
+ String version = null;
+ while (version == null && project != null) {
+ version = project.getOriginalModel().getVersion();
+ project = project.getParent();
+ }
+ return version;
+ }
+
private String getDevelopmentVersion(String projectId, ReleaseDescriptor releaseDescriptor) {
String projectVersion = releaseDescriptor.getProjectDevelopmentVersion(projectId);
diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractRewritePomsPhase.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractRewritePomsPhase.java
index 71972df19..9b4dbde22 100644
--- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractRewritePomsPhase.java
+++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractRewritePomsPhase.java
@@ -23,15 +23,12 @@
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.TimeZone;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.ArtifactUtils;
@@ -63,6 +60,8 @@
import org.apache.maven.shared.release.transform.ModelETLFactory;
import org.apache.maven.shared.release.transform.ModelETLRequest;
import org.apache.maven.shared.release.transform.jdom2.JDomModelETLFactory;
+import org.apache.maven.shared.release.util.CiFriendlyVersion;
+import org.apache.maven.shared.release.util.MavenExpression;
import org.apache.maven.shared.release.util.ReleaseUtil;
import org.codehaus.plexus.util.StringUtils;
@@ -92,18 +91,6 @@ public abstract class AbstractRewritePomsPhase extends AbstractReleasePhase impl
*/
private String modelETL = JDomModelETLFactory.NAME;
- /**
- * Regular expression pattern matching Maven expressions (i.e. references to Maven properties).
- * The first group selects the property name the expression refers to.
- */
- private static final Pattern EXPRESSION_PATTERN = Pattern.compile("\\$\\{(.+?)\\}");
-
- /**
- * All Maven properties allowed to be referenced in parent versions via expressions
- * @see CI-Friendly Versions
- */
- private static final List CI_FRIENDLY_PROPERTIES = Arrays.asList("revision", "sha1", "changelist");
-
private long startTime = -1 * 1000;
protected AbstractRewritePomsPhase(
@@ -455,23 +442,6 @@ private void rewriteVersion(
modelTarget.setVersion(version);
}
- /**
- * Extracts the Maven property name from a given expression.
- * @param expression the expression
- * @return either {@code null} if value is no expression otherwise the property referenced in the expression
- */
- public static String extractPropertyFromExpression(String expression) {
- Matcher matcher = EXPRESSION_PATTERN.matcher(expression);
- if (!matcher.find()) {
- return null;
- }
- return matcher.group(1);
- }
-
- public static boolean isCiFriendlyVersion(String version) {
- return CI_FRIENDLY_PROPERTIES.contains(extractPropertyFromExpression(version));
- }
-
private String rewriteParent(
MavenProject project,
Model targetModel,
@@ -494,7 +464,8 @@ private String rewriteParent(
throw new ReleaseFailureException("Version for parent '" + parent.getName() + "' was not mapped");
}
} else {
- if (!isCiFriendlyVersion(targetModel.getParent().getVersion())) {
+ if (!CiFriendlyVersion.isCiFriendlyVersion(
+ targetModel.getParent().getVersion())) {
targetModel.getParent().setVersion(parentVersion);
} else {
logInfo(
@@ -564,7 +535,7 @@ private void rewriteArtifactVersions(
logInfo(result, " Updating " + artifactId + " to " + mappedVersion);
coordinate.setVersion(mappedVersion);
} else {
- String property = extractPropertyFromExpression(rawVersion);
+ String property = MavenExpression.extractPropertyFromExpression(rawVersion);
if (property != null) {
if (property.startsWith("project.")
|| property.startsWith("pom.")
@@ -609,7 +580,9 @@ private void rewriteArtifactVersions(
}
}
} else {
- if (CI_FRIENDLY_PROPERTIES.contains(property)) {
+ if (CiFriendlyVersion.isCiFriendlyProperty(property)) {
+ // the parent's pom revision is set inside
+ // org.apache.maven.shared.release.transform.jdom2.JDomModel.setVersion
logInfo(
result,
" Ignoring artifact version update for CI friendly expression "
diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomModel.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomModel.java
index 20d972bd9..4b14e82d8 100644
--- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomModel.java
+++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomModel.java
@@ -31,7 +31,8 @@
import org.apache.maven.model.Profile;
import org.apache.maven.model.Reporting;
import org.apache.maven.model.Scm;
-import org.apache.maven.shared.release.phase.AbstractRewritePomsPhase;
+import org.apache.maven.shared.release.config.ReleaseDescriptor;
+import org.apache.maven.shared.release.util.CiFriendlyVersion;
import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.Text;
@@ -47,13 +48,19 @@ public class JDomModel extends Model {
private final JDomModelBase modelBase;
+ /**
+ * The ReleaseDescriptor after a commit performed
+ *
+ */
+ private final ReleaseDescriptor releaseDescriptor;
+
/**
*
Constructor for JDomModel.
*
* @param document a {@link org.jdom2.Document} object
*/
- public JDomModel(Document document) {
- this(document.getRootElement());
+ public JDomModel(Document document, ReleaseDescriptor releaseDescriptor) {
+ this(document.getRootElement(), releaseDescriptor);
}
/**
@@ -61,8 +68,9 @@ public JDomModel(Document document) {
*
* @param project a {@link org.jdom2.Element} object
*/
- public JDomModel(Element project) {
+ public JDomModel(Element project, ReleaseDescriptor releaseDescriptor) {
this.project = project;
+ this.releaseDescriptor = releaseDescriptor;
this.modelBase = new JDomModelBase(project);
}
@@ -180,7 +188,7 @@ public void setVersion(String version) {
if (versionElement == null) {
// never add version when parent references CI friendly property
- if (!(parentVersion != null && AbstractRewritePomsPhase.isCiFriendlyVersion(parentVersion))
+ if (!(parentVersion != null && CiFriendlyVersion.isCiFriendlyVersion(parentVersion))
&& !version.equals(parentVersion)) {
// we will add this after artifactId, since it was missing but different from the inherited version
Element artifactIdElement = project.getChild("artifactId", project.getNamespace());
@@ -192,14 +200,9 @@ public void setVersion(String version) {
project.addContent(index + 2, versionElement);
}
} else {
- if (AbstractRewritePomsPhase.isCiFriendlyVersion(versionElement.getTextNormalize())) {
+ if (CiFriendlyVersion.isCiFriendlyVersion(versionElement.getTextNormalize())) {
// try to rewrite property if CI friendly expression is used
- String ciFriendlyPropertyName =
- AbstractRewritePomsPhase.extractPropertyFromExpression(versionElement.getTextNormalize());
- Properties properties = getProperties();
- if (properties != null) {
- properties.setProperty(ciFriendlyPropertyName, version);
- }
+ CiFriendlyVersion.rewriteVersionAndProperties(version, getProperties(), releaseDescriptor);
} else {
JDomUtils.rewriteValue(versionElement, version);
}
diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomModelETL.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomModelETL.java
index 86bf8e272..640f574e0 100644
--- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomModelETL.java
+++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomModelETL.java
@@ -159,7 +159,7 @@ public void load(File targetFile) throws ReleaseExecutionException {
@Override
public Model getModel() {
- return new JDomModel(document);
+ return new JDomModel(document, releaseDescriptor);
}
private void normaliseLineEndings(Document document) {
diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomProperties.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomProperties.java
index b2c314f34..f689ff451 100644
--- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomProperties.java
+++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomProperties.java
@@ -51,10 +51,13 @@ public JDomProperties(Element properties) {
}
@Override
- public synchronized Object setProperty(String key, String value) {
- Element property = properties.getChild(key, properties.getNamespace());
+ public synchronized Object put(Object key, Object value) {
+ Element property = properties.getChild((String) key, properties.getNamespace());
- JDomUtils.rewriteValue(property, value);
+ if (property == null) {
+ property = new Element((String) key, properties.getNamespace());
+ }
+ JDomUtils.rewriteValue(property, (String) value);
// todo follow specs of Hashtable.put
return null;
@@ -112,9 +115,20 @@ public String getProperty(String key) {
}
}
+ @Override
+ public boolean containsKey(Object key) {
+ if (key instanceof String) {
+ Element property = properties.getChild((String) key, properties.getNamespace());
+ return property != null;
+ }
+ return false;
+ }
+
@Override
public String getProperty(String key, String defaultValue) {
- throw new UnsupportedOperationException();
+ String property = getProperty(key);
+
+ return property == null ? defaultValue : property;
}
@Override
diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/util/CiFriendlyVersion.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/util/CiFriendlyVersion.java
new file mode 100644
index 000000000..d5cc3662a
--- /dev/null
+++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/util/CiFriendlyVersion.java
@@ -0,0 +1,112 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.shared.release.util;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Properties;
+import java.util.Set;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.maven.artifact.ArtifactUtils;
+import org.apache.maven.shared.release.config.ReleaseDescriptor;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class CiFriendlyVersion {
+ private static final Logger LOGGER = LoggerFactory.getLogger(CiFriendlyVersion.class);
+
+ /**
+ * All Maven properties allowed to be referenced in parent versions via expressions
+ * @see CI-Friendly Versions
+ */
+ public static final String REVISION = "revision";
+
+ public static final String SHA1 = "sha1";
+ public static final String CHANGELIST = "changelist";
+
+ private static final Set CI_FRIENDLY_PROPERTIES = new HashSet<>(Arrays.asList(REVISION, SHA1, CHANGELIST));
+
+ private static final String SNAPSHOT = "-SNAPSHOT";
+
+ private CiFriendlyVersion() {}
+
+ public static boolean isCiFriendlyVersion(String version) {
+ if (StringUtils.isEmpty(version)) {
+ return false;
+ }
+ return isCiFriendlyProperty(MavenExpression.extractPropertyFromExpression(version));
+ }
+
+ public static boolean isCiFriendlyProperty(String property) {
+ return CI_FRIENDLY_PROPERTIES.contains(property);
+ }
+
+ public static void rewriteVersionAndProperties(
+ String version, Properties properties, ReleaseDescriptor releaseDescriptor) {
+ // try to rewrite property if CI friendly expression is used
+ if (properties != null) {
+ String sha1 = resolveSha1Property(properties, releaseDescriptor);
+ // assume that everybody follows the example and properties are simply chained
+ // and the changelist can only be '-SNAPSHOT'
+ if (ArtifactUtils.isSnapshot(version)) {
+ if (properties.containsKey(CHANGELIST)) {
+ String revision = version.replace(sha1, "").replace(SNAPSHOT, "");
+ setAndLogPropertyChange(properties, REVISION, revision);
+ setAndLogPropertyChange(properties, CHANGELIST, SNAPSHOT);
+ } else {
+ String revision = version.replace(sha1, "");
+ setAndLogPropertyChange(properties, REVISION, revision);
+ }
+ if (properties.containsKey(SHA1)) {
+ // drop the value for the next version
+ setAndLogPropertyChange(properties, SHA1, "");
+ }
+ } else {
+ properties.setProperty(REVISION, version.replace(sha1, ""));
+ if (properties.containsKey(CHANGELIST)) {
+ setAndLogPropertyChange(properties, CHANGELIST, "");
+ }
+ if (properties.containsKey(SHA1) && !sha1.isEmpty()) {
+ // we need this to restore the revision for the next development
+ // or release:prepare should provide sha1 after a commit
+ // or a user should provide it as an additional `arguments` in plugin configuration
+ // see maven-release-plugin/src/it/projects/prepare/ci-friendly-multi-module
+ setAndLogPropertyChange(properties, SHA1, sha1);
+ }
+ }
+ }
+ }
+
+ private static void setAndLogPropertyChange(Properties properties, String key, String value) {
+ LOGGER.info("Updating {} property to {}", key, value);
+ properties.setProperty(key, value);
+ }
+
+ public static String resolveSha1Property(Properties properties, ReleaseDescriptor releaseDescriptor) {
+ String sha1 = properties.getProperty(SHA1);
+ String scmVersion = releaseDescriptor.getScmReleasedPomRevision();
+ String systemSha1 = System.getProperty(SHA1);
+ String result = StringUtils.isNotEmpty(systemSha1)
+ ? systemSha1
+ : StringUtils.isNotEmpty(sha1) ? sha1 : scmVersion != null ? scmVersion : "";
+ LOGGER.info("Resolved SHA1 property value {}", result);
+ return result;
+ }
+}
diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/util/MavenExpression.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/util/MavenExpression.java
new file mode 100644
index 000000000..f832c0929
--- /dev/null
+++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/util/MavenExpression.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.shared.release.util;
+
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * @author Mikhail Kolesnikov
+ */
+public class MavenExpression {
+ /**
+ * Regular expression pattern matching Maven expressions (i.e. references to Maven properties).
+ * The first group selects the property name the expression refers to.
+ */
+ private static final Pattern EXPRESSION_PATTERN = Pattern.compile("\\$\\{(.+?)}");
+
+ private MavenExpression() {}
+
+ public static String evaluate(String expression, Map, ?> properties) {
+ StringBuilder result = new StringBuilder(expression);
+ Matcher matcher = EXPRESSION_PATTERN.matcher(result);
+ while (matcher.find()) {
+ String propertyName = matcher.group(1);
+ Object propertyValue = properties.get(propertyName);
+ result.replace(matcher.start(), matcher.end(), String.valueOf(propertyValue));
+ matcher.reset();
+ }
+ return result.toString();
+ }
+
+ /**
+ * Extracts the Maven property name from a given expression.
+ * @param expression the expression
+ * @return either {@code null} if value is no expression otherwise the property referenced in the expression
+ */
+ public static String extractPropertyFromExpression(String expression) {
+ Matcher matcher = EXPRESSION_PATTERN.matcher(expression);
+ if (!matcher.find()) {
+ return null;
+ }
+ return matcher.group(1);
+ }
+}
diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/MapVersionsPhaseTest.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/MapVersionsPhaseTest.java
index 36baf5df2..ffbb84ae1 100644
--- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/MapVersionsPhaseTest.java
+++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/MapVersionsPhaseTest.java
@@ -2452,6 +2452,8 @@ private static MavenProject createProject(String artifactId, String version) {
model.setGroupId("groupId");
model.setArtifactId(artifactId);
model.setVersion(version);
- return new MavenProject(model);
+ MavenProject mavenProject = new MavenProject(model);
+ mavenProject.setOriginalModel(model);
+ return mavenProject;
}
}
diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/RewritePomsForDevelopmentPhaseTest.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/RewritePomsForDevelopmentPhaseTest.java
index b303a514f..366d04f41 100644
--- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/RewritePomsForDevelopmentPhaseTest.java
+++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/RewritePomsForDevelopmentPhaseTest.java
@@ -398,4 +398,37 @@ public void testRewritePomDependenciesWithoutDependenciesVersionUpdate() throws
assertTrue(comparePomFiles(reactorProjects));
}
+
+ @Test
+ public void testRewritePomWithCiFriendlyReactor() throws Exception {
+ List reactorProjects = createReactorProjects("pom-with-parent-and-cifriendly-expressions");
+
+ ReleaseDescriptorBuilder builder =
+ createDescriptorFromProjects(reactorProjects, "pom-with-parent-and-cifriendly-expressions");
+ builder.addReleaseVersion("groupId:artifactId", RELEASE_VERSION);
+ builder.addDevelopmentVersion("groupId:artifactId", NEXT_VERSION);
+ builder.addReleaseVersion("groupId:subproject1", RELEASE_VERSION);
+ builder.addDevelopmentVersion("groupId:subproject1", NEXT_VERSION);
+
+ mapScm(builder);
+
+ phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects);
+
+ assertTrue(comparePomFiles(reactorProjects));
+ }
+
+ @Test
+ public void testRewritePomWithCiFriendlyReactorWithOnlyRevision() throws Exception {
+ List reactorProjects = createReactorProjects("pom-with-parent-and-cifriendly-revision");
+
+ ReleaseDescriptorBuilder builder =
+ createDescriptorFromProjects(reactorProjects, "pom-with-parent-and-cifriendly-revision");
+ builder.addReleaseVersion("groupId:artifactId", RELEASE_VERSION);
+ builder.addDevelopmentVersion("groupId:artifactId", NEXT_VERSION);
+ builder.addReleaseVersion("groupId:subproject1", RELEASE_VERSION);
+ builder.addDevelopmentVersion("groupId:subproject1", NEXT_VERSION);
+ phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects);
+
+ assertTrue(comparePomFiles(reactorProjects));
+ }
}
diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/RewritePomsForReleasePhaseTest.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/RewritePomsForReleasePhaseTest.java
index 71515aed7..547acb5a8 100644
--- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/RewritePomsForReleasePhaseTest.java
+++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/RewritePomsForReleasePhaseTest.java
@@ -334,6 +334,19 @@ public void testRewritePomWithCiFriendlyReactor() throws Exception {
assertTrue(comparePomFiles(reactorProjects));
}
+ @Test
+ public void testRewritePomWithCiFriendlyReactorWithOnlyRevision() throws Exception {
+ List reactorProjects = createReactorProjects("pom-with-parent-and-cifriendly-revision");
+
+ ReleaseDescriptorBuilder builder =
+ createDescriptorFromProjects(reactorProjects, "pom-with-parent-and-cifriendly-revision");
+ builder.addReleaseVersion("groupId:artifactId", NEXT_VERSION);
+ builder.addReleaseVersion("groupId:subproject1", NEXT_VERSION);
+ phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects);
+
+ assertTrue(comparePomFiles(reactorProjects));
+ }
+
// MRELEASE-311
@Test
public void testRewritePomWithDependencyPropertyCoordinate() throws Exception {
diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/transform/jdom2/JDomModelTest.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/transform/jdom2/JDomModelTest.java
index ebd0ec282..3967274b1 100644
--- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/transform/jdom2/JDomModelTest.java
+++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/transform/jdom2/JDomModelTest.java
@@ -22,6 +22,8 @@
import org.apache.maven.model.Model;
import org.apache.maven.model.Scm;
+import org.apache.maven.shared.release.config.ReleaseDescriptor;
+import org.apache.maven.shared.release.config.ReleaseDescriptorBuilder;
import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.input.SAXBuilder;
@@ -33,19 +35,20 @@
public class JDomModelTest {
private SAXBuilder builder = new SAXBuilder();
+ private ReleaseDescriptor releaseDescriptor = new ReleaseDescriptorBuilder().build();
@Test
public void testGetScm() throws Exception {
String content = "";
Document document = builder.build(new StringReader(content));
- assertNull(new JDomModel(document).getScm());
+ assertNull(new JDomModel(document, releaseDescriptor).getScm());
}
@Test
public void testSetScm() throws Exception {
String content = "";
Document document = builder.build(new StringReader(content));
- Model model = new JDomModel(document);
+ Model model = new JDomModel(document, releaseDescriptor);
assertNull(model.getScm());
model.setScm(new Scm());
@@ -59,7 +62,7 @@ public void testSetScm() throws Exception {
public void testSetVersion() throws Exception {
String content = "";
Element projectElm = builder.build(new StringReader(content)).getRootElement();
- Model model = new JDomModel(projectElm);
+ Model model = new JDomModel(projectElm, releaseDescriptor);
assertNull(model.getVersion());
model.setVersion("VERSION");
@@ -69,9 +72,9 @@ public void testSetVersion() throws Exception {
assertNull(model.getVersion());
// inherit from parent via CI friendly
- content = "${revision}";
+ content = "${revision}${changelist}";
projectElm = builder.build(new StringReader(content)).getRootElement();
- model = new JDomModel(projectElm);
+ model = new JDomModel(projectElm, releaseDescriptor);
assertNull(model.getVersion());
model.setVersion("PARENT_VERSION");
assertNull(getVersion(projectElm));
@@ -79,7 +82,7 @@ public void testSetVersion() throws Exception {
// this business logic might need to moved.
content = "PARENT_VERSION";
projectElm = builder.build(new StringReader(content)).getRootElement();
- model = new JDomModel(projectElm);
+ model = new JDomModel(projectElm, releaseDescriptor);
assertNull(model.getVersion());
model.setVersion("PARENT_VERSION");
diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/transform/jdom2/JDomPropertiesTest.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/transform/jdom2/JDomPropertiesTest.java
index fa9f48d99..0335a1160 100644
--- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/transform/jdom2/JDomPropertiesTest.java
+++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/transform/jdom2/JDomPropertiesTest.java
@@ -101,9 +101,12 @@ public void testGetProperty() throws Exception {
assertEquals("VALUE", new JDomProperties(propertiesElm).getProperty("KEY"));
}
- @Test(expected = UnsupportedOperationException.class)
- public void testGetPropertyDefault() {
- new JDomProperties(null).getProperty(null, null);
+ @Test
+ public void testGetPropertyDefault() throws Exception {
+ String content = "";
+ Element propertiesElm = builder.build(new StringReader(content)).getRootElement();
+ assertNull(new JDomProperties(propertiesElm).getProperty("KEY", null));
+ assertEquals("", new JDomProperties(propertiesElm).getProperty("KEY", ""));
}
@Test(expected = UnsupportedOperationException.class)
diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/util/MavenExpressionTest.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/util/MavenExpressionTest.java
new file mode 100644
index 000000000..12c1b2d4b
--- /dev/null
+++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/util/MavenExpressionTest.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.shared.release.util;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Properties;
+
+import junit.framework.TestCase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+/**
+ * @author Mikhail Kolesnikov
+ */
+@RunWith(Parameterized.class)
+public class MavenExpressionTest extends TestCase {
+
+ private final String expected;
+ private final String expression;
+ private final Properties properties = new Properties();
+
+ public MavenExpressionTest(String expected, String expression) {
+ this.expected = expected;
+ this.expression = expression;
+ properties.setProperty("revision", "12");
+ properties.setProperty("sha1", "34");
+ properties.setProperty("changelist", "56");
+ }
+
+ @Parameters(name = "expected result {0} for expression {1}")
+ public static Collection