8000 Script functions by krystian-panek-vmltech · Pull Request #92 · wttech/acm · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Script functions #92

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

Merged
merged 2 commits into from
May 7, 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
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ public String getId() {
}

public String getContent() throws AcmException {
return definition.getContent();
return StringUtils.trim(definition.getContent());
Copy link
Preview
Copilot AI May 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If definition.getContent() could return null, consider using a null-safe approach such as StringUtils.trimToEmpty to avoid potential NullPointerExceptions.

Suggested change
return StringUtils.trim(definition.getContent());
return StringUtils.trimToEmpty(definition.getContent());

Copilot uses AI. Check for mistakes.

}

public String getDocumentation() throws AcmException {
return definition.getDocumentation();
return StringUtils.trim(definition.getDocumentation());
}

@JsonIgnore
Expand All @@ -74,7 +74,7 @@ public String getName() {
}

public String getGroup() {
String result = definition.getGroup();
String result = StringUtils.trim(definition.getGroup());
if (StringUtils.isBlank(result)) {
result = StringUtils.substringBeforeLast(getPath(), "/");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/**
* Generate a list of all system classes in the current JVM.
* This version of the script is designed to be run in the context of AEM running on Java 9+.
*
* Arguments allow to:
* - print the list (for debugging purposes),
* - save it directly in the repository in expected path.
*
* @author Krystian Panek <krystian.panek@vml.com>
*/
import com.vml.es.aem.acm.core.assist.JavaClassDictionary

import java.lang.module.ModuleFinder
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/**
* Generate a list of all system classes in the current JVM.
* This version of the script is designed to be run in the context of AEM running on Java 8.
*
* Arguments allow to:
* - print the list (for debugging purposes),
* - save it directly in the repository in expected path.
*
* @author Krystian Panek <krystian.panek@vml.com>
*/
import com.vml.es.aem.acm.core.assist.JavaClassDictionary
import java.util.function.Consumer
import java.util.jar.JarFile
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/**
* Prints "Hello World!" to the console.
*
* This is a minimal example of AEM Content Manager script.
*
* @author Krystian Panek <krystian.panek@vml.com>
*/
boolean canRun() {
return condition.always()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/**
* Prints animal information to the console based on user input.
*
* This is an example of AEM Content Manager script with arguments.
*
* @author Krystian Panek <krystian.panek@vml.com>
*/
void describeRun() {
args.string("animalName") { value = "Whiskers" ; validator = "(v, a) => a.animalType === 'cat' ? (v && v.startsWith('W') || 'Cat name must start with W!') : true" }
args.select("animalType") { value = "cat"; options = ["cat", "dog", "bird", "fish", "hamster", "rabbit", "turtle", "lizard", "snake", "frog"] }
Expand Down
2 changes: 2 additions & 0 deletions ui.frontend/src/utils/monaco/groovy/completions.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { Monaco } from '@monaco-editor/react';
import { registerAemCodeCompletions } from './completions/aem-code.ts';
import { registerCoreCompletions } from './completions/core.ts';
import { registerSelfCodeCompletions } from './completions/self-code.ts';

export function registerCompletions(instance: Monaco) {
registerCoreCompletions(instance);
registerSelfCodeCompletions(instance);
registerAemCodeCompletions(instance);
}
10 changes: 5 additions & 5 deletions ui.frontend/src/utils/monaco/groovy/completions/aem-code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,16 @@ function registerResourceCompletion(instance: Monaco) {

function monacoKind(kind: string): monaco.languages.CompletionItemKind {
switch (kind.toLowerCase()) {
case 'class':
case SuggestionKind.CLASS:
return monaco.languages.CompletionItemKind.Class;
case SuggestionKind.VARIABLE:
return monaco.languages.CompletionItemKind.Variable;
case SuggestionKind.SNIPPET:
return monaco.languages.CompletionItemKind.Snippet;
case 'method':
return monaco.languages.CompletionItemKind.Method;
case 'function':
return monaco.languages.CompletionItemKind.Function;
case 'variable':
return monaco.languages.CompletionItemKind.Variable;
case 'snippet':
return monaco.languages.CompletionItemKind.Snippet;
default:
return monaco.languages.CompletionItemKind.Text;
}
Expand Down
85 changes: 85 additions & 0 deletions ui.frontend/src/utils/monaco/groovy/completions/core.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import { Monaco } from '@monaco-editor/react';
import * as monaco from 'monaco-editor';
import { LANGUAGE_ID } from '../../groovy.ts';
import {MarkdownString} from "monaco-editor/esm/vs/base/common/htmlContent";

export function registerCoreCompletions(instance: Monaco) {
registerScriptCompletions(instance);
}

/**
* Completions for class 'groovy.lang.Script' which is the base class for all Groovy scripts.
*/
export function registerScriptCompletions(instance: Monaco) {
instance.languages.registerCompletionItemProvider(LANGUAGE_ID, {
provideCompletionItems: (model: monaco.editor.ITextModel, position: monaco.Position) => {
const modelPosition = model.getWordUntilPosition(position);
const range = new monaco.Range(position.lineNumber, modelPosition.startColumn, position.lineNumber, modelPosition.endColumn);
const suggestions: monaco.languages.CompletionItem[] = [
{
label: 'println()',
insertText: 'println()',
documentation: new MarkdownString('Prints a line to the console.'),
kind: monaco.languages.CompletionItemKind.Function,
range,
},
{
label: 'print()',
kind: monaco.languages.CompletionItemKind.Function,
insertText: 'print()',
documentation: new MarkdownString('Prints to the console without a newline.'),
range,
},
{
label: 'println(Object value)',
kind: monaco.languages.CompletionItemKind.Function,
insertText: 'println(${1:value})',
insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet,
documentation: new MarkdownString(`
Prints the given value to the console, followed by a newline.

For example:

\`\`\`groovy
println("Hello, World!")
\`\`\`
`),
range,
},
{
label: 'printf(String format, Object value)',
kind: monaco.languages.CompletionItemKind.Function,
insertText: 'printf(${1:format}, ${2:value})',
insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet,
documentation: new MarkdownString(`
Prints a formatted string to the console.

For example:

\`\`\`groovy
printf("Hello %s!", "John")
\`\`\`
`),
range,
},
{
label: 'printf(String format, Object[] values)',
kind: monaco.languages.CompletionItemKind.Function,
insertText: 'printf(${1:format}, ${2:values})',
insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet,
documentation: new MarkdownString(`
Prints a formatted string with multiple values to the console.

For example:
\`\`\`groovy
printf("Hello %s! You have %d new message(s)!", "John", 5)
\`\`\`
`),
range,
}
];

return { suggestions };
},
});
}
0