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

Fix #233 Follow redirects more than once #234

Merged
merged 1 commit into from
Feb 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading