Skip to content

Commit

Permalink
Added logging of missing names, licenses and validating urls for POM …
Browse files Browse the repository at this point in the history
…files
  • Loading branch information
jaredsburrows committed Oct 21, 2017
1 parent e48167e commit 08dc12e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build.gradle
@@ -1,5 +1,5 @@
plugins {
id "com.gradle.build-scan" version "1.9"
id "com.gradle.build-scan" version "1.10"
id "com.github.kt3k.coveralls" version "2.8.2"
id "com.jfrog.artifactory" version "4.4.18"
id "com.jfrog.bintray" version "1.7.3"
Expand Down
14 changes: 10 additions & 4 deletions src/main/groovy/com/jaredsburrows/license/LicenseReportTask.groovy
Expand Up @@ -91,7 +91,8 @@ class LicenseReportTask extends DefaultTask {

// Iterate through all POMs in order from our custom POM configuration
project.configurations."$POM_CONFIGURATION".resolvedConfiguration.lenientConfiguration.artifacts.each { pom ->
final text = new XmlParser().parse(pom.file)
final pomFile = pom.file
final text = new XmlParser().parse(pomFile)

// Parse POM file
def name = text.name?.text() ? text.name?.text() : text.artifactId?.text()
Expand All @@ -110,6 +111,12 @@ class LicenseReportTask extends DefaultTask {
licenseName = licenseName?.trim()
licenseURL = licenseURL?.trim()

// If the POM is missing a name, do not record it
if (!name) {
logger.log(LogLevel.WARN, String.format("POM file is missing a name: %s", pomFile))
return
}

// For all "com.android.support" libraries, use Apache 2
if (!licenseName || !licenseURL) {
logger.log(LogLevel.INFO, String.format("Project, %s, has no license in POM file.", name))
Expand All @@ -118,17 +125,16 @@ class LicenseReportTask extends DefaultTask {
licenseName = APACHE_LICENSE_NAME
licenseURL = APACHE_LICENSE_URL
} else {
logger.log(LogLevel.WARN, String.format("%s dependency does not have a license.", name))
return
}
}

// If the POM is missing a name, do not record it
if (!name) return

// If the POM is missing a license, do not record it
try {
new URL(licenseURL)
} catch (Exception ignore) {
logger.log(LogLevel.WARN, String.format("%s dependency does not have a valid license URL.", name))
return
}

Expand Down

0 comments on commit 08dc12e

Please sign in to comment.