Skip to content

Commit

Permalink
Merge pull request #279 from ppalaga/i278
Browse files Browse the repository at this point in the history
Fix #278 Add timeout parameters to AbstractDownloadLicensesMojo
  • Loading branch information
ppalaga authored Feb 21, 2019
2 parents 98e90b6 + 8775350 commit 87489be
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,30 @@ public abstract class AbstractDownloadLicensesMojo
@Parameter( property = "license.writeVersions", defaultValue = "true" )
private boolean writeVersions;

/**
* Connect timeout in milliseconds passed to the HTTP client when downloading licenses from remote URLs.
*
* @since 1.18
*/
@Parameter( property = "license.connectTimeout", defaultValue = "5000" )
private int connectTimeout;

/**
* Socket timeout in milliseconds passed to the HTTP client when downloading licenses from remote URLs.
*
* @since 1.18
*/
@Parameter( property = "license.socketTimeout", defaultValue = "5000" )
private int socketTimeout;

/**
* Connect request timeout in milliseconds passed to the HTTP client when downloading licenses from remote URLs.
*
* @since 1.18
*/
@Parameter( property = "license.connectionRequestTimeout", defaultValue = "5000" )
private int connectionRequestTimeout;

// ----------------------------------------------------------------------
// Plexus Components
// ----------------------------------------------------------------------
Expand Down Expand Up @@ -619,7 +643,8 @@ public void execute()
// The resulting list of licenses after dependency resolution
final List<ProjectLicenseInfo> depProjectLicenses = new ArrayList<>();

try ( LicenseDownloader licenseDownloader = new LicenseDownloader( findActiveProxy() ) )
try ( LicenseDownloader licenseDownloader =
new LicenseDownloader( findActiveProxy(), connectTimeout, socketTimeout, connectionRequestTimeout ) )
{
for ( MavenProject project : dependencies )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,22 +74,16 @@
public class LicenseDownloader implements AutoCloseable
{

/**
* Defines the connection timeout in milliseconds when attempting to download license files.
*/
public static final int DEFAULT_CONNECTION_TIMEOUT = 5000;

private static final Pattern EXTENSION_PATTERN = Pattern.compile( "\\.[a-z]{1,4}$", Pattern.CASE_INSENSITIVE );

private final CloseableHttpClient client;

public LicenseDownloader( Proxy proxy )
public LicenseDownloader( Proxy proxy, int connectTimeout, int socketTimeout, int connectionRequestTimeout )
{

final Builder configBuilder = RequestConfig.copy( RequestConfig.DEFAULT ) //
.setConnectTimeout( DEFAULT_CONNECTION_TIMEOUT ) //
.setSocketTimeout( DEFAULT_CONNECTION_TIMEOUT ) //
.setConnectionRequestTimeout( DEFAULT_CONNECTION_TIMEOUT );
.setConnectTimeout( connectTimeout ) //
.setSocketTimeout( socketTimeout ) //
.setConnectionRequestTimeout( connectionRequestTimeout );

HttpClientBuilder clientBuilder = HttpClients.custom().setDefaultRequestConfig( configBuilder.build() );
if ( proxy != null )
Expand Down

0 comments on commit 87489be

Please sign in to comment.