Fixed the YAML issue; fixes gh-88
This commit is contained in:
@@ -36,10 +36,14 @@
|
||||
<version>5.0.3</version>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<!--<dependency>-->
|
||||
<!--<groupId>com.esotericsoftware.yamlbeans</groupId>-->
|
||||
<!--<artifactId>yamlbeans</artifactId>-->
|
||||
<!--<version>1.13</version>-->
|
||||
<!--</dependency>-->
|
||||
<dependency>
|
||||
<groupId>com.esotericsoftware.yamlbeans</groupId>
|
||||
<artifactId>yamlbeans</artifactId>
|
||||
<version>1.13</version>
|
||||
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
||||
<artifactId>jackson-dataformat-yaml</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
package org.springframework.cloud.release.internal.spring;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.esotericsoftware.yamlbeans.YamlReader;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.config.YamlMapFactoryBean;
|
||||
import org.springframework.beans.factory.config.YamlPropertiesFactoryBean;
|
||||
import org.springframework.boot.context.properties.bind.Binder;
|
||||
import org.springframework.boot.context.properties.source.MapConfigurationPropertySource;
|
||||
import org.springframework.cloud.release.internal.ReleaserProperties;
|
||||
import org.springframework.cloud.release.internal.ReleaserPropertiesAware;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
@@ -41,10 +41,16 @@ class ReleaserPropertiesUpdater {
|
||||
File releaserConfig = new File(clonedProjectFromOrg, "config/releaser.yml");
|
||||
if (releaserConfig.exists()) {
|
||||
try {
|
||||
Object read = new YamlReader(new FileReader(releaserConfig)).read();
|
||||
YamlPropertiesFactoryBean yamlProcessor = new YamlPropertiesFactoryBean();
|
||||
yamlProcessor.setResources(new FileSystemResource(releaserConfig));
|
||||
Properties properties = yamlProcessor.getObject();
|
||||
ReleaserProperties releaserProperties = new Binder(
|
||||
new MapConfigurationPropertySource((Map) read))
|
||||
.bind("releaser", ReleaserProperties.class).get();
|
||||
new MapConfigurationPropertySource(properties.entrySet().stream().collect(
|
||||
Collectors.toMap(
|
||||
e -> e.getKey().toString(),
|
||||
e -> e.getValue().toString()
|
||||
)
|
||||
))).bind("releaser", ReleaserProperties.class).get();
|
||||
log.info("config/releaser.yml found. Will update the current properties");
|
||||
copy.setMaven(releaserProperties.getMaven());
|
||||
copy.setGradle(releaserProperties.getGradle());
|
||||
|
||||
@@ -53,7 +53,24 @@ public class ReleaserPropertiesIntegrationTests {
|
||||
ReleaserPropertiesHaving having = ((ReleaserPropertiesHaving) aware);
|
||||
BDDAssertions.then(having.properties.getPom().getBranch()).isEqualTo("barrrr");
|
||||
BDDAssertions.then(having.properties.getMaven().getBuildCommand()).isEqualTo("./scripts/noIntegration.sh");
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@Test public void should_update_properties_including_existing_releaser_config_for_netflix() {
|
||||
ReleaserProperties properties = new ReleaserProperties();
|
||||
properties.getPom().setBranch("bazzzz");
|
||||
URL resource = ReleaserPropertiesIntegrationTests.class
|
||||
.getResource("/projects/project-with-netflix-config");
|
||||
|
||||
new ReleaserPropertiesUpdater(this.context).updateProperties(properties,
|
||||
new File(resource.getFile()));
|
||||
|
||||
BDDAssertions.then(this.propertiesAware).hasSize(2);
|
||||
this.propertiesAware.forEach(aware -> {
|
||||
ReleaserPropertiesHaving having = ((ReleaserPropertiesHaving) aware);
|
||||
BDDAssertions.then(having.properties.getPom().getBranch()).isEqualTo("bazzzz");
|
||||
BDDAssertions.then(having.properties.getMaven().getBuildCommand()).isEqualTo("./scripts/build.sh {{systemProps}}");
|
||||
});
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
releaser:
|
||||
maven:
|
||||
buildCommand: ./scripts/build.sh {{systemProps}}
|
||||
Reference in New Issue
Block a user