import org.sonar.api.checks.CheckFactory;
import org.sonar.api.rules.ActiveRule;
+import org.sonar.check.BelongsToProfile;
import org.sonar.check.Priority;
import org.sonar.check.Rule;
/**
* Companion of {@link org.sonar.plugins.squid.bridges.DesignBridge} which actually does the job on finding cycles and creation of violations.
+ *
+ * @since 3.2
*/
@Rule(key = "CycleBetweenPackages", priority = Priority.MAJOR)
+@BelongsToProfile(title = "Sonar way", priority = Priority.MAJOR)
public class CycleBetweenPackagesCheck extends SquidCheck {
/**
*/
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.resources.Java;
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;
@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);
+ return annotationProfileParser.parse(SquidConstants.REPOSITORY_KEY, RulesProfile.SONAR_WAY_NAME, Java.KEY, SquidRuleRepository.getCheckClasses(), messages);
}
-}
\ No newline at end of file
+}
// If resource cannot be obtained, then silently ignore, because anyway warning will be printed by method saveEdge
if ((fromFile != null) && (toFile != null)) {
Violation violation = Violation.create(rule, fromFile)
- .setMessage("Remove the dependency on the source file \"" + toFile.getLongName() + "\" to break a package cycle.");
+ .setMessage("Remove the dependency on the source file \"" + toFile.getLongName() + "\" to break a package cycle.")
+ .setCost((double) subEdge.getWeight());
context.saveViolation(violation);
}
}
SonarWayProfile definition = new SonarWayProfile(new AnnotationProfileParser(ruleFinder()));
RulesProfile profile = definition.createProfile(validation);
- assertThat(profile.getActiveRulesByRepository(SquidConstants.REPOSITORY_KEY)).hasSize(1);
+ assertThat(profile.getActiveRulesByRepository(SquidConstants.REPOSITORY_KEY)).hasSize(2);
assertThat(profile.getName()).isEqualTo(RulesProfile.SONAR_WAY_NAME);
assertThat(validation.hasErrors()).isFalse();
}
SonarWayWithFindbugsProfile definition = new SonarWayWithFindbugsProfile(new SonarWayProfile(new AnnotationProfileParser(ruleFinder())));
RulesProfile profile = definition.createProfile(validation);
- assertThat(profile.getActiveRulesByRepository(SquidConstants.REPOSITORY_KEY)).hasSize(1);
+ assertThat(profile.getActiveRulesByRepository(SquidConstants.REPOSITORY_KEY)).hasSize(2);
assertThat(profile.getName()).isEqualTo(RulesProfile.SONAR_WAY_FINDBUGS_NAME);
assertThat(validation.hasErrors()).isFalse();
}