Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
outofcoffee committed Sep 20, 2016
2 parents 6e5d083 + f142530 commit e80196e
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 13 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]
## [0.2.2] - 2016-09-20
### Added
- ...
- Adds support for XML format Java properties files.
- Adds support for specifying multiple properties files.

## [0.2.1] - 2016-09-20
### Added
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

group 'io.apiman.cli'
version '0.2.1'
version '0.2.2'

buildscript {
repositories {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public class ApplyCommand extends AbstractFinalCommand {
private List<String> properties;

@Option(name = "--propertiesFile", usage = "Properties file")
private Path propertiesFile;
private List<Path> propertiesFiles;

@Option(name = "--serverVersion", aliases = {"-sv"}, usage = "Management API server version")
private ManagementApiVersion serverVersion = ManagementApiVersion.DEFAULT_VERSION;
Expand All @@ -97,18 +97,22 @@ public void applyDeclaration() {
final Map<String, String> parsedProperties = BeanUtil.parseReplacements(properties);

// check for properties file
if (null != propertiesFile) {
ofNullable(propertiesFiles).ifPresent(propertiesFiles -> propertiesFiles.forEach(propertiesFile -> {
LOGGER.trace("Loading properties file: {}", propertiesFile);

final Properties fileProperties = new Properties();
try (final InputStream propertiesIn = Files.newInputStream(propertiesFile, StandardOpenOption.READ)) {
fileProperties.load(propertiesIn);
if (propertiesFile.toAbsolutePath().toString().toLowerCase().endsWith(".xml")) {
fileProperties.loadFromXML(propertiesIn);
} else {
fileProperties.load(propertiesIn);
}
} catch (IOException e) {
throw new CommandException(String.format("Error loading properties file: %s", propertiesFile), e);
}

fileProperties.forEach((key, value) -> parsedProperties.put((String) key, (String) value));
}
}));

final Declaration declaration;

Expand Down Expand Up @@ -453,8 +457,8 @@ public void setProperties(List<String> properties) {
this.properties = properties;
}

public void setPropertiesFile(Path propertiesFile) {
this.propertiesFile = propertiesFile;
public void setPropertiesFiles(List<Path> propertiesFiles) {
this.propertiesFiles = propertiesFiles;
}

public void setServerAddress(String serverAddress) {
Expand Down
12 changes: 10 additions & 2 deletions src/test/java/io/apiman/cli/command/DeclarativeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,12 @@ public void testApplyDeclaration_Full() throws Exception {

/**
* Expect that the configuration in the declaration can be applied, resolving placeholders passed
* from the command line as well as from a properties file.
* from:
* <ul>
* <li>the command line (using '-P key=value')</li>
* <li>a key=value format Java properties file (.properties)</li>
* <li>an XML format Java properties file (.xml)</li>
* </ul>
*
* @throws Exception
*/
Expand All @@ -99,7 +104,10 @@ public void testApplyDeclaration_WithProperties() throws Exception {

command.setDeclarationFile(Paths.get(DeclarativeTest.class.getResource("/simple-placeholders.yml").toURI()));
command.setProperties(inlineProperties);
command.setPropertiesFile(Paths.get(DeclarativeTest.class.getResource("/declaration-test.properties").toURI()));
command.setPropertiesFiles(Lists.newArrayList(
Paths.get(DeclarativeTest.class.getResource("/placeholder-test.properties").toURI()),
Paths.get(DeclarativeTest.class.getResource("/placeholder-test.xml").toURI())
));

command.applyDeclaration();
}
Expand Down
2 changes: 0 additions & 2 deletions src/test/resources/declaration-test.properties

This file was deleted.

1 change: 1 addition & 0 deletions src/test/resources/placeholder-test.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
gw.username=user
5 changes: 5 additions & 0 deletions src/test/resources/placeholder-test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
<entry key="gw.password"><![CDATA[Pa$$word1!]]></entry>
</properties>

0 comments on commit e80196e

Please sign in to comment.