Skip to content

Commit

Permalink
Fix #233 Follow redirects more than once
Browse files Browse the repository at this point in the history
  • Loading branch information
ppalaga committed Feb 5, 2019
1 parent dbc3392 commit e2860a9
Show file tree
Hide file tree
Showing 7 changed files with 195 additions and 83 deletions.
5 changes: 5 additions & 0 deletions pom.xml
Expand Up @@ -294,6 +294,11 @@
<version>2.3.20</version>
</dependency>

<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>

<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion src/it/download-licenses-force/invoker.properties
@@ -1 +1 @@
invoker.goals = clean license:download-licenses -Dlicense.forceDownload=true -Dlicense.errorRemedy=xmlOutput
invoker.goals = clean license:download-licenses -Dlicense.forceDownload=true -Dlicense.errorRemedy=xmlOutput -Dlicense.sortByGroupIdAndArtifactId=true
13 changes: 13 additions & 0 deletions src/it/download-licenses-force/licenses.expected.xml
Expand Up @@ -13,5 +13,18 @@
</license>
</licenses>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-search-parent</artifactId>
<version>5.10.3.Final</version>
<licenses>
<license>
<name>GNU Lesser General Public License v2.1 or later</name>
<url>http://www.opensource.org/licenses/LGPL-2.1</url>
<file>gnu lesser general public license v2.1 or later - lgpl-2.1.txt.html</file>
<comments>See also: http://hibernate.org/license</comments>
</license>
</licenses>
</dependency>
</dependencies>
</licenseSummary>
12 changes: 12 additions & 0 deletions src/it/download-licenses-force/pom.xml
Expand Up @@ -24,6 +24,18 @@
<artifactId>groovy-all</artifactId>
<version>1.0-jsr-04</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-search-parent</artifactId>
<type>pom</type>
<version>5.10.3.Final</version>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

<build>
Expand Down
4 changes: 4 additions & 0 deletions src/it/download-licenses-force/postbuild.groovy
Expand Up @@ -30,6 +30,10 @@ assert Files.exists(asl2)
assert !asl2.text.contains('This content is fake.')
assert asl2.text.contains('Version 2.0, January 2004')

final Path lgpl21 = basePath.resolve('target/generated-resources/licenses/gnu lesser general public license v2.1 or later - lgpl-2.1.txt.html')
assert Files.exists(lgpl21)
assert lgpl21.text.contains('Version 2.1, February 1999')

final Path expectedLicensesXml = basePath.resolve('licenses.expected.xml')
final Path licensesXml = basePath.resolve('target/generated-resources/licenses.xml')
assert expectedLicensesXml.text.equals(licensesXml.text)
Expand Down
Expand Up @@ -38,6 +38,7 @@
import org.codehaus.mojo.license.model.ProjectLicenseInfo;
import org.codehaus.mojo.license.utils.FileUtil;
import org.codehaus.mojo.license.utils.LicenseDownloader;
import org.codehaus.mojo.license.utils.LicenseDownloader.LicenseDownloadResult;
import org.codehaus.mojo.license.utils.LicenseSummaryReader;
import org.codehaus.mojo.license.utils.LicenseSummaryWriter;
import org.codehaus.mojo.license.utils.MojoHelper;
Expand All @@ -47,7 +48,7 @@
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.charset.Charset;
import java.nio.file.Path;
Expand Down Expand Up @@ -458,28 +459,37 @@ public void execute()
// The resulting list of licenses after dependency resolution
List<ProjectLicenseInfo> depProjectLicenses = new ArrayList<>();

for ( MavenProject project : dependencies )
try ( LicenseDownloader licenseDownloader = new LicenseDownloader() )
{
Artifact artifact = project.getArtifact();
getLog().debug( "Checking licenses for project " + artifact );
String artifactProjectId = getArtifactProjectId( artifact );
ProjectLicenseInfo depProject;
if ( configuredDepLicensesMap.containsKey( artifactProjectId ) )
for ( MavenProject project : dependencies )
{
depProject = configuredDepLicensesMap.get( artifactProjectId );
depProject.setVersion( artifact.getVersion() );
}
else
{
depProject = createDependencyProject( project );
}
if ( !offline )
{
downloadLicenses( depProject );
Artifact artifact = project.getArtifact();
getLog().debug( "Checking licenses for project " + artifact );
String artifactProjectId = getArtifactProjectId( artifact );
ProjectLicenseInfo depProject;
if ( configuredDepLicensesMap.containsKey( artifactProjectId ) )
{
depProject = configuredDepLicensesMap.get( artifactProjectId );
depProject.setVersion( artifact.getVersion() );
}
else
{
depProject = createDependencyProject( project );
}
if ( !offline )
{
downloadLicenses( licenseDownloader, depProject );
}
depProjectLicenses.add( depProject );
}
depProjectLicenses.add( depProject );
}
catch ( Exception e )
{
throw new RuntimeException( e );
}



try
{
if ( sortByGroupIdAndArtifactId )
Expand Down Expand Up @@ -867,7 +877,8 @@ private String getLicenseFileName( ProjectLicenseInfo depProject, final URL lice
* @param depProject The project which generated the dependency
* @throws MojoFailureException
*/
private void downloadLicenses( ProjectLicenseInfo depProject ) throws MojoFailureException
private void downloadLicenses( LicenseDownloader licenseDownloader, ProjectLicenseInfo depProject )
throws MojoFailureException
{
getLog().debug( "Downloading license(s) for project " + depProject );

Expand Down Expand Up @@ -906,9 +917,20 @@ private void downloadLicenses( ProjectLicenseInfo depProject ) throws MojoFailur
{
if ( !downloadedLicenseURLs.containsKey( licenseUrl ) || organizeLicensesByDependencies )
{
licenseOutputFile = LicenseDownloader.downloadLicense( licenseUrl, proxyLoginPasswordEncoded,
licenseOutputFile, getLog() );
downloadedLicenseURLs.put( licenseUrl, licenseOutputFile );
final LicenseDownloadResult result =
licenseDownloader.downloadLicense( licenseUrl, proxyLoginPasswordEncoded, licenseOutputFile,
getLog() );

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

}
}

Expand All @@ -918,7 +940,7 @@ private void downloadLicenses( ProjectLicenseInfo depProject ) throws MojoFailur
}

}
catch ( MalformedURLException e )
catch ( URISyntaxException e )
{
handleError( depProject, "POM for dependency " + depProject.toString() + " has an invalid license URL: "
+ licenseUrl );
Expand Down

0 comments on commit e2860a9

Please sign in to comment.