diff options
author | simonbrandhof <simon.brandhof@gmail.com> | 2011-05-27 15:57:20 +0200 |
---|---|---|
committer | simonbrandhof <simon.brandhof@gmail.com> | 2011-05-27 16:06:37 +0200 |
commit | e2136eabb58be699e3caf541efd4cfe7bb8c7e9f (patch) | |
tree | a4935a7d35c9009ff25b3eb3498cff15c24ce524 /sonar-deprecated/src/main/java | |
parent | 2a80f3d0b52a0859d35b8582ac059932b3b0c0f8 (diff) | |
download | sonarqube-e2136eabb58be699e3caf541efd4cfe7bb8c7e9f.tar.gz sonarqube-e2136eabb58be699e3caf541efd4cfe7bb8c7e9f.zip |
SONAR-2475 remove org.sonar.api.checks.checkers and org.sonar.api.checks.profiles
Diffstat (limited to 'sonar-deprecated/src/main/java')
9 files changed, 0 insertions, 856 deletions
diff --git a/sonar-deprecated/src/main/java/org/sonar/api/checks/checkers/AnnotationCheckerFactory.java b/sonar-deprecated/src/main/java/org/sonar/api/checks/checkers/AnnotationCheckerFactory.java deleted file mode 100644 index 78b36dfa0a8..00000000000 --- a/sonar-deprecated/src/main/java/org/sonar/api/checks/checkers/AnnotationCheckerFactory.java +++ /dev/null @@ -1,160 +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.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; - } - -} diff --git a/sonar-deprecated/src/main/java/org/sonar/api/checks/checkers/CheckerFactory.java b/sonar-deprecated/src/main/java/org/sonar/api/checks/checkers/CheckerFactory.java deleted file mode 100644 index 1c28fca8493..00000000000 --- a/sonar-deprecated/src/main/java/org/sonar/api/checks/checkers/CheckerFactory.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.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(); -} diff --git a/sonar-deprecated/src/main/java/org/sonar/api/checks/checkers/MessageDispatcher.java b/sonar-deprecated/src/main/java/org/sonar/api/checks/checkers/MessageDispatcher.java deleted file mode 100644 index 242693eb485..00000000000 --- a/sonar-deprecated/src/main/java/org/sonar/api/checks/checkers/MessageDispatcher.java +++ /dev/null @@ -1,111 +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.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(); - } - -} diff --git a/sonar-deprecated/src/main/java/org/sonar/api/checks/checkers/UnvalidCheckerException.java b/sonar-deprecated/src/main/java/org/sonar/api/checks/checkers/UnvalidCheckerException.java deleted file mode 100644 index b89ec23ebc6..00000000000 --- a/sonar-deprecated/src/main/java/org/sonar/api/checks/checkers/UnvalidCheckerException.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.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); - } -} diff --git a/sonar-deprecated/src/main/java/org/sonar/api/checks/profiles/AnnotationCheckProfileFactory.java b/sonar-deprecated/src/main/java/org/sonar/api/checks/profiles/AnnotationCheckProfileFactory.java deleted file mode 100644 index ee849c50180..00000000000 --- a/sonar-deprecated/src/main/java/org/sonar/api/checks/profiles/AnnotationCheckProfileFactory.java +++ /dev/null @@ -1,72 +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.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); - } - } -} diff --git a/sonar-deprecated/src/main/java/org/sonar/api/checks/profiles/Check.java b/sonar-deprecated/src/main/java/org/sonar/api/checks/profiles/Check.java deleted file mode 100644 index 45e5b5e9f08..00000000000 --- a/sonar-deprecated/src/main/java/org/sonar/api/checks/profiles/Check.java +++ /dev/null @@ -1,111 +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.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(); - } -} diff --git a/sonar-deprecated/src/main/java/org/sonar/api/checks/profiles/CheckProfile.java b/sonar-deprecated/src/main/java/org/sonar/api/checks/profiles/CheckProfile.java deleted file mode 100644 index 58268e5167b..00000000000 --- a/sonar-deprecated/src/main/java/org/sonar/api/checks/profiles/CheckProfile.java +++ /dev/null @@ -1,136 +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.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; - } -} diff --git a/sonar-deprecated/src/main/java/org/sonar/api/checks/profiles/CheckProfileProvider.java b/sonar-deprecated/src/main/java/org/sonar/api/checks/profiles/CheckProfileProvider.java deleted file mode 100644 index 7f893ff5b7b..00000000000 --- a/sonar-deprecated/src/main/java/org/sonar/api/checks/profiles/CheckProfileProvider.java +++ /dev/null @@ -1,35 +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.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(); - -} diff --git a/sonar-deprecated/src/main/java/org/sonar/api/checks/profiles/CheckProfileXmlMarshaller.java b/sonar-deprecated/src/main/java/org/sonar/api/checks/profiles/CheckProfileXmlMarshaller.java deleted file mode 100644 index 3502c5ed307..00000000000 --- a/sonar-deprecated/src/main/java/org/sonar/api/checks/profiles/CheckProfileXmlMarshaller.java +++ /dev/null @@ -1,156 +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.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); - } - } - - } -} |