Skip to content

Commit 2055b94

Browse files
Copilotchrisrueger
andcommitted
Improve documentation for string replacement and file listing macros
Co-authored-by: chrisrueger <188422+chrisrueger@users.noreply.github.com>
1 parent dc0de6c commit 2055b94

File tree

6 files changed

+383
-29
lines changed

6 files changed

+383
-29
lines changed

docs/_macros/env.md

Lines changed: 65 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,70 @@
22
layout: default
33
class: Macro
44
title: env ';' KEY (';' STRING)?
5-
summary: The given environment variable or a default if the environment variable is not defined. The default is an empty string if not specified.
5+
summary: Get an environment variable with an optional default
66
---
77

8-
The specified key is looked up in `System.env` and returned. If the environment variable specified
9-
by key is not set, then the default string is returned. The default is an empty string if not
10-
specified.
8+
## Summary
9+
10+
The `env` macro looks up an environment variable and returns its value, or returns a default value if the variable is not set. The default is an empty string if not specified.
11+
12+
## Syntax
13+
14+
```
15+
${env;<variable>[;<default>]}
16+
```
17+
18+
## Parameters
19+
20+
- `variable` - The environment variable name to look up
21+
- `default` (optional) - Value to return if variable not set (default: empty string)
22+
23+
## Behavior
24+
25+
- Looks up environment variable via `System.getenv()`
26+
- Returns variable value if set
27+
- Returns default if variable not set
28+
- Default is empty string if not specified
29+
- Case-sensitive on Unix/Linux, case-insensitive on Windows
30+
31+
## Examples
32+
33+
Get environment variable with default:
34+
```
35+
${env;JAVA_HOME;/usr/lib/jvm/default}
36+
```
37+
38+
Check if variable exists:
39+
```
40+
${if;${env;CI};running-in-ci;local-build}
41+
```
42+
43+
Use in paths:
44+
```
45+
user.home=${env;HOME;/home/default}
46+
```
47+
48+
Empty default:
49+
```
50+
${env;OPTIONAL_VAR}
51+
# Returns value or "" if not set
52+
```
53+
54+
## Use Cases
55+
56+
- Accessing environment configuration
57+
- CI/CD environment detection
58+
- User-specific paths
59+
- System configuration
60+
- Platform differences
61+
- Secure credentials (with caution)
62+
63+
## Notes
64+
65+
- Accesses system environment variables
66+
- Case sensitivity varies by OS
67+
- Returns default for undefined variables
68+
- Empty string is valid default
69+
- **Security**: Be cautious with credentials
70+
- See also: `${def}` for properties
71+
- See also: `${system}` for system commands

docs/_macros/lsa.md

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,69 @@
22
layout: default
33
class: Macro
44
title: lsa ';' DIR (';' SELECTORS )
5-
summary: A list of absolute paths for files in the given directory optionally filtered by selectors.
5+
summary: List files with absolute paths, optionally filtered
66
---
77

8-
The `lsa` macro returns a list of absolute paths for the files in the given directory. The optional selectors can be used to filter the result.
8+
## Summary
99

10-
lsa ; <dir> [ ; <selector> ] *
10+
The `lsa` macro returns a comma-separated list of absolute file paths from a directory, with optional filtering using selectors.
11+
12+
## Syntax
13+
14+
```
15+
${lsa;<directory>[;<selector>...]}
16+
```
17+
18+
## Parameters
19+
20+
- `directory` - Directory path to list (relative to project base)
21+
- `selector` (optional) - One or more file selectors/patterns to filter results
22+
23+
## Behavior
24+
25+
- Lists files in the specified directory
26+
- Returns absolute paths
27+
- Optional filtering with selectors
28+
- Comma-separated output
29+
- Non-recursive (single directory level)
30+
31+
## Examples
32+
33+
List all files:
34+
```
35+
${lsa;src/main/java}
36+
# Returns absolute paths
37+
```
38+
39+
Filter by pattern:
40+
```
41+
${lsa;lib;*.jar}
42+
# Lists all JAR files with absolute paths
43+
```
44+
45+
Multiple filters:
46+
```
47+
${lsa;resources;*.xml;*.properties}
48+
```
49+
50+
Use in manifest:
51+
```
52+
Resources: ${lsa;config}
53+
```
54+
55+
## Use Cases
56+
57+
- File discovery with absolute paths
58+
- Build input collection
59+
- Resource gathering
60+
- File listing for processing
61+
- Dependency collection
62+
63+
## Notes
64+
65+
- Returns absolute paths
66+
- Non-recursive listing
67+
- Selectors use file patterns
68+
- See also: `${lsr}` for relative paths
69+
- See also: `${glob}` for pattern matching
70+
- See also: `${findfile}` for recursive search

docs/_macros/lsr.md

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,70 @@
22
layout: default
33
class: Macro
44
title: lsr ';' DIR (';' SELECTORS )
5-
summary: A list of file names in the given directory optionally filtered by selectors.
5+
summary: List files with relative paths, optionally filtered
66
---
77

8-
The `lsr` macro returns a list of file names in the given directory. The optional selectors can be used to filter the result.
8+
## Summary
99

10-
lsr ; <dir> [ ; <selector> ] *
10+
The `lsr` macro returns a comma-separated list of relative file paths from a directory, with optional filtering using selectors.
11+
12+
## Syntax
13+
14+
```
15+
${lsr;<directory>[;<selector>...]}
16+
```
17+
18+
## Parameters
19+
20+
- `directory` - Directory path to list (relative to project base)
21+
- `selector` (optional) - One or more file selectors/patterns to filter results
22+
23+
## Behavior
24+
25+
- Lists files in the specified directory
26+
- Returns relative paths (from the directory)
27+
- Optional filtering with selectors
28+
- Comma-separated output
29+
- Recursive by default
30+
31+
## Examples
32+
33+
List all files:
34+
```
35+
${lsr;src/main/java}
36+
# Returns relative paths
37+
```
38+
39+
Filter by pattern:
40+
```
41+
${lsr;lib;*.jar}
42+
# Lists all JAR files with relative paths
43+
```
44+
45+
Find source files:
46+
```
47+
${lsr;src;*.java}
48+
# All Java source files
49+
```
50+
51+
Multiple patterns:
52+
```
53+
${lsr;resources;*.xml;*.properties}
54+
```
55+
56+
## Use Cases
57+
58+
- File discovery with relative paths
59+
- Source file collection
60+
- Resource listing
61+
- Build inputs
62+
- Pattern-based file selection
63+
64+
## Notes
65+
66+
- Returns relative paths
67+
- Recursive listing
68+
- Selectors use file patterns
69+
- See also: `${lsa}` for absolute paths
70+
- See also: `${glob}` for pattern matching
71+
- See also: `${findfile}` for filtered recursive search

docs/_macros/replace.md

Lines changed: 64 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,75 @@
22
layout: default
33
class: Macro
44
title: replace ';' LIST ';' REGEX (';' STRING (';' STRING)? )?
5-
summary: Replace elements in a list when it matches a regular expression
5+
summary: Replace parts of list elements using regex patterns
66
---
77

8-
replace ; <list> ; <regex> [ ; <replacement> [ ; <delimiter> ] ]
8+
## Summary
99

10-
Replace all parts within elements of the list that match the regular expression regex with the replacement. The `replace` macro uses a simple splitter, the regular expression `\s*,\s*`, to split the list into elements. So any comma in the input list will be use to split the list into elements. See [replacelist](replacelist.html) for an equivalent macro which has a more sophisticated splitter which takes quoted sections of the string into account.
10+
The `replace` macro applies regex-based replacement to each element in a comma-separated list. Uses simple comma splitting (doesn't handle quoted sections).
1111

12-
The replacement can use the `$[0-9]` back references defined in the regular expressions. The macro uses `element.replaceAll(regex,replacement)` method to do the replacement. The default replacement is the empty string. The default delimiter is ",".
12+
## Syntax
13+
14+
```
15+
${replace;<list>;<regex>[;<replacement>[;<delimiter>]]}
16+
```
17+
18+
## Parameters
19+
20+
- `list` - Comma-separated list of elements
21+
- `regex` - Regular expression pattern to match
22+
- `replacement` (optional) - Replacement string with `$1-$9` back-references (default: empty)
23+
- `delimiter` (optional) - Output delimiter (default: ",")
24+
25+
## Behavior
26+
27+
- Splits list on commas (simple: `\s*,\s*`)
28+
- Applies `element.replaceAll(regex, replacement)` to each
29+
- Supports regex back-references (`$1`, `$2`, etc.)
30+
- Cannot handle commas within quoted sections
31+
- Returns delimited result
1332

1433
## Examples
1534

16-
impls: foo,bar
17-
${replace;${impls};$;.jar} => foo.jar,bar.jar
35+
Add file extension:
36+
```
37+
impls: foo,bar
38+
${replace;${impls};$;.jar}
39+
# Returns: "foo.jar,bar.jar"
40+
```
41+
42+
Replace pattern:
43+
```
44+
${replace;v1.0,v2.0,v3.0;^v;version-}
45+
# Returns: "version-1.0,version-2.0,version-3.0"
46+
```
47+
48+
Using back-references:
49+
```
50+
${replace;com.example.api,com.example.impl;com\.example\.(.+);$1}
51+
# Returns: "api,impl"
52+
```
53+
54+
Custom delimiter:
55+
```
56+
${replace;a,b,c;$;-suffix;;}
57+
# Returns: "a-suffix;b-suffix;c-suffix"
58+
```
59+
60+
## Use Cases
61+
62+
- Adding prefixes/suffixes to list elements
63+
- Pattern-based transformations
64+
- File extension handling
65+
- List element modification
66+
- Bulk string operations
67+
68+
## Notes
69+
70+
- Simple comma splitting only
71+
- For quoted sections, use `${replacelist}`
72+
- Regex uses Java syntax
73+
- Empty replacement removes matched text
74+
- See also: `${replacelist}` for quoted section support
75+
- See also: `${replacestring}` for single string replacement
1876

docs/_macros/replacelist.md

Lines changed: 57 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,68 @@
22
layout: default
33
class: Macro
44
title: replacelist ';' LIST ';' REGEX (';' STRING (';' STRING)? )?
5-
summary: Replace elements in a list when it matches a regular expression
5+
summary: Replace parts of list elements using regex with quoted section support
66
---
77

8-
replacelist ; <list> ; <regex> [ ; <replacement> [ ; <delimiter> ] ]
8+
## Summary
99

10-
Replace all parts within elements of the list that match the regular expression regex with the replacement. The `replacelist` macro uses a sophisticated splitter to split the list into elements. This splitter understands quoted sections within the list and does not split on commas inside the quoted sections.
10+
The `replacelist` macro applies regex-based replacement to each element in a list. Unlike `${replace}`, it uses a sophisticated splitter that handles quoted sections, preserving commas within quotes.
1111

12-
The replacement can use the `$[0-9]` back references defined in the regular expressions. The macro uses `element.replaceAll(regex,replacement)` method to do the replacement. The default replacement is the empty string. The default delimiter is ",".
12+
## Syntax
13+
14+
```
15+
${replacelist;<list>;<regex>[;<replacement>[;<delimiter>]]}
16+
```
17+
18+
## Parameters
19+
20+
- `list` - List of elements (can contain quoted sections with commas)
21+
- `regex` - Regular expression pattern to match
22+
- `replacement` (optional) - Replacement string with `$1-$9` back-references (default: empty)
23+
- `delimiter` (optional) - Output delimiter (default: ",")
24+
25+
## Behavior
26+
27+
- Splits list intelligently (respects quoted sections)
28+
- Applies `element.replaceAll(regex, replacement)` to each
29+
- Supports regex back-references (`$1`, `$2`, etc.)
30+
- Preserves quoted sections during splitting
31+
- Returns delimited result
1332

1433
## Examples
1534

16-
impls: foo;version="[1,2)", bar;version="[1.2,2)"
17-
${replacelist;${list;impls};$;\\;strategy=highest} =>
18-
foo;version="[1,2)";strategy=highest,bar;version="[1.2,2)";strategy=highest
35+
Add to quoted elements:
36+
```
37+
impls: foo;version="[1,2)", bar;version="[1.2,2)"
38+
${replacelist;${list;impls};$;\\;strategy=highest}
39+
# Returns: foo;version="[1,2)";strategy=highest,bar;version="[1.2,2)";strategy=highest
40+
```
41+
42+
Process dependencies:
43+
```
44+
deps: lib;version="1.0,2.0",tool;version="2.0"
45+
${replacelist;${deps};$;,optional}
46+
```
47+
48+
Back-references with quotes:
49+
```
50+
${replacelist;a="x,y",b="z";(.+)="(.+)";$1:$2}
51+
```
52+
53+
## Use Cases
54+
55+
- OSGi manifest attribute manipulation
56+
- Dependency list processing
57+
- Version range handling
58+
- Complex list transformations
59+
- Preserving structured data
60+
61+
## Notes
62+
63+
- Handles quoted sections properly
64+
- More robust than `${replace}` for OSGi attributes
65+
- Regex uses Java syntax
66+
- Empty replacement removes matched text
67+
- See also: `${replace}` for simple splitting
68+
- See also: `${replacestring}` for single strings
1969

0 commit comments

Comments
 (0)