[maven-repo-helper] 01/01: Moved the TreePath class to a separate file

Emmanuel Bourg ebourg-guest at moszumanska.debian.org
Fri Apr 1 12:23:49 UTC 2016


This is an automated email from the git hooks/post-receive script.

ebourg-guest pushed a commit to branch master
in repository maven-repo-helper.

commit e04ea2a416f221d6f7352cf1207a95a3f03403aa
Author: Emmanuel Bourg <ebourg at apache.org>
Date:   Tue Oct 20 00:18:30 2015 +0200

    Moved the TreePath class to a separate file
---
 src/main/java/org/debian/maven/repo/POMReader.java |  64 -----------
 src/main/java/org/debian/maven/repo/TreePath.java  | 126 +++++++++++++++++++++
 .../java/org/debian/maven/repo/POMReaderTest.java  |  29 -----
 .../java/org/debian/maven/repo/TreePathTest.java   |  52 +++++++++
 4 files changed, 178 insertions(+), 93 deletions(-)

diff --git a/src/main/java/org/debian/maven/repo/POMReader.java b/src/main/java/org/debian/maven/repo/POMReader.java
index a2cdc57..f7dffd2 100644
--- a/src/main/java/org/debian/maven/repo/POMReader.java
+++ b/src/main/java/org/debian/maven/repo/POMReader.java
@@ -259,68 +259,4 @@ public class POMReader {
         }
         return str;
     }
-
-    static class TreePath<S> {
-        private LinkedList<S> path = new LinkedList<S>();
-
-        // forwarding functions to the inner LinkedList
-        public void add(S el) { path.addLast(el); }
-        public void remove() { path.removeLast(); }
-        public boolean contains(S el) { return path.contains(el); }
-        public int size() { return path.size(); }
-        public S get(int index) { return path.get(index); }
-
-        public S parent(int generations) {
-            int index = (path.size() - 1) - generations;
-            return index >= 0 ? path.get(index) : null;
-        }
-
-        private boolean matches(String patternString, boolean anchored) {
-            String[] patterns = patternString.split("/");
-
-            if(anchored && patterns.length != path.size()) return false;
-
-            int pathIndex = path.size() - patterns.length - 1;
-            if(pathIndex < -1) return false;
-
-            for (String pattern : patterns) {
-                ++pathIndex;
-                if ("*".equals(pattern)) {
-                    continue;
-                }
-                if (!pattern.equals(path.get(pathIndex))) {
-                    return false;
-                }
-            }
-            return true;
-        }
-
-        /**
-         * Does this path match the pattern?
-         * 
-         * The pattern is separated by slashes / and can contain the * wildcard for any path element to match
-         * anything. The matching is anchored at the end of the path. So the pattern does not need to start at
-         * the root.
-         * 
-         * A pattern that starts with a slash is also anchored at the start.
-         * 
-         * @param patternString
-         */
-        public boolean matches(String patternString) {
-            if(patternString.startsWith("/")) {
-                return matches(patternString.substring(1), true);
-            } else {
-                return matches(patternString, false);
-            }
-        }
-        
-        public DependencyType match() {
-            for(DependencyType depType : DependencyType.values()) {
-                if(matches(depType.pattern)) {
-                    return depType;
-                }
-            }
-            return null;
-        }
-    }
 }
diff --git a/src/main/java/org/debian/maven/repo/TreePath.java b/src/main/java/org/debian/maven/repo/TreePath.java
new file mode 100644
index 0000000..889a18f
--- /dev/null
+++ b/src/main/java/org/debian/maven/repo/TreePath.java
@@ -0,0 +1,126 @@
+/*
+ * Copyright 2009 Ludovic Claude.
+ *
+ * Licensed 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.debian.maven.repo;
+
+import java.util.LinkedList;
+
+/**
+ * Path in a tree like structure.
+ * 
+ * @param <S> the type of the elements in the path
+ */
+class TreePath<S> {
+
+    private LinkedList<S> path = new LinkedList<S>();
+
+    /**
+     * Appends an element to the path.
+     */
+    public void add(S el) {
+        path.addLast(el);
+    }
+
+    /**
+     * Removes the last element of the path.
+     */
+    public void remove() {
+        path.removeLast();
+    }
+
+    /**
+     * Tells if the path contains the specified element.
+     */
+    public boolean contains(S el) {
+        return path.contains(el);
+    }
+
+    /**
+     * Returns the length of the path.
+     */
+    public int size() {
+        return path.size();
+    }
+
+    /**
+     * Returns the element of the path at the specified index.
+     */
+    public S get(int index) {
+        return path.get(index);
+    }
+
+    /**
+     * Returns the n-th parent of the last element in the path.
+     * 
+     * @param generations 1: parent, 2: grand parent, etc
+     */
+    public S parent(int generations) {
+        int index = (path.size() - 1) - generations;
+        return index >= 0 ? path.get(index) : null;
+    }
+
+    /**
+     * Does this path match the pattern?
+     *
+     * The pattern is separated by slashes / and can contain the * wildcard for any path element to match
+     * anything. The matching is anchored at the end of the path. So the pattern does not need to start at
+     * the root.
+     *
+     * A pattern that starts with a slash is also anchored at the start.
+     *
+     * @param patternString
+     */
+    public boolean matches(String patternString) {
+        if (patternString.startsWith("/")) {
+            return matches(patternString.substring(1), true);
+        } else {
+            return matches(patternString, false);
+        }
+    }
+
+    private boolean matches(String patternString, boolean anchored) {
+        String[] patterns = patternString.split("/");
+
+        if (anchored && patterns.length != path.size()) {
+            return false;
+        }
+
+        int pathIndex = path.size() - patterns.length - 1;
+        if (pathIndex < -1) {
+            return false;
+        }
+
+        for (String pattern : patterns) {
+            ++pathIndex;
+            if ("*".equals(pattern)) {
+                continue;
+            }
+            if (!pattern.equals(path.get(pathIndex))) {
+                return false;
+            }
+        }
+        return true;
+    }
+    
+    public POMInfo.DependencyType match() {
+        for (POMInfo.DependencyType depType : POMInfo.DependencyType.values()) {
+            if (matches(depType.pattern)) {
+                return depType;
+            }
+        }
+        return null;
+    }
+}
diff --git a/src/test/java/org/debian/maven/repo/POMReaderTest.java b/src/test/java/org/debian/maven/repo/POMReaderTest.java
index aacd7e0..e6205e5 100644
--- a/src/test/java/org/debian/maven/repo/POMReaderTest.java
+++ b/src/test/java/org/debian/maven/repo/POMReaderTest.java
@@ -17,7 +17,6 @@
 package org.debian.maven.repo;
 
 import org.debian.maven.TemporaryPomFolder;
-import org.debian.maven.repo.POMReader.TreePath;
 import org.junit.Rule;
 import org.junit.Test;
 
@@ -377,34 +376,6 @@ public class POMReaderTest {
         assertEquals("version", "1.43.0", info.getThisPom().getVersion());
     }
 
-    @Test
-    public void testTreePathMatches() {
-        TreePath<String> path = new TreePath<String>();
-        path.add("a");
-        path.add("b");
-        path.add("c");
-        path.add("d");
-
-        assertTrue(path.matches("a/b/c/d"));
-        assertTrue(path.matches("b/c/d"));
-        assertTrue(path.matches("c/d"));
-        assertTrue(path.matches("d"));
-
-        assertTrue(path.matches("*/b/c/d"));
-        assertTrue(path.matches("a/*/c/d"));
-        assertTrue(path.matches("a/b/*/d"));
-        assertTrue(path.matches("a/b/c/*"));
-
-        assertTrue(path.matches("/*/b/c/d"));
-        assertTrue(path.matches("/a/*/c/d"));
-        assertTrue(path.matches("/a/b/*/d"));
-        assertTrue(path.matches("/a/b/c/*"));
-
-        assertFalse(path.matches("/b/c/d"));
-        assertFalse(path.matches("/c/d"));
-        assertFalse(path.matches("/d"));
-    }
-
     /**
      * Ensures all modules are properly parsed, including those defined in a profile.
      */
diff --git a/src/test/java/org/debian/maven/repo/TreePathTest.java b/src/test/java/org/debian/maven/repo/TreePathTest.java
new file mode 100644
index 0000000..02db84a
--- /dev/null
+++ b/src/test/java/org/debian/maven/repo/TreePathTest.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2009 Ludovic Claude.
+ *
+ * Licensed 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.debian.maven.repo;
+
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+public class TreePathTest {
+
+    @Test
+    public void testMatches() {
+        TreePath<String> path = new TreePath<String>();
+        path.add("a");
+        path.add("b");
+        path.add("c");
+        path.add("d");
+
+        assertTrue(path.matches("a/b/c/d"));
+        assertTrue(path.matches("b/c/d"));
+        assertTrue(path.matches("c/d"));
+        assertTrue(path.matches("d"));
+
+        assertTrue(path.matches("*/b/c/d"));
+        assertTrue(path.matches("a/*/c/d"));
+        assertTrue(path.matches("a/b/*/d"));
+        assertTrue(path.matches("a/b/c/*"));
+
+        assertTrue(path.matches("/*/b/c/d"));
+        assertTrue(path.matches("/a/*/c/d"));
+        assertTrue(path.matches("/a/b/*/d"));
+        assertTrue(path.matches("/a/b/c/*"));
+
+        assertFalse(path.matches("/b/c/d"));
+        assertFalse(path.matches("/c/d"));
+        assertFalse(path.matches("/d"));
+    }
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/maven-repo-helper.git



More information about the pkg-java-commits mailing list