Example usage for org.apache.commons.lang StringUtils defaultIfBlank

List of usage examples for org.apache.commons.lang StringUtils defaultIfBlank

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils defaultIfBlank.

Prototype

public static String defaultIfBlank(String str, String defaultStr) 

Source Link

Document

Returns either the passed in String, or if the String is whitespace, empty ("") or null, the value of defaultStr.

Usage

From source file:org.sonar.batch.bootstrap.ProjectTempFolderProvider.java

public TempFolder provide(AnalysisProperties props) {
    if (projectTempFolder == null) {
        String workingDirPath = StringUtils.defaultIfBlank(props.property(CoreProperties.WORKING_DIRECTORY),
                CoreProperties.WORKING_DIRECTORY_DEFAULT_VALUE);
        Path workingDir = Paths.get(workingDirPath).normalize();

        if (!workingDir.isAbsolute()) {
            Path base = getBasePath(props);
            workingDir = base.resolve(workingDir);
        }/*  ww w . ja  v  a  2  s.  c om*/

        Path tempDir = workingDir.resolve(TMP_NAME);
        try {
            Files.createDirectories(tempDir);
        } catch (IOException e) {
            throw new IllegalStateException("Unable to create root temp directory " + tempDir, e);
        }
        projectTempFolder = new DefaultTempFolder(tempDir.toFile(), true);
        this.instance = projectTempFolder;
    }
    return projectTempFolder;
}

From source file:org.sonar.batch.bootstrap.TempFolderProvider.java

public TempFolder provide(BootstrapProperties bootstrapProps) {
    if (tempFolder == null) {
        String workingDirPath = StringUtils.defaultIfBlank(
                bootstrapProps.property(CoreProperties.WORKING_DIRECTORY),
                CoreProperties.WORKING_DIRECTORY_DEFAULT_VALUE);
        File workingDir = new File(workingDirPath).getAbsoluteFile();
        File tempDir = new File(workingDir, ".sonartmp");
        try {/*from w w  w .  java  2  s.c  o  m*/
            FileUtils.forceMkdir(tempDir);
        } catch (IOException e) {
            throw new IllegalStateException("Unable to create root temp directory " + tempDir, e);
        }
        tempFolder = new DefaultTempFolder(tempDir);
    }
    return tempFolder;
}

From source file:org.sonar.batch.bootstrapper.LoggingConfiguration.java

public LoggingConfiguration setFormat(String format) {
    return addSubstitutionVariable(PROPERTY_FORMAT, StringUtils.defaultIfBlank(format, FORMAT_DEFAULT));
}

From source file:org.sonar.batch.bootstrapper.LoggingConfigurator.java

private static void setCustomRootAppender(LoggingConfiguration conf) {
    Logger logger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
    String level = StringUtils.defaultIfBlank(
            conf.getSubstitutionVariables().get(LoggingConfiguration.PROPERTY_ROOT_LOGGER_LEVEL),
            LoggingConfiguration.LEVEL_ROOT_DEFAULT);

    if (logger.getAppender(CUSTOM_APPENDER_NAME) == null) {
        logger.detachAndStopAllAppenders();
        logger.addAppender(createAppender(conf.getLogOutput()));
    }/*from   w  w  w.  jav a2 s.  com*/
    logger.setLevel(Level.toLevel(level));
}

From source file:org.sonar.batch.cache.GlobalPersistentCacheProvider.java

private static String getServerUrl(GlobalProperties props) {
    return StringUtils.removeEnd(
            StringUtils.defaultIfBlank(props.property("sonar.host.url"), "http://localhost:9000"), "/");
}

From source file:org.sonar.batch.DefaultProfileLoader.java

public RulesProfile load(Project project) {
    String profileName = StringUtils.defaultIfBlank(settings.getString("sonar.profile"),
            settings.getString("sonar.profile." + project.getLanguageKey()));

    if (StringUtils.isBlank(profileName)) {
        // This means that the current language is not supported by any installed plugin, otherwise at least a
        // "Default <Language Name>" profile would have been created by ActivateDefaultProfiles class.
        throw new SonarException(
                "You must install a plugin that supports the language '" + project.getLanguageKey() + "'");
    }/*from  w  ww.  j  a  va2 s .c om*/

    RulesProfile profile = dao.getProfile(project.getLanguageKey(), profileName);
    if (profile == null) {
        throw new SonarException(
                "Quality profile not found : " + profileName + ", language " + project.getLanguageKey());
    }

    return hibernateHack(profile);
}

From source file:org.sonar.batch.issue.ignore.pattern.AbstractPatternInitializer.java

@VisibleForTesting
protected final void initPatterns() {
    // Patterns Multicriteria
    multicriteriaPatterns = Lists.newArrayList();
    String patternConf = StringUtils.defaultIfBlank(settings.getString(getMulticriteriaConfigurationKey()), "");
    for (String id : StringUtils.split(patternConf, ',')) {
        String propPrefix = getMulticriteriaConfigurationKey() + "." + id + ".";
        String resourceKeyPattern = settings.getString(propPrefix + "resourceKey");
        String ruleKeyPattern = settings.getString(propPrefix + "ruleKey");
        String lineRange = "*";
        String[] fields = new String[] { resourceKeyPattern, ruleKeyPattern, lineRange };
        PatternDecoder.checkRegularLineConstraints(StringUtils.join(fields, ","), fields);
        IssuePattern pattern = new IssuePattern(firstNonNull(resourceKeyPattern, "*"),
                firstNonNull(ruleKeyPattern, "*"));
        PatternDecoder.decodeRangeOfLines(pattern, firstNonNull(lineRange, "*"));
        multicriteriaPatterns.add(pattern);
    }//  w w w . j av a 2 s .  co m
}

From source file:org.sonar.batch.issue.ignore.pattern.IssueExclusionPatternInitializer.java

@VisibleForTesting
protected final void loadFileContentPatterns() {
    // Patterns Block
    blockPatterns = Lists.newArrayList();
    String patternConf = StringUtils
            .defaultIfBlank(getSettings().getString(IssueExclusionProperties.PATTERNS_BLOCK_KEY), "");
    for (String id : StringUtils.split(patternConf, ',')) {
        String propPrefix = IssueExclusionProperties.PATTERNS_BLOCK_KEY + "." + id + ".";
        String beginBlockRegexp = getSettings()
                .getString(propPrefix + IssueExclusionProperties.BEGIN_BLOCK_REGEXP);
        String endBlockRegexp = getSettings().getString(propPrefix + IssueExclusionProperties.END_BLOCK_REGEXP);
        String[] fields = new String[] { beginBlockRegexp, endBlockRegexp };
        PatternDecoder.checkDoubleRegexpLineConstraints(StringUtils.join(fields, ","), fields);
        IssuePattern pattern = new IssuePattern().setBeginBlockRegexp(nullToEmpty(beginBlockRegexp))
                .setEndBlockRegexp(nullToEmpty(endBlockRegexp));
        blockPatterns.add(pattern);/* w  ww.  j av  a 2  s  .c  om*/
    }

    // Patterns All File
    allFilePatterns = Lists.newArrayList();
    patternConf = StringUtils
            .defaultIfBlank(getSettings().getString(IssueExclusionProperties.PATTERNS_ALLFILE_KEY), "");
    for (String id : StringUtils.split(patternConf, ',')) {
        String propPrefix = IssueExclusionProperties.PATTERNS_ALLFILE_KEY + "." + id + ".";
        String allFileRegexp = getSettings().getString(propPrefix + IssueExclusionProperties.FILE_REGEXP);
        PatternDecoder.checkWholeFileRegexp(allFileRegexp);
        IssuePattern pattern = new IssuePattern().setAllFileRegexp(nullToEmpty(allFileRegexp));
        allFilePatterns.add(pattern);
    }
}

From source file:org.sonar.batch.platform.DefaultServer.java

@Override
public String getURL() {
    return StringUtils.removeEnd(
            StringUtils.defaultIfBlank(props.property("sonar.host.url"), "http://localhost:9000"), "/");
}

From source file:org.sonar.batch.profiling.PhasesSumUpTimeProfiler.java

public PhasesSumUpTimeProfiler(System2 system, GlobalProperties bootstrapProps) {
    String workingDirPath = StringUtils.defaultIfBlank(
            bootstrapProps.property(CoreProperties.WORKING_DIRECTORY),
            CoreProperties.WORKING_DIRECTORY_DEFAULT_VALUE);
    File workingDir = new File(workingDirPath).getAbsoluteFile();
    this.out = new File(workingDir, "profiling");
    this.out.mkdirs();
    this.totalProfiling = new ModuleProfiling(null, system);
    this.system = system;
}