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.scan.filesystem.LanguageDetection.java

LanguageDetection(Settings settings, LanguagesRepository languages) {
    for (Language language : languages.all()) {
        String[] filePatterns = settings.getStringArray(getFileLangPatternPropKey(language.key()));
        PathPattern[] pathPatterns = PathPattern.create(filePatterns);
        if (pathPatterns.length > 0) {
            patternsByLanguage.put(language.key(), pathPatterns);
        } else {//  www.  j ava2s.  c  o m
            // If no custom language pattern is defined then fallback to suffixes declared by language
            String[] patterns = language.fileSuffixes().toArray(new String[language.fileSuffixes().size()]);
            for (int i = 0; i < patterns.length; i++) {
                String suffix = patterns[i];
                String extension = sanitizeExtension(suffix);
                patterns[i] = new StringBuilder().append("**/*.").append(extension).toString();
            }
            PathPattern[] defaultLanguagePatterns = PathPattern.create(patterns);
            patternsByLanguage.put(language.key(), defaultLanguagePatterns);
            LOG.debug("Declared extensions of language " + language + " were converted to "
                    + getDetails(language.key()));
        }
    }

    forcedLanguage = StringUtils.defaultIfBlank(settings.getString(CoreProperties.PROJECT_LANGUAGE_PROPERTY),
            null);
    // First try with lang patterns
    if (forcedLanguage != null) {
        if (!patternsByLanguage.containsKey(forcedLanguage)) {
            throw MessageException.of("No language is installed with key '" + forcedLanguage
                    + "'. Please update property '" + CoreProperties.PROJECT_LANGUAGE_PROPERTY + "'");
        }
        languagesToConsider.add(forcedLanguage);
    } else {
        languagesToConsider.addAll(patternsByLanguage.keySet());
    }
}

From source file:org.sonar.batch.scan.ProjectReactorBuilder.java

@VisibleForTesting
protected static void checkMandatoryProperties(Map<String, String> props, String[] mandatoryProps) {
    StringBuilder missing = new StringBuilder();
    for (String mandatoryProperty : mandatoryProps) {
        if (!props.containsKey(mandatoryProperty)) {
            if (missing.length() > 0) {
                missing.append(", ");
            }//from  w w  w. j a v  a 2s.  co  m
            missing.append(mandatoryProperty);
        }
    }
    String moduleKey = StringUtils.defaultIfBlank(props.get(MODULE_KEY_PROPERTY),
            props.get(CoreProperties.PROJECT_KEY_PROPERTY));
    if (missing.length() != 0) {
        throw new IllegalStateException("You must define the following mandatory properties for '"
                + (moduleKey == null ? "Unknown" : moduleKey) + "': " + missing);
    }
}

From source file:org.sonar.ce.queue.report.ReportSubmitter.java

@CheckForNull
private ComponentDto createProject(String projectKey, @Nullable String projectBranch,
        @Nullable String projectName) {
    DbSession dbSession = dbClient.openSession(false);
    try {/*from  ww  w . jav a 2s  .c  o  m*/
        boolean wouldCurrentUserHaveScanPermission = permissionService
                .wouldCurrentUserHavePermissionWithDefaultTemplate(dbSession, SCAN_EXECUTION, projectBranch,
                        projectKey, Qualifiers.PROJECT);
        if (!wouldCurrentUserHaveScanPermission) {
            throw insufficientPrivilegesException();
        }

        NewComponent newProject = new NewComponent(projectKey,
                StringUtils.defaultIfBlank(projectName, projectKey));
        newProject.setBranch(projectBranch);
        newProject.setQualifier(Qualifiers.PROJECT);
        // "provisioning" permission is check in ComponentService
        ComponentDto project = componentService.create(dbSession, newProject);
        permissionService.applyDefaultPermissionTemplate(dbSession, project.getKey());
        return project;
    } finally {
        dbClient.closeSession(dbSession);
    }
}

From source file:org.sonar.core.issue.IssueUpdater.java

public boolean assign(DefaultIssue issue, @Nullable String assignee, IssueChangeContext context) {
    String sanitizedAssignee = StringUtils.defaultIfBlank(assignee, null);
    if (!Objects.equal(sanitizedAssignee, issue.assignee())) {
        issue.setFieldChange(context, "assignee", issue.assignee(), sanitizedAssignee);
        issue.setAssignee(sanitizedAssignee);
        issue.setUpdateDate(context.date());
        issue.setChanged(true);/*from  w ww  . j a va 2 s .  c  o m*/
        issue.setSendNotifications(true);
        return true;
    }
    return false;
}

From source file:org.sonar.core.issue.IssueUpdater.java

public boolean plan(DefaultIssue issue, @Nullable String actionPlanKey, IssueChangeContext context) {
    String sanitizedActionPlanKey = StringUtils.defaultIfBlank(actionPlanKey, null);
    if (!Objects.equal(sanitizedActionPlanKey, issue.actionPlanKey())) {
        issue.setFieldChange(context, "actionPlanKey", issue.actionPlanKey(), sanitizedActionPlanKey);
        issue.setActionPlanKey(sanitizedActionPlanKey);
        issue.setUpdateDate(context.date());
        issue.setChanged(true);// w  w w  . j  av  a  2s . c o  m
        issue.setSendNotifications(true);
        return true;
    }
    return false;
}

From source file:org.sonar.core.user.DefaultUser.java

public DefaultUser setEmail(@Nullable String s) {
    this.email = StringUtils.defaultIfBlank(s, null);
    return this;
}

From source file:org.sonar.ide.eclipse.core.internal.jobs.AnalyseProjectJob.java

public AnalyseProjectJob(AnalyseProjectRequest request) {
    super(Messages.AnalyseProjectJob_title);
    this.project = request.getProject();
    this.debugEnabled = request.isDebugEnabled();
    this.incremental = !request.isForceFullPreview();
    this.extraProps = request.getExtraProps();
    this.jvmArgs = StringUtils.defaultIfBlank(request.getJvmArgs(), "");
    this.sonarProject = SonarProject.getInstance(project);
    this.sonarServer = SonarCorePlugin.getServersManager().findServer(sonarProject.getUrl());
    // Prevent modifications of project during analysis
    setRule(ResourcesPlugin.getWorkspace().getRuleFactory().buildRule());
}

From source file:org.sonar.java.resolve.Convert.java

public static String fullName(String packagePart, String className) {
    String pck = StringUtils.defaultIfBlank(packagePart, "");
    if (StringUtils.isNotEmpty(pck)) {
        pck += ".";
    }//  w  w  w .j a  va 2 s. c  om
    return pck + className;
}

From source file:org.sonar.plugins.activedirectory.windows.auth.WindowsAuthSettings.java

/**
 * Returns true if sonar authentication is set to return group names in lowercase.  By default it is set to true.
 *//*from   w ww . j a v a2s .  c  om*/
public boolean getIsSonarAuthenticatorGroupDownCase() {
    String sonarAuthenticatorGroupDownCase = StringUtils.defaultIfBlank(
            settings.getString(LDAP_WINDOWS_GROUP_DOWNCASE),
            Boolean.toString(DEFAULT_SONAR_AUTHENTICATOR_GROUP_DOWNCASE));

    return Boolean.parseBoolean(sonarAuthenticatorGroupDownCase);
}

From source file:org.sonar.plugins.activedirectory.windows.auth.WindowsAuthSettings.java

/**
 * Settings to specify if Ldap Windows compatibility mode is enabled or not.  By default compatibility mode is disabled
 *//*from   ww  w  .j a  va  2 s  .  com*/
public boolean getIsLdapWindowsCompatibilityModeEnabled() {
    String ldapWindowsCompatibilityMode = StringUtils.defaultIfBlank(
            settings.getString(LDAP_WINDOWS_COMPATIBILITY_MODE),
            Boolean.toString(DEFAULT_WINDOWS_COMPATIBILITY_MODE));

    return Boolean.parseBoolean(ldapWindowsCompatibilityMode);
}