Skip to content

Commit 942bb58

Browse files
authored
Include license in latest version table (#156)
* Include license in latest version table * Link to licenses * Create a markdown method to link to licenses
1 parent a6d676c commit 942bb58

File tree

2 files changed

+31
-19
lines changed

2 files changed

+31
-19
lines changed

src/main/kotlin/org/openrewrite/Licenses.kt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,19 @@ package org.openrewrite
33
enum class License {
44
Apache2,
55
MSAL,
6-
Proprietary
6+
Proprietary;
7+
8+
private fun label() = when(this) {
9+
Apache2 -> "Apache License Version 2.0"
10+
MSAL -> "Moderne Source Available"
11+
Proprietary -> "Moderne Proprietary"
12+
}
13+
private fun url() = when(this) {
14+
Apache2 -> "https://www.apache.org/licenses/LICENSE-2.0"
15+
MSAL -> "https://docs.moderne.io/licensing/moderne-source-available-license"
16+
Proprietary -> "https://docs.moderne.io/licensing/overview"
17+
}
18+
fun markdown() = "[${label()}](${url()})"
719
}
820

921
fun getLicense(recipeOrigin: RecipeOrigin): License {

src/main/kotlin/org/openrewrite/RecipeMarkdownGenerator.kt

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,13 @@ class RecipeMarkdownGenerator : Runnable {
173173
val recipeDescriptors: Collection<RecipeDescriptor> = env.listRecipeDescriptors()
174174
val categoryDescriptors = ArrayList(env.listCategoryDescriptors())
175175
val markdownArtifacts = TreeMap<String, MarkdownRecipeArtifact>()
176-
val recipesWithDataTables = ArrayList<RecipeDescriptor>();
176+
val recipesWithDataTables = ArrayList<RecipeDescriptor>()
177177
val moderneProprietaryRecipes = TreeMap<String, MutableList<RecipeDescriptor>>()
178178
var recipeCount = 0
179179

180180
// Create the recipe docs
181181
for (recipeDescriptor in recipeDescriptors) {
182-
recipeCount++;
182+
recipeCount++
183183
var origin: RecipeOrigin?
184184
var rawUri = recipeDescriptor.source.toString()
185185
val exclamationIndex = rawUri.indexOf('!')
@@ -202,7 +202,7 @@ class RecipeMarkdownGenerator : Runnable {
202202
}
203203

204204
if (filteredDataTables.isNotEmpty()) {
205-
recipesWithDataTables.add(recipeDescriptor);
205+
recipesWithDataTables.add(recipeDescriptor)
206206
}
207207

208208
if (getLicense(origin) == License.Proprietary) {
@@ -336,15 +336,15 @@ class RecipeMarkdownGenerator : Runnable {
336336
"it won't be included in this list._\n")
337337

338338
for (recipe in recipesWithDataTables) {
339-
var recipePath = "";
339+
var recipePath: String
340340

341341
if (recipe.name.count { it == '.' } == 2 &&
342342
recipe.name.contains("org.openrewrite.")) {
343-
recipePath = "recipes/core/" + recipe.name.removePrefix("org.openrewrite.").lowercase();
343+
recipePath = "recipes/core/" + recipe.name.removePrefix("org.openrewrite.").lowercase()
344344
} else if (recipe.name.contains("io.moderne.ai")) {
345-
recipePath = "recipes/ai/" + recipe.name.removePrefix("io.moderne.ai.").replace(".", "/").lowercase();
345+
recipePath = "recipes/ai/" + recipe.name.removePrefix("io.moderne.ai.").replace(".", "/").lowercase()
346346
} else {
347-
recipePath = "recipes/" + recipe.name.removePrefix("org.openrewrite.").replace(".", "/").lowercase();
347+
recipePath = "recipes/" + recipe.name.removePrefix("org.openrewrite.").replace(".", "/").lowercase()
348348
}
349349

350350
writeln("### [${recipe.displayName}](../${recipePath}.md)\n ")
@@ -397,11 +397,11 @@ class RecipeMarkdownGenerator : Runnable {
397397
to align the versions of Rewrite's modules to ensure compatibility.
398398
The use of the "bill of materials" means that a developer will only need to specify explicit versions of the BOM and the build plugins:
399399
400-
| Module | Version |
401-
|-----------------------------------------------------------------------------------------------------------------------| ---------- |
402-
| [**org.openrewrite.recipe:rewrite-recipe-bom**](https://github.com/openrewrite/rewrite-recipe-bom) | **${bomLink}** |
403-
| [**org.openrewrite:rewrite-maven-plugin**](https://github.com/openrewrite/rewrite-maven-plugin) | **${mavenLink}** |
404-
| [**org.openrewrite:rewrite-gradle-plugin**](https://github.com/openrewrite/rewrite-gradle-plugin) | **${gradleLink}** |
400+
| Module | Version | License |
401+
|-----------------------------------------------------------------------------------------------------------------------| ---------- | ------- |
402+
| [**org.openrewrite.recipe:rewrite-recipe-bom**](https://github.com/openrewrite/rewrite-recipe-bom) | **${bomLink}** | ${License.Apache2.markdown()} |
403+
| [**org.openrewrite:rewrite-maven-plugin**](https://github.com/openrewrite/rewrite-maven-plugin) | **${mavenLink}** | ${License.MSAL.markdown()} |
404+
| [**org.openrewrite:rewrite-gradle-plugin**](https://github.com/openrewrite/rewrite-gradle-plugin) | **${gradleLink}** |${License.MSAL.markdown()} |
405405
""".trimIndent()
406406
)
407407
var cliInstallGavs = ""
@@ -410,7 +410,7 @@ class RecipeMarkdownGenerator : Runnable {
410410
cliInstallGavs += "${origin.groupId}:${origin.artifactId}:${versionPlaceholder} "
411411
val repoLink = "[${origin.groupId}:${origin.artifactId}](${origin.githubUrl()})"
412412
val releaseLink = "[${origin.version}](${origin.githubUrl()}/releases/tag/v${origin.version})"
413-
writeln("| ${repoLink.padEnd(117)} | ${releaseLink.padEnd(90)} |")
413+
writeln("| ${repoLink.padEnd(117)} | ${releaseLink.padEnd(90)} | ${getLicense(origin).markdown()} |")
414414
}
415415
//language=markdown
416416
writeln(
@@ -1007,7 +1007,7 @@ class RecipeMarkdownGenerator : Runnable {
10071007
origin: RecipeOrigin
10081008
) {
10091009
if (recipesToIgnore.contains(recipeDescriptor.name)) {
1010-
return;
1010+
return
10111011
}
10121012

10131013
val sidebarFormattedName = recipeDescriptor.displayName
@@ -1070,7 +1070,7 @@ import TabItem from '@theme/TabItem';
10701070

10711071
writeSourceLinks(recipeDescriptor, origin)
10721072
writeOptions(recipeDescriptor)
1073-
writeLicense(recipeDescriptor, origin)
1073+
writeLicense(origin)
10741074
writeDefinition(recipeDescriptor, origin)
10751075
writeUsage(recipeDescriptor, origin)
10761076
writeModerneLink(recipeDescriptor)
@@ -1195,7 +1195,7 @@ import TabItem from '@theme/TabItem';
11951195
}
11961196
}
11971197

1198-
private fun BufferedWriter.writeLicense(recipeDescriptor: RecipeDescriptor, origin: RecipeOrigin) {
1198+
private fun BufferedWriter.writeLicense(origin: RecipeOrigin) {
11991199
val licenseText = when (getLicense(origin)) {
12001200
License.Apache2 -> "This recipe is available under the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0)."
12011201
License.MSAL -> "This recipe is available under the [Moderne Source Available License](https://docs.moderne.io/licensing/moderne-source-available-license/)."
@@ -1544,11 +1544,11 @@ import TabItem from '@theme/TabItem';
15441544
.replace("<script>", "//<script//>")
15451545

15461546
if (recipesToIgnore.contains(recipe.name)) {
1547-
continue;
1547+
continue
15481548
}
15491549

15501550
if (recipesThatShouldHaveLinksRemoved.contains(recipeDescriptor.name)) {
1551-
writeln("* $formattedRecipeDisplayName");
1551+
writeln("* $formattedRecipeDisplayName")
15521552
} else {
15531553
writeln("* [" + formattedRecipeDisplayName + "](" + pathToRecipes + getRecipePath(recipe) + ")")
15541554
}

0 commit comments

Comments
 (0)