diff options
author | Simon Brandhof <simon.brandhof@gmail.com> | 2014-02-20 22:55:25 +0100 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@gmail.com> | 2014-02-20 22:55:25 +0100 |
commit | 3f42ac85a4495333dbe76e1b1587ea05b7d900a4 (patch) | |
tree | ab77293f1318ae3e2800ef35e1a3d9fb31660ade /sonar-testing-harness/src | |
parent | dc41ad75cb32f1ff59b2ec61905bdbc2dc581dc5 (diff) | |
download | sonarqube-3f42ac85a4495333dbe76e1b1587ea05b7d900a4.tar.gz sonarqube-3f42ac85a4495333dbe76e1b1587ea05b7d900a4.zip |
RuleRepositoryTestHelper is back
Diffstat (limited to 'sonar-testing-harness/src')
-rw-r--r-- | sonar-testing-harness/src/main/java/org/sonar/test/i18n/RuleRepositoryTestHelper.java | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/sonar-testing-harness/src/main/java/org/sonar/test/i18n/RuleRepositoryTestHelper.java b/sonar-testing-harness/src/main/java/org/sonar/test/i18n/RuleRepositoryTestHelper.java new file mode 100644 index 00000000000..62c45d8f77b --- /dev/null +++ b/sonar-testing-harness/src/main/java/org/sonar/test/i18n/RuleRepositoryTestHelper.java @@ -0,0 +1,67 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2013 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube 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. + * + * SonarQube 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.test.i18n; + +import com.google.common.io.Closeables; +import org.sonar.api.rules.Rule; +import org.sonar.api.rules.RuleRepository; +import org.sonar.api.utils.SonarException; +import org.sonar.test.TestUtils; + +import java.io.IOException; +import java.io.InputStream; +import java.util.List; +import java.util.Properties; + +public final class RuleRepositoryTestHelper { + private RuleRepositoryTestHelper() { + // Static utility class + } + + public static List<Rule> createRulesWithNameAndDescription(String pluginKey, RuleRepository repository) { + Properties props = loadProperties(String.format("/org/sonar/l10n/%s.properties", pluginKey)); + + List<Rule> rules = repository.createRules(); + for (Rule rule : rules) { + String name = props.getProperty(String.format("rule.%s.%s.name", repository.getKey(), rule.getKey())); + String description = TestUtils.getResourceContent(String.format("/org/sonar/l10n/%s/rules/%s/%s.html", pluginKey, repository.getKey(), rule.getKey())); + + rule.setName(name); + rule.setDescription(description); + } + + return rules; + } + + private static Properties loadProperties(String resourcePath) { + Properties properties = new Properties(); + + InputStream input = null; + try { + input = TestUtils.class.getResourceAsStream(resourcePath); + properties.load(input); + return properties; + } catch (IOException e) { + throw new SonarException("Unable to read properties " + resourcePath, e); + } finally { + Closeables.closeQuietly(input); + } + } +} |