-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e67d6d0
commit 93a9894
Showing
3 changed files
with
171 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/main/groovy/com/rundeck/plugins/ansible/util/YamlUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.rundeck.plugins.ansible.util; | ||
|
||
import org.apache.commons.lang.StringUtils; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* A utility class providing helper methods for working with YAML data. | ||
*/ | ||
public class YamlUtil { | ||
|
||
public static final String ALIASES = "aliases"; | ||
public static final String ALIAS_MATCH = "<<:"; | ||
|
||
/** | ||
* Checks for aliases and anchors within the provided YAML content and returns a map of alias occurrences. | ||
* | ||
* @param content The YAML content string to analyze for aliases and anchors. | ||
* @return A map where keys are alias names and values are their corresponding counts within the content. | ||
*/ | ||
public static Map<String, Integer> checkAliasesAndAnchors(String content) { | ||
Map<String, Integer> resp = new HashMap<>(); | ||
int total = countAliases(content); | ||
resp.put(ALIASES, total); | ||
return resp; | ||
} | ||
|
||
/** | ||
* Counts the number of aliases within the provided YAML content string. | ||
* | ||
* @param content The YAML content string to analyze for aliases. | ||
* @return The total number of aliases found in the content. | ||
*/ | ||
private static int countAliases(String content) { | ||
return StringUtils.countMatches(content, ALIAS_MATCH); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters