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

support regex in aliases #167

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
11 changes: 9 additions & 2 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,15 @@ downloadLicenses {
]

aliases = [
(apacheTwo) : ['The Apache Software License, Version 2.0', 'Apache 2', 'Apache License Version 2.0', 'Apache License, Version 2.0', 'Apache License 2.0', license('Apache License', 'http://www.apache.org/licenses/LICENSE-2.0')],
(bsd) : ['BSD', license('New BSD License', 'http://www.opensource.org/licenses/bsd-license.php')]
(apacheTwo) : [ 'The Apache Software License, Version 2.0',
'Apache 2', 'Apache License Version 2.0',
'/Apache License,? [Vv]ersion 2.0/', // Regex are supported when alias is surrounded by forward slashes
'Apache License 2.0',
license('Apache License', 'http://www.apache.org/licenses/LICENSE-2.0')
],
(bsd) : [ 'BSD', license('New BSD License',
'http://www.opensource.org/licenses/bsd-license.php')
]
]

excludeDependencies = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class LicenseResolver {
aliasEntry.value.any {
aliasElem ->
if (aliasElem instanceof String) {
return aliasElem == licenseMetadata.licenseName
return aliasElem[0,-1] != '//' ? licenseMetadata.licenseName == aliasElem : licenseMetadata.licenseName.matches(aliasElem[1..-2])
} else if(aliasElem instanceof LicenseMetadata) {
return aliasElem == licenseMetadata
}
Expand Down Expand Up @@ -266,7 +266,7 @@ class LicenseResolver {
aliasEntry.value.any {
aliasElem ->
if (aliasElem instanceof String) {
return aliasElem == license.licenseName
return aliasElem[0,-1] != '//' ? license.licenseName == aliasElem : license.licenseName.matches(aliasElem[1..-2])
} else if(aliasElem instanceof LicenseMetadata) {
return aliasElem == license
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,55 @@ class DownloadLicensesIntegTest extends Specification {
dependencyWithLicenseUrlPresent(xmlByDependency, "testDependency3.jar", "MY_URL")
}

def "Test that aliases supports regex"() {
setup:
File dependencyJar1 = new File(projectDir, "testDependency1.jar")
dependencyJar1.createNewFile()

File dependencyJar2 = new File(projectDir, "testDependency2.jar")
dependencyJar2.createNewFile()

File dependencyJar3 = new File(projectDir, "testDependency3.jar")
dependencyJar3.createNewFile()

HashMap<Object, List> aliases = new HashMap()
aliases.put(license("The Apache Software License, Version 2.0", "MY_URL"), ["/Apache [23]/", "The Apache 2", "Apache"])
downloadLicenses.aliases = aliases

downloadLicenses.licenses = ["testDependency1.jar": license("Apache 3"),
"testDependency2.jar": license("The Apache 2"),
"testDependency3.jar": license("Apache")]

project.dependencies {
runtime project.files("testDependency1.jar")
runtime project.files("testDependency2.jar")
runtime project.files("testDependency3.jar")
}

when:
downloadLicenses.execute()

then:
File f = getLicenseReportFolder()
assertLicenseReportsExist(f)

def xmlByDependency = xml4LicenseByDependencyReport(f)
def xmlByLicense = xml4DependencyByLicenseReport(f)

dependenciesInReport(xmlByDependency) == 3
licensesInReport(xmlByLicense) == 1

[email protected]() == "The Apache Software License, Version 2.0"
xmlByLicense.license.dependency.size() == 3

dependencyWithLicensePresent(xmlByDependency, "testDependency1.jar", "testDependency1.jar", "The Apache Software License, Version 2.0")
dependencyWithLicensePresent(xmlByDependency, "testDependency2.jar", "testDependency2.jar", "The Apache Software License, Version 2.0")
dependencyWithLicensePresent(xmlByDependency, "testDependency3.jar", "testDependency3.jar", "The Apache Software License, Version 2.0")
dependencyWithLicenseUrlPresent(xmlByDependency, "testDependency1.jar", "MY_URL")
dependencyWithLicenseUrlPresent(xmlByDependency, "testDependency2.jar", "MY_URL")
dependencyWithLicenseUrlPresent(xmlByDependency, "testDependency3.jar", "MY_URL")
}

def "Test that aliases can me mixed in mapping licenseMetadata/String->list<String/LicenseMetadata> mapping for file dependencies"() {
setup:
File dependencyJar1 = new File(projectDir, "testDependency1.jar")
Expand Down