Search in sources :

Example 21 with CheckForNull

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

the class Request method paramAsDateTime.

@CheckForNull
public Date paramAsDateTime(String key) {
    String stringDate = param(key);
    if (stringDate == null) {
        return null;
    }
    Date date = parseDateTimeQuietly(stringDate);
    if (date != null) {
        return date;
    }
    date = parseDateQuietly(stringDate);
    checkArgument(date != null, "'%s' cannot be parsed as either a date or date+time", stringDate);
    return date;
}
Also used : Date(java.util.Date) CheckForNull(javax.annotation.CheckForNull)

Example 22 with CheckForNull

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

the class DateUtils method parseDateOrDateTime.

/**
   * @throws IllegalArgumentException if stringDate is not a correctly formed date or datetime
   * @return the datetime, {@code null} if stringDate is null
   * @since 6.1
   */
@CheckForNull
public static Date parseDateOrDateTime(@Nullable String stringDate) {
    if (stringDate == null) {
        return null;
    }
    Date date = parseDateTimeQuietly(stringDate);
    if (date != null) {
        return date;
    }
    date = parseDateQuietly(stringDate);
    checkArgument(date != null, "Date '%s' cannot be parsed as either a date or date+time", stringDate);
    return date;
}
Also used : Date(java.util.Date) CheckForNull(javax.annotation.CheckForNull)

Example 23 with CheckForNull

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

the class SensorContextTester method referencesForSymbolAt.

/**
   * Return list of symbol references ranges for the symbol at a given position in a file.
   * @param componentKey Key of the file like 'myProjectKey:src/foo.php'
   * @param line Line you want to query
   * @param lineOffset Offset you want to query.
   * @return List of references for the symbol (potentially empty) or null if there is no symbol at this position.
   */
@CheckForNull
public Collection<TextRange> referencesForSymbolAt(String componentKey, int line, int lineOffset) {
    DefaultSymbolTable symbolTable = sensorStorage.symbolsPerComponent.get(componentKey);
    if (symbolTable == null) {
        return null;
    }
    DefaultTextPointer location = new DefaultTextPointer(line, lineOffset);
    for (Map.Entry<TextRange, Set<TextRange>> symbol : symbolTable.getReferencesBySymbol().entrySet()) {
        if (symbol.getKey().start().compareTo(location) <= 0 && symbol.getKey().end().compareTo(location) > 0) {
            return symbol.getValue();
        }
    }
    return null;
}
Also used : Set(java.util.Set) TextRange(org.sonar.api.batch.fs.TextRange) DefaultSymbolTable(org.sonar.api.batch.sensor.symbol.internal.DefaultSymbolTable) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) DefaultTextPointer(org.sonar.api.batch.fs.internal.DefaultTextPointer) CheckForNull(javax.annotation.CheckForNull)

Example 24 with CheckForNull

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

the class InputFileBuilder method create.

@CheckForNull
DefaultInputFile create(Path file, InputFile.Type type, Charset defaultEncoding) {
    String relativePath = pathResolver.relativePath(moduleBaseDir, file);
    if (relativePath == null) {
        LOG.warn("File '{}' is ignored. It is not located in module basedir '{}'.", file.toAbsolutePath(), moduleBaseDir);
        return null;
    }
    DefaultIndexedFile indexedFile = new DefaultIndexedFile(moduleKey, moduleBaseDir, relativePath, type, idGenerator.get());
    String language = langDetection.language(indexedFile);
    if (language == null && langDetection.forcedLanguage() != null) {
        LOG.warn("File '{}' is ignored because it doens't belong to the forced langauge '{}'", file.toAbsolutePath(), langDetection.forcedLanguage());
        return null;
    }
    indexedFile.setLanguage(language);
    DefaultInputFile inputFile = new DefaultInputFile(indexedFile, f -> metadataGenerator.setMetadata(f, defaultEncoding));
    if (language != null) {
        inputFile.setPublish(true);
    }
    return inputFile;
}
Also used : DefaultIndexedFile(org.sonar.api.batch.fs.internal.DefaultIndexedFile) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) CheckForNull(javax.annotation.CheckForNull)

Example 25 with CheckForNull

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

the class ProjectReactorBuilder method initModuleBuildDir.

@CheckForNull
private static File initModuleBuildDir(File moduleBaseDir, Map<String, String> moduleProperties) {
    String buildDir = moduleProperties.get(PROPERTY_PROJECT_BUILDDIR);
    if (StringUtils.isBlank(buildDir)) {
        return null;
    }
    File customBuildDir = new File(buildDir);
    if (customBuildDir.isAbsolute()) {
        return customBuildDir;
    }
    return new File(moduleBaseDir, customBuildDir.getPath());
}
Also used : File(java.io.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