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