001 /*
002 * SonarQube, open source software quality management tool.
003 * Copyright (C) 2008-2014 SonarSource
004 * mailto:contact AT sonarsource DOT com
005 *
006 * SonarQube is free software; you can redistribute it and/or
007 * modify it under the terms of the GNU Lesser General Public
008 * License as published by the Free Software Foundation; either
009 * version 3 of the License, or (at your option) any later version.
010 *
011 * SonarQube is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014 * Lesser General Public License for more details.
015 *
016 * You should have received a copy of the GNU Lesser General Public License
017 * along with this program; if not, write to the Free Software Foundation,
018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
019 */
020 package org.sonar.batch.rule;
021
022 import com.google.common.collect.ImmutableMap;
023 import org.sonar.api.BatchComponent;
024 import org.sonar.batch.protocol.input.ProjectReferentials;
025
026 import javax.annotation.CheckForNull;
027
028 import java.util.Collection;
029 import java.util.Map;
030
031 /**
032 * Lists the Quality profiles enabled on the current module.
033 */
034 public class ModuleQProfiles implements BatchComponent {
035
036 public static final String SONAR_PROFILE_PROP = "sonar.profile";
037 private final Map<String, QProfile> byLanguage;
038
039 public ModuleQProfiles(ProjectReferentials ref) {
040 ImmutableMap.Builder<String, QProfile> builder = ImmutableMap.builder();
041
042 for (org.sonar.batch.protocol.input.QProfile qProfile : ref.qProfiles()) {
043 builder.put(qProfile.language(),
044 new QProfile().setKey(qProfile.key()).setName(qProfile.name()).setLanguage(qProfile.language()).setRulesUpdatedAt(qProfile.rulesUpdatedAt()));
045 }
046 byLanguage = builder.build();
047 }
048
049 public Collection<QProfile> findAll() {
050 return byLanguage.values();
051 }
052
053 @CheckForNull
054 public QProfile findByLanguage(String language) {
055 return byLanguage.get(language);
056 }
057 }