Search in sources :

Example 86 with CheckForNull

use of javax.annotation.CheckForNull in project sonarqube by SonarSource.

the class AbstractDbTester method pkOf.

@CheckForNull
private PK pkOf(Connection connection, String tableName) throws SQLException {
    try (ResultSet resultSet = connection.getMetaData().getPrimaryKeys(null, null, tableName)) {
        String pkName = null;
        ArrayList<String> columnNames = null;
        while (resultSet.next()) {
            if (columnNames == null) {
                pkName = resultSet.getString("PK_NAME");
                columnNames = new ArrayList<>(1);
            } else {
                assertThat(pkName).as("Multiple primary keys found").isEqualTo(resultSet.getString("PK_NAME"));
            }
            columnNames.add(resultSet.getInt("KEY_SEQ") - 1, resultSet.getString("COLUMN_NAME"));
        }
        if (columnNames == null) {
            return null;
        }
        return new PK(pkName, columnNames);
    }
}
Also used : ResultSet(java.sql.ResultSet) CheckForNull(javax.annotation.CheckForNull)

Example 87 with CheckForNull

use of javax.annotation.CheckForNull in project sonarqube by SonarSource.

the class AbstractDbTester method getColumnIndex.

@CheckForNull
private Integer getColumnIndex(ResultSet res, String column) {
    try {
        ResultSetMetaData meta = res.getMetaData();
        int numCol = meta.getColumnCount();
        for (int i = 1; i < numCol + 1; i++) {
            if (meta.getColumnLabel(i).toLowerCase().equals(column.toLowerCase())) {
                return i;
            }
        }
        return null;
    } catch (Exception e) {
        throw new IllegalStateException("Fail to get column index");
    }
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) SQLException(java.sql.SQLException) DatabaseUnitException(org.dbunit.DatabaseUnitException) CheckForNull(javax.annotation.CheckForNull)

Example 88 with CheckForNull

use of javax.annotation.CheckForNull in project sonarqube by SonarSource.

the class AppFileSystemTest method getFileKey.

@CheckForNull
private static Object getFileKey(File fileInTempDir) throws IOException {
    Path path = Paths.get(fileInTempDir.toURI());
    BasicFileAttributes attrs = Files.readAttributes(path, BasicFileAttributes.class);
    return attrs.fileKey();
}
Also used : Path(java.nio.file.Path) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) CheckForNull(javax.annotation.CheckForNull)

Example 89 with CheckForNull

use of javax.annotation.CheckForNull in project sonarqube by SonarSource.

the class FilterParser method tryParsingCriterionNotHavingValues.

@CheckForNull
private static Criterion tryParsingCriterionNotHavingValues(String criterion) {
    Matcher matcher = PATTERN.matcher(criterion);
    if (!matcher.find()) {
        return null;
    }
    Criterion.Builder builder = new Criterion.Builder();
    builder.setKey(matcher.group(1));
    String operatorValue = matcher.group(2);
    String value = matcher.group(3);
    if (!isNullOrEmpty(operatorValue) && !isNullOrEmpty(value)) {
        builder.setOperator(Operator.getByValue(operatorValue));
        builder.setValue(sanitizeValue(value));
    }
    return builder.build();
}
Also used : Matcher(java.util.regex.Matcher) CheckForNull(javax.annotation.CheckForNull)

Example 90 with CheckForNull

use of javax.annotation.CheckForNull in project sonarqube by SonarSource.

the class CommonRule method processFile.

@CheckForNull
public DefaultIssue processFile(Component file, String fileLanguage) {
    DefaultIssue issue = null;
    RuleKey ruleKey = RuleKey.of(commonRepositoryForLang(fileLanguage), key);
    Optional<ActiveRule> activeRule = activeRulesHolder.get(ruleKey);
    if (activeRule.isPresent()) {
        CommonRuleIssue cri = doProcessFile(file, activeRule.get());
        if (cri != null) {
            issue = new DefaultIssue();
            issue.setGap(cri.effortToFix);
            issue.setMessage(cri.message);
            issue.setRuleKey(ruleKey);
            issue.setSeverity(activeRule.get().getSeverity());
            issue.setLine(null);
            issue.setChecksum("");
        }
    }
    return issue;
}
Also used : RuleKey(org.sonar.api.rule.RuleKey) ActiveRule(org.sonar.server.computation.task.projectanalysis.qualityprofile.ActiveRule) DefaultIssue(org.sonar.core.issue.DefaultIssue) CheckForNull(javax.annotation.CheckForNull)

Aggregations

CheckForNull (javax.annotation.CheckForNull)149 IOException (java.io.IOException)18 Tree (org.apache.jackrabbit.oak.api.Tree)16 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)12 ArrayList (java.util.ArrayList)9 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)9 Stopwatch (com.google.common.base.Stopwatch)8 UnsupportedCallbackException (javax.security.auth.callback.UnsupportedCallbackException)8 Date (java.util.Date)7 SnapshotDto (org.sonar.db.component.SnapshotDto)7 Period (org.sonar.server.computation.task.projectanalysis.period.Period)7 File (java.io.File)6 SQLException (java.sql.SQLException)6 DocumentStoreException (org.apache.jackrabbit.oak.plugins.document.DocumentStoreException)6 ExecutionException (java.util.concurrent.ExecutionException)5 ValidationModel (org.apache.sling.validation.model.ValidationModel)5 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)4 Root (org.apache.jackrabbit.oak.api.Root)4 Utils.resolveCommitRevision (org.apache.jackrabbit.oak.plugins.document.util.Utils.resolveCommitRevision)4 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)4