|
19 | 19 | package org.apache.maven.plugins.javadoc;
|
20 | 20 |
|
21 | 21 | import java.io.File;
|
| 22 | +import java.util.ArrayList; |
22 | 23 | import java.util.Enumeration;
|
23 | 24 | import java.util.HashSet;
|
| 25 | +import java.util.List; |
24 | 26 | import java.util.Set;
|
25 | 27 | import java.util.zip.ZipEntry;
|
26 | 28 | import java.util.zip.ZipFile;
|
27 | 29 |
|
28 | 30 | import org.apache.maven.execution.MavenSession;
|
29 | 31 | import org.apache.maven.model.Plugin;
|
30 | 32 | import org.apache.maven.plugin.MojoExecution;
|
| 33 | +import org.apache.maven.plugin.logging.Log; |
31 | 34 | import org.apache.maven.plugin.testing.AbstractMojoTestCase;
|
32 | 35 | import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
|
33 | 36 | import org.apache.maven.project.MavenProject;
|
@@ -191,4 +194,116 @@ public void testIncludeMavenDescriptorWhenExplicitlyConfigured() throws Exceptio
|
191 | 194 | "META-INF/maven/org.apache.maven.plugins.maven-javadoc-plugin.unit/javadocjar-archive-config/pom.xml",
|
192 | 195 | "META-INF/maven/org.apache.maven.plugins.maven-javadoc-plugin.unit/javadocjar-archive-config/pom.properties");
|
193 | 196 | }
|
| 197 | + |
| 198 | + public void testStale() throws Exception { |
| 199 | + File testPom = new File(getBasedir(), "src/test/resources/unit/stale-test/stale-test-plugin-config.xml"); |
| 200 | + JavadocJar mojo = lookupMojo(testPom); |
| 201 | + BufferingLog log = new BufferingLog(); |
| 202 | + mojo.setLog(log); |
| 203 | + |
| 204 | + Thread.sleep(500); |
| 205 | + |
| 206 | + new File(getBasedir(), "target/test/unit/stale-test/target/maven-javadoc-plugin-stale-data.txt").delete(); |
| 207 | + mojo.execute(); |
| 208 | + assertThat(log.getMessages()).contains("[INFO] No previous run data found, generating javadoc."); |
| 209 | + |
| 210 | + Thread.sleep(500); |
| 211 | + |
| 212 | + log.getMessages().clear(); |
| 213 | + mojo.execute(); |
| 214 | + assertThat(log.getMessages()).contains("[INFO] Skipping javadoc generation, everything is up to date."); |
| 215 | + } |
| 216 | + |
| 217 | + private static class BufferingLog implements Log { |
| 218 | + private final List<String> messages = new ArrayList<>(); |
| 219 | + |
| 220 | + public List<String> getMessages() { |
| 221 | + return messages; |
| 222 | + } |
| 223 | + |
| 224 | + @Override |
| 225 | + public boolean isDebugEnabled() { |
| 226 | + return true; |
| 227 | + } |
| 228 | + |
| 229 | + @Override |
| 230 | + public void debug(CharSequence charSequence) { |
| 231 | + debug(charSequence, null); |
| 232 | + } |
| 233 | + |
| 234 | + @Override |
| 235 | + public void debug(CharSequence charSequence, Throwable throwable) { |
| 236 | + message("DEBUG", charSequence, throwable); |
| 237 | + } |
| 238 | + |
| 239 | + @Override |
| 240 | + public void debug(Throwable throwable) { |
| 241 | + debug(null, throwable); |
| 242 | + } |
| 243 | + |
| 244 | + @Override |
| 245 | + public boolean isInfoEnabled() { |
| 246 | + return true; |
| 247 | + } |
| 248 | + |
| 249 | + @Override |
| 250 | + public void info(CharSequence charSequence) { |
| 251 | + info(charSequence, null); |
| 252 | + } |
| 253 | + |
| 254 | + @Override |
| 255 | + public void info(CharSequence charSequence, Throwable throwable) { |
| 256 | + message("INFO", charSequence, throwable); |
| 257 | + } |
| 258 | + |
| 259 | + @Override |
| 260 | + public void info(Throwable throwable) { |
| 261 | + info(null, throwable); |
| 262 | + } |
| 263 | + |
| 264 | + @Override |
| 265 | + public boolean isWarnEnabled() { |
| 266 | + return true; |
| 267 | + } |
| 268 | + |
| 269 | + @Override |
| 270 | + public void warn(CharSequence charSequence) { |
| 271 | + warn(charSequence, null); |
| 272 | + } |
| 273 | + |
| 274 | + @Override |
| 275 | + public void warn(CharSequence charSequence, Throwable throwable) { |
| 276 | + message("WARN", charSequence, throwable); |
| 277 | + } |
| 278 | + |
| 279 | + @Override |
| 280 | + public void warn(Throwable throwable) { |
| 281 | + warn(null, throwable); |
| 282 | + } |
| 283 | + |
| 284 | + @Override |
| 285 | + public boolean isErrorEnabled() { |
| 286 | + return true; |
| 287 | + } |
| 288 | + |
| 289 | + @Override |
| 290 | + public void error(CharSequence charSequence) { |
| 291 | + error(charSequence, null); |
| 292 | + } |
| 293 | + |
| 294 | + @Override |
| 295 | + public void error(CharSequence charSequence, Throwable throwable) { |
| 296 | + message("ERROR", charSequence, throwable); |
| 297 | + } |
| 298 | + |
| 299 | + @Override |
| 300 | + public void error(Throwable throwable) { |
| 301 | + error(null, throwable); |
| 302 | + } |
| 303 | + |
| 304 | + private void message(String level, CharSequence message, Throwable throwable) { |
| 305 | + messages.add("[" + level + "]" + (message != null ? " " + message : "") |
| 306 | + + (throwable != null ? " " + throwable : "")); |
| 307 | + } |
| 308 | + } |
194 | 309 | }
|
0 commit comments