Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MSITE-757] remove Maven 2 support #24

Merged
merged 5 commits into from
May 26, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 0 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -323,12 +323,6 @@ under the License.
<version>3.3.0</version>
</dependency>

<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-classworlds</artifactId>
<version>2.5.2</version>
</dependency>

<!-- Doxia -->
<dependency>
<groupId>org.apache.maven.doxia</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
import org.apache.maven.wagon.observers.Debug;
import org.apache.maven.wagon.proxy.ProxyInfo;
import org.apache.maven.wagon.repository.Repository;
import org.codehaus.classworlds.ClassRealm;
import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.configurator.ComponentConfigurationException;
Expand All @@ -67,7 +66,6 @@
import org.codehaus.plexus.util.xml.Xpp3Dom;

import java.io.File;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
Expand Down Expand Up @@ -501,16 +499,16 @@ private static void chmod( final Wagon wagon, final Repository repository, final
* and the <code>protocol</code> of the given <code>repository</code>.
* </p>
* <p>
* Extract from <a href="http://java.sun.com/j2se/1.5.0/docs/guide/net/properties.html">
* Extract from <a href="https://docs.oracle.com/javase/1.5.0/docs/guide/net/properties.html">
* J2SE Doc : Networking Properties - nonProxyHosts</a> : "The value can be a list of hosts,
* each separated by a |, and in addition a wildcard character (*) can be used for matching"
* </p>
* <p>
* Defensively support for comma (",") and semi colon (";") in addition to pipe ("|") as separator.
* Defensively support comma (",") and semi colon (";") in addition to pipe ("|") as separator.
* </p>
*
* @param repository the Repository to extract the ProxyInfo from.
* @param wagonManager the WagonManager used to connect to the Repository.
* @param repository the Repository to extract the ProxyInfo from
* @param wagonManager the WagonManager used to connect to the Repository
* @return a ProxyInfo object instantiated or <code>null</code> if no matching proxy is found
*/
public static ProxyInfo getProxyInfo( Repository repository, WagonManager wagonManager )
Expand Down Expand Up @@ -560,11 +558,7 @@ else if ( host.equals( nonProxyHost ) )
}

/**
* Get proxy information for Maven 3.
*
* @param repository
* @param settingsDecrypter
* @return
* Get proxy information.
*/
private ProxyInfo getProxy( Repository repository, SettingsDecrypter settingsDecrypter )
{
Expand Down Expand Up @@ -646,12 +640,6 @@ private ProxyInfo getProxy( Repository repository, SettingsDecrypter settingsDec
/**
* Configure the Wagon with the information from serverConfigurationMap ( which comes from settings.xml )
*
* @param wagon
* @param repositoryId
* @param settings
* @param container
* @param log
* @throws TransferFailedException
* @todo Remove when {@link WagonManager#getWagon(Repository) is available}. It's available in Maven 2.0.5.
*/
private static void configureWagon( Wagon wagon, String repositoryId, Settings settings, PlexusContainer container,
Expand All @@ -677,15 +665,8 @@ private static void configureWagon( Wagon wagon, String repositoryId, Settings s
{
componentConfigurator =
(ComponentConfigurator) container.lookup( ComponentConfigurator.ROLE, "basic" );
if ( isMaven3OrMore() )
{
componentConfigurator.configureComponent( wagon, plexusConf,
componentConfigurator.configureComponent( wagon, plexusConf,
container.getContainerRealm() );
}
else
{
configureWagonWithMaven2( componentConfigurator, wagon, plexusConf, container );
}
}
catch ( final ComponentLookupException e )
{
Expand Down Expand Up @@ -716,33 +697,6 @@ private static void configureWagon( Wagon wagon, String repositoryId, Settings s
}
}

private static void configureWagonWithMaven2( ComponentConfigurator componentConfigurator, Wagon wagon,
PlexusConfiguration plexusConf, PlexusContainer container )
throws ComponentConfigurationException
{
// in Maven 2.x :
// * container.getContainerRealm() -> org.codehaus.classworlds.ClassRealm
// * componentConfiguration 3rd param is org.codehaus.classworlds.ClassRealm
// so use some reflection see MSITE-609
try
{
Method methodContainerRealm = container.getClass().getMethod( "getContainerRealm" );
ClassRealm realm = (ClassRealm) methodContainerRealm.invoke( container );

Method methodConfigure = componentConfigurator.getClass().getMethod( "configureComponent",
new Class[]{ Object.class,
PlexusConfiguration.class,
ClassRealm.class } );

methodConfigure.invoke( componentConfigurator, wagon, plexusConf, realm );
}
catch ( Exception e )
{
throw new ComponentConfigurationException(
"Failed to configure wagon component for a Maven2 use " + e.getMessage(), e );
}
}

/**
* {@inheritDoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,40 +230,25 @@ protected void checkInputEncoding()
protected List<MavenReportExecution> getReports()
throws MojoExecutionException
{
final List<MavenReportExecution> allReports;
if ( isMaven3OrMore() )
MavenReportExecutorRequest mavenReportExecutorRequest = new MavenReportExecutorRequest();
mavenReportExecutorRequest.setLocalRepository( localRepository );
mavenReportExecutorRequest.setMavenSession( mavenSession );
mavenReportExecutorRequest.setProject( project );
mavenReportExecutorRequest.setReportPlugins( getReportingPlugins() );

MavenReportExecutor mavenReportExecutor;
try
{
// Maven 3
MavenReportExecutorRequest mavenReportExecutorRequest = new MavenReportExecutorRequest();
mavenReportExecutorRequest.setLocalRepository( localRepository );
mavenReportExecutorRequest.setMavenSession( mavenSession );
mavenReportExecutorRequest.setProject( project );
mavenReportExecutorRequest.setReportPlugins( getReportingPlugins() );

MavenReportExecutor mavenReportExecutor;
try
{
mavenReportExecutor = container.lookup( MavenReportExecutor.class );
}
catch ( ComponentLookupException e )
{
throw new MojoExecutionException( "could not get MavenReportExecutor component", e );
}

allReports = mavenReportExecutor.buildMavenReports( mavenReportExecutorRequest );
mavenReportExecutor = container.lookup( MavenReportExecutor.class );
}
else
catch ( ComponentLookupException e )
{
// Maven 2
allReports = new ArrayList<>( reports.size() );
for ( MavenReport report : reports )
{
allReports.add( new MavenReportExecution( report ) );
}
throw new MojoExecutionException( "could not get MavenReportExecutor component", e );
}

List<MavenReportExecution> allReports = mavenReportExecutor.buildMavenReports( mavenReportExecutorRequest );

// filter out reports that can't be generated
// todo Lambda Java 1.8
List<MavenReportExecution> reportExecutions = new ArrayList<>( allReports.size() );
for ( MavenReportExecution exec : allReports )
{
Expand All @@ -276,7 +261,7 @@ protected List<MavenReportExecution> getReports()
}

/**
* Get the report plugins from reporting section, adding if necessary (ni.e. not excluded)
* Get the report plugins from reporting section, adding if necessary (i.e. not excluded)
* default reports (i.e. maven-project-info-reports)
*
* @return the effective list of reports
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,57 +76,16 @@ public ReportDocumentRenderer( MavenReportExecution mavenReportExecution, Render

this.renderingContext = renderingContext;

if ( mavenReportExecution.getPlugin() == null )
{
// Maven 2: report has been prepared in Maven Core, MavenReportExecution contains only the report
this.reportMojoInfo = getPluginInfo( report );
}
else
{
// Maven 3: full MavenReportExecution prepared by maven-reporting-impl
this.reportMojoInfo =
mavenReportExecution.getPlugin().getArtifactId() + ':' + mavenReportExecution.getPlugin().getVersion()
+ ':' + mavenReportExecution.getGoal();
}
// full MavenReportExecution prepared by maven-reporting-impl
this.reportMojoInfo =
mavenReportExecution.getPlugin().getArtifactId() + ':' + mavenReportExecution.getPlugin().getVersion()
+ ':' + mavenReportExecution.getGoal();

this.classLoader = mavenReportExecution.getClassLoader();

this.log = log;
}

/**
* Get plugin information from report's Manifest.
*
* @param report the Maven report
* @return plugin information as Specification Title followed by Specification Version if set in Manifest and
* supported by JVM
*/
private String getPluginInfo( MavenReport report )
{
Package pkg = report.getClass().getPackage();

if ( pkg != null )
{
String title = pkg.getSpecificationTitle();
String version = pkg.getSpecificationVersion();

if ( title == null )
{
return version;
}
else if ( version == null )
{
return title;
}
else
{
return title + ' ' + version;
}
}

return null;
}

private static class MultiPageSubSink
extends SiteRendererSink
{
Expand Down