*/
package org.sonar.java.ast.check;
+import org.sonar.check.BelongsToProfile;
+
import java.util.Arrays;
import java.util.List;
import java.util.Set;
* @since 2.13
*/
@Rule(key = "CommentedOutCodeLine", priority = Priority.MAJOR)
+@BelongsToProfile(title = "Sonar way", priority = Priority.MAJOR)
public class CommentedOutCodeLineCheck extends JavaAstVisitor {
private static final double THRESHOLD = 0.9;
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 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.plugins.squid;
+
+import org.sonar.api.resources.Java;
+
+import com.google.common.collect.ImmutableList;
+import org.sonar.api.profiles.AnnotationProfileParser;
+import org.sonar.api.profiles.ProfileDefinition;
+import org.sonar.api.profiles.RulesProfile;
+import org.sonar.api.utils.ValidationMessages;
+import org.sonar.java.ast.check.CommentedOutCodeLineCheck;
+
+import java.util.Collection;
+
+public class SonarWayProfile extends ProfileDefinition {
+ private final AnnotationProfileParser annotationProfileParser;
+
+ public SonarWayProfile(AnnotationProfileParser annotationProfileParser) {
+ this.annotationProfileParser = annotationProfileParser;
+ }
+
+ @Override
+ public RulesProfile createProfile(ValidationMessages messages) {
+ Collection<Class> rules = ImmutableList.<Class> of(CommentedOutCodeLineCheck.class);
+
+ return annotationProfileParser.parse(SquidConstants.REPOSITORY_KEY, RulesProfile.SONAR_WAY_NAME, Java.KEY, rules, messages);
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 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.plugins.squid;
+
+import org.sonar.api.profiles.ProfileDefinition;
+import org.sonar.api.profiles.RulesProfile;
+import org.sonar.api.utils.ValidationMessages;
+
+public class SonarWayWithFindbugsProfile extends ProfileDefinition {
+ private final SonarWayProfile sonarWay;
+
+ public SonarWayWithFindbugsProfile(SonarWayProfile sonarWay) {
+ this.sonarWay = sonarWay;
+ }
+
+ @Override
+ public RulesProfile createProfile(ValidationMessages validationMessages) {
+ RulesProfile profile = sonarWay.createProfile(validationMessages);
+ profile.setName(RulesProfile.SONAR_WAY_FINDBUGS_NAME);
+ return profile;
+ }
+}
+
public List<Class<? extends Extension>> getExtensions() {
return ImmutableList.of(
- SquidSensor.class,
- SquidRuleRepository.class,
- JavaSourceImporter.class,
+ ChidamberKemererDistributionBuilder.class,
+ ClassesDecorator.class,
FileComplexityDistributionDecorator.class,
FunctionComplexityDistributionBuilder.class,
- ClassesDecorator.class,
- ChidamberKemererDistributionBuilder.class,
- FunctionsDecorator.class);
+ FunctionsDecorator.class,
+ JavaSourceImporter.class,
+ SonarWayProfile.class,
+ SonarWayWithFindbugsProfile.class,
+ SquidRuleRepository.class,
+ SquidSensor.class);
}
-
}
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 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.plugins.squid;
+
+import org.junit.Test;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+import org.sonar.api.profiles.AnnotationProfileParser;
+import org.sonar.api.profiles.RulesProfile;
+import org.sonar.api.rules.Rule;
+import org.sonar.api.rules.RuleFinder;
+import org.sonar.api.utils.ValidationMessages;
+
+import static org.fest.assertions.Assertions.assertThat;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class SonarWayProfileTest {
+ @Test
+ public void should_create_sonar_way_profile() {
+ ValidationMessages validation = ValidationMessages.create();
+
+ SonarWayProfile definition = new SonarWayProfile(new AnnotationProfileParser(ruleFinder()));
+ RulesProfile profile = definition.createProfile(validation);
+
+ assertThat(profile.getActiveRulesByRepository(SquidConstants.REPOSITORY_KEY)).hasSize(1);
+ assertThat(profile.getName()).isEqualTo(RulesProfile.SONAR_WAY_NAME);
+ assertThat(validation.hasErrors()).isFalse();
+ }
+
+ @Test
+ public void should_create_sonar_way_with_findbugs_profile() {
+ ValidationMessages validation = ValidationMessages.create();
+
+ SonarWayWithFindbugsProfile definition = new SonarWayWithFindbugsProfile(new SonarWayProfile(new AnnotationProfileParser(ruleFinder())));
+ RulesProfile profile = definition.createProfile(validation);
+
+ assertThat(profile.getActiveRulesByRepository(SquidConstants.REPOSITORY_KEY)).hasSize(1);
+ assertThat(profile.getName()).isEqualTo(RulesProfile.SONAR_WAY_FINDBUGS_NAME);
+ assertThat(validation.hasErrors()).isFalse();
+ }
+
+ static RuleFinder ruleFinder() {
+ return when(mock(RuleFinder.class).findByKey(anyString(), anyString())).thenAnswer(new Answer<Rule>() {
+ public Rule answer(InvocationOnMock invocation) {
+ Object[] arguments = invocation.getArguments();
+ return Rule.create((String) arguments[0], (String) arguments[1], (String) arguments[1]);
+ }
+ }).getMock();
+ }
+}
import org.junit.Test;
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
+import static org.fest.assertions.Assertions.assertThat;
public class SquidPluginTest {
-
@Test
public void coverageForFun() {
- assertThat(new SquidPlugin().getExtensions().size(), is(8));
+ assertThat(new SquidPlugin().getExtensions()).hasSize(10);
}
}