You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2017/09/20 15:13:52 UTC

[myfaces-tobago] 01/02: TOBAGO-1782: Clean up * dependency to commons-collections is no longer needed.

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

lofwyr pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/myfaces-tobago.git

commit 9dc0f5cca023c17dd61f31f521aabb12b72b59ec
Author: Udo Schnurpfeil <lo...@apache.org>
AuthorDate: Wed Sep 20 17:02:41 2017 +0200

    TOBAGO-1782: Clean up
    * dependency to commons-collections is no longer needed.
---
 pom.xml                                            |  7 ----
 src/docbook/tobago-tutorial.xml                    |  2 +-
 tobago-core/pom.xml                                |  4 ---
 .../internal/config/TobagoConfigBuilder.java       |  9 +++---
 .../apache/myfaces/tobago/util/ComponentUtils.java | 11 +++++--
 .../myfaces/tobago/context/MarkupUnitTest.java     | 37 ++++++++++++++--------
 .../internal/mock/servlet/MockHttpSession.java     |  5 ++-
 7 files changed, 40 insertions(+), 35 deletions(-)

diff --git a/pom.xml b/pom.xml
index 4508d8f..41407d0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -42,7 +42,6 @@
     <mojarra23.version>2.3.2</mojarra23.version>
     <slf4j.version>1.7.25</slf4j.version>
     <logback.version>1.2.3</logback.version>
-    <commons-collection.version>4.1</commons-collection.version>
     <maven.compile.source>1.8</maven.compile.source>
     <maven.compile.target>1.8</maven.compile.target>
     <maven.compile.encoding>UTF-8</maven.compile.encoding>
@@ -207,7 +206,6 @@
           <links>
             <link>http://docs.oracle.com/javase/6/docs/api/</link>
             <link>http://docs.oracle.com/javaee/6/api/</link>
-            <link>https://commons.apache.org/proper/commons-collections/javadocs/api-release/</link>
             <link>http://www.slf4j.org/apidocs</link>
             <link>http://junit.sourceforge.net/javadoc/</link>
             <link>http://logback.qos.ch/apidocs/</link>
@@ -447,11 +445,6 @@
         <version>1.9.3</version>
       </dependency>
       <dependency>
-        <groupId>org.apache.commons</groupId>
-        <artifactId>commons-collections4</artifactId>
-        <version>${commons-collection.version}</version>
-      </dependency>
-      <dependency>
         <groupId>commons-codec</groupId>
         <artifactId>commons-codec</artifactId>
         <version>1.10</version>
diff --git a/src/docbook/tobago-tutorial.xml b/src/docbook/tobago-tutorial.xml
index abd4732..d63acf3 100644
--- a/src/docbook/tobago-tutorial.xml
+++ b/src/docbook/tobago-tutorial.xml
@@ -122,7 +122,7 @@
       </listitem>
 
       <listitem>
-        <para>commons-collections</para>
+        <para>commons-collections (only since Tobago 3.x)</para>
       </listitem>
 
       <listitem>
diff --git a/tobago-core/pom.xml b/tobago-core/pom.xml
index 2c0241b..a9881ec 100644
--- a/tobago-core/pom.xml
+++ b/tobago-core/pom.xml
@@ -157,10 +157,6 @@
       <artifactId>commons-beanutils</artifactId>
     </dependency>
     <dependency>
-      <groupId>org.apache.commons</groupId>
-      <artifactId>commons-collections4</artifactId>
-    </dependency>
-    <dependency>
       <groupId>org.apache.myfaces.tobago</groupId>
       <artifactId>tobago-tool-apt</artifactId>
       <version>${project.version}</version>
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigBuilder.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigBuilder.java
index cfd90bb..0fc09ce 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigBuilder.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigBuilder.java
@@ -19,7 +19,6 @@
 
 package org.apache.myfaces.tobago.internal.config;
 
-import org.apache.commons.collections4.CollectionUtils;
 import org.apache.myfaces.tobago.config.TobagoConfig;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -32,6 +31,7 @@ import java.io.IOException;
 import java.net.URISyntaxException;
 import java.net.URL;
 import java.util.ArrayList;
+import java.util.Enumeration;
 import java.util.List;
 
 public class TobagoConfigBuilder {
@@ -104,10 +104,9 @@ public class TobagoConfigBuilder {
         LOG.info("Searching for '" + META_INF_TOBAGO_CONFIG_XML + "'");
       }
       final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
-      final List<URL> urls = new ArrayList<>();
-      CollectionUtils.addAll(urls, classLoader.getResources(META_INF_TOBAGO_CONFIG_XML));
-
-      for (final URL themeUrl : urls) {
+      final Enumeration<URL> urls = classLoader.getResources(META_INF_TOBAGO_CONFIG_XML);
+      while (urls.hasMoreElements()) {
+        final URL themeUrl = urls.nextElement();
         try {
           final TobagoConfigFragment fragment = new TobagoConfigParser().parse(themeUrl);
           fragment.setUrl(themeUrl);
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/util/ComponentUtils.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/util/ComponentUtils.java
index c6dec3d..5442f99 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/util/ComponentUtils.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/util/ComponentUtils.java
@@ -19,7 +19,6 @@
 
 package org.apache.myfaces.tobago.util;
 
-import org.apache.commons.collections4.CollectionUtils;
 import org.apache.myfaces.tobago.component.Attributes;
 import org.apache.myfaces.tobago.component.Facets;
 import org.apache.myfaces.tobago.component.RendererTypes;
@@ -696,7 +695,15 @@ public final class ComponentUtils {
       if (renderer != null) {
         if (component instanceof UISelectMany) {
           final Object converted = renderer.getConvertedValue(facesContext, component, new String[]{stringValue});
-          return converted instanceof Collection ? CollectionUtils.get(converted, 0) : ((Object[]) converted)[0];
+          if (converted instanceof Object[]) {
+            return ((Object[]) converted)[0];
+          } else if (converted instanceof List) {
+            ((List) converted).get(0);
+          } else if (converted instanceof Collection) {
+            return ((Collection) converted).iterator().next();
+          } else {
+            return null;
+          }
         } else {
           return renderer.getConvertedValue(facesContext, component, stringValue);
         }
diff --git a/tobago-core/src/test/java/org/apache/myfaces/tobago/context/MarkupUnitTest.java b/tobago-core/src/test/java/org/apache/myfaces/tobago/context/MarkupUnitTest.java
index 381ce32..922fcce 100644
--- a/tobago-core/src/test/java/org/apache/myfaces/tobago/context/MarkupUnitTest.java
+++ b/tobago-core/src/test/java/org/apache/myfaces/tobago/context/MarkupUnitTest.java
@@ -19,11 +19,13 @@
 
 package org.apache.myfaces.tobago.context;
 
-import org.apache.commons.collections4.IteratorUtils;
 import org.junit.Assert;
 import org.junit.Test;
 
+import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
 
 public class MarkupUnitTest {
   
@@ -33,13 +35,13 @@ public class MarkupUnitTest {
   public void testString() {
     Assert.assertNull(Markup.valueOf((String) null));
     
-    Assert.assertArrayEquals(new String[] {"accent"}, IteratorUtils.toArray(Markup.valueOf("accent").iterator()));
+    Assert.assertArrayEquals(new String[] {"accent"}, toArray(Markup.valueOf("accent").iterator()));
     
-    Assert.assertArrayEquals(AB, IteratorUtils.toArray(Markup.valueOf("a,b").iterator()));
+    Assert.assertArrayEquals(AB, toArray(Markup.valueOf("a,b").iterator()));
     
-    Assert.assertArrayEquals(AB, IteratorUtils.toArray(Markup.valueOf("a, b").iterator()));
+    Assert.assertArrayEquals(AB, toArray(Markup.valueOf("a, b").iterator()));
     
-    Assert.assertArrayEquals(AB, IteratorUtils.toArray(Markup.valueOf(", \ta , ,\n b ,").iterator()));
+    Assert.assertArrayEquals(AB, toArray(Markup.valueOf(", \ta , ,\n b ,").iterator()));
   }
   
   @Test
@@ -48,27 +50,27 @@ public class MarkupUnitTest {
     
     Assert.assertNull(Markup.valueOf(new String[] {}));
     
-    Assert.assertArrayEquals(AB, IteratorUtils.toArray(Markup.valueOf(new String[] {"a", "b"}).iterator()));
+    Assert.assertArrayEquals(AB, toArray(Markup.valueOf(new String[] {"a", "b"}).iterator()));
     
-    Assert.assertArrayEquals(AB, IteratorUtils.toArray(Markup.valueOf(new String[] {" a ", " b "}).iterator()));
+    Assert.assertArrayEquals(AB, toArray(Markup.valueOf(new String[] {" a ", " b "}).iterator()));
   }
   
   @Test
   public void testObject() {
     Assert.assertNull(Markup.valueOf((Object) null));
 
-    Assert.assertArrayEquals(AB, IteratorUtils.toArray(Markup.valueOf((Object) ", \ta , ,\n b ,").iterator()));
+    Assert.assertArrayEquals(AB, toArray(Markup.valueOf((Object) ", \ta , ,\n b ,").iterator()));
 
-    Assert.assertArrayEquals(AB, IteratorUtils.toArray(Markup.valueOf((Object) new String[] {"a", "b"}).iterator()));
+    Assert.assertArrayEquals(AB, toArray(Markup.valueOf((Object) new String[] {"a", "b"}).iterator()));
     
     Assert.assertArrayEquals(AB,
-        IteratorUtils.toArray(Markup.valueOf((Object) new String[] {" a ", " b "}).iterator()));
+        toArray(Markup.valueOf((Object) new String[] {" a ", " b "}).iterator()));
     
-    Assert.assertArrayEquals(AB, IteratorUtils.toArray(Markup.valueOf(new StringBuilder("a, b")).iterator()));
+    Assert.assertArrayEquals(AB, toArray(Markup.valueOf(new StringBuilder("a, b")).iterator()));
     
-    Assert.assertArrayEquals(AB, IteratorUtils.toArray(Markup.valueOf(AB).iterator()));
+    Assert.assertArrayEquals(AB, toArray(Markup.valueOf(AB).iterator()));
     
-    Assert.assertArrayEquals(AB, IteratorUtils.toArray(Markup.valueOf(Arrays.asList(AB)).iterator()));
+    Assert.assertArrayEquals(AB, toArray(Markup.valueOf(Arrays.asList(AB)).iterator()));
   }
   
   @Test
@@ -145,4 +147,13 @@ public class MarkupUnitTest {
     Assert.assertFalse(ab.contains(Markup.valueOf("a,c")));
     Assert.assertFalse(ab.contains(Markup.valueOf("a,c,d,e,c,f,e,f")));
   }
+
+  public static Object[] toArray(final Iterator<?> iterator) {
+    final List<Object> list = new ArrayList<Object>(10);
+    while (iterator.hasNext()) {
+        list.add(iterator.next());
+    }
+    return list.toArray();
+  }
+
 }
diff --git a/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/mock/servlet/MockHttpSession.java b/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/mock/servlet/MockHttpSession.java
index 312c1de..f520164 100644
--- a/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/mock/servlet/MockHttpSession.java
+++ b/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/mock/servlet/MockHttpSession.java
@@ -19,14 +19,13 @@
 
 package org.apache.myfaces.tobago.internal.mock.servlet;
 
-import org.apache.commons.collections4.iterators.IteratorEnumeration;
-
 import javax.servlet.ServletContext;
 import javax.servlet.http.HttpSession;
 import javax.servlet.http.HttpSessionContext;
 import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Vector;
 
 public class MockHttpSession implements HttpSession {
 
@@ -39,7 +38,7 @@ public class MockHttpSession implements HttpSession {
 
   @Override
   public Enumeration<String> getAttributeNames() {
-    return new IteratorEnumeration(attributes.keySet().iterator());
+    return new Vector(attributes.keySet()).elements();
   }
 
   @Override

-- 
To stop receiving notification emails like this one, please contact
"commits@myfaces.apache.org" <co...@myfaces.apache.org>.