aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-deprecated/src
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2011-05-25 11:00:03 +0200
committersimonbrandhof <simon.brandhof@gmail.com>2011-05-25 23:56:22 +0200
commit27b6358cba309925505e09f4d44d3157435bf096 (patch)
treed6c4e61d472e4e8abe4cbf0093f786d53bf58968 /sonar-deprecated/src
parentafb886f523968dbdbd4ee7a3ee6a85052e12bde9 (diff)
downloadsonarqube-27b6358cba309925505e09f4d44d3157435bf096.tar.gz
sonarqube-27b6358cba309925505e09f4d44d3157435bf096.zip
SONAR-2469 refactor Module
SONAR-2469 instanciation strategy of batch extensions SONAR-2469 fix initialization of project
Diffstat (limited to 'sonar-deprecated/src')
-rw-r--r--sonar-deprecated/src/main/java/org/sonar/api/checks/templates/AnnotationCheckTemplateFactory.java114
-rw-r--r--sonar-deprecated/src/main/java/org/sonar/api/checks/templates/BundleCheckTemplate.java110
-rw-r--r--sonar-deprecated/src/main/java/org/sonar/api/checks/templates/BundleCheckTemplateProperty.java69
-rw-r--r--sonar-deprecated/src/main/java/org/sonar/api/checks/templates/CheckTemplate.java134
-rw-r--r--sonar-deprecated/src/main/java/org/sonar/api/checks/templates/CheckTemplateFactory.java33
-rw-r--r--sonar-deprecated/src/main/java/org/sonar/api/checks/templates/CheckTemplateProperty.java71
-rw-r--r--sonar-deprecated/src/main/java/org/sonar/api/checks/templates/CheckTemplateRepositories.java64
-rw-r--r--sonar-deprecated/src/main/java/org/sonar/api/checks/templates/CheckTemplateRepository.java170
-rw-r--r--sonar-deprecated/src/main/java/org/sonar/api/checks/templates/DefaultCheckTemplate.java81
-rw-r--r--sonar-deprecated/src/main/java/org/sonar/api/checks/templates/DefaultCheckTemplateProperty.java62
-rw-r--r--sonar-deprecated/src/main/java/org/sonar/api/checks/templates/XmlCheckTemplateFactory.java100
-rw-r--r--sonar-deprecated/src/main/java/org/sonar/api/rules/AbstractImportableRulesRepository.java75
-rw-r--r--sonar-deprecated/src/main/java/org/sonar/api/rules/AbstractRulesRepository.java76
-rw-r--r--sonar-deprecated/src/main/java/org/sonar/api/rules/ConfigurationExportable.java29
-rw-r--r--sonar-deprecated/src/main/java/org/sonar/api/rules/ConfigurationImportable.java30
-rw-r--r--sonar-deprecated/src/main/java/org/sonar/api/rules/RulesRepository.java58
-rw-r--r--sonar-deprecated/src/main/java/org/sonar/api/rules/StandardProfileXmlParser.java119
-rw-r--r--sonar-deprecated/src/main/java/org/sonar/api/rules/StandardRulesXmlParser.java158
-rw-r--r--sonar-deprecated/src/test/java/org/sonar/api/checks/templates/AnnotationCheckTemplateFactoryTest.java159
-rw-r--r--sonar-deprecated/src/test/java/org/sonar/api/checks/templates/BundleCheckTemplateTest.java74
-rw-r--r--sonar-deprecated/src/test/java/org/sonar/api/checks/templates/CheckTemplateRepositoriesTest.java57
-rw-r--r--sonar-deprecated/src/test/java/org/sonar/api/checks/templates/DefaultCheckTemplateTest.java42
-rw-r--r--sonar-deprecated/src/test/java/org/sonar/api/rules/StandardProfileXmlParserTest.java174
-rw-r--r--sonar-deprecated/src/test/java/org/sonar/api/rules/StandardRulesXmlParserTest.java125
-rw-r--r--sonar-deprecated/src/test/resources/org/sonar/api/rules/test_profile.xml7
-rw-r--r--sonar-deprecated/src/test/resources/org/sonar/api/rules/test_profile_name_null.xml6
26 files changed, 0 insertions, 2197 deletions
diff --git a/sonar-deprecated/src/main/java/org/sonar/api/checks/templates/AnnotationCheckTemplateFactory.java b/sonar-deprecated/src/main/java/org/sonar/api/checks/templates/AnnotationCheckTemplateFactory.java
deleted file mode 100644
index 74de09d275b..00000000000
--- a/sonar-deprecated/src/main/java/org/sonar/api/checks/templates/AnnotationCheckTemplateFactory.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2011 SonarSource
- * 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.api.checks.templates;
-
-import org.apache.commons.lang.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.sonar.check.AnnotationIntrospector;
-
-import java.lang.reflect.Field;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-/**
- * @since 2.1 (experimental)
- * @deprecated since 2.3
- */
-@Deprecated
-public class AnnotationCheckTemplateFactory {
-
- private static final Logger LOG = LoggerFactory.getLogger(AnnotationCheckTemplateFactory.class);
-
- private Collection<Class> annotatedClasses;
-
- public AnnotationCheckTemplateFactory(Collection<Class> annotatedClasses) {
- this.annotatedClasses = annotatedClasses;
- }
-
- public List<CheckTemplate> create() {
- List<CheckTemplate> templates = new ArrayList<CheckTemplate>();
- for (Class annotatedClass : annotatedClasses) {
- BundleCheckTemplate template = create(annotatedClass);
- if (template != null) {
- templates.add(template);
- }
- }
- return templates;
- }
-
-
- protected BundleCheckTemplate create(Class annotatedClass) {
- org.sonar.check.Check checkAnnotation = AnnotationIntrospector.getCheckAnnotation(annotatedClass);
- if (checkAnnotation == null) {
- LOG.warn("The class " + annotatedClass.getCanonicalName() + " is not a check template. It should be annotated with " + CheckTemplate.class);
- return null;
- }
-
- BundleCheckTemplate check = toTemplate(annotatedClass, checkAnnotation);
- Field[] fields = annotatedClass.getDeclaredFields();
- if (fields != null) {
- for (Field field : fields) {
- BundleCheckTemplateProperty property = toProperty(check, field);
- if (property != null) {
- check.addProperty(property);
- }
- }
- }
- return check;
- }
-
- private static BundleCheckTemplate toTemplate(Class annotatedClass, org.sonar.check.Check checkAnnotation) {
- String key = AnnotationIntrospector.getCheckKey(annotatedClass);
- String bundle = getBundleBaseName(checkAnnotation, annotatedClass);
-
- BundleCheckTemplate check = new BundleCheckTemplate(key, bundle);
- check.setDefaultDescription(checkAnnotation.description());
- check.setDefaultTitle(checkAnnotation.title());
- check.setIsoCategory(checkAnnotation.isoCategory());
- check.setPriority(checkAnnotation.priority());
-
- return check;
- }
-
- private static String getBundleBaseName(org.sonar.check.Check checkAnnotation, Class annotatedClass) {
- String bundle = checkAnnotation.bundle();
- if (StringUtils.isBlank(bundle)) {
- bundle = annotatedClass.getCanonicalName();
- }
- return bundle;
- }
-
- private static BundleCheckTemplateProperty toProperty(BundleCheckTemplate check, Field field) {
- org.sonar.check.CheckProperty propertyAnnotation = field.getAnnotation(org.sonar.check.CheckProperty.class);
- if (propertyAnnotation != null) {
- String fieldKey = propertyAnnotation.key();
- if (fieldKey==null || "".equals(fieldKey)) {
- fieldKey = field.getName();
- }
- BundleCheckTemplateProperty property = new BundleCheckTemplateProperty(check, fieldKey);
- property.setDefaultTitle(propertyAnnotation.title());
- property.setDefaultDescription(propertyAnnotation.description());
- return property;
- }
- return null;
- }
-}
diff --git a/sonar-deprecated/src/main/java/org/sonar/api/checks/templates/BundleCheckTemplate.java b/sonar-deprecated/src/main/java/org/sonar/api/checks/templates/BundleCheckTemplate.java
deleted file mode 100644
index 55a5e11dd96..00000000000
--- a/sonar-deprecated/src/main/java/org/sonar/api/checks/templates/BundleCheckTemplate.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2011 SonarSource
- * 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.api.checks.templates;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.Locale;
-import java.util.MissingResourceException;
-import java.util.ResourceBundle;
-
-/**
- * @since 2.1 (experimental)
- * @deprecated since 2.3
- */
-@Deprecated
-public class BundleCheckTemplate extends CheckTemplate {
- private static final Logger LOG = LoggerFactory.getLogger(BundleCheckTemplate.class);
-
- private String bundleBaseName;
- private String defaultTitle;
- private String defaultDescription;
-
- protected BundleCheckTemplate(String key, String bundleBaseName) {
- super(key);
- this.bundleBaseName = bundleBaseName;
- }
-
- protected BundleCheckTemplate(String key, Class bundleClass) {
- this(key, bundleClass.getCanonicalName());
- }
-
- protected String getDefaultTitle() {
- if (defaultTitle == null || "".equals(defaultTitle)) {
- return getKey();
- }
- return defaultTitle;
- }
-
- protected void setDefaultTitle(String defaultTitle) {
- this.defaultTitle = defaultTitle;
- }
-
- protected String getDefaultDescription() {
- return defaultDescription;
- }
-
- protected void setDefaultDescription(String defaultDescription) {
- this.defaultDescription = defaultDescription;
- }
-
- @Override
- public String getTitle(Locale locale) {
- return getText("title", locale, getDefaultTitle());
- }
-
- @Override
- public String getDescription(Locale locale) {
- return getText("description", locale, getDefaultDescription());
- }
-
- @Override
- public String getMessage(Locale locale, String key, Object... params) {
- return null;
- }
-
- protected String getText(String key, Locale locale, String defaultValue) {
- String result = null;
- ResourceBundle bundle = getBundle(locale);
- if (bundle != null) {
- try {
- result = bundle.getString(key);
- } catch (MissingResourceException e) {
- LOG.debug(e.getMessage());
- }
- }
- if (result == null) {
- result = defaultValue;
- }
- return result;
- }
-
- protected ResourceBundle getBundle(Locale locale) {
- try {
- if (locale != null) {
- return ResourceBundle.getBundle(bundleBaseName, locale);
- }
- } catch (MissingResourceException e) {
- // do nothing : use the default values
- }
- return null;
- }
-}
diff --git a/sonar-deprecated/src/main/java/org/sonar/api/checks/templates/BundleCheckTemplateProperty.java b/sonar-deprecated/src/main/java/org/sonar/api/checks/templates/BundleCheckTemplateProperty.java
deleted file mode 100644
index 6c87a39200b..00000000000
--- a/sonar-deprecated/src/main/java/org/sonar/api/checks/templates/BundleCheckTemplateProperty.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2011 SonarSource
- * 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.api.checks.templates;
-
-import java.util.Locale;
-
-/**
- * @since 2.1 (experimental)
- * @deprecated since 2.3
- */
-@Deprecated
-public class BundleCheckTemplateProperty extends CheckTemplateProperty {
-
- private BundleCheckTemplate check;
- private String defaultTitle;
- private String defaultDescription;
-
- public BundleCheckTemplateProperty(BundleCheckTemplate check, String key) {
- setKey(key);
- this.check = check;
- }
-
- public String getDefaultTitle() {
- if (defaultTitle == null || "".equals(defaultTitle)) {
- return getKey();
- }
- return defaultTitle;
- }
-
- public void setDefaultTitle(String s) {
- this.defaultTitle = s;
- }
-
-
- @Override
- public String getTitle(Locale locale) {
- return check.getText("property." + getKey() + ".title", locale, getDefaultTitle());
- }
-
- public String getDefaultDescription() {
- return defaultDescription;
- }
-
- public void setDefaultDescription(String s) {
- this.defaultDescription = s;
- }
-
- @Override
- public String getDescription(Locale locale) {
- return check.getText("property." + getKey() + ".description", locale, getDefaultDescription());
- }
-}
diff --git a/sonar-deprecated/src/main/java/org/sonar/api/checks/templates/CheckTemplate.java b/sonar-deprecated/src/main/java/org/sonar/api/checks/templates/CheckTemplate.java
deleted file mode 100644
index 313e64a4c80..00000000000
--- a/sonar-deprecated/src/main/java/org/sonar/api/checks/templates/CheckTemplate.java
+++ /dev/null
@@ -1,134 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2011 SonarSource
- * 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.api.checks.templates;
-
-import org.sonar.check.IsoCategory;
-import org.sonar.check.Priority;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Locale;
-
-/**
- * @since 2.1 (experimental)
- * @deprecated since 2.3
- */
-@Deprecated
-public abstract class CheckTemplate {
-
- protected String key;
- protected String configKey;
- protected Priority priority;
- protected IsoCategory isoCategory;
- protected List<CheckTemplateProperty> properties;
-
- public CheckTemplate(String key) {
- this.key = key;
- }
-
- public CheckTemplate() {
- }
-
- public String getKey() {
- return key;
- }
-
- public void setKey(String s) {
- this.key = s;
- }
-
- public Priority getPriority() {
- return priority;
- }
-
- public void setPriority(Priority p) {
- this.priority = p;
- }
-
- public IsoCategory getIsoCategory() {
- return isoCategory;
- }
-
- public void setIsoCategory(IsoCategory c) {
- this.isoCategory = c;
- }
-
- public String getConfigKey() {
- return configKey;
- }
-
- public void setConfigKey(String configKey) {
- this.configKey = configKey;
- }
-
- public abstract String getTitle(Locale locale);
-
- public abstract String getDescription(Locale locale);
-
- public abstract String getMessage(Locale locale, String key, Object... params);
-
- public List<CheckTemplateProperty> getProperties() {
- if (properties==null) {
- return Collections.emptyList();
- }
- return properties;
- }
-
- public void addProperty(CheckTemplateProperty p) {
- if (properties==null) {
- properties = new ArrayList<CheckTemplateProperty>();
- }
- properties.add(p);
- }
-
- public CheckTemplateProperty getProperty(String key) {
- if (properties!=null) {
- for (CheckTemplateProperty property : properties) {
- if (property.getKey().equals(key)) {
- return property;
- }
- }
- }
- return null;
- }
-
- /**
- * Checks are equal within the same plugin. Two plugins can have two different checks with the same key.
- */
- @Override
- public final boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (!(o instanceof CheckTemplate)) {
- return false;
- }
-
- CheckTemplate checkTemplate = (CheckTemplate) o;
- return key.equals(checkTemplate.key);
- }
-
- @Override
- public final int hashCode() {
- return key.hashCode();
- }
-
-} \ No newline at end of file
diff --git a/sonar-deprecated/src/main/java/org/sonar/api/checks/templates/CheckTemplateFactory.java b/sonar-deprecated/src/main/java/org/sonar/api/checks/templates/CheckTemplateFactory.java
deleted file mode 100644
index 7f1aa486db3..00000000000
--- a/sonar-deprecated/src/main/java/org/sonar/api/checks/templates/CheckTemplateFactory.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2011 SonarSource
- * 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.api.checks.templates;
-
-import java.util.Collection;
-
-/**
- * @since 2.1 (experimental)
- * @deprecated since 2.3
- */
-@Deprecated
-public abstract class CheckTemplateFactory {
-
- public abstract Collection<CheckTemplate> create();
-
-}
diff --git a/sonar-deprecated/src/main/java/org/sonar/api/checks/templates/CheckTemplateProperty.java b/sonar-deprecated/src/main/java/org/sonar/api/checks/templates/CheckTemplateProperty.java
deleted file mode 100644
index b94082d9c7c..00000000000
--- a/sonar-deprecated/src/main/java/org/sonar/api/checks/templates/CheckTemplateProperty.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2011 SonarSource
- * 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.api.checks.templates;
-
-import java.util.Locale;
-
-/**
- * @since 2.1 (experimental)
- * @deprecated since 2.3
- */
-@Deprecated
-public abstract class CheckTemplateProperty implements Comparable<CheckTemplateProperty> {
-
- protected String key;
-
- public String getKey() {
- return key;
- }
-
- public void setKey(String s) {
- this.key = s;
- }
-
- public abstract String getTitle(Locale locale);
-
- public String getDescription() {
- return getDescription(Locale.ENGLISH);
- }
-
-
- public abstract String getDescription(Locale locale);
-
- @Override
- public final boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (!(o instanceof CheckTemplateProperty)) {
- return false;
- }
-
- CheckTemplateProperty that = (CheckTemplateProperty) o;
- return key.equals(that.key);
- }
-
- @Override
- public final int hashCode() {
- return key.hashCode();
- }
-
- public int compareTo(CheckTemplateProperty o) {
- return getKey().compareTo(o.getKey());
- }
-}
diff --git a/sonar-deprecated/src/main/java/org/sonar/api/checks/templates/CheckTemplateRepositories.java b/sonar-deprecated/src/main/java/org/sonar/api/checks/templates/CheckTemplateRepositories.java
deleted file mode 100644
index 4cc5029413d..00000000000
--- a/sonar-deprecated/src/main/java/org/sonar/api/checks/templates/CheckTemplateRepositories.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2011 SonarSource
- * 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.api.checks.templates;
-
-import org.sonar.api.ServerExtension;
-
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * @since 2.1 (experimental)
- * @deprecated since 2.3
- */
-@Deprecated
-public class CheckTemplateRepositories implements ServerExtension {
-
- private Map<String, CheckTemplateRepository> repositoriesByKey = new HashMap<String, CheckTemplateRepository>();
-
- public CheckTemplateRepositories(CheckTemplateRepository[] repositories) {
- if (repositories != null) {
- for (CheckTemplateRepository templateRepository : repositories) {
- repositoriesByKey.put(templateRepository.getKey(), templateRepository);
- }
- }
- }
-
- public CheckTemplateRepositories() {
- // DO NOT REMOVE THIS CONSTRUCTOR. It is used by Picocontainer when no repositories are available.
- }
-
- public CheckTemplateRepository getRepository(String key) {
- return repositoriesByKey.get(key);
- }
-
- public Collection<CheckTemplateRepository> getRepositories() {
- return repositoriesByKey.values();
- }
-
- public CheckTemplate getTemplate(String repositoryKey, String templateKey) {
- CheckTemplateRepository repo = getRepository(repositoryKey);
- if (repo != null) {
- return repo.getTemplate(templateKey);
- }
- return null;
- }
-}
diff --git a/sonar-deprecated/src/main/java/org/sonar/api/checks/templates/CheckTemplateRepository.java b/sonar-deprecated/src/main/java/org/sonar/api/checks/templates/CheckTemplateRepository.java
deleted file mode 100644
index 3ce30317cb2..00000000000
--- a/sonar-deprecated/src/main/java/org/sonar/api/checks/templates/CheckTemplateRepository.java
+++ /dev/null
@@ -1,170 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2011 SonarSource
- * 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.api.checks.templates;
-
-import org.apache.commons.io.IOUtils;
-import org.sonar.api.profiles.RulesProfile;
-import org.sonar.api.resources.Language;
-import org.sonar.api.rules.Rule;
-import org.sonar.api.rules.RuleParam;
-import org.sonar.api.rules.RulePriority;
-import org.sonar.api.rules.RulesRepository;
-
-import java.io.InputStream;
-import java.util.*;
-
-/**
- * @since 2.1 (experimental)
- * @deprecated since 2.3
- */
-@Deprecated
-public class CheckTemplateRepository implements RulesRepository {
-
- private String key;
- private Language language;
- private List<CheckTemplate> templates;
- private Map<String, CheckTemplate> templatesByKey;
-
- public CheckTemplateRepository() {
- }
-
- public CheckTemplateRepository(String key) {
- if (key == null) {
- throw new IllegalArgumentException("Key can not be null");
- }
- this.key = key;
- }
-
- public String getKey() {
- return key;
- }
-
- public CheckTemplateRepository setKey(String key) {
- this.key = key;
- return this;
- }
-
- public Language getLanguage() {
- return language;
- }
-
- public CheckTemplateRepository setLanguage(Language l) {
- this.language = l;
- return this;
- }
-
- public List<CheckTemplate> getTemplates() {
- if (templates == null) {
- return Collections.emptyList();
- }
- return templates;
- }
-
- public CheckTemplateRepository setTemplates(List<CheckTemplate> c) {
- this.templates = c;
- return this;
- }
-
- public CheckTemplate getTemplate(String key) {
- if (templatesByKey == null || templatesByKey.isEmpty()) {
- templatesByKey = new HashMap<String, CheckTemplate>();
- for (CheckTemplate template : templates) {
- templatesByKey.put(template.getKey(), template);
- }
- }
- return templatesByKey.get(key);
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (o == null || getClass() != o.getClass()) {
- return false;
- }
-
- CheckTemplateRepository that = (CheckTemplateRepository) o;
- return key.equals(that.key);
-
- }
-
- @Override
- public int hashCode() {
- return key.hashCode();
- }
-
- public static CheckTemplateRepository createFromXml(String repositoryKey, Language language, String pathToXml) {
- InputStream input = CheckTemplateRepository.class.getResourceAsStream(pathToXml);
- try {
- List<CheckTemplate> templates = new XmlCheckTemplateFactory().parse(input);
- CheckTemplateRepository repository = new CheckTemplateRepository(repositoryKey);
- repository.setTemplates(templates);
- repository.setLanguage(language);
- return repository;
-
- } finally {
- IOUtils.closeQuietly(input);
- }
- }
-
- public static CheckTemplateRepository createFromAnnotatedClasses(String repositoryKey, Language language, Collection<Class> classes) {
- AnnotationCheckTemplateFactory factory = new AnnotationCheckTemplateFactory(classes);
- CheckTemplateRepository repository = new CheckTemplateRepository(repositoryKey);
- repository.setTemplates(factory.create());
- repository.setLanguage(language);
- return repository;
- }
-
- /*
- * CODE FOR BACKWARD COMPATIBLITY
- * This class should not extend RulesRepository in next versions
- */
-
- public List<Rule> getInitialReferential() {
- List<Rule> rules = new ArrayList<Rule>();
- for (CheckTemplate checkTemplate : getTemplates()) {
- rules.add(toRule(checkTemplate));
- }
- return rules;
- }
-
- private Rule toRule(CheckTemplate checkTemplate) {
- Rule rule = new Rule(getKey(), checkTemplate.getKey());
- rule.setDescription(checkTemplate.getDescription(Locale.ENGLISH));
- rule.setName(checkTemplate.getTitle(Locale.ENGLISH));
- rule.setSeverity(RulePriority.fromCheckPriority(checkTemplate.getPriority()));
- for (CheckTemplateProperty checkTemplateProperty : checkTemplate.getProperties()) {
- RuleParam param = rule.createParameter(checkTemplateProperty.getKey());
- param.setDescription(checkTemplateProperty.getDescription(Locale.ENGLISH));
- param.setType("s");
- }
-
- return rule;
- }
-
- public List<Rule> parseReferential(String fileContent) {
- return Collections.emptyList();
- }
-
- public List<RulesProfile> getProvidedProfiles() {
- return Collections.emptyList();
- }
-}
diff --git a/sonar-deprecated/src/main/java/org/sonar/api/checks/templates/DefaultCheckTemplate.java b/sonar-deprecated/src/main/java/org/sonar/api/checks/templates/DefaultCheckTemplate.java
deleted file mode 100644
index e1fa871fdd2..00000000000
--- a/sonar-deprecated/src/main/java/org/sonar/api/checks/templates/DefaultCheckTemplate.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2011 SonarSource
- * 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.api.checks.templates;
-
-import org.apache.commons.lang.builder.ToStringBuilder;
-
-import java.util.Locale;
-
-/**
- * EXPERIMENTAL - will be used in version 2.2
- *
- * Non-internationalized check
- *
- * @since 2.1
- */
-public class DefaultCheckTemplate extends CheckTemplate {
-
- private String title;
- private String description;
-
- public DefaultCheckTemplate() {
- }
-
- public DefaultCheckTemplate(String key) {
- super(key);
- }
-
- public void setTitle(String title) {
- this.title = title;
- }
-
- public void setDescription(String description) {
- this.description = description;
- }
-
- @Override
- public String getTitle(Locale locale) {
- if (title == null || "".equals(title)) {
- return getKey();
- }
- return title;
- }
-
- @Override
- public String getDescription(Locale locale) {
- return description;
- }
-
- @Override
- public String getMessage(Locale locale, String key, Object... params) {
- return null;
- }
-
- @Override
- public String toString() {
- return new ToStringBuilder(this)
- .append("key", key)
- .append("title", title)
- .append("configKey", configKey)
- .append("priority", priority)
- .append("isoCategory", isoCategory)
- .toString();
- }
-}
diff --git a/sonar-deprecated/src/main/java/org/sonar/api/checks/templates/DefaultCheckTemplateProperty.java b/sonar-deprecated/src/main/java/org/sonar/api/checks/templates/DefaultCheckTemplateProperty.java
deleted file mode 100644
index 06f9e2eb648..00000000000
--- a/sonar-deprecated/src/main/java/org/sonar/api/checks/templates/DefaultCheckTemplateProperty.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2011 SonarSource
- * 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.api.checks.templates;
-
-import org.sonar.api.checks.templates.CheckTemplateProperty;
-
-import java.util.Locale;
-
-/**
- * @since 2.1
- */
-public class DefaultCheckTemplateProperty extends CheckTemplateProperty {
-
- private String title;
- private String description;
-
- public String getTitle() {
- if (title == null || "".equals(title)) {
- return getKey();
- }
- return title;
- }
-
- @Override
- public String getTitle(Locale locale) {
- return getTitle();
- }
-
- public void setTitle(String s) {
- this.title = s;
- }
-
- public String getDescription() {
- return description;
- }
-
- public void setDescription(String s) {
- this.description = s;
- }
-
- @Override
- public String getDescription(Locale locale) {
- return getDescription();
- }
-}
diff --git a/sonar-deprecated/src/main/java/org/sonar/api/checks/templates/XmlCheckTemplateFactory.java b/sonar-deprecated/src/main/java/org/sonar/api/checks/templates/XmlCheckTemplateFactory.java
deleted file mode 100644
index 3ffaed0f003..00000000000
--- a/sonar-deprecated/src/main/java/org/sonar/api/checks/templates/XmlCheckTemplateFactory.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2011 SonarSource
- * 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.api.checks.templates;
-
-import org.apache.commons.io.IOUtils;
-import org.apache.commons.lang.CharEncoding;
-import org.sonar.api.rules.Rule;
-import org.sonar.api.rules.RuleParam;
-import org.sonar.api.rules.StandardRulesXmlParser;
-import org.sonar.api.utils.SonarException;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.Reader;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * EXPERIMENTAL - will be used in version 2.2
- *
- * @since 2.1
- */
-public class XmlCheckTemplateFactory {
-
- public List<CheckTemplate> parseXml(String xml) {
- InputStream input = null;
- try {
- input = IOUtils.toInputStream(xml, CharEncoding.UTF_8);
- return parse(input);
-
- } catch (IOException e) {
- throw new SonarException("Can't parse xml file", e);
-
- } finally {
- IOUtils.closeQuietly(input);
- }
- }
-
- public List<CheckTemplate> parse(Reader reader) {
- StandardRulesXmlParser parser = new StandardRulesXmlParser();
- List<Rule> rules = parser.parse(reader);
- return toCheckTemplates(rules);
-
- }
-
- public List<CheckTemplate> parse(InputStream input) {
- StandardRulesXmlParser parser = new StandardRulesXmlParser();
- List<Rule> rules = parser.parse(input);
- return toCheckTemplates(rules);
-
- }
-
- private List<CheckTemplate> toCheckTemplates(List<Rule> rules) {
- List<CheckTemplate> templates = new ArrayList<CheckTemplate>();
- if (rules != null) {
- for (Rule rule : rules) {
- DefaultCheckTemplate template = new DefaultCheckTemplate(rule.getKey());
- templates.add(template);
-
- template.setConfigKey(rule.getConfigKey());
- template.setDescription(rule.getDescription());
- template.setPriority(rule.getSeverity().toCheckPriority());
- template.setTitle(rule.getName());
-
- if (rule.getParams() != null) {
- for (RuleParam param : rule.getParams()) {
- template.addProperty(toProperty(param));
- }
- }
- }
- }
- return templates;
- }
-
- private CheckTemplateProperty toProperty(RuleParam param) {
- DefaultCheckTemplateProperty property = new DefaultCheckTemplateProperty();
- property.setKey(param.getKey());
- property.setTitle(param.getKey());
- property.setDescription(param.getDescription());
- return property;
- }
-
-}
diff --git a/sonar-deprecated/src/main/java/org/sonar/api/rules/AbstractImportableRulesRepository.java b/sonar-deprecated/src/main/java/org/sonar/api/rules/AbstractImportableRulesRepository.java
deleted file mode 100644
index 99264e2a141..00000000000
--- a/sonar-deprecated/src/main/java/org/sonar/api/rules/AbstractImportableRulesRepository.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2011 SonarSource
- * 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.api.rules;
-
-import org.apache.commons.io.IOUtils;
-import org.apache.commons.lang.CharEncoding;
-import org.sonar.api.profiles.RulesProfile;
-import org.sonar.api.resources.Language;
-import org.sonar.api.utils.SonarException;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.TreeMap;
-
-@Deprecated
-public abstract class AbstractImportableRulesRepository<LANG extends Language, MAPPER extends RulePriorityMapper<?, ?>> extends AbstractRulesRepository<LANG, MAPPER> implements ConfigurationImportable {
-
- public AbstractImportableRulesRepository(LANG language, MAPPER mapper) {
- super(language, mapper);
- }
-
- /**
- * A map a of profiles to import, The profile name as key, and the xml profile file name in the classpath
- *
- * @return
- */
- public abstract Map<String, String> getBuiltInProfiles();
-
- public final List<RulesProfile> getProvidedProfiles() {
- List<RulesProfile> profiles = new ArrayList<RulesProfile>();
-
- Map<String, String> defaultProfiles = new TreeMap<String, String>(getBuiltInProfiles());
- for (Map.Entry<String, String> entry : defaultProfiles.entrySet()) {
- profiles.add(loadProvidedProfile(entry.getKey(), getCheckResourcesBase() + entry.getValue()));
- }
- return profiles;
- }
-
- public final RulesProfile loadProvidedProfile(String name, String fileName) {
- InputStream input = null;
- try {
- input = getClass().getResourceAsStream(fileName);
- RulesProfile profile = new RulesProfile(name, getLanguage().getKey());
- profile.setActiveRules(importConfiguration(IOUtils.toString(input, CharEncoding.UTF_8), getInitialReferential()));
- return profile;
-
- } catch (IOException e) {
- throw new SonarException("Configuration file not found for the profile : " + name, e);
-
- } finally {
- IOUtils.closeQuietly(input);
- }
- }
-
-}
diff --git a/sonar-deprecated/src/main/java/org/sonar/api/rules/AbstractRulesRepository.java b/sonar-deprecated/src/main/java/org/sonar/api/rules/AbstractRulesRepository.java
deleted file mode 100644
index 5f7e1c3c99b..00000000000
--- a/sonar-deprecated/src/main/java/org/sonar/api/rules/AbstractRulesRepository.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2011 SonarSource
- * 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.api.rules;
-
-import org.apache.commons.io.IOUtils;
-import org.sonar.api.resources.Language;
-import org.sonar.api.utils.SonarException;
-
-import java.io.InputStream;
-import java.util.List;
-
-@Deprecated
-public abstract class AbstractRulesRepository<LANG extends Language, MAPPER extends RulePriorityMapper<?, ?>> implements RulesRepository<LANG> {
-
- private MAPPER priorityMapper;
- private LANG language;
-
- public AbstractRulesRepository(LANG language, MAPPER priorityMapper) {
- super();
- this.priorityMapper = priorityMapper;
- this.language = language;
- }
-
- public LANG getLanguage() {
- return language;
- }
-
- public abstract String getRepositoryResourcesBase();
-
- public final List<Rule> getInitialReferential() {
- String baseCP = getCheckResourcesBase();
- InputStream input = getClass().getResourceAsStream(baseCP + "rules.xml");
- if (input == null) {
- throw new SonarException("Resource not found : " + baseCP + "rules.xml");
- }
- try {
- return new StandardRulesXmlParser().parse(input);
- }
- finally {
- IOUtils.closeQuietly(input);
- }
- }
-
- public List<Rule> parseReferential(String fileContent) {
- return new StandardRulesXmlParser().parse(fileContent);
- }
-
- public MAPPER getRulePriorityMapper() {
- return priorityMapper;
- }
-
- protected String getCheckResourcesBase() {
- String base = getRepositoryResourcesBase();
- base = base.startsWith("/") ? base : "/" + base;
- base = base.endsWith("/") ? base : base + "/";
- return base;
- }
-
-}
diff --git a/sonar-deprecated/src/main/java/org/sonar/api/rules/ConfigurationExportable.java b/sonar-deprecated/src/main/java/org/sonar/api/rules/ConfigurationExportable.java
deleted file mode 100644
index c87b0cb88d8..00000000000
--- a/sonar-deprecated/src/main/java/org/sonar/api/rules/ConfigurationExportable.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2011 SonarSource
- * 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.api.rules;
-
-import org.sonar.api.profiles.RulesProfile;
-
-@Deprecated
-public interface ConfigurationExportable {
-
- String exportConfiguration(RulesProfile profile);
-
-}
diff --git a/sonar-deprecated/src/main/java/org/sonar/api/rules/ConfigurationImportable.java b/sonar-deprecated/src/main/java/org/sonar/api/rules/ConfigurationImportable.java
deleted file mode 100644
index 3c32c98f31c..00000000000
--- a/sonar-deprecated/src/main/java/org/sonar/api/rules/ConfigurationImportable.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2011 SonarSource
- * 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.api.rules;
-
-import java.util.List;
-import org.sonar.api.rules.Rule;
-
-@Deprecated
-public interface ConfigurationImportable {
-
- List<ActiveRule> importConfiguration(String configuration, List<Rule> rules);
-
-}
diff --git a/sonar-deprecated/src/main/java/org/sonar/api/rules/RulesRepository.java b/sonar-deprecated/src/main/java/org/sonar/api/rules/RulesRepository.java
deleted file mode 100644
index 2a09816b6c2..00000000000
--- a/sonar-deprecated/src/main/java/org/sonar/api/rules/RulesRepository.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2011 SonarSource
- * 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.api.rules;
-
-import org.sonar.api.BatchExtension;
-import org.sonar.api.ServerExtension;
-import org.sonar.api.profiles.RulesProfile;
-import org.sonar.api.resources.Language;
-
-import java.util.List;
-
-/**
- * @deprecated since 2.3
- */
-@Deprecated
-public interface RulesRepository<LANG extends Language> extends BatchExtension, ServerExtension {
-
- /**
- * @return the language the repository is associated
- */
- LANG getLanguage();
-
- /**
- * @return the list of rules of the repository
- */
- List<Rule> getInitialReferential();
-
- /**
- * The method to parse the base referential of rules and return a list of rules
- *
- * @param fileContent the initial referential
- * @return a list of rules
- */
- List<Rule> parseReferential(String fileContent);
-
- /**
- * @return a list of profiles that are provided with the referential
- */
- List<RulesProfile> getProvidedProfiles();
-
-}
diff --git a/sonar-deprecated/src/main/java/org/sonar/api/rules/StandardProfileXmlParser.java b/sonar-deprecated/src/main/java/org/sonar/api/rules/StandardProfileXmlParser.java
deleted file mode 100644
index e2098c4c872..00000000000
--- a/sonar-deprecated/src/main/java/org/sonar/api/rules/StandardProfileXmlParser.java
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2011 SonarSource
- * 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.api.rules;
-
-import com.thoughtworks.xstream.XStream;
-import org.apache.commons.lang.StringUtils;
-import org.sonar.api.profiles.RulesProfile;
-import org.sonar.api.rules.xml.Profile;
-import org.sonar.api.rules.xml.Property;
-import org.sonar.api.utils.SonarException;
-
-import java.util.ArrayList;
-import java.util.List;
-
-@Deprecated
-public class StandardProfileXmlParser {
-
- private final List<Rule> rules;
-
- public StandardProfileXmlParser() {
- rules = new ArrayList<Rule>();
- }
-
- public StandardProfileXmlParser(List<Rule> rules) {
- this.rules = rules;
- }
-
- /**
- * see the XML format into the unit test src/test/java/.../StandardProfileXmlParserTest
- */
- public Profile parse(String xml) {
- return (Profile) getXStream().fromXML(xml);
- }
-
- private XStream getXStream() {
- XStream xstream = new XStream();
- xstream.processAnnotations(Profile.class);
- xstream.processAnnotations(Rule.class);
- xstream.processAnnotations(Property.class);
- return xstream;
- }
-
- public RulesProfile importConfiguration(String configuration) {
- RulesProfile rulesProfile = new RulesProfile();
- List<ActiveRule> activeRules = new ArrayList<ActiveRule>();
- Profile profile = buildProfileFromXml(configuration);
-
- rulesProfile.setName(profile.getName());
- rulesProfile.setLanguage(profile.getLanguage());
-
- if (StringUtils.isBlank(rulesProfile.getName())) {
- throw new SonarException("Profile name can't be null or empty");
- }
-
- buildActiveRulesFromProfile(profile, activeRules);
- rulesProfile.setActiveRules(activeRules);
- return rulesProfile;
- }
-
- protected Profile buildProfileFromXml(String configuration) {
- StandardProfileXmlParser xstream = new StandardProfileXmlParser();
- return xstream.parse(configuration);
- }
-
- protected void buildActiveRulesFromProfile(Profile profile, List<ActiveRule> activeRules) {
- if (profile.getRules() != null && !profile.getRules().isEmpty()) {
- for (org.sonar.api.rules.xml.Rule module : profile.getRules()) {
- String ref = module.getKey();
- for (Rule rule : rules) {
- if (rule.getConfigKey().equals(ref)) {
- RulePriority rulePriority = getRulePriority(module);
- ActiveRule activeRule = new ActiveRule(null, rule, rulePriority);
- activeRule.setActiveRuleParams(getActiveRuleParams(module, rule, activeRule));
- activeRules.add(activeRule);
- break;
- }
- }
- }
- }
- }
-
- private RulePriority getRulePriority(org.sonar.api.rules.xml.Rule module) {
- return StringUtils.isBlank(module.getPriority()) ? null : RulePriority.valueOfString(module.getPriority());
- }
-
- private List<ActiveRuleParam> getActiveRuleParams(org.sonar.api.rules.xml.Rule module, Rule rule, ActiveRule activeRule) {
- List<ActiveRuleParam> activeRuleParams = new ArrayList<ActiveRuleParam>();
- if (module.getProperties() != null) {
- for (Property property : module.getProperties()) {
- if (rule.getParams() != null) {
- for (RuleParam ruleParam : rule.getParams()) {
- if (ruleParam.getKey().equals(property.getName())) {
- activeRuleParams.add(new ActiveRuleParam(activeRule, ruleParam, property.getValue()));
- }
- }
- }
- }
- }
- return activeRuleParams;
- }
-
-} \ No newline at end of file
diff --git a/sonar-deprecated/src/main/java/org/sonar/api/rules/StandardRulesXmlParser.java b/sonar-deprecated/src/main/java/org/sonar/api/rules/StandardRulesXmlParser.java
deleted file mode 100644
index cf3b1798408..00000000000
--- a/sonar-deprecated/src/main/java/org/sonar/api/rules/StandardRulesXmlParser.java
+++ /dev/null
@@ -1,158 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2011 SonarSource
- * 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.api.rules;
-
-import com.thoughtworks.xstream.XStream;
-import com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter;
-import com.thoughtworks.xstream.core.util.QuickWriter;
-import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
-import com.thoughtworks.xstream.io.xml.PrettyPrintWriter;
-import com.thoughtworks.xstream.io.xml.XppDriver;
-import org.apache.commons.io.IOUtils;
-import org.apache.commons.lang.CharEncoding;
-import org.apache.commons.lang.StringUtils;
-import org.sonar.api.utils.SonarException;
-
-import java.io.*;
-import java.lang.ref.WeakReference;
-import java.util.*;
-
-@Deprecated
-public class StandardRulesXmlParser {
-
- /**
- * see the XML format into the unit test src/test/java/.../StandardRulesXmlParserTest
- */
- public List<Rule> parse(String xml) {
- InputStream inputStream = null;
- try {
- inputStream = IOUtils.toInputStream(xml, CharEncoding.UTF_8);
- return setDefaultRuleSeverities((List<Rule>) getXStream().fromXML(inputStream));
-
- } catch (IOException e) {
- throw new SonarException("Can't parse xml file", e);
-
- } finally {
- IOUtils.closeQuietly(inputStream);
- }
- }
-
- public List<Rule> parse(Reader reader) {
- return setDefaultRuleSeverities((List<Rule>) getXStream().fromXML(reader));
- }
-
- public List<Rule> parse(InputStream input) {
- try {
- return setDefaultRuleSeverities((List<Rule>) getXStream().fromXML(new InputStreamReader(input, CharEncoding.UTF_8)));
-
- } catch (UnsupportedEncodingException e) {
- throw new SonarException("Can't parse xml file", e);
- }
- }
-
- private List<Rule> setDefaultRuleSeverities(List<Rule> rules) {
- for (Rule rule : rules) {
- if (rule.getSeverity() == null) {
- rule.setSeverity(RulePriority.MAJOR);
- }
- }
- return rules;
- }
-
- public String toXml(List<Rule> rules) {
- return getXStream().toXML(rules);
- }
-
- private static class CDataXppDriver extends XppDriver {
- @Override
- public HierarchicalStreamWriter createWriter(Writer out) {
- return new XDataPrintWriter(out);
- }
- }
-
- private static class XDataPrintWriter extends PrettyPrintWriter {
- public XDataPrintWriter(Writer writer) {
- super(writer);
- }
-
- @Override
- protected void writeText(QuickWriter writer, String text) {
- writer.write("<![CDATA[");
- writer.write(text);
- writer.write("]]>");
- }
- }
-
- private XStream getXStream() {
- XStream xstream = new XStream(new CDataXppDriver());
- xstream.registerConverter(new TrimStringConverter());
- xstream.alias("rules", ArrayList.class);
-
- xstream.omitField(Rule.class, "category");
-
- xstream.alias("rule", Rule.class);
- xstream.useAttributeFor(Rule.class, "key");
- xstream.useAttributeFor("priority", RulePriority.class);
-
- xstream.addImplicitCollection(Rule.class, "params");
-
- xstream.alias("param", RuleParam.class);
- xstream.useAttributeFor(RuleParam.class, "key");
- xstream.useAttributeFor(RuleParam.class, "type");
-
- // only for backward compatibility with sonar 1.4.
- xstream.omitField(RuleParam.class, "defaultValue");
- return xstream;
- }
-
- /**
- * See http://svn.codehaus.org/xstream/trunk/xstream/src/java/com/thoughtworks/xstream/converters/basic/StringConverter.java
- */
- public static class TrimStringConverter extends AbstractSingleValueConverter {
-
- private final Map cache;
-
- public TrimStringConverter(final Map map) {
- cache = map;
- }
-
- public TrimStringConverter() {
- this(Collections.synchronizedMap(new WeakHashMap()));
- }
-
- public boolean canConvert(final Class type) {
- return type.equals(String.class);
- }
-
- public Object fromString(final String str) {
- String trim = StringUtils.trim(str);
- final WeakReference ref = (WeakReference) cache.get(trim);
- String s = (String) (ref == null ? null : ref.get());
-
- if (s == null) {
- // fill cache
- cache.put(str, new WeakReference(trim));
- s = trim;
- }
-
- return s;
- }
- }
-}
diff --git a/sonar-deprecated/src/test/java/org/sonar/api/checks/templates/AnnotationCheckTemplateFactoryTest.java b/sonar-deprecated/src/test/java/org/sonar/api/checks/templates/AnnotationCheckTemplateFactoryTest.java
deleted file mode 100644
index bae346a718f..00000000000
--- a/sonar-deprecated/src/test/java/org/sonar/api/checks/templates/AnnotationCheckTemplateFactoryTest.java
+++ /dev/null
@@ -1,159 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2011 SonarSource
- * 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.api.checks.templates;
-
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.sonar.api.checks.samples.*;
-import org.sonar.check.IsoCategory;
-
-import java.util.Iterator;
-import java.util.Locale;
-
-import static junit.framework.Assert.assertNotNull;
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.*;
-
-public class AnnotationCheckTemplateFactoryTest {
-
- private static final Locale DEFAULT_LOCALE = Locale.ENGLISH;
- private static final Locale ALTERNATIVE_LOCALE = Locale.FRENCH;
- private static final Locale UNKNOWN_LOCALE = Locale.CHINESE;
-
- private static final Locale JVM_LOCALE = Locale.getDefault();
-
- @BeforeClass
- public static void beforeAll() {
- Locale.setDefault(Locale.ENGLISH);
- }
-
- @AfterClass
- public static void afterAll() {
- Locale.setDefault(JVM_LOCALE);
- }
-
- @Test
- public void checkWithDefaultValues() {
- BundleCheckTemplate check = new AnnotationCheckTemplateFactory(null).create(SimpleAnnotatedCheck.class);
- assertNotNull(check);
-
- assertThat(check.getKey(), is("org.sonar.api.checks.samples.SimpleAnnotatedCheck"));
-
- assertThat(check.getTitle(DEFAULT_LOCALE), is("org.sonar.api.checks.samples.SimpleAnnotatedCheck"));
- assertThat(check.getTitle(ALTERNATIVE_LOCALE), is("org.sonar.api.checks.samples.SimpleAnnotatedCheck"));
- assertThat(check.getTitle(UNKNOWN_LOCALE), is("org.sonar.api.checks.samples.SimpleAnnotatedCheck"));
-
- assertThat(check.getDescription(DEFAULT_LOCALE), is(""));
- assertThat(check.getDescription(ALTERNATIVE_LOCALE), is(""));
- assertThat(check.getDescription(UNKNOWN_LOCALE), is(""));
-
- assertEquals(IsoCategory.Efficiency, check.getIsoCategory());
-
- assertThat(check.getProperties().size(), is(2));
- Iterator<CheckTemplateProperty> it = check.getProperties().iterator();
-
- CheckTemplateProperty maxTemplateProperty = it.next();
- assertThat(maxTemplateProperty.getKey(), is("max"));
-
- assertThat(maxTemplateProperty.getDescription(DEFAULT_LOCALE), is(""));
- assertThat(maxTemplateProperty.getDescription(ALTERNATIVE_LOCALE), is(""));
- assertThat(maxTemplateProperty.getDescription(UNKNOWN_LOCALE), is(""));
-
- CheckTemplateProperty minTemplateProperty = it.next();
- assertThat(minTemplateProperty.getKey(), is("min"));
- }
-
- @Test
- public void failOnNonCheckClass() {
- assertNull(new AnnotationCheckTemplateFactory(null).create(String.class));
- }
-
- @Test
- public void checkWithDetailedMessages() {
- BundleCheckTemplate check = new AnnotationCheckTemplateFactory(null).create(DetailedAnnotatedCheck.class);
- assertNotNull(check);
-
- assertThat(check.getKey(), is("org.sonar.api.checks.samples.DetailedAnnotatedCheck"));
-
- assertThat(check.getTitle(DEFAULT_LOCALE), is("Detailed Check"));
- assertThat(check.getTitle(ALTERNATIVE_LOCALE), is("Detailed Check"));
- assertThat(check.getTitle(UNKNOWN_LOCALE), is("Detailed Check"));
-
- assertThat(check.getDescription(DEFAULT_LOCALE), is("Detailed description"));
- assertThat(check.getDescription(ALTERNATIVE_LOCALE), is("Detailed description"));
- assertThat(check.getDescription(UNKNOWN_LOCALE), is("Detailed description"));
-
- assertThat(check.getIsoCategory(), is(IsoCategory.Reliability));
-
- assertThat(check.getProperties().size(), is(2));
- Iterator<CheckTemplateProperty> it = check.getProperties().iterator();
-
- CheckTemplateProperty maxTemplateProperty = it.next();
- assertThat(maxTemplateProperty.getKey(), is("max"));
-
- assertThat(maxTemplateProperty.getDescription(DEFAULT_LOCALE), is("Maximum value"));
- assertThat(maxTemplateProperty.getDescription(ALTERNATIVE_LOCALE), is("Maximum value"));
- assertThat(maxTemplateProperty.getDescription(UNKNOWN_LOCALE), is("Maximum value"));
- }
-
- @Test
- public void checkWithInternationalizedMessages() {
- BundleCheckTemplate check = new AnnotationCheckTemplateFactory(null).create(AnnotatedCheckWithBundles.class);
- assertNotNull(check);
-
- assertThat(check.getKey(), is("org.sonar.api.checks.samples.AnnotatedCheckWithBundles"));
- assertThat(check.getTitle(DEFAULT_LOCALE), is("I18n Check"));
- assertThat(check.getTitle(ALTERNATIVE_LOCALE), is("Règle d'internationalisation"));
- assertThat(check.getTitle(UNKNOWN_LOCALE), is("I18n Check"));
-
- assertThat(check.getDescription(DEFAULT_LOCALE), is("Description in english"));
- assertThat(check.getDescription(ALTERNATIVE_LOCALE), is("Description en Français"));
- assertThat(check.getDescription(UNKNOWN_LOCALE), is("Description in english"));
-
- assertThat(check.getProperties().size(), is(2));
- Iterator<CheckTemplateProperty> it = check.getProperties().iterator();
-
- CheckTemplateProperty maxTemplateProperty = it.next();
- assertThat(maxTemplateProperty.getKey(), is("max"));
-
- assertThat(maxTemplateProperty.getDescription(DEFAULT_LOCALE), is("Description in english of the maximum value"));
- assertThat(maxTemplateProperty.getDescription(ALTERNATIVE_LOCALE), is("Description en Français de la valeur maximale"));
- assertThat(maxTemplateProperty.getDescription(UNKNOWN_LOCALE), is("Description in english of the maximum value"));
- }
-
- @Test
- public void loadBundlesFromAlternativePath() {
- BundleCheckTemplate check = new AnnotationCheckTemplateFactory(null).create(I18nCheckWithAlternativeBundle.class);
- assertNotNull(check);
-
- assertThat(check.getKey(), is("new_key"));
- assertThat(check.getTitle(DEFAULT_LOCALE), is("Alternative Path to Bundle"));
- }
-
- @Test
- public void loadFromAnnotationIfNoDefaultLocale() {
- BundleCheckTemplate check = new AnnotationCheckTemplateFactory(null).create(I18nCheckWithoutDefaultLocale.class);
- assertNotNull(check);
-
- assertThat(check.getTitle(DEFAULT_LOCALE), is("Title from annotation"));
- assertThat(check.getTitle(ALTERNATIVE_LOCALE), is("Titre depuis le bundle"));
- }
-}
diff --git a/sonar-deprecated/src/test/java/org/sonar/api/checks/templates/BundleCheckTemplateTest.java b/sonar-deprecated/src/test/java/org/sonar/api/checks/templates/BundleCheckTemplateTest.java
deleted file mode 100644
index d1ce879c470..00000000000
--- a/sonar-deprecated/src/test/java/org/sonar/api/checks/templates/BundleCheckTemplateTest.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2011 SonarSource
- * 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.api.checks.templates;
-
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.sonar.api.checks.samples.AnnotatedCheckWithBundles;
-import org.sonar.api.checks.samples.SimpleAnnotatedCheck;
-
-import java.util.Locale;
-
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertThat;
-
-public class BundleCheckTemplateTest {
-
- private static final Locale DEFAULT_LOCALE = Locale.getDefault();
-
- @BeforeClass
- public static void beforeAll() {
- Locale.setDefault(Locale.ENGLISH);
- }
-
- @AfterClass
- public static void afterAll() {
- Locale.setDefault(DEFAULT_LOCALE);
- }
-
- @Test
- public void loadBundlesFromClass() {
- BundleCheckTemplate check = new BundleCheckTemplate("key", AnnotatedCheckWithBundles.class);
-
- assertNotNull(check.getBundle(Locale.ENGLISH));
- assertNotNull(check.getBundle(Locale.FRENCH));
- assertNotNull(check.getBundle(Locale.CHINESE)); // use the english bundle
-
- assertThat(check.getBundle(Locale.ENGLISH).getString("title"), is("I18n Check"));
- assertThat(check.getBundle(Locale.CHINESE).getString("title"), is("I18n Check"));
- assertThat(check.getBundle(Locale.FRENCH).getString("title"), is("Règle d'internationalisation"));
- }
-
- @Test
- public void useDefaultValuesWhenNoBundles() {
- BundleCheckTemplate check = new BundleCheckTemplate("key", SimpleAnnotatedCheck.class);
- check.setDefaultTitle("default title");
- check.setDefaultDescription("default desc");
-
- assertThat(check.getTitle(null), is("default title"));
- assertThat(check.getTitle(Locale.ENGLISH), is("default title"));
- assertThat(check.getTitle(Locale.CHINESE), is("default title"));
-
- assertThat(check.getDescription(Locale.ENGLISH), is("default desc"));
- assertThat(check.getDescription(Locale.CHINESE), is("default desc"));
- }
-}
diff --git a/sonar-deprecated/src/test/java/org/sonar/api/checks/templates/CheckTemplateRepositoriesTest.java b/sonar-deprecated/src/test/java/org/sonar/api/checks/templates/CheckTemplateRepositoriesTest.java
deleted file mode 100644
index 0b032d77797..00000000000
--- a/sonar-deprecated/src/test/java/org/sonar/api/checks/templates/CheckTemplateRepositoriesTest.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2011 SonarSource
- * 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.api.checks.templates;
-
-import org.junit.Test;
-import org.sonar.api.checks.templates.CheckTemplateRepositories;
-import org.sonar.api.checks.templates.CheckTemplateRepository;
-
-import static junit.framework.Assert.assertEquals;
-import static junit.framework.Assert.assertNull;
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public class CheckTemplateRepositoriesTest {
-
- @Test
- public void noRepositories() {
- CheckTemplateRepositories templateRepositories = new CheckTemplateRepositories();
- assertNull(templateRepositories.getRepository("foo"));
- assertThat(templateRepositories.getRepositories().size(), is(0));
- }
-
- @Test
- public void getRepositoryByKey() {
- CheckTemplateRepository repo1 = mock(CheckTemplateRepository.class);
- when(repo1.getKey()).thenReturn("one");
-
- CheckTemplateRepository repo2 = mock(CheckTemplateRepository.class);
- when(repo2.getKey()).thenReturn("two");
-
- CheckTemplateRepositories templateRepositories = new CheckTemplateRepositories(new CheckTemplateRepository[]{repo1, repo2});
-
- assertThat(templateRepositories.getRepositories().size(), is(2));
- assertEquals(repo1, templateRepositories.getRepository("one"));
- assertEquals(repo2, templateRepositories.getRepository("two"));
- assertNull(templateRepositories.getRepository("foo"));
- }
-}
diff --git a/sonar-deprecated/src/test/java/org/sonar/api/checks/templates/DefaultCheckTemplateTest.java b/sonar-deprecated/src/test/java/org/sonar/api/checks/templates/DefaultCheckTemplateTest.java
deleted file mode 100644
index ad15e02eec5..00000000000
--- a/sonar-deprecated/src/test/java/org/sonar/api/checks/templates/DefaultCheckTemplateTest.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2011 SonarSource
- * 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.api.checks.templates;
-
-import org.junit.Test;
-
-import java.util.Locale;
-
-import static org.junit.Assert.assertEquals;
-
-public class DefaultCheckTemplateTest {
-
- @Test
- public void isNotInternationalized() {
- DefaultCheckTemplate check = new DefaultCheckTemplate("key1");
- check.setTitle("title");
- check.setDescription("desc");
-
- assertEquals("title", check.getTitle(Locale.ENGLISH));
- assertEquals(check.getTitle(Locale.ENGLISH), check.getTitle(Locale.FRENCH));
-
- assertEquals("desc", check.getDescription(Locale.ENGLISH));
- assertEquals(check.getDescription(Locale.ENGLISH), check.getDescription(Locale.FRENCH));
- }
-}
diff --git a/sonar-deprecated/src/test/java/org/sonar/api/rules/StandardProfileXmlParserTest.java b/sonar-deprecated/src/test/java/org/sonar/api/rules/StandardProfileXmlParserTest.java
deleted file mode 100644
index 1820670b7f3..00000000000
--- a/sonar-deprecated/src/test/java/org/sonar/api/rules/StandardProfileXmlParserTest.java
+++ /dev/null
@@ -1,174 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2011 SonarSource
- * 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.api.rules;
-
-import org.apache.commons.io.IOUtils;
-import org.hamcrest.CoreMatchers;
-import org.junit.Assert;
-import org.junit.Test;
-import org.sonar.api.profiles.RulesProfile;
-import org.sonar.api.rules.xml.Profile;
-import org.sonar.api.rules.xml.Property;
-import org.sonar.api.utils.SonarException;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-
-public class StandardProfileXmlParserTest {
-
- @Test
- public void checkAllFields() {
- StandardProfileXmlParser parser = new StandardProfileXmlParser();
- String xml = "<profile name='Sonar way' language='java'><rule key=\"2006\" priority=\"warning\" /><rule key=\"2007\" priority=\"error\"><property name=\"toto\" value=\"titi\" /></rule></profile>";
- Profile profile = parser.parse(xml);
-
- assertEquals(2, profile.getRules().size());
- assertEquals("Sonar way", profile.getName());
-
- org.sonar.api.rules.xml.Rule rule1 = profile.getRules().get(0);
- assertEquals("2006", rule1.getKey());
- assertEquals("warning", rule1.getPriority());
- assertNull(rule1.getProperties());
-
- org.sonar.api.rules.xml.Rule rule2 = profile.getRules().get(1);
- assertEquals("2007", rule2.getKey());
- assertEquals("error", rule2.getPriority());
- assertEquals(rule2.getProperties().size(), 1);
-
- Property property = rule2.getProperties().get(0);
- assertEquals("toto", property.getName());
- assertEquals("titi", property.getValue());
- }
-
- @Test(expected = SonarException.class)
- public void shouldProfileNameBeNotNull() throws IOException {
- InputStream input = getClass().getResourceAsStream("/org/sonar/api/rules/test_profile_name_null.xml");
- StandardProfileXmlParser standardProfileXmlParser = new StandardProfileXmlParser();
- standardProfileXmlParser.importConfiguration(IOUtils.toString(input));
- }
-
- @Test
- public void shouldBuildProfileFromXml() throws IOException {
- StandardProfileXmlParser standardProfileXmlParser = new StandardProfileXmlParser();
- InputStream input = getClass().getResourceAsStream("/org/sonar/api/rules/test_profile.xml");
- Profile profile = standardProfileXmlParser.buildProfileFromXml(IOUtils.toString(input));
-
- assertThat("Sonar way", is(profile.getName()));
- assertThat(profile.getRules().size(), is(3));
-
- org.sonar.api.rules.xml.Rule rule1 = profile.getRules().get(0);
- assertThat(rule1.getKey(), is("2006"));
- assertThat(rule1.getPriority(), is("warning"));
- assertNull(rule1.getProperties());
-
- org.sonar.api.rules.xml.Rule rule2 = profile.getRules().get(1);
- assertThat(rule2.getKey(), is("2007"));
- assertThat(rule2.getPriority(), is("error"));
- assertThat(rule2.getProperties().size(), is(1));
-
- org.sonar.api.rules.xml.Rule rule3 = profile.getRules().get(2);
- assertThat(rule3.getKey(), is("2008"));
- assertThat(rule3.getPriority(), is("critical"));
- assertNull(rule3.getProperties());
-
- Property rule2Property = rule2.getProperties().get(0);
- assertThat(rule2Property.getName(), is("toto"));
- assertThat(rule2Property.getValue(), is("titi"));
- }
-
- @Test
- public void shouldImportConfiguration() throws IOException {
- final List<Rule> inputRules = buildRulesFixture();
- List<ActiveRule> activeRulesExpected = buildActiveRulesFixture(inputRules);
-
- StandardProfileXmlParser standardProfileXmlParser = new StandardProfileXmlParser(inputRules);
-
- InputStream input = getClass().getResourceAsStream("/org/sonar/api/rules/test_profile.xml");
- RulesProfile profile = standardProfileXmlParser.importConfiguration(IOUtils.toString(input));
- List<ActiveRule> results = profile.getActiveRules();
-
- assertThat("Sonar way", CoreMatchers.is(profile.getName()));
- assertThat(results.size(), is(activeRulesExpected.size()));
- assertActiveRulesAreEquals(results, activeRulesExpected);
- }
-
- private List<Rule> buildRulesFixture() {
- List<Rule> rules = new ArrayList<Rule>();
-
- Rule rule1 = new Rule("One rule", "2006",
- "2006", null, "MYPLUGIN", null);
-
- Rule rule2 = new Rule("Another rule", "2007",
- "2007", null, "MYPLUGIN", null);
- RuleParam ruleParam2 = new RuleParam(rule2, "toto", null, "s");
- rule2.setParams(Arrays.asList(ruleParam2));
-
- Rule rule3 = new Rule("Third rule", "2008",
- "2008", null, "MYPLUGIN", null);
-
- rules.add(rule1);
- rules.add(rule2);
- rules.add(rule3);
-
- return rules;
- }
-
- private List<ActiveRule> buildActiveRulesFixture(List<Rule> rules) {
- List<ActiveRule> activeRules = new ArrayList<ActiveRule>();
-
- ActiveRule activeRule1 = new ActiveRule(null, rules.get(0), RulePriority.INFO);
- activeRules.add(activeRule1);
-
- ActiveRule activeRule2 = new ActiveRule(null, rules.get(1), RulePriority.MAJOR);
- activeRule2.setActiveRuleParams(Arrays.asList(new ActiveRuleParam(activeRule2, rules.get(1).getParams().get(0), "titi")));
- activeRules.add(activeRule2);
-
- ActiveRule activeRule3 = new ActiveRule(null, rules.get(2), RulePriority.CRITICAL);
- activeRules.add(activeRule3);
-
- return activeRules;
- }
-
- private void assertActiveRulesAreEquals(List<ActiveRule> activeRules1, List<ActiveRule> activeRules2) {
- for (int i = 0; i < activeRules1.size(); i++) {
- ActiveRule activeRule1 = activeRules1.get(i);
- ActiveRule activeRule2 = activeRules2.get(i);
- assertTrue(activeRule1.getRule().equals(activeRule2.getRule()) && activeRule1.getSeverity().equals(activeRule2.getSeverity()));
-
- Assert.assertEquals(activeRule1.getActiveRuleParams().size(), (activeRule2.getActiveRuleParams().size()));
- for (int j = 0; j < activeRule1.getActiveRuleParams().size(); j++) {
- ActiveRuleParam activeRuleParam1 = activeRule1.getActiveRuleParams().get(j);
- ActiveRuleParam activeRuleParam2 = activeRule2.getActiveRuleParams().get(j);
- assertTrue(activeRuleParam1.getRuleParam().equals(activeRuleParam2.getRuleParam())
- && activeRuleParam1.getValue().equals(activeRuleParam2.getValue()));
- }
- }
- }
-
-}
diff --git a/sonar-deprecated/src/test/java/org/sonar/api/rules/StandardRulesXmlParserTest.java b/sonar-deprecated/src/test/java/org/sonar/api/rules/StandardRulesXmlParserTest.java
deleted file mode 100644
index ab367b42532..00000000000
--- a/sonar-deprecated/src/test/java/org/sonar/api/rules/StandardRulesXmlParserTest.java
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2011 SonarSource
- * 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.api.rules;
-
-import org.apache.commons.io.IOUtils;
-import org.junit.Assert;
-import org.junit.Test;
-
-import java.util.List;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-
-public class StandardRulesXmlParserTest {
- @Test
- public void checkAllFields() {
- StandardRulesXmlParser parser = new StandardRulesXmlParser();
- String xml = "<rules><rule key='key1' category='cat1'><name>my name</name><configKey>my_config_key</configKey><description>my description</description><param key='param1'><type>s</type><description>param description</description></param><param key='param2'><type>integer</type><description>param description 2</description></param></rule></rules>";
- List<Rule> rules = parser.parse(xml);
- assertEquals(1, rules.size());
-
- Rule rule = rules.get(0);
- Assert.assertEquals("key1", rule.getKey());
- Assert.assertEquals("my name", rule.getName());
- Assert.assertEquals("my_config_key", rule.getConfigKey());
- Assert.assertEquals("my description", rule.getDescription());
- Assert.assertEquals(2, rule.getParams().size());
- Assert.assertEquals("param1", rule.getParams().get(0).getKey());
- Assert.assertEquals("s", rule.getParams().get(0).getType());
- Assert.assertEquals("param description", rule.getParams().get(0).getDescription());
- }
-
- @Test
- public void ruleCanHaveALevel() {
- StandardRulesXmlParser parser = new StandardRulesXmlParser();
- String xml = "<rules><rule key='1' priority='CRITICAL'><category name='cat1'/></rule></rules>";
- List<Rule> rules = parser.parse(xml);
- Assert.assertEquals(RulePriority.CRITICAL, rules.get(0).getSeverity());
- }
-
- @Test
- public void ruleShouldHaveADefaultLevel() {
- StandardRulesXmlParser parser = new StandardRulesXmlParser();
- String xml = "<rules><rule key='1'><category name='cat1'/></rule></rules>";
- List<Rule> rules = parser.parse(xml);
- Assert.assertEquals(RulePriority.MAJOR, rules.get(0).getSeverity());
- }
-
- @Test
- public void shouldDefineManyRules() {
- StandardRulesXmlParser parser = new StandardRulesXmlParser();
- String xml = "<rules><rule key='key1' category='cat1' /><rule key='key2' category='cat1' /></rules>";
- List<Rule> rules = parser.parse(xml);
- assertEquals(2, rules.size());
- Assert.assertEquals("key1", rules.get(0).getKey());
- Assert.assertEquals("key2", rules.get(1).getKey());
- }
-
- @Test
- public void someFielsShouldBeNull() {
- StandardRulesXmlParser parser = new StandardRulesXmlParser();
- String xml = "<rules><rule key='key1' category='cat1' /></rules>";
- List<Rule> rules = parser.parse(xml);
- assertNull(rules.get(0).getDescription());
- assertNull(rules.get(0).getName());
- assertNull(rules.get(0).getConfigKey());
- }
-
- @Test
- public void shouldContainCDataDescription() {
- StandardRulesXmlParser parser = new StandardRulesXmlParser();
- String xml = "<rules><rule key='key1' category='cat1'><description> <![CDATA[<xml> </nodes> and accents ��� ]]> </description></rule></rules>";
- List<Rule> rules = parser.parse(xml);
- assertEquals(1, rules.size());
- Assert.assertEquals("<xml> </nodes> and accents ���", rules.get(0).getDescription());
- }
-
- @Test
- public void shouldBeBackwardCompatibleWithDefaultVersionProperty() {
- StandardRulesXmlParser parser = new StandardRulesXmlParser();
- String xml = "<rules><rule key='key1' category='cat1'><name>my name</name><configKey>my_config_key</configKey><param key='param1'><type>s</type><description>param description</description><defaultValue>xxx</defaultValue></param></rule></rules>";
- List<Rule> rules = parser.parse(xml);
- assertEquals(1, rules.size());
-
- Rule rule = rules.get(0);
- Assert.assertEquals("key1", rule.getKey());
- Assert.assertEquals(1, rule.getParams().size());
- Assert.assertEquals("param1", rule.getParams().get(0).getKey());
- }
-
- @Test
- public void shouldParseStringInUt8() {
- StandardRulesXmlParser parser = new StandardRulesXmlParser();
- String xml = "<rules><rule key='key1' category='cat1' ><description>\\u00E9</description></rule></rules>";
- List<Rule> rules = parser.parse(xml);
- assertThat(rules.get(0).getDescription(), is("\\u00E9"));
- }
-
- @Test
- public void shouldParseInputStreamInUt8() {
- StandardRulesXmlParser parser = new StandardRulesXmlParser();
- String xml = "<rules><rule key='key1' category='cat1' ><description>\\u00E9</description></rule></rules>";
- List<Rule> rules = parser.parse(IOUtils.toInputStream(xml));
- assertThat(rules.get(0).getDescription(), is("\\u00E9"));
- }
-}
diff --git a/sonar-deprecated/src/test/resources/org/sonar/api/rules/test_profile.xml b/sonar-deprecated/src/test/resources/org/sonar/api/rules/test_profile.xml
deleted file mode 100644
index 29e2024bf51..00000000000
--- a/sonar-deprecated/src/test/resources/org/sonar/api/rules/test_profile.xml
+++ /dev/null
@@ -1,7 +0,0 @@
-<profile name="Sonar way" language='java'>
- <rule key="2006" priority="warning"/>
- <rule key="2007" priority="error">
- <property name="toto" value="titi"/>
- </rule>
- <rule key="2008" priority="critical"/>
-</profile> \ No newline at end of file
diff --git a/sonar-deprecated/src/test/resources/org/sonar/api/rules/test_profile_name_null.xml b/sonar-deprecated/src/test/resources/org/sonar/api/rules/test_profile_name_null.xml
deleted file mode 100644
index 65d39e70403..00000000000
--- a/sonar-deprecated/src/test/resources/org/sonar/api/rules/test_profile_name_null.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-<profile name="" language='java'>
- <rule key="2006" priority="warning"/>
- <rule key="2007" priority="error">
- <property name="toto" value="titi"/>
- </rule>
-</profile> \ No newline at end of file