]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-10110 Remove log detecting old projects
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 27 Nov 2017 13:27:39 +0000 (14:27 +0100)
committerEric Hartmann <hartmann.eric@gmail.Com>
Mon, 4 Dec 2017 12:44:55 +0000 (13:44 +0100)
server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevelStartup.java
server/sonar-server/src/main/java/org/sonar/server/startup/DisplayLogOnDeprecatedProjects.java [deleted file]
server/sonar-server/src/test/java/org/sonar/server/startup/DisplayLogOnDeprecatedProjectsTest.java [deleted file]

index f8c07e82b44a8966c69684599002acc1ce0dac33..8613ab0ecfeb236b6d914db87d4f5429532ece8a 100644 (file)
@@ -33,7 +33,6 @@ import org.sonar.server.qualityprofile.RegisterQualityProfiles;
 import org.sonar.server.rule.RegisterRules;
 import org.sonar.server.rule.WebServerRuleFinder;
 import org.sonar.server.startup.DeleteOldAnalysisReportsFromFs;
-import org.sonar.server.startup.DisplayLogOnDeprecatedProjects;
 import org.sonar.server.startup.GeneratePluginIndex;
 import org.sonar.server.startup.RegisterMetrics;
 import org.sonar.server.startup.RegisterPermissionTemplates;
@@ -67,7 +66,6 @@ public class PlatformLevelStartup extends PlatformLevel {
       RegisterQualityProfiles.class,
       RegisterPermissionTemplates.class,
       RenameDeprecatedPropertyKeys.class,
-      DisplayLogOnDeprecatedProjects.class,
       DeleteOldAnalysisReportsFromFs.class);
 
     // RegisterServletFilters makes the WebService engine of Level4 served by the MasterServletFilter, therefor it
diff --git a/server/sonar-server/src/main/java/org/sonar/server/startup/DisplayLogOnDeprecatedProjects.java b/server/sonar-server/src/main/java/org/sonar/server/startup/DisplayLogOnDeprecatedProjects.java
deleted file mode 100644 (file)
index 693fead..0000000
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2017 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.server.startup;
-
-import org.picocontainer.Startable;
-import org.sonar.api.utils.log.Logger;
-import org.sonar.api.utils.log.Loggers;
-import org.sonar.db.DbClient;
-import org.sonar.db.DbSession;
-import org.sonar.db.component.ComponentDto;
-import org.sonar.db.loadedtemplate.LoadedTemplateDto;
-
-/**
- * Display a log for each project that hasn't been analysed since SonarQube 4.2 (column DEPRECATED_KEE is null)
- *
- * Should be removed after next LTS
- *
- * @since 5.2
- */
-public class DisplayLogOnDeprecatedProjects implements Startable {
-
-  private static final Logger LOG = Loggers.get(DisplayLogOnDeprecatedProjects.class);
-
-  private static final String TEMPLATE_KEY = "DisplayLogOnDeprecatedProjects";
-
-  private final DbClient dbClient;
-
-  public DisplayLogOnDeprecatedProjects(DbClient dbClient) {
-    this.dbClient = dbClient;
-  }
-
-  @Override
-  public void start() {
-    try (DbSession dbSession = dbClient.openSession(false)) {
-      if (!hasAlreadyBeenExecuted(dbSession)) {
-        return;
-      }
-      displayLogOnDeprecatedProjectKeys(dbSession);
-      registerTasks(dbSession);
-      dbSession.commit();
-    }
-  }
-
-  private void displayLogOnDeprecatedProjectKeys(DbSession session) {
-    boolean hasDetectDeprecatedProjects = false;
-    for (ComponentDto project : dbClient.componentDao().selectProjects(session)) {
-      if (project.deprecatedKey() == null) {
-        if (!hasDetectDeprecatedProjects) {
-          LOG.warn("We detected that the following projects have not been analysed on a SonarQube version greater than 4.2 (included):");
-          hasDetectDeprecatedProjects = true;
-        }
-        LOG.warn(" - {}", project.getDbKey());
-      }
-    }
-    if (hasDetectDeprecatedProjects) {
-      LOG.warn("As a consequence, some features of the Web UI will be broken for them, and any new analysis will consider all issues as new issues.");
-    }
-  }
-
-  private boolean hasAlreadyBeenExecuted(DbSession session) {
-    return dbClient.loadedTemplateDao().countByTypeAndKey(LoadedTemplateDto.ONE_SHOT_TASK_TYPE, TEMPLATE_KEY, session) == 0;
-  }
-
-  private void registerTasks(DbSession session) {
-    dbClient.loadedTemplateDao().insert(new LoadedTemplateDto(TEMPLATE_KEY, LoadedTemplateDto.ONE_SHOT_TASK_TYPE), session);
-  }
-
-  @Override
-  public void stop() {
-    // Nothing to do
-  }
-}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/startup/DisplayLogOnDeprecatedProjectsTest.java b/server/sonar-server/src/test/java/org/sonar/server/startup/DisplayLogOnDeprecatedProjectsTest.java
deleted file mode 100644 (file)
index 31c19bf..0000000
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2017 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.server.startup;
-
-import org.junit.Rule;
-import org.junit.Test;
-import org.sonar.api.utils.System2;
-import org.sonar.api.utils.log.LogTester;
-import org.sonar.db.DbClient;
-import org.sonar.db.DbSession;
-import org.sonar.db.DbTester;
-import org.sonar.db.component.ComponentTesting;
-import org.sonar.db.organization.OrganizationDto;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class DisplayLogOnDeprecatedProjectsTest {
-
-  static final String PROJECT_KEY = "PROJECT_KEY";
-  static final String DEPRECATED_PROJECT_KEY = "DEPRECATED_PROJECT_KEY";
-
-  @Rule
-  public LogTester logTester = new LogTester();
-
-  @Rule
-  public DbTester dbTester = DbTester.create(System2.INSTANCE);
-
-  DbClient dbClient = dbTester.getDbClient();
-  DbSession dbSession = dbTester.getSession();
-
-  DisplayLogOnDeprecatedProjects underTest = new DisplayLogOnDeprecatedProjects(dbClient);
-
-  @Test
-  public void display_log_on_deprecated_project() throws Exception {
-    OrganizationDto organizationDto = dbTester.organizations().insert();
-    dbClient.componentDao().insert(dbSession, ComponentTesting.newPrivateProjectDto(organizationDto)
-      .setDbKey(DEPRECATED_PROJECT_KEY)
-      .setDeprecatedKey(null));
-    dbSession.commit();
-
-    underTest.start();
-
-    assertThat(logTester.logs()).containsOnly(
-      "We detected that the following projects have not been analysed on a SonarQube version greater than 4.2 (included):",
-      " - " + DEPRECATED_PROJECT_KEY,
-      "As a consequence, some features of the Web UI will be broken for them, and any new analysis will consider all issues as new issues.");
-  }
-
-  @Test
-  public void not_display_log_when_task_already_executed() throws Exception {
-    OrganizationDto organizationDto = dbTester.organizations().insert();
-    dbClient.componentDao().insert(dbSession, ComponentTesting.newPrivateProjectDto(organizationDto)
-      .setDbKey(DEPRECATED_PROJECT_KEY)
-      .setDeprecatedKey(null));
-    dbSession.commit();
-
-    underTest.start();
-    assertThat(logTester.logs()).isNotEmpty();
-    logTester.clear();
-
-    underTest.start();
-    assertThat(logTester.logs()).isEmpty();
-  }
-
-  @Test
-  public void nothing_do_when_no_deprecated_project() throws Exception {
-    OrganizationDto organizationDto = dbTester.organizations().insert();
-    dbClient.componentDao().insert(dbSession, ComponentTesting.newPrivateProjectDto(organizationDto)
-      .setDbKey(PROJECT_KEY)
-      .setDeprecatedKey(PROJECT_KEY));
-    dbSession.commit();
-
-    underTest.start();
-
-    assertThat(logTester.logs()).isEmpty();
-  }
-
-  @Test
-  public void nothing_do_when_no_project() throws Exception {
-    underTest.start();
-
-    assertThat(logTester.logs()).isEmpty();
-  }
-}