Skip to content

Commit

Permalink
Fix #235 NPE when there is no <url> under <license>
Browse files Browse the repository at this point in the history
  • Loading branch information
ppalaga committed Feb 5, 2019
1 parent 61fec38 commit 1942da6
Showing 1 changed file with 58 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -890,72 +890,81 @@ private void downloadLicenses( LicenseDownloader licenseDownloader, ProjectLicen
return;
}

int licenseIndex = 0;
for ( ProjectLicense license : licenses )
{
final String licenseUrl = rewriteLicenseUrlIfNecessary( license.getUrl() );
try
if ( license.getUrl() == null )
{

File licenseOutputFile = downloadedLicenseURLs.get( licenseUrl );
if ( licenseOutputFile == null )
handleError( depProject, "No URL for license at index " + licenseIndex + " in dependency "
+ depProject.toString() );
}
else
{
final String licenseUrl = rewriteLicenseUrlIfNecessary( license.getUrl() );
try
{
final String licenseFileName;
if ( license.getFile() != null )
{
licenseFileName = new File( license.getFile() ).getName();
}
else
{
licenseFileName = getLicenseFileName( depProject,
new URL( license.getUrl() ),
license.getName() );
}
licenseOutputFile = new File( licensesOutputDirectory, licenseFileName );
}

if ( !licenseOutputFile.exists() || forceDownload )
{
if ( !downloadedLicenseURLs.containsKey( licenseUrl ) || organizeLicensesByDependencies )
File licenseOutputFile = downloadedLicenseURLs.get( licenseUrl );
if ( licenseOutputFile == null )
{
final LicenseDownloadResult result =
licenseDownloader.downloadLicense( licenseUrl, proxyLoginPasswordEncoded, licenseOutputFile,
getLog() );

if ( result.isSuccess() )
final String licenseFileName;
if ( license.getFile() != null )
{
licenseOutputFile = result.getFile();
downloadedLicenseURLs.put( licenseUrl, licenseOutputFile );
licenseFileName = new File( license.getFile() ).getName();
}
else
{
handleError( depProject, result.getErrorMessage() );
licenseFileName = getLicenseFileName( depProject,
new URL( license.getUrl() ),
license.getName() );
}
licenseOutputFile = new File( licensesOutputDirectory, licenseFileName );
}

if ( !licenseOutputFile.exists() || forceDownload )
{
if ( !downloadedLicenseURLs.containsKey( licenseUrl ) || organizeLicensesByDependencies )
{
final LicenseDownloadResult result =
licenseDownloader.downloadLicense( licenseUrl, proxyLoginPasswordEncoded,
licenseOutputFile, getLog() );

if ( result.isSuccess() )
{
licenseOutputFile = result.getFile();
downloadedLicenseURLs.put( licenseUrl, licenseOutputFile );
}
else
{
handleError( depProject, result.getErrorMessage() );
}

}
}

if ( licenseOutputFile != null )
{
license.setFile( licenseOutputFile.getName() );
}
}

if ( licenseOutputFile != null )
}
catch ( URISyntaxException e )
{
license.setFile( licenseOutputFile.getName() );
handleError( depProject, "POM for dependency " + depProject.toString()
+ " has an invalid license URL: " + licenseUrl );
}
catch ( FileNotFoundException e )
{
handleError( depProject, "POM for dependency " + depProject.toString()
+ " has a license URL that returns file not found: " + licenseUrl );
}
catch ( IOException e )
{
handleError( depProject, "Unable to retrieve license from URL '" + licenseUrl + "' for dependency '"
+ depProject.toString() + "': " + e.getMessage() );
}

}
catch ( URISyntaxException e )
{
handleError( depProject, "POM for dependency " + depProject.toString() + " has an invalid license URL: "
+ licenseUrl );
}
catch ( FileNotFoundException e )
{
handleError( depProject, "POM for dependency " + depProject.toString()
+ " has a license URL that returns file not found: " + licenseUrl );
}
catch ( IOException e )
{
handleError( depProject, "Unable to retrieve license from URL '" + licenseUrl + "' for dependency '"
+ depProject.toString() + "': " + e.getMessage() );
}

licenseIndex++;
}

}
Expand Down

0 comments on commit 1942da6

Please sign in to comment.