|
|
@ -8,6 +8,7 @@ package com.keyware.sonar.cxx; |
|
|
|
|
|
|
|
|
|
|
|
import com.google.common.io.Resources; |
|
|
|
import com.google.common.io.Resources; |
|
|
|
import com.google.gson.Gson; |
|
|
|
import com.google.gson.Gson; |
|
|
|
|
|
|
|
import com.keyware.sonar.cxx.rules.SecurityDesignRuleRepository; |
|
|
|
import org.sonar.api.server.profile.BuiltInQualityProfilesDefinition; |
|
|
|
import org.sonar.api.server.profile.BuiltInQualityProfilesDefinition; |
|
|
|
import org.sonar.cxx.checks.CheckList; |
|
|
|
import org.sonar.cxx.checks.CheckList; |
|
|
|
import org.sonarsource.api.sonarlint.SonarLintSide; |
|
|
|
import org.sonarsource.api.sonarlint.SonarLintSide; |
|
|
@ -23,34 +24,33 @@ import java.util.List; |
|
|
|
@SonarLintSide |
|
|
|
@SonarLintSide |
|
|
|
public class CxxSonarWayProfile implements BuiltInQualityProfilesDefinition { |
|
|
|
public class CxxSonarWayProfile implements BuiltInQualityProfilesDefinition { |
|
|
|
|
|
|
|
|
|
|
|
private static String readResource(URL resource) { |
|
|
|
private static String readResource(URL resource) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
return Resources.toString(resource, StandardCharsets.UTF_8); |
|
|
|
return Resources.toString(resource, StandardCharsets.UTF_8); |
|
|
|
} catch (IOException e) { |
|
|
|
} catch (IOException e) { |
|
|
|
throw new IllegalStateException("Failed to read: " + resource, e); |
|
|
|
throw new IllegalStateException("Failed to read: " + resource, e); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static Profile readProfile() { |
|
|
|
static Profile readProfile() { |
|
|
|
URL resource = CxxSonarWayProfile.class.getResource("/org/sonar/l10n/cxx/rules/cxx/Sonar_way_profile.json"); |
|
|
|
URL resource = CxxSonarWayProfile.class.getResource("/org/sonar/l10n/cxx/rules/cxx/Sonar_way_profile.json"); |
|
|
|
return new Gson().fromJson(readResource(resource), Profile.class); |
|
|
|
return new Gson().fromJson(readResource(resource), Profile.class); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void define(Context context) { |
|
|
|
|
|
|
|
var sonarWay = context.createBuiltInQualityProfile("Sonar way", CxxLanguage.KEY); |
|
|
|
|
|
|
|
Profile jsonProfile = readProfile(); |
|
|
|
|
|
|
|
jsonProfile.ruleKeys.forEach((key) -> { |
|
|
|
|
|
|
|
sonarWay.activateRule(CheckList.REPOSITORY_KEY, key); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sonarWay.done(); |
|
|
|
@Override |
|
|
|
} |
|
|
|
public void define(Context context) { |
|
|
|
|
|
|
|
var sonarWay = context.createBuiltInQualityProfile("Sonar way", CxxLanguage.KEY); |
|
|
|
|
|
|
|
Profile jsonProfile = readProfile(); |
|
|
|
|
|
|
|
jsonProfile.ruleKeys.forEach((key) -> { |
|
|
|
|
|
|
|
sonarWay.activateRule(CheckList.REPOSITORY_KEY, key); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
sonarWay.done(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static class Profile { |
|
|
|
static class Profile { |
|
|
|
|
|
|
|
|
|
|
|
public String name; |
|
|
|
public String name; |
|
|
|
public List<String> ruleKeys; |
|
|
|
public List<String> ruleKeys; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|