Example usage for org.apache.commons.text.matcher StringMatcherFactory INSTANCE

List of usage examples for org.apache.commons.text.matcher StringMatcherFactory INSTANCE

Introduction

In this page you can find the example usage for org.apache.commons.text.matcher StringMatcherFactory INSTANCE.

Prototype

StringMatcherFactory INSTANCE

To view the source code for org.apache.commons.text.matcher StringMatcherFactory INSTANCE.

Click Source Link

Document

Defines the singleton for this class.

Usage

From source file:com.blackducksoftware.integration.hub.detect.detector.clang.ClangCompileCommandParser.java

public List<String> getCompilerArgsForGeneratingDepsMkFile(final String origCompileCommand,
        final String depsMkFilePath, final Map<String, String> optionOverrides) {
    logger.trace(String.format("origCompileCommand         : %s", origCompileCommand));
    String quotesRemovedCompileCommand = escapeQuotedWhitespace(origCompileCommand.trim());
    logger.trace(String.format("quotesRemovedCompileCommand: %s", quotesRemovedCompileCommand));
    StringTokenizer tokenizer = new StringTokenizer(quotesRemovedCompileCommand);
    tokenizer.setQuoteMatcher(StringMatcherFactory.INSTANCE.quoteMatcher());
    final List<String> argList = new ArrayList<>();
    String lastPart = "";
    int partIndex = 0;
    while (tokenizer.hasNext()) {
        String part = unEscapeDoubleQuotes(restoreWhitespace(tokenizer.nextToken()));
        if (partIndex > 0) {
            String optionValueOverride = null;
            for (String optionToOverride : optionOverrides.keySet()) {
                if (optionToOverride.equals(lastPart)) {
                    optionValueOverride = optionOverrides.get(optionToOverride);
                }/* w w w .ja  v a 2  s  .  co  m*/
            }
            if (optionValueOverride != null) {
                argList.add(optionValueOverride);
            } else {
                argList.add(part);
            }
        }
        lastPart = part;
        partIndex++;
    }
    argList.add("-M");
    argList.add("-MF");
    argList.add(depsMkFilePath);
    return argList;
}

From source file:org.lenskit.gradle.LenskitPlugin.java

public void apply(Project project) {
    final LenskitExtension lenskit = project.getExtensions().create("lenskit", LenskitExtension.class, project);

    for (MetaProperty prop : DefaultGroovyMethods.getMetaClass(lenskit).getProperties()) {
        String prjProp = "lenskit." + prop.getName();
        if (project.hasProperty(prjProp)) {
            Object val = project.findProperty(prjProp);
            String vstr = val != null ? val.toString() : null;
            logger.info("setting property {} to {}", prjProp, val);
            Class type = prop.getType();
            Consumer<Object> set = (v) -> prop.setProperty(lenskit, v);
            if (type.equals(Property.class)) {
                Method m = null;// w w w. j a v a2  s  .  c  o  m
                try {
                    m = lenskit.getClass().getMethod("get" + StringUtils.capitalize(prop.getName()));
                } catch (NoSuchMethodException e) {
                    throw new RuntimeException(e);
                }
                Type t = m.getGenericReturnType();
                Map<TypeVariable<?>, Type> args = TypeUtils.getTypeArguments(t, Property.class);
                Type rt = args.get(Property.class.getTypeParameters()[0]);
                type = TypeUtils.getRawType(rt, Object.class);
                set = (v) -> ((Property) prop.getProperty(lenskit)).set(v);
            }

            if (type.equals(List.class)) {// if the type is list update the val using strtokenizer
                StringTokenizer tok = new StringTokenizer(vstr, StringMatcherFactory.INSTANCE.splitMatcher(),
                        StringMatcherFactory.INSTANCE.quoteMatcher());
                val = DefaultGroovyMethods.toList(tok);
            } else if (type.equals(String.class)) {
                val = vstr;
            } else {
                val = StringConvert.INSTANCE.convertFromString(type, vstr);
            }

            set.accept(val);
        }

    }

}