Skip to content

Commit f2c0657

Browse files
committed
[JXR-173] Upgrade Maven Reporting API to 3.1.1/Maven Reporting Impl to 3.2.0
This plugin hasn't been touched testwise for a very long time. The testing approach from MPIR has been applied to accommodate M-R-Impl 3.2.0 and future versions of it. This also upgrades for ITs: * Maven Site Plugin to 3.12.1 * Maven Javadoc Plugin to 3.4.1 This closes #66
1 parent 92a5d69 commit f2c0657

25 files changed

Lines changed: 355 additions & 173 deletions

maven-jxr-plugin/pom.xml

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ under the License.
3737

3838
<properties>
3939
<mavenVersion>3.2.5</mavenVersion>
40+
<aetherVersion>1.0.0.v20140518</aetherVersion>
4041
</properties>
4142

4243
<prerequisites>
@@ -85,16 +86,15 @@ under the License.
8586
<artifactId>wagon-provider-api</artifactId>
8687
<version>2.8</version><!-- like Maven 3.2.5 -->
8788
</dependency>
89+
<dependency>
90+
<groupId>org.apache.maven.reporting</groupId>
91+
<artifactId>maven-reporting-api</artifactId>
92+
<version>3.1.1</version>
93+
</dependency>
8894
<dependency>
8995
<groupId>org.apache.maven.reporting</groupId>
9096
<artifactId>maven-reporting-impl</artifactId>
91-
<version>3.1.0</version>
92-
<exclusions>
93-
<exclusion>
94-
<groupId>org.codehaus.plexus</groupId>
95-
<artifactId>plexus-container-default</artifactId>
96-
</exclusion>
97-
</exclusions>
97+
<version>3.2.0</version>
9898
</dependency>
9999

100100
<!-- shared utils -->
@@ -126,6 +126,36 @@ under the License.
126126
</exclusion>
127127
</exclusions>
128128
</dependency>
129+
<dependency>
130+
<groupId>org.eclipse.aether</groupId>
131+
<artifactId>aether-api</artifactId>
132+
<version>${aetherVersion}</version>
133+
<scope>test</scope>
134+
</dependency>
135+
<dependency>
136+
<groupId>org.eclipse.aether</groupId>
137+
<artifactId>aether-impl</artifactId>
138+
<version>${aetherVersion}</version>
139+
<scope>test</scope>
140+
</dependency>
141+
<dependency>
142+
<groupId>org.eclipse.aether</groupId>
143+
<artifactId>aether-connector-basic</artifactId>
144+
<version>${aetherVersion}</version>
145+
<scope>test</scope>
146+
</dependency>
147+
<dependency>
148+
<groupId>org.eclipse.aether</groupId>
149+
<artifactId>aether-transport-wagon</artifactId>
150+
<version>${aetherVersion}</version>
151+
<scope>test</scope>
152+
</dependency>
153+
<dependency>
154+
<groupId>org.apache.maven.wagon</groupId>
155+
<artifactId>wagon-http-lightweight</artifactId>
156+
<version>3.5.1</version>
157+
<scope>test</scope>
158+
</dependency>
129159
<dependency>
130160
<groupId>junit</groupId>
131161
<artifactId>junit</artifactId>
@@ -189,7 +219,6 @@ under the License.
189219
<artifactId>maven-invoker-plugin</artifactId>
190220
<configuration>
191221
<writeJunitReport>true</writeJunitReport>
192-
<projectsDirectory>src/it</projectsDirectory>
193222
<cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
194223
<pomIncludes>
195224
<pomInclude>*/pom.xml</pomInclude>

maven-jxr-plugin/src/main/java/org/apache/maven/plugin/jxr/AbstractJxrReport.java

Lines changed: 9 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,19 @@
3131
import java.util.Locale;
3232
import java.util.ResourceBundle;
3333

34-
import org.apache.maven.doxia.siterenderer.Renderer;
34+
import org.apache.maven.execution.MavenSession;
3535
import org.apache.maven.jxr.JXR;
3636
import org.apache.maven.jxr.JavaCodeTransform;
3737
import org.apache.maven.jxr.JxrException;
3838
import org.apache.maven.jxr.pacman.FileManager;
3939
import org.apache.maven.jxr.pacman.PackageManager;
4040
import org.apache.maven.model.ReportPlugin;
41-
import org.apache.maven.plugin.MojoExecutionException;
42-
import org.apache.maven.plugins.annotations.Component;
4341
import org.apache.maven.plugins.annotations.Parameter;
4442
import org.apache.maven.project.MavenProject;
4543
import org.apache.maven.reporting.AbstractMavenReport;
4644
import org.apache.maven.reporting.MavenReportException;
4745
import org.codehaus.plexus.languages.java.version.JavaVersion;
4846
import org.codehaus.plexus.util.FileUtils;
49-
import org.codehaus.plexus.util.ReaderFactory;
5047
import org.codehaus.plexus.util.StringUtils;
5148

5249
/**
@@ -60,31 +57,9 @@
6057
public abstract class AbstractJxrReport
6158
extends AbstractMavenReport
6259
{
63-
@Parameter( defaultValue = "${project}", readonly = true, required = true )
64-
private MavenProject project;
6560

66-
@Component
67-
private Renderer siteRenderer;
68-
69-
/**
70-
* Output folder where the main page of the report will be generated. Note that this parameter is only relevant if
71-
* the goal is run directly from the command line or from the default lifecycle. If the goal is run indirectly as
72-
* part of a site generation, the output directory configured in the Maven Site Plugin will be used instead.
73-
*/
74-
@Parameter( defaultValue = "${project.reporting.outputDirectory}", required = true )
75-
private File outputDirectory;
76-
77-
/**
78-
* File input encoding.
79-
*/
80-
@Parameter( property = "encoding", defaultValue = "${project.build.sourceEncoding}" )
81-
private String inputEncoding;
82-
83-
/**
84-
* File output encoding.
85-
*/
86-
@Parameter( property = "outputEncoding", defaultValue = "${project.reporting.outputEncoding}" )
87-
private String outputEncoding;
61+
@Parameter( defaultValue = "${session}", readonly = true, required = true )
62+
private MavenSession session;
8863

8964
/**
9065
* Title of window of the Xref HTML files.
@@ -171,18 +146,6 @@ public abstract class AbstractJxrReport
171146
*/
172147
private JavaVersion javadocTemplatesVersion;
173148

174-
/**
175-
* Gets the effective reporting output files encoding.
176-
*
177-
* @return The effective reporting output file encoding, never <code>null</code>: defaults to <code>UTF-8</code>
178-
* instead.
179-
*/
180-
@Override
181-
protected String getOutputEncoding()
182-
{
183-
return ( outputEncoding == null ) ? ReaderFactory.UTF_8 : outputEncoding;
184-
}
185-
186149
/**
187150
* Compiles the list of directories which contain source files that will be included in the JXR report generation.
188151
*
@@ -270,16 +233,10 @@ private void createXref( Locale locale, String destinationDirectory, List<String
270233
FileManager fileManager = new FileManager();
271234
PackageManager packageManager = new PackageManager( fileManager );
272235
JavaCodeTransform codeTransform = new JavaCodeTransform( packageManager, fileManager );
273-
236+
274237
JXR jxr = new JXR( packageManager, codeTransform );
275238
jxr.setDest( Paths.get( destinationDirectory ) );
276-
if ( StringUtils.isEmpty( inputEncoding ) )
277-
{
278-
String platformEncoding = System.getProperty( "file.encoding" );
279-
getLog().warn( "File encoding has not been set, using platform encoding " + platformEncoding
280-
+ ", i.e. build is platform dependent!" );
281-
}
282-
jxr.setInputEncoding( inputEncoding );
239+
jxr.setInputEncoding( getInputEncoding() );
283240
jxr.setLocale( locale );
284241
jxr.setOutputEncoding( getOutputEncoding() );
285242
jxr.setRevision( "HEAD" );
@@ -457,21 +414,14 @@ private void copyResources( String dir, String sourceFolder, String... files )
457414
}
458415

459416
@Override
460-
protected Renderer getSiteRenderer()
417+
protected MavenProject getProject()
461418
{
462-
return siteRenderer;
463-
}
464-
465-
@Override
466-
protected String getOutputDirectory()
467-
{
468-
return outputDirectory.getAbsolutePath();
419+
return project;
469420
}
470421

471-
@Override
472-
public MavenProject getProject()
422+
protected MavenSession getSession()
473423
{
474-
return project;
424+
return session;
475425
}
476426

477427
/**
@@ -500,33 +450,6 @@ protected boolean canGenerateReport( List<String> sourceDirs )
500450
return canGenerate;
501451
}
502452

503-
/*
504-
* This is called for a standalone execution. Well, that's the claim. It also ends up called for the aggregate mojo,
505-
* since that is configured as an execution, not in the reporting section, at least by some people on some days. We
506-
* do NOT want the default behavior.
507-
*/
508-
@Override
509-
public void execute()
510-
throws MojoExecutionException
511-
{
512-
513-
if ( skip )
514-
{
515-
getLog().info( "Skipping JXR." );
516-
return;
517-
}
518-
519-
Locale locale = Locale.getDefault();
520-
try
521-
{
522-
executeReport( locale );
523-
}
524-
catch ( MavenReportException e )
525-
{
526-
throw new MojoExecutionException( "Error generating JXR report", e );
527-
}
528-
}
529-
530453
@Override
531454
protected void executeReport( Locale locale )
532455
throws MavenReportException
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
package org.apache.maven.plugin.jxr;
2+
3+
/*
4+
* Licensed to the Apache Software Foundation (ASF) under one
5+
* or more contributor license agreements. See the NOTICE file
6+
* distributed with this work for additional information
7+
* regarding copyright ownership. The ASF licenses this file
8+
* to you under the Apache License, Version 2.0 (the
9+
* "License"); you may not use this file except in compliance
10+
* with the License. You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing,
15+
* software distributed under the License is distributed on an
16+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
* KIND, either express or implied. See the License for the
18+
* specific language governing permissions and limitations
19+
* under the License.
20+
*/
21+
22+
import java.io.File;
23+
import java.io.IOException;
24+
import java.nio.file.Files;
25+
26+
import org.apache.maven.plugin.LegacySupport;
27+
import org.apache.maven.plugin.testing.AbstractMojoTestCase;
28+
import org.apache.maven.plugin.testing.ArtifactStubFactory;
29+
import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
30+
import org.apache.maven.project.DefaultProjectBuildingRequest;
31+
import org.apache.maven.project.MavenProject;
32+
import org.apache.maven.project.ProjectBuilder;
33+
import org.apache.maven.project.ProjectBuildingRequest;
34+
import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory;
35+
import org.eclipse.aether.DefaultRepositorySystemSession;
36+
import org.eclipse.aether.repository.LocalRepository;
37+
38+
/**
39+
* Abstract class to test reports generation.
40+
*/
41+
public abstract class AbstractJxrTestCase
42+
extends AbstractMojoTestCase
43+
{
44+
private ArtifactStubFactory artifactStubFactory;
45+
46+
/**
47+
* The current project to be test.
48+
*/
49+
private MavenProject testMavenProject;
50+
51+
@Override
52+
protected void setUp()
53+
throws Exception
54+
{
55+
// required for mojo lookups to work
56+
super.setUp();
57+
58+
artifactStubFactory = new DependencyArtifactStubFactory( getTestFile( "target" ), true, false );
59+
artifactStubFactory.getWorkingDir().mkdirs();
60+
}
61+
62+
@Override
63+
protected void tearDown()
64+
throws Exception
65+
{
66+
super.tearDown();
67+
}
68+
69+
/**
70+
* Get the current Maven project
71+
*
72+
* @return the maven project
73+
*/
74+
protected MavenProject getTestMavenProject()
75+
{
76+
return testMavenProject;
77+
}
78+
79+
/**
80+
* Get the generated report as file in the test maven project.
81+
*
82+
* @param name the name of the report.
83+
* @return the generated report as file
84+
* @throws IOException if the return file doesnt exist
85+
*/
86+
protected File getGeneratedReport( String name )
87+
throws IOException
88+
{
89+
String outputDirectory = getBasedir() + "/target/test/unit/" + getTestMavenProject().getArtifactId();
90+
91+
File report = new File( outputDirectory, name );
92+
if ( !report.exists() )
93+
{
94+
throw new IOException( "File not found. Attempted: " + report );
95+
}
96+
97+
return report;
98+
}
99+
100+
/**
101+
* Generate the report and return the generated file
102+
*
103+
* @param goal the mojo goal.
104+
* @param pluginXml the name of the xml file in "src/test/resources/plugin-configs/".
105+
* @return the generated HTML file
106+
* @throws Exception if any
107+
*/
108+
protected File generateReport( String goal, String pluginXml )
109+
throws Exception
110+
{
111+
File pluginXmlFile = new File( getBasedir(), "src/test/resources/unit/" + pluginXml );
112+
AbstractJxrReport mojo = createReportMojo( goal, pluginXmlFile );
113+
return generateReport( mojo, pluginXmlFile );
114+
}
115+
116+
protected AbstractJxrReport createReportMojo( String goal, File pluginXmlFile )
117+
throws Exception
118+
{
119+
AbstractJxrReport mojo = (AbstractJxrReport) lookupMojo( goal, pluginXmlFile );
120+
assertNotNull( "Mojo not found.", mojo );
121+
122+
LegacySupport legacySupport = lookup( LegacySupport.class );
123+
legacySupport.setSession( newMavenSession( new MavenProjectStub() ) );
124+
DefaultRepositorySystemSession repoSession =
125+
(DefaultRepositorySystemSession) legacySupport.getRepositorySession();
126+
repoSession.setLocalRepositoryManager( new SimpleLocalRepositoryManagerFactory().newInstance( repoSession, new LocalRepository( artifactStubFactory.getWorkingDir() ) ) );
127+
128+
setVariableValueToObject( mojo, "session", legacySupport.getSession() );
129+
setVariableValueToObject( mojo, "remoteRepositories", mojo.getProject().getRemoteArtifactRepositories() );
130+
return mojo;
131+
}
132+
133+
protected File generateReport( AbstractJxrReport mojo, File pluginXmlFile )
134+
throws Exception
135+
{
136+
mojo.execute();
137+
138+
ProjectBuilder builder = lookup( ProjectBuilder.class );
139+
140+
ProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest();
141+
buildingRequest.setRepositorySession( lookup( LegacySupport.class ).getRepositorySession() );
142+
143+
testMavenProject = builder.build( pluginXmlFile, buildingRequest ).getProject();
144+
145+
File outputDir = mojo.getReportOutputDirectory();
146+
String filename = mojo.getOutputName() + ".html";
147+
148+
return new File( outputDir, filename );
149+
}
150+
151+
/**
152+
* Read the contents of the specified file object into a string
153+
*/
154+
protected String readFile( File xrefTestDir, String fileName ) throws IOException
155+
{
156+
return new String( Files.readAllBytes( xrefTestDir.toPath().resolve( fileName ) ) );
157+
}
158+
159+
}

0 commit comments

Comments
 (0)