Skip to content

Commit

Permalink
Quality profiles should be the default ones
Browse files Browse the repository at this point in the history
Add empty rule so that DB profile can remain the default one
  • Loading branch information
gquerret committed Feb 24, 2020
1 parent b3640e9 commit f55cc0d
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class Constants {

// Key of the default rule repository
public static final String STD_REPOSITORY_KEY = "rssw-oe";
public static final String STD_DB_REPOSITORY_KEY = "rssw-oedb";
public static final String RSSW_REPOSITORY_KEY = "rssw-oe-main";
public static final String RSSW_DB_REPOSITORY_KEY = "rssw-oedb-main";

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* OpenEdge plugin for SonarQube
* Copyright (c) 2019-2020 Riverside Software
* contact AT riverside DASH software DOT fr
*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
package org.sonar.plugins.openedge.checks;

import org.antlr.v4.runtime.tree.ParseTree;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.check.Priority;
import org.sonar.check.Rule;
import org.sonar.plugins.openedge.api.checks.OpenEdgeDumpFileCheck;
import org.sonar.plugins.openedge.api.model.SqaleConstantRemediation;

@Rule(priority = Priority.INFO, name = "No-op database rule")
@SqaleConstantRemediation(value = "1min")
public class NoOpDatabaseRule extends OpenEdgeDumpFileCheck {

@Override
public void execute(InputFile file, ParseTree o) {
// No-op
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.sonar.plugins.openedge.api.checks.OpenEdgeProparseCheck;
import org.sonar.plugins.openedge.checks.ClumsySyntax;
import org.sonar.plugins.openedge.checks.LargeTransactionScope;
import org.sonar.plugins.openedge.checks.NoOpDatabaseRule;
import org.sonar.plugins.openedge.checks.SharedObjectsAnalyzer;

public class BasicChecksRegistration implements CheckRegistration {
Expand Down Expand Up @@ -59,7 +60,7 @@ public static Class<? extends OpenEdgeProparseCheck>[] ppCheckClasses() {
*/
@SuppressWarnings("unchecked")
public static Class<? extends OpenEdgeDumpFileCheck>[] dbCheckClasses() {
return new Class[] {};
return new Class[] {NoOpDatabaseRule.class};
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,17 @@

import org.sonar.api.server.profile.BuiltInQualityProfilesDefinition;
import org.sonar.plugins.openedge.api.Constants;
import org.sonar.plugins.openedge.checks.NoOpDatabaseRule;

public class OpenEdgeDBProfile implements BuiltInQualityProfilesDefinition {
public static final String PROFILE_NAME = "Sonar way";

@Override
public void define(Context context) {
context.createBuiltInQualityProfile(PROFILE_NAME, Constants.DB_LANGUAGE_KEY).done();
NewBuiltInQualityProfile profile = context.createBuiltInQualityProfile(PROFILE_NAME,
Constants.DB_LANGUAGE_KEY).setDefault(true);
profile.activateRule(Constants.STD_DB_REPOSITORY_KEY, NoOpDatabaseRule.class.getName());
profile.done();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public class OpenEdgeProfile implements BuiltInQualityProfilesDefinition {

@Override
public void define(Context context) {
NewBuiltInQualityProfile profile = context.createBuiltInQualityProfile(PROFILE_NAME, Constants.LANGUAGE_KEY);
NewBuiltInQualityProfile profile = context.createBuiltInQualityProfile(PROFILE_NAME,
Constants.LANGUAGE_KEY).setDefault(true);

profile.activateRule(Constants.STD_REPOSITORY_KEY, OpenEdgeRulesDefinition.PROPARSE_ERROR_RULEKEY);
profile.activateRule(Constants.STD_REPOSITORY_KEY, OpenEdgeRulesDefinition.COMPILER_WARNING_RULEKEY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public OpenEdgeRulesDefinition(SonarRuntime runtime) {
@Override
public void define(Context context) {
NewRepository repository = context.createRepository(Constants.STD_REPOSITORY_KEY, Constants.LANGUAGE_KEY).setName(REPOSITORY_NAME);

AnnotationBasedRulesDefinition annotationLoader = new AnnotationBasedRulesDefinition(repository, Constants.LANGUAGE_KEY, runtime);
annotationLoader.addRuleClasses(false, Arrays.<Class> asList(BasicChecksRegistration.ppCheckClasses()));

Expand Down Expand Up @@ -93,6 +92,11 @@ public void define(Context context) {
Constants.STD_REPOSITORY_KEY, proparseRule.key())));

repository.done();

NewRepository repository2 = context.createRepository(Constants.STD_DB_REPOSITORY_KEY, Constants.DB_LANGUAGE_KEY).setName(REPOSITORY_NAME);
AnnotationBasedRulesDefinition annotationLoader2 = new AnnotationBasedRulesDefinition(repository2, Constants.DB_LANGUAGE_KEY, runtime);
annotationLoader2.addRuleClasses(false, Arrays.<Class> asList(BasicChecksRegistration.dbCheckClasses()));
repository2.done();
}

private void createWarningRule(NewRepository repository, String ruleKey, String name, String remediationCost) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>Just an empty rule you can safely ignore</p>

0 comments on commit f55cc0d

Please sign in to comment.