You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by jb...@apache.org on 2019/03/26 07:00:15 UTC

[karaf] branch karaf-4.2.x updated: KARAF-6209: Add SortedProperties class to karaf tooling

This is an automated email from the ASF dual-hosted git repository.

jbonofre pushed a commit to branch karaf-4.2.x
in repository https://gitbox.apache.org/repos/asf/karaf.git


The following commit(s) were added to refs/heads/karaf-4.2.x by this push:
     new 82e0346  KARAF-6209: Add SortedProperties class to karaf tooling
82e0346 is described below

commit 82e03467430b82f4ccffc43827aed3e7381129f7
Author: Benjamin Graf <be...@gmx.net>
AuthorDate: Sun Mar 24 17:44:52 2019 +0100

    KARAF-6209: Add SortedProperties class to karaf tooling
---
 .../karaf/tools/utils/KarafPropertiesFile.java     |  5 +--
 .../apache/karaf/tools/utils/SortedProperties.java | 47 ++++++++++++++++++++++
 2 files changed, 49 insertions(+), 3 deletions(-)

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 11bd1c7..2c1a962 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
@@ -23,11 +23,10 @@ import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
-import java.util.Properties;
 
 public class KarafPropertiesFile {
 
-    private final Properties properties;
+    private final SortedProperties properties;
     private final File propertyFile;
 
     public KarafPropertiesFile(File karafHome, String location) {
@@ -36,7 +35,7 @@ public class KarafPropertiesFile {
 
     public KarafPropertiesFile(File propertyFile) {
         this.propertyFile = propertyFile;
-        properties = new Properties();
+        properties = new SortedProperties();
     }
 
     private static File homedPropFile(File karafHome, String location) {
diff --git a/tooling/utils/src/main/java/org/apache/karaf/tools/utils/SortedProperties.java b/tooling/utils/src/main/java/org/apache/karaf/tools/utils/SortedProperties.java
new file mode 100644
index 0000000..d1c171a
--- /dev/null
+++ b/tooling/utils/src/main/java/org/apache/karaf/tools/utils/SortedProperties.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.karaf.tools.utils;
+
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+import java.util.TreeSet;
+
+/**
+ * Sort properties for better readability.
+ */
+public class SortedProperties extends Properties {
+
+    private static final long serialVersionUID = 1L;
+
+    @Override
+    public Set<Object> keySet() {
+        return Collections.unmodifiableSet(new TreeSet<>(super.keySet()));
+    }
+
+    @Override
+    public Set<Map.Entry<Object, Object>> entrySet() {
+        return Collections.unmodifiableSet(new TreeSet<>(super.entrySet()));
+    }
+
+    @Override
+    public synchronized Enumeration<Object> keys() {
+        return Collections.enumeration(new TreeSet<>(super.keySet()));
+    }
+}