Search in sources :

Example 1 with CheckForNull

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

the class DeprecatedPropertiesWsTest method getProperty.

@CheckForNull
private static Properties.Property getProperty(WsClient wsClient, String key, @Nullable String componentKey, boolean useIdParameter) throws UnsupportedEncodingException {
    GetRequest getRequest = useIdParameter ? new GetRequest("api/properties").setParam("id", encode(key, "UTF-8")).setParam("resource", componentKey) : new GetRequest("api/properties/" + encode(key, "UTF-8")).setParam("resource", componentKey);
    WsResponse response = wsClient.wsConnector().call(getRequest).failIfNotSuccessful();
    Properties.Property[] properties = Properties.parse(response.content());
    return Arrays.stream(properties).findFirst().orElseGet(() -> null);
}
Also used : GetRequest(org.sonarqube.ws.client.GetRequest) WsResponse(org.sonarqube.ws.client.WsResponse) CheckForNull(javax.annotation.CheckForNull)

Example 2 with CheckForNull

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

the class SettingsTest method getSetting.

@CheckForNull
private static Setting getSetting(String key, SettingsService settingsService) {
    ValuesWsResponse response = settingsService.values(ValuesRequest.builder().setKeys(key).build());
    List<Settings.Setting> settings = response.getSettingsList();
    return settings.isEmpty() ? null : settings.get(0);
}
Also used : ValuesWsResponse(org.sonarqube.ws.Settings.ValuesWsResponse) Setting(org.sonarqube.ws.Settings.Setting) CheckForNull(javax.annotation.CheckForNull)

Example 3 with CheckForNull

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

the class FileSourceDao method selectLineHashes.

@CheckForNull
public List<String> selectLineHashes(DbSession dbSession, String fileUuid) {
    Connection connection = dbSession.getConnection();
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        pstmt = connection.prepareStatement("SELECT line_hashes FROM file_sources WHERE file_uuid=? AND data_type=?");
        pstmt.setString(1, fileUuid);
        pstmt.setString(2, Type.SOURCE);
        rs = pstmt.executeQuery();
        if (rs.next()) {
            String string = rs.getString(1);
            if (string == null) {
                return Collections.emptyList();
            }
            return END_OF_LINE_SPLITTER.splitToList(string);
        }
        return null;
    } catch (SQLException e) {
        throw new IllegalStateException("Fail to read FILE_SOURCES.LINE_HASHES of file " + fileUuid, e);
    } finally {
        DbUtils.closeQuietly(connection, pstmt, rs);
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) CheckForNull(javax.annotation.CheckForNull)

Example 4 with CheckForNull

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

the class LogbackHelper method getPropertyValueAsLevel.

@CheckForNull
private static Level getPropertyValueAsLevel(Props props, String propertyKey) {
    String value = props.value(propertyKey);
    if (value == null) {
        return null;
    }
    Level level = Level.toLevel(value, Level.INFO);
    if (!isAllowed(level)) {
        throw new IllegalArgumentException(format("log level %s in property %s is not a supported value (allowed levels are %s)", level, propertyKey, Arrays.toString(ALLOWED_ROOT_LOG_LEVELS)));
    }
    return level;
}
Also used : Level(ch.qos.logback.classic.Level) CheckForNull(javax.annotation.CheckForNull)

Example 5 with CheckForNull

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

the class ActivityAction method loadComponentUuids.

@CheckForNull
private List<String> loadComponentUuids(DbSession dbSession, ActivityWsRequest request) {
    String componentUuid = request.getComponentId();
    String componentQuery = request.getQuery();
    if (componentUuid != null) {
        return singletonList(componentUuid);
    }
    if (componentQuery != null) {
        ComponentQuery componentDtoQuery = ComponentQuery.builder().setNameOrKeyQuery(componentQuery).setQualifiers(POSSIBLE_QUALIFIERS.toArray(new String[0])).build();
        List<ComponentDto> componentDtos = dbClient.componentDao().selectByQuery(dbSession, componentDtoQuery, 0, CeTaskQuery.MAX_COMPONENT_UUIDS);
        return Lists.transform(componentDtos, ComponentDto::uuid);
    }
    return null;
}
Also used : ComponentQuery(org.sonar.db.component.ComponentQuery) ComponentDto(org.sonar.db.component.ComponentDto) StringUtils.defaultString(org.apache.commons.lang.StringUtils.defaultString) 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