Skip to content

Commit

Permalink
Fix quality flaws
Browse files Browse the repository at this point in the history
  • Loading branch information
julienlancelot committed Mar 13, 2015
1 parent 2b49391 commit 2e14b83
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
Expand Up @@ -21,6 +21,7 @@
package org.sonar.server.computation.step; package org.sonar.server.computation.step;


import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import org.sonar.api.i18n.I18n; import org.sonar.api.i18n.I18n;
import org.sonar.api.resources.Qualifiers; import org.sonar.api.resources.Qualifiers;
Expand All @@ -37,6 +38,7 @@


import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map;
import java.util.Set; import java.util.Set;


import static com.google.common.collect.Sets.newHashSet; import static com.google.common.collect.Sets.newHashSet;
Expand All @@ -46,6 +48,14 @@ public class PersistComponentLinksStep implements ComputationStep {
private final DbClient dbClient; private final DbClient dbClient;
private final I18n i18n; private final I18n i18n;


private static final Map<Constants.ComponentLinkType, String> typesConverter = ImmutableMap.of(
Constants.ComponentLinkType.HOME, ComponentLinkDto.TYPE_HOME_PAGE,
Constants.ComponentLinkType.SCM, ComponentLinkDto.TYPE_SOURCES,
Constants.ComponentLinkType.SCM_DEV, ComponentLinkDto.TYPE_SOURCES_DEV,
Constants.ComponentLinkType.CI, ComponentLinkDto.TYPE_CI,
Constants.ComponentLinkType.ISSUE, ComponentLinkDto.TYPE_ISSUE_TRACKER
);

public PersistComponentLinksStep(DbClient dbClient, I18n i18n) { public PersistComponentLinksStep(DbClient dbClient, I18n i18n) {
this.dbClient = dbClient; this.dbClient = dbClient;
this.i18n = i18n; this.i18n = i18n;
Expand Down Expand Up @@ -123,20 +133,12 @@ public boolean apply(@Nullable ComponentLinkDto input) {
} }
} }


private static String convertType(Constants.ComponentLinkType type) { private static String convertType(Constants.ComponentLinkType reportType) {
switch (type) { String type = typesConverter.get(reportType);
case HOME: if (type != null) {
return ComponentLinkDto.TYPE_HOME_PAGE; return type;
case SCM: } else {
return ComponentLinkDto.TYPE_SOURCES; throw new IllegalArgumentException(String.format("Unsupported type %s", reportType.name()));
case SCM_DEV:
return ComponentLinkDto.TYPE_SOURCES_DEV;
case CI:
return ComponentLinkDto.TYPE_CI;
case ISSUE:
return ComponentLinkDto.TYPE_ISSUE_TRACKER;
default:
throw new IllegalArgumentException(String.format("Unsupported type %s", type.name()));
} }
} }


Expand Down
Expand Up @@ -30,11 +30,11 @@
*/ */
public class ComponentLinkDto { public class ComponentLinkDto {


public static String TYPE_HOME_PAGE = "homepage"; public static final String TYPE_HOME_PAGE = "homepage";
public static String TYPE_CI = "ci"; public static final String TYPE_CI = "ci";
public static String TYPE_ISSUE_TRACKER = "issue"; public static final String TYPE_ISSUE_TRACKER = "issue";
public static String TYPE_SOURCES = "scm"; public static final String TYPE_SOURCES = "scm";
public static String TYPE_SOURCES_DEV = "scm_dev"; public static final String TYPE_SOURCES_DEV = "scm_dev";


public static List<String> PROVIDED_TYPES = ImmutableList.of(TYPE_HOME_PAGE, TYPE_CI, TYPE_ISSUE_TRACKER, TYPE_SOURCES, TYPE_SOURCES_DEV); public static List<String> PROVIDED_TYPES = ImmutableList.of(TYPE_HOME_PAGE, TYPE_CI, TYPE_ISSUE_TRACKER, TYPE_SOURCES, TYPE_SOURCES_DEV);


Expand Down

0 comments on commit 2e14b83

Please sign in to comment.