KARAF-3982: add 'prepend' support.
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/3c2afb20 Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/3c2afb20 Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/3c2afb20 Branch: refs/heads/master Commit: 3c2afb204d457ea98e0b9130196b329d1eb1c334 Parents: 1ad8aa9 Author: Benson Margulies <[email protected]> Authored: Sun Sep 13 07:26:08 2015 -0400 Committer: Benson Margulies <[email protected]> Committed: Sun Sep 13 07:38:11 2015 -0400 ---------------------------------------------------------------------- .../org/apache/karaf/tooling/AssemblyMojo.java | 6 +++++ .../karaf-maven-plugin/src/site/apt/usage.apt | 6 ++++- tooling/utils/pom.xml | 2 ++ .../karaf/tools/utils/KarafPropertiesFile.java | 13 ++++++---- tooling/utils/src/main/mdo/edits.mdo | 27 ++++++++++++++++++-- .../tools/utils/KarafPropertiesEditorTest.java | 3 ++- .../org/apache/karaf/tools/utils/test-edits.xml | 6 +++++ 7 files changed, 54 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/karaf/blob/3c2afb20/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/AssemblyMojo.java ---------------------------------------------------------------------- diff --git a/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/AssemblyMojo.java b/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/AssemblyMojo.java index c0653c5..ff634ee 100644 --- a/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/AssemblyMojo.java +++ b/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/AssemblyMojo.java @@ -199,6 +199,12 @@ public class AssemblyMojo extends MojoSupport { <key>org.osgi.framework.system.capabilities</key> <value>my-magic-capability</value> </edit> + <edit> + <file>config.properties</file> + <operation prepend='true'>extend</operation> + <key>some-other-list</key> + <value>my-value-goes-first</value> + </edit> </edits> </property-edits> </pre> http://git-wip-us.apache.org/repos/asf/karaf/blob/3c2afb20/tooling/karaf-maven-plugin/src/site/apt/usage.apt ---------------------------------------------------------------------- diff --git a/tooling/karaf-maven-plugin/src/site/apt/usage.apt b/tooling/karaf-maven-plugin/src/site/apt/usage.apt index 1194e34..1fbf3e4 100644 --- a/tooling/karaf-maven-plugin/src/site/apt/usage.apt +++ b/tooling/karaf-maven-plugin/src/site/apt/usage.apt @@ -186,6 +186,10 @@ Packagings </plugin> +---+ + property-file-edits specifies the location of an XML file that specifies edits to 'etc' files as they are + copied from the reference to the assembly. By default, the value of this parameter is src/main/karaf/assembly-property-edits.xml; + if you add a file at that location, the plugin will apply the edits you specify in it. + defaultStartLevel determines the start level of bundles that do not have startLevel set in the feature xml descriptor. If not set, the default is 30. Project dependencies that are feature or kar packaging are treated differently depending on whether they are scope runtime, or compile/provided. Runtime scope dependencies are installed @@ -204,4 +208,4 @@ Packagings - adds the feature project dependencies and features in kar dependencies of scope runtime to the features service configuration. The result is packed up into zip and tar.gz assemblies. Normally to get a working server you would include at least the karaf-framework kar and most likely the karaf-full kar: these are used - to assemble the minimal and full server. \ No newline at end of file + to assemble the minimal and full server. http://git-wip-us.apache.org/repos/asf/karaf/blob/3c2afb20/tooling/utils/pom.xml ---------------------------------------------------------------------- diff --git a/tooling/utils/pom.xml b/tooling/utils/pom.xml index 8476f28..03ec561 100644 --- a/tooling/utils/pom.xml +++ b/tooling/utils/pom.xml @@ -53,11 +53,13 @@ <version>1.8.3</version> <executions> <execution> + <phase>generate-sources</phase> <goals> <goal>java</goal> <goal>stax-reader</goal> <goal>stax-writer</goal> <goal>xsd</goal> + <goal>xdoc</goal> </goals> </execution> </executions> http://git-wip-us.apache.org/repos/asf/karaf/blob/3c2afb20/tooling/utils/src/main/java/org/apache/karaf/tools/utils/KarafPropertiesFile.java ---------------------------------------------------------------------- diff --git a/tooling/utils/src/main/java/org/apache/karaf/tools/utils/KarafPropertiesFile.java b/tooling/utils/src/main/java/org/apache/karaf/tools/utils/KarafPropertiesFile.java index ef75d75..43efd73 100644 --- a/tooling/utils/src/main/java/org/apache/karaf/tools/utils/KarafPropertiesFile.java +++ b/tooling/utils/src/main/java/org/apache/karaf/tools/utils/KarafPropertiesFile.java @@ -60,18 +60,21 @@ public class KarafPropertiesFile { properties.put(key, value); } - public void extend(String key, String value) { + public void extend(String key, String value, boolean prepend) { if (properties.get(key) == null) { properties.put(key, value); return; + } else if (prepend) { + properties.put(key, JoinUtil.join(value, (String) properties.get(key))); + } else { + properties.put(key, JoinUtil.join((String) properties.get(key), value)); } - properties.put(key, JoinUtil.join((String)properties.get(key), value)); } public void apply(KarafPropertyEdit editSpec) { - if ("extend".equals(editSpec.getOperation())) { - extend(editSpec.getKey(), editSpec.getValue()); - } else if ("put".equals(editSpec.getOperation())) { + if ("extend".equals(editSpec.getOperation().getOperation())) { + extend(editSpec.getKey(), editSpec.getValue(), editSpec.getOperation().isPrepend()); + } else if ("put".equals(editSpec.getOperation().getOperation())) { put(editSpec.getKey(), editSpec.getValue()); } else { throw new IllegalArgumentException("Operation must be 'extend' or 'put', not " + editSpec.getOperation()); http://git-wip-us.apache.org/repos/asf/karaf/blob/3c2afb20/tooling/utils/src/main/mdo/edits.mdo ---------------------------------------------------------------------- diff --git a/tooling/utils/src/main/mdo/edits.mdo b/tooling/utils/src/main/mdo/edits.mdo index 5dfc48e..b0d3f86 100644 --- a/tooling/utils/src/main/mdo/edits.mdo +++ b/tooling/utils/src/main/mdo/edits.mdo @@ -51,6 +51,25 @@ </field> </fields> </class> + <class> + <name>Operation</name> + <fields> + <field xml.content="true"> + <name>operation</name> + <type>String</type> + <description> + 'extend' to extend the existing value, 'put' to replace. + </description> + <required>true</required> + </field> + <field xml.attribute="true"> + <name>prepend</name> + <version>1.0.0</version> + <type>boolean</type> + <description><![CDATA[for the 'extend' operation, indicates that the value should be placed at the head of the list.]]></description> + </field> + </fields> + </class> <class xml.tagName="edit"> <name>KarafPropertyEdit</name> <version>1.0.0+</version> @@ -61,12 +80,16 @@ <field> <name>operation</name> <version>1.0.0+</version> - <type>String</type> + <association> + <type>Operation</type> + <multiplicity>1</multiplicity> + </association> <description> - 'extend' to extend the existing value, 'put' to replace. + The operation to perform: 'put' or 'extend'. </description> <required>true</required> </field> + <field> <name>file</name> <version>1.0.0+</version> http://git-wip-us.apache.org/repos/asf/karaf/blob/3c2afb20/tooling/utils/src/test/java/org/apache/karaf/tools/utils/KarafPropertiesEditorTest.java ---------------------------------------------------------------------- diff --git a/tooling/utils/src/test/java/org/apache/karaf/tools/utils/KarafPropertiesEditorTest.java b/tooling/utils/src/test/java/org/apache/karaf/tools/utils/KarafPropertiesEditorTest.java index e49226e..0705ede 100644 --- a/tooling/utils/src/test/java/org/apache/karaf/tools/utils/KarafPropertiesEditorTest.java +++ b/tooling/utils/src/test/java/org/apache/karaf/tools/utils/KarafPropertiesEditorTest.java @@ -51,6 +51,7 @@ public class KarafPropertiesEditorTest { Path path = FileSystems.getDefault().getPath("target"); Path outputEtc = Files.createTempDirectory(path, "test-etc"); + outputEtc.toFile().deleteOnExit(); KarafPropertiesEditor editor = new KarafPropertiesEditor(); editor.setInputEtc(new File(ETC_TO_START_WITH)) @@ -64,7 +65,7 @@ public class KarafPropertiesEditorTest { properties.load(resultInputStream); } assertEquals("equinox", properties.getProperty("karaf.framework")); - assertEquals("root,toor", properties.getProperty("karaf.name")); + assertEquals("prepended,root,toor", properties.getProperty("karaf.name")); resultConfigProps = new File(outputEtc.toFile(), "jre.properties"); try (InputStream resultInputStream = new FileInputStream(resultConfigProps)) { http://git-wip-us.apache.org/repos/asf/karaf/blob/3c2afb20/tooling/utils/src/test/resources/org/apache/karaf/tools/utils/test-edits.xml ---------------------------------------------------------------------- diff --git a/tooling/utils/src/test/resources/org/apache/karaf/tools/utils/test-edits.xml b/tooling/utils/src/test/resources/org/apache/karaf/tools/utils/test-edits.xml index 59b792b..1fba57f 100644 --- a/tooling/utils/src/test/resources/org/apache/karaf/tools/utils/test-edits.xml +++ b/tooling/utils/src/test/resources/org/apache/karaf/tools/utils/test-edits.xml @@ -42,5 +42,11 @@ <key>test-add-two</key> <value>This is the gun that shoots cereal</value> </edit> + <edit> + <file>config.properties</file> + <operation prepend="true">extend</operation> + <key>karaf.name</key> + <value>prepended</value> + </edit> </edits> </property-edits>
