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

Include license in latest version table #156

Merged
merged 3 commits into from
Jan 8, 2025
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
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:

timtebeek marked this conversation as resolved.
Show resolved Hide resolved
| 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
Loading