bval-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject [42/50] bval git commit: BVAL-159 drop commons dependencies
Date Tue, 16 Oct 2018 17:31:46 GMT
BVAL-159 drop commons dependencies


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

Branch: refs/heads/bv2
Commit: ac7d327ac177ac8dbc38a41dee6675d5fc0f6326
Parents: bb7622c
Author: Romain Manni-Bucau <rmannibucau@gmail.com>
Authored: Sun Oct 7 17:37:37 2018 +0200
Committer: Matt Benson <mbenson@apache.org>
Committed: Tue Oct 16 12:28:20 2018 -0500

----------------------------------------------------------------------
 bval-jsr/pom.xml                                |  11 +-
 .../apache/bval/jsr/util/PathNavigation.java    |  44 +---
 .../main/java/org/apache/bval/util/Escapes.java | 203 +++++++++++++++++++
 .../test/java/org/apache/bval/jsr/xml/Demo.java |   3 +-
 pom.xml                                         |  14 +-
 5 files changed, 217 insertions(+), 58 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/bval/blob/ac7d327a/bval-jsr/pom.xml
----------------------------------------------------------------------
diff --git a/bval-jsr/pom.xml b/bval-jsr/pom.xml
index b94b02d..d810e0d 100644
--- a/bval-jsr/pom.xml
+++ b/bval-jsr/pom.xml
@@ -151,11 +151,6 @@
 
     <dependencies>
         <dependency>
-            <groupId>commons-beanutils</groupId>
-            <artifactId>commons-beanutils-core</artifactId>
-            <optional>true</optional>
-        </dependency>
-        <dependency>
             <groupId>org.apache.commons</groupId>
             <artifactId>commons-weaver-privilizer-api</artifactId>
         </dependency>
@@ -195,7 +190,7 @@
         <dependency>
           <groupId>org.apache.geronimo.specs</groupId>
           <artifactId>geronimo-interceptor_1.2_spec</artifactId>
-          <version>1.0-alpha-1</version>
+          <version>1.0</version>
           <scope>provided</scope>
         </dependency>
         <dependency>
@@ -204,10 +199,6 @@
             <version>1.0</version>
             <scope>provided</scope>
         </dependency>
-        <dependency>
-	        <groupId>com.oracle</groupId>
-	        <artifactId>javafx</artifactId>
-        </dependency>
 
         <!-- Testing dependencies -->
         <dependency>

http://git-wip-us.apache.org/repos/asf/bval/blob/ac7d327a/bval-jsr/src/main/java/org/apache/bval/jsr/util/PathNavigation.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/jsr/util/PathNavigation.java b/bval-jsr/src/main/java/org/apache/bval/jsr/util/PathNavigation.java
index 06d486c..6a6497a 100644
--- a/bval-jsr/src/main/java/org/apache/bval/jsr/util/PathNavigation.java
+++ b/bval-jsr/src/main/java/org/apache/bval/jsr/util/PathNavigation.java
@@ -16,11 +16,7 @@
  */
 package org.apache.bval.jsr.util;
 
-import javax.validation.ValidationException;
-
-import org.apache.bval.util.Exceptions;
-import org.apache.bval.util.Validate;
-import org.apache.commons.lang3.StringEscapeUtils;
+import static org.apache.bval.util.Escapes.unescapeJava;
 
 import java.io.IOException;
 import java.io.StringWriter;
@@ -29,7 +25,11 @@ import java.text.ParsePosition;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
-import java.util.logging.Logger;
+
+import javax.validation.ValidationException;
+
+import org.apache.bval.util.Exceptions;
+import org.apache.bval.util.Validate;
 
 /**
  * Defines a path navigation algorithm and a means of interacting with same.
@@ -142,18 +142,10 @@ public class PathNavigation {
         }
 
         protected void handleNextChar(CharSequence path, PathPosition pos, Writer target)
throws IOException {
-            target.write(Character.toChars(Character.codePointAt(path, pos.getIndex())));
-            pos.next();
-        }
-    }
-
-    private static class FullQuotedStringParser extends QuotedStringParser {
-
-        @Override
-        protected void handleNextChar(CharSequence path, PathPosition pos, Writer target)
throws IOException {
-            final int codePoints = StringEscapeUtils.UNESCAPE_JAVA.translate(path, pos.getIndex(),
target);
+            final int codePoints = unescapeJava(path, pos.getIndex(), target);
             if (codePoints == 0) {
-                super.handleNextChar(path, pos, target);
+                target.write(Character.toChars(Character.codePointAt(path, pos.getIndex())));
+                pos.next();
             } else {
                 for (int i = 0; i < codePoints; i++) {
                     pos.plus(Character.charCount(Character.codePointAt(path, pos.getIndex())));
@@ -162,20 +154,7 @@ public class PathNavigation {
         }
     }
 
-    private static final Logger LOG = Logger.getLogger(PathNavigation.class.getName());
-
-    private static final QuotedStringParser QUOTED_STRING_PARSER;
-
-    static {
-        QuotedStringParser quotedStringParser;
-        try {
-            quotedStringParser = new FullQuotedStringParser();
-        } catch (Exception e) {
-            LOG.warning("Apache commons-lang3 is not on the classpath; Java escaping in quotes
will not be available.");
-            quotedStringParser = new QuotedStringParser();
-        }
-        QUOTED_STRING_PARSER = quotedStringParser;
-    }
+    private static final QuotedStringParser QUOTED_STRING_PARSER = new QuotedStringParser();
 
     /**
      * Create a new PathNavigation instance.
@@ -262,8 +241,7 @@ public class PathNavigation {
 
     /**
      * Handles an index/key. If the text contained between [] is surrounded by a pair of
" or ', it will be treated as a
-     * string which may contain Java escape sequences. This function is only available if
commons-lang3 is available on
-     * the classpath!
+     * string which may contain Java escape sequences.
      * 
      * @param path
      * @param pos

http://git-wip-us.apache.org/repos/asf/bval/blob/ac7d327a/bval-jsr/src/main/java/org/apache/bval/util/Escapes.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/util/Escapes.java b/bval-jsr/src/main/java/org/apache/bval/util/Escapes.java
new file mode 100644
index 0000000..10ea1b2
--- /dev/null
+++ b/bval-jsr/src/main/java/org/apache/bval/util/Escapes.java
@@ -0,0 +1,203 @@
+/**
+ * Copyright (C) 2006-2018 Talend Inc. - www.talend.com
+ * <p>
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.apache.bval.util;
+
+import java.io.IOException;
+import java.io.Writer;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+// taken from commons-lang3
+public final class Escapes {
+    private static final CharSequenceTranslator UNESCAPE_JAVA =
+            new AggregateTranslator(
+                    new OctalUnescaper(),     // .between('\1', '\377'),
+                    new UnicodeUnescaper(),
+                    new LookupTranslator(new String[][] {
+                            {"\\b", "\b"},
+                            {"\\n", "\n"},
+                            {"\\t", "\t"},
+                            {"\\f", "\f"},
+                            {"\\r", "\r"}
+                    }),
+                    new LookupTranslator(
+                            new String[][] {
+                                    {"\\\\", "\\"},
+                                    {"\\\"", "\""},
+                                    {"\\'", "'"},
+                                    {"\\", ""}
+                            })
+            );
+
+    private Escapes() {
+        // no-op
+    }
+
+    public static int unescapeJava(final CharSequence from, final int offset, final Writer
output) {
+        // return StringEscapeUtils.UNESCAPE_JAVA.translate(path, pos.getIndex(), target);
+        return UNESCAPE_JAVA.translate(from, offset, output);
+    }
+
+    protected interface CharSequenceTranslator {
+        int translate(CharSequence input, int index, Writer out);
+    }
+
+    private static class AggregateTranslator implements CharSequenceTranslator {
+        private final CharSequenceTranslator[] translators;
+
+        private AggregateTranslator(final CharSequenceTranslator... translators) {
+            this.translators = translators;
+        }
+
+        @Override
+        public int translate(final CharSequence input, final int index, final Writer out)
{
+            for (final CharSequenceTranslator translator : translators) {
+                final int consumed = translator.translate(input, index, out);
+                if(consumed != 0) {
+                    return consumed;
+                }
+            }
+            return 0;
+        }
+    }
+
+    private static class OctalUnescaper implements CharSequenceTranslator {
+        @Override
+        public int translate(final CharSequence input, final int index, final Writer out)
{
+            final int remaining = input.length() - index - 1;
+            final StringBuilder builder = new StringBuilder();
+            if (input.charAt(index) == '\\' && remaining > 0 && isOctalDigit(input.charAt(index
+ 1))) {
+                final int next = index + 1;
+                final int next2 = index + 2;
+                final int next3 = index + 3;
+
+                builder.append(input.charAt(next));
+
+                if (remaining > 1 && isOctalDigit(input.charAt(next2))) {
+                    builder.append(input.charAt(next2));
+                    if (remaining > 2 && isZeroToThree(input.charAt(next)) &&
isOctalDigit(input.charAt(next3))) {
+                        builder.append(input.charAt(next3));
+                    }
+                }
+
+                try {
+                    out.write(Integer.parseInt(builder.toString(), 8));
+                } catch (IOException e) {
+                    throw new IllegalStateException(e);
+                }
+                return 1 + builder.length();
+            }
+            return 0;
+        }
+
+        private boolean isOctalDigit(final char ch) {
+            return ch >= '0' && ch <= '7';
+        }
+
+        private boolean isZeroToThree(final char ch) {
+            return ch >= '0' && ch <= '3';
+        }
+    }
+
+    public static class UnicodeUnescaper implements CharSequenceTranslator {
+        @Override
+        public int translate(final CharSequence input, final int index, final Writer out)
{
+            if (input.charAt(index) == '\\' && index + 1 < input.length() &&
input.charAt(index + 1) == 'u') {
+                int i = 2;
+                while (index + i < input.length() && input.charAt(index + i) ==
'u') {
+                    i++;
+                }
+
+                if (index + i < input.length() && input.charAt(index + i) == '+')
{
+                    i++;
+                }
+
+                if (index + i + 4 <= input.length()) {
+                    // Get 4 hex digits
+                    final CharSequence unicode = input.subSequence(index + i, index + i +
4);
+
+                    try {
+                        final int value = Integer.parseInt(unicode.toString(), 16);
+                        out.write((char) value);
+                    } catch (final NumberFormatException nfe) {
+                        throw new IllegalArgumentException("Unable to parse unicode value:
" + unicode, nfe);
+                    } catch (final IOException e) {
+                        throw new IllegalStateException(e);
+                    }
+                    return i + 4;
+                }
+                throw new IllegalArgumentException("Less than 4 hex digits in unicode value:
'" + input.subSequence(index, input.length())
+                        + "' due to end of CharSequence");
+            }
+            return 0;
+        }
+    }
+
+    public static class LookupTranslator implements CharSequenceTranslator {
+        private final Map<String, String> lookupMap;
+        private final Set<Character> prefixSet;
+        private final int shortest;
+        private final int longest;
+
+        private LookupTranslator(final String[][] lookup) {
+            lookupMap = new HashMap<>();
+            prefixSet = new HashSet<>();
+            int _shortest = Integer.MAX_VALUE;
+            int _longest = 0;
+            if (lookup != null) {
+                for (final CharSequence[] seq : lookup) {
+                    this.lookupMap.put(seq[0].toString(), seq[1].toString());
+                    this.prefixSet.add(seq[0].charAt(0));
+                    final int sz = seq[0].length();
+                    if (sz < _shortest) {
+                        _shortest = sz;
+                    }
+                    if (sz > _longest) {
+                        _longest = sz;
+                    }
+                }
+            }
+            shortest = _shortest;
+            longest = _longest;
+        }
+
+        @Override
+        public int translate(final CharSequence input, final int index, final Writer out)
{
+            if (prefixSet.contains(input.charAt(index))) {
+                int max = longest;
+                if (index + longest > input.length()) {
+                    max = input.length() - index;
+                }
+                for (int i = max; i >= shortest; i--) {
+                    final CharSequence subSeq = input.subSequence(index, index + i);
+                    final String result = lookupMap.get(subSeq.toString());
+
+                    if (result != null) {
+                        try {
+                            out.write(result);
+                        } catch (final IOException e) {
+                            throw new IllegalStateException(e);
+                        }
+                        return i;
+                    }
+                }
+            }
+            return 0;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/bval/blob/ac7d327a/bval-jsr/src/test/java/org/apache/bval/jsr/xml/Demo.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/test/java/org/apache/bval/jsr/xml/Demo.java b/bval-jsr/src/test/java/org/apache/bval/jsr/xml/Demo.java
index 2552a3d..793fa5f 100644
--- a/bval-jsr/src/test/java/org/apache/bval/jsr/xml/Demo.java
+++ b/bval-jsr/src/test/java/org/apache/bval/jsr/xml/Demo.java
@@ -23,7 +23,6 @@ import javax.xml.bind.UnmarshallerHandler;
 import javax.xml.parsers.SAXParser;
 import javax.xml.parsers.SAXParserFactory;
 
-import org.apache.commons.lang3.builder.ToStringBuilder;
 import org.junit.Test;
 import org.xml.sax.InputSource;
 import org.xml.sax.XMLReader;
@@ -51,6 +50,6 @@ public class Demo {
         InputSource xml = new InputSource(getClass().getResourceAsStream("/sample-validation2.xml"));
         xr.parse(xml);
         JAXBElement<ValidationConfigType> result = (JAXBElement<ValidationConfigType>)
unmarshallerHandler.getResult();
-        System.out.println(ToStringBuilder.reflectionToString(result.getValue()));
+        System.out.println(result.getValue());
     }
 }

http://git-wip-us.apache.org/repos/asf/bval/blob/ac7d327a/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 8b2545a..1fe732b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -324,11 +324,6 @@
                 <optional>true</optional>
             </dependency>
             <dependency>
-                <groupId>commons-beanutils</groupId>
-                <artifactId>commons-beanutils-core</artifactId>
-                <version>1.8.3</version>
-            </dependency>
-            <dependency>
                 <groupId>org.apache.commons</groupId>
                 <artifactId>commons-weaver-privilizer-api</artifactId>
                 <version>${commons.weaver.version}</version>
@@ -364,16 +359,9 @@
             <dependency>
                 <groupId>org.apache.tomcat</groupId>
                 <artifactId>tomcat-el-api</artifactId>
-                <version>9.0.5</version>
+                <version>9.0.12</version>
                 <scope>provided</scope>
             </dependency>
-            <dependency>
-	            <groupId>com.oracle</groupId>
-	            <artifactId>javafx</artifactId>
-	            <version>8.0</version>
-	            <systemPath>${java.home}/lib/ext/jfxrt.jar</systemPath>
-	            <scope>system</scope>
-            </dependency>
         </dependencies>
     </dependencyManagement>
 


Mime
View raw message