All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.api.checks.CheckFactory Maven / Gradle / Ivy

There is a newer version: 9.4.0.54424
Show newest version
/*
 * 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.api.checks;

import com.google.common.collect.Maps;
import org.sonar.api.profiles.RulesProfile;
import org.sonar.api.rules.ActiveRule;

import java.util.Collection;
import java.util.Map;

/**
 * @since 2.3
 * @deprecated since 4.2 use {@link org.sonar.api.batch.rule.CheckFactory}
 */
@Deprecated
public abstract class CheckFactory {

  private Map checkByActiveRule = Maps.newIdentityHashMap();
  private Map activeRuleByCheck = Maps.newIdentityHashMap();
  private RulesProfile profile;
  private String repositoryKey;

  protected CheckFactory(RulesProfile profile, String repositoryKey) {
    this.repositoryKey = repositoryKey;
    this.profile = profile;
  }

  protected void init() {
    checkByActiveRule.clear();
    activeRuleByCheck.clear();
    for (ActiveRule activeRule : profile.getActiveRulesByRepository(repositoryKey)) {
      C check = createCheck(activeRule);
      checkByActiveRule.put(activeRule, check);
      activeRuleByCheck.put(check, activeRule);
    }
  }

  abstract C createCheck(ActiveRule activeRule);

  public final String getRepositoryKey() {
    return repositoryKey;
  }

  public final Collection getChecks() {
    return checkByActiveRule.values();
  }

  public final C getCheck(ActiveRule activeRule) {
    return checkByActiveRule.get(activeRule);
  }

  public final ActiveRule getActiveRule(C check) {
    return activeRuleByCheck.get(check);
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy