Skip to content

Commit

Permalink
Include license in latest version table (#156)
Browse files Browse the repository at this point in the history
* Include license in latest version table

* Link to licenses

* Create a markdown method to link to licenses
  • Loading branch information
timtebeek authored Jan 8, 2025
1 parent a6d676c commit 942bb58
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 19 deletions.
14 changes: 13 additions & 1 deletion src/main/kotlin/org/openrewrite/Licenses.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,19 @@ package org.openrewrite
enum class License {
Apache2,
MSAL,
Proprietary
Proprietary;

private fun label() = when(this) {
Apache2 -> "Apache License Version 2.0"
MSAL -> "Moderne Source Available"
Proprietary -> "Moderne Proprietary"
}
private fun url() = when(this) {
Apache2 -> "https://www.apache.org/licenses/LICENSE-2.0"
MSAL -> "https://docs.moderne.io/licensing/moderne-source-available-license"
Proprietary -> "https://docs.moderne.io/licensing/overview"
}
fun markdown() = "[${label()}](${url()})"
}

fun getLicense(recipeOrigin: RecipeOrigin): License {
Expand Down
36 changes: 18 additions & 18 deletions src/main/kotlin/org/openrewrite/RecipeMarkdownGenerator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,13 @@ class RecipeMarkdownGenerator : Runnable {
val recipeDescriptors: Collection<RecipeDescriptor> = env.listRecipeDescriptors()
val categoryDescriptors = ArrayList(env.listCategoryDescriptors())
val markdownArtifacts = TreeMap<String, MarkdownRecipeArtifact>()
val recipesWithDataTables = ArrayList<RecipeDescriptor>();
val recipesWithDataTables = ArrayList<RecipeDescriptor>()
val moderneProprietaryRecipes = TreeMap<String, MutableList<RecipeDescriptor>>()
var recipeCount = 0

// Create the recipe docs
for (recipeDescriptor in recipeDescriptors) {
recipeCount++;
recipeCount++
var origin: RecipeOrigin?
var rawUri = recipeDescriptor.source.toString()
val exclamationIndex = rawUri.indexOf('!')
Expand All @@ -202,7 +202,7 @@ class RecipeMarkdownGenerator : Runnable {
}

if (filteredDataTables.isNotEmpty()) {
recipesWithDataTables.add(recipeDescriptor);
recipesWithDataTables.add(recipeDescriptor)
}

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

for (recipe in recipesWithDataTables) {
var recipePath = "";
var recipePath: String

if (recipe.name.count { it == '.' } == 2 &&
recipe.name.contains("org.openrewrite.")) {
recipePath = "recipes/core/" + recipe.name.removePrefix("org.openrewrite.").lowercase();
recipePath = "recipes/core/" + recipe.name.removePrefix("org.openrewrite.").lowercase()
} else if (recipe.name.contains("io.moderne.ai")) {
recipePath = "recipes/ai/" + recipe.name.removePrefix("io.moderne.ai.").replace(".", "/").lowercase();
recipePath = "recipes/ai/" + recipe.name.removePrefix("io.moderne.ai.").replace(".", "/").lowercase()
} else {
recipePath = "recipes/" + recipe.name.removePrefix("org.openrewrite.").replace(".", "/").lowercase();
recipePath = "recipes/" + recipe.name.removePrefix("org.openrewrite.").replace(".", "/").lowercase()
}

writeln("### [${recipe.displayName}](../${recipePath}.md)\n ")
Expand Down Expand Up @@ -397,11 +397,11 @@ class RecipeMarkdownGenerator : Runnable {
to align the versions of Rewrite's modules to ensure compatibility.
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:
| Module | Version |
|-----------------------------------------------------------------------------------------------------------------------| ---------- |
| [**org.openrewrite.recipe:rewrite-recipe-bom**](https://github.com/openrewrite/rewrite-recipe-bom) | **${bomLink}** |
| [**org.openrewrite:rewrite-maven-plugin**](https://github.com/openrewrite/rewrite-maven-plugin) | **${mavenLink}** |
| [**org.openrewrite:rewrite-gradle-plugin**](https://github.com/openrewrite/rewrite-gradle-plugin) | **${gradleLink}** |
| Module | Version | License |
|-----------------------------------------------------------------------------------------------------------------------| ---------- | ------- |
| [**org.openrewrite.recipe:rewrite-recipe-bom**](https://github.com/openrewrite/rewrite-recipe-bom) | **${bomLink}** | ${License.Apache2.markdown()} |
| [**org.openrewrite:rewrite-maven-plugin**](https://github.com/openrewrite/rewrite-maven-plugin) | **${mavenLink}** | ${License.MSAL.markdown()} |
| [**org.openrewrite:rewrite-gradle-plugin**](https://github.com/openrewrite/rewrite-gradle-plugin) | **${gradleLink}** |${License.MSAL.markdown()} |
""".trimIndent()
)
var cliInstallGavs = ""
Expand All @@ -410,7 +410,7 @@ class RecipeMarkdownGenerator : Runnable {
cliInstallGavs += "${origin.groupId}:${origin.artifactId}:${versionPlaceholder} "
val repoLink = "[${origin.groupId}:${origin.artifactId}](${origin.githubUrl()})"
val releaseLink = "[${origin.version}](${origin.githubUrl()}/releases/tag/v${origin.version})"
writeln("| ${repoLink.padEnd(117)} | ${releaseLink.padEnd(90)} |")
writeln("| ${repoLink.padEnd(117)} | ${releaseLink.padEnd(90)} | ${getLicense(origin).markdown()} |")
}
//language=markdown
writeln(
Expand Down Expand Up @@ -1007,7 +1007,7 @@ class RecipeMarkdownGenerator : Runnable {
origin: RecipeOrigin
) {
if (recipesToIgnore.contains(recipeDescriptor.name)) {
return;
return
}

val sidebarFormattedName = recipeDescriptor.displayName
Expand Down Expand Up @@ -1070,7 +1070,7 @@ import TabItem from '@theme/TabItem';

writeSourceLinks(recipeDescriptor, origin)
writeOptions(recipeDescriptor)
writeLicense(recipeDescriptor, origin)
writeLicense(origin)
writeDefinition(recipeDescriptor, origin)
writeUsage(recipeDescriptor, origin)
writeModerneLink(recipeDescriptor)
Expand Down Expand Up @@ -1195,7 +1195,7 @@ import TabItem from '@theme/TabItem';
}
}

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

if (recipesToIgnore.contains(recipe.name)) {
continue;
continue
}

if (recipesThatShouldHaveLinksRemoved.contains(recipeDescriptor.name)) {
writeln("* $formattedRecipeDisplayName");
writeln("* $formattedRecipeDisplayName")
} else {
writeln("* [" + formattedRecipeDisplayName + "](" + pathToRecipes + getRecipePath(recipe) + ")")
}
Expand Down

0 comments on commit 942bb58

Please sign in to comment.