Fixed overriding of properties
This commit is contained in:
@@ -22,6 +22,7 @@ import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -518,4 +519,29 @@ public class ReleaserProperties {
|
||||
+ this.sagan + ", fixedVersions=" + this.fixedVersions + ", metaRelease="
|
||||
+ this.metaRelease + '}';
|
||||
}
|
||||
|
||||
public ReleaserProperties copy() {
|
||||
ReleaserProperties copy = new ReleaserProperties();
|
||||
copy.setFixedVersions(new HashMap<>(this.fixedVersions));
|
||||
copy.setWorkingDir(this.workingDir);
|
||||
Git git = new Git();
|
||||
BeanUtils.copyProperties(this.git, git);
|
||||
copy.setGit(git);
|
||||
Gradle gradle = new Gradle();
|
||||
BeanUtils.copyProperties(this.gradle, gradle);
|
||||
copy.setGradle(gradle);
|
||||
Maven maven = new Maven();
|
||||
BeanUtils.copyProperties(this.maven, maven);
|
||||
copy.setMaven(maven);
|
||||
MetaRelease metaRelease = new MetaRelease();
|
||||
BeanUtils.copyProperties(this.metaRelease, metaRelease);
|
||||
copy.setMetaRelease(metaRelease);
|
||||
Pom pom = new Pom();
|
||||
BeanUtils.copyProperties(this.pom, pom);
|
||||
copy.setPom(pom);
|
||||
Sagan sagan = new Sagan();
|
||||
BeanUtils.copyProperties(this.sagan, sagan);
|
||||
copy.setSagan(sagan);
|
||||
return copy;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
package org.springframework.cloud.release.internal;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import org.assertj.core.api.BDDAssertions;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
@@ -25,4 +32,55 @@ public class ReleaserPropertiesTests {
|
||||
then(properties.getWorkingDir()).isNotEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_return_a_copy_of_properties() throws Exception {
|
||||
ReleaserProperties properties = new ReleaserProperties();
|
||||
properties.setWorkingDir("foo");
|
||||
properties.setFixedVersions(map());
|
||||
properties.getMaven().setBuildCommand("foo2");
|
||||
properties.getGradle().setIgnoredGradleRegex(Arrays.asList("foo3", "foo4"));
|
||||
properties.getMetaRelease().setProjectsToSkip(Arrays.asList("foo5", "foo6"));
|
||||
properties.getGit().setPassword("foo7");
|
||||
properties.getPom().setIgnoredPomRegex(Arrays.asList("foo8", "foo9"));
|
||||
properties.getSagan().setBaseUrl("foo10");
|
||||
|
||||
ReleaserProperties copy = properties.copy();
|
||||
copy.setWorkingDir("bar");
|
||||
copy.setFixedVersions(map2());
|
||||
copy.getMaven().setBuildCommand("bar2");
|
||||
copy.getGradle().setIgnoredGradleRegex(Arrays.asList("bar3", "bar4"));
|
||||
copy.getMetaRelease().setProjectsToSkip(Arrays.asList("bar5", "bar6"));
|
||||
copy.getGit().setPassword("bar7");
|
||||
copy.getPom().setIgnoredPomRegex(Arrays.asList("bar8", "bar9"));
|
||||
copy.getSagan().setBaseUrl("bar10");
|
||||
|
||||
BDDAssertions.then(properties.getWorkingDir())
|
||||
.isEqualTo("foo");
|
||||
BDDAssertions.then(properties.getFixedVersions())
|
||||
.isEqualTo(map());
|
||||
BDDAssertions.then(properties.getMaven().getBuildCommand())
|
||||
.isEqualTo("foo2");
|
||||
BDDAssertions.then(properties.getGradle().getIgnoredGradleRegex())
|
||||
.isEqualTo(Arrays.asList("foo3", "foo4"));
|
||||
BDDAssertions.then(properties.getMetaRelease().getProjectsToSkip())
|
||||
.isEqualTo(Arrays.asList("foo5", "foo6"));
|
||||
BDDAssertions.then(properties.getGit().getPassword())
|
||||
.isEqualTo("foo7");
|
||||
BDDAssertions.then(properties.getPom().getIgnoredPomRegex())
|
||||
.isEqualTo(Arrays.asList("foo8", "foo9"));
|
||||
BDDAssertions.then(properties.getSagan().getBaseUrl())
|
||||
.isEqualTo("foo10");
|
||||
}
|
||||
|
||||
private Map<String, String> map() {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("foo", "bar");
|
||||
return map;
|
||||
}
|
||||
|
||||
private Map<String, String> map2() {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("bar", "foo");
|
||||
return map;
|
||||
}
|
||||
}
|
||||
@@ -43,7 +43,7 @@ class ReleaserPropertiesUpdater {
|
||||
|
||||
private ReleaserProperties updatePropertiesFromFile(ReleaserProperties copy,
|
||||
File clonedProjectFromOrg) {
|
||||
File releaserConfig = new File(clonedProjectFromOrg, "config/releaser.yml");
|
||||
File releaserConfig = releaserConfig(clonedProjectFromOrg);
|
||||
if (releaserConfig.exists()) {
|
||||
try {
|
||||
YamlPropertiesFactoryBean yamlProcessor = new YamlPropertiesFactoryBean();
|
||||
@@ -72,4 +72,8 @@ class ReleaserPropertiesUpdater {
|
||||
copy.setWorkingDir(clonedProjectFromOrg.getAbsolutePath());
|
||||
return copy;
|
||||
}
|
||||
|
||||
File releaserConfig(File clonedProjectFromOrg) {
|
||||
return new File(clonedProjectFromOrg, "config/releaser.yml");
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.springframework.cloud.release.internal.spring;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -59,9 +60,11 @@ public class SpringReleaser {
|
||||
log.info("Meta Release picked. Will iterate over all projects and perform release of each one");
|
||||
this.properties.getGit().setFetchVersionsFromGit(false);
|
||||
this.properties.getMetaRelease().setEnabled(options.metaRelease);
|
||||
ReleaserProperties original = clonePropertiesForProject(this.properties);
|
||||
ReleaserProperties original = this.properties.copy();
|
||||
log.info("The following properties were found [{}]", original);
|
||||
metaReleaseProjects(options)
|
||||
.forEach(project -> processProjectForMetaRelease(clonePropertiesForProject(original), options, project));
|
||||
.forEach(project ->
|
||||
processProjectForMetaRelease(original.copy(), options, project));
|
||||
} else {
|
||||
log.info("Single project release picked. Will release only the current project");
|
||||
File projectFolder = projectFolder();
|
||||
@@ -70,11 +73,10 @@ public class SpringReleaser {
|
||||
this.optionsProcessor.postReleaseOptions(options, postReleaseOptionsAgs(options, projectsAndVersion));
|
||||
}
|
||||
|
||||
private void processProjectForMetaRelease(ReleaserProperties copy, Options options, String project) {
|
||||
void processProjectForMetaRelease(ReleaserProperties copy, Options options, String project) {
|
||||
log.info("Original properties [\n\n{}\n\n]", copy);
|
||||
File clonedProjectFromOrg = this.releaser.clonedProjectFromOrg(project);
|
||||
ReleaserProperties updatedProps = updatePropertiesIfCustomConfigPresent(copy, clonedProjectFromOrg);
|
||||
this.updater.updateProperties(updatedProps);
|
||||
updatePropertiesIfCustomConfigPresent(copy, clonedProjectFromOrg);
|
||||
log.info("Successfully cloned the project [{}] to [{}]", project, clonedProjectFromOrg);
|
||||
try {
|
||||
processProject(options, clonedProjectFromOrg, TaskType.RELEASE);
|
||||
@@ -85,18 +87,12 @@ public class SpringReleaser {
|
||||
}
|
||||
}
|
||||
|
||||
private ReleaserProperties clonePropertiesForProject(ReleaserProperties from) {
|
||||
ReleaserProperties copy = new ReleaserProperties();
|
||||
BeanUtils.copyProperties(from, copy);
|
||||
return copy;
|
||||
}
|
||||
|
||||
private ReleaserProperties updatePropertiesIfCustomConfigPresent(ReleaserProperties copy,
|
||||
File clonedProjectFromOrg) {
|
||||
return this.updater.updateProperties(copy, clonedProjectFromOrg);
|
||||
}
|
||||
|
||||
private List<String> metaReleaseProjects(Options options) {
|
||||
List<String> metaReleaseProjects(Options options) {
|
||||
List<String> projects = new ArrayList<>(this.properties.getFixedVersions().keySet());
|
||||
log.info("List of projects that should not be cloned {}", this.properties.getMetaRelease().getProjectsToSkip());
|
||||
List<String> filteredProjects = projects.stream()
|
||||
@@ -187,7 +183,7 @@ public class SpringReleaser {
|
||||
}
|
||||
}
|
||||
|
||||
private ProjectsAndVersion processProject(Options options, File project, TaskType taskType) {
|
||||
ProjectsAndVersion processProject(Options options, File project, TaskType taskType) {
|
||||
ProjectsAndVersion projectsAndVersion = projects(project);
|
||||
ProjectVersion originalVersion = new ProjectVersion(project);
|
||||
final Args defaultArgs = new Args(this.releaser, project, projectsAndVersion.projectVersions,
|
||||
|
||||
@@ -0,0 +1,143 @@
|
||||
package org.springframework.cloud.release.internal.spring;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
import org.assertj.core.api.BDDAssertions;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.BDDMockito;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.springframework.cloud.release.internal.Releaser;
|
||||
import org.springframework.cloud.release.internal.ReleaserProperties;
|
||||
import org.springframework.cloud.release.internal.ReleaserPropertiesAware;
|
||||
import org.springframework.cloud.release.internal.options.Options;
|
||||
import org.springframework.cloud.release.internal.options.OptionsBuilder;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class SpringReleaserTests {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(SpringReleaserTests.class);
|
||||
|
||||
@Mock Releaser releaser;
|
||||
ReleaserProperties properties = properties();
|
||||
@Mock OptionsProcessor optionsProcessor;
|
||||
@Mock ApplicationContext context;
|
||||
Aware1 aware1 = new Aware1();
|
||||
Aware2 aware2 = new Aware2();
|
||||
ReleaserPropertiesUpdater updater;
|
||||
File releaserUpdater = new File(ReleaserPropertiesUpdaterTests.class
|
||||
.getResource("/projects/releaser-updater/config/releaser.yml").toURI());
|
||||
|
||||
public SpringReleaserTests() throws URISyntaxException {
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
BDDMockito.given(this.releaser.clonedProjectFromOrg(BDDMockito.anyString()))
|
||||
.willReturn(new File("/whatever"));
|
||||
BDDMockito.given(this.context.getBeansOfType(ReleaserPropertiesAware.class))
|
||||
.willReturn(awareBeans());
|
||||
this.updater = new ReleaserPropertiesUpdater(this.context) {
|
||||
|
||||
int counter = 0;
|
||||
|
||||
@Override
|
||||
File releaserConfig(File clonedProjectFromOrg) {
|
||||
if (this.counter == 0) {
|
||||
log.info("First run");
|
||||
this.counter = this.counter + 1;
|
||||
return releaserUpdater;
|
||||
}
|
||||
log.info("Second run");
|
||||
return new File("does/not/exist");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private Map<String, ReleaserPropertiesAware> awareBeans() {
|
||||
Map<String, ReleaserPropertiesAware> aware = new HashMap<>();
|
||||
aware.put("aware1", this.aware1);
|
||||
aware.put("aware2", this.aware2);
|
||||
return aware;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_make_a_copy_of_properties() {
|
||||
SpringReleaser releaser = stubbedSpringReleaser();
|
||||
|
||||
releaser.release(new OptionsBuilder().metaRelease(true).options());
|
||||
|
||||
assertBuildCommand(this.aware1.properties);
|
||||
assertBuildCommand(this.aware2.properties);
|
||||
}
|
||||
|
||||
private void assertBuildCommand(Queue<ReleaserProperties> properties) {
|
||||
BDDAssertions.then(properties.poll().getMaven().getBuildCommand())
|
||||
.isEqualTo("./scripts/noIntegration.sh");
|
||||
BDDAssertions.then(properties.poll().getMaven().getBuildCommand())
|
||||
.isEqualTo("build");
|
||||
}
|
||||
|
||||
private SpringReleaser stubbedSpringReleaser() {
|
||||
return new SpringReleaser(this.releaser, this.properties,
|
||||
this.optionsProcessor, this.updater) {
|
||||
|
||||
@Override
|
||||
Args postReleaseOptionsAgs(Options options, ProjectsAndVersion projectsAndVersion) {
|
||||
return new Args(TaskType.RELEASE);
|
||||
}
|
||||
|
||||
@Override
|
||||
List<String> metaReleaseProjects(Options options) {
|
||||
return Arrays.asList("aware1", "aware2");
|
||||
}
|
||||
|
||||
@Override
|
||||
ProjectsAndVersion processProject(Options options, File project, TaskType taskType) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private ReleaserProperties properties() {
|
||||
ReleaserProperties properties = new ReleaserProperties();
|
||||
properties.getMaven().setBuildCommand("build");
|
||||
return properties;
|
||||
}
|
||||
}
|
||||
|
||||
class Aware1 implements ReleaserPropertiesAware {
|
||||
|
||||
Queue<ReleaserProperties> properties = new LinkedBlockingQueue<>();
|
||||
|
||||
@Override
|
||||
public void setReleaserProperties(ReleaserProperties properties) {
|
||||
this.properties.add(properties);
|
||||
}
|
||||
}
|
||||
|
||||
class Aware2 implements ReleaserPropertiesAware {
|
||||
|
||||
Queue<ReleaserProperties> properties = new LinkedBlockingQueue<>();
|
||||
|
||||
@Override
|
||||
public void setReleaserProperties(ReleaserProperties properties) {
|
||||
this.properties.add(properties);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user