You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by rf...@apache.org on 2018/05/13 15:38:23 UTC

[maven-studies] branch maven-xml updated: Introduce ParentVersionResolver to offer stronger resolution options

This is an automated email from the ASF dual-hosted git repository.

rfscholte pushed a commit to branch maven-xml
in repository https://gitbox.apache.org/repos/asf/maven-studies.git


The following commit(s) were added to refs/heads/maven-xml by this push:
     new 6630917  Introduce ParentVersionResolver to offer stronger resolution options
6630917 is described below

commit 6630917fca9f7532bf92a6edb70b0c335c6fe309
Author: rfscholte <rf...@apache.org>
AuthorDate: Sun May 13 17:38:17 2018 +0200

    Introduce ParentVersionResolver to offer stronger resolution options
---
 .../maven/xml/filters/ParentVersionResolver.java   | 42 ++++++++++++++++++++++
 .../apache/maven/xml/filters/ParentXMLFilter.java  |  7 ++--
 .../apache/maven/xml/filters/ModelFilterTest.java  |  2 +-
 .../maven/xml/filters/ParentXMLFilterTest.java     |  4 +--
 4 files changed, 48 insertions(+), 7 deletions(-)

diff --git a/src/main/java/org/apache/maven/xml/filters/ParentVersionResolver.java b/src/main/java/org/apache/maven/xml/filters/ParentVersionResolver.java
new file mode 100644
index 0000000..74ec4b0
--- /dev/null
+++ b/src/main/java/org/apache/maven/xml/filters/ParentVersionResolver.java
@@ -0,0 +1,42 @@
+package org.apache.maven.xml.filters;
+
+/*
+ * 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.
+ */
+
+/**
+ * 
+ * @author Robert Scholte
+ * @since 4.0.0
+ */
+@FunctionalInterface
+public interface ParentVersionResolver
+{
+    /**
+     * Resolve the version based on the relative path.
+     * The groupId and artifactId can be used to confirm the expected parent.
+     * Return {@code null} if the version could not be resolved, so the xml will
+     * stay as it is and the ModelBuilder will make it fail.
+     *  
+     * @param relativePath the relativePath
+     * @param groupId the groupId
+     * @param artifactId the artifactId
+     * @return the resolved version, otherwise {@code null}
+     */
+    String resolve( String relativePath, String groupId, String artifactId );
+}
diff --git a/src/main/java/org/apache/maven/xml/filters/ParentXMLFilter.java b/src/main/java/org/apache/maven/xml/filters/ParentXMLFilter.java
index 71daff6..a5bdff8 100644
--- a/src/main/java/org/apache/maven/xml/filters/ParentXMLFilter.java
+++ b/src/main/java/org/apache/maven/xml/filters/ParentXMLFilter.java
@@ -21,7 +21,6 @@ package org.apache.maven.xml.filters;
 
 import java.util.ArrayList;
 import java.util.List;
-import java.util.function.Function;
 
 import org.apache.maven.xml.SAXEvent;
 import org.apache.maven.xml.SAXEventFactory;
@@ -64,9 +63,9 @@ public class ParentXMLFilter
 
     private SAXEventFactory eventFactory;
 
-    private final Function<String, String> relativePathMapper;
+    private final ParentVersionResolver relativePathMapper;
 
-    public ParentXMLFilter( Function<String, String> relativePathMapper )
+    public ParentXMLFilter( ParentVersionResolver relativePathMapper )
     {
         this.relativePathMapper = relativePathMapper;
     }
@@ -318,6 +317,6 @@ public class ParentXMLFilter
 
     protected String relativePathToVersion( String relativePath )
     {
-        return relativePathMapper.apply( relativePath );
+        return relativePathMapper.resolve( relativePath, groupId, artifactId );
     }
 }
diff --git a/src/test/java/org/apache/maven/xml/filters/ModelFilterTest.java b/src/test/java/org/apache/maven/xml/filters/ModelFilterTest.java
index 8961fe2..4c40baf 100644
--- a/src/test/java/org/apache/maven/xml/filters/ModelFilterTest.java
+++ b/src/test/java/org/apache/maven/xml/filters/ModelFilterTest.java
@@ -40,7 +40,7 @@ public class ModelFilterTest extends AbstractXMLFilterTests
         // order matters!!
         filter.addFilter( new ThisXMLFilter( x -> "1.0.0" ) );
         filter.addFilter( new FastForwardFilter() );
-        filter.addFilter( new ParentXMLFilter( x -> "1.0.0" ) );
+        filter.addFilter( new ParentXMLFilter( ( r, g, a ) -> "1.0.0" ) );
         filter.addFilter( new ReactorDependencyXMLFilter( x -> "2.0.0" ) );
     }
     
diff --git a/src/test/java/org/apache/maven/xml/filters/ParentXMLFilterTest.java b/src/test/java/org/apache/maven/xml/filters/ParentXMLFilterTest.java
index 5531529..b50fda7 100644
--- a/src/test/java/org/apache/maven/xml/filters/ParentXMLFilterTest.java
+++ b/src/test/java/org/apache/maven/xml/filters/ParentXMLFilterTest.java
@@ -32,7 +32,7 @@ public class ParentXMLFilterTest extends AbstractXMLFilterTests
     @Before
     public void setUp()
     {
-        filter = new ParentXMLFilter( r -> "1.0.0" );
+        filter = new ParentXMLFilter( ( r, g, a ) -> "1.0.0" );
     }
 
     @Test
@@ -99,7 +99,7 @@ public class ParentXMLFilterTest extends AbstractXMLFilterTests
     @Test
     public void testInvalidRelativePath() throws Exception
     {
-        XMLFilter filter = new ParentXMLFilter( r -> null );
+        XMLFilter filter = new ParentXMLFilter( ( r, g, a ) -> null );
         
         String input = "<parent>"
             + "<groupId>GROUPID</groupId>"

-- 
To stop receiving notification emails like this one, please contact
rfscholte@apache.org.