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 5610ef061..00467f076 100644 --- a/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java +++ b/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java @@ -1618,8 +1618,10 @@ public AbstractJavadocMojo( * This is used to skip the generation if nothing has changed. *

* + * @deprecated this mechanism was broken and has been removed * @since 3.2.0 */ + @Deprecated @Parameter( property = "staleDataPath", defaultValue = "${project.build.directory}/maven-javadoc-plugin-stale-data.txt") @@ -4971,70 +4973,6 @@ private void addTagletsFromTagletArtifacts(List arguments) throws MavenR * @throws MavenReportException if any errors occur */ private void executeJavadocCommandLine(Commandline cmd, File javadocOutputDirectory) throws MavenReportException { - if (staleDataPath != null) { - if (!isUpToDate(cmd)) { - doExecuteJavadocCommandLine(cmd, javadocOutputDirectory); - StaleHelper.writeStaleData(cmd, staleDataPath.toPath()); - } - } else { - doExecuteJavadocCommandLine(cmd, javadocOutputDirectory); - } - } - - /** - * Check if the javadoc is uptodate or not - * - * @param cmd not null - * @return true is the javadoc is uptodate, false otherwise - * @throws MavenReportException if any error occur - */ - private boolean isUpToDate(Commandline cmd) throws MavenReportException { - try { - List curdata = StaleHelper.getStaleData(cmd); - Path cacheData = staleDataPath.toPath(); - List prvdata; - if (Files.isRegularFile(cacheData)) { - prvdata = Files.lines(cacheData, EncodingUtils.getExpectedEncoding()) - .collect(Collectors.toList()); - } else { - prvdata = null; - } - if (curdata.equals(prvdata)) { - getLog().debug("Skipping javadoc generation, everything is up to date."); - return true; - } else { - if (prvdata == null) { - getLog().debug("No previous run data found, generating javadoc."); - } else { - getLog().debug("Configuration changed, re-generating javadoc."); - if (getLog().isDebugEnabled()) { - List newStrings = new ArrayList<>(curdata); - List remStrings = new ArrayList<>(prvdata); - newStrings.removeAll(prvdata); - remStrings.removeAll(curdata); - if (!remStrings.isEmpty()) { - getLog().debug(" Removed: " + String.join(", ", remStrings)); - } - if (!newStrings.isEmpty()) { - getLog().debug(" Added: " + String.join(", ", newStrings)); - } - } - } - } - } catch (IOException e) { - throw new MavenReportException("Error checking uptodate status", e); - } - return false; - } - - /** - * Execute the Javadoc command line - * - * @param cmd not null - * @param javadocOutputDirectory not null - * @throws MavenReportException if any errors occur - */ - private void doExecuteJavadocCommandLine(Commandline cmd, File javadocOutputDirectory) throws MavenReportException { if (getLog().isDebugEnabled()) { // no quoted arguments getLog().debug(CommandLineUtils.toString(cmd.getCommandline()).replaceAll("'", "")); diff --git a/src/main/java/org/apache/maven/plugins/javadoc/StaleHelper.java b/src/main/java/org/apache/maven/plugins/javadoc/StaleHelper.java deleted file mode 100644 index bcdf307e1..000000000 --- a/src/main/java/org/apache/maven/plugins/javadoc/StaleHelper.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * 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. - */ -package org.apache.maven.plugins.javadoc; - -import java.io.File; -import java.io.IOException; -import java.nio.file.DirectoryStream; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; - -import org.apache.maven.reporting.MavenReportException; -import org.codehaus.plexus.util.cli.Commandline; - -/** - * Helper class to compute and write data used to detect a - * stale javadoc. - */ -public class StaleHelper { - - /** - * Compute the data used to detect a stale javadoc - * - * @param cmd the command line - * @return the stale data - * @throws MavenReportException if an error occurs - */ - public static List getStaleData(Commandline cmd) throws MavenReportException { - try { - List ignored = new ArrayList<>(); - List options = new ArrayList<>(); - Path dir = cmd.getWorkingDirectory().toPath().toAbsolutePath().normalize(); - String[] args = cmd.getArguments(); - Collections.addAll(options, args); - - for (String arg : args) { - if (arg.startsWith("@")) { - String name = arg.substring(1); - options.addAll(Files.readAllLines(dir.resolve(name), EncodingUtils.getExpectedEncoding())); - ignored.add(name); - } - } - List state = new ArrayList<>(options); - boolean cp = false; - boolean sp = false; - for (String arg : options) { - if (cp) { - String s = unquote(arg); - for (String ps : s.split(File.pathSeparator)) { - Path p = dir.resolve(ps); - state.add(p + " = " + lastmod(p)); - } - } else if (sp) { - String s = unquote(arg); - for (String ps : s.split(File.pathSeparator)) { - Path p = dir.resolve(ps); - for (Path c : walk(p)) { - if (Files.isRegularFile(c)) { - state.add(c + " = " + lastmod(c)); - } - } - state.add(p + " = " + lastmod(p)); - } - } - cp = "-classpath".equals(arg); - sp = "-sourcepath".equals(arg); - } - for (Path p : walk(dir)) { - if (Files.isRegularFile(p) && !ignored.contains(p.getFileName().toString())) { - state.add(p + " = " + lastmod(p)); - } - } - return state; - } catch (Exception e) { - throw new MavenReportException("Unable to compute stale date", e); - } - } - - /** - * Write the data used to detect a stale javadoc - * - * @param cmd the command line - * @param path the stale data path - * @throws MavenReportException if an error occurs - */ - public static void writeStaleData(Commandline cmd, Path path) throws MavenReportException { - try { - List curdata = getStaleData(cmd); - Files.createDirectories(path.getParent()); - Files.write(path, curdata, EncodingUtils.getExpectedEncoding()); - } catch (IOException e) { - throw new MavenReportException("Error checking stale data", e); - } - } - - private static Collection walk(Path dir) { - Collection paths = new ArrayList<>(); - try (DirectoryStream directoryStream = Files.newDirectoryStream(dir)) { - for (Path p : directoryStream) { - paths.add(p); - } - return paths; - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - private static String unquote(String s) { - if (s.startsWith("'") && s.endsWith("'")) { - return s.substring(1, s.length() - 1).replaceAll("\\\\'", "'"); - } else { - return s; - } - } - - private static long lastmod(Path p) { - try { - return Files.getLastModifiedTime(p).toMillis(); - } catch (IOException e) { - return 0; - } - } -} diff --git a/src/test/java/org/apache/maven/plugins/javadoc/JavadocJarMojoTest.java b/src/test/java/org/apache/maven/plugins/javadoc/JavadocJarMojoTest.java index f36257eb0..ebb175996 100644 --- a/src/test/java/org/apache/maven/plugins/javadoc/JavadocJarMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/javadoc/JavadocJarMojoTest.java @@ -43,8 +43,6 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.mockito.Mockito.clearInvocations; -import static org.mockito.Mockito.verify; /** * @author Maria Odea Ching @@ -175,20 +173,4 @@ void testIncludeMavenDescriptorWhenExplicitlyConfigured(JavadocJarMojo mojo) thr "META-INF/maven/org.apache.maven.plugins.maven-javadoc-plugin.unit/javadocjar-archive-config/pom.xml", "META-INF/maven/org.apache.maven.plugins.maven-javadoc-plugin.unit/javadocjar-archive-config/pom.properties"); } - - @Test - @InjectMojo(goal = "jar", pom = "stale-test-plugin-config.xml") - @Basedir("/unit/stale-test") - void testStale(JavadocJarMojo mojo) throws Exception { - - new File(getBasedir(), "/target/maven-javadoc-plugin-stale-data.txt").delete(); - - mojo.execute(); - verify(log).debug("No previous run data found, generating javadoc."); - - clearInvocations(log); - - mojo.execute(); - verify(log).debug("Skipping javadoc generation, everything is up to date."); - } } diff --git a/src/test/resources/unit/stale-test/src/main/java/maven/App.java b/src/test/resources/unit/stale-test/src/main/java/maven/App.java deleted file mode 100644 index 35e299ce8..000000000 --- a/src/test/resources/unit/stale-test/src/main/java/maven/App.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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. - */ -package maven; - -/** - * Hello world! - * - */ -public class App -{ - public static void main( String[] args ) - { - System.out.println( "Hello World!" ); - } -} diff --git a/src/test/resources/unit/stale-test/stale-test-plugin-config.xml b/src/test/resources/unit/stale-test/stale-test-plugin-config.xml deleted file mode 100644 index f1d5cf923..000000000 --- a/src/test/resources/unit/stale-test/stale-test-plugin-config.xml +++ /dev/null @@ -1,54 +0,0 @@ - - - - 4.0.0 - org.apache.maven.plugins.maven-javadoc-plugin.unit - pom-test - 1.0-SNAPSHOT - pom - project1 - - - - org.apache.maven.plugins - maven-javadoc-plugin - - ${basedir}/target - pom-test - javadoc - ${basedir}/target/site - ${basedir}/target/javadoc-bundle-options - protected - ISO-8859-1 - - - Maven Pom 1.0-SNAPSHOT API - true - ${basedir}/src/java/javadoc - java - true - true - ${basedir}/target/maven-javadoc-plugin-stale-data.txt - - - - -