@@ -1,38 +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.server.component; | |||
import com.google.common.base.Function; | |||
import javax.annotation.Nonnull; | |||
import org.sonar.api.resources.ResourceType; | |||
public class ResourceTypeFunctions { | |||
public static final Function<ResourceType, String> RESOURCE_TYPE_TO_QUALIFIER = ResourceTypeToQualifier.INSTANCE; | |||
private enum ResourceTypeToQualifier implements Function<ResourceType, String> { | |||
INSTANCE; | |||
@Override | |||
public String apply(@Nonnull ResourceType resourceType) { | |||
return resourceType.getQualifier(); | |||
} | |||
} | |||
} |
@@ -25,7 +25,6 @@ import com.google.common.base.Predicate; | |||
import com.google.common.base.Splitter; | |||
import com.google.common.base.Strings; | |||
import com.google.common.collect.Collections2; | |||
import com.google.common.collect.Iterables; | |||
import com.google.common.collect.Lists; | |||
import com.google.common.collect.Sets; | |||
import java.util.Arrays; | |||
@@ -56,7 +55,6 @@ import org.sonar.db.DbSession; | |||
import org.sonar.db.component.ComponentDto; | |||
import org.sonar.db.component.SnapshotDto; | |||
import org.sonar.server.component.ComponentService; | |||
import org.sonar.server.rule.RuleKeyFunctions; | |||
import org.sonar.server.user.UserSession; | |||
import org.sonar.server.util.RubyUtils; | |||
import org.sonarqube.ws.client.issue.IssuesWsParameters; | |||
@@ -453,7 +451,7 @@ public class IssueQueryService { | |||
@CheckForNull | |||
private static Collection<RuleKey> stringsToRules(@Nullable Collection<String> rules) { | |||
if (rules != null) { | |||
return newArrayList(Iterables.transform(rules, RuleKeyFunctions.stringToRuleKey())); | |||
return Collections2.transform(rules, RuleKey::parse); | |||
} | |||
return null; | |||
} |
@@ -20,6 +20,7 @@ | |||
package org.sonar.server.issue.ws; | |||
import com.google.common.base.Function; | |||
import com.google.common.collect.Collections2; | |||
import com.google.common.collect.Lists; | |||
import java.util.Collection; | |||
import java.util.EnumSet; | |||
@@ -29,6 +30,7 @@ import java.util.Map; | |||
import java.util.Set; | |||
import javax.annotation.Nullable; | |||
import org.sonar.api.issue.Issue; | |||
import org.sonar.api.rule.RuleKey; | |||
import org.sonar.api.rule.Severity; | |||
import org.sonar.api.rules.RuleType; | |||
import org.sonar.api.server.ws.Request; | |||
@@ -43,7 +45,6 @@ import org.sonar.server.issue.IssueQuery; | |||
import org.sonar.server.issue.IssueQueryService; | |||
import org.sonar.server.issue.index.IssueDoc; | |||
import org.sonar.server.issue.index.IssueIndex; | |||
import org.sonar.server.rule.RuleKeyFunctions; | |||
import org.sonar.server.user.UserSession; | |||
import org.sonarqube.ws.Issues.SearchWsResponse; | |||
import org.sonarqube.ws.client.issue.SearchWsRequest; | |||
@@ -408,7 +409,7 @@ public class SearchAction implements IssuesWsAction { | |||
private void collectFacets(SearchResponseLoader.Collector collector, Facets facets) { | |||
Set<String> facetRules = facets.getBucketKeys(PARAM_RULES); | |||
if (facetRules != null) { | |||
collector.addAll(SearchAdditionalField.RULES, from(facetRules).transform(RuleKeyFunctions.stringToRuleKey())); | |||
collector.addAll(SearchAdditionalField.RULES, Collections2.transform(facetRules, RuleKey::parse)); | |||
} | |||
collector.addProjectUuids(facets.getBucketKeys(PARAM_PROJECT_UUIDS)); | |||
collector.addComponentUuids(facets.getBucketKeys(PARAM_COMPONENT_UUIDS)); |
@@ -24,6 +24,7 @@ import java.util.Set; | |||
import java.util.regex.Pattern; | |||
import java.util.regex.PatternSyntaxException; | |||
import javax.annotation.Nullable; | |||
import org.sonar.api.resources.ResourceType; | |||
import org.sonar.api.resources.ResourceTypes; | |||
import org.sonar.core.permission.GlobalPermissions; | |||
import org.sonar.core.permission.ProjectPermissions; | |||
@@ -33,7 +34,6 @@ import org.sonar.server.usergroups.ws.GroupIdOrAnyone; | |||
import static com.google.common.base.Strings.isNullOrEmpty; | |||
import static java.lang.String.format; | |||
import static org.apache.commons.lang.StringUtils.isBlank; | |||
import static org.sonar.server.component.ResourceTypeFunctions.RESOURCE_TYPE_TO_QUALIFIER; | |||
import static org.sonar.server.ws.WsUtils.checkRequest; | |||
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PERMISSION; | |||
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PROJECT_KEY_PATTERN; | |||
@@ -77,7 +77,7 @@ public class PermissionRequestValidator { | |||
return; | |||
} | |||
Set<String> rootQualifiers = FluentIterable.from(resourceTypes.getRoots()) | |||
.transform(RESOURCE_TYPE_TO_QUALIFIER) | |||
.transform(ResourceType::getQualifier) | |||
.toSet(); | |||
checkRequest(rootQualifiers.contains(qualifier), | |||
format("The '%s' parameter must be one of %s. '%s' was passed.", PARAM_QUALIFIER, rootQualifiers, qualifier)); |
@@ -26,6 +26,7 @@ import com.google.common.collect.Table; | |||
import com.google.common.collect.TreeBasedTable; | |||
import java.util.List; | |||
import javax.annotation.Nullable; | |||
import org.sonar.api.resources.ResourceType; | |||
import org.sonar.api.resources.ResourceTypes; | |||
import org.sonar.api.utils.Paging; | |||
import org.sonar.db.DbClient; | |||
@@ -37,7 +38,6 @@ import org.sonarqube.ws.client.permission.SearchProjectPermissionsWsRequest; | |||
import static java.util.Collections.singletonList; | |||
import static org.sonar.api.utils.Paging.forPageIndex; | |||
import static org.sonar.server.component.ResourceTypeFunctions.RESOURCE_TYPE_TO_QUALIFIER; | |||
import static org.sonar.server.permission.ws.ProjectWsRef.newOptionalWsProjectRef; | |||
import static org.sonar.server.permission.ws.SearchProjectPermissionsData.newBuilder; | |||
@@ -49,7 +49,7 @@ public class SearchProjectPermissionsDataLoader { | |||
public SearchProjectPermissionsDataLoader(DbClient dbClient, PermissionWsSupport wsSupport, ResourceTypes resourceTypes) { | |||
this.dbClient = dbClient; | |||
this.wsSupport = wsSupport; | |||
this.rootQualifiers = Collections2.transform(resourceTypes.getRoots(), RESOURCE_TYPE_TO_QUALIFIER).toArray(new String[resourceTypes.getRoots().size()]); | |||
this.rootQualifiers = Collections2.transform(resourceTypes.getRoots(), ResourceType::getQualifier).toArray(new String[resourceTypes.getRoots().size()]); | |||
} | |||
SearchProjectPermissionsData load(DbSession dbSession, SearchProjectPermissionsWsRequest request) { |
@@ -24,6 +24,7 @@ import com.google.common.collect.Collections2; | |||
import java.util.List; | |||
import javax.annotation.Nullable; | |||
import org.sonar.api.i18n.I18n; | |||
import org.sonar.api.resources.ResourceType; | |||
import org.sonar.api.resources.ResourceTypes; | |||
import org.sonar.api.server.ws.Request; | |||
import org.sonar.api.server.ws.Response; | |||
@@ -40,7 +41,6 @@ import org.sonar.server.permission.ws.PermissionsWsAction; | |||
import org.sonar.server.user.UserSession; | |||
import org.sonarqube.ws.client.permission.BulkApplyTemplateWsRequest; | |||
import static org.sonar.server.component.ResourceTypeFunctions.RESOURCE_TYPE_TO_QUALIFIER; | |||
import static org.sonar.server.permission.PermissionPrivilegeChecker.checkGlobalAdmin; | |||
import static org.sonar.server.permission.ws.PermissionsWsParametersBuilder.createTemplateParameters; | |||
import static org.sonar.server.permission.ws.template.WsTemplateRef.newTemplateRef; | |||
@@ -116,7 +116,7 @@ public class BulkApplyTemplateAction implements PermissionsWsAction { | |||
private String[] qualifiers(@Nullable String qualifier) { | |||
return qualifier == null | |||
? Collections2.transform(resourceTypes.getRoots(), RESOURCE_TYPE_TO_QUALIFIER).toArray(new String[resourceTypes.getRoots().size()]) | |||
? Collections2.transform(resourceTypes.getRoots(), ResourceType::getQualifier).toArray(new String[resourceTypes.getRoots().size()]) | |||
: (new String[] {qualifier}); | |||
} | |||
@@ -25,11 +25,11 @@ import java.util.Set; | |||
import javax.annotation.Nonnull; | |||
import org.sonar.api.config.Settings; | |||
import org.sonar.api.resources.Qualifiers; | |||
import org.sonar.api.resources.ResourceType; | |||
import org.sonar.api.resources.ResourceTypes; | |||
import static com.google.common.collect.FluentIterable.from; | |||
import static com.google.common.collect.Ordering.natural; | |||
import static org.sonar.server.component.ResourceTypeFunctions.RESOURCE_TYPE_TO_QUALIFIER; | |||
import static org.sonar.server.permission.DefaultPermissionTemplates.DEFAULT_TEMPLATE_PROPERTY; | |||
import static org.sonar.server.permission.DefaultPermissionTemplates.defaultRootQualifierTemplateProperty; | |||
@@ -44,14 +44,14 @@ public class DefaultPermissionTemplateFinder { | |||
public Set<String> getDefaultTemplateUuids() { | |||
return from(resourceTypes.getRoots()) | |||
.transform(RESOURCE_TYPE_TO_QUALIFIER) | |||
.transform(ResourceType::getQualifier) | |||
.transform(new QualifierToDefaultTemplate(settings)) | |||
.toSortedSet(natural()); | |||
} | |||
public List<TemplateUuidQualifier> getDefaultTemplatesByQualifier() { | |||
return from(resourceTypes.getRoots()) | |||
.transform(RESOURCE_TYPE_TO_QUALIFIER) | |||
.transform(ResourceType::getQualifier) | |||
.transform(new QualifierToTemplateUuidQualifier(settings)) | |||
.toList(); | |||
} |
@@ -46,8 +46,6 @@ import static com.google.common.collect.ImmutableSortedSet.copyOf; | |||
import static com.google.common.collect.Iterables.filter; | |||
import static com.google.common.collect.Iterables.transform; | |||
import static java.lang.String.CASE_INSENSITIVE_ORDER; | |||
import static org.sonar.core.platform.PluginInfoFunctions.toKey; | |||
import static org.sonar.core.platform.PluginInfoFunctions.toName; | |||
public class PluginWSCommons { | |||
static final String PROPERTY_KEY = "key"; | |||
@@ -73,8 +71,8 @@ public class PluginWSCommons { | |||
static final String PROPERTY_CHANGE_LOG_URL = "changeLogUrl"; | |||
public static final Ordering<PluginInfo> NAME_KEY_PLUGIN_METADATA_COMPARATOR = Ordering.natural() | |||
.onResultOf(toName()) | |||
.compound(Ordering.natural().onResultOf(toKey())); | |||
.onResultOf(PluginInfo::getName) | |||
.compound(Ordering.natural().onResultOf(PluginInfo::getKey)); | |||
public static final Comparator<Plugin> NAME_KEY_PLUGIN_ORDERING = Ordering.from(CASE_INSENSITIVE_ORDER) | |||
.onResultOf(PluginToName.INSTANCE) | |||
.compound( |
@@ -1,49 +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.server.rule; | |||
import com.google.common.base.Function; | |||
import javax.annotation.Nonnull; | |||
import org.sonar.api.rule.RuleKey; | |||
public final class RuleKeyFunctions { | |||
private RuleKeyFunctions() { | |||
// only static methods | |||
} | |||
public static Function<String, RuleKey> stringToRuleKey() { | |||
return StringToRuleKey.INSTANCE; | |||
} | |||
/** | |||
* Transforms a string representation of key to {@link RuleKey}. It | |||
* does not accept null string inputs. | |||
*/ | |||
private enum StringToRuleKey implements Function<String, RuleKey> { | |||
INSTANCE; | |||
@Nonnull | |||
@Override | |||
public RuleKey apply(@Nonnull String input) { | |||
return RuleKey.parse(input); | |||
} | |||
} | |||
} |
@@ -26,6 +26,7 @@ import java.util.Set; | |||
import javax.annotation.Nullable; | |||
import org.sonar.api.i18n.I18n; | |||
import org.sonar.api.resources.Qualifiers; | |||
import org.sonar.api.resources.ResourceType; | |||
import org.sonar.api.resources.ResourceTypes; | |||
import org.sonar.api.server.ws.WebService; | |||
@@ -33,7 +34,6 @@ import static com.google.common.base.Predicates.not; | |||
import static com.google.common.collect.FluentIterable.from; | |||
import static com.google.common.collect.Ordering.natural; | |||
import static java.lang.String.format; | |||
import static org.sonar.server.component.ResourceTypeFunctions.RESOURCE_TYPE_TO_QUALIFIER; | |||
public class WsParameterBuilder { | |||
private static final String PARAM_QUALIFIER = "qualifier"; | |||
@@ -59,14 +59,14 @@ public class WsParameterBuilder { | |||
private static Set<String> getRootQualifiers(ResourceTypes resourceTypes) { | |||
return from(resourceTypes.getRoots()) | |||
.transform(RESOURCE_TYPE_TO_QUALIFIER) | |||
.transform(ResourceType::getQualifier) | |||
.filter(not(IsDeprecatedQualifier.INSTANCE)) | |||
.toSortedSet(natural()); | |||
} | |||
private static Set<String> getAllQualifiers(ResourceTypes resourceTypes) { | |||
return from(resourceTypes.getAll()) | |||
.transform(RESOURCE_TYPE_TO_QUALIFIER) | |||
.transform(ResourceType::getQualifier) | |||
.filter(not(IsDeprecatedQualifier.INSTANCE)) | |||
.toSortedSet(natural()); | |||
} |
@@ -1,46 +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.server.rule; | |||
import java.util.Arrays; | |||
import java.util.Collection; | |||
import java.util.List; | |||
import org.junit.Test; | |||
import org.sonar.api.rule.RuleKey; | |||
import org.sonar.test.TestUtils; | |||
import static com.google.common.collect.FluentIterable.from; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
public class RuleKeyFunctionsTest { | |||
@Test | |||
public void stringToRuleKey() { | |||
Collection<String> strings = Arrays.asList("js:S001", "java:S002"); | |||
List<RuleKey> keys = from(strings).transform(RuleKeyFunctions.stringToRuleKey()).toList(); | |||
assertThat(keys).containsExactly(RuleKey.of("js", "S001"), RuleKey.of("java", "S002")); | |||
} | |||
@Test | |||
public void on_static_methods() { | |||
assertThat(TestUtils.hasOnlyPrivateConstructors(RuleKeyFunctions.class)).isTrue(); | |||
} | |||
} |
@@ -1,56 +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.core.platform; | |||
import com.google.common.base.Function; | |||
import javax.annotation.Nonnull; | |||
public final class PluginInfoFunctions { | |||
private PluginInfoFunctions() { | |||
// utility class | |||
} | |||
public static Function<PluginInfo, String> toName() { | |||
return PluginInfoToName.INSTANCE; | |||
} | |||
public static Function<PluginInfo, String> toKey() { | |||
return PluginInfoToKey.INSTANCE; | |||
} | |||
private enum PluginInfoToName implements Function<PluginInfo, String> { | |||
INSTANCE; | |||
@Override | |||
public String apply(@Nonnull PluginInfo input) { | |||
return input.getName(); | |||
} | |||
} | |||
private enum PluginInfoToKey implements Function<PluginInfo, String> { | |||
INSTANCE; | |||
@Override | |||
public String apply(@Nonnull PluginInfo input) { | |||
return input.getKey(); | |||
} | |||
} | |||
} |