Skip to content

Commit

Permalink
feat(core): add EE flag on the documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
tchiotludo committed Aug 6, 2024
1 parent d81c6e5 commit 0162810
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

class PluginDocCommandTest {

public static final String PLUGIN_TEMPLATE_TEST = "plugin-template-test-0.17.0-SNAPSHOT.jar";
public static final String PLUGIN_TEMPLATE_TEST = "plugin-template-test-0.18.0-SNAPSHOT.jar";

@Test
void run() throws IOException, URISyntaxException {
Expand Down Expand Up @@ -51,22 +51,27 @@ void run() throws IOException, URISyntaxException {
assertThat(directory.listFiles().length, is(3));

var readme = directory.toPath().resolve("index.md");
assertThat(new String(Files.readAllBytes(readme)), containsString("""
var readmeContent = new String(Files.readAllBytes(readme));

assertThat(readmeContent, containsString("""
---
title: Template test
description: "Plugin template for Kestra"
editLink: false
---
# Template test
"""));

assertThat(readmeContent, containsString("""
Plugin template for Kestra
This is a more complex description of the plugin.
This is in markdown and will be inline inside the plugin page.
"""));
assertThat(new String(Files.readAllBytes(readme)), containsString(

assertThat(readmeContent, containsString(
"""
/> Subgroup title
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

class PluginListCommandTest {

private static final String PLUGIN_TEMPLATE_TEST = "plugin-template-test-0.17.0-SNAPSHOT.jar";
private static final String PLUGIN_TEMPLATE_TEST = "plugin-template-test-0.18.0-SNAPSHOT.jar";

@Test
void run() throws IOException, URISyntaxException {
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
public class ClassPluginDocumentation<T> extends AbstractClassDocumentation<T> {
private String icon;
private String group;
protected String docLicense;
private String pluginTitle;
private String subGroup;
private String replacement;
Expand All @@ -26,6 +27,7 @@ private ClassPluginDocumentation(JsonSchemaGenerator jsonSchemaGenerator, Regist
// plugins metadata
this.cls = alias == null ? cls.getName() : alias;
this.group = plugin.group();
this.docLicense = plugin.license();
this.pluginTitle = plugin.title();
this.icon = plugin.icon(cls);
if (alias != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ private static List<Document> index(RegisteredPlugin plugin) throws IOException
builder.put("description", plugin.description());
}

if (plugin.license() != null) {
builder.put("docLicense", plugin.license());
}

if (plugin.longDescription() != null) {
builder.put("longDescription", plugin.longDescription());
}
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/java/io/kestra/core/docs/Plugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class Plugin {
private String name;
private String title;
private String description;
private String license;
private String longDescription;
private String group;
private String version;
Expand All @@ -43,6 +44,7 @@ public static Plugin of(RegisteredPlugin registeredPlugin, @Nullable String subg
}
plugin.group = registeredPlugin.group();
plugin.description = registeredPlugin.description();
plugin.license = registeredPlugin.license();
plugin.longDescription = registeredPlugin.longDescription();
plugin.version = registeredPlugin.version();
plugin.guides = registeredPlugin.getGuides();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ public String description() {
return this.getManifest() == null ? null : this.getManifest().getMainAttributes().getValue("X-Kestra-Description");
}

public String license() {
return this.getManifest() == null ? null : this.getManifest().getMainAttributes().getValue("X-Kestra-License");
}

public String longDescription() {
try (var is = this.getClassLoader().getResourceAsStream("doc/" + this.group() + ".md")) {
if(is != null) {
Expand Down
6 changes: 6 additions & 0 deletions core/src/main/resources/docs/index.peb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ editLink: false
---
# {% if icon -%}<img width="25" src="data:image/svg+xml;base64,{{ icon }}" /> {% endif %}{{ title | replace({"-": " "}) | capitalize }}

{% if docLicense == "EE" %}
::alert{type="info"}
This plugin requires an Enterprise Edition license.
::
{%- endif %}

{{ description }}

{{ longDescription }}
Expand Down
7 changes: 7 additions & 0 deletions core/src/main/resources/docs/task.peb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ This plugin is currently in beta. While it is considered safe for use, please be
::
{%- endif %}


{% if docLicense == "EE" %}
::alert{type="info"}
This plugin requires an Enterprise Edition license.
::
{%- endif %}

```yaml
type: "{{ cls }}"
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ void tasks() throws URISyntaxException {
assertThat(doc.getDocExamples().size(), is(2));
assertThat(doc.getIcon(), is(notNullValue()));
assertThat(doc.getInputs().size(), is(5));
assertThat(doc.getDocLicense(), is("EE"));

// simple
assertThat(((Map<String, String>) doc.getInputs().get("format")).get("type"), is("string"));
Expand Down Expand Up @@ -100,6 +101,7 @@ void trigger() throws URISyntaxException {
ClassPluginDocumentation<? extends AbstractTrigger> doc = ClassPluginDocumentation.of(jsonSchemaGenerator, scan, Schedule.class, null);

assertThat(doc.getDefs().size(), is(2));
assertThat(doc.getDocLicense(), nullValue());

assertThat(((Map<String, Object>) doc.getDefs().get("io.kestra.core.models.tasks.WorkerGroup")).get("type"), is("object"));
assertThat(((Map<String, Object>) ((Map<String, Object>) doc.getDefs().get("io.kestra.core.models.tasks.WorkerGroup")).get("properties")).size(), is(1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ void tasks() throws URISyntaxException, IOException {
assertThat(render, containsString("description: \"Short description for this task\""));
assertThat(render, containsString("`VALUE_1`"));
assertThat(render, containsString("`VALUE_2`"));
assertThat(render, containsString("requires an Enterprise Edition"));
}

@SuppressWarnings({"rawtypes", "unchecked"})
Expand All @@ -64,8 +65,8 @@ void dag() throws IOException {

assertThat(render, containsString("Dag"));
assertThat(render, containsString("**Required:** ✔️"));

assertThat(render, containsString("`concurrent`"));
assertThat(render, not(containsString("requires an Enterprise Edition")));

int propertiesIndex = render.indexOf("Properties");
int definitionsIndex = render.indexOf("Definitions");
Expand Down Expand Up @@ -160,6 +161,18 @@ void pluginDoc() throws Exception {
assertThat(doc.getBody(), containsString("## <img width=\"25\" src=\"data:image/svg+xml;base64,"));
}

@Test
void pluginEeDoc() throws Exception {
Path plugins = Paths.get(Objects.requireNonNull(ClassPluginDocumentationTest.class.getClassLoader().getResource("plugins")).toURI());

PluginScanner pluginScanner = new PluginScanner(ClassPluginDocumentationTest.class.getClassLoader());
List<RegisteredPlugin> list = pluginScanner.scan(plugins);

List<Document> docs = documentationGenerator.generate(list.stream().filter(r -> r.license() != null).findFirst().orElseThrow());
Document doc = docs.getFirst();
assertThat(doc.getBody(), containsString("requires an Enterprise"));
}

@SuppressWarnings("unchecked")
@Test
void taskRunner() throws IOException {
Expand Down
Binary file not shown.

0 comments on commit 0162810

Please sign in to comment.