maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject [maven-shade-plugin] branch MSHADE-322 updated: extracting SortedProperties to be able to reuse it in the test validating properties keys stability + fixing related test
Date Sun, 11 Aug 2019 18:04:31 GMT
This is an automated email from the ASF dual-hosted git repository.

rmannibucau pushed a commit to branch MSHADE-322
in repository https://gitbox.apache.org/repos/asf/maven-shade-plugin.git


The following commit(s) were added to refs/heads/MSHADE-322 by this push:
     new 7b28524  extracting SortedProperties to be able to reuse it in the test validating
properties keys stability + fixing related test
7b28524 is described below

commit 7b285244d569d69fe0d1b00738aa855930f0d7ce
Author: Romain Manni-Bucau <rmannibucau@apache.org>
AuthorDate: Sun Aug 11 20:04:20 2019 +0200

    extracting SortedProperties to be able to reuse it in the test validating properties keys
stability + fixing related test
---
 .../resource/properties/PropertiesTransformer.java | 29 +--------
 .../resource/properties/SortedProperties.java      | 76 ++++++++++++++++++++++
 .../properties/PropertiesTransformerTest.java      |  6 +-
 3 files changed, 80 insertions(+), 31 deletions(-)

diff --git a/src/main/java/org/apache/maven/plugins/shade/resource/properties/PropertiesTransformer.java
b/src/main/java/org/apache/maven/plugins/shade/resource/properties/PropertiesTransformer.java
index a6a7aff..2f4cad3 100644
--- a/src/main/java/org/apache/maven/plugins/shade/resource/properties/PropertiesTransformer.java
+++ b/src/main/java/org/apache/maven/plugins/shade/resource/properties/PropertiesTransformer.java
@@ -197,34 +197,7 @@ public class PropertiesTransformer implements ResourceTransformer
 
     private static Properties mergeProperties( final List<Properties> sortedProperties
)
     {
-        final Properties mergedProperties = new Properties()
-        {
-            @Override
-            public synchronized Enumeration<Object> keys() // ensure it is sorted to
be deterministic
-            {
-                final List<String> keys = new LinkedList<>();
-                for ( Object k : super.keySet() )
-                {
-                    keys.add( (String) k );
-                }
-                Collections.sort( keys );
-                final Iterator<String> it = keys.iterator();
-                return new Enumeration<Object>()
-                {
-                    @Override
-                    public boolean hasMoreElements()
-                    {
-                        return it.hasNext();
-                    }
-
-                    @Override
-                    public Object nextElement()
-                    {
-                        return it.next();
-                    }
-                };
-            }
-        };
+        final Properties mergedProperties = new SortedProperties();
         for ( final Properties p : sortedProperties )
         {
             mergedProperties.putAll( p );
diff --git a/src/main/java/org/apache/maven/plugins/shade/resource/properties/SortedProperties.java
b/src/main/java/org/apache/maven/plugins/shade/resource/properties/SortedProperties.java
new file mode 100644
index 0000000..9da99c4
--- /dev/null
+++ b/src/main/java/org/apache/maven/plugins/shade/resource/properties/SortedProperties.java
@@ -0,0 +1,76 @@
+package org.apache.maven.plugins.shade.resource.properties;
+
+/*
+ * 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.
+ */
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+public class SortedProperties extends Properties
+{
+    @Override
+    public Set<Map.Entry<Object, Object>> entrySet()
+    {
+        final List<Map.Entry<Object, Object>> entries = new ArrayList<>(
super.entrySet() );
+        Collections.sort( entries, new Comparator<Map.Entry<Object, Object>>()
+        {
+            @Override
+            public int compare( Map.Entry<Object, Object> o1, Map.Entry<Object,
Object> o2 )
+            {
+                return String.valueOf( o1.getKey() ).compareTo( String.valueOf( o2.getKey()
) );
+            }
+        });
+        return new HashSet<>( entries );
+    }
+
+    @Override
+    public synchronized Enumeration<Object> keys() // ensure it is sorted to be deterministic
+    {
+        final List<String> keys = new LinkedList<>();
+        for ( Object k : super.keySet() )
+        {
+            keys.add( (String) k );
+        }
+        Collections.sort( keys );
+        final Iterator<String> it = keys.iterator();
+        return new Enumeration<Object>()
+        {
+            @Override
+            public boolean hasMoreElements()
+            {
+                return it.hasNext();
+            }
+
+            @Override
+            public Object nextElement()
+            {
+                return it.next();
+            }
+        };
+    }
+}
diff --git a/src/test/java/org/apache/maven/plugins/shade/resource/properties/PropertiesTransformerTest.java
b/src/test/java/org/apache/maven/plugins/shade/resource/properties/PropertiesTransformerTest.java
index e0d105c..330c379 100644
--- a/src/test/java/org/apache/maven/plugins/shade/resource/properties/PropertiesTransformerTest.java
+++ b/src/test/java/org/apache/maven/plugins/shade/resource/properties/PropertiesTransformerTest.java
@@ -48,7 +48,7 @@ public class PropertiesTransformerTest
     @Test
     public void propertiesRewritingIsStable() throws IOException
     {
-        final Properties properties = new Properties();
+        final Properties properties = new SortedProperties();
         properties.setProperty("a", "1");
         properties.setProperty("b", "2");
 
@@ -61,8 +61,8 @@ public class PropertiesTransformerTest
 
         assertEquals(
             "# Merged by maven-shade-plugin\n" +
-            "b=2\n" +
-            "a=1\n", os.toString("UTF-8").replace( System.lineSeparator(), "\n" ) );
+            "a=1\n" +
+            "b=2\n", os.toString("UTF-8").replace( System.lineSeparator(), "\n" ) );
     }
 
     @Test


Mime
View raw message