cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: [CXF-7124] Better support for finding a shared package, patch from Neal Hu applied
Date Fri, 04 Nov 2016 12:23:48 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.1.x-fixes 9f91f73f9 -> d77f42b28


[CXF-7124] Better support for finding a shared package, patch from Neal Hu applied


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/d77f42b2
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/d77f42b2
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/d77f42b2

Branch: refs/heads/3.1.x-fixes
Commit: d77f42b28f81c2fe125423eaa6f7f8304905f12d
Parents: 9f91f73
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Fri Nov 4 12:22:47 2016 +0000
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Fri Nov 4 12:23:30 2016 +0000

----------------------------------------------------------------------
 .../apache/cxf/common/util/PackageUtils.java    | 30 +++++++++++---------
 .../cxf/common/util/PackageUtilsTest.java       | 16 +++++++++++
 2 files changed, 32 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/d77f42b2/core/src/main/java/org/apache/cxf/common/util/PackageUtils.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/cxf/common/util/PackageUtils.java b/core/src/main/java/org/apache/cxf/common/util/PackageUtils.java
index b743320..9ff5510 100644
--- a/core/src/main/java/org/apache/cxf/common/util/PackageUtils.java
+++ b/core/src/main/java/org/apache/cxf/common/util/PackageUtils.java
@@ -20,7 +20,6 @@
 package org.apache.cxf.common.util;
 
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.List;
 import java.util.StringTokenizer;
 
@@ -51,20 +50,23 @@ public final class PackageUtils {
     }
     
     public static String getSharedPackageName(List<Class<?>> classes) {
-        List<String> currentParts = null;
+        if (classes.isEmpty()) {
+            return "";
+        }
+        List<List<String>> lParts = new  ArrayList<List<String>>(classes.size());
+        List<String> currentParts = new ArrayList<String>();
         for (Class<?> cls : classes) {
-            List<String> parts = StringUtils.getParts(getPackageName(cls), "\\.");
-            if (currentParts == null) {
-                currentParts = parts;
-            } else {
-                List<String> subList = Collections.emptyList();
-                for (int i = parts.size() - 1; i > 0; i--) {
-                    subList = parts.subList(0, i + 1);
-                    if (currentParts.equals(subList)) {
-                        break;
-                    }
-                }
-                currentParts.retainAll(subList);
+            lParts.add(StringUtils.getParts(getPackageName(cls), "\\."));
+        }
+        for (int i = 0; i < lParts.get(0).size(); i++) {
+            int j = 1;
+            for (; j < lParts.size(); j++) {
+                if (i > (lParts.get(j).size() - 1) || !lParts.get(j).get(i).equals(lParts.get(0).get(i)))
{
+                    break;
+                }  
+            }
+            if (j == lParts.size()) {
+                currentParts.add(lParts.get(j - 1).get(i));
             }
         }
         StringBuilder sb = new StringBuilder();

http://git-wip-us.apache.org/repos/asf/cxf/blob/d77f42b2/core/src/test/java/org/apache/cxf/common/util/PackageUtilsTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/cxf/common/util/PackageUtilsTest.java b/core/src/test/java/org/apache/cxf/common/util/PackageUtilsTest.java
index 46e32af..081df8a 100644
--- a/core/src/test/java/org/apache/cxf/common/util/PackageUtilsTest.java
+++ b/core/src/test/java/org/apache/cxf/common/util/PackageUtilsTest.java
@@ -77,4 +77,20 @@ public class PackageUtilsTest extends Assert {
             Arrays.asList(Annotation.class, Array.class));       
         assertEquals("java.lang", packageName);
     }
+    @Test
+    public void testSharedPackageNameManyClassesCommonRoot4() throws Exception {
+        String packageName = PackageUtils.getSharedPackageName(
+            Arrays.asList(org.apache.cxf.common.util.PackageUtils.class, 
+                    org.apache.cxf.bus.CXFBusFactory.class,
+                    org.apache.cxf.common.jaxb.JAXBContextCache.class));       
+        assertEquals("org.apache.cxf", packageName);
+    }
+    @Test
+    public void testSharedPackageNameManyClassesCommonRoot5() throws Exception {
+        String packageName = PackageUtils.getSharedPackageName(
+            Arrays.asList(java.lang.annotation.Annotation.class, 
+                    org.apache.cxf.bus.CXFBusFactory.class,
+                    org.apache.cxf.common.jaxb.JAXBContextCache.class));       
+        assertEquals("", packageName);
+    }
 }


Mime
View raw message