From 42746662a3de20ffdcad0f2398007f0adfb370be Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Tue, 31 Jan 2017 16:15:14 +0100 Subject: [PATCH] Drop class ComponentDtoFunctions --- .../java/org/sonar/ce/queue/CeQueueImpl.java | 3 +- .../sonar/server/ce/ws/ActivityAction.java | 3 +- .../server/component/ComponentService.java | 3 +- .../step/ValidateProjectStep.java | 3 +- .../sonar/server/issue/IssueQueryService.java | 3 +- .../server/test/ws/CoveredFilesAction.java | 3 +- .../org/sonar/server/test/ws/ListAction.java | 3 +- .../db/component/ComponentDtoFunctions.java | 72 ------------------- 8 files changed, 7 insertions(+), 86 deletions(-) delete mode 100644 sonar-db/src/main/java/org/sonar/db/component/ComponentDtoFunctions.java diff --git a/server/sonar-server/src/main/java/org/sonar/ce/queue/CeQueueImpl.java b/server/sonar-server/src/main/java/org/sonar/ce/queue/CeQueueImpl.java index e82c1bf9786..4fa28e398c4 100644 --- a/server/sonar-server/src/main/java/org/sonar/ce/queue/CeQueueImpl.java +++ b/server/sonar-server/src/main/java/org/sonar/ce/queue/CeQueueImpl.java @@ -44,7 +44,6 @@ import static com.google.common.base.Predicates.notNull; import static com.google.common.collect.FluentIterable.from; import static java.util.Collections.singleton; import static java.util.Objects.requireNonNull; -import static org.sonar.db.component.ComponentDtoFunctions.toUuid; @ComputeEngineSide public class CeQueueImpl implements CeQueue { @@ -122,7 +121,7 @@ public class CeQueueImpl implements CeQueue { .toSet(); Map componentDtoByUuid = from(dbClient.componentDao() .selectByUuids(dbSession, componentUuids)) - .uniqueIndex(toUuid()); + .uniqueIndex(ComponentDto::uuid); return from(dtos) .transform(new CeQueueDtoToCeTask(defaultOrganizationProvider.get().getUuid(), componentDtoByUuid)) diff --git a/server/sonar-server/src/main/java/org/sonar/server/ce/ws/ActivityAction.java b/server/sonar-server/src/main/java/org/sonar/server/ce/ws/ActivityAction.java index 9c26b418bcd..883a92f8ca9 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/ce/ws/ActivityAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/ce/ws/ActivityAction.java @@ -47,7 +47,6 @@ import org.sonar.db.ce.CeQueueDto; import org.sonar.db.ce.CeTaskQuery; import org.sonar.db.ce.CeTaskTypes; import org.sonar.db.component.ComponentDto; -import org.sonar.db.component.ComponentDtoFunctions; import org.sonar.db.component.ComponentQuery; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.user.UserSession; @@ -238,7 +237,7 @@ public class ActivityAction implements CeWsAction { .setQualifiers(POSSIBLE_QUALIFIERS.toArray(new String[0])) .build(); List componentDtos = dbClient.componentDao().selectByQuery(dbSession, componentDtoQuery, 0, CeTaskQuery.MAX_COMPONENT_UUIDS); - return Lists.transform(componentDtos, ComponentDtoFunctions.toUuid()); + return Lists.transform(componentDtos, ComponentDto::uuid); } return null; diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/ComponentService.java b/server/sonar-server/src/main/java/org/sonar/server/component/ComponentService.java index 484024826f1..4cd31e7df82 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/component/ComponentService.java +++ b/server/sonar-server/src/main/java/org/sonar/server/component/ComponentService.java @@ -38,7 +38,6 @@ import org.sonar.server.user.UserSession; import static com.google.common.collect.Lists.newArrayList; import static org.sonar.core.component.ComponentKeys.isValidModuleKey; -import static org.sonar.db.component.ComponentDtoFunctions.toKey; import static org.sonar.db.component.ComponentKeyUpdaterDao.checkIsProjectOrModule; import static org.sonar.server.ws.WsUtils.checkRequest; @@ -93,7 +92,7 @@ public class ComponentService { List components = dbClient.componentDao().selectByKeys(session, componentKeys); if (!ignoreMissingComponents && components.size() < componentKeys.size()) { - Collection foundKeys = Collections2.transform(components, toKey()); + Collection foundKeys = Collections2.transform(components, ComponentDto::getKey); Set missingKeys = Sets.newHashSet(componentKeys); missingKeys.removeAll(foundKeys); throw new NotFoundException("The following component keys do not match any component:\n" + diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/ValidateProjectStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/ValidateProjectStep.java index 78bfa76f1ee..a1286722d6c 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/ValidateProjectStep.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/ValidateProjectStep.java @@ -47,7 +47,6 @@ import org.sonar.server.computation.task.step.ComputationStep; import static com.google.common.collect.FluentIterable.from; import static java.lang.String.format; import static org.sonar.api.utils.DateUtils.formatDateTime; -import static org.sonar.db.component.ComponentDtoFunctions.toKey; /** * Validate project and modules. It will fail in the following cases : @@ -81,7 +80,7 @@ public class ValidateProjectStep implements ComputationStep { try { Component root = treeRootHolder.getRoot(); List baseModules = dbClient.componentDao().selectEnabledModulesFromProjectKey(session, root.getKey()); - Map baseModulesByKey = from(baseModules).uniqueIndex(toKey()); + Map baseModulesByKey = from(baseModules).uniqueIndex(ComponentDto::key); ValidateProjectsVisitor visitor = new ValidateProjectsVisitor(session, dbClient.componentDao(), baseModulesByKey); new DepthTraversalTypeAwareCrawler(visitor).visit(root); diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/IssueQueryService.java b/server/sonar-server/src/main/java/org/sonar/server/issue/IssueQueryService.java index 76c3b257061..f999fe5a9e0 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/IssueQueryService.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/IssueQueryService.java @@ -69,7 +69,6 @@ import static org.sonar.api.utils.DateUtils.longToDate; import static org.sonar.api.utils.DateUtils.parseDateOrDateTime; import static org.sonar.api.utils.DateUtils.parseEndingDateOrDateTime; import static org.sonar.api.utils.DateUtils.parseStartingDateOrDateTime; -import static org.sonar.db.component.ComponentDtoFunctions.toProjectUuid; import static org.sonar.server.ws.WsUtils.checkFoundWithOptional; import static org.sonar.server.ws.WsUtils.checkRequest; import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_COMPONENTS; @@ -400,7 +399,7 @@ public class IssueQueryService { private void addDeveloperTechnicalProjects(IssueQuery.Builder builder, DbSession session, Collection componentUuids, Collection authors) { Collection technicalProjects = dbClient.componentDao().selectByUuids(session, componentUuids); - Collection developerUuids = Collections2.transform(technicalProjects, toProjectUuid()); + Collection developerUuids = Collections2.transform(technicalProjects, ComponentDto::projectUuid); Collection authorsFromProjects = authorsFromParamsOrFromDeveloper(session, developerUuids, authors); builder.authors(authorsFromProjects); Collection projectUuids = Collections2.transform(technicalProjects, ComponentDto::getCopyResourceUuid); diff --git a/server/sonar-server/src/main/java/org/sonar/server/test/ws/CoveredFilesAction.java b/server/sonar-server/src/main/java/org/sonar/server/test/ws/CoveredFilesAction.java index f8beed6e987..fcdba6f8b61 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/test/ws/CoveredFilesAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/test/ws/CoveredFilesAction.java @@ -34,7 +34,6 @@ import org.sonar.core.util.Uuids; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.component.ComponentDto; -import org.sonar.db.component.ComponentDtoFunctions; import org.sonar.server.test.index.CoveredFileDoc; import org.sonar.server.test.index.TestDoc; import org.sonar.server.test.index.TestIndex; @@ -111,7 +110,7 @@ public class CoveredFilesAction implements TestsWsAction { } finally { dbClient.closeSession(dbSession); } - return Maps.uniqueIndex(components, ComponentDtoFunctions.toUuid()); + return Maps.uniqueIndex(components, ComponentDto::uuid); } private static class CoveredFileToFileUuidFunction implements Function { diff --git a/server/sonar-server/src/main/java/org/sonar/server/test/ws/ListAction.java b/server/sonar-server/src/main/java/org/sonar/server/test/ws/ListAction.java index 5c824be2651..1d5be532947 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/test/ws/ListAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/test/ws/ListAction.java @@ -36,7 +36,6 @@ import org.sonar.core.util.Uuids; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.component.ComponentDto; -import org.sonar.db.component.ComponentDtoFunctions; import org.sonar.server.component.ComponentFinder; import org.sonar.server.es.SearchOptions; import org.sonar.server.es.SearchResult; @@ -194,7 +193,7 @@ public class ListAction implements TestsWsAction { List fileUuids = Lists.transform(tests, new TestToFileUuidFunction()); List components = dbClient.componentDao().selectByUuids(dbSession, fileUuids); - return Maps.uniqueIndex(components, ComponentDtoFunctions.toUuid()); + return Maps.uniqueIndex(components, ComponentDto::uuid); } private SearchResult searchTests(DbSession dbSession, @Nullable String testUuid, @Nullable String testFileUuid, @Nullable String testFileKey, diff --git a/sonar-db/src/main/java/org/sonar/db/component/ComponentDtoFunctions.java b/sonar-db/src/main/java/org/sonar/db/component/ComponentDtoFunctions.java deleted file mode 100644 index 19e953fa956..00000000000 --- a/sonar-db/src/main/java/org/sonar/db/component/ComponentDtoFunctions.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact 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.db.component; - -import com.google.common.base.Function; -import javax.annotation.Nonnull; - -/** - * Common Functions on ComponentDto. - */ -public final class ComponentDtoFunctions { - private ComponentDtoFunctions() { - // prevents instantiation - } - - public static Function toKey() { - return ToKey.INSTANCE; - } - - public static Function toProjectUuid() { - return ToProjectUuid.INSTANCE; - } - - public static Function toUuid() { - return ToUuid.INSTANCE; - } - - private enum ToKey implements Function { - INSTANCE; - - @Override - public String apply(@Nonnull ComponentDto input) { - return input.key(); - } - } - - private enum ToProjectUuid implements Function { - INSTANCE; - - @Override - public String apply(ComponentDto input) { - return input.projectUuid(); - } - } - - private enum ToUuid implements Function { - INSTANCE; - - @Override - public String apply(ComponentDto input) { - return input.uuid(); - } - } - -} -- 2.39.5