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 2021/08/18 10:11:40 UTC

[maven-javadoc-plugin] branch master updated: [MJAVADOC-679] "Unable to compute stale date" in a directory with accent characters (charset issue)

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

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


The following commit(s) were added to refs/heads/master by this push:
     new d2dd532  [MJAVADOC-679] "Unable to compute stale date" in a directory with accent characters (charset issue)
d2dd532 is described below

commit d2dd5321dc02e793d87c722224c40d94a607cb51
Author: rfscholte <rf...@apache.org>
AuthorDate: Wed Aug 18 12:11:27 2021 +0200

    [MJAVADOC-679] "Unable to compute stale date" in a directory with accent characters (charset issue)
---
 .../projects/MJAVADOC-679_encoding/module1/pom.xml | 49 ++++++++++++++++++
 .../module1/src/main/java/com/foo/MyClass.java     | 26 ++++++++++
 src/it/projects/MJAVADOC-679_encoding/pom.xml      | 59 ++++++++++++++++++++++
 src/it/projects/MJAVADOC-679_encoding/setup.groovy | 20 ++++++++
 .../maven/plugins/javadoc/AbstractJavadocMojo.java | 26 +++++++---
 .../apache/maven/plugins/javadoc/StaleHelper.java  | 19 +++++--
 6 files changed, 190 insertions(+), 9 deletions(-)

diff --git a/src/it/projects/MJAVADOC-679_encoding/module1/pom.xml b/src/it/projects/MJAVADOC-679_encoding/module1/pom.xml
new file mode 100644
index 0000000..1b6b9fa
--- /dev/null
+++ b/src/it/projects/MJAVADOC-679_encoding/module1/pom.xml
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ 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 xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <parent>
+    <groupId>org.apache.maven.plugins.javadoc.it</groupId>
+    <artifactId>mjavadoc679</artifactId>
+    <version>1.0-SNAPSHOT</version>
+  </parent>
+  <artifactId>module1</artifactId>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-javadoc-plugin</artifactId>
+        <executions>
+          <execution>
+            <goals>
+              <goal>jar</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>
diff --git a/src/it/projects/MJAVADOC-679_encoding/module1/src/main/java/com/foo/MyClass.java b/src/it/projects/MJAVADOC-679_encoding/module1/src/main/java/com/foo/MyClass.java
new file mode 100644
index 0000000..385265d
--- /dev/null
+++ b/src/it/projects/MJAVADOC-679_encoding/module1/src/main/java/com/foo/MyClass.java
@@ -0,0 +1,26 @@
+package com.foo;
+
+/*
+ * 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.util.Arrays;
+
+public class MyClass
+{
+}
diff --git a/src/it/projects/MJAVADOC-679_encoding/pom.xml b/src/it/projects/MJAVADOC-679_encoding/pom.xml
new file mode 100644
index 0000000..d0d3d0e
--- /dev/null
+++ b/src/it/projects/MJAVADOC-679_encoding/pom.xml
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ 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 xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.plugins.javadoc.it</groupId>
+  <artifactId>mjavadoc679</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  <packaging>pom</packaging>
+
+  <url>https://issues.apache.org/jira/browse/MJAVADOC-679</url>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    <maven.compiler.source>@maven.compiler.source@</maven.compiler.source>
+    <maven.compiler.target>@maven.compiler.target@</maven.compiler.target>
+  </properties>
+
+  <build>
+    <pluginManagement>
+      <plugins>
+        <plugin>
+          <groupId>org.apache.maven.plugins</groupId>
+          <artifactId>maven-compiler-plugin</artifactId>
+          <version>3.8.0</version>
+        </plugin>
+        <plugin>
+          <groupId>org.apache.maven.plugins</groupId>
+          <artifactId>maven-javadoc-plugin</artifactId>
+          <version>@project.version@</version>
+        </plugin>
+      </plugins>
+    </pluginManagement>
+  </build>
+
+  <modules>
+    <module>môdülé</module>
+  </modules>
+</project>
diff --git a/src/it/projects/MJAVADOC-679_encoding/setup.groovy b/src/it/projects/MJAVADOC-679_encoding/setup.groovy
new file mode 100644
index 0000000..e6403b3
--- /dev/null
+++ b/src/it/projects/MJAVADOC-679_encoding/setup.groovy
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+ 
+new File(basedir, 'module1').renameTo(new File(basedir, 'môdülé')) 
\ No newline at end of file
diff --git a/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java b/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java
index 05dfe49..bc81ff6 100644
--- a/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java
+++ b/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java
@@ -114,6 +114,7 @@ import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
 import java.net.URLClassLoader;
+import java.nio.charset.Charset;
 import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
 import java.nio.file.Path;
@@ -4822,15 +4823,18 @@ public abstract class AbstractJavadocMojo
         options.append( StringUtils.join( arguments.iterator(),
                                           SystemUtils.LINE_SEPARATOR ) );
 
-        /* default to platform encoding */
-        String outputFileEncoding = null;
+        Charset outputFileEncoding;
         if ( JAVA_VERSION.isAtLeast( "9" ) && JAVA_VERSION.isBefore( "12" ) )
         {
-            outputFileEncoding = StandardCharsets.UTF_8.name();
+            outputFileEncoding = StandardCharsets.UTF_8;
+        }
+        else
+        {
+            outputFileEncoding = Charset.defaultCharset();
         }
         try
         {
-            FileUtils.fileWrite( optionsFile.getAbsolutePath(), outputFileEncoding, options.toString() );
+            Files.write( optionsFile.toPath(), Collections.singleton( options ), outputFileEncoding );
         }
         catch ( IOException e )
         {
@@ -4880,10 +4884,20 @@ public abstract class AbstractJavadocMojo
             quotedFiles.add( JavadocUtil.quotedPathArgument( file ) );
         }
 
+        Charset cs;
+        if ( JavaVersion.JAVA_SPECIFICATION_VERSION.isAtLeast( "9" )
+            && JavaVersion.JAVA_SPECIFICATION_VERSION.isBefore( "12" ) )
+        {
+            cs = StandardCharsets.UTF_8;
+        }
+        else
+        {
+            cs = Charset.defaultCharset();
+        }
+
         try
         {
-            FileUtils.fileWrite( argfileFile.getAbsolutePath(), null /* platform encoding */,
-                                 StringUtils.join( quotedFiles.iterator(), SystemUtils.LINE_SEPARATOR ) );
+            Files.write( argfileFile.toPath(), quotedFiles, cs );
         }
         catch ( IOException e )
         {
diff --git a/src/main/java/org/apache/maven/plugins/javadoc/StaleHelper.java b/src/main/java/org/apache/maven/plugins/javadoc/StaleHelper.java
index 1e585da..a5aa586 100644
--- a/src/main/java/org/apache/maven/plugins/javadoc/StaleHelper.java
+++ b/src/main/java/org/apache/maven/plugins/javadoc/StaleHelper.java
@@ -21,6 +21,7 @@ package org.apache.maven.plugins.javadoc;
 
 import java.io.File;
 import java.io.IOException;
+import java.nio.charset.Charset;
 import java.nio.charset.StandardCharsets;
 import java.nio.file.DirectoryStream;
 import java.nio.file.Files;
@@ -31,7 +32,7 @@ import java.util.Collections;
 import java.util.List;
 
 import org.apache.maven.reporting.MavenReportException;
-import org.codehaus.plexus.util.FileUtils;
+import org.codehaus.plexus.languages.java.version.JavaVersion;
 import org.codehaus.plexus.util.StringUtils;
 import org.codehaus.plexus.util.cli.Commandline;
 
@@ -59,12 +60,24 @@ public class StaleHelper
             Path dir = cmd.getWorkingDirectory().toPath().toAbsolutePath().normalize();
             String[] args = cmd.getArguments();
             Collections.addAll( options, args );
+            
+            final Charset cs;
+            if ( JavaVersion.JAVA_SPECIFICATION_VERSION.isAtLeast( "9" )
+                && JavaVersion.JAVA_SPECIFICATION_VERSION.isBefore( "12" ) )
+            {
+                cs = StandardCharsets.UTF_8;
+            }
+            else
+            {
+                cs = Charset.defaultCharset();
+            }
+            
             for ( String arg : args )
             {
                 if ( arg.startsWith( "@" ) )
                 {
                     String name = arg.substring( 1 );
-                    options.addAll( Files.readAllLines( dir.resolve( name ), StandardCharsets.UTF_8 ) );
+                    options.addAll( Files.readAllLines( dir.resolve( name ), cs ) );
                     ignored.add( name );
                 }
             }
@@ -130,7 +143,7 @@ public class StaleHelper
         {
             String curdata = getStaleData( cmd );
             Files.createDirectories( path.getParent() );
-            FileUtils.fileWrite( path.toFile(), null /* platform encoding */, curdata );
+            Files.write( path, Collections.singleton( curdata ), Charset.defaultCharset() );
         }
         catch ( IOException e )
         {