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 {
.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))
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;
.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;
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;
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" +
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 :
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);
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;
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);
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;
} finally {
dbClient.closeSession(dbSession);
}
- return Maps.uniqueIndex(components, ComponentDtoFunctions.toUuid());
+ return Maps.uniqueIndex(components, ComponentDto::uuid);
}
private static class CoveredFileToFileUuidFunction implements Function<CoveredFileDoc, String> {
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;
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,
+++ /dev/null
-/*
- * 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();
- }
- }
-
-}