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 missing override for InventoryReportRenderer #304

Merged
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
7 changes: 4 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up JDK 11
uses: actions/setup-java@v2
uses: actions/setup-java@v4
with:
java-version: '11'
distribution: 'adopt'
Expand All @@ -24,7 +24,8 @@ jobs:
- name: Build with Gradle
run: ./gradlew test
- name: Unit tests results
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
if: always()
with:
name: unit-tests-results
path: build/reports/tests/test
6 changes: 5 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ dependencies {
implementation localGroovy()

testImplementation gradleTestKit()
testImplementation('org.spockframework:spock-core:2.1-groovy-3.0') {
testImplementation('org.spockframework:spock-core:2.4-M4-groovy-3.0') {
exclude group: 'org.codehaus.groovy'
}
}
Expand All @@ -39,6 +39,10 @@ test {
showStandardStreams = true
exceptionFormat = 'full'
}
systemProperty("spock.snapshots.rootPath", "src/test/resources")
systemProperty("spock.snapshots.updateSnapshots", !System.getenv("CI"))
systemProperty("spock.snapshots.writeActualSnapshotOnMismatch", !System.getenv("CI"))

outputs.upToDateWhen { false }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.jk1.license.render
package com.github.jk1.license.render

import com.github.jk1.license.*
import com.github.jk1.license.util.Files
Expand All @@ -29,7 +29,7 @@ class InventoryReportRenderer implements ReportRenderer {
protected int counter
protected File overridesFile
protected boolean isInitialized = false
private Map<String, Map<String, String>> overrides = [:]
private Map<String, Map<String, String>> _overrides = [:]

InventoryReportRenderer(String fileName = 'licenses.txt', String name = null, File overridesFile = null) {
this.name = name
Expand All @@ -45,14 +45,14 @@ class InventoryReportRenderer implements ReportRenderer {

Map<String, Map<String, String>> getOverrides() {
parseOverrides(overridesFile)
return this.overrides
return _overrides
}

@Override
void render(ProjectData data) {
project = data.project
if( name == null ) name = project.name
config = project.licenseReport
if (name == null) name = project.name
config = (LicenseReportExtension) project.extensions.getByName("licenseReport")
output = new File(config.absoluteOutputDir, fileName)
output.delete() // clear old output
def inventory = buildLicenseInventory(data)
Expand All @@ -61,23 +61,23 @@ class InventoryReportRenderer implements ReportRenderer {

}

protected synchronized Map<String, Map<String, String>> parseOverrides(File file) {
protected synchronized void parseOverrides(File file) {
if (isInitialized) {
return
}
isInitialized = true
overrides = [:]
Map<String, Map<String, String>> overrideMap = [:]
if (file) {
file.withReader { Reader reader ->
String line
while ((line = reader.readLine()) != null) {
String[] columns = line.split(/\|/)
String groupNameVersion = columns[0]
overrides[groupNameVersion] = [projectUrl: safeGet(columns, 1), license: safeGet(columns, 2), licenseUrl: safeGet(columns, 3)]
overrideMap[groupNameVersion] = [projectUrl: safeGet(columns, 1), license: safeGet(columns, 2), licenseUrl: safeGet(columns, 3)]
}
}
}
return overrides
_overrides = overrideMap
isInitialized = true
}

protected Map<String, List<ModuleData>> buildLicenseInventory(ProjectData data) {
Expand Down Expand Up @@ -238,7 +238,7 @@ class InventoryReportRenderer implements ReportRenderer {
}
}

protected printDependencyLicenseFiles(TreeSet<LicenseFileData> licenseFiles) {
protected printDependencyLicenseFiles(Set<LicenseFileData> licenseFiles) {
output << " - Embedded license files: \n - " + licenseFiles.first().fileDetails.collect {
it.file
}.unique().join(' \n - ')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,13 @@ class ProjectDataFixture {

static License APACHE2_LICENSE() {
new License(
name: "Apache License, Version 2.0",
url: "https://www.apache.org/licenses/LICENSE-2.0"
name: "Apache License, Version 2.0",
url: "https://www.apache.org/licenses/LICENSE-2.0"
)
}
static License UNKNOWN_LICENSE() {
new License(
name: "Unknown"
)
}
static License MIT_LICENSE() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
* Copyright 2018 Evgeny Naumenko <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.jk1.license.render

import com.github.jk1.license.LicenseReportExtension
import com.github.jk1.license.ProjectBuilder
import com.github.jk1.license.ProjectData
import spock.lang.Snapshot
import spock.lang.Snapshotter
import spock.lang.Specification
import spock.lang.TempDir

import static com.github.jk1.license.ProjectDataFixture.*

class AbstractInventoryReportRendererSpec extends Specification {

@Snapshot
Snapshotter snapshotter
@TempDir
File testProjectDir
File outputFile
File overrides

ProjectBuilder builder = new ProjectBuilder()
ProjectData projectData

def setup() {
outputFile = new File(testProjectDir, "output")
outputFile.delete()
overrides = new File(testProjectDir, "overrides.txt")
overrides.text = "dummy-group:mod2:0.0.1|https://projecturl|Apache License, Version 2.0|http://www.apache.org/licenses/LICENSE-2.0.txt"

LicenseReportExtension extension = GRADLE_PROJECT().licenseReport
extension.outputDir = testProjectDir

// copy apache2 license file
def apache2LicenseFile = new File(getClass().getResource('/apache2.license').toURI())
new File(testProjectDir, "apache2.license") << apache2LicenseFile.text

projectData = builder.project {
configurations(["runtime", "test"]) { configName ->
configuration(configName) {
module("mod1") {
pom("pom1") {
license(APACHE2_LICENSE(), url: "https://www.apache.org/licenses/LICENSE-2.0")
}
licenseFiles {
licenseFileDetails(file: "apache2.license", license: "Apache License, Version 2.0", licenseUrl: "https://www.apache.org/licenses/LICENSE-2.0")
}
manifest("mani1") {
license("Apache 2.0")
}
}
module("mod2") {
pom("pom2") {
license(UNKNOWN_LICENSE())
}
}
module("mod3") {
pom("pom3") {
license(UNKNOWN_LICENSE())
}
}

module("mod4") {
pom("pom2") {
license(APACHE2_LICENSE())
}
pom("pom3") {
license(APACHE2_LICENSE())
license(MIT_LICENSE())
}
licenseFiles {
licenseFileDetails(file: "apache2.license", license: "Apache License, Version 2.0", licenseUrl: "https://www.apache.org / licenses / LICENSE - 2.0 ")
}
manifest("mani1") {
license("Apache 2.0")
}
}
}

importedModulesBundle("bundle1") {
importedModule(name: "mod1", license: "Apache 2", licenseUrl: "apache-url")
importedModule(name: "mod2", license: "Apache 2", licenseUrl: "apache-url")
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright 2018 Evgeny Naumenko <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.jk1.license.render

class InventoryHtmlReportRendererSpec extends AbstractInventoryReportRendererSpec {

def "check the correct generation of html"() {
def renderer = new InventoryHtmlReportRenderer(outputFile.name, "name", overrides)

when:
renderer.render(projectData)

then:
outputFile.exists()
def sanitizedOutput = outputFile.text.replaceAll("<em>[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2} [A-Z0-9-]+</em>", "DATE")
snapshotter.assertThat(sanitizedOutput).matchesSnapshot()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2018 Evgeny Naumenko <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.jk1.license.render

class InventoryMarkdownReportRendererSpec extends AbstractInventoryReportRendererSpec {

def "check the correct generation of markdown"() {
def renderer = new InventoryMarkdownReportRenderer(outputFile.name, "name", overrides)
when:
renderer.render(projectData)
then:
outputFile.exists()
def sanitizedOutput = outputFile.text.replaceAll("_[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2} [A-Z0-9-]+_", "DATE")
snapshotter.assertThat(sanitizedOutput).matchesSnapshot()
}
}
Loading
Loading