Skip to content

Commit

Permalink
[MSITE-757] remove Maven 2 support (#24)
Browse files Browse the repository at this point in the history
remove Maven 2 support
* remove dependency on classworlds
  • Loading branch information
elharo committed May 26, 2020
1 parent d8845db commit f37789b
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 74 deletions.
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 @@ -171,11 +171,11 @@ public void execute()
}

/**
* Make sure the given url ends with a slash.
* Make sure the given URL ends with a slash.
*
* @param url a String.
* @return if url already ends with '/' it is returned unchanged,
* otherwise a '/' character is appended.
* @param url a String
* @return if url already ends with '/' it is returned unchanged.
* Otherwise a '/' character is appended.
*/
protected static String appendSlash( final String url )
{
Expand Down Expand Up @@ -476,13 +476,75 @@ private static void chmod( final Wagon wagon, final Repository repository, final
}

/**
* Get proxy information for Maven 3.
* Get proxy information.
* <p>
* Get the <code>ProxyInfo</code> of the proxy associated with the <code>host</code>
* and the <code>protocol</code> of the given <code>repository</code>.
* </p>
* <p>
* 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 comma (",") and semi colon (";") in addition to pipe ("|") as separator.
* </p>
*
* @param repository the Repository to extract the ProxyInfo from.
* @param settingsDecrypter settings password decrypter.
* @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 )
{
ProxyInfo proxyInfo = wagonManager.getProxy( repository.getProtocol() );

if ( proxyInfo == null )
{
return null;
}

String host = repository.getHost();
String nonProxyHostsAsString = proxyInfo.getNonProxyHosts();
for ( String nonProxyHost : StringUtils.split( nonProxyHostsAsString, ",;|" ) )
{
if ( StringUtils.contains( nonProxyHost, "*" ) )
{
// Handle wildcard at the end, beginning or middle of the nonProxyHost
final int pos = nonProxyHost.indexOf( '*' );
String nonProxyHostPrefix = nonProxyHost.substring( 0, pos );
String nonProxyHostSuffix = nonProxyHost.substring( pos + 1 );
// prefix*
if ( StringUtils.isNotEmpty( nonProxyHostPrefix ) && host.startsWith( nonProxyHostPrefix )
&& StringUtils.isEmpty( nonProxyHostSuffix ) )
{
return null;
}
// *suffix
if ( StringUtils.isEmpty( nonProxyHostPrefix ) && StringUtils.isNotEmpty( nonProxyHostSuffix )
&& host.endsWith( nonProxyHostSuffix ) )
{
return null;
}
// prefix*suffix
if ( StringUtils.isNotEmpty( nonProxyHostPrefix ) && host.startsWith( nonProxyHostPrefix )
&& StringUtils.isNotEmpty( nonProxyHostSuffix ) && host.endsWith( nonProxyHostSuffix ) )
{
return null;
}
}
else if ( host.equals( nonProxyHost ) )
{
return null;
}
}
return proxyInfo;
}

/**
* Get proxy information.
*
* @param repository the Repository to extract the ProxyInfo from
* @param settingsDecrypter settings password decrypter
* @return a ProxyInfo object instantiated or <code>null</code> if no matching proxy is found.
*/
private ProxyInfo getProxy( Repository repository, SettingsDecrypter settingsDecrypter )
Expand Down Expand Up @@ -565,12 +627,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 @@ -596,7 +652,6 @@ private static void configureWagon( Wagon wagon, String repositoryId, Settings s
{
componentConfigurator =
(ComponentConfigurator) container.lookup( ComponentConfigurator.ROLE, "basic" );

componentConfigurator.configureComponent( wagon, plexusConf, container.getContainerRealm() );
}
catch ( final ComponentLookupException e )
Expand Down Expand Up @@ -732,7 +787,7 @@ private static class URIEncoder
private static final String MARK = "-_.!~*'()";
private static final String RESERVED = ";/?:@&=+$,";

public static String encodeURI( final String uriString )
private static String encodeURI( final String uriString )
{
final char[] chars = uriString.toCharArray();
final StringBuilder uri = new StringBuilder( chars.length );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,20 +230,19 @@ protected void checkInputEncoding()
protected List<MavenReportExecution> getReports()
throws MojoExecutionException
{
MavenReportExecutorRequest mavenReportExecutorRequest = new MavenReportExecutorRequest();
mavenReportExecutorRequest.setLocalRepository( localRepository );
mavenReportExecutorRequest.setMavenSession( mavenSession );
mavenReportExecutorRequest.setProject( project );
mavenReportExecutorRequest.setReportPlugins( getReportingPlugins() );

try
{
MavenReportExecutor mavenReportExecutor = container.lookup( MavenReportExecutor.class );

MavenReportExecutorRequest mavenReportExecutorRequest = new MavenReportExecutorRequest();
mavenReportExecutorRequest.setLocalRepository( localRepository );
mavenReportExecutorRequest.setMavenSession( mavenSession );
mavenReportExecutorRequest.setProject( project );
mavenReportExecutorRequest.setReportPlugins( getReportingPlugins() );

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 @@ -261,7 +260,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

0 comments on commit f37789b

Please sign in to comment.