Skip to content

Commit 20be054

Browse files
Hardening, minors
1 parent b990392 commit 20be054

File tree

6 files changed

+40
-34
lines changed

6 files changed

+40
-34
lines changed

core/src/main/java/dev/vml/es/acm/core/code/Code.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ public String getContent() {
6262
}
6363

6464
@Override
65-
public CodeMetadata getMetadata() {
66-
return CodeMetadata.of(this);
65+
public ExecutableMetadata getMetadata() {
66+
return ExecutableMetadata.of(this);
6767
}
6868

6969
public String toString() {

core/src/main/java/dev/vml/es/acm/core/code/Executable.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ public interface Executable extends Serializable {
1212

1313
String getContent();
1414

15-
CodeMetadata getMetadata();
15+
ExecutableMetadata getMetadata();
1616
}

core/src/main/java/dev/vml/es/acm/core/code/CodeMetadata.java renamed to core/src/main/java/dev/vml/es/acm/core/code/ExecutableMetadata.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
import org.slf4j.Logger;
1313
import org.slf4j.LoggerFactory;
1414

15-
public class CodeMetadata implements Serializable {
15+
public class ExecutableMetadata implements Serializable {
1616

17-
public static final CodeMetadata EMPTY = new CodeMetadata(new LinkedHashMap<>());
17+
public static final ExecutableMetadata EMPTY = new ExecutableMetadata(new LinkedHashMap<>());
1818

19-
private static final Logger LOG = LoggerFactory.getLogger(CodeMetadata.class);
19+
private static final Logger LOG = LoggerFactory.getLogger(ExecutableMetadata.class);
2020

2121
private static final Pattern BLOCK_COMMENT_PATTERN =
2222
Pattern.compile("/\\*(?!\\*)([^*]|\\*(?!/))*\\*/", Pattern.DOTALL);
@@ -30,11 +30,11 @@ public class CodeMetadata implements Serializable {
3030

3131
private Map<String, Object> values;
3232

33-
public CodeMetadata(Map<String, Object> values) {
33+
public ExecutableMetadata(Map<String, Object> values) {
3434
this.values = values;
3535
}
3636

37-
public static CodeMetadata of(Executable executable) {
37+
public static ExecutableMetadata of(Executable executable) {
3838
try {
3939
return parse(executable.getContent());
4040
} catch (Exception e) {
@@ -43,11 +43,11 @@ public static CodeMetadata of(Executable executable) {
4343
}
4444
}
4545

46-
public static CodeMetadata parse(String code) {
46+
public static ExecutableMetadata parse(String code) {
4747
if (StringUtils.isNotBlank(code)) {
4848
String blockComment = findFirstBlockComment(code);
4949
if (blockComment != null) {
50-
return new CodeMetadata(parseBlockComment(blockComment));
50+
return new ExecutableMetadata(parseBlockComment(blockComment));
5151
}
5252
}
5353
return EMPTY;

core/src/main/java/dev/vml/es/acm/core/script/Script.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import com.fasterxml.jackson.annotation.JsonIgnore;
44
import dev.vml.es.acm.core.AcmException;
5-
import dev.vml.es.acm.core.code.CodeMetadata;
5+
import dev.vml.es.acm.core.code.ExecutableMetadata;
66
import dev.vml.es.acm.core.code.Executable;
77
import java.io.IOException;
88
import java.io.InputStream;
@@ -57,8 +57,8 @@ public String getContent() throws AcmException {
5757
}
5858

5959
@Override
60-
public CodeMetadata getMetadata() {
61-
return CodeMetadata.of(this);
60+
public ExecutableMetadata getMetadata() {
61+
return ExecutableMetadata.of(this);
6262
}
6363

6464
@JsonIgnore

core/src/test/java/dev/vml/es/acm/core/code/CodeMetadataTest.java renamed to core/src/test/java/dev/vml/es/acm/core/code/ExecutableMetadataTest.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import java.util.List;
1111
import org.junit.jupiter.api.Test;
1212

13-
class CodeMetadataTest {
13+
class ExecutableMetadataTest {
1414

1515
private static final Path SCRIPTS_BASE_PATH =
1616
Paths.get("../ui.content.example/src/main/content/jcr_root/conf/acm/settings/script");
@@ -22,22 +22,22 @@ private String readScript(String relativePath) throws IOException {
2222

2323
@Test
2424
void shouldParseEmptyCode() {
25-
CodeMetadata metadata = CodeMetadata.parse("");
25+
ExecutableMetadata metadata = ExecutableMetadata.parse("");
2626

2727
assertTrue(metadata.getValues().isEmpty());
2828
}
2929

3030
@Test
3131
void shouldParseNullCode() {
32-
CodeMetadata metadata = CodeMetadata.parse(null);
32+
ExecutableMetadata metadata = ExecutableMetadata.parse(null);
3333

3434
assertTrue(metadata.getValues().isEmpty());
3535
}
3636

3737
@Test
3838
void shouldParseHelloWorldScript() throws IOException {
3939
String code = readScript("manual/example/ACME-200_hello-world.groovy");
40-
CodeMetadata metadata = CodeMetadata.parse(code);
40+
ExecutableMetadata metadata = ExecutableMetadata.parse(code);
4141

4242
assertEquals(
4343
"Prints \"Hello World!\" to the console.", metadata.getValues().get("description"));
@@ -46,7 +46,7 @@ void shouldParseHelloWorldScript() throws IOException {
4646
@Test
4747
void shouldParseInputsScript() throws IOException {
4848
String code = readScript("manual/example/ACME-201_inputs.groovy");
49-
CodeMetadata metadata = CodeMetadata.parse(code);
49+
ExecutableMetadata metadata = ExecutableMetadata.parse(code);
5050

5151
String description = (String) metadata.getValues().get("description");
5252
assertNotNull(description);
@@ -57,7 +57,7 @@ void shouldParseInputsScript() throws IOException {
5757
@Test
5858
void shouldParsePageThumbnailScript() throws IOException {
5959
String code = readScript("manual/example/ACME-202_page-thumbnail.groovy");
60-
CodeMetadata metadata = CodeMetadata.parse(code);
60+
ExecutableMetadata metadata = ExecutableMetadata.parse(code);
6161
String description = (String) metadata.getValues().get("description");
6262

6363
assertNotNull(description);
@@ -69,7 +69,7 @@ void shouldParsePageThumbnailScript() throws IOException {
6969
@Test
7070
void shouldParseScriptWithoutFrontmatter() throws IOException {
7171
String code = readScript("automatic/example/ACME-20_once.groovy");
72-
CodeMetadata metadata = CodeMetadata.parse(code);
72+
ExecutableMetadata metadata = ExecutableMetadata.parse(code);
7373

7474
assertFalse(metadata.getValues().isEmpty());
7575
assertNotNull(metadata.getValues().get("description"));
@@ -90,7 +90,7 @@ void shouldParseMultipleAuthors() {
9090
+ "void doRun() {\n"
9191
+ " println \"Hello\"\n"
9292
+ "}";
93-
CodeMetadata metadata = CodeMetadata.parse(code);
93+
ExecutableMetadata metadata = ExecutableMetadata.parse(code);
9494
Object authors = metadata.getValues().get("author");
9595
assertTrue(authors instanceof List);
9696
@SuppressWarnings("unchecked")
@@ -115,7 +115,7 @@ void shouldParseCustomTags() {
115115
+ " println \"Hello\"\n"
116116
+ "}";
117117

118-
CodeMetadata metadata = CodeMetadata.parse(code);
118+
ExecutableMetadata metadata = ExecutableMetadata.parse(code);
119119

120120
assertEquals("Custom script with metadata", metadata.getValues().get("description"));
121121
assertEquals("1.0.0", metadata.getValues().get("version"));

ui.frontend/src/components/ExecutableMetadata.tsx

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import React from 'react';
55
import { ExecutableMetadata as ExecutableMetadataType } from '../types/executable';
66
import Markdown from './Markdown';
77
import SnippetCode from './SnippetCode';
8+
import { Strings } from '../utils/strings';
89

910
type ExecutableMetadataProps = {
1011
metadata: ExecutableMetadataType | null | undefined;
@@ -25,35 +26,40 @@ const ExecutableMetadata: React.FC<ExecutableMetadataProps> = ({ metadata }) =>
2526
<Content>
2627
<View marginBottom="size-100">
2728
<Text>
28-
Use a block comment with YAML frontmatter at the top of your script file.{' '}
29+
Use YAML frontmatter in a block comment. Supports{' '}
2930
<Link href="https://github.github.com/gfm/" target="_blank">
30-
GitHub Flavored Markdown
31+
GFM
3132
</Link>{' '}
32-
is supported in all metadata values.
33+
and{' '}
34+
<Link href="https://mermaid.js.org/intro/syntax-reference.html" target="_blank">
35+
Mermaid
36+
</Link>
37+
.
3338
</Text>
3439
</View>
3540
<SnippetCode
3641
language="groovy"
3742
fontSize="small"
3843
content={`/*
3944
---
40-
version: 1.0
45+
version: '1.0'
4146
author: john.doe@acme.com
42-
tags:
43-
- content
44-
- migration
47+
tags: [content, migration]
4548
---
46-
Explain the script purpose here.
49+
This script demonstrates metadata parsing.
4750
48-
You can use **bold**, *italic*, [links](https://example.com), and other GFM formatting.
51+
\`\`\`mermaid
52+
graph LR
53+
A-->B-->C
54+
\`\`\`
4955
*/
5056
5157
void doRun() {
52-
// Script code
58+
// code
5359
}`}
5460
/>
5561
<View marginTop="size-100">
56-
<Text>The comment must be followed by a blank line. Can appear at file start or after imports.</Text>
62+
<Text>Notice that comment must be followed by a blank line.</Text>
5763
</View>
5864
</Content>
5965
</ContextualHelp>
@@ -66,7 +72,7 @@ void doRun() {
6672
return (
6773
<Flex direction="column" gap="size-200">
6874
{Object.entries(metadata).map(([key, value]) => {
69-
const label = key.charAt(0).toUpperCase() + key.slice(1);
75+
const label = Strings.capitalizeWords(key);
7076

7177
if (key === 'tags' && Array.isArray(value)) {
7278
return (

0 commit comments

Comments
 (0)