Made gradle updater less birttle

This commit is contained in:
Marcin Grzejszczak
2019-01-22 21:15:37 +01:00
parent 27a3b9773c
commit d57d8f98e7
3 changed files with 23 additions and 20 deletions

View File

@@ -94,13 +94,18 @@ public class GradleUpdater implements ReleaserPropertiesAware {
Properties props = loadProps(file);
final Map<String, String> substitution = this.properties.getGradle()
.getGradlePropsSubstitution();
props.entrySet().stream().forEach(entry -> {
if (substitution.containsKey(entry.getKey())) {
Object projectName = substitution.get(entry.getKey());
ProjectVersion value = this.projects.forName((String) projectName);
log.info("Replacing [{}->{}] with [{}->{}]", entry.getKey(), entry.getValue(), entry.getKey(), value);
changedString.set(changedString.get().replace(entry.getKey() + "=" + entry.getValue(),
entry.getKey() + "=" + value));
props.forEach((key, value1) -> {
if (substitution.containsKey(key)) {
String projectName = substitution.get(key);
if (!this.projects.containsProject(projectName)) {
log.warn("Should update project with name [{}] but it wasn't found in the list of projects [{}]", projectName, this.projects
.asList());
return;
}
ProjectVersion value = this.projects.forName(projectName);
log.info("Replacing [{}->{}] with [{}->{}]", key, value1, key, value);
changedString.set(changedString.get().replace(key + "=" + value1,
key + "=" + value));
}
});
storeString(path, changedString.get());

View File

@@ -75,18 +75,12 @@ public class Projects extends HashSet<ProjectVersion> {
final ProjectVersion thisProject = new ProjectVersion(projectRoot);
return this.stream().filter(projectVersion -> projectVersion.projectName.equals(thisProject.projectName))
.findFirst()
.orElseThrow(() -> exception(thisProject.projectName));
.orElseThrow(() -> exception(this, thisProject.projectName));
}
private static IllegalStateException exception(String projectName) {
private static IllegalStateException exception(Projects projects, String projectName) {
return new IllegalStateException(
"Project with name [" + projectName + "] is not present. "
+ additionalErrorMessage(projectName));
}
private static IllegalStateException exceptionStartingWithName(String projectName) {
return new IllegalStateException(
"Project starting with name [" + projectName + "] is not present. "
"Project with name [" + projectName + "] is not present in the list of projects [" + projects.asList() + "] . "
+ additionalErrorMessage(projectName));
}
@@ -98,7 +92,7 @@ public class Projects extends HashSet<ProjectVersion> {
public ProjectVersion forName(String projectName) {
return this.stream().filter(projectVersion -> projectVersion.projectName.equals(projectName))
.findFirst()
.orElseThrow(() -> exception(projectName));
.orElseThrow(() -> exception(this, projectName));
}
public boolean containsProject(String projectName) {
@@ -114,4 +108,8 @@ public class Projects extends HashSet<ProjectVersion> {
public boolean containsSnapshots() {
return this.stream().anyMatch(ProjectVersion::isSnapshot);
}
public String asList() {
return this.stream().map(version -> version.projectName + ":" + version.version).collect(Collectors.joining(","));
}
}

View File

@@ -1,8 +1,5 @@
package org.springframework.cloud.release.internal.pom;
import static org.assertj.core.api.BDDAssertions.then;
import static org.assertj.core.api.BDDAssertions.thenThrownBy;
import java.io.File;
import java.net.URISyntaxException;
import java.util.Collections;
@@ -13,6 +10,9 @@ import org.junit.Test;
import org.springframework.cloud.release.internal.ReleaserProperties;
import static org.assertj.core.api.BDDAssertions.then;
import static org.assertj.core.api.BDDAssertions.thenThrownBy;
/**
* @author Marcin Grzejszczak
*/