Skip to content

Commit

Permalink
Merge branch 'release/4.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
chrimaeon committed Mar 20, 2022
2 parents d54488f + 1ba0ec6 commit 44fc2f9
Show file tree
Hide file tree
Showing 17 changed files with 165 additions and 151 deletions.
1 change: 1 addition & 0 deletions .github/workflows/create_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jobs:
- name: Create Release Notes
run: ./gradlew --quiet getChangelog --no-header > ./RELEASE_NOTES.md
- name: Create Release
id: create_release
uses: chrimaeon/github-create-release-action@0.2.0
env:
GITHUB_TOKEN: ${{ github.token }}
Expand Down
2 changes: 1 addition & 1 deletion .idea/copyright/CMG_Apps.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 12 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,29 @@

### Security

## [4.1.0]
## [4.2.0]
### Added
- XSD Schema for the XML reporter

### Changed
- Sort dependencies by name and version
- XML Schema changed
- `<version>` is now attribute to `<library>`
- `<url>` is now a attribute to `<license>`
- `<library>` has an `id` attribute now

### Deprecated

### Removed

### Fixed
- HTML Reports includes all libraries again

### Security

## [4.1.0]
### Changed
- Sort dependencies by name and version

## [4.0.0]
### Added
- Kotlin Multiplatform support
Expand All @@ -50,4 +59,4 @@
## [3.1.0]
### Changed
- All public properties are now provided Properties
- Use Kotlin Serialization instead of Moshi
- Use Kotlin Serialization instead of Moshi
16 changes: 3 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Using the plugins DSL

```groovy
plugins {
id "com.cmgapps.licenses" version "4.1.0"
id "com.cmgapps.licenses" version "4.2.0"
}
```

Expand All @@ -26,7 +26,7 @@ buildscript {
}
dependencies {
classpath("com.cmgapps:gradle-licenses-plugin:4.1.0")
classpath("com.cmgapps:gradle-licenses-plugin:4.2.0")
}
}
Expand Down Expand Up @@ -124,17 +124,7 @@ licenses {
```text
Copyright (c) 2018. Christian Grach <christian.grach@cmgapps.com>
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.
SPDX-License-Identifier: Apache-2.0
```

[TextResource]: https://docs.gradle.org/current/dsl/org.gradle.api.resources.TextResource.html
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Deps.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ object Deps {
const val versionsVersion = "0.40.0"
}

const val androidGradlePlugin = "com.android.tools.build:gradle:7.0.4"
const val androidGradlePlugin = "com.android.tools.build:gradle:7.1.2"
const val kotlinMultiplatformPlugin = "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
const val apacheCommonsCsv = "org.apache.commons:commons-csv:1.9.0"
const val mavenModel = "org.apache.maven:maven-model:3.8.4"
Expand Down
13 changes: 2 additions & 11 deletions example/kotlin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
/*
* Copyright (c) 2019. Christian Grach <christian.grach@cmgapps.com>
*
* 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.
* SPDX-License-Identifier: Apache-2.0
*/

plugins {
Expand All @@ -36,6 +26,7 @@ licenses {
destination = buildDir.resolve("reports").resolve("licenses.txt")
generate { list -> list.map { it.name }.joinToString() }
}
xml.enabled = true
}
}

Expand Down
2 changes: 1 addition & 1 deletion pom.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# limitations under the License.
#
group=com.cmgapps
versionName=4.1.0
versionName=4.2.0
pomName=Gradle Licenses Plugin
pomArtifactId=gradle-licenses-plugin
pomDescription=Gradle plugin that provides a task to generate a license report of your project.
Expand Down
7 changes: 6 additions & 1 deletion src/main/kotlin/com/cmgapps/license/reporter/HtmlReport.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ internal class HtmlReport(

libraries.forEach { library ->
library.licenses.forEach { license ->
licenseListMap[license] ?: mutableListOf<Library>().also { licenseListMap[license] = it }.add(library)
val licenseList = licenseListMap[license]
if (licenseList == null) {
licenseListMap[license] = mutableListOf(library)
} else {
licenseList.add(library)
}
}
}

Expand Down
49 changes: 24 additions & 25 deletions src/main/kotlin/com/cmgapps/license/reporter/XmlReport.kt
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
/*
* Copyright (c) 2019. Christian Grach <christian.grach@cmgapps.com>
*
* 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.
* SPDX-License-Identifier: Apache-2.0
*/

package com.cmgapps.license.reporter
Expand All @@ -21,39 +11,45 @@ internal class XmlReport(libraries: List<com.cmgapps.license.model.Library>) : R
override fun generate(): String {
return libraries {
for (library in libraries) {
library {
library(
id = "${library.name} ${library.version}".replace(whitespaceRegex, "_"),
version = library.version.toString()
) {
name {
+library.name
}
version {
+(library.version.toString())
}

description {
+(library.description ?: "")
}

licenses {
for (license in library.licenses) {
license {
license(url = license.url) {
name {
+license.name
}
url {
+license.url
}
}
}
}
}
}
}.toString()
}

companion object {
private val whitespaceRegex = "\\s".toRegex()
}
}

internal class Libraries : Tag("libraries") {

fun library(init: Library.() -> Unit) = initTag(Library(), init)
fun library(id: String, version: String, init: Library.() -> Unit): Library {
val tag = initTag(Library(), init)
tag.attributes["id"] = id
tag.attributes["version"] = version
return tag
}

override fun render(builder: StringBuilder, intent: String, format: Boolean) {
builder.append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>")
Expand All @@ -66,7 +62,6 @@ internal class Libraries : Tag("libraries") {

internal class Library : Tag("library") {
fun name(init: Name.() -> Unit) = initTag(Name(), init)
fun version(init: Version.() -> Unit) = initTag(Version(), init)
fun description(init: Description.() -> Unit) = initTag(Description(), init)
fun licenses(init: Licenses.() -> Unit) = initTag(Licenses(), init)
}
Expand All @@ -75,18 +70,22 @@ internal class Name : TagWithText("name")
internal class Version : TagWithText("version")
internal class Description : TagWithText("description")
internal class Licenses : Tag("licenses") {
fun license(init: License.() -> Unit) = initTag(License(), init)
fun license(url: String, init: License.() -> Unit) {
val tag = initTag(License(), init)
tag.attributes["url"] = url
}
}

internal class License : Tag("license") {
fun name(init: Name.() -> Unit) = initTag(Name(), init)
fun url(init: Url.() -> Unit) = initTag(Url(), init)
}

internal class Url : TagWithText("url")

internal fun libraries(init: Libraries.() -> Unit): Libraries {
val libraries = Libraries()
libraries.attributes["xmlns"] = "https://www.cmgapps.com"
libraries.attributes["xmlns:xsi"] = "http://www.w3.org/2001/XMLSchema-instance"
libraries.attributes["xsi:schemaLocation"] = "https://www.cmgapps.com https://www.cmgapps.com/xsd/licenses.xsd"

libraries.init()
return libraries
}
57 changes: 22 additions & 35 deletions src/test/kotlin/com/cmgapps/license/LicensesTaskShould.kt
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
/*
* Copyright (c) 2019. Christian Grach <christian.grach@cmgapps.com>
*
* 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.
* SPDX-License-Identifier: Apache-2.0
*/

package com.cmgapps.license
Expand Down Expand Up @@ -174,30 +164,27 @@ class LicensesTaskShould {
assertThat(
outputFile.readText(),
`is`(
"<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" +
"<libraries>\n" +
" <library>\n" +
" <name>\n" +
" Fake dependency name\n" +
" </name>\n" +
" <version>\n" +
" 1.0.0\n" +
" </version>\n" +
" <description>\n" +
" Fake dependency description\n" +
" </description>\n" +
" <licenses>\n" +
" <license>\n" +
" <name>\n" +
" Some license\n" +
" </name>\n" +
" <url>\n" +
" http://website.tld/\n" +
" </url>\n" +
" </license>\n" +
" </licenses>\n" +
" </library>\n" +
"</libraries>\n"
"""
<?xml version="1.0" encoding="UTF-8" ?>
<libraries xmlns="https://www.cmgapps.com" xsi:schemaLocation="https://www.cmgapps.com https://www.cmgapps.com/xsd/licenses.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<library id="Fake_dependency_name_1.0.0" version="1.0.0">
<name>
Fake dependency name
</name>
<description>
Fake dependency description
</description>
<licenses>
<license url="http://website.tld/">
<name>
Some license
</name>
</license>
</licenses>
</library>
</libraries>
""".trimIndent()
)
)
}
Expand Down
15 changes: 13 additions & 2 deletions src/test/kotlin/com/cmgapps/license/helper/LibrariesHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,19 @@ object LibrariesHelper {
License(
"MIT License",
"http://opensource.org/licenses/MIT"
)
)
),
),
),
Library(
"Test lib 2",
ComparableVersion("2.3.4"),
"descriptions of lib 2",
listOf(
License(
"Apache 2.0",
"http://www.apache.org/licenses/LICENSE-2.0.txt"
),
),
)
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ class CsvReportShould {
result,
`is`(
"Name,Version,Description,License Name,License Url\r\n" +
"Test lib 1,1.0,proper description,Apache 2.0,http://www.apache.org/licenses/LICENSE-2.0.txt\r\n"
"Test lib 1,1.0,proper description,Apache 2.0,http://www.apache.org/licenses/LICENSE-2.0.txt\r\n" +
"Test lib 2,2.3.4,descriptions of lib 2,Apache 2.0,http://www.apache.org/licenses/LICENSE-2.0.txt\r\n"
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class HtmlReportShould {
"<h3>Notice for packages:</h3>" +
"<ul>" +
"<li>Test lib 1</li>" +
"<li>Test lib 2</li>" +
"</ul>" +
"<pre>" +
getFileContent("apache-2.0.txt") +
Expand Down
11 changes: 11 additions & 0 deletions src/test/kotlin/com/cmgapps/license/reporter/JsonReportShould.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ class JsonReportShould {
"url": "http://opensource.org/licenses/MIT"
}
]
},
{
"name": "Test lib 2",
"version": "2.3.4",
"description": "descriptions of lib 2",
"licenses": [
{
"name": "Apache 2.0",
"url": "http://www.apache.org/licenses/LICENSE-2.0.txt"
}
]
}
]
""".trimIndent()
Expand Down
Loading

0 comments on commit 44fc2f9

Please sign in to comment.