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.










share|improve this 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.

















    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.










    share|improve this 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.















      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.










      share|improve this question













      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      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.
























          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);
          }
          }





          share|improve this answer





















          • 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


















          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);
          }
          }





          share|improve this answer





















          • 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















          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);
          }
          }





          share|improve this answer





















          • 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













          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);
          }
          }





          share|improve this answer












          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);
          }
          }






          share|improve this answer












          share|improve this answer



          share|improve this answer










          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


















          • 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



          Popular posts from this blog

          404 Error Contact Form 7 ajax form submitting

          How to know if a Active Directory user can login interactively

          TypeError: fit_transform() missing 1 required positional argument: 'X'