Skip to content

Commit

Permalink
Merge pull request #222 from ppalaga/i195
Browse files Browse the repository at this point in the history
Fix #195 License names with slashes generate illegal filenames when in
  • Loading branch information
ppalaga committed Feb 1, 2019
2 parents ef027fc + 0b934cd commit 2f86e23
Show file tree
Hide file tree
Showing 12 changed files with 151 additions and 60 deletions.
1 change: 1 addition & 0 deletions src/it/ISSUE-195/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invoker.goals = clean license:download-licenses -Dlicense.organizeLicensesByDependencies=true
53 changes: 53 additions & 0 deletions src/it/ISSUE-195/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.codehaus.mojo.license</groupId>
<artifactId>ISSUE-195</artifactId>
<version>1.0-SNAPSHOT</version>
<name>Integration Test ISSUE-195</name>
<url>http://maven.apache.org</url>
<description>
ISSUE-195
</description>

<dependencies>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>javax.activation-api</artifactId>
<version>1.2.0</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>license-maven-plugin</artifactId>
<version>@pom.version@</version>
<executions>
<execution>
<goals>
<goal>download-licenses</goal>
</goals>
</execution>
</executions>
<configuration>
<licenseUrlReplacements>
<licenseUrlReplacement>
<regexp>https://github.com/javaee/activation/blob/master/LICENSE.txt</regexp>
<replacement>https://raw.githubusercontent.com/javaee/activation/master/LICENSE.txt</replacement>
</licenseUrlReplacement>
</licenseUrlReplacements>
</configuration>
</plugin>
</plugins>
</build>
</project>
25 changes: 25 additions & 0 deletions src/it/ISSUE-195/postbuild.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* #%L
* License Maven Plugin
* %%
* Copyright (C) 2008 - 2011 CodeLutin, Codehaus, Tony Chemit, Tony chemit
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>.
* #L%
*/

assert new File(basedir, 'target/generated-resources/licenses.xml').exists()
assert new File(basedir, 'target/generated-resources/licenses/commons-logging.commons-logging_apache_license_2.0.txt').exists()
assert new File(basedir, 'target/generated-resources/licenses/javax.activation.javax.activation-api_cddl_gplv2+ce.txt').exists()
14 changes: 14 additions & 0 deletions src/it/ISSUE-195/src/license/licenses.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<licenseSummary>
<dependencies>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<licenses>
<license>
<name>Apache License 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
</license>
</licenses>
</dependency>
</dependencies>
</licenseSummary>
15 changes: 15 additions & 0 deletions src/it/ISSUE-195/src/main/java/org/codehaus/mojo/HelloWorld.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.codehaus.mojo;

public class HelloWorld
{

/**
* @param args
*/
public static void main( String[] args )
{
// TODO Auto-generated method stub

}

}
2 changes: 1 addition & 1 deletion src/it/PR-32/child1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<licenses>
<license>
<name>LGPL 3.0</name>
<url>http://jaxx.nuiton.org/v/latest/license.html</url>
<url>https://www.gnu.org/licenses/lgpl-3.0.txt</url>
</license>
</licenses>

Expand Down
38 changes: 7 additions & 31 deletions src/it/PR-32/postbuild.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -19,36 +19,12 @@
* <http://www.gnu.org/licenses/lgpl-3.0.html>.
* #L%
*/
def assertExistsFile(file)
{
if ( !file.exists() || file.isDirectory() )
{
println(file.getAbsolutePath() + " file is missing or a directory.")
assert false
}
assert true
}

def assertContains(file, content, expected)
{
if ( !content.contains(expected) )
{
println(expected + " was not found in file [" + file + "]\n :" + content)
return false
}
return true
}
def lgpl3 = new File(basedir, 'child2/target/generated-resources/licenses/lgpl 3.0 - lgpl-3.0.txt')
assert lgpl3.exists()
assert lgpl3.text.contains('GNU LESSER GENERAL PUBLIC LICENSE');

file = new File(basedir, 'child2/target/generated-resources/licenses/lgpl 3.0 - license.html');
assertExistsFile(file);

content = file.text;
assert assertContains(file, content, 'http://jaxx.nuiton.org/index.html');

file = new File(basedir, 'child2/target/generated-resources/licenses.xml');
assertExistsFile(file);

content = file.text;
assert assertContains(file, content, '<url>http://jaxx.nuiton.org/v/latest/license.html</url>');

return true;
def licensesXml = new File(basedir, 'child2/target/generated-resources/licenses.xml');
assert licensesXml.exists()
assert licensesXml.text.contains('<file>lgpl 3.0 - lgpl-3.0.txt</file>')
assert licensesXml.text.contains('<url>https://www.gnu.org/licenses/lgpl-3.0.txt</url>')
4 changes: 2 additions & 2 deletions src/it/PR-33/child1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
<artifactId>PR-33-child1</artifactId>
<licenses>
<license>
<name>LGPL 3.0</name>
<url>http://jaxx.nuiton.org/v/latest/license.html</url>
<name>LGPL 2.1</name>
<url>https://www.gnu.org/licenses/lgpl-2.1.txt</url>
</license>
</licenses>

Expand Down
2 changes: 1 addition & 1 deletion src/it/PR-33/child2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<licenses>
<license>
<name>LGPL 3.0</name>
<url>http://nuiton-config.nuiton.org/v/latest/license.html</url>
<url>https://www.gnu.org/licenses/lgpl-3.0.txt</url>
</license>
</licenses>
</project>
29 changes: 12 additions & 17 deletions src/it/PR-33/postbuild.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,18 @@ def assertContains(file, content, expected) {
return true
}

file = new File(basedir, 'child3/target/generated-resources/licenses/org.codehaus.mojo.license.test.pr-33-child1_lgpl_3.0.html');
assertExistsFile(file);

content = file.text;
assert assertContains(file, content, 'http://jaxx.nuiton.org/index.html');
def lgpl3 = new File(basedir, 'child3/target/generated-resources/licenses/org.codehaus.mojo.license.test.pr-33-child1_lgpl_2.1.txt')
assert lgpl3.exists()
assert lgpl3.text.contains('Version 2.1, February 1999');

file = new File(basedir, 'child3/target/generated-resources/licenses/org.codehaus.mojo.license.test.pr-33-child2_lgpl_3.0.html');
assertExistsFile(file);
def lgpl21 = new File(basedir, 'child3/target/generated-resources/licenses/org.codehaus.mojo.license.test.pr-33-child2_lgpl_3.0.txt')
assert lgpl21.exists()
assert lgpl21.text.contains('Version 3, 29 June 2007');

content = file.text;
assert assertContains(file, content, 'nuiton-config');

file = new File(basedir, 'child3/target/generated-resources/licenses.xml');
assertExistsFile(file);

content = file.text;
assert assertContains(file, content, '<url>http://jaxx.nuiton.org/v/latest/license.html</url>');
assert assertContains(file, content, '<url>http://nuiton-config.nuiton.org/v/latest/license.html</url>');

return true;
def licensesXml = new File(basedir, 'child3/target/generated-resources/licenses.xml');
assert licensesXml.exists()
assert licensesXml.text.contains('<file>org.codehaus.mojo.license.test.pr-33-child1_lgpl_2.1.txt</file>')
assert licensesXml.text.contains('<url>https://www.gnu.org/licenses/lgpl-2.1.txt</url>')
assert licensesXml.text.contains('<file>org.codehaus.mojo.license.test.pr-33-child2_lgpl_3.0.txt</file>')
assert licensesXml.text.contains('<url>https://www.gnu.org/licenses/lgpl-3.0.txt</url>')
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.SortedMap;
Expand Down Expand Up @@ -737,16 +738,15 @@ private String getLicenseFileName( ProjectLicenseInfo depProject, final URL lice
licenseFileName = String.format( "%s.%s%s", depProject.getGroupId(), depProject.getArtifactId(),
licenseName != null
? "_" + licenseName
: "" ).toLowerCase().replaceAll( "\\s+", "_" );
: "" ).replaceAll( "\\s+", "_" );
}
else
{
licenseFileName = licenseUrlFile.getName();

if ( licenseName != null )
{
licenseFileName = licenseName.replaceAll( "/", "_" )
+ " - " + licenseUrlFile.getName();
licenseFileName = licenseName + " - " + licenseUrlFile.getName();
}

// Check if the file has a valid file extention
Expand All @@ -756,10 +756,11 @@ private String getLicenseFileName( ProjectLicenseInfo depProject, final URL lice
// This means it isn't a valid file extension, so append the default
licenseFileName = licenseFileName + defaultExtension;
}

// Force lower case so we don't end up with multiple copies of the same license
licenseFileName = licenseFileName.toLowerCase();
}

// lower case and (back)slash removal
licenseFileName = licenseFileName.toLowerCase( Locale.US ).replaceAll( "[\\\\/]+", "_" );

return licenseFileName;
}

Expand Down Expand Up @@ -811,7 +812,7 @@ private void downloadLicenses( ProjectLicenseInfo depProject )
if ( !downloadedLicenseURLs.containsKey( licenseUrl ) || organizeLicensesByDependencies )
{
licenseOutputFile = LicenseDownloader.downloadLicense( licenseUrl, proxyLoginPasswordEncoded,
licenseOutputFile );
licenseOutputFile, getLog() );
downloadedLicenseURLs.put( licenseUrl, licenseOutputFile );
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import java.net.URL;
import java.net.URLConnection;

import org.apache.maven.plugin.logging.Log;

/**
* Utilities for downloading remote license files.
*
Expand All @@ -54,10 +56,11 @@ public class LicenseDownloader
* @param licenseUrlString the URL
* @param loginPassword the credentials part for the URL, can be {@code null}
* @param outputFile a hint where to store the license file
* @param log
* @return the path to the file where the downloaded license file was stored
* @throws IOException
*/
public static File downloadLicense( String licenseUrlString, String loginPassword, File outputFile )
public static File downloadLicense( String licenseUrlString, String loginPassword, File outputFile, Log log )
throws IOException
{
if ( licenseUrlString == null || licenseUrlString.length() == 0 )
Expand All @@ -72,6 +75,8 @@ public static File downloadLicense( String licenseUrlString, String loginPasswor
{
int status = ( (HttpURLConnection) connection ).getResponseCode();

log.debug( String.format( "Got HTTP response %d for URL '%s'", status, licenseUrlString ) );

redirect = HttpURLConnection.HTTP_MOVED_TEMP == status || HttpURLConnection.HTTP_MOVED_PERM == status
|| HttpURLConnection.HTTP_SEE_OTHER == status;
}
Expand All @@ -84,6 +89,12 @@ public static File downloadLicense( String licenseUrlString, String loginPasswor
// open the new connnection again
connection = newConnection( newUrl, loginPassword );

if ( connection instanceof HttpURLConnection )
{
int status = ( (HttpURLConnection) connection ).getResponseCode();
log.debug( String.format( "Got HTTP response %d for URL '%s'", status, licenseUrlString ) );
}

}

try ( InputStream licenseInputStream = connection.getInputStream() )
Expand Down

0 comments on commit 2f86e23

Please sign in to comment.