Skip to content

Commit d2dd532

Browse files
committed
[MJAVADOC-679] "Unable to compute stale date" in a directory with accent characters (charset issue)
1 parent 791cb8b commit d2dd532

File tree

6 files changed

+190
-9
lines changed

6 files changed

+190
-9
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Licensed to the Apache Software Foundation (ASF) under one
4+
~ or more contributor license agreements. See the NOTICE file
5+
~ distributed with this work for additional information
6+
~ regarding copyright ownership. The ASF licenses this file
7+
~ to you under the Apache License, Version 2.0 (the
8+
~ "License"); you may not use this file except in compliance
9+
~ with the License. You may obtain a copy of the License at
10+
~
11+
~ http://www.apache.org/licenses/LICENSE-2.0
12+
~
13+
~ Unless required by applicable law or agreed to in writing,
14+
~ software distributed under the License is distributed on an
15+
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
~ KIND, either express or implied. See the License for the
17+
~ specific language governing permissions and limitations
18+
~ under the License.
19+
-->
20+
21+
<project xmlns="http://maven.apache.org/POM/4.0.0"
22+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
23+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
24+
<modelVersion>4.0.0</modelVersion>
25+
26+
<parent>
27+
<groupId>org.apache.maven.plugins.javadoc.it</groupId>
28+
<artifactId>mjavadoc679</artifactId>
29+
<version>1.0-SNAPSHOT</version>
30+
</parent>
31+
<artifactId>module1</artifactId>
32+
33+
<build>
34+
<plugins>
35+
<plugin>
36+
<groupId>org.apache.maven.plugins</groupId>
37+
<artifactId>maven-javadoc-plugin</artifactId>
38+
<executions>
39+
<execution>
40+
<goals>
41+
<goal>jar</goal>
42+
</goals>
43+
</execution>
44+
</executions>
45+
</plugin>
46+
</plugins>
47+
</build>
48+
49+
</project>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.foo;
2+
3+
/*
4+
* Licensed to the Apache Software Foundation (ASF) under one
5+
* or more contributor license agreements. See the NOTICE file
6+
* distributed with this work for additional information
7+
* regarding copyright ownership. The ASF licenses this file
8+
* to you under the Apache License, Version 2.0 (the
9+
* "License"); you may not use this file except in compliance
10+
* with the License. You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing,
15+
* software distributed under the License is distributed on an
16+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
* KIND, either express or implied. See the License for the
18+
* specific language governing permissions and limitations
19+
* under the License.
20+
*/
21+
22+
import java.util.Arrays;
23+
24+
public class MyClass
25+
{
26+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Licensed to the Apache Software Foundation (ASF) under one
4+
~ or more contributor license agreements. See the NOTICE file
5+
~ distributed with this work for additional information
6+
~ regarding copyright ownership. The ASF licenses this file
7+
~ to you under the Apache License, Version 2.0 (the
8+
~ "License"); you may not use this file except in compliance
9+
~ with the License. You may obtain a copy of the License at
10+
~
11+
~ http://www.apache.org/licenses/LICENSE-2.0
12+
~
13+
~ Unless required by applicable law or agreed to in writing,
14+
~ software distributed under the License is distributed on an
15+
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
~ KIND, either express or implied. See the License for the
17+
~ specific language governing permissions and limitations
18+
~ under the License.
19+
-->
20+
21+
<project xmlns="http://maven.apache.org/POM/4.0.0"
22+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
23+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
24+
<modelVersion>4.0.0</modelVersion>
25+
26+
<groupId>org.apache.maven.plugins.javadoc.it</groupId>
27+
<artifactId>mjavadoc679</artifactId>
28+
<version>1.0-SNAPSHOT</version>
29+
<packaging>pom</packaging>
30+
31+
<url>https://issues.apache.org/jira/browse/MJAVADOC-679</url>
32+
33+
<properties>
34+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
35+
<maven.compiler.source>@maven.compiler.source@</maven.compiler.source>
36+
<maven.compiler.target>@maven.compiler.target@</maven.compiler.target>
37+
</properties>
38+
39+
<build>
40+
<pluginManagement>
41+
<plugins>
42+
<plugin>
43+
<groupId>org.apache.maven.plugins</groupId>
44+
<artifactId>maven-compiler-plugin</artifactId>
45+
<version>3.8.0</version>
46+
</plugin>
47+
<plugin>
48+
<groupId>org.apache.maven.plugins</groupId>
49+
<artifactId>maven-javadoc-plugin</artifactId>
50+
<version>@project.version@</version>
51+
</plugin>
52+
</plugins>
53+
</pluginManagement>
54+
</build>
55+
56+
<modules>
57+
<module>môdülé</module>
58+
</modules>
59+
</project>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
new File(basedir, 'module1').renameTo(new File(basedir, 'môdülé'))

src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@
114114
import java.net.URISyntaxException;
115115
import java.net.URL;
116116
import java.net.URLClassLoader;
117+
import java.nio.charset.Charset;
117118
import java.nio.charset.StandardCharsets;
118119
import java.nio.file.Files;
119120
import java.nio.file.Path;
@@ -4822,15 +4823,18 @@ private void addCommandLineOptions( Commandline cmd, List<String> arguments, Fil
48224823
options.append( StringUtils.join( arguments.iterator(),
48234824
SystemUtils.LINE_SEPARATOR ) );
48244825

4825-
/* default to platform encoding */
4826-
String outputFileEncoding = null;
4826+
Charset outputFileEncoding;
48274827
if ( JAVA_VERSION.isAtLeast( "9" ) && JAVA_VERSION.isBefore( "12" ) )
48284828
{
4829-
outputFileEncoding = StandardCharsets.UTF_8.name();
4829+
outputFileEncoding = StandardCharsets.UTF_8;
4830+
}
4831+
else
4832+
{
4833+
outputFileEncoding = Charset.defaultCharset();
48304834
}
48314835
try
48324836
{
4833-
FileUtils.fileWrite( optionsFile.getAbsolutePath(), outputFileEncoding, options.toString() );
4837+
Files.write( optionsFile.toPath(), Collections.singleton( options ), outputFileEncoding );
48344838
}
48354839
catch ( IOException e )
48364840
{
@@ -4880,10 +4884,20 @@ private void addCommandLineArgFile( Commandline cmd, File javadocOutputDirectory
48804884
quotedFiles.add( JavadocUtil.quotedPathArgument( file ) );
48814885
}
48824886

4887+
Charset cs;
4888+
if ( JavaVersion.JAVA_SPECIFICATION_VERSION.isAtLeast( "9" )
4889+
&& JavaVersion.JAVA_SPECIFICATION_VERSION.isBefore( "12" ) )
4890+
{
4891+
cs = StandardCharsets.UTF_8;
4892+
}
4893+
else
4894+
{
4895+
cs = Charset.defaultCharset();
4896+
}
4897+
48834898
try
48844899
{
4885-
FileUtils.fileWrite( argfileFile.getAbsolutePath(), null /* platform encoding */,
4886-
StringUtils.join( quotedFiles.iterator(), SystemUtils.LINE_SEPARATOR ) );
4900+
Files.write( argfileFile.toPath(), quotedFiles, cs );
48874901
}
48884902
catch ( IOException e )
48894903
{

src/main/java/org/apache/maven/plugins/javadoc/StaleHelper.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import java.io.File;
2323
import java.io.IOException;
24+
import java.nio.charset.Charset;
2425
import java.nio.charset.StandardCharsets;
2526
import java.nio.file.DirectoryStream;
2627
import java.nio.file.Files;
@@ -31,7 +32,7 @@
3132
import java.util.List;
3233

3334
import org.apache.maven.reporting.MavenReportException;
34-
import org.codehaus.plexus.util.FileUtils;
35+
import org.codehaus.plexus.languages.java.version.JavaVersion;
3536
import org.codehaus.plexus.util.StringUtils;
3637
import org.codehaus.plexus.util.cli.Commandline;
3738

@@ -59,12 +60,24 @@ public static String getStaleData( Commandline cmd )
5960
Path dir = cmd.getWorkingDirectory().toPath().toAbsolutePath().normalize();
6061
String[] args = cmd.getArguments();
6162
Collections.addAll( options, args );
63+
64+
final Charset cs;
65+
if ( JavaVersion.JAVA_SPECIFICATION_VERSION.isAtLeast( "9" )
66+
&& JavaVersion.JAVA_SPECIFICATION_VERSION.isBefore( "12" ) )
67+
{
68+
cs = StandardCharsets.UTF_8;
69+
}
70+
else
71+
{
72+
cs = Charset.defaultCharset();
73+
}
74+
6275
for ( String arg : args )
6376
{
6477
if ( arg.startsWith( "@" ) )
6578
{
6679
String name = arg.substring( 1 );
67-
options.addAll( Files.readAllLines( dir.resolve( name ), StandardCharsets.UTF_8 ) );
80+
options.addAll( Files.readAllLines( dir.resolve( name ), cs ) );
6881
ignored.add( name );
6982
}
7083
}
@@ -130,7 +143,7 @@ public static void writeStaleData( Commandline cmd, Path path )
130143
{
131144
String curdata = getStaleData( cmd );
132145
Files.createDirectories( path.getParent() );
133-
FileUtils.fileWrite( path.toFile(), null /* platform encoding */, curdata );
146+
Files.write( path, Collections.singleton( curdata ), Charset.defaultCharset() );
134147
}
135148
catch ( IOException e )
136149
{

0 commit comments

Comments
 (0)