Example usage for org.springframework.util StringUtils commaDelimitedListToSet

List of usage examples for org.springframework.util StringUtils commaDelimitedListToSet

Introduction

In this page you can find the example usage for org.springframework.util StringUtils commaDelimitedListToSet.

Prototype

public static Set<String> commaDelimitedListToSet(@Nullable String str) 

Source Link

Document

Convert a comma delimited list (e.g., a row from a CSV file) into a set.

Usage

From source file:org.springframework.yarn.configuration.EnvironmentFactoryBean.java

@Override
public void afterPropertiesSet() throws Exception {
    environment = createEnvironment();//from www .j  a v  a2 s. c  o m

    if (properties != null) {
        // if we have properties, merge those into environment
        CollectionUtils.mergePropertiesIntoMap(properties, environment);
    }

    boolean addDelimiter = false;

    // set CLASSPATH variable if there's something to set
    StringBuilder classPathEnv = new StringBuilder();
    if (StringUtils.hasText(classpath)) {
        classPathEnv.append(classpath);
        addDelimiter = true;
    }

    ArrayList<String> paths = new ArrayList<String>();

    if (includeBaseDirectory) {
        paths.add("./*");
    }

    if (useDefaultYarnClasspath) {
        if (log.isDebugEnabled()) {
            log.debug("Trying to use a default yarn classpath");
        }

        String defaultYarnClasspathString = "";
        if (StringUtils.hasText(defaultYarnAppClasspath)) {
            defaultYarnClasspathString = defaultYarnAppClasspath;
        } else if (configuration != null) {
            defaultYarnClasspathString = configuration.get(YarnConfiguration.YARN_APPLICATION_CLASSPATH);
            if (!StringUtils.hasText(defaultYarnClasspathString)) {
                // 2.3.x changed yarn.application.classpath to be empty in yarn-default.xml, so
                // if we got empty, fall back to DEFAULT_YARN_APPLICATION_CLASSPATH
                defaultYarnClasspathString = StringUtils
                        .arrayToCommaDelimitedString(YarnConfiguration.DEFAULT_YARN_APPLICATION_CLASSPATH);
                log.info("Yarn classpath from configuration empty, fall back to " + defaultYarnClasspathString);
            } else {
                log.info("Yarn classpath from configuration " + defaultYarnClasspathString);
            }
        }
        paths.addAll(StringUtils.commaDelimitedListToSet(defaultYarnClasspathString));
    }

    if (useDefaultMapreduceClasspath) {
        if (log.isDebugEnabled()) {
            log.debug("Trying to use a mr yarn classpath");
        }
        String defaultMapreduceClasspathString = "";
        if (StringUtils.hasText(defaultMapreduceAppClasspath)) {
            defaultMapreduceClasspathString = defaultMapreduceAppClasspath;
        } else if (configuration != null) {
            defaultMapreduceClasspathString = configuration.get("mapreduce.application.classpath");
            if (!StringUtils.hasText(defaultMapreduceClasspathString)) {
                // using reflection with this because we don't have these
                // classes in a project classpath and this is just
                // a fall back for default value
                defaultMapreduceClasspathString = readStaticField("org.apache.hadoop.mapreduce.MRJobConfig",
                        "DEFAULT_MAPREDUCE_APPLICATION_CLASSPATH", getClass().getClassLoader());
                log.info("Mapreduce classpath from configuration empty, fall back to "
                        + defaultMapreduceClasspathString);
            } else {
                log.info("Mapreduce classpath from configuration " + defaultMapreduceClasspathString);
            }
        }
        paths.addAll(StringUtils.commaDelimitedListToSet(defaultMapreduceClasspathString));
    }

    Iterator<String> iterator = paths.iterator();
    // add delimiter if we're about to add something
    if (iterator.hasNext()) {
        classPathEnv.append(addDelimiter ? delimiter : "");
    }
    while (iterator.hasNext()) {
        classPathEnv.append(iterator.next());
        if (iterator.hasNext()) {
            classPathEnv.append(delimiter);
        }
    }

    String classpathString = classPathEnv.toString();
    if (StringUtils.hasText(classpathString)) {
        environment.put("CLASSPATH", classpathString);
        log.info("Adding CLASSPATH=" + classpathString);
    }
}