Skip to content

Commit

Permalink
[MJAVADOC-679] "Unable to compute stale date" in a directory with acc…
Browse files Browse the repository at this point in the history
…ent characters (charset issue)
  • Loading branch information
rfscholte committed Aug 18, 2021
1 parent 791cb8b commit d2dd532
Show file tree
Hide file tree
Showing 6 changed files with 190 additions and 9 deletions.
49 changes: 49 additions & 0 deletions src/it/projects/MJAVADOC-679_encoding/module1/pom.xml
Original file line number Diff line number Diff line change
@@ -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>
Original file line number Diff line number Diff line change
@@ -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
{
}
59 changes: 59 additions & 0 deletions src/it/projects/MJAVADOC-679_encoding/pom.xml
Original file line number Diff line number Diff line change
@@ -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>
20 changes: 20 additions & 0 deletions src/it/projects/MJAVADOC-679_encoding/setup.groovy
Original file line number Diff line number Diff line change
@@ -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é'))
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
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;
Expand Down Expand Up @@ -4822,15 +4823,18 @@ private void addCommandLineOptions( Commandline cmd, List<String> arguments, Fil
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 )
{
Expand Down Expand Up @@ -4880,10 +4884,20 @@ private void addCommandLineArgFile( Commandline cmd, File javadocOutputDirectory
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 )
{
Expand Down
19 changes: 16 additions & 3 deletions src/main/java/org/apache/maven/plugins/javadoc/StaleHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

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;
Expand All @@ -31,7 +32,7 @@
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;

Expand Down Expand Up @@ -59,12 +60,24 @@ public static String getStaleData( Commandline cmd )
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 );
}
}
Expand Down Expand Up @@ -130,7 +143,7 @@ public static void writeStaleData( Commandline cmd, Path path )
{
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 )
{
Expand Down

0 comments on commit d2dd532

Please sign in to comment.