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

Extra report info #44

Merged
merged 7 commits into from
Jun 14, 2018
Merged
Show file tree
Hide file tree
Changes from 5 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
27 changes: 25 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ Example `build.gradle`:
dependencies {
compile "com.android.support:design:26.1.0"
compile "pl.droidsonroids.gif:android-gif-drawable:1.2.3"
compile "wsdl4j:wsdl4j:1.5.1" // Very old library with no license info available
}
```

Expand All @@ -74,6 +75,10 @@ dependencies {
<body>
<h3>Notice for packages:</h3>
<ul>
<li>
<a href='#76480'>WSDL4J</a>
</li>
<pre>No license found</pre>
<li>
<a href='#-989315363'>Android GIF Drawable Library</a>
</li>
Expand Down Expand Up @@ -106,7 +111,8 @@ dependencies {
"license": "The MIT License",
"license_url": "http://opensource.org/licenses/MIT"
}
]
],
"dependency": "pl.droidsonroids.gif:android-gif-drawable:1.2.3"
},
{
"project": "Design",
Expand All @@ -122,11 +128,28 @@ dependencies {
"license": "The Apache Software License",
"license_url": "http://www.apache.org/licenses/LICENSE-2.0.txt"
}
]
],
"dependency": "com.android.support:design:26.1.0"
},
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The indentation here is wrong. :/

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

screen shot 2018-06-13 at 9 23 07 am

{
"project": "WSDL4J",
"description": "Java stub generator for WSDL",
"version": "1.5.1",
"developers": [

],
"url": "http://sf.net/projects/wsdl4j",
"year": null,
"licenses": [

],
"dependency": "wsdl4j:wsdl4j:1.5.1"
}
]
```

Note, if no license information is found for a component, the `licenses` element in the JSON output will be an empty array.

## Configuration
The plugin can be configured to generate specific reports and automatically copy the reports to the assets directory (Android projects only). The default behaviours are:
- Java projects: Generate both the HTML report and the JSON report.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class LicenseReportTask extends DefaultTask {
def licenses = findLicenses(pomFile)
if (!licenses) {
logger.log(LogLevel.WARN, "${name} dependency does not have a license.")
return
licenses = []
}

// Store the information that we need
Expand All @@ -162,7 +162,8 @@ class LicenseReportTask extends DefaultTask {
developers: developers,
licenses: licenses,
url: url,
year: year
year: year,
gav: pom.owner
)

projects << project
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ final class Project {
String url
List<Developer> developers
String year
String gav // Group/artifact/version
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ final class HtmlReport {
final static def CSS_STYLE = BODY_CSS + " " + PRE_CSS
final static def OPEN_SOURCE_LIBRARIES = "Open source licenses"
final static def NO_LIBRARIES = "None"
final static def NO_LICENSE = "No license found"
final static def NOTICE_LIBRARIES = "Notice for packages:"
final static def NO_URL = "N/A"
final List<Project> projects

HtmlReport(def projects) {
Expand All @@ -35,7 +37,12 @@ final class HtmlReport {

// Store packages by license
projects.each { project ->
def key = project.licenses[0]
def key = new License(name: NO_LICENSE, url: NO_URL)

if (project.licenses && project.licenses.size > 0) {
key = project.licenses[0]
}

if (!projectsMap.containsKey(key)) {
projectsMap.put(key, [])
}
Expand Down Expand Up @@ -73,7 +80,9 @@ final class HtmlReport {
// Display associated license with libraries
// Try to find license by URL, name and then default to whatever is listed in the POM.xml
def licenseMap = LicenseHelper.LICENSE_MAP
if (licenseMap.containsKey(entry.key.url)) {
if (!currentProject.licenses || currentProject.licenses.size == 0) {
pre(NO_LICENSE)
} else if (licenseMap.containsKey(entry.key.url)) {
a(name: currentLicense)
pre(getLicenseText(licenseMap.get(entry.key.url)))
} else if (licenseMap.containsKey(entry.key.name)) {
Expand All @@ -83,7 +92,7 @@ final class HtmlReport {
if (currentProject && (currentProject.licenses[0].name.trim() || currentProject.licenses[0].url.trim())) {
pre("${currentProject.licenses[0].name.trim()}\n${currentProject.licenses[0].url.trim()}")
} else {
pre(NO_LIBRARIES)
pre(NO_LICENSE)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ final class JsonReport {
private final static def LICENSE = "license"
private final static def LICENSE_URL = "license_url"
private final static def EMPTY_JSON_ARRAY = "[]"
private final static def DEPENDENCY = "dependency"
private final List<Project> projects

JsonReport(projects) {
Expand Down Expand Up @@ -45,7 +46,8 @@ final class JsonReport {
"$DEVELOPERS" : project.developers*.name,
"$URL" : project.url ? project.url : null,
"$YEAR" : project.year ? project.year : null,
"$LICENSES" : licensesJson
"$LICENSES" : licensesJson,
"$DEPENDENCY" : project.gav
]
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,35 @@ final class LicenseReportTaskAndroidSpec extends BaseAndroidSpecification {
<title>Open source licenses</title>
</head>
<body>
<h3>None</h3>
<h3>Notice for packages:</h3>
<ul>
<li>
<a href='#76480'>Firebase-core</a>
</li>
<pre>No license found</pre>
</ul>
</body>
</html>
""".stripIndent().trim()
def actualJson = task.jsonFile.text.stripIndent().trim()
def expectedJson =
"""
[]
[
{
"project": "Firebase-core",
"description": null,
"version": "10.0.1",
"developers": [

],
"url": null,
"year": null,
"licenses": [

],
"dependency": "com.google.firebase:firebase-core:10.0.1"
}
]
""".stripIndent().trim()

then:
Expand Down Expand Up @@ -186,7 +207,8 @@ final class LicenseReportTaskAndroidSpec extends BaseAndroidSpecification {
"license": "The Apache Software License",
"license_url": "http://www.apache.org/licenses/LICENSE-2.0.txt"
}
]
],
"dependency": "com.android.support:appcompat-v7:26.1.0"
},
{
"project": "Design",
Expand All @@ -202,7 +224,8 @@ final class LicenseReportTaskAndroidSpec extends BaseAndroidSpecification {
"license": "The Apache Software License",
"license_url": "http://www.apache.org/licenses/LICENSE-2.0.txt"
}
]
],
"dependency": "com.android.support:design:26.1.0"
}
]
""".stripIndent().trim()
Expand Down Expand Up @@ -285,7 +308,8 @@ final class LicenseReportTaskAndroidSpec extends BaseAndroidSpecification {
"license": "The Apache Software License",
"license_url": "http://www.apache.org/licenses/LICENSE-2.0.txt"
}
]
],
"dependency": "com.android.support:appcompat-v7:26.1.0"
},
{
"project": "Design",
Expand All @@ -301,7 +325,8 @@ final class LicenseReportTaskAndroidSpec extends BaseAndroidSpecification {
"license": "The Apache Software License",
"license_url": "http://www.apache.org/licenses/LICENSE-2.0.txt"
}
]
],
"dependency": "com.android.support:design:26.1.0"
}
]
""".stripIndent().trim()
Expand Down Expand Up @@ -404,7 +429,8 @@ final class LicenseReportTaskAndroidSpec extends BaseAndroidSpecification {
"license": "The Apache Software License",
"license_url": "http://www.apache.org/licenses/LICENSE-2.0.txt"
}
]
],
"dependency": "com.android.support:appcompat-v7:26.1.0"
},
{
"project": "Design",
Expand All @@ -420,7 +446,8 @@ final class LicenseReportTaskAndroidSpec extends BaseAndroidSpecification {
"license": "The Apache Software License",
"license_url": "http://www.apache.org/licenses/LICENSE-2.0.txt"
}
]
],
"dependency": "com.android.support:design:26.1.0"
},
{
"project": "Support-annotations",
Expand All @@ -436,7 +463,8 @@ final class LicenseReportTaskAndroidSpec extends BaseAndroidSpecification {
"license": "The Apache Software License",
"license_url": "http://www.apache.org/licenses/LICENSE-2.0.txt"
}
]
],
"dependency": "com.android.support:support-annotations:26.1.0"
},
{
"project": "Support-v4",
Expand All @@ -452,7 +480,8 @@ final class LicenseReportTaskAndroidSpec extends BaseAndroidSpecification {
"license": "The Apache Software License",
"license_url": "http://www.apache.org/licenses/LICENSE-2.0.txt"
}
]
],
"dependency": "com.android.support:support-v4:26.1.0"
}
]
""".stripIndent().trim()
Expand Down Expand Up @@ -533,7 +562,8 @@ final class LicenseReportTaskAndroidSpec extends BaseAndroidSpecification {
"license": "The MIT License",
"license_url": "http://opensource.org/licenses/MIT"
}
]
],
"dependency": "pl.droidsonroids.gif:android-gif-drawable:1.2.3"
},
{
"project": "Design",
Expand All @@ -549,7 +579,8 @@ final class LicenseReportTaskAndroidSpec extends BaseAndroidSpecification {
"license": "The Apache Software License",
"license_url": "http://www.apache.org/licenses/LICENSE-2.0.txt"
}
]
],
"dependency": "com.android.support:design:26.1.0"
}
]
""".stripIndent().trim()
Expand Down Expand Up @@ -732,7 +763,8 @@ http://website.tld/</pre>
"license": "The Apache Software License",
"license_url": "http://www.apache.org/licenses/LICENSE-2.0.txt"
}
]
],
"dependency": "com.android.support:design:26.1.0"
},
{
"project": "Fake dependency name",
Expand All @@ -748,7 +780,8 @@ http://website.tld/</pre>
"license": "Some license",
"license_url": "http://website.tld/"
}
]
],
"dependency": "group:name:1.0.0"
}
]
""".stripIndent().trim()
Expand Down
Loading