Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reject illegal placeholder in Maven CI friendly version property #22131

Merged
merged 1 commit into from Dec 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -239,6 +239,11 @@ public static String resolveVersion(String rawVersion, Model rawModel) {
if (resolved == null) {
return null;
}
if (resolved.contains("${")) {
throw new IllegalArgumentException("Illegal placeholder in Maven CI friendly version property \""
+ matcher.group(1) + "\": " + resolved
+ "\n\tPlease consult https://maven.apache.org/maven-ci-friendly.html#single-project-setup");
}
matcher.appendReplacement(sb, resolved);
}
matcher.appendTail(sb);
Expand Down
@@ -0,0 +1,53 @@
package io.quarkus.bootstrap.resolver.maven.workspace;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import org.apache.maven.model.Model;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

public class ModelUtilsTest {

@Test
void resolveVersion_literal() {
assertThat(ModelUtils.resolveVersion("1.0.0", new Model())).isEqualTo("1.0.0");
}

@ParameterizedTest
@ValueSource(strings = { "${revision}", "${sha1}", "${changelist}" })
void resolveVersion_notResolvable(String rawVersion) {
assertThat(ModelUtils.resolveVersion(rawVersion, new Model())).isNull();
}

@ParameterizedTest
@ValueSource(strings = { "revision", "sha1", "changelist" })
void resolveVersion_resolvable(String ciFriendlyPropertyName) {
var model = new Model();
model.getProperties().put(ciFriendlyPropertyName, "1.0.0");

assertThat(ModelUtils.resolveVersion("${" + ciFriendlyPropertyName + "}", model)).isEqualTo("1.0.0");
}

@Test
void resolveVersion_allCiFriendlyPropertyNames() {
var model = new Model();
model.getProperties().put("revision", "1");
model.getProperties().put("sha1", "2");
model.getProperties().put("changelist", "3");

assertThat(ModelUtils.resolveVersion("${revision}.${sha1}.${changelist}", model)).isEqualTo("1.2.3");
}

@Test
void resolveVersion_illegalPlaceholder() {
var model = new Model();
model.getProperties().put("revision", "${main.project.version}");
model.getProperties().put("main.project.version", "1.6.0-SNAPSHOT");

assertThatThrownBy(() -> ModelUtils.resolveVersion("${revision}", model))
.isExactlyInstanceOf(IllegalArgumentException.class)
.hasMessageContainingAll("revision", "main.project.version");
}
}