Search in sources :

Example 6 with CheckForNull

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

the class FilterParser method tryParsingCriterionHavingValues.

@CheckForNull
private static Criterion tryParsingCriterionHavingValues(String criterion) {
    Matcher matcher = PATTERN_HAVING_VALUES.matcher(criterion);
    if (!matcher.find()) {
        return null;
    }
    Criterion.Builder builder = new Criterion.Builder();
    builder.setKey(matcher.group(1));
    builder.setOperator(Operator.IN);
    builder.setValues(IN_VALUES_SPLITTER.splitToList(matcher.group(3)));
    return builder.build();
}
Also used : Matcher(java.util.regex.Matcher) CheckForNull(javax.annotation.CheckForNull)

Example 7 with CheckForNull

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

the class LoadPeriodsStep method buildPeriod.

@CheckForNull
private Period buildPeriod(Component projectOrView, DbSession session) {
    Optional<ComponentDto> projectDto = dbClient.componentDao().selectByKey(session, projectOrView.getKey());
    // No project on first analysis, no period
    if (!projectDto.isPresent()) {
        return null;
    }
    boolean isReportType = projectOrView.getType().isReportType();
    PeriodResolver periodResolver = new PeriodResolver(dbClient, session, projectDto.get().uuid(), analysisMetadataHolder.getAnalysisDate(), isReportType ? projectOrView.getReportAttributes().getVersion() : null);
    Settings settings = settingsRepository.getSettings(projectOrView);
    Period period = periodResolver.resolve(settings);
    // SONAR-4700 Add a past snapshot only if it exists
    if (period != null) {
        return period;
    }
    return null;
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) Period(org.sonar.server.computation.task.projectanalysis.period.Period) Settings(org.sonar.api.config.Settings) CheckForNull(javax.annotation.CheckForNull)

Example 8 with CheckForNull

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

the class PeriodResolver method findNearestSnapshotToTargetDate.

@CheckForNull
private static SnapshotDto findNearestSnapshotToTargetDate(List<SnapshotDto> snapshots, Long targetDate) {
    long bestDistance = Long.MAX_VALUE;
    SnapshotDto nearest = null;
    for (SnapshotDto snapshot : snapshots) {
        long distance = Math.abs(snapshot.getCreatedAt() - targetDate);
        if (distance <= bestDistance) {
            bestDistance = distance;
            nearest = snapshot;
        }
    }
    return nearest;
}
Also used : SnapshotDto(org.sonar.db.component.SnapshotDto) CheckForNull(javax.annotation.CheckForNull)

Example 9 with CheckForNull

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

the class DebtCalculator method calculate.

@CheckForNull
public Duration calculate(DefaultIssue issue) {
    Rule rule = ruleRepository.getByKey(issue.ruleKey());
    DebtRemediationFunction fn = rule.getRemediationFunction();
    if (fn != null) {
        verifyEffortToFix(issue, fn);
        Duration debt = Duration.create(0);
        String gapMultiplier = fn.gapMultiplier();
        if (fn.type().usesGapMultiplier() && !Strings.isNullOrEmpty(gapMultiplier)) {
            int effortToFixValue = MoreObjects.firstNonNull(issue.effortToFix(), 1).intValue();
            // TODO convert to Duration directly in Rule#remediationFunction -> better performance + error handling
            debt = durations.decode(gapMultiplier).multiply(effortToFixValue);
        }
        String baseEffort = fn.baseEffort();
        if (fn.type().usesBaseEffort() && !Strings.isNullOrEmpty(baseEffort)) {
            // TODO convert to Duration directly in Rule#remediationFunction -> better performance + error handling
            debt = debt.add(durations.decode(baseEffort));
        }
        return debt;
    }
    return null;
}
Also used : DebtRemediationFunction(org.sonar.api.server.debt.DebtRemediationFunction) Duration(org.sonar.api.utils.Duration) CheckForNull(javax.annotation.CheckForNull)

Example 10 with CheckForNull

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

the class FileMoveDetectionStep method getFile.

@CheckForNull
private File getFile(DbSession dbSession, DbComponent dbComponent) {
    if (dbComponent.getPath() == null) {
        return null;
    }
    FileSourceDto fileSourceDto = dbClient.fileSourceDao().selectSourceByFileUuid(dbSession, dbComponent.getUuid());
    if (fileSourceDto == null) {
        return null;
    }
    String lineHashes = firstNonNull(fileSourceDto.getLineHashes(), "");
    return new File(dbComponent.getPath(), LINES_HASHES_SPLITTER.splitToList(lineHashes));
}
Also used : FileSourceDto(org.sonar.db.source.FileSourceDto) File(org.sonar.server.computation.task.projectanalysis.filemove.FileSimilarity.File) 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