Skip to content

Commit

Permalink
Merge branch 'ms5' into 'alpha'
Browse files Browse the repository at this point in the history
Ms5

See merge request Griefed/ServerPackCreator!522
  • Loading branch information
Griefed committed Sep 16, 2023
2 parents b83ae74 + 4d2c382 commit da171ac
Show file tree
Hide file tree
Showing 15 changed files with 2,437 additions and 482 deletions.
46 changes: 0 additions & 46 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -456,49 +456,3 @@ SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGES.

END OF TERMS AND CONDITIONS

How to Apply These Terms to Your New Libraries

If you develop a new library, and you want it to be of the greatest
possible use to the public, we recommend making it free software that
everyone can redistribute and change. You can do so by permitting
redistribution under these terms (or, alternatively, under the terms of the
ordinary General Public License).

To apply these terms, attach the following notices to the library. It is
safest to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least the
"copyright" line and a pointer to where the full notice is found.

<one line to give the library's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
USA

Also add information on how to contact you by electronic and paper mail.

You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the library, if
necessary. Here is a sample; alter the names:

Yoyodyne, Inc., hereby disclaims all copyright interest in the
library `Frob' (a library for tweaking knobs) written by James Random
Hacker.

<signature of Ty Coon>, 1 April 1990
Ty Coon, President of Vice

That's all there is to it!
7 changes: 4 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import de.griefed.common.gradle.LicenseAgreementRenderer
import de.griefed.common.gradle.SubprojectLicenseFilter
import org.gradle.plugins.ide.idea.model.IdeaLanguageLevel

Expand Down Expand Up @@ -60,7 +61,7 @@ licenseReport {
renderers = arrayOf<com.github.jk1.license.render.ReportRenderer>(

Check notice on line 61 in build.gradle.kts

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unnecessary type argument

Remove explicit type arguments
com.github.jk1.license.render.InventoryHtmlReportRenderer("index.html", "Dependency Licences"),
com.github.jk1.license.render.InventoryMarkdownReportRenderer("licences.md", "Dependency Licenses"),
com.github.jk1.license.render.TextReportRenderer()
LicenseAgreementRenderer("LICENSE-AGREEMENT")
)
}

Expand Down Expand Up @@ -107,11 +108,11 @@ tasks.register<Copy>("copyPluginsApiUnitTests") {

tasks.register<Delete>("cleanLicenseReport") {
delete(licenseReports)
delete(projectDir.resolve("serverpackcreator-gui/src/main/resources/de/griefed/resources/gui/THIRD-PARTY-NOTICES.txt"))
delete(projectDir.resolve("serverpackcreator-gui/src/main/resources/de/griefed/resources/gui/LICENSE-AGREEMENT"))
}

tasks.register<Copy>("copyLicenseReport") {
from(rootDir.resolve("licenses/THIRD-PARTY-NOTICES.txt"))
from(rootDir.resolve("licenses/LICENSE-AGREEMENT"))
into(rootDir.resolve("serverpackcreator-gui/src/main/resources/de/griefed/resources/gui"))
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
/* Copyright (C) 2023 Griefed
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*
* The full license can be found at https:github.com/Griefed/ServerPackCreator/blob/main/LICENSE
*/
package de.griefed.common.gradle

import com.github.jk1.license.*
import com.github.jk1.license.render.ReportRenderer
import com.github.jk1.license.util.Files
import org.gradle.api.Project
import java.io.File
import java.net.URL

/**
* Custom made license renderer for https://github.com/jk1/Gradle-License-Report to generate a decent license
* agreement for use in installers.
*
* @author Griefed
*/
class LicenseAgreementRenderer(private val fileName: String = "LICENSE-AGREEMENT"): ReportRenderer {

private lateinit var project: Project
private lateinit var output: File
private lateinit var outputDir: File
private var counter: Int = 1

override fun render(data: ProjectData) {
project = data.project
outputDir = File(data.project.rootDir,"licenses")
output = File(data.project.rootDir,"licenses/${fileName}")
output.writeText("")
output.appendText("ServerPackCreator license agreement:\n\n")
output.appendText("ServerPackCreator ${project.version} license:\n\n")
output.appendText(File(data.project.rootDir,"LICENSE").readText() + "\n\n")
output.appendText("Used libraries / dependencies licenses:\n\n")
output.appendText("-------------------------------------------------------\n\n")
output.appendText(getDependencyLicenses(data))
}

private fun getDependencyLicenses(data: ProjectData): String {
var text = ""
for (dependencyData in data.allDependencies) {
text += "($counter of ${data.allDependencies.size})"
text += getDependencyLicense(dependencyData)
text += "\n#######################################\n\n"
counter++
}
return text
}

private fun getDependencyLicense(data: ModuleData): String {
var projectUrlDone = false
var text = ""
if (data.group.isNotEmpty()) {
text = append(text,"Group: ${data.group}")
}
if (data.name.isNotEmpty()) {
text = append(text,"Name: ${data.name}")
}
if (data.version.isNotEmpty()) {
text = append(text,"Version: ${data.version}")
}
if (data.poms.isEmpty() && data.manifests.isEmpty()) {
text = append(text,"No license information found\n\n")
}
if (data.manifests.isNotEmpty() && data.poms.isNotEmpty()) {
val manifest = data.manifests.first()
val pomData = data.poms.first()
if (!manifest.url.isNullOrBlank() && !pomData.projectUrl.isNullOrBlank() && manifest.url == pomData.projectUrl) {
text = append(text,"Project URL: ${manifest.url}\\n\\n")
projectUrlDone = true
}
}
if (data.manifests.isNotEmpty()) {
val manifest = data.manifests.first()
if (!manifest.url.isNullOrBlank() && !projectUrlDone) {
text = append(text,"Manifest Project URL: ${manifest.url}\n\n")
}
if (!manifest.license.isNullOrBlank()) {
if (Files.maybeLicenseUrl(manifest.licenseUrl)) {
text = append(text,"Manifest license URL: ${manifest.licenseUrl}\n\n")
} else if (manifest.hasPackagedLicense) {
text = append(text,"Packaged License File: ${manifest.license}\n\n")
} else {
text = append(text,"Manifest License: ${manifest.license} (Not packaged)\n\n")
}
}
}
if (data.poms.isNotEmpty()) {
val pomData = data.poms.first()
if (pomData.projectUrl.isNotEmpty() && !projectUrlDone) {
text = append(text,"POM Project URL: ${pomData.projectUrl}\n\n")
}
if (pomData.licenses.isNotEmpty()) {
for (license in pomData.licenses) {
text = append(text,"POM License: ${license.name}")
if (!license.url.isNullOrBlank()) {
text = if (Files.maybeLicenseUrl(license.url)) {
append(text," - ${license.url}\n\n")
} else {
append(text,"License: ${license.url}\n\n")
}
}
}
}
}
if (data.licenseFiles.isNotEmpty() && data.licenseFiles.first().fileDetails.isNotEmpty()) {
text = append(text,"Embedded license:\n")
for (content in data.licenseFiles.first().fileDetails) {
text = append(text,File(outputDir,content.file).readText() + "\n")
}
} else if (data.poms.isNotEmpty() && data.poms.first().licenses.isNotEmpty()) {
text = append(text,"POM license(s): \n\n")
for (license in data.poms.first().licenses) {
text = append(text,"License: ${license.name}")
text = append(text,"URL: ${license.url}\n\n")
if (!license.url.isNullOrBlank() && license.url.endsWith(".txt",ignoreCase = true) && Files.maybeLicenseUrl(license.url)) {
try {
text = append(text, URL(license.url).readText() + "\n")
} catch (_: Exception) {}
}
}
}
return text
}

private fun append(toAppendTo: String, text: String): String {
return "$toAppendTo\n$text"
}
}
Loading

0 comments on commit da171ac

Please sign in to comment.