]> source.dussan.org Git - sonarqube.git/commitdiff
Drop class ComponentDtoFunctions
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Tue, 31 Jan 2017 15:15:14 +0000 (16:15 +0100)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Wed, 1 Feb 2017 16:11:52 +0000 (17:11 +0100)
server/sonar-server/src/main/java/org/sonar/ce/queue/CeQueueImpl.java
server/sonar-server/src/main/java/org/sonar/server/ce/ws/ActivityAction.java
server/sonar-server/src/main/java/org/sonar/server/component/ComponentService.java
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/ValidateProjectStep.java
server/sonar-server/src/main/java/org/sonar/server/issue/IssueQueryService.java
server/sonar-server/src/main/java/org/sonar/server/test/ws/CoveredFilesAction.java
server/sonar-server/src/main/java/org/sonar/server/test/ws/ListAction.java
sonar-db/src/main/java/org/sonar/db/component/ComponentDtoFunctions.java [deleted file]

index e82c1bf97869500df1dc0d493da982455bd2be20..4fa28e398c44c4c2864c2013d593f361b3f4becd 100644 (file)
@@ -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<String, ComponentDto> componentDtoByUuid = from(dbClient.componentDao()
       .selectByUuids(dbSession, componentUuids))
-        .uniqueIndex(toUuid());
+        .uniqueIndex(ComponentDto::uuid);
 
     return from(dtos)
       .transform(new CeQueueDtoToCeTask(defaultOrganizationProvider.get().getUuid(), componentDtoByUuid))
index 9c26b418bcd29437c10cc12948fce6f67fae13bd..883a92f8ca9b0d5fe575d886bc7c64d2d88c3606 100644 (file)
@@ -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<ComponentDto> 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;
index 484024826f1d29c5780206e230ba220476a0e2cf..4cd31e7df82910aabf1e4004aa7d5a3d85f39cd0 100644 (file)
@@ -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<ComponentDto> components = dbClient.componentDao().selectByKeys(session, componentKeys);
 
       if (!ignoreMissingComponents && components.size() < componentKeys.size()) {
-        Collection<String> foundKeys = Collections2.transform(components, toKey());
+        Collection<String> foundKeys = Collections2.transform(components, ComponentDto::getKey);
         Set<String> missingKeys = Sets.newHashSet(componentKeys);
         missingKeys.removeAll(foundKeys);
         throw new NotFoundException("The following component keys do not match any component:\n" +
index 78bfa76f1eec19b61f657f3e9fe92d8cfb36f289..a1286722d6c1e309d9fc073222f404d1a538f408 100644 (file)
@@ -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<ComponentDto> baseModules = dbClient.componentDao().selectEnabledModulesFromProjectKey(session, root.getKey());
-      Map<String, ComponentDto> baseModulesByKey = from(baseModules).uniqueIndex(toKey());
+      Map<String, ComponentDto> baseModulesByKey = from(baseModules).uniqueIndex(ComponentDto::key);
       ValidateProjectsVisitor visitor = new ValidateProjectsVisitor(session, dbClient.componentDao(), baseModulesByKey);
       new DepthTraversalTypeAwareCrawler(visitor).visit(root);
 
index 76c3b2570616e29a8f3d9630329643c56e1ec2fa..f999fe5a9e0ffc31f7e59c5db5a7a1867f4b95b5 100644 (file)
@@ -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<String> componentUuids, Collection<String> authors) {
     Collection<ComponentDto> technicalProjects = dbClient.componentDao().selectByUuids(session, componentUuids);
-    Collection<String> developerUuids = Collections2.transform(technicalProjects, toProjectUuid());
+    Collection<String> developerUuids = Collections2.transform(technicalProjects, ComponentDto::projectUuid);
     Collection<String> authorsFromProjects = authorsFromParamsOrFromDeveloper(session, developerUuids, authors);
     builder.authors(authorsFromProjects);
     Collection<String> projectUuids = Collections2.transform(technicalProjects, ComponentDto::getCopyResourceUuid);
index f8beed6e987ecad7e9b20550c9db67b39681e3d2..fcdba6f8b61c24b29712c10cbff2b6eb228f26a5 100644 (file)
@@ -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<CoveredFileDoc, String> {
index 5c824be26517f258176cbaa2b031bfce90fb6403..1d5be53294791cdd0745cb73f2e645069afecd42 100644 (file)
@@ -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<String> fileUuids = Lists.transform(tests, new TestToFileUuidFunction());
     List<ComponentDto> components = dbClient.componentDao().selectByUuids(dbSession, fileUuids);
 
-    return Maps.uniqueIndex(components, ComponentDtoFunctions.toUuid());
+    return Maps.uniqueIndex(components, ComponentDto::uuid);
   }
 
   private SearchResult<TestDoc> 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 (file)
index 19e953f..0000000
+++ /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<ComponentDto, String> toKey() {
-    return ToKey.INSTANCE;
-  }
-
-  public static Function<ComponentDto, String> toProjectUuid() {
-    return ToProjectUuid.INSTANCE;
-  }
-
-  public static Function<ComponentDto, String> toUuid() {
-    return ToUuid.INSTANCE;
-  }
-
-  private enum ToKey implements Function<ComponentDto, String> {
-    INSTANCE;
-
-    @Override
-    public String apply(@Nonnull ComponentDto input) {
-      return input.key();
-    }
-  }
-
-  private enum ToProjectUuid implements Function<ComponentDto, String> {
-    INSTANCE;
-
-    @Override
-    public String apply(ComponentDto input) {
-      return input.projectUuid();
-    }
-  }
-
-  private enum ToUuid implements Function<ComponentDto, String> {
-    INSTANCE;
-
-    @Override
-    public String apply(ComponentDto input) {
-      return input.uuid();
-    }
-  }
-
-}