[ 
https://issues.apache.org/jira/browse/MNG-6437?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17614790#comment-17614790
 ] 

ASF GitHub Bot commented on MNG-6437:
-------------------------------------

gnodet commented on code in PR #812:
URL: https://github.com/apache/maven/pull/812#discussion_r990825137


##########
maven-core/src/main/java/org/apache/maven/plugin/ReflectionValueExtractor.java:
##########
@@ -0,0 +1,366 @@
+package org.apache.maven.plugin;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+import java.lang.ref.WeakReference;
+import java.lang.reflect.Array;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.WeakHashMap;
+
+import org.codehaus.plexus.util.StringUtils;
+import org.codehaus.plexus.util.introspection.ClassMap;
+
+/**
+ * <p>
+ * Using simple dotted expressions to extract the values from an Object 
instance, For example we might want to extract a
+ * value like: <code>project.build.sourceDirectory</code>
+ * </p>
+ * <p>
+ * The implementation supports indexed, nested and mapped properties similar 
to the JSP way.
+ * </p>
+ * <p>
+ * In addition to usual getters using {@code getXxx} or {@code isXxx} 
suffixes, accessors
+ * using {code asXxx} or {@ocode toXxx} prefixes are also supported.
+ * </p>
+ */
+public class ReflectionValueExtractor
+{
+    private static final Class<?>[] CLASS_ARGS = new Class[0];
+
+    private static final Object[] OBJECT_ARGS = new Object[0];
+
+    /**
+     * Use a WeakHashMap here, so the keys (Class objects) can be garbage 
collected. This approach prevents permgen
+     * space overflows due to retention of discarded classloaders.
+     */
+    private static final Map<Class<?>, WeakReference<ClassMap>> CLASS_MAPS = 
new WeakHashMap<>();
+
+    static final int EOF = -1;
+
+    static final char PROPERTY_START = '.';
+
+    static final char INDEXED_START = '[';
+
+    static final char INDEXED_END = ']';
+
+    static final char MAPPED_START = '(';
+
+    static final char MAPPED_END = ')';
+
+    static class Tokenizer
+    {
+        final String expression;
+
+        int idx;
+
+        Tokenizer( String expression )
+        {
+            this.expression = expression;
+        }
+
+        public int peekChar()
+        {
+            return idx < expression.length() ? expression.charAt( idx ) : EOF;
+        }
+
+        public int skipChar()
+        {
+            return idx < expression.length() ? expression.charAt( idx++ ) : 
EOF;
+        }
+
+        public String nextToken( char delimiter )
+        {
+            int start = idx;
+
+            while ( idx < expression.length() && delimiter != 
expression.charAt( idx ) )
+            {
+                idx++;
+            }
+
+            // delimiter MUST be present
+            if ( idx <= start || idx >= expression.length() )
+            {
+                return null;
+            }
+
+            return expression.substring( start, idx++ );
+        }
+
+        public String nextPropertyName()
+        {
+            final int start = idx;
+
+            while ( idx < expression.length() && 
Character.isJavaIdentifierPart( expression.charAt( idx ) ) )
+            {
+                idx++;
+            }
+
+            // property name does not require delimiter
+            if ( idx <= start || idx > expression.length() )
+            {
+                return null;
+            }
+
+            return expression.substring( start, idx );
+        }
+
+        public int getPosition()
+        {
+            return idx < expression.length() ? idx : EOF;
+        }
+
+        // to make tokenizer look pretty in debugger
+        @Override
+        public String toString()
+        {
+            return idx < expression.length() ? expression.substring( idx ) : 
"<EOF>";
+        }
+    }
+
+    private ReflectionValueExtractor()
+    {
+    }
+
+    /**
+     * <p>The implementation supports indexed, nested and mapped 
properties.</p>
+     *
+     * <ul>
+     * <li>nested properties should be defined by a dot, i.e. 
"user.address.street"</li>
+     * <li>indexed properties (java.util.List or array instance) should be 
contains <code>(\\w+)\\[(\\d+)\\]</code>
+     * pattern, i.e. "user.addresses[1].street"</li>
+     * <li>mapped properties should be contains <code>(\\w+)\\((.+)\\)</code> 
pattern, i.e.
+     * "user.addresses(myAddress).street"</li>

Review Comment:
   Well, I have not written this code, this is just a copy from the plexus 
class with a small modification to add support for `toXxx` and `asXxx`.





> Generic .uri suffix to get the URI representation of any file property
> ----------------------------------------------------------------------
>
>                 Key: MNG-6437
>                 URL: https://issues.apache.org/jira/browse/MNG-6437
>             Project: Maven
>          Issue Type: Improvement
>          Components: Core
>    Affects Versions: 3.5.4
>            Reporter: Claude Brisson
>            Assignee: Guillaume Nodet
>            Priority: Major
>             Fix For: 4.0.0-alpha-1, 4.0.0
>
>
> It's impossible to properly generate, for instance, a java policy file which 
> needs files URIs, using either Cargo properties and filtered config files, or 
> just filtered resources.
> In both cases, the problem is the impossibility to generate proper URIs when 
> expanding Maven properties (see also MNG-3760).
> The candidate feature is to add a way to explicitly request the URI when 
> expanding a property by means of a {{.uri}} suffix. The underlying 
> {{getUri()}} method should rely on the correct {{Path#toUri()}} and neither 
> {{File#toUri()}} nor {{File#toString()}}, see the SO reference in MNG-6386.
> For instance:
>  * {{${project.basedir.uri}}} instead of the broken {{${project.baseUri}}} 
> (and of course fix MNG-6436 otherwise it's useless)
>  * {{${project.build.directory.uri}}}
>  * {{${settings.localRepository.uri}}}
>  * etc
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to