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