how to scan java properties file in sonarqube [closed]
up vote
0
down vote
favorite
I am writing custom rules using SonarQube to scan properties and config files.
Can you please guide me how to write this custom code.
properties sonarqube rules
closed as off-topic by Michael Dodd, AdrianHHH, Masoud, sideshowbarker, Pearly Spencer Nov 19 at 21:29
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it." – AdrianHHH, Masoud, Pearly Spencer
If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
up vote
0
down vote
favorite
I am writing custom rules using SonarQube to scan properties and config files.
Can you please guide me how to write this custom code.
properties sonarqube rules
closed as off-topic by Michael Dodd, AdrianHHH, Masoud, sideshowbarker, Pearly Spencer Nov 19 at 21:29
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it." – AdrianHHH, Masoud, Pearly Spencer
If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am writing custom rules using SonarQube to scan properties and config files.
Can you please guide me how to write this custom code.
properties sonarqube rules
I am writing custom rules using SonarQube to scan properties and config files.
Can you please guide me how to write this custom code.
properties sonarqube rules
properties sonarqube rules
asked Nov 19 at 14:03
sorab
7129
7129
closed as off-topic by Michael Dodd, AdrianHHH, Masoud, sideshowbarker, Pearly Spencer Nov 19 at 21:29
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it." – AdrianHHH, Masoud, Pearly Spencer
If this question can be reworded to fit the rules in the help center, please edit the question.
closed as off-topic by Michael Dodd, AdrianHHH, Masoud, sideshowbarker, Pearly Spencer Nov 19 at 21:29
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it." – AdrianHHH, Masoud, Pearly Spencer
If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
There is a plugin for java properties file https://github.com/racodond/sonar-jproperties-plugin. You can fork it and write your custom rules.
Here is an example rule wich checks for not allowed key and value combination
public class KeyValueCheck extends DoubleDispatchVisitorCheck {
private static final String SIMPLE_IS_PATTERN_TEMPLATE = "(%s)";
protected final Pattern patternKey;
protected final Pattern patternValue;
private final String VIOLATION_MESSAGE;
private final boolean matches;
boolean checkValue = false;
public KeyValueCheck(String key, String value, String message, boolean matches) {
VIOLATION_MESSAGE = message;
this.matches = matches;
this.patternKey = Pattern.compile(String.format(SIMPLE_IS_PATTERN_TEMPLATE, key), Pattern.CASE_INSENSITIVE);
this.patternValue = Pattern.compile(String.format(SIMPLE_IS_PATTERN_TEMPLATE, value), Pattern.CASE_INSENSITIVE);
}
@Override
public void visitKey(KeyTree tree) {
Matcher matcher = patternKey.matcher(tree.text());
if (matcher.matches()) {
checkValue = true;
}
super.visitKey(tree);
}
@Override
public void visitValue(ValueTree tree) {
if (checkValue) {
Matcher matcher = patternValue.matcher(tree.text());
if (matches == patternValue.matcher(tree.text()).matches()) {
addPreciseIssue(tree, VIOLATION_MESSAGE);
}
checkValue = false;
}
super.visitValue(tree);
}
}
Thanks, Is there some reference material on how to write custom sonarqube rules.
– sorab
Nov 21 at 14:54
Is sonarqube multi-lingual, can i get the UI in german or french
– sorab
Nov 21 at 14:56
internatinalization github.com/SonarQubeCommunity/sonar-l10n-de
– Josef Procházka
Nov 22 at 8:56
custom sonar rules - There is a lot of examples on the internet, but the best source is the source code of plugins itself. You can get lot of help in SonarQube email groups groups.google.com/forum/#!forum/sonarqube
– Josef Procházka
Nov 22 at 8:59
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
There is a plugin for java properties file https://github.com/racodond/sonar-jproperties-plugin. You can fork it and write your custom rules.
Here is an example rule wich checks for not allowed key and value combination
public class KeyValueCheck extends DoubleDispatchVisitorCheck {
private static final String SIMPLE_IS_PATTERN_TEMPLATE = "(%s)";
protected final Pattern patternKey;
protected final Pattern patternValue;
private final String VIOLATION_MESSAGE;
private final boolean matches;
boolean checkValue = false;
public KeyValueCheck(String key, String value, String message, boolean matches) {
VIOLATION_MESSAGE = message;
this.matches = matches;
this.patternKey = Pattern.compile(String.format(SIMPLE_IS_PATTERN_TEMPLATE, key), Pattern.CASE_INSENSITIVE);
this.patternValue = Pattern.compile(String.format(SIMPLE_IS_PATTERN_TEMPLATE, value), Pattern.CASE_INSENSITIVE);
}
@Override
public void visitKey(KeyTree tree) {
Matcher matcher = patternKey.matcher(tree.text());
if (matcher.matches()) {
checkValue = true;
}
super.visitKey(tree);
}
@Override
public void visitValue(ValueTree tree) {
if (checkValue) {
Matcher matcher = patternValue.matcher(tree.text());
if (matches == patternValue.matcher(tree.text()).matches()) {
addPreciseIssue(tree, VIOLATION_MESSAGE);
}
checkValue = false;
}
super.visitValue(tree);
}
}
Thanks, Is there some reference material on how to write custom sonarqube rules.
– sorab
Nov 21 at 14:54
Is sonarqube multi-lingual, can i get the UI in german or french
– sorab
Nov 21 at 14:56
internatinalization github.com/SonarQubeCommunity/sonar-l10n-de
– Josef Procházka
Nov 22 at 8:56
custom sonar rules - There is a lot of examples on the internet, but the best source is the source code of plugins itself. You can get lot of help in SonarQube email groups groups.google.com/forum/#!forum/sonarqube
– Josef Procházka
Nov 22 at 8:59
add a comment |
up vote
0
down vote
accepted
There is a plugin for java properties file https://github.com/racodond/sonar-jproperties-plugin. You can fork it and write your custom rules.
Here is an example rule wich checks for not allowed key and value combination
public class KeyValueCheck extends DoubleDispatchVisitorCheck {
private static final String SIMPLE_IS_PATTERN_TEMPLATE = "(%s)";
protected final Pattern patternKey;
protected final Pattern patternValue;
private final String VIOLATION_MESSAGE;
private final boolean matches;
boolean checkValue = false;
public KeyValueCheck(String key, String value, String message, boolean matches) {
VIOLATION_MESSAGE = message;
this.matches = matches;
this.patternKey = Pattern.compile(String.format(SIMPLE_IS_PATTERN_TEMPLATE, key), Pattern.CASE_INSENSITIVE);
this.patternValue = Pattern.compile(String.format(SIMPLE_IS_PATTERN_TEMPLATE, value), Pattern.CASE_INSENSITIVE);
}
@Override
public void visitKey(KeyTree tree) {
Matcher matcher = patternKey.matcher(tree.text());
if (matcher.matches()) {
checkValue = true;
}
super.visitKey(tree);
}
@Override
public void visitValue(ValueTree tree) {
if (checkValue) {
Matcher matcher = patternValue.matcher(tree.text());
if (matches == patternValue.matcher(tree.text()).matches()) {
addPreciseIssue(tree, VIOLATION_MESSAGE);
}
checkValue = false;
}
super.visitValue(tree);
}
}
Thanks, Is there some reference material on how to write custom sonarqube rules.
– sorab
Nov 21 at 14:54
Is sonarqube multi-lingual, can i get the UI in german or french
– sorab
Nov 21 at 14:56
internatinalization github.com/SonarQubeCommunity/sonar-l10n-de
– Josef Procházka
Nov 22 at 8:56
custom sonar rules - There is a lot of examples on the internet, but the best source is the source code of plugins itself. You can get lot of help in SonarQube email groups groups.google.com/forum/#!forum/sonarqube
– Josef Procházka
Nov 22 at 8:59
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
There is a plugin for java properties file https://github.com/racodond/sonar-jproperties-plugin. You can fork it and write your custom rules.
Here is an example rule wich checks for not allowed key and value combination
public class KeyValueCheck extends DoubleDispatchVisitorCheck {
private static final String SIMPLE_IS_PATTERN_TEMPLATE = "(%s)";
protected final Pattern patternKey;
protected final Pattern patternValue;
private final String VIOLATION_MESSAGE;
private final boolean matches;
boolean checkValue = false;
public KeyValueCheck(String key, String value, String message, boolean matches) {
VIOLATION_MESSAGE = message;
this.matches = matches;
this.patternKey = Pattern.compile(String.format(SIMPLE_IS_PATTERN_TEMPLATE, key), Pattern.CASE_INSENSITIVE);
this.patternValue = Pattern.compile(String.format(SIMPLE_IS_PATTERN_TEMPLATE, value), Pattern.CASE_INSENSITIVE);
}
@Override
public void visitKey(KeyTree tree) {
Matcher matcher = patternKey.matcher(tree.text());
if (matcher.matches()) {
checkValue = true;
}
super.visitKey(tree);
}
@Override
public void visitValue(ValueTree tree) {
if (checkValue) {
Matcher matcher = patternValue.matcher(tree.text());
if (matches == patternValue.matcher(tree.text()).matches()) {
addPreciseIssue(tree, VIOLATION_MESSAGE);
}
checkValue = false;
}
super.visitValue(tree);
}
}
There is a plugin for java properties file https://github.com/racodond/sonar-jproperties-plugin. You can fork it and write your custom rules.
Here is an example rule wich checks for not allowed key and value combination
public class KeyValueCheck extends DoubleDispatchVisitorCheck {
private static final String SIMPLE_IS_PATTERN_TEMPLATE = "(%s)";
protected final Pattern patternKey;
protected final Pattern patternValue;
private final String VIOLATION_MESSAGE;
private final boolean matches;
boolean checkValue = false;
public KeyValueCheck(String key, String value, String message, boolean matches) {
VIOLATION_MESSAGE = message;
this.matches = matches;
this.patternKey = Pattern.compile(String.format(SIMPLE_IS_PATTERN_TEMPLATE, key), Pattern.CASE_INSENSITIVE);
this.patternValue = Pattern.compile(String.format(SIMPLE_IS_PATTERN_TEMPLATE, value), Pattern.CASE_INSENSITIVE);
}
@Override
public void visitKey(KeyTree tree) {
Matcher matcher = patternKey.matcher(tree.text());
if (matcher.matches()) {
checkValue = true;
}
super.visitKey(tree);
}
@Override
public void visitValue(ValueTree tree) {
if (checkValue) {
Matcher matcher = patternValue.matcher(tree.text());
if (matches == patternValue.matcher(tree.text()).matches()) {
addPreciseIssue(tree, VIOLATION_MESSAGE);
}
checkValue = false;
}
super.visitValue(tree);
}
}
answered Nov 19 at 14:56
Josef Procházka
9152724
9152724
Thanks, Is there some reference material on how to write custom sonarqube rules.
– sorab
Nov 21 at 14:54
Is sonarqube multi-lingual, can i get the UI in german or french
– sorab
Nov 21 at 14:56
internatinalization github.com/SonarQubeCommunity/sonar-l10n-de
– Josef Procházka
Nov 22 at 8:56
custom sonar rules - There is a lot of examples on the internet, but the best source is the source code of plugins itself. You can get lot of help in SonarQube email groups groups.google.com/forum/#!forum/sonarqube
– Josef Procházka
Nov 22 at 8:59
add a comment |
Thanks, Is there some reference material on how to write custom sonarqube rules.
– sorab
Nov 21 at 14:54
Is sonarqube multi-lingual, can i get the UI in german or french
– sorab
Nov 21 at 14:56
internatinalization github.com/SonarQubeCommunity/sonar-l10n-de
– Josef Procházka
Nov 22 at 8:56
custom sonar rules - There is a lot of examples on the internet, but the best source is the source code of plugins itself. You can get lot of help in SonarQube email groups groups.google.com/forum/#!forum/sonarqube
– Josef Procházka
Nov 22 at 8:59
Thanks, Is there some reference material on how to write custom sonarqube rules.
– sorab
Nov 21 at 14:54
Thanks, Is there some reference material on how to write custom sonarqube rules.
– sorab
Nov 21 at 14:54
Is sonarqube multi-lingual, can i get the UI in german or french
– sorab
Nov 21 at 14:56
Is sonarqube multi-lingual, can i get the UI in german or french
– sorab
Nov 21 at 14:56
internatinalization github.com/SonarQubeCommunity/sonar-l10n-de
– Josef Procházka
Nov 22 at 8:56
internatinalization github.com/SonarQubeCommunity/sonar-l10n-de
– Josef Procházka
Nov 22 at 8:56
custom sonar rules - There is a lot of examples on the internet, but the best source is the source code of plugins itself. You can get lot of help in SonarQube email groups groups.google.com/forum/#!forum/sonarqube
– Josef Procházka
Nov 22 at 8:59
custom sonar rules - There is a lot of examples on the internet, but the best source is the source code of plugins itself. You can get lot of help in SonarQube email groups groups.google.com/forum/#!forum/sonarqube
– Josef Procházka
Nov 22 at 8:59
add a comment |