+++ /dev/null
-/*
- * 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.batch;
-
-import org.picocontainer.injectors.ProviderAdapter;
-import org.sonar.api.checks.profiles.Check;
-import org.sonar.api.checks.profiles.CheckProfile;
-import org.sonar.api.profiles.RulesProfile;
-import org.sonar.api.rules.ActiveRule;
-import org.sonar.api.rules.ActiveRuleParam;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-public class CheckProfileProvider extends ProviderAdapter {
-
- private CheckProfile profile = null;
-
- public CheckProfile provide(RulesProfile ruleProfile) {
- if (profile == null) {
- profile = new CheckProfile(ruleProfile.getName(), ruleProfile.getLanguage());
- for (ActiveRule activeRule : ruleProfile.getActiveRules()) {
- Check check = toCheck(activeRule);
- profile.addCheck(check);
- }
- }
- return profile;
- }
-
- private Check toCheck(ActiveRule activeRule) {
- Check check = new Check(activeRule.getPluginName(), activeRule.getRuleKey());
- check.setPriority(activeRule.getSeverity().toCheckPriority());
- check.setProperties(toParameters(activeRule.getActiveRuleParams()));
- return check;
- }
-
- private Map<String, String> toParameters(List<ActiveRuleParam> params) {
- Map<String, String> map = new HashMap<String, String>();
- if (params != null) {
- for (ActiveRuleParam param : params) {
- map.put(param.getRuleParam().getKey(), param.getValue());
- }
- }
- return map;
- }
-}
addComponent(PastViolationsLoader.class);
addComponent(ProfileLoader.class, DefaultProfileLoader.class);
addAdapter(new ProfileProvider());
- addAdapter(new CheckProfileProvider());
}
private void addCoreComponents() {
+++ /dev/null
-/*
- * 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.checkers;
-
-import org.apache.commons.lang.StringUtils;
-import org.sonar.api.checks.profiles.Check;
-import org.sonar.api.checks.profiles.CheckProfile;
-import org.sonar.check.AnnotationIntrospector;
-import org.sonar.check.CheckProperty;
-
-import java.lang.reflect.Field;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.IdentityHashMap;
-import java.util.Map;
-
-/**
- * @since 2.1 (experimental)
- * @deprecated since 2.3
- */
-@Deprecated
-
-public class AnnotationCheckerFactory<CHECKER> extends CheckerFactory<CHECKER> {
-
- private CheckProfile profile;
- private String repositoryKey;
- private Collection<Class<CHECKER>> checkerClasses;
-
- public AnnotationCheckerFactory(CheckProfile profile, String repositoryKey, Collection<Class<CHECKER>> checkerClasses) {
- this.profile = profile;
- this.repositoryKey = repositoryKey;
- this.checkerClasses = checkerClasses;
- }
-
- public Map<Check, CHECKER> create() {
- Map<String, Class<CHECKER>> classesByKey = getClassesByKey(checkerClasses);
-
- Map<Check, CHECKER> map = new IdentityHashMap<Check, CHECKER>();
- for (Check check : profile.getChecks(repositoryKey)) {
- Class<CHECKER> clazz = classesByKey.get(check.getTemplateKey());
- if (clazz != null) {
- CHECKER checker = instantiate(check, clazz);
- if (checker != null) {
- map.put(check, checker);
- }
- }
- }
- return map;
- }
-
- CHECKER instantiate(Check check, Class<CHECKER> clazz) {
- try {
- CHECKER checker = clazz.newInstance();
- configureFields(check, checker);
- return checker;
-
- } catch (UnvalidCheckerException e) {
- throw e;
-
- } catch (Exception e) {
- throw new UnvalidCheckerException("The checker " + clazz.getCanonicalName() + " can not be created", e);
- }
- }
-
- private void configureFields(Check check, CHECKER checker) throws IllegalAccessException {
- for (Map.Entry<String, String> entry : check.getProperties().entrySet()) {
- Field field = getField(checker, entry.getKey());
- if (field == null) {
- throw new UnvalidCheckerException("The field " + entry.getKey() + " does not exist or is not annotated with @CheckProperty");
- }
- if (StringUtils.isNotBlank(entry.getValue())) {
- configureField(checker, field, entry);
- }
- }
-
- }
-
- private void configureField(Object checker, Field field, Map.Entry<String, String> parameter) throws IllegalAccessException {
- field.setAccessible(true);
-
- if (field.getType().equals(String.class)) {
- field.set(checker, parameter.getValue());
-
- } else if (field.getType().getSimpleName().equals("int")) {
- field.setInt(checker, Integer.parseInt(parameter.getValue()));
-
- } else if (field.getType().getSimpleName().equals("short")) {
- field.setShort(checker, Short.parseShort(parameter.getValue()));
-
- } else if (field.getType().getSimpleName().equals("long")) {
- field.setLong(checker, Long.parseLong(parameter.getValue()));
-
- } else if (field.getType().getSimpleName().equals("double")) {
- field.setDouble(checker, Double.parseDouble(parameter.getValue()));
-
- } else if (field.getType().getSimpleName().equals("boolean")) {
- field.setBoolean(checker, Boolean.parseBoolean(parameter.getValue()));
-
- } else if (field.getType().getSimpleName().equals("byte")) {
- field.setByte(checker, Byte.parseByte(parameter.getValue()));
-
- } else if (field.getType().equals(Integer.class)) {
- field.set(checker, new Integer(Integer.parseInt(parameter.getValue())));
-
- } else if (field.getType().equals(Long.class)) {
- field.set(checker, new Long(Long.parseLong(parameter.getValue())));
-
- } else if (field.getType().equals(Double.class)) {
- field.set(checker, new Double(Double.parseDouble(parameter.getValue())));
-
- } else if (field.getType().equals(Boolean.class)) {
- field.set(checker, Boolean.valueOf(Boolean.parseBoolean(parameter.getValue())));
-
- } else {
- throw new UnvalidCheckerException("The type of the field " + field + " is not supported: " + field.getType());
- }
- }
-
- private Field getField(Object checker, String key) {
- Field[] fields = checker.getClass().getDeclaredFields();
- for (Field field : fields) {
- CheckProperty annotation = field.getAnnotation(CheckProperty.class);
- if (annotation != null) {
- if (key.equals(field.getName()) || key.equals(annotation.key())) {
- return field;
- }
- }
- }
- return null;
- }
-
- private Map<String, Class<CHECKER>> getClassesByKey(Collection<Class<CHECKER>> checkerClasses) {
- Map<String, Class<CHECKER>> result = new HashMap<String, Class<CHECKER>>();
- for (Class<CHECKER> checkerClass : checkerClasses) {
- String key = AnnotationIntrospector.getCheckKey(checkerClass);
- if (key != null) {
- result.put(key, checkerClass);
- }
- }
- return result;
- }
-
-}
+++ /dev/null
-/*
- * 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.checkers;
-
-import org.sonar.api.checks.profiles.Check;
-
-import java.util.Map;
-
-/**
- * @since 2.1 (experimental)
- * @deprecated since 2.3
- */
-@Deprecated
-public abstract class CheckerFactory<CHECKER> {
- public abstract Map<Check, CHECKER> create();
-}
+++ /dev/null
-/*
- * 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.checkers;
-
-import com.google.common.collect.Maps;
-import org.sonar.api.batch.SensorContext;
-import org.sonar.api.checks.profiles.Check;
-import org.sonar.api.checks.profiles.CheckProfile;
-import org.sonar.api.resources.Resource;
-import org.sonar.api.rules.Rule;
-import org.sonar.api.rules.RulePriority;
-import org.sonar.api.rules.Violation;
-import org.sonar.check.Message;
-
-import java.util.Collection;
-import java.util.Locale;
-import java.util.Map;
-
-/**
- * @since 2.1 (experimental)
- * @deprecated since 2.3
- */
-@Deprecated
-public class MessageDispatcher {
-
- private Map<Check, Object> checkersByCheck;
- private Map<Object, Check> checksByChecker;
- private SensorContext context;
-
- public MessageDispatcher(SensorContext context) {
- this.context = context;
- checkersByCheck = Maps.newIdentityHashMap();
- checksByChecker = Maps.newIdentityHashMap();
- }
-
- public void registerChecker(Check check, Object checker) {
- checkersByCheck.put(check, checker);
- checksByChecker.put(checker, check);
- }
-
- public void registerCheckers(CheckerFactory factory) {
- Map<Check, Object> map = factory.create();
- for (Map.Entry<Check, Object> entry : map.entrySet()) {
- registerChecker(entry.getKey(), entry.getValue());
- }
- }
-
- public void registerCheckers(CheckProfile profile) {
- for (Check check : profile.getChecks()) {
- registerChecker(check, check);
- }
- }
-
- public Object getChecker(Check check) {
- return checkersByCheck.get(check);
- }
-
- public Check getCheck(Object checker) {
- return checksByChecker.get(checker);
- }
-
- public Collection getCheckers() {
- return checkersByCheck.values();
- }
-
- public void unregisterCheck(Check check) {
- Object checker = checkersByCheck.remove(check);
- if (checker != null) {
- checksByChecker.remove(checker);
- }
- }
-
- public void unregisterChecks(CheckProfile profile) {
- for (Check check : profile.getChecks()) {
- unregisterCheck(check);
- }
- }
-
- public void log(Resource resource, Message message) {
- Object checker = message.getChecker();
- Check check = getCheck(checker);
- Violation violation = Violation.create(new Rule(check.getRepositoryKey(), check.getTemplateKey()), resource);
- violation.setLineId(message.getLine());
- violation.setMessage(message.getText(Locale.ENGLISH));
- violation.setSeverity(RulePriority.fromCheckPriority(check.getPriority()));
- context.saveViolation(violation);
- }
-
- public void clear() {
- checkersByCheck.clear();
- checksByChecker.clear();
- }
-
-}
+++ /dev/null
-/*
- * 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.checkers;
-
-/**
- * @since 2.1 (experimental)
- * @deprecated since 2.3
- */
-@Deprecated
-public class UnvalidCheckerException extends RuntimeException {
- public UnvalidCheckerException() {
- }
-
- public UnvalidCheckerException(String message) {
- super(message);
- }
-
- public UnvalidCheckerException(String message, Throwable cause) {
- super(message, cause);
- }
-
- public UnvalidCheckerException(Throwable cause) {
- super(cause);
- }
-}
+++ /dev/null
-/*
- * 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.profiles;
-
-import org.sonar.check.AnnotationIntrospector;
-import org.sonar.check.BelongsToProfile;
-import org.sonar.check.BelongsToProfiles;
-
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * @since 2.1 (experimental)
- * @deprecated since 2.3
- */
-@Deprecated
-public final class AnnotationCheckProfileFactory {
-
- private AnnotationCheckProfileFactory() {
- }
-
- public static Collection<CheckProfile> create(String repositoryKey, String language, Collection<Class> checkClasses) {
- Map<String, CheckProfile> profilesByTitle = new HashMap<String, CheckProfile>();
-
- if (checkClasses != null) {
- for (Class aClass : checkClasses) {
- BelongsToProfiles belongsToProfiles = (BelongsToProfiles) aClass.getAnnotation(BelongsToProfiles.class);
- if (belongsToProfiles != null) {
- for (BelongsToProfile belongsToProfile : belongsToProfiles.value()) {
- registerProfile(profilesByTitle, aClass, belongsToProfile, repositoryKey, language);
- }
- }
- BelongsToProfile belongsToProfile = (BelongsToProfile) aClass.getAnnotation(BelongsToProfile.class);
- registerProfile(profilesByTitle, aClass, belongsToProfile, repositoryKey, language);
- }
- }
-
- return profilesByTitle.values();
- }
-
- private static void registerProfile(Map<String, CheckProfile> profilesByTitle, Class aClass, BelongsToProfile belongsToProfile, String repositoryKey, String language) {
- if (belongsToProfile != null) {
- String title = belongsToProfile.title();
- CheckProfile profile = profilesByTitle.get(title);
- if (profile == null) {
- profile = new CheckProfile(title, language);
- profilesByTitle.put(title, profile);
- }
- Check check = new Check(repositoryKey, AnnotationIntrospector.getCheckKey(aClass));
- check.setPriority(belongsToProfile.priority());
- profile.addCheck(check);
- }
- }
-}
+++ /dev/null
-/*
- * 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.profiles;
-
-import org.apache.commons.lang.builder.ToStringBuilder;
-import org.sonar.check.Priority;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * @since 2.1 (experimental)
- * @deprecated since 2.3
- */
-@Deprecated
-public class Check {
-
- private String repositoryKey;
- private String templateKey;
- private Priority priority = null;
- private final Map<String, String> properties = new HashMap<String,String>();
-
- public Check() {
- }
-
- public Check(String repositoryKey, String templateKey) {
- this.repositoryKey = repositoryKey;
- this.templateKey = templateKey;
- }
-
- public String getTemplateKey() {
- return templateKey;
- }
-
- public String getRepositoryKey() {
- return repositoryKey;
- }
-
- public void setRepositoryKey(String repositoryKey) {
- this.repositoryKey = repositoryKey;
- }
-
- public void setTemplateKey(String templateKey) {
- this.templateKey = templateKey;
- }
-
- public Priority getPriority() {
- return priority;
- }
-
- public void setPriority(Priority priority) {
- this.priority = priority;
- }
-
- public Map<String, String> getProperties() {
- return properties;
- }
-
- public String getProperty(String key) {
- return properties.get(key);
- }
-
- public void addProperty(String key, Object value) {
- properties.put(key, value.toString());
- }
-
- public void addProperties(Map<String, String> properties) {
- this.properties.putAll(properties);
- }
-
- public void setProperties(Map<String, String> properties) {
- this.properties.clear();
- this.properties.putAll(properties);
- }
-
- @Override
- public boolean equals(Object o) {
- return o == this;
- }
-
- @Override
- public int hashCode() {
- return super.hashCode();
- }
-
- @Override
- public String toString() {
- return new ToStringBuilder(this)
- .append("repository", repositoryKey)
- .append("template", templateKey)
- .append("priority", priority)
- .toString();
- }
-}
+++ /dev/null
-/*
- * 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.profiles;
-
-import org.sonar.api.BatchExtension;
-import org.sonar.api.ServerExtension;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-/**
- * @since 2.1 (experimental)
- * @deprecated since 2.3
- */
-@Deprecated
-public class CheckProfile implements BatchExtension, ServerExtension {
-
- private String name;
- private String language;
- private List<Check> checks = new ArrayList<Check>();
-
- public CheckProfile(String name, String language) {
- if (name == null) {
- throw new IllegalArgumentException("Name can not be null");
- }
- if (language == null) {
- throw new IllegalArgumentException("Language can not be null");
- }
- this.name = name;
- this.language = language;
- }
-
- public String getName() {
- return name;
- }
-
- public String getLanguage() {
- return language;
- }
-
- public List<Check> getChecks() {
- return checks;
- }
-
- public List<Check> getChecks(String repositoryKey) {
- List<Check> result = new ArrayList<Check>();
- for (Check check : getChecks()) {
- if (check.getRepositoryKey().equals(repositoryKey)) {
- result.add(check);
- }
- }
- return result;
- }
-
- public List<Check> getChecks(String repositoryKey, String templateKey) {
- List<Check> result = new ArrayList<Check>();
- List<Check> repoChecks = getChecks(repositoryKey);
- for (Check repoCheck : repoChecks) {
- if (repoCheck.getTemplateKey().equals(templateKey)) {
- result.add(repoCheck);
- }
- }
- return result;
- }
-
- /**
- * We assume there is only one check for this template
- */
- public Check getCheck(String repositoryKey, String templateKey) {
- List<Check> repoChecks = getChecks(repositoryKey);
- for (Check repoCheck : repoChecks) {
- if (repoCheck.getTemplateKey().equals(templateKey)) {
- return repoCheck;
- }
- }
- return null;
- }
-
- public void addCheck(Check check) {
- checks.add(check);
- }
-
- public void setChecks(Collection<Check> list) {
- checks.clear();
- checks.addAll(list);
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (o == null || getClass() != o.getClass()) {
- return false;
- }
-
- CheckProfile profile = (CheckProfile) o;
- if (!language.equals(profile.language)) {
- return false;
- }
- if (!name.equals(profile.name)) {
- return false;
- }
- return true;
- }
-
- @Override
- public int hashCode() {
- int result = name.hashCode();
- result = 31 * result + language.hashCode();
- return result;
- }
-
- @Override
- public String toString() {
- return name;
- }
-}
+++ /dev/null
-/*
- * 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.profiles;
-
-import org.sonar.api.ServerExtension;
-
-import java.util.Collection;
-
-/**
- * @since 2.1 (experimental)
- * @deprecated since 2.3
- */
-@Deprecated
-public abstract class CheckProfileProvider implements ServerExtension {
-
- public abstract Collection<CheckProfile> provide();
-
-}
+++ /dev/null
-/*
- * 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.profiles;
-
-import com.thoughtworks.xstream.XStream;
-import com.thoughtworks.xstream.converters.Converter;
-import com.thoughtworks.xstream.converters.MarshallingContext;
-import com.thoughtworks.xstream.converters.UnmarshallingContext;
-import com.thoughtworks.xstream.io.HierarchicalStreamReader;
-import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
-import com.thoughtworks.xstream.io.xml.CompactWriter;
-import com.thoughtworks.xstream.io.xml.XppDriver;
-import org.apache.commons.io.IOUtils;
-import org.sonar.check.Priority;
-
-import java.io.InputStreamReader;
-import java.io.Reader;
-import java.io.Writer;
-import java.util.Map;
-
-/**
- * @since 2.1 (experimental)
- * @deprecated since 2.3
- */
-@Deprecated
-public final class CheckProfileXmlMarshaller {
-
- public static void toXml(CheckProfile profile, Writer writer) {
- getXStream().toXML(profile, writer);
- }
-
- public static CheckProfile fromXml(Reader xml) {
- return (CheckProfile) getXStream().fromXML(xml);
- }
-
- public static CheckProfile fromXmlInClasspath(String pathToXml) {
- return fromXmlInClasspath(pathToXml, CheckProfileXmlMarshaller.class);
- }
-
- public static CheckProfile fromXmlInClasspath(String pathToXml, Class clazz) {
- Reader reader = new InputStreamReader(clazz.getResourceAsStream(pathToXml));
- try {
- return fromXml(reader);
- } finally {
- IOUtils.closeQuietly(reader);
- }
- }
-
- private static XStream getXStream() {
- XStream xstream = new XStream(new CompactDriver());
- xstream.setClassLoader(CheckProfileXmlMarshaller.class.getClassLoader());
- xstream.registerConverter(new CheckConverter());
- xstream.alias("profile", CheckProfile.class);
- xstream.alias("check", Check.class);
- xstream.addImplicitCollection(CheckProfile.class, "checks");
- return xstream;
- }
-
- private static class CompactDriver extends XppDriver {
- @Override
- public HierarchicalStreamWriter createWriter(Writer out) {
- return new XDataPrintWriter(out);
- }
- }
-
-
- private static class XDataPrintWriter extends CompactWriter {
- public XDataPrintWriter(Writer writer) {
- super(writer, XML_1_0);
- }
- }
-
- private static class CheckConverter implements Converter {
-
- public boolean canConvert(Class clazz) {
- return clazz.equals(Check.class);
- }
-
- public void marshal(Object value, HierarchicalStreamWriter writer, MarshallingContext context) {
- Check check = (Check) value;
- writer.startNode("repository");
- writer.setValue(check.getRepositoryKey());
- writer.endNode();
- writer.startNode("template");
- writer.setValue(check.getTemplateKey());
- writer.endNode();
- writer.startNode("priority");
- writer.setValue(check.getPriority().toString());
- writer.endNode();
- for (Map.Entry<String, String> entry : check.getProperties().entrySet()) {
- if (entry.getValue() != null) {
- writer.startNode("property");
- writer.startNode("key");
- writer.setValue(entry.getKey());
- writer.endNode();
- writer.startNode("value");
- // TODO is escaping automatically supported by xstream ?
- writer.setValue(entry.getValue());
- writer.endNode();
- writer.endNode();
- }
- }
- }
-
- public Object unmarshal(HierarchicalStreamReader reader,
- UnmarshallingContext context) {
- Check check = new Check();
- while (reader.hasMoreChildren()) {
- reader.moveDown();
- readValue(reader, check);
- reader.moveUp();
- }
- return check;
- }
-
- private void readValue(HierarchicalStreamReader reader, Check check) {
- if (reader.getNodeName().equals("repository")) {
- check.setRepositoryKey(reader.getValue());
-
- } else if (reader.getNodeName().equals("template")) {
- check.setTemplateKey(reader.getValue());
-
- } else if (reader.getNodeName().equals("priority")) {
- check.setPriority(Priority.valueOf(reader.getValue()));
-
- } else if (reader.getNodeName().equals("property")) {
- reader.moveDown();
- String key = reader.getValue();
- reader.moveUp();
-
- reader.moveDown();
- String value = reader.getValue();
- reader.moveUp();
- check.addProperty(key, value);
- }
- }
-
- }
-}
+++ /dev/null
-/*
- * 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.checkers;
-
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.sonar.api.checks.profiles.CheckProfile;
-import org.sonar.check.Check;
-import org.sonar.check.CheckProperty;
-import org.sonar.check.IsoCategory;
-import org.sonar.check.Priority;
-
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.Map;
-
-import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public class AnnotationCheckerFactoryTest {
-
- private AnnotationCheckerFactory factory = null;
-
- @Before
- public void before() {
- CheckProfile profile = new CheckProfile("test", "java");
- factory = new AnnotationCheckerFactory(profile, "repository", Arrays.asList(
- CheckerWithoutProperties.class,
- CheckerWithStringProperty.class,
- CheckerWithPrimitiveProperties.class));
-
- }
-
- @Test
- public void createCheckerWithoutProperties() {
- org.sonar.api.checks.profiles.Check check = mockCheck(CheckerWithoutProperties.class);
- CheckerWithoutProperties checker = (CheckerWithoutProperties) factory.instantiate(check, CheckerWithoutProperties.class);
- assertNotNull(checker);
- }
-
- @Test
- public void createCheckerWithStringProperty() {
- org.sonar.api.checks.profiles.Check check = mockCheck(CheckerWithStringProperty.class);
-
- Map map = new HashMap();
- map.put("max", "foo");
- when(check.getProperties()).thenReturn(map);
-
- CheckerWithStringProperty checker = (CheckerWithStringProperty) factory.instantiate(check, CheckerWithStringProperty.class);
- assertNotNull(checker);
- assertThat(checker.getMax(), is("foo"));
- }
-
- @Test(expected = UnvalidCheckerException.class)
- public void failIfMissingProperty() {
- org.sonar.api.checks.profiles.Check check = mockCheck(CheckerWithStringProperty.class);
-
- Map map = new HashMap();
- map.put("max", "foo");
- map.put("missing", "bar");
- when(check.getProperties()).thenReturn(map);
-
- factory.instantiate(check, CheckerWithStringProperty.class);
- }
-
- @Test
- public void createCheckerWithPrimitiveProperties() {
- org.sonar.api.checks.profiles.Check check = mockCheck(CheckerWithPrimitiveProperties.class);
-
- Map map = new HashMap();
- map.put("max", "300");
- map.put("active", "true");
- when(check.getProperties()).thenReturn(map);
-
- CheckerWithPrimitiveProperties checker = (CheckerWithPrimitiveProperties) factory.instantiate(check, CheckerWithPrimitiveProperties.class);
- assertNotNull(checker);
- assertThat(checker.getMax(), is(300));
- assertThat(checker.isActive(), is(true));
- }
-
- @Test
- public void createCheckerWithIntegerProperty() {
- org.sonar.api.checks.profiles.Check check = mockCheck(CheckerWithIntegerProperty.class);
-
- Map map = new HashMap();
- map.put("max", "300");
- when(check.getProperties()).thenReturn(map);
-
- CheckerWithIntegerProperty checker = (CheckerWithIntegerProperty) factory.instantiate(check, CheckerWithIntegerProperty.class);
- assertNotNull(checker);
- assertThat(checker.getMax(), is(300));
- }
-
- @Test
- public void createCheckerWithDefaultValues() {
- org.sonar.api.checks.profiles.Check check = mockCheck(CheckerWithPrimitiveProperties.class);
- when(check.getProperties()).thenReturn(new HashMap<String, String>());
-
- CheckerWithPrimitiveProperties checker = (CheckerWithPrimitiveProperties) factory.instantiate(check, CheckerWithPrimitiveProperties.class);
- assertNotNull(checker);
- assertThat(checker.getMax(), is(50));
- assertThat(checker.isActive(), is(false));
- }
-
- @Test(expected=UnvalidCheckerException.class)
- public void checkWithUnsupportedPropertyType() {
- org.sonar.api.checks.profiles.Check check = mockCheck(CheckWithUnsupportedPropertyType.class);
- Map map = new HashMap();
- map.put("max", "300");
- when(check.getProperties()).thenReturn(map);
-
- factory.instantiate(check, CheckWithUnsupportedPropertyType.class);
- }
-
- @Test
- @Ignore("Key is not used as i18n is not managed on properties.")
- public void createCheckerWithOverridenPropertyKey() {
- org.sonar.api.checks.profiles.Check check = mockCheck(CheckWithOverridenPropertyKey.class);
- Map map = new HashMap();
- map.put("maximum", "300");
- when(check.getProperties()).thenReturn(map);
-
- CheckWithOverridenPropertyKey checker = (CheckWithOverridenPropertyKey) factory.instantiate(check, CheckWithOverridenPropertyKey.class);
- assertNotNull(checker);
- assertThat(checker.getMax(), is(300));
- }
-
-
- private org.sonar.api.checks.profiles.Check mockCheck(Class checkerClass) {
- org.sonar.api.checks.profiles.Check check = mock(org.sonar.api.checks.profiles.Check.class);
- when(check.getRepositoryKey()).thenReturn("repository");
- when(check.getTemplateKey()).thenReturn(checkerClass.getCanonicalName());
- return check;
- }
-}
-
-@Check(isoCategory = IsoCategory.Efficiency, priority = Priority.CRITICAL)
-class CheckWithOverridenPropertyKey{
-
- @CheckProperty(key = "maximum")
- private int max = 50;
-
- public int getMax() {
- return max;
- }
-}
\ No newline at end of file
+++ /dev/null
-/*
- * 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.checkers;
-
-import org.sonar.check.Check;
-import org.sonar.check.CheckProperty;
-import org.sonar.check.IsoCategory;
-import org.sonar.check.Priority;
-
-@Check(isoCategory = IsoCategory.Efficiency, priority = Priority.CRITICAL)
-class CheckWithUnsupportedPropertyType {
-
- @CheckProperty
- private StringBuilder max = null;
-
-}
+++ /dev/null
-/*
- * 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.checkers;
-
-import org.sonar.check.Check;
-import org.sonar.check.CheckProperty;
-import org.sonar.check.IsoCategory;
-import org.sonar.check.Priority;
-
-@Check(isoCategory = IsoCategory.Efficiency, priority = Priority.CRITICAL)
-class CheckerWithIntegerProperty {
-
- @CheckProperty
- private Integer max;
-
- public Integer getMax() {
- return max;
- }
-}
+++ /dev/null
-/*
- * 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.checkers;
-
-import org.sonar.check.Check;
-import org.sonar.check.CheckProperty;
-import org.sonar.check.IsoCategory;
-import org.sonar.check.Priority;
-
-@Check(isoCategory = IsoCategory.Efficiency, priority = Priority.CRITICAL)
-class CheckerWithPrimitiveProperties {
-
- @CheckProperty(description = "Maximum threshold")
- private int max = 50;
-
- @CheckProperty
- private boolean active;
-
- public int getMax() {
- return max;
- }
-
- public boolean isActive() {
- return active;
- }
-}
+++ /dev/null
-/*
- * 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.checkers;
-
-import org.sonar.check.Check;
-import org.sonar.check.CheckProperty;
-import org.sonar.check.IsoCategory;
-import org.sonar.check.Priority;
-
-@Check(isoCategory = IsoCategory.Efficiency, priority = Priority.CRITICAL)
-class CheckerWithStringProperty {
-
- @CheckProperty(key = "maiximum")
- private String max;
-
- public String getMax() {
- return max;
- }
-}
+++ /dev/null
-/*
- * 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.checkers;
-
-import org.sonar.check.Check;
-import org.sonar.check.IsoCategory;
-import org.sonar.check.Priority;
-
-@Check(isoCategory = IsoCategory.Efficiency, priority = Priority.CRITICAL)
-class CheckerWithoutProperties {
-
-}
+++ /dev/null
-/*
- * 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.profiles;
-
-import org.hamcrest.BaseMatcher;
-import org.hamcrest.Description;
-import org.junit.Test;
-import org.sonar.check.Priority;
-
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-
-import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertThat;
-import static org.junit.internal.matchers.IsCollectionContaining.hasItem;
-
-/**
- * Created by IntelliJ IDEA.
- * User: simonbrandhof
- * Date: Sep 14, 2010
- * Time: 11:02:28 AM
- * To change this template use File | Settings | File Templates.
- */
-public class AnnotationCheckProfileFactoryTest {
-
- @Test
- public void noChecks() {
- assertThat(AnnotationCheckProfileFactory.create("plugin_foo", "java", null).size(), is(0));
- assertThat(AnnotationCheckProfileFactory.create("plugin_foo", "java", Collections.<Class>emptyList()).size(), is(0));
- }
-
- @Test
- public void create() {
- Collection<CheckProfile> profiles = AnnotationCheckProfileFactory.create("plugin_foo", "java", Arrays.<Class>asList(FakeCheckOne.class));
- assertThat(profiles.size(), is(1));
-
- CheckProfile profile = profiles.iterator().next();
- assertThat(profile.getName(), is("profile one"));
- assertThat(profile.getChecks().size(), is(1));
- assertThat(profile.getChecks().get(0).getPriority(), is(Priority.MINOR));
- }
-
- @Test
- public void provideManyProfiles() {
- Collection<CheckProfile> profiles = AnnotationCheckProfileFactory.create("plugin_foo", "java", Arrays.<Class>asList(FakeCheckOne.class, FakeCheckTwo.class));
- assertThat(profiles.size(), is(2));
-
- assertThat(profiles, hasItem(new CheckProfileMatcher("profile one", 2)));
- assertThat(profiles, hasItem(new CheckProfileMatcher("profile two", 1)));
- }
-}
-
-class CheckProfileMatcher extends BaseMatcher<CheckProfile> {
- private String name;
- private int numberOfChecks;
-
- CheckProfileMatcher(String name, int numberOfChecks) {
- this.name = name;
- this.numberOfChecks = numberOfChecks;
- }
-
- public boolean matches(Object o) {
- CheckProfile profile = (CheckProfile) o;
- return profile.getName().equals(name) && profile.getChecks().size() == numberOfChecks;
- }
-
- public void describeTo(Description description) {
- }
-}
\ No newline at end of file
+++ /dev/null
-/*
- * 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.profiles;
-
-import org.junit.Test;
-
-import static junit.framework.Assert.*;
-import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertThat;
-
-public class CheckProfileTest {
-
- @Test
- public void testCheck() {
- CheckProfile profile = new CheckProfile("fake", "java");
- assertThat(profile.getName(), is("fake"));
- assertThat(profile.getLanguage(), is("java"));
- assertThat(profile.getChecks().size(), is(0));
- }
-
- @Test
- public void equalsByNameAndLanguage() {
- CheckProfile profile1 = new CheckProfile("fake1", "java");
- CheckProfile profile1Clone = new CheckProfile("fake1", "java");
- CheckProfile profile2 = new CheckProfile("fake1", "php");
-
- assertTrue(profile1.equals(profile1));
- assertTrue(profile1.equals(profile1Clone));
- assertFalse(profile1.equals(profile2));
-
- assertEquals(profile1.hashCode(), profile1Clone.hashCode());
- }
-
- @Test
- public void addChecks() {
- CheckProfile profile = new CheckProfile("fake", "java");
- profile.addCheck(new Check("repo", "template"));
-
- assertThat(profile.getChecks().size(), is(1));
- assertThat(profile.getChecks("repo").size(), is(1));
- assertThat(profile.getChecks("other repo").size(), is(0));
- }
-}
+++ /dev/null
-/*
- * 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.profiles;
-
-import org.apache.commons.io.IOUtils;
-import org.custommonkey.xmlunit.Diff;
-import org.custommonkey.xmlunit.XMLUnit;
-import org.junit.Before;
-import org.junit.Test;
-import org.sonar.check.Priority;
-import org.xml.sax.SAXException;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.StringReader;
-import java.io.StringWriter;
-
-import static junit.framework.Assert.assertTrue;
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-
-public class CheckProfileXmlMarshallerTest {
-
- private String expectedXml;
-
- @Before
- public void loadExpectedXml() throws IOException {
- InputStream input = getClass().getResourceAsStream("/org/sonar/api/checks/profiles/CheckProfileXmlMarshallerTest/profile.xml");
- try {
- expectedXml = IOUtils.toString(input);
- } finally {
- IOUtils.closeQuietly(input);
- }
- }
-
-
- @Test
- public void toXml() throws IOException, SAXException {
- CheckProfile profile = new CheckProfile("one", "java");
- Check check1 = new Check("checkstyle", "C1");
- check1.setPriority(Priority.MINOR);
- check1.addProperty("min", "1");
- check1.addProperty("max", "3");
- profile.addCheck(check1);
-
- StringWriter writer = new StringWriter();
- CheckProfileXmlMarshaller.toXml(profile, writer);
-
- XMLUnit.setIgnoreWhitespace(true);
- Diff diff = XMLUnit.compareXML(expectedXml, writer.toString());
- assertTrue(diff.similar());
- }
-
-
- @Test
- public void fromXml() throws IOException, SAXException {
- CheckProfile profile = CheckProfileXmlMarshaller.fromXml(new StringReader(expectedXml));
- assertThat(profile.getName(), is("one"));
- assertThat(profile.getLanguage(), is("java"));
- assertThat(profile.getChecks("checkstyle").size(), is(1));
- assertThat(profile.getChecks("unknown").size(), is(0));
-
- Check check = profile.getChecks("checkstyle").get(0);
- assertThat(check.getRepositoryKey(), is("checkstyle"));
- assertThat(check.getTemplateKey(), is("C1"));
- assertThat(check.getPriority(), is(Priority.MINOR));
-
- assertThat(check.getProperties().size(), is(2));
- assertThat(check.getProperty("min"), is("1"));
- assertThat(check.getProperty("max"), is("3"));
- }
-
- @Test
- public void fromXmlInClasspath() {
- CheckProfile profile = CheckProfileXmlMarshaller.fromXmlInClasspath("/org/sonar/api/checks/profiles/CheckProfileXmlMarshallerTest/profile.xml");
- assertThat(profile.getName(), is("one"));
- }
-}
+++ /dev/null
-/*
- * 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.profiles;
-
-import org.junit.Test;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import static junit.framework.Assert.assertFalse;
-import static junit.framework.Assert.assertTrue;
-import static org.junit.Assert.assertThat;
-import static org.hamcrest.core.Is.is;
-
-public class CheckTest {
-
- @Test
- public void testParameters() {
- Check check = new Check("fake_plugin", "fake_key");
- assertThat(check.getProperties().size(), is(0));
-
- check.addProperty("foo", "bar");
- assertThat(check.getProperties().size(), is(1));
- assertThat(check.getProperties().get("foo"), is("bar"));
-
- Map<String, String> newParams = new HashMap<String, String>();
- newParams.put("foo", "new foo");
- newParams.put("hello", "world");
-
- check.setProperties(newParams);
- assertThat(check.getProperties().size(), is(2));
- assertThat(check.getProperties().get("foo"), is("new foo"));
- assertThat(check.getProperties().get("hello"), is("world"));
- }
-
- @Test
- public void equalsByReference() {
- Check check1 = new Check("fake_plugin", "fake_key");
- Check check2 = new Check("fake_plugin", "fake_key");
-
- assertTrue(check1.equals(check1));
- assertFalse(check1.equals(check2));
- }
-}
+++ /dev/null
-/*
- * 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.profiles;
-
-import org.sonar.check.BelongsToProfile;
-import org.sonar.check.IsoCategory;
-import org.sonar.check.Priority;
-
-/**
- * Created by IntelliJ IDEA.
- * User: simonbrandhof
- * Date: Sep 14, 2010
- * Time: 11:02:28 AM
- * To change this template use File | Settings | File Templates.
- */
-@org.sonar.check.Check(priority = Priority.BLOCKER, isoCategory = IsoCategory.Maintainability)
-@BelongsToProfile(title = "profile one", priority = Priority.MINOR)
-class FakeCheckOne {
-
-}
+++ /dev/null
-/*
- * 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.profiles;
-
-import org.sonar.check.BelongsToProfile;
-import org.sonar.check.BelongsToProfiles;
-import org.sonar.check.IsoCategory;
-import org.sonar.check.Priority;
-
-/**
- * Created by IntelliJ IDEA.
- * User: simonbrandhof
- * Date: Sep 14, 2010
- * Time: 11:02:28 AM
- * To change this template use File | Settings | File Templates.
- */
-@org.sonar.check.Check(priority = Priority.BLOCKER, isoCategory = IsoCategory.Maintainability)
-@BelongsToProfiles({
- @BelongsToProfile(title = "profile two", priority = Priority.INFO),
- @BelongsToProfile(title = "profile one", priority = Priority.MINOR)
-})
-class FakeCheckTwo {
-
-}
+++ /dev/null
-/*
- * 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.samples;
-
-import org.sonar.check.Check;
-import org.sonar.check.CheckProperty;
-import org.sonar.check.IsoCategory;
-
-@Check(isoCategory = IsoCategory.Efficiency)
-public final class AnnotatedCheckWithBundles {
- @CheckProperty
- private String max;
-
- @CheckProperty
- protected String min;
-
- private int nonConfigurableProperty;
-
- public String getMax() {
- return max;
- }
-
- public void setMax(String max) {
- this.max = max;
- }
-}
+++ /dev/null
-/*
- * 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.samples;
-
-import org.sonar.check.Check;
-import org.sonar.check.CheckProperty;
-import org.sonar.check.IsoCategory;
-
-@Check(title ="Detailed Check", description = "Detailed description", isoCategory = IsoCategory.Reliability)
-public class DetailedAnnotatedCheck {
-
- @CheckProperty(description ="Maximum value")
- private String max;
-
- @CheckProperty(description ="Minimum value")
- protected String min;
-
- private int nonConfigurableProperty;
-
- public String getMax() {
- return max;
- }
-
- public void setMax(String max) {
- this.max = max;
- }
-}
+++ /dev/null
-/*
- * 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.samples;
-
-import org.sonar.check.Check;
-import org.sonar.check.IsoCategory;
-
-@Check(
- key = "new_key",
- bundle = "org.sonar.api.checks.samples.alternative.path.AlternativeBundle",
- isoCategory = IsoCategory.Efficiency)
-public class I18nCheckWithAlternativeBundle {
-}
+++ /dev/null
-/*
- * 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.samples;
-
-import org.sonar.check.Check;
-import org.sonar.check.IsoCategory;
-
-@Check(title = "Title from annotation", isoCategory = IsoCategory.Efficiency)
-public class I18nCheckWithoutDefaultLocale {
-}
+++ /dev/null
-/*
- * 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.samples;
-
-import org.sonar.check.Check;
-import org.sonar.check.CheckProperty;
-import org.sonar.check.IsoCategory;
-
-@Check(isoCategory = IsoCategory.Efficiency)
-public class SimpleAnnotatedCheck {
-
- @CheckProperty
- private String max;
-
- @CheckProperty
- protected String min;
-
- private int nonConfigurableProperty;
-
- public String getMax() {
- return max;
- }
-
- public void setMax(String max) {
- this.max = max;
- }
-}
-
+++ /dev/null
-<profile>
- <name>one</name>
- <language>java</language>
- <check>
- <repository>checkstyle</repository>
- <template>C1</template>
- <priority>MINOR</priority>
- <property>
- <key>min</key>
- <value>1</value>
- </property>
- <property>
- <key>max</key>
- <value>3</value>
- </property>
- </check>
-</profile>
\ No newline at end of file
+++ /dev/null
-title: I18n Check
-description: Description in english
-property.max.title: Maximum value
-property.max.description: Description in english of the maximum value
-property.min.title: Minimum value
-property.min.description: Description in english of the minimum value
\ No newline at end of file
+++ /dev/null
-title: Règle d'internationalisation
-description: Description en Français
-property.max.title: Valeur maximale
-property.max.description: Description en Français de la valeur maximale
-property.min.title: Valeur minimale
-property.min.description: Description en Français de la valeur minimale
+++ /dev/null
-title: Titre depuis le bundle
-description: Seul le francais est disponible dans les bundles
\ No newline at end of file
+++ /dev/null
-title : Alternative Path to Bundle
-description : description of Alternative Path to Bundle
\ No newline at end of file