1 package org.apache.maven.plugins.javadoc;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import static org.apache.commons.io.FileUtils.copyDirectory;
23 import static org.apache.commons.io.FileUtils.deleteDirectory;
24 import static org.assertj.core.api.Assertions.assertThat;
25 import static org.junit.Assume.assumeThat;
26 import static org.hamcrest.CoreMatchers.anyOf;
27 import static org.hamcrest.CoreMatchers.containsString;
28 import static org.hamcrest.CoreMatchers.is;
29
30 import static org.mockito.Mockito.mock;
31 import static org.mockito.Mockito.spy;
32 import static org.mockito.Mockito.when;
33
34 import java.io.File;
35 import java.io.IOException;
36 import java.net.HttpURLConnection;
37 import java.net.URL;
38 import java.nio.charset.Charset;
39 import java.nio.charset.StandardCharsets;
40 import java.nio.file.Files;
41 import java.nio.file.Path;
42 import java.util.HashMap;
43 import java.util.List;
44 import java.util.Map;
45 import java.util.Objects;
46
47 import org.apache.maven.execution.MavenSession;
48 import org.apache.maven.model.Plugin;
49 import org.apache.maven.plugin.LegacySupport;
50 import org.apache.maven.plugin.MojoExecution;
51 import org.apache.maven.plugin.MojoExecutionException;
52 import org.apache.maven.plugin.testing.AbstractMojoTestCase;
53 import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
54 import org.apache.maven.plugins.javadoc.ProxyServer.AuthAsyncProxyServlet;
55 import org.apache.maven.project.MavenProject;
56 import org.apache.maven.project.ProjectBuildingRequest;
57 import org.apache.maven.repository.internal.MavenRepositorySystemSession;
58 import org.apache.maven.settings.Proxy;
59 import org.apache.maven.settings.Settings;
60 import org.apache.maven.shared.utils.StringUtils;
61 import org.apache.maven.shared.utils.io.FileUtils;
62 import org.codehaus.plexus.languages.java.version.JavaVersion;
63 import org.hamcrest.MatcherAssert;
64 import org.junit.AssumptionViolatedException;
65 import org.slf4j.Logger;
66 import org.slf4j.LoggerFactory;
67 import org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager;
68
69
70
71
72
73
74
75 public class JavadocReportTest
76 extends AbstractMojoTestCase
77 {
78
79 private static final char LINE_SEPARATOR = ' ';
80
81 public static final String OPTIONS_UMLAUT_ENCODING = "Options Umlaut Encoding ö ä ü ß";
82
83
84 private static boolean TEST_REPO_CREATED = false;
85
86 private Path unit;
87
88 private File localRepo;
89
90 private static final Logger LOGGER = LoggerFactory.getLogger( JavadocReportTest.class );
91
92
93 @Override
94 protected void setUp()
95 throws Exception
96 {
97 super.setUp();
98
99 unit = new File( getBasedir(), "src/test/resources/unit" ).toPath();
100
101 localRepo = new File( getBasedir(), "target/local-repo/" );
102
103 createTestRepo();
104 }
105
106
107 private JavadocReport lookupMojo( Path testPom )
108 throws Exception
109 {
110 JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom.toFile() );
111
112 MojoExecution mojoExec = new MojoExecution( new Plugin(), "javadoc", null );
113
114 setVariableValueToObject( mojo, "mojo", mojoExec );
115
116 MavenProject currentProject = new MavenProjectStub();
117 currentProject.setGroupId( "GROUPID" );
118 currentProject.setArtifactId( "ARTIFACTID" );
119
120 setVariableValueToObject( mojo, "session", newMavenSession( currentProject ) );
121
122 return mojo;
123 }
124
125
126
127
128
129
130 private void createTestRepo()
131 throws IOException
132 {
133 if ( TEST_REPO_CREATED )
134 {
135 return;
136 }
137
138 localRepo.mkdirs();
139
140
141
142
143
144 Path sourceDir = unit.resolve( "doclet-test/artifact-doclet" );
145 assertThat( sourceDir ).exists();
146 copyDirectory( sourceDir.toFile(), localRepo );
147
148
149
150
151
152 sourceDir = unit.resolve( "doclet-path-test/artifact-doclet" );
153 assertThat( sourceDir ).exists();
154 copyDirectory( sourceDir.toFile(), localRepo );
155
156
157
158
159
160
161 sourceDir = unit.resolve( "taglet-test/artifact-taglet" );
162 assertThat( sourceDir ).exists();
163 copyDirectory( sourceDir.toFile(), localRepo );
164
165
166
167
168
169 sourceDir = unit.resolve( "stylesheetfile-test/artifact-stylesheetfile" );
170 assertThat( sourceDir ).exists();
171 copyDirectory( sourceDir.toFile(), localRepo );
172
173
174
175
176
177 sourceDir = unit.resolve( "helpfile-test/artifact-helpfile" );
178 assertThat( sourceDir ).exists();
179 copyDirectory( sourceDir.toFile(), localRepo );
180
181
182 List<String> files =
183 FileUtils.getFileAndDirectoryNames( localRepo, FileUtils.getDefaultExcludesAsString(), null, true,
184 true, true, true );
185 for ( String filename : files )
186 {
187 File file = new File( filename );
188
189 if ( file.isDirectory() )
190 {
191 deleteDirectory( file );
192 }
193 else
194 {
195 file.delete();
196 }
197 }
198
199 TEST_REPO_CREATED = true;
200 }
201
202
203
204
205
206
207
208
209
210
211 private static String readFile( Path file )
212 throws IOException
213 {
214 return readFile( file, StandardCharsets.UTF_8 );
215 }
216
217
218
219
220
221
222
223
224
225
226
227 private static String readFile( Path file, Charset cs )
228 throws IOException
229 {
230 StringBuilder str = new StringBuilder( (int) Files.size( file ) );
231
232 for ( String strTmp : Files.readAllLines( file, cs ) )
233 {
234 str.append( LINE_SEPARATOR);
235 str.append( strTmp );
236 }
237
238 return str.toString();
239 }
240
241
242
243
244
245
246 public void testDefaultConfiguration()
247 throws Exception
248 {
249 Path testPom = unit.resolve( "default-configuration/default-configuration-plugin-config.xml" );
250 JavadocReport mojo = lookupMojo( testPom );
251 mojo.execute();
252
253
254 Path apidocs = new File( getBasedir(), "target/test/unit/default-configuration/target/site/apidocs" ).toPath();
255
256 String appHtml = "def/configuration/App.html";
257 Path generatedFile = apidocs.resolve( appHtml );
258 assertThat( generatedFile ).exists();
259
260 if ( JavaVersion.JAVA_SPECIFICATION_VERSION.isBefore( "16" ) )
261 {
262 String url = Objects.requireNonNull( mojo.getDefaultJavadocApiLink() ).getUrl();
263 HttpURLConnection connection = (HttpURLConnection) new URL( url ).openConnection();
264 connection.setRequestMethod( "HEAD" );
265 try
266 {
267
268 if ( connection.getResponseCode() == HttpURLConnection.HTTP_OK )
269 {
270 try
271 {
272 assumeThat( connection.getURL().toString(), is( url ) );
273
274
275 MatcherAssert.assertThat( url + " available, but " + appHtml + " is missing link to java.lang.Object",
276 new String( Files.readAllBytes(generatedFile), StandardCharsets.UTF_8 ),
277 anyOf( containsString( "/docs/api/java/lang/Object.html" ),
278 containsString( "/docs/api/java.base/java/lang/Object.html" ) ) );
279 }
280 catch ( AssumptionViolatedException e )
281 {
282 LOGGER.warn( "ignoring defaultAPI check: {}", e.getMessage() );
283 }
284 }
285 }
286 catch (Exception e)
287 {
288 LOGGER.error("error connecting to javadoc URL: {}", url);
289 throw e;
290 }
291 }
292 else
293 {
294 MatcherAssert.assertThat( new String( Files.readAllBytes(generatedFile), StandardCharsets.UTF_8 ),
295 containsString( "/docs/api/java.base/java/lang/Object.html" ) );
296 }
297
298 assertThat( apidocs.resolve( "def/configuration/AppSample.html" )).exists();
299 assertThat( apidocs.resolve( "def/configuration/package-summary.html" )).exists();
300 assertThat( apidocs.resolve( "def/configuration/package-tree.html" )).exists();
301 assertThat( apidocs.resolve( "def/configuration/package-use.html" )).exists();
302
303
304 if ( JavaVersion.JAVA_SPECIFICATION_VERSION.isBefore( "11" ) )
305 {
306 assertThat( apidocs.resolve( "def/configuration/package-frame.html" )).exists();
307 assertThat( apidocs.resolve( "allclasses-frame.html" )).exists();
308 assertThat( apidocs.resolve( "allclasses-noframe.html" )).exists();
309 }
310
311
312 assertThat( apidocs.resolve( "def/configuration/class-use/App.html" )).exists();
313 assertThat( apidocs.resolve( "def/configuration/class-use/AppSample.html" )).exists();
314
315
316 assertThat( apidocs.resolve( "constant-values.html" )).exists();
317 assertThat( apidocs.resolve( "deprecated-list.html" ) ).exists();
318 assertThat( apidocs.resolve( "help-doc.html" )).exists();
319 assertThat( apidocs.resolve( "index-all.html" )).exists();
320 assertThat( apidocs.resolve( "index.html" )).exists();
321 assertThat( apidocs.resolve( "overview-tree.html" )).exists();
322 assertThat( apidocs.resolve( "stylesheet.css" )).exists();
323
324 if ( JavaVersion.JAVA_VERSION.isAtLeast( "10" ) )
325 {
326 assertThat( apidocs.resolve( "element-list" )).exists();
327 }
328 else
329 {
330 assertThat( apidocs.resolve( "package-list" )).exists();
331 }
332 }
333
334
335
336
337
338
339 public void testSubpackages()
340 throws Exception
341 {
342 Path testPom = unit.resolve( "subpackages-test/subpackages-test-plugin-config.xml" );
343 JavadocReport mojo = lookupMojo( testPom );
344 mojo.execute();
345
346 Path apidocs = new File( getBasedir(), "target/test/unit/subpackages-test/target/site/apidocs" ).toPath();
347
348
349 assertThat( apidocs.resolve( "subpackages/test/excluded" ) ).doesNotExist();
350 assertThat( apidocs.resolve( "subpackages/test/included/exclude" ) ).doesNotExist();
351
352
353 assertThat( apidocs.resolve( "subpackages/test/App.html" ) ).exists();
354 assertThat( apidocs.resolve( "subpackages/test/AppSample.html" ) ).exists();
355 assertThat( apidocs.resolve( "subpackages/test/included/IncludedApp.html" ) ).exists();
356 assertThat( apidocs.resolve( "subpackages/test/included/IncludedAppSample.html" ) ).exists();
357 }
358
359 public void testIncludesExcludes()
360 throws Exception
361 {
362 Path testPom = unit.resolve( "file-include-exclude-test/file-include-exclude-plugin-config.xml" );
363 JavadocReport mojo = lookupMojo( testPom );
364 mojo.execute();
365
366 Path apidocs = new File( getBasedir(), "target/test/unit/file-include-exclude-test/target/site/apidocs" ).toPath();
367
368
369 assertThat( apidocs.resolve( "subpackages/test/App.html" ) ).exists();
370 assertThat( apidocs.resolve( "subpackages/test/AppSample.html" ) ).exists();
371 assertThat( apidocs.resolve( "subpackages/test/included/IncludedApp.html" ) ).exists();
372 assertThat( apidocs.resolve( "subpackages/test/included/IncludedAppSample.html" ) ).exists();
373 assertThat( apidocs.resolve( "subpackages/test/PariahApp.html" ) ).doesNotExist();
374 }
375
376
377
378
379
380
381 public void testDocfiles()
382 throws Exception
383 {
384
385
386 if ( JavaVersion.JAVA_SPECIFICATION_VERSION.isAtLeast( "9" ) )
387 {
388 return;
389 }
390
391 Path testPom = unit.resolve( "docfiles-test/docfiles-test-plugin-config.xml" );
392 JavadocReport mojo = lookupMojo( testPom );
393 mojo.execute();
394
395 Path apidocs = new File( getBasedir(), "target/test/unit/docfiles-test/target/site/apidocs/" ).toPath();
396
397
398 assertThat( apidocs.resolve( "docfiles/test/doc-files" )).exists();
399 assertThat( apidocs.resolve( "docfiles/test/doc-files/included-dir1/sample-included1.gif" )).exists();
400 assertThat( apidocs.resolve( "docfiles/test/doc-files/included-dir2/sample-included2.gif" )).exists();
401 assertThat( apidocs.resolve( "docfiles/test/doc-files/excluded-dir1" )).doesNotExist();
402 assertThat( apidocs.resolve( "docfiles/test/doc-files/excluded-dir2" )).doesNotExist();
403
404 testPom = unit.resolve( "docfiles-with-java-test/docfiles-with-java-test-plugin-config.xml" );
405 mojo = lookupMojo( testPom );
406 mojo.execute();
407 }
408
409
410
411
412
413
414
415 public void testCustomConfiguration()
416 throws Exception
417 {
418 Path testPom = unit.resolve( "custom-configuration/custom-configuration-plugin-config.xml" );
419 JavadocReport mojo = lookupMojo( testPom );
420 mojo.execute();
421
422 Path apidocs = new File( getBasedir(), "target/test/unit/custom-configuration/target/site/apidocs" ).toPath();
423
424
425 assertThat( apidocs.resolve( "overview-tree.html" ) ).doesNotExist();
426 assertThat( apidocs.resolve( "custom/configuration/package-tree.html" ) ).doesNotExist();
427
428
429 assertThat( apidocs.resolve( "index-all.html" ) ).doesNotExist();
430
431
432
433
434 assertThat( apidocs.resolve( "deprecated-list.html" ) ).doesNotExist();
435 assertThat( apidocs.resolve( "custom/configuration/App.html" ) ).doesNotExist();
436
437
438
439 String str = readFile( apidocs.resolve( "custom/configuration/AppSample.html" ) );
440 assertFalse( str.toLowerCase().contains( "author" ) );
441
442
443 assertTrue( str.toUpperCase().contains( "SAMPLE BOTTOM CONTENT" ) );
444
445
446 if ( JavaVersion.JAVA_VERSION.isBefore( "11.0.2" ) )
447 {
448 assertThat( str ).containsIgnoringCase(
449 "href=\"http://java.sun.com/j2se/1.4.2/docs/api/java/lang/string.html" );
450 }
451 else
452 {
453 assertTrue( str.toLowerCase().contains(
454 "href=\"http://java.sun.com/j2se/1.4.2/docs/api/java.base/java/lang/string.html" ) );
455 }
456
457
458 assertTrue( str.toUpperCase().contains( "MAVEN JAVADOC PLUGIN TEST" ) );
459
460
461 if ( JavaVersion.JAVA_VERSION.isBefore( "16-ea" ) )
462 {
463 assertTrue( str.toUpperCase().contains( "MAVEN JAVADOC PLUGIN TEST FOOTER" ) );
464 }
465
466
467 assertFalse( str.toUpperCase().contains( "/HELP-DOC.HTML" ) );
468
469
470 assertThat( apidocs.resolve( "custom/configuration/exclude1/Exclude1App.html" ) ).exists();
471 assertThat( apidocs.resolve( "custom/configuration/exclude1/subexclude/SubexcludeApp.html" ) ).doesNotExist();
472 assertThat( apidocs.resolve( "custom/configuration/exclude2/Exclude2App.html" ) ).doesNotExist();
473
474 assertThat( apidocs.resolve( "options" ) ).isRegularFile();
475
476 String contentOptions = new String( Files.readAllBytes( apidocs.resolve( "options" ) ), StandardCharsets.UTF_8 );
477
478 assertNotNull( contentOptions );
479 assertThat( contentOptions ).contains( "-link" ).contains( "http://java.sun.com/j2se/" );
480 }
481
482
483
484
485
486
487 public void testDoclets()
488 throws Exception
489 {
490 if ( JavaVersion.JAVA_SPECIFICATION_VERSION.isAtLeast( "13" ) )
491 {
492
493 return;
494 }
495
496
497
498
499
500
501 Path testPom = unit.resolve( "doclet-test/doclet-test-plugin-config.xml" );
502 JavadocReport mojo = lookupMojo( testPom );
503
504 MavenSession session = spy( newMavenSession( mojo.project ) );
505 ProjectBuildingRequest buildingRequest = mock( ProjectBuildingRequest.class );
506 when( buildingRequest.getRemoteRepositories() ).thenReturn( mojo.project.getRemoteArtifactRepositories() );
507 when( session.getProjectBuildingRequest() ).thenReturn( buildingRequest );
508 MavenRepositorySystemSession repositorySession = new MavenRepositorySystemSession();
509 repositorySession.setLocalRepositoryManager( new SimpleLocalRepositoryManager( localRepo ) );
510 when( buildingRequest.getRepositorySession() ).thenReturn( repositorySession );
511 when( session.getRepositorySession() ).thenReturn( repositorySession );
512 LegacySupport legacySupport = lookup( LegacySupport.class );
513 legacySupport.setSession( session );
514
515 setVariableValueToObject( mojo, "session", session );
516
517 mojo.execute();
518
519 Path generatedFile = new File( getBasedir(), "target/test/unit/doclet-test/target/site/apidocs/graph.dot" ).toPath();
520 assertThat( generatedFile ).exists();
521
522 Path optionsFile = new File( mojo.getOutputDirectory(), "options" ).toPath();
523 assertThat( optionsFile ).exists();
524 String options = readFile( optionsFile );
525 assertThat( options ).contains( "/target/local-repo/umlgraph/UMLGraph/2.1/UMLGraph-2.1.jar" );
526
527
528
529
530
531
532 testPom = unit.resolve( "doclet-path-test/doclet-path-test-plugin-config.xml" );
533 mojo = lookupMojo( testPom );
534 setVariableValueToObject( mojo, "session", session );
535 mojo.execute();
536
537 generatedFile = new File( getBasedir(), "target/test/unit/doclet-test/target/site/apidocs/graph.dot" ).toPath();
538 assertThat( generatedFile ).exists();
539
540 optionsFile = new File( mojo.getOutputDirectory(), "options" ).toPath();
541 assertThat( optionsFile ).exists();
542 options = readFile( optionsFile );
543 assertThat( options ).contains( "/target/local-repo/umlgraph/UMLGraph/2.1/UMLGraph-2.1.jar" )
544 .contains( "/target/local-repo/umlgraph/UMLGraph-bis/2.1/UMLGraph-bis-2.1.jar" );
545 }
546
547
548
549
550
551
552 public void testQuotedPath()
553 throws Exception
554 {
555 Path testPom = unit.resolve( "quotedpath'test/quotedpath-test-plugin-config.xml" );
556 JavadocReport mojo = lookupMojo( testPom );
557 mojo.execute();
558
559 Path apidocs = new File( getBasedir(), "target/test/unit/quotedpath'test/target/site/apidocs" ).toPath();
560
561
562 assertThat( apidocs.resolve( "quotedpath/test/App.html" ) ).exists();
563 assertThat( apidocs.resolve( "quotedpath/test/AppSample.html" ) ).exists();
564
565
566 assertThat( apidocs.resolve( "index-all.html" ) ).exists();
567 assertThat( apidocs.resolve( "index.html" ) ).exists();
568 assertThat( apidocs.resolve( "overview-tree.html" ) ).exists();
569 assertThat( apidocs.resolve( "stylesheet.css" ) ).exists();
570
571 if ( JavaVersion.JAVA_VERSION.isBefore( "10" ) )
572 {
573 assertThat( apidocs.resolve( "package-list" ) ).exists();
574 }
575 else
576 {
577 assertThat( apidocs.resolve( "element-list" ) ).exists();
578 }
579 }
580
581
582
583
584
585
586 public void testOptionsUmlautEncoding()
587 throws Exception
588 {
589 Path testPom = unit.resolve( "optionsumlautencoding-test/optionsumlautencoding-test-plugin-config.xml" );
590 JavadocReport mojo = lookupMojo( testPom );
591 mojo.execute();
592
593 Path optionsFile = new File( mojo.getOutputDirectory(), "options" ).toPath();
594 assertThat( optionsFile ).exists();
595
596
597 String content;
598 String expected;
599 if ( JavaVersion.JAVA_VERSION.isAtLeast( "9" ) && JavaVersion.JAVA_VERSION.isBefore( "12" ) )
600 {
601 content = readFile( optionsFile, StandardCharsets.UTF_8 );
602 expected = OPTIONS_UMLAUT_ENCODING;
603 }
604 else
605 {
606 content = readFile( optionsFile, Charset.defaultCharset() );
607 expected = new String( OPTIONS_UMLAUT_ENCODING.getBytes( Charset.defaultCharset() ) );
608 }
609
610 assertThat( content ).contains( expected );
611
612 Path apidocs = new File( getBasedir(), "target/test/unit/optionsumlautencoding-test/target/site/apidocs" ).toPath();
613
614
615 assertThat( apidocs.resolve( "optionsumlautencoding/test/App.html" ) ).exists();
616 assertThat( apidocs.resolve( "optionsumlautencoding/test/AppSample.html" ) ).exists();
617
618
619 assertThat( apidocs.resolve( "index-all.html" ) ).exists();
620 assertThat( apidocs.resolve( "index.html" ) ).exists();
621 assertThat( apidocs.resolve( "overview-tree.html" ) ).exists();
622 assertThat( apidocs.resolve( "stylesheet.css" ) ).exists();
623
624 if ( JavaVersion.JAVA_VERSION.isBefore( "10" ) )
625 {
626 assertThat( apidocs.resolve( "package-list" )).exists();
627 }
628 else
629 {
630 assertThat( apidocs.resolve( "element-list" )).exists();
631 }
632 }
633
634
635
636
637 public void testExceptions()
638 throws Exception
639 {
640 try
641 {
642 Path testPom = unit.resolve( "default-configuration/exception-test-plugin-config.xml" );
643 JavadocReport mojo = lookupMojo( testPom );
644 mojo.execute();
645
646 fail( "Must throw exception." );
647 }
648 catch ( Exception e )
649 {
650 assertTrue( true );
651
652 try
653 {
654 deleteDirectory( new File( getBasedir(), "exception" ) );
655 }
656 catch ( IOException ie )
657 {
658
659 }
660 }
661 }
662
663
664
665
666
667
668 public void testTaglets()
669 throws Exception
670 {
671
672
673
674
675
676
677
678 if ( JavaVersion.JAVA_SPECIFICATION_VERSION.isAtLeast( "10" ) )
679 {
680 return;
681 }
682
683 Path testPom = unit.resolve( "taglet-test/taglet-test-plugin-config.xml" );
684 JavadocReport mojo = lookupMojo( testPom );
685
686 MavenSession session = spy( newMavenSession( mojo.project ) );
687 ProjectBuildingRequest buildingRequest = mock( ProjectBuildingRequest.class );
688 when( buildingRequest.getRemoteRepositories() ).thenReturn( mojo.project.getRemoteArtifactRepositories() );
689 when( session.getProjectBuildingRequest() ).thenReturn( buildingRequest );
690 MavenRepositorySystemSession repositorySession = new MavenRepositorySystemSession();
691 repositorySession.setLocalRepositoryManager( new SimpleLocalRepositoryManager( localRepo ) );
692 when( buildingRequest.getRepositorySession() ).thenReturn( repositorySession );
693 when( session.getRepositorySession() ).thenReturn( repositorySession );
694 LegacySupport legacySupport = lookup( LegacySupport.class );
695 legacySupport.setSession( session );
696
697 setVariableValueToObject( mojo, "session", session );
698
699 mojo.execute();
700
701 Path apidocs = new File( getBasedir(), "target/test/unit/taglet-test/target/site/apidocs" ).toPath();
702
703 assertThat( apidocs.resolve( "index.html" )).exists();
704
705 Path appFile = apidocs.resolve( "taglet/test/App.html" );
706 assertThat( appFile ).exists();
707 String appString = readFile( appFile );
708 assertThat( appString ).contains( "<b>To Do:</b>" );
709 }
710
711
712
713
714
715
716 public void testJdk5()
717 throws Exception
718 {
719
720
721 if ( JavaVersion.JAVA_SPECIFICATION_VERSION.isAtLeast( "9" ) )
722 {
723 return;
724 }
725
726 Path testPom = unit.resolve( "jdk5-test/jdk5-test-plugin-config.xml" );
727 JavadocReport mojo = lookupMojo( testPom );
728 mojo.execute();
729
730 Path apidocs = new File( getBasedir(), "target/test/unit/jdk5-test/target/site/apidocs" ).toPath();
731
732 assertThat( apidocs.resolve( "index.html" ) ).exists();
733
734 Path overviewSummary = apidocs.resolve( "overview-summary.html" );
735 assertThat( overviewSummary ).exists();
736 String content = readFile( overviewSummary );
737 assertThat( content ).contains( "<b>Test the package-info</b>" );
738
739 Path packageSummary = apidocs.resolve( "jdk5/test/package-summary.html" );
740 assertThat( packageSummary ).exists();
741 content = readFile( packageSummary );
742 assertThat( content ).contains( "<b>Test the package-info</b>" );
743 }
744
745
746
747
748
749
750
751 public void testToFindJavadoc()
752 throws Exception
753 {
754 String oldJreHome = System.getProperty( "java.home" );
755 System.setProperty( "java.home", "foo/bar" );
756
757 Path testPom = unit.resolve( "javaHome-test/javaHome-test-plugin-config.xml" );
758 JavadocReport mojo = lookupMojo( testPom );
759 mojo.execute();
760
761 System.setProperty( "java.home", oldJreHome );
762 }
763
764
765
766
767
768
769 public void testJavadocResources()
770 throws Exception
771 {
772 Path testPom = unit.resolve( "resources-test/resources-test-plugin-config.xml" );
773 JavadocReport mojo = lookupMojo( testPom );
774 mojo.execute();
775
776 Path apidocs = new File( getBasedir(), "target/test/unit/resources-test/target/site/apidocs/" ).toPath();
777
778 Path app = apidocs.resolve( "resources/test/App.html" );
779 assertThat( app ).exists();
780 String content = readFile( app );
781 assertThat( content ).contains( "<img src=\"doc-files/maven-feather.png\" alt=\"Maven\">" );
782 assertThat( apidocs.resolve( "resources/test/doc-files/maven-feather.png" )).exists();
783
784 Path app2 = apidocs.resolve( "resources/test2/App2.html" );
785 assertThat( app2 ).exists();
786 content = readFile( app2 );
787 assertThat( content ).contains( "<img src=\"doc-files/maven-feather.png\" alt=\"Maven\">" );
788 assertThat( apidocs.resolve( "resources/test2/doc-files/maven-feather.png" )).doesNotExist();
789
790
791 testPom = unit.resolve( "resources-with-excludes-test/resources-with-excludes-test-plugin-config.xml" );
792 mojo = lookupMojo( testPom );
793 mojo.execute();
794
795 apidocs = new File( getBasedir(),
796 "target/test/unit/resources-with-excludes-test/target/site/apidocs" ).toPath();
797
798 app = apidocs.resolve( "resources/test/App.html" );
799 assertThat( app ).exists();
800 content = readFile( app );
801 assertThat( content ).contains( "<img src=\"doc-files/maven-feather.png\" alt=\"Maven\">" );
802
803 JavaVersion javadocVersion = (JavaVersion) getVariableValueFromObject( mojo, "javadocRuntimeVersion" );
804 if( javadocVersion.isAtLeast( "1.8" ) )
805 {
806
807 assertThat( apidocs.resolve( "resources/test/doc-files/maven-feather.png" ))
808 .as("Javadoc runtime version: " + javadocVersion
809 + "\nThis bug appeared in JDK8 and was planned to be fixed in JDK9, see JDK-8032205")
810 .exists();
811 }
812 else
813 {
814 assertThat( apidocs.resolve( "resources/test/doc-files/maven-feather.png" ) ).doesNotExist();
815 }
816 assertThat( apidocs.resolve( "resources/test2/doc-files/maven-feather.png" ) ).exists();
817
818 app2 = apidocs.resolve( "resources/test2/App2.html" );
819 assertThat( app2 ).exists();
820 content = readFile( app2 );
821 assertThat( content ).contains( "<img src=\"doc-files/maven-feather.png\" alt=\"Maven\">" );
822 assertThat( apidocs.resolve( "resources/test2/doc-files/maven-feather.png" ) ).exists();
823 }
824
825
826
827
828
829
830 public void testPom()
831 throws Exception
832 {
833 Path testPom = unit.resolve( "pom-test/pom-test-plugin-config.xml" );
834 JavadocReport mojo = lookupMojo( testPom );
835 mojo.execute();
836
837 assertThat( new File( getBasedir(), "target/test/unit/pom-test/target/site" )).doesNotExist();
838 }
839
840
841
842
843
844
845 public void testTag()
846 throws Exception
847 {
848 Path testPom = unit.resolve( "tag-test/tag-test-plugin-config.xml" );
849 JavadocReport mojo = lookupMojo( testPom );
850 mojo.execute();
851
852 Path app = new File( getBasedir(), "target/test/unit/tag-test/target/site/apidocs/tag/test/App.html" ).toPath();
853 assertThat( app ).exists();
854 String readed = readFile( app );
855 assertThat( readed ).contains( ">To do something:</" ).contains( ">Generator Class:</" );
856
857
858
859 if ( JavaVersion.JAVA_SPECIFICATION_VERSION.isBefore( "11" ) )
860 {
861 assertThat( readed ).contains( ">Version:</" );
862 assertTrue( readed.toLowerCase().contains( "</dt>" + LINE_SEPARATOR + " <dd>1.0</dd>" ) || readed.toLowerCase().contains(
863 "</dt>" + LINE_SEPARATOR + "<dd>1.0</dd>" ) );
864 }
865 }
866
867
868
869
870
871
872 public void testHeaderFooter()
873 throws Exception
874 {
875 Path testPom = unit.resolve( "header-footer-test/header-footer-test-plugin-config.xml" );
876 JavadocReport mojo = lookupMojo( testPom );
877 try
878 {
879 mojo.execute();
880 }
881 catch ( MojoExecutionException e )
882 {
883 fail( "Doesnt handle correctly newline for header or footer parameter" );
884 }
885
886 assertTrue( true );
887 }
888
889
890
891
892
893
894 public void testNewline()
895 throws Exception
896 {
897 Path testPom = unit.resolve( "newline-test/newline-test-plugin-config.xml" );
898 JavadocReport mojo = lookupMojo( testPom );
899 try
900 {
901 mojo.execute();
902 }
903 catch ( MojoExecutionException e )
904 {
905 fail( "Doesn't handle correctly newline for string parameters. See options and packages files." );
906 }
907
908 assertTrue( true );
909 }
910
911
912
913
914
915
916 public void testJdk6()
917 throws Exception
918 {
919
920
921 if ( JavaVersion.JAVA_SPECIFICATION_VERSION.isAtLeast( "12" ) )
922 {
923 return;
924 }
925
926 Path testPom = unit.resolve( "jdk6-test/jdk6-test-plugin-config.xml" );
927 JavadocReport mojo = lookupMojo( testPom );
928 mojo.execute();
929
930 Path apidocs = new File( getBasedir(), "target/test/unit/jdk6-test/target/site/apidocs" ).toPath();
931 assertThat( apidocs.resolve( "index.html" ) ).exists();
932
933 Path overview;
934 if ( JavaVersion.JAVA_SPECIFICATION_VERSION.isBefore( "11" ) )
935 {
936 overview = apidocs.resolve( "overview-summary.html" );
937 }
938 else
939 {
940 overview = apidocs.resolve( "index.html" );
941 }
942
943 assertThat( overview ).exists();
944 String content = readFile( overview );
945 assertThat( content ).contains( "Top - Copyright © All rights reserved." )
946 .contains( "Header - Copyright © All rights reserved." )
947 .contains( "Footer - Copyright © All rights reserved." );
948
949 Path packageSummary = apidocs.resolve( "jdk6/test/package-summary.html" );
950 assertThat( packageSummary ).exists();
951 content = readFile( packageSummary );
952 assertThat( content ).contains( "Top - Copyright © All rights reserved." )
953 .contains( "Header - Copyright © All rights reserved." )
954 .contains( "Footer - Copyright © All rights reserved." );
955 }
956
957
958
959
960
961
962 public void testProxy()
963 throws Exception
964 {
965 Settings settings = new Settings();
966 Proxy proxy = new Proxy();
967
968
969 proxy.setActive( true );
970 proxy.setHost( "127.0.0.1" );
971 proxy.setPort( 80 );
972 proxy.setProtocol( "http" );
973 proxy.setUsername( "toto" );
974 proxy.setPassword( "toto" );
975 proxy.setNonProxyHosts( "www.google.com|*.somewhere.com" );
976 settings.addProxy( proxy );
977
978 Path testPom = new File( getBasedir(), "src/test/resources/unit/proxy-test/proxy-test-plugin-config.xml" ).toPath();
979 JavadocReport mojo = lookupMojo( testPom );
980
981 MavenSession session = spy( newMavenSession( mojo.project ) );
982 ProjectBuildingRequest buildingRequest = mock( ProjectBuildingRequest.class );
983 when( buildingRequest.getRemoteRepositories() ).thenReturn( mojo.project.getRemoteArtifactRepositories() );
984 when( session.getProjectBuildingRequest() ).thenReturn( buildingRequest );
985 MavenRepositorySystemSession repositorySession = new MavenRepositorySystemSession();
986 repositorySession.setLocalRepositoryManager( new SimpleLocalRepositoryManager( localRepo ) );
987 when( buildingRequest.getRepositorySession() ).thenReturn( repositorySession );
988 when( session.getRepositorySession() ).thenReturn( repositorySession );
989 LegacySupport legacySupport = lookup( LegacySupport.class );
990 legacySupport.setSession( session );
991
992 setVariableValueToObject( mojo, "settings", settings );
993 setVariableValueToObject( mojo, "session", session );
994 mojo.execute();
995
996 Path commandLine = new File( getBasedir(), "target/test/unit/proxy-test/target/site/apidocs/javadoc." + ( SystemUtils.IS_OS_WINDOWS ? "bat" : "sh" ) ).toPath();
997 assertThat( commandLine ).exists();
998 String readed = readFile( commandLine );
999 assertThat( readed ).contains( "-J-Dhttp.proxyHost=127.0.0.1" ).contains( "-J-Dhttp.proxyPort=80" );
1000 if ( SystemUtils.IS_OS_WINDOWS )
1001 {
1002 assertThat( readed ).contains( " -J-Dhttp.nonProxyHosts=\"www.google.com^|*.somewhere.com\" " );
1003 }
1004 else
1005 {
1006 assertThat( readed ).contains( " \"-J-Dhttp.nonProxyHosts=\\\"www.google.com^|*.somewhere.com\\\"\" " );
1007 }
1008
1009 Path options = new File( getBasedir(), "target/test/unit/proxy-test/target/site/apidocs/options" ).toPath();
1010 assertThat( options ).exists();
1011 String optionsContent = readFile( options );
1012
1013 assertThat( optionsContent ).doesNotContain( "-link" );
1014
1015
1016 ProxyServer proxyServer = null;
1017 AuthAsyncProxyServlet proxyServlet;
1018 try
1019 {
1020 proxyServlet = new AuthAsyncProxyServlet();
1021 proxyServer = new ProxyServer( proxyServlet );
1022 proxyServer.start();
1023
1024 settings = new Settings();
1025 proxy = new Proxy();
1026 proxy.setActive( true );
1027 proxy.setHost( proxyServer.getHostName() );
1028 proxy.setPort( proxyServer.getPort() );
1029 proxy.setProtocol( "http" );
1030 settings.addProxy( proxy );
1031
1032 mojo = lookupMojo( testPom );
1033 setVariableValueToObject( mojo, "settings", settings );
1034 setVariableValueToObject( mojo, "session", session );
1035 mojo.execute();
1036 readed = readFile( commandLine );
1037 assertTrue( readed.contains( "-J-Dhttp.proxyHost=" + proxyServer.getHostName() ) );
1038 assertTrue( readed.contains( "-J-Dhttp.proxyPort=" + proxyServer.getPort() ) );
1039
1040 optionsContent = readFile( options );
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051 }
1052 finally
1053 {
1054 if ( proxyServer != null )
1055 {
1056 proxyServer.stop();
1057 }
1058 }
1059
1060
1061 Map<String, String> authentications = new HashMap<>();
1062 authentications.put( "foo", "bar" );
1063 try
1064 {
1065 proxyServlet = new AuthAsyncProxyServlet( authentications );
1066 proxyServer = new ProxyServer( proxyServlet );
1067 proxyServer.start();
1068
1069 settings = new Settings();
1070 proxy = new Proxy();
1071 proxy.setActive( true );
1072 proxy.setHost( proxyServer.getHostName() );
1073 proxy.setPort( proxyServer.getPort() );
1074 proxy.setProtocol( "http" );
1075 proxy.setUsername( "foo" );
1076 proxy.setPassword( "bar" );
1077 settings.addProxy( proxy );
1078
1079 mojo = lookupMojo( testPom );
1080 setVariableValueToObject( mojo, "settings", settings );
1081 setVariableValueToObject( mojo, "session", session );
1082 mojo.execute();
1083 readed = readFile( commandLine );
1084 assertThat( readed ).contains( "-J-Dhttp.proxyHost=" + proxyServer.getHostName() )
1085 .contains( "-J-Dhttp.proxyPort=" + proxyServer.getPort() );
1086
1087 optionsContent = readFile( options );
1088
1089
1090
1091 }
1092 finally
1093 {
1094 if ( proxyServer != null )
1095 {
1096 proxyServer.stop();
1097 }
1098 }
1099 }
1100
1101
1102
1103
1104
1105
1106 public void testValidateOptions()
1107 throws Exception
1108 {
1109
1110 Path testPom = unit.resolve( "validate-options-test/wrong-encoding-test-plugin-config.xml" );
1111 JavadocReport mojo = lookupMojo( testPom );
1112 try
1113 {
1114 mojo.execute();
1115 fail( "No wrong encoding catch" );
1116 }
1117 catch ( MojoExecutionException e )
1118 {
1119 assertTrue( "No wrong encoding catch", e.getMessage().contains( "Unsupported option <encoding/>" ) );
1120 }
1121 testPom = unit.resolve( "validate-options-test/wrong-docencoding-test-plugin-config.xml" );
1122 mojo = lookupMojo( testPom );
1123 try
1124 {
1125 mojo.execute();
1126 fail( "No wrong docencoding catch" );
1127 }
1128 catch ( MojoExecutionException e )
1129 {
1130 assertTrue( "No wrong docencoding catch", e.getMessage().contains( "Unsupported option <docencoding/>" ) );
1131 }
1132 testPom = unit.resolve( "validate-options-test/wrong-charset-test-plugin-config.xml" );
1133 mojo = lookupMojo( testPom );
1134 try
1135 {
1136 mojo.execute();
1137 fail( "No wrong charset catch" );
1138 }
1139 catch ( MojoExecutionException e )
1140 {
1141 assertTrue( "No wrong charset catch", e.getMessage().contains( "Unsupported option <charset/>" ) );
1142 }
1143
1144
1145 testPom = unit.resolve( "validate-options-test/wrong-locale-test-plugin-config.xml" );
1146 mojo = lookupMojo( testPom );
1147 try
1148 {
1149 mojo.execute();
1150 fail( "No wrong locale catch" );
1151 }
1152 catch ( MojoExecutionException e )
1153 {
1154 assertTrue( "No wrong locale catch", e.getMessage().contains( "Unsupported option <locale/>" ) );
1155 }
1156 testPom = unit.resolve( "validate-options-test/wrong-locale-with-variant-test-plugin-config.xml" );
1157 mojo = lookupMojo( testPom );
1158 mojo.execute();
1159 assertTrue( "No wrong locale catch", true );
1160
1161
1162 testPom = unit.resolve( "validate-options-test/conflict-options-test-plugin-config.xml" );
1163 mojo = lookupMojo( testPom );
1164 try
1165 {
1166 mojo.execute();
1167 fail( "No conflict catch" );
1168 }
1169 catch ( MojoExecutionException e )
1170 {
1171 assertTrue( "No conflict catch", e.getMessage().contains( "Option <nohelp/> conflicts with <helpfile/>" ) );
1172 }
1173 }
1174
1175
1176
1177
1178
1179
1180 public void testTagletArtifacts()
1181 throws Exception
1182 {
1183
1184
1185 if ( JavaVersion.JAVA_SPECIFICATION_VERSION.isAtLeast( "10" ) )
1186 {
1187 return;
1188 }
1189
1190 Path testPom = unit.resolve( "tagletArtifacts-test/tagletArtifacts-test-plugin-config.xml" );
1191 JavadocReport mojo = lookupMojo( testPom );
1192
1193 MavenSession session = spy( newMavenSession( mojo.project ) );
1194 ProjectBuildingRequest buildingRequest = mock( ProjectBuildingRequest.class );
1195 when( buildingRequest.getRemoteRepositories() ).thenReturn( mojo.project.getRemoteArtifactRepositories() );
1196 when( session.getProjectBuildingRequest() ).thenReturn( buildingRequest );
1197 MavenRepositorySystemSession repositorySession = new MavenRepositorySystemSession();
1198 repositorySession.setLocalRepositoryManager( new SimpleLocalRepositoryManager( localRepo ) );
1199 when( buildingRequest.getRepositorySession() ).thenReturn( repositorySession );
1200 when( session.getRepositorySession() ).thenReturn( repositorySession );
1201 LegacySupport legacySupport = lookup( LegacySupport.class );
1202 legacySupport.setSession( session );
1203 setVariableValueToObject( mojo, "session", session );
1204
1205 mojo.execute();
1206
1207 Path optionsFile = new File( mojo.getOutputDirectory(), "options" ).toPath();
1208 assertThat( optionsFile ).exists();
1209 String options = readFile( optionsFile );
1210
1211 assertThat( StringUtils.countMatches( options, LINE_SEPARATOR + "-taglet" + LINE_SEPARATOR ) ).isEqualTo( 22 );
1212 assertThat( options ).contains( "org.apache.maven.tools.plugin.javadoc.MojoAggregatorTypeTaglet" )
1213 .contains( "org.apache.maven.tools.plugin.javadoc.MojoComponentFieldTaglet" )
1214 .contains( "org.apache.maven.tools.plugin.javadoc.MojoConfiguratorTypeTaglet" )
1215 .contains( "org.apache.maven.tools.plugin.javadoc.MojoExecuteTypeTaglet" )
1216 .contains( "org.apache.maven.tools.plugin.javadoc.MojoExecutionStrategyTypeTaglet" )
1217 .contains( "org.apache.maven.tools.plugin.javadoc.MojoGoalTypeTaglet" )
1218 .contains( "org.apache.maven.tools.plugin.javadoc.MojoInheritByDefaultTypeTaglet" )
1219 .contains( "org.apache.maven.tools.plugin.javadoc.MojoInstantiationStrategyTypeTaglet" )
1220 .contains( "org.apache.maven.tools.plugin.javadoc.MojoParameterFieldTaglet" )
1221 .contains( "org.apache.maven.tools.plugin.javadoc.MojoPhaseTypeTaglet" )
1222 .contains( "org.apache.maven.tools.plugin.javadoc.MojoReadOnlyFieldTaglet" )
1223 .contains( "org.apache.maven.tools.plugin.javadoc.MojoRequiredFieldTaglet" )
1224 .contains( "org.apache.maven.tools.plugin.javadoc.MojoRequiresDependencyResolutionTypeTaglet" )
1225 .contains( "org.apache.maven.tools.plugin.javadoc.MojoRequiresDirectInvocationTypeTaglet" )
1226 .contains( "org.apache.maven.tools.plugin.javadoc.MojoRequiresOnLineTypeTaglet" )
1227 .contains( "org.apache.maven.tools.plugin.javadoc.MojoRequiresProjectTypeTaglet" )
1228 .contains( "org.apache.maven.tools.plugin.javadoc.MojoRequiresReportsTypeTaglet" )
1229 .contains( "org.codehaus.plexus.javadoc.PlexusConfigurationTaglet" )
1230 .contains( "org.codehaus.plexus.javadoc.PlexusRequirementTaglet" )
1231 .contains( "org.codehaus.plexus.javadoc.PlexusComponentTaglet" );
1232 }
1233
1234
1235
1236
1237
1238
1239 public void testStylesheetfile()
1240 throws Exception
1241 {
1242 Path testPom = unit.resolve( "stylesheetfile-test/pom.xml" );
1243
1244 JavadocReport mojo = lookupMojo( testPom );
1245 assertNotNull( mojo );
1246
1247 MavenSession session = spy( newMavenSession( mojo.project ) );
1248 ProjectBuildingRequest buildingRequest = mock( ProjectBuildingRequest.class );
1249 when( buildingRequest.getRemoteRepositories() ).thenReturn( mojo.project.getRemoteArtifactRepositories() );
1250 when( session.getProjectBuildingRequest() ).thenReturn( buildingRequest );
1251 MavenRepositorySystemSession repositorySession = new MavenRepositorySystemSession();
1252 repositorySession.setLocalRepositoryManager( new SimpleLocalRepositoryManager( localRepo ) );
1253 when( buildingRequest.getRepositorySession() ).thenReturn( repositorySession );
1254 when( session.getRepositorySession() ).thenReturn( repositorySession );
1255 LegacySupport legacySupport = lookup( LegacySupport.class );
1256 legacySupport.setSession( session );
1257 setVariableValueToObject( mojo, "session", session );
1258
1259 Path apidocs = new File( getBasedir(), "target/test/unit/stylesheetfile-test/target/site/apidocs" ).toPath();
1260
1261 Path stylesheetfile = apidocs.resolve( "stylesheet.css" );
1262 Path options = apidocs.resolve( "options" );
1263
1264
1265 setVariableValueToObject( mojo, "stylesheet", "javamaven" );
1266
1267 try
1268 {
1269 mojo.execute();
1270 fail();
1271 }
1272 catch ( Exception e )
1273 {
1274 assertTrue( true );
1275 }
1276
1277
1278 setVariableValueToObject( mojo, "stylesheet", "java" );
1279 mojo.execute();
1280
1281 String content = readFile( stylesheetfile );
1282 if ( JavaVersion.JAVA_VERSION.isAtLeast( "13-ea" ) )
1283 {
1284 assertTrue( content.contains( "/*" + LINE_SEPARATOR
1285 + " * Javadoc style sheet" + LINE_SEPARATOR
1286 + " */" ) );
1287 }
1288 else if ( JavaVersion.JAVA_VERSION.isAtLeast( "10" ) )
1289 {
1290 assertTrue( content.contains( "/* " + LINE_SEPARATOR
1291 + " * Javadoc style sheet" + LINE_SEPARATOR
1292 + " */" ) );
1293 }
1294 else
1295 {
1296 assertTrue( content.contains( "/* Javadoc style sheet */" ) );
1297 }
1298
1299 String optionsContent = readFile( options );
1300 assertFalse( optionsContent.contains( "-stylesheetfile" ) );
1301
1302
1303 setVariableValueToObject( mojo, "stylesheet", "maven" );
1304 mojo.execute();
1305
1306 content = readFile( stylesheetfile );
1307 assertTrue( content.contains( "/* Javadoc style sheet */" )
1308 && content.contains( "Licensed to the Apache Software Foundation (ASF) under one" ) );
1309
1310 optionsContent = readFile( options );
1311 assertTrue( optionsContent.contains( "-stylesheetfile" ) );
1312 assertTrue( optionsContent.contains( "'" + stylesheetfile.toFile().getAbsolutePath().replaceAll( "\\\\", "/" ) + "'" ) );
1313
1314
1315 setVariableValueToObject( mojo, "stylesheet", null );
1316 setVariableValueToObject( mojo, "stylesheetfile", "com/mycompany/app/javadoc/css/stylesheet.css" );
1317 mojo.execute();
1318
1319 content = readFile( stylesheetfile );
1320 assertTrue( content.contains( "/* Custom Javadoc style sheet in project */" ) );
1321
1322 optionsContent = readFile( options );
1323 assertTrue( optionsContent.contains( "-stylesheetfile" ) );
1324 Path stylesheetResource =
1325 unit.resolve( "stylesheetfile-test/src/main/resources/com/mycompany/app/javadoc/css/stylesheet.css" );
1326 assertTrue( optionsContent.contains( "'" + stylesheetResource.toFile().getAbsolutePath().replaceAll( "\\\\", "/" )
1327 + "'" ) );
1328
1329
1330 setVariableValueToObject( mojo, "stylesheetfile", "com/mycompany/app/javadoc/css2/stylesheet.css" );
1331 mojo.execute();
1332
1333 content = readFile( stylesheetfile );
1334 assertTrue( content.contains( "/* Custom Javadoc style sheet in artefact */" ) );
1335
1336 optionsContent = readFile( options );
1337 assertTrue( optionsContent.contains( "-stylesheetfile" ) );
1338 assertTrue( optionsContent.contains( "'" + stylesheetfile.toFile().getAbsolutePath().replaceAll( "\\\\", "/" ) + "'" ) );
1339
1340
1341 Path css =
1342 unit.resolve( "stylesheetfile-test/src/main/resources/com/mycompany/app/javadoc/css3/stylesheet.css" );
1343 setVariableValueToObject( mojo, "stylesheetfile", css.toFile().getAbsolutePath() );
1344 mojo.execute();
1345
1346 content = readFile( stylesheetfile );
1347 assertTrue( content.contains( "/* Custom Javadoc style sheet as file */" ) );
1348
1349 optionsContent = readFile( options );
1350 assertTrue( optionsContent.contains( "-stylesheetfile" ) );
1351 stylesheetResource =
1352 unit.resolve( "stylesheetfile-test/src/main/resources/com/mycompany/app/javadoc/css3/stylesheet.css" );
1353 assertTrue( optionsContent.contains( "'" + stylesheetResource.toFile().getAbsolutePath().replaceAll( "\\\\", "/" ) + "'" ) );
1354 }
1355
1356
1357
1358
1359
1360
1361 public void testHelpfile()
1362 throws Exception
1363 {
1364 Path testPom = unit.resolve( "helpfile-test/pom.xml" );
1365
1366 JavadocReport mojo = lookupMojo( testPom );
1367 assertNotNull( mojo );
1368
1369 MavenSession session = spy( newMavenSession( mojo.project ) );
1370 ProjectBuildingRequest buildingRequest = mock( ProjectBuildingRequest.class );
1371 when( buildingRequest.getRemoteRepositories() ).thenReturn( mojo.project.getRemoteArtifactRepositories() );
1372 when( session.getProjectBuildingRequest() ).thenReturn( buildingRequest );
1373 MavenRepositorySystemSession repositorySession = new MavenRepositorySystemSession();
1374 repositorySession.setLocalRepositoryManager( new SimpleLocalRepositoryManager( localRepo ) );
1375 when( buildingRequest.getRepositorySession() ).thenReturn( repositorySession );
1376 when( session.getRepositorySession() ).thenReturn( repositorySession );
1377 LegacySupport legacySupport = lookup( LegacySupport.class );
1378 legacySupport.setSession( session );
1379 setVariableValueToObject( mojo, "session", session );
1380
1381 Path apidocs = new File( getBasedir(), "target/test/unit/helpfile-test/target/site/apidocs" ).toPath();
1382
1383 Path helpfile = apidocs.resolve( "help-doc.html" );
1384 Path options = apidocs.resolve( "options" );
1385
1386
1387 mojo.execute();
1388
1389 String content = readFile( helpfile );
1390 assertTrue( content.contains( "<!-- Generated by javadoc" ) );
1391
1392 String optionsContent = readFile( options );
1393 assertFalse( optionsContent.contains( "-helpfile" ) );
1394
1395
1396 setVariableValueToObject( mojo, "helpfile", "com/mycompany/app/javadoc/helpfile/help-doc.html" );
1397
1398 setVariableValueToObject( mojo, "session", session );
1399
1400 mojo.execute();
1401
1402 content = readFile( helpfile );
1403 assertTrue( content.contains( "<!-- Help file from artefact -->" ) );
1404
1405 optionsContent = readFile( options );
1406 assertTrue( optionsContent.contains( "-helpfile" ) );
1407 Path help = apidocs.resolve( "help-doc.html" );
1408 assertTrue( optionsContent.contains( "'" + help.toFile().getAbsolutePath().replaceAll( "\\\\", "/" ) + "'" ) );
1409
1410
1411 setVariableValueToObject( mojo, "helpfile", "com/mycompany/app/javadoc/helpfile2/help-doc.html" );
1412 mojo.execute();
1413
1414 content = readFile( helpfile );
1415 assertTrue( content.contains( "<!-- Help file from file -->" ) );
1416
1417 optionsContent = readFile( options );
1418 assertTrue( optionsContent.contains( "-helpfile" ) );
1419 help = unit.resolve( "helpfile-test/src/main/resources/com/mycompany/app/javadoc/helpfile2/help-doc.html" );
1420 assertTrue( optionsContent.contains( "'" + help.toFile().getAbsolutePath().replaceAll( "\\\\", "/" ) + "'" ) );
1421
1422
1423 help = unit.resolve( "helpfile-test/src/main/resources/com/mycompany/app/javadoc/helpfile2/help-doc.html" );
1424 setVariableValueToObject( mojo, "helpfile", help.toFile().getAbsolutePath() );
1425 mojo.execute();
1426
1427 content = readFile( helpfile );
1428 assertTrue( content.contains( "<!-- Help file from file -->" ) );
1429
1430 optionsContent = readFile( options );
1431 assertTrue( optionsContent.contains( "-helpfile" ) );
1432 assertTrue( optionsContent.contains( "'" + help.toFile().getAbsolutePath().replaceAll( "\\\\", "/" ) + "'" ) );
1433 }
1434 }