You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by eo...@apache.org on 2019/01/27 20:45:45 UTC

[maven-enforcer] branch master updated: [MENFORCER-319] Handle parsing of pom.xml in BanDuplicatePomDependencyVersions.java similarly to how actual Maven model parser handles it to fix handling of pom.xml files with UTF-8 BOM.

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

eolivelli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-enforcer.git


The following commit(s) were added to refs/heads/master by this push:
     new c2f1ce2  [MENFORCER-319] Handle parsing of pom.xml in BanDuplicatePomDependencyVersions.java similarly to how actual Maven model parser handles it to fix handling of pom.xml files with UTF-8 BOM.
c2f1ce2 is described below

commit c2f1ce236a6be3654c27aa27d1595f0aeb23fd9c
Author: Vaclav Haisman <vh...@gmail.com>
AuthorDate: Tue Nov 13 17:28:36 2018 +0100

    [MENFORCER-319] Handle parsing of pom.xml in BanDuplicatePomDependencyVersions.java
    similarly to how actual Maven model parser handles it to fix handling
    of pom.xml files with UTF-8 BOM.
---
 .../BanDuplicatePomDependencyVersions.java         | 10 ++--
 .../invoker.properties                             | 18 ++++++
 .../pom.xml                                        | 65 ++++++++++++++++++++++
 .../verify.groovy                                  | 26 +++++++++
 4 files changed, 114 insertions(+), 5 deletions(-)

diff --git a/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/BanDuplicatePomDependencyVersions.java b/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/BanDuplicatePomDependencyVersions.java
index 5eaa09a..36a94ed 100644
--- a/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/BanDuplicatePomDependencyVersions.java
+++ b/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/BanDuplicatePomDependencyVersions.java
@@ -19,8 +19,8 @@ package org.apache.maven.plugins.enforcer;
  * under the License.
  */
 
+import java.io.FileInputStream;
 import java.io.FileNotFoundException;
-import java.io.FileReader;
 import java.io.IOException;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -66,13 +66,13 @@ public class BanDuplicatePomDependencyVersions
 
         // re-read model, because M3 uses optimized model
         MavenXpp3Reader modelReader = new MavenXpp3Reader();
-        FileReader pomReader = null;
+        FileInputStream pomInputStream = null;
         Model model;
         try
         {
-            pomReader = new FileReader( project.getFile() );
+            pomInputStream = new FileInputStream( project.getFile() );
 
-            model = modelReader.read( pomReader );
+            model = modelReader.read( pomInputStream, false );
         }
         catch ( FileNotFoundException e )
         {
@@ -88,7 +88,7 @@ public class BanDuplicatePomDependencyVersions
         }
         finally
         {
-            IOUtil.close( pomReader );
+            IOUtil.close( pomInputStream );
         }
 
         // @todo reuse ModelValidator when possible
diff --git a/maven-enforcer-plugin/src/it/projects/ban-pom-dependency-version-utf8-with-bom/invoker.properties b/maven-enforcer-plugin/src/it/projects/ban-pom-dependency-version-utf8-with-bom/invoker.properties
new file mode 100644
index 0000000..c98ac4c
--- /dev/null
+++ b/maven-enforcer-plugin/src/it/projects/ban-pom-dependency-version-utf8-with-bom/invoker.properties
@@ -0,0 +1,18 @@
+# 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.
+
+invoker.buildResult=failure
\ No newline at end of file
diff --git a/maven-enforcer-plugin/src/it/projects/ban-pom-dependency-version-utf8-with-bom/pom.xml b/maven-enforcer-plugin/src/it/projects/ban-pom-dependency-version-utf8-with-bom/pom.xml
new file mode 100644
index 0000000..125f87e
--- /dev/null
+++ b/maven-enforcer-plugin/src/it/projects/ban-pom-dependency-version-utf8-with-bom/pom.xml
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- This file is intenitonally in UTF-8 BOM encoding. Keep it that way. -->
+<!--
+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.
+-->
+
+<project>
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.its.enforcer</groupId>
+  <artifactId>ban-pom-dependency-version-utf8-with-bom</artifactId>
+  <version>1.0-SNAPSHOT</version>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-enforcer-plugin</artifactId>
+        <version>@project.version@</version>
+        <executions>
+          <execution>
+            <id>test</id>
+            <goals>
+              <goal>enforce</goal>
+            </goals>
+            <configuration>
+              <rules>
+                <banDuplicatePomDependencyVersions/>
+              </rules>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.maven.plugins.enforcer.its</groupId>
+      <artifactId>menforcer152</artifactId>
+      <version>1.0</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven.plugins.enforcer.its</groupId>
+      <artifactId>menforcer152</artifactId>
+      <version>1.0</version>
+    </dependency>
+  </dependencies>
+
+</project>
diff --git a/maven-enforcer-plugin/src/it/projects/ban-pom-dependency-version-utf8-with-bom/verify.groovy b/maven-enforcer-plugin/src/it/projects/ban-pom-dependency-version-utf8-with-bom/verify.groovy
new file mode 100644
index 0000000..eb917f9
--- /dev/null
+++ b/maven-enforcer-plugin/src/it/projects/ban-pom-dependency-version-utf8-with-bom/verify.groovy
@@ -0,0 +1,26 @@
+/*
+ * 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.
+ */
+File buildLog = new File( basedir, 'build.log' )
+assert buildLog.text.contains( '[WARNING] Rule 0: org.apache.maven.plugins.enforcer.BanDuplicatePomDependencyVersions failed with message:' )
+assert buildLog.text.contains( 'Found 1 duplicate dependency declaration in this project:' )
+assert buildLog.text.contains( '- dependencies.dependency[org.apache.maven.plugins.enforcer.its:menforcer152:jar] ( 2 times )' )
+
+
+
+ 
\ No newline at end of file