use of com.google.common.base.Splitter in project gerrit by GerritCodeReview.
the class ChangeField method getDirectories.
public static Set<String> getDirectories(ChangeData cd) {
List<String> paths = cd.currentFilePaths();
Splitter s = Splitter.on('/').omitEmptyStrings();
Set<String> r = new HashSet<>();
for (String path : paths) {
StringBuilder directory = new StringBuilder();
r.add(directory.toString());
String nextPart = null;
for (String part : s.split(path.toLowerCase(Locale.US))) {
if (nextPart != null) {
r.add(nextPart);
if (directory.length() > 0) {
directory.append("/");
}
directory.append(nextPart);
String intermediateDir = directory.toString();
int i = intermediateDir.indexOf('/');
while (i >= 0) {
r.add(intermediateDir);
intermediateDir = intermediateDir.substring(i + 1);
i = intermediateDir.indexOf('/');
}
}
nextPart = part;
}
}
return r;
}
use of com.google.common.base.Splitter in project gerrit by GerritCodeReview.
the class SchemaUtil method getNameParts.
public static Set<String> getNameParts(String name, Iterable<String> emails) {
Splitter at = Splitter.on('@');
Splitter s = Splitter.on(CharMatcher.anyOf("@.- /_")).omitEmptyStrings();
HashSet<String> parts = new HashSet<>();
for (String email : emails) {
if (email == null) {
continue;
}
String lowerEmail = email.toLowerCase(Locale.US);
parts.add(lowerEmail);
Iterables.addAll(parts, at.split(lowerEmail));
Iterables.addAll(parts, s.split(lowerEmail));
}
if (name != null) {
Iterables.addAll(parts, s.split(name.toLowerCase(Locale.US)));
}
return parts;
}
use of com.google.common.base.Splitter in project gerrit by GerritCodeReview.
the class ChangeEmail method getDiffTemplateData.
/**
* Generate a list of maps representing each line of the unified diff. The line maps will have a
* 'type' key which maps to one of 'common', 'add' or 'remove' and a 'text' key which maps to the
* line's content.
*
* @param sourceDiff the unified diff that we're converting to the map.
* @return map of 'type' to a line's content.
*/
protected static ImmutableList<ImmutableMap<String, String>> getDiffTemplateData(String sourceDiff) {
ImmutableList.Builder<ImmutableMap<String, String>> result = ImmutableList.builder();
Splitter lineSplitter = Splitter.on(System.getProperty("line.separator"));
for (String diffLine : lineSplitter.split(sourceDiff)) {
ImmutableMap.Builder<String, String> lineData = ImmutableMap.builder();
lineData.put("text", diffLine);
// Skip empty lines and lines that look like diff headers.
if (diffLine.isEmpty() || diffLine.startsWith("---") || diffLine.startsWith("+++")) {
lineData.put("type", "common");
} else {
switch(diffLine.charAt(0)) {
case '+':
lineData.put("type", "add");
break;
case '-':
lineData.put("type", "remove");
break;
default:
lineData.put("type", "common");
break;
}
}
result.add(lineData.build());
}
return result.build();
}
use of com.google.common.base.Splitter in project unleash-maven-plugin by shillner.
the class AbstractUnleashMojo method getReleaseArgs.
@MojoProduces
@Named("releaseArgs")
@MojoInject
private Properties getReleaseArgs(Log log) {
Properties args = new Properties();
Splitter splitter = Splitter.on('=');
for (String arg : this.releaseArgs) {
List<String> split = splitter.splitToList(arg);
if (split.size() == 2) {
args.put(split.get(0), split.get(1));
} else {
log.warn("Could not set '" + arg + "' as a Property for the Maven release build.");
}
}
// Add default property indicating that the unleash plugin is triggering the build
args.put("isUnleashBuild", "true");
return args;
}
use of com.google.common.base.Splitter in project graylog2-server by Graylog2.
the class KeyValue method evaluate.
@Override
public Map<String, String> evaluate(FunctionArgs args, EvaluationContext context) {
final String value = valueParam.required(args, context);
if (Strings.isNullOrEmpty(value)) {
return null;
}
final CharMatcher kvPairsMatcher = splitParam.optional(args, context).orElse(CharMatcher.whitespace());
final CharMatcher kvDelimMatcher = valueSplitParam.optional(args, context).orElse(CharMatcher.anyOf("="));
Splitter outerSplitter = Splitter.on(DelimiterCharMatcher.withQuoteHandling(kvPairsMatcher)).omitEmptyStrings().trimResults();
final Splitter entrySplitter = Splitter.on(kvDelimMatcher).omitEmptyStrings().limit(2).trimResults();
return new MapSplitter(outerSplitter, entrySplitter, ignoreEmptyValuesParam.optional(args, context).orElse(true), trimCharactersParam.optional(args, context).orElse(CharMatcher.none()), trimValueCharactersParam.optional(args, context).orElse(CharMatcher.none()), allowDupeKeysParam.optional(args, context).orElse(true), duplicateHandlingParam.optional(args, context).orElse("take_first")).split(value);
}
Aggregations