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