Skip to content
This repository has been archived by the owner on Dec 10, 2024. It is now read-only.

Commit

Permalink
Merge pull request #67 from Inform-Software/default-profile-from-text
Browse files Browse the repository at this point in the history
Replace deprecated XML profile with a simple text file (fixes #65)
  • Loading branch information
TobiX authored Aug 3, 2021
2 parents 6a8dfd0 + 7fd5bba commit e243dae
Show file tree
Hide file tree
Showing 9 changed files with 193 additions and 455 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ jobs:
java: [8, 11]
sonar:
- ""
- "8.3.0.34182"
- "8.9.0.43852"
include:
- java: 8
sonar: ""
archive: "yes"
- java: 11
sonar: "9.0.0.45539"

runs-on: ubuntu-latest

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ public String toString() {
public static List<Object> getExtensions() {
return Arrays.asList(
GroovySensor.class,
GroovySonarWayProfile.class,
PropertyDefinition.builder(IGNORE_HEADER_COMMENTS)
.name("Ignore Header Comments")
.description(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Sonar Groovy Plugin
* Copyright (C) 2010-2021 SonarQube Community
*
* 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 02110-1301, USA.
*/
package org.sonar.plugins.groovy;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import org.sonar.api.server.profile.BuiltInQualityProfilesDefinition;
import org.sonar.plugins.groovy.codenarc.CodeNarcRulesDefinition;
import org.sonar.plugins.groovy.foundation.Groovy;
import org.sonarsource.api.sonarlint.SonarLintSide;

@SonarLintSide
public class GroovySonarWayProfile implements BuiltInQualityProfilesDefinition {

@Override
public void define(Context context) {
NewBuiltInQualityProfile sonarWay =
context.createBuiltInQualityProfile("Sonar way", Groovy.KEY);

addRulesFromText(CodeNarcRulesDefinition.REPOSITORY_KEY, sonarWay);
sonarWay.done();
}

private static void addRulesFromText(String repo, NewBuiltInQualityProfile profile) {
try (BufferedReader reader =
new BufferedReader(
new InputStreamReader(
GroovySonarWayProfile.class.getResourceAsStream("profile-default.txt"),
StandardCharsets.UTF_8))) {
reader
.lines()
.forEach(
(String rule) -> {
if (!rule.isEmpty()) {
profile.activateRule(repo, rule);
}
});
} catch (IOException e) {
throw new IllegalStateException("Failed to read: profile-default.txt", e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ public static List<Object> getExtensions() {
return Arrays.asList(
CodeNarcRulesDefinition.class,
CodeNarcSensor.class,
SonarWayProfile.class,
PropertyDefinition.builder(CODENARC_REPORT_PATHS)
.name("CodeNarc Reports")
.description(
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
org.codenarc.rule.basic.AssignmentInConditionalRule
org.codenarc.rule.exceptions.CatchErrorRule
org.codenarc.rule.exceptions.CatchExceptionRule
org.codenarc.rule.exceptions.CatchNullPointerExceptionRule
org.codenarc.rule.exceptions.CatchRuntimeExceptionRule
org.codenarc.rule.design.CloneableWithoutCloneRule
org.codenarc.rule.braces.ElseBlockBracesRule
org.codenarc.rule.grails.GrailsPublicControllerMethodRule.fixed
org.codenarc.rule.grails.GrailsServletContextReferenceRule
org.codenarc.rule.grails.GrailsStatelessServiceRule
org.codenarc.rule.size.NestedBlockDepthRule
org.codenarc.rule.concurrency.NestedSynchronizationRule
org.codenarc.rule.logging.PrintStackTraceRule
org.codenarc.rule.logging.PrintlnRule
org.codenarc.rule.basic.ReturnFromFinallyBlockRule
org.codenarc.rule.concurrency.SynchronizedMethodRule
org.codenarc.rule.logging.SystemErrPrintRule
org.codenarc.rule.logging.SystemOutPrintRule
org.codenarc.rule.concurrency.SystemRunFinalizersOnExitRule
org.codenarc.rule.concurrency.ThreadYieldRule
org.codenarc.rule.exceptions.ThrowErrorRule
org.codenarc.rule.exceptions.ThrowExceptionRule
org.codenarc.rule.basic.ThrowExceptionFromFinallyBlockRule
org.codenarc.rule.exceptions.ThrowNullPointerExceptionRule
org.codenarc.rule.exceptions.ThrowRuntimeExceptionRule
org.codenarc.rule.exceptions.ThrowThrowableRule
org.codenarc.rule.imports.UnnecessaryGroovyImportRule
org.codenarc.rule.imports.UnusedImportRule
org.codenarc.rule.unused.UnusedPrivateFieldRule
org.codenarc.rule.unused.UnusedPrivateMethodRule
org.codenarc.rule.unused.UnusedVariableRule.fixed
org.codenarc.rule.concurrency.VolatileLongOrDoubleFieldRule
org.codenarc.rule.basic.DuplicateCaseStatementRule
org.codenarc.rule.basic.EmptyCatchBlockRule
org.codenarc.rule.basic.EmptyElseBlockRule
org.codenarc.rule.basic.EmptyFinallyBlockRule
org.codenarc.rule.basic.EmptyForStatementRule
org.codenarc.rule.basic.EmptyIfStatementRule
org.codenarc.rule.basic.EmptyInstanceInitializerRule
org.codenarc.rule.basic.EmptyMethodRule
org.codenarc.rule.basic.EmptyStaticInitializerRule
org.codenarc.rule.basic.EmptySwitchStatementRule
org.codenarc.rule.basic.EmptySynchronizedStatementRule
org.codenarc.rule.basic.EmptyTryBlockRule
org.codenarc.rule.basic.EmptyWhileStatementRule
org.codenarc.rule.basic.EqualsAndHashCodeRule
org.codenarc.rule.basic.EqualsOverloadedRule
org.codenarc.rule.basic.EmptyClassRule
org.codenarc.rule.imports.DuplicateImportRule
org.codenarc.rule.imports.ImportFromSamePackageRule
org.codenarc.rule.imports.ImportFromSunPackagesRule
org.codenarc.rule.naming.ClassNameSameAsFilenameRule
org.codenarc.rule.unused.UnusedPrivateMethodParameterRule
org.codenarc.rule.unused.UnusedMethodParameterRule
org.codenarc.rule.convention.ConfusingTernaryRule
org.codenarc.rule.convention.InvertedIfElseRule
org.codenarc.rule.convention.VectorIsObsoleteRule
org.codenarc.rule.convention.HashtableIsObsoleteRule
Loading

0 comments on commit e243dae

Please sign in to comment.