camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [2/2] camel git commit: CAMEL-10118: Test exclusions were ignored by arquillian
Date Thu, 07 Jul 2016 07:20:04 GMT
CAMEL-10118: Test exclusions were ignored by arquillian


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

Branch: refs/heads/master
Commit: e05899b5a419357460a3fd10ce10fac74439af45
Parents: 3161563
Author: Nicola Ferraro <ni.ferraro@gmail.com>
Authored: Wed Jul 6 17:17:18 2016 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Thu Jul 7 09:19:56 2016 +0200

----------------------------------------------------------------------
 .../springboot/util/ArquillianPackager.java     | 18 ++++++-
 .../springboot/util/DependencyResolver.java     | 50 ++++++++++++++++++++
 2 files changed, 67 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/e05899b5/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/util/ArquillianPackager.java
----------------------------------------------------------------------
diff --git a/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/util/ArquillianPackager.java
b/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/util/ArquillianPackager.java
index 4cb453f3..865a49f 100644
--- a/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/util/ArquillianPackager.java
+++ b/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/util/ArquillianPackager.java
@@ -120,6 +120,7 @@ public final class ArquillianPackager {
         List<MavenDependencyExclusion> commonExclusions = new LinkedList<>();
         commonExclusions.add(MavenDependencies.createExclusion("org.slf4j", "slf4j-log4j12"));
         commonExclusions.add(MavenDependencies.createExclusion("log4j", "log4j"));
+        commonExclusions.add(MavenDependencies.createExclusion("log4j", "apache-log4j-extras"));
         commonExclusions.add(MavenDependencies.createExclusion("org.slf4j", "slf4j-simple"));
         commonExclusions.add(MavenDependencies.createExclusion("org.slf4j", "slf4j-simple"));
         commonExclusions.add(MavenDependencies.createExclusion("org.slf4j", "slf4j-jdk14"));
@@ -167,7 +168,22 @@ public final class ArquillianPackager {
                 if (!validTestDependency(config, c)) {
                     continue;
                 }
-                MavenDependency dep = MavenDependencies.createDependency(c, ScopeType.RUNTIME,
false, commonExclutionArray);
+
+                // Re-adding exclusions, as Arquillian resolver ignores them
+                Set<String> pomExclusions = DependencyResolver.getExclusions(config.getModuleBasePath()
+ "/pom.xml", c.getGroupId(), c.getArtifactId());
+                MavenDependencyExclusion[] artExclusions;
+                if(pomExclusions.isEmpty()) {
+                    artExclusions = commonExclutionArray;
+                } else {
+                    List<MavenDependencyExclusion> specificExclusions = new LinkedList<>(Arrays.asList(commonExclutionArray));
+                    for(String spEx : pomExclusions) {
+                        specificExclusions.add(MavenDependencies.createExclusion(spEx));
+                    }
+                    artExclusions = specificExclusions.toArray(new MavenDependencyExclusion[]{});
+                }
+
+
+                MavenDependency dep = MavenDependencies.createDependency(c, ScopeType.RUNTIME,
false, artExclusions);
                 moduleDependencies.add(dep);
             }
         }

http://git-wip-us.apache.org/repos/asf/camel/blob/e05899b5/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/util/DependencyResolver.java
----------------------------------------------------------------------
diff --git a/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/util/DependencyResolver.java
b/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/util/DependencyResolver.java
index 19fd33d..3b9cda8 100644
--- a/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/util/DependencyResolver.java
+++ b/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/util/DependencyResolver.java
@@ -16,13 +16,20 @@
  */
 package org.apache.camel.itest.springboot.util;
 
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathConstants;
 import javax.xml.xpath.XPathExpression;
 import javax.xml.xpath.XPathFactory;
 
 import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
 
 /**
  * Resolves the currently used version of a library. Useful to run unit tests directly from
the IDE, without passing additional parameters.
@@ -39,6 +46,49 @@ public final class DependencyResolver {
     }
 
     /**
+     * Retrieves a list of transitive exclusions included in the pom, given the coordinate
of a maven dependency.
+     * Useful to overcome limitations of Arquillian maven resolver.
+     *
+     * @param pom the pom where dependencies should be looked up
+     * @param groupId the group id of the dependency
+     * @param artifactId the artifact id of the dependency
+     * @return the set of exclusions in the form groupId:artifactId
+     * @throws Exception if anything goes wrong
+     */
+    public static Set<String> getExclusions(String pom, String groupId, String artifactId)
throws Exception {
+        String expression = "/project/dependencies/dependency[groupId='" + groupId + "' and
artifactId='" + artifactId + "']/exclusions";
+
+        DocumentBuilder builder = factory.newDocumentBuilder();
+        Document doc = builder.parse(pom);
+        XPath xpath = xPathfactory.newXPath();
+        XPathExpression expr = xpath.compile(expression);
+
+        NodeList nodes = (NodeList) expr.evaluate(doc, XPathConstants.NODESET);
+        if (nodes == null || nodes.getLength() < 1) {
+            return Collections.emptySet();
+        }
+
+        Set<String> exclusionSet = new HashSet<>();
+
+        NodeList exclusions = nodes.item(0).getChildNodes();
+        for (int i = 0; i < exclusions.getLength(); i++) {
+            Node exclusionNode = exclusions.item(i);
+            if (exclusionNode instanceof Element) {
+                Element exclusion = (Element) exclusionNode;
+                NodeList exclGroupIds = exclusion.getElementsByTagName("groupId");
+                String exclGroupIdVal = exclGroupIds.getLength() == 0 ? null : exclGroupIds.item(0).getTextContent();
+                NodeList exclArtifactIds = exclusion.getElementsByTagName("artifactId");
+                String exclArtifactIdVal = exclGroupIds.getLength() == 0 ? null : exclArtifactIds.item(0).getTextContent();
+                if (exclGroupIdVal != null && exclArtifactIdVal != null) {
+                    exclusionSet.add(exclGroupIdVal + ":" + exclArtifactIdVal);
+                }
+            }
+        }
+
+        return exclusionSet;
+    }
+
+    /**
      * Gets a groupId and artifactId in the form "groupId:artifactId" and returns the current
version from the pom.
      * Uses {@link DependencyResolver#withVersion(String, String)} using a default prefix.
      *


Mime
View raw message