Fixed overriding of properties
This commit is contained in:
@@ -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