org.sonar.maven.ProfileProvider Maven / Gradle / Ivy
/*
* Sonar, open source software quality management tool.
* Copyright (C) 2009 SonarSource SA
* mailto:contact AT sonarsource DOT com
*
* Sonar 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.
*
* Sonar 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 Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
package org.sonar.maven;
import org.picocontainer.injectors.ProviderAdapter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.commons.profiles.ProfilesDao;
import org.sonar.commons.rules.RulesProfile;
import org.sonar.plugins.api.maven.model.MavenPom;
public class ProfileProvider extends ProviderAdapter {
private static final Logger LOG = LoggerFactory.getLogger(ProfileProvider.class);
private RulesProfile profile;
public RulesProfile provide(MavenPom pom, ProfilesDao dao) {
if (profile == null) {
String profileName = (String) pom.getProperty(MavenPom.PARAM_PROFILE);
if (profileName == null) {
MavenPom rootPom = pom.getRootPom();
profile = dao.getActiveProfile(rootPom.getLanguageKey(), rootPom.getKey());
if (profile == null) {
throw new RuntimeException("Quality profile not found for " + rootPom.getKey() + ", language " + rootPom.getLanguageKey());
}
} else {
profile = dao.getProfile(pom.getLanguageKey(), profileName);
if (profile == null) {
throw new RuntimeException("Quality profile not found : " + profileName + ", language " + pom.getLanguageKey());
}
}
LOG.info("Selected quality profile : {}", profile);
}
return profile;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy