Search in sources :

Example 51 with Profiler

use of org.sonar.api.utils.log.Profiler in project sonarqube by SonarSource.

the class RegisterQualityProfiles method renameOutdatedProfiles.

/**
 * The Quality profiles created by users should be renamed when they have the same name
 * as the built-in profile to be persisted.
 * <p>
 * When upgrading from < 6.5 , all existing profiles are considered as "custom" (created
 * by users) because the concept of built-in profile is not persisted. The "Sonar way" profiles
 * are renamed to "Sonar way (outdated copy) in order to avoid conflicts with the new
 * built-in profile "Sonar way", which has probably different configuration.
 */
private void renameOutdatedProfiles(DbSession dbSession, BuiltInQProfile profile) {
    Collection<String> uuids = dbClient.qualityProfileDao().selectUuidsOfCustomRulesProfiles(dbSession, profile.getLanguage(), profile.getName());
    if (uuids.isEmpty()) {
        return;
    }
    Profiler profiler = Profiler.createIfDebug(Loggers.get(getClass())).start();
    String newName = profile.getName() + " (outdated copy)";
    LOGGER.info("Rename Quality profiles [{}/{}] to [{}]", profile.getLanguage(), profile.getName(), newName);
    dbClient.qualityProfileDao().renameRulesProfilesAndCommit(dbSession, uuids, newName);
    profiler.stopDebug(format("%d Quality profiles renamed to [%s]", uuids.size(), newName));
}
Also used : Profiler(org.sonar.api.utils.log.Profiler)

Example 52 with Profiler

use of org.sonar.api.utils.log.Profiler in project sonarqube by SonarSource.

the class BuiltInQProfileRepositoryImpl method initialize.

@Override
public void initialize() {
    checkState(qProfiles == null, "initialize must be called only once");
    Profiler profiler = Profiler.create(LOGGER).startInfo("Load quality profiles");
    BuiltInQualityProfilesDefinition.Context context = new BuiltInQualityProfilesDefinition.Context();
    for (BuiltInQualityProfilesDefinition definition : definitions) {
        definition.define(context);
    }
    Map<String, Map<String, BuiltInQualityProfile>> rulesProfilesByLanguage = validateAndClean(context);
    this.qProfiles = toFlatList(rulesProfilesByLanguage);
    ensureAllLanguagesHaveAtLeastOneBuiltInQP();
    profiler.stopDebug();
}
Also used : Profiler(org.sonar.api.utils.log.Profiler) BuiltInQualityProfilesDefinition(org.sonar.api.server.profile.BuiltInQualityProfilesDefinition) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 53 with Profiler

use of org.sonar.api.utils.log.Profiler in project sonarqube by SonarSource.

the class ScannerPluginInstaller method listInstalledPlugins.

/**
 * Gets information about the plugins installed on server (filename, checksum)
 */
private InstalledPlugin[] listInstalledPlugins() {
    Profiler profiler = Profiler.create(LOG).startInfo("Load plugins index");
    GetRequest getRequest = new GetRequest(PLUGINS_WS_URL);
    InstalledPlugins installedPlugins;
    try (Reader reader = wsClient.call(getRequest).contentReader()) {
        installedPlugins = new Gson().fromJson(reader, InstalledPlugins.class);
    } catch (Exception e) {
        throw new IllegalStateException("Fail to parse response of " + PLUGINS_WS_URL, e);
    }
    profiler.stopInfo();
    return installedPlugins.plugins;
}
Also used : Profiler(org.sonar.api.utils.log.Profiler) GetRequest(org.sonarqube.ws.client.GetRequest) Reader(java.io.Reader) Gson(com.google.gson.Gson)

Example 54 with Profiler

use of org.sonar.api.utils.log.Profiler in project sonarqube by SonarSource.

the class DefaultScannerWsClient method call.

/**
 * If an exception is not thrown, the response needs to be closed by either calling close() directly, or closing the
 * body content's stream/reader.
 *
 * @throws IllegalStateException if the request could not be executed due to a connectivity problem or timeout. Because networks can
 *                               fail during an exchange, it is possible that the remote server accepted the request before the failure
 * @throws MessageException      if there was a problem with authentication or if a error message was parsed from the response.
 * @throws HttpException         if the response code is not in range [200..300). Consider using {@link #createErrorMessage(HttpException)} to create more relevant messages for the users.
 */
public WsResponse call(WsRequest request) {
    checkState(!globalMode.isMediumTest(), "No WS call should be made in medium test mode");
    Profiler profiler = Profiler.createIfDebug(LOG).start();
    WsResponse response = target.wsConnector().call(request);
    profiler.stopDebug(format("%s %d %s", request.getMethod(), response.code(), response.requestUrl()));
    failIfUnauthorized(response);
    return response;
}
Also used : Profiler(org.sonar.api.utils.log.Profiler) WsResponse(org.sonarqube.ws.client.WsResponse)

Example 55 with Profiler

use of org.sonar.api.utils.log.Profiler in project sonarqube by SonarSource.

the class ProjectPullRequestsProvider method provide.

@Bean("ProjectPullRequests")
public ProjectPullRequests provide(@Nullable ProjectPullRequestsLoader loader, ScannerProperties scannerProperties) {
    if (loader == null) {
        return new ProjectPullRequests(Collections.emptyList());
    }
    Profiler profiler = Profiler.create(LOG).startInfo(LOG_MSG);
    ProjectPullRequests pullRequests = loader.load(scannerProperties.getProjectKey());
    profiler.stopInfo();
    return pullRequests;
}
Also used : Profiler(org.sonar.api.utils.log.Profiler) Bean(org.springframework.context.annotation.Bean)

Aggregations

Profiler (org.sonar.api.utils.log.Profiler)56 Bean (org.springframework.context.annotation.Bean)7 HashMap (java.util.HashMap)6 IOException (java.io.IOException)5 DbSession (org.sonar.db.DbSession)5 GetRequest (org.sonarqube.ws.client.GetRequest)5 File (java.io.File)3 Reader (java.io.Reader)3 RulesDefinition (org.sonar.api.server.rule.RulesDefinition)3 InputStream (java.io.InputStream)2 Path (java.nio.file.Path)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 CheckForNull (javax.annotation.CheckForNull)2 OptInCaching (org.picocontainer.behaviors.OptInCaching)2 ReflectionLifecycleStrategy (org.picocontainer.lifecycle.ReflectionLifecycleStrategy)2 NullComponentMonitor (org.picocontainer.monitors.NullComponentMonitor)2 InputFile (org.sonar.api.batch.fs.InputFile)2 NewRule (org.sonar.api.batch.rule.internal.NewRule)2 RulesBuilder (org.sonar.api.batch.rule.internal.RulesBuilder)2