Made gradle updater less birttle
This commit is contained in:
@@ -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());
|
||||
|
||||
@@ -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(","));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user