From bfd6333c445b9c55f95212ab8643346e6079017b Mon Sep 17 00:00:00 2001 From: Pete Cornish Date: Tue, 20 Sep 2016 14:50:49 +0100 Subject: [PATCH 1/3] New development version. --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index a0df462..3fe8b82 100644 --- a/build.gradle +++ b/build.gradle @@ -15,7 +15,7 @@ */ group 'io.apiman.cli' -version '0.2.1' +version '0.2.2-SNAPSHOT' buildscript { repositories { From a6341a8b37a55eb1a830a4f53867bffaaafc011c Mon Sep 17 00:00:00 2001 From: Pete Cornish Date: Tue, 20 Sep 2016 19:22:16 +0100 Subject: [PATCH 2/3] Adds support for XML format Java properties files. Adds support for specifying multiple properties files. --- .../core/declarative/command/ApplyCommand.java | 16 ++++++++++------ .../io/apiman/cli/command/DeclarativeTest.java | 12 ++++++++++-- src/test/resources/declaration-test.properties | 2 -- src/test/resources/placeholder-test.properties | 1 + src/test/resources/placeholder-test.xml | 5 +++++ 5 files changed, 26 insertions(+), 10 deletions(-) delete mode 100644 src/test/resources/declaration-test.properties create mode 100644 src/test/resources/placeholder-test.properties create mode 100644 src/test/resources/placeholder-test.xml diff --git a/src/main/java/io/apiman/cli/core/declarative/command/ApplyCommand.java b/src/main/java/io/apiman/cli/core/declarative/command/ApplyCommand.java index 95ffaf6..55491d5 100644 --- a/src/main/java/io/apiman/cli/core/declarative/command/ApplyCommand.java +++ b/src/main/java/io/apiman/cli/core/declarative/command/ApplyCommand.java @@ -75,7 +75,7 @@ public class ApplyCommand extends AbstractFinalCommand { private List properties; @Option(name = "--propertiesFile", usage = "Properties file") - private Path propertiesFile; + private List propertiesFiles; @Option(name = "--serverVersion", aliases = {"-sv"}, usage = "Management API server version") private ManagementApiVersion serverVersion = ManagementApiVersion.DEFAULT_VERSION; @@ -97,18 +97,22 @@ public void applyDeclaration() { final Map 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; @@ -453,8 +457,8 @@ public void setProperties(List properties) { this.properties = properties; } - public void setPropertiesFile(Path propertiesFile) { - this.propertiesFile = propertiesFile; + public void setPropertiesFiles(List propertiesFiles) { + this.propertiesFiles = propertiesFiles; } public void setServerAddress(String serverAddress) { diff --git a/src/test/java/io/apiman/cli/command/DeclarativeTest.java b/src/test/java/io/apiman/cli/command/DeclarativeTest.java index e734c6d..b654ae0 100644 --- a/src/test/java/io/apiman/cli/command/DeclarativeTest.java +++ b/src/test/java/io/apiman/cli/command/DeclarativeTest.java @@ -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: + *
    + *
  • the command line (using '-P key=value')
  • + *
  • a key=value format Java properties file (.properties)
  • + *
  • an XML format Java properties file (.xml)
  • + *
* * @throws Exception */ @@ -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(); } diff --git a/src/test/resources/declaration-test.properties b/src/test/resources/declaration-test.properties deleted file mode 100644 index 479175b..0000000 --- a/src/test/resources/declaration-test.properties +++ /dev/null @@ -1,2 +0,0 @@ -gw.username=user -gw.password=Pa$$word1! diff --git a/src/test/resources/placeholder-test.properties b/src/test/resources/placeholder-test.properties new file mode 100644 index 0000000..5901f66 --- /dev/null +++ b/src/test/resources/placeholder-test.properties @@ -0,0 +1 @@ +gw.username=user diff --git a/src/test/resources/placeholder-test.xml b/src/test/resources/placeholder-test.xml new file mode 100644 index 0000000..466e2ca --- /dev/null +++ b/src/test/resources/placeholder-test.xml @@ -0,0 +1,5 @@ + + + + + From f142530b4f5ed5e4df882544cdfbbb1a9e151d28 Mon Sep 17 00:00:00 2001 From: Pete Cornish Date: Tue, 20 Sep 2016 19:23:14 +0100 Subject: [PATCH 3/3] Release 0.2.2. --- CHANGELOG.md | 5 +++-- build.gradle | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4209f13..0c77b89 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/build.gradle b/build.gradle index 3fe8b82..3defcfa 100644 --- a/build.gradle +++ b/build.gradle @@ -15,7 +15,7 @@ */ group 'io.apiman.cli' -version '0.2.2-SNAPSHOT' +version '0.2.2' buildscript { repositories {