PMD scan fails

PMD
  • Please log in to reply

#1
windows version welkinsuite

martin.vanputten

    Posted 22 Nov 2017 and edited 13 Dec 2017

    Trying to run a PMD scan. I have configured a ruleset using the Welkin Suite template and turned everything on. Went into the project properites and set the appropriate configuration file and enabled PMD by setting to true.

    When selecting "Scan with PMD" from either the project or a single file no results are displayed and the bottom left says "PMD scan fails".

    Is there something I've missed while setting this up. I don't have any files in the included files but to be honest there are a hundred files and I'm assuming if left blank it just adds all of them. I'll keep testing that though for now.



    14 replies to this topic

    #2

    martin.vanputten

      Posted 22 Nov 2017

      If setting a file in the Included files section under resulet configuration, saving... and then loading the same configuration the newly added file is now in the excluded files list.



      #3

      martin.vanputten

        Posted 22 Nov 2017

        OK, so manually editing the xml file and replacing exclude with include puts it in the right section but then after loading the configuration and then resaving it puts it back to exclude... so the IDE currently does not allow including files.



        #4

        vlgubanovich

          Posted 22 Nov 2017

          Hi Martin,

          Regarding includes and excludes in the PMD ruleset - you don't need to do this for IDE to work correctly with PMD. You can leave them blank (and I'd ask you to leave them blank while testing the steps below). If executing PMD manually from the Solution Explorer - it scans only selected folder/files. If you setup the IDE to execute PMD before build - it scans only changed files. However, includes and excludes gives you more options to fine-tune the scanning behavior and as far as I understand it's expected to have regular expressions there, but I might be wrong as for our cases we don't use such options :)


          Regarding the failed PMD scan I'd kindly ask you to check if you could run PMD outside the IDE. You can use the next steps for this:
          - open the next folder: C:\Program Files (x86)\The Welkin Suite\The Welkin Suite\PMD\BIN - here PMD binaries are located;
          - in the text box where you can see the path to the folder (in the Windows Explorer itself), please enter 'cmd' and click Enter;
          - after this, please run the next command: pmd -d [Full path yo the files which you want to scan] -f xml -R [Full path to your ruleset].
          Please let me know what would be the result. If you would have any error, please share them with us.

          Also, may I please clarify with you what version of Java do you have?
          We have been faced with the similar issue working with Java version 9, and this is related to PMS sources - they cannot be launched even outside of the IDE.
          If you have the version 9 of Java, you can downgrade it and check if the issue would be reproduced. Of course, if the downgrade is acceptable for you. Otherwise we'll update the bundled PMD version to 6.0 once it's released and we hope this issue will be resolved there.


          Hope this helps and you'll enjoy automated PMD reports in your IDE :)


          Thank you,

          Vladimir


          Vladimir Gubanovich
          Head of Product
           
          The Welkin Suite
          skype id: vladimir.gubanovich
          e-mail: vladimir.gubanovich@welkinsuite.com


          #5

          martin.vanputten

            Posted 23 Nov 2017

            I did have version 9 installed. So what I did was installed 8 as well so that both versions exist and then modified the batch file to point to version 8. I now get get an error when running via command prompt "Could not find or load main class Files" but the path is definitelly correct, even tabbed directories in cmd to verify it finds it for me. What would that error point to as there is no traditional main class file. I also tried a single file via command prompt as well as the entire src/classes directory.



            #6

            martin.vanputten

              Posted 24 Nov 2017

              I've realized the the error message seems to be because of how java is being called in the batch file... I'll try to change it it a bit but essentially the way its calling is expecting a java class file which is not intended.



              #7

              martin.vanputten

                Posted 24 Nov 2017

                Follow up, I believe the classpath error is being returned after searching inside the lib folder containing the jar files.



                #8

                martin.vanputten

                  Posted 27 Nov 2017

                  Bypassed the batch file and manually typed everything in cmd, this appears to work... validation returned on every file in the src folder. This is using java version 8.



                  #9

                  martin.vanputten

                    Posted 27 Nov 2017

                    Batch file now working 100%... issue was with spaces within path variables.

                    Heres the script:


                    @echo off
                    set MAIN_CLASS=net.sourceforge.pmd.PMD
                    set CLASSPATH=-classpath ..\lib\* %MAIN_CLASS%
                    set RULES="C:\Users\thisguy\Documents\The Welkin Suite\Projects\The company\Full Ruleset.xml"
                    set DIRECTORY="C:\Users\thisguy\Documents\The Welkin Suite\Projects\The company\Dev Salesforce\src"
                    set JAVA8="C:\Program Files (x86)\Java\jre1.8.0_151\bin\java.exe"

                    %JAVA8% %CLASSPATH% -R %RULES% -d %DIRECTORY%


                    #10

                    martin.vanputten

                      Posted 27 Nov 2017

                      Ok, as it stands... running the batch file inside command prompt works... however the response is not usable unless organized. Running this from within the IDE is a no go. It will run... and it will fail. After 15 minutes from doing a build it came back with error after error, nothing related to a the ruleset. Running it on a file doesn't return an error but just says it failed. When it does run during a build... the IDE used 25% of the cpu and memory sky rocketed.



                      #11

                      vlgubanovich

                        Posted 28 Nov 2017

                        Hi Martin,


                        Thank you for so much details about your investigation :)

                        It's still not exactly clear what (or I'd say "why") happens when you try to execute PMD from The Welkin Suite.

                        If I understand correctly - for your batch file testing you've created your own .bat file? In case if this is true - can you open The Welkin Suite's installation folder, navigate to the PMD\bin folder there and modify the pmd.bat file in the following way:

                        @echo off
                        set TOPDIR=%~dp0..
                        set OPTS=
                        set MAIN_CLASS=net.sourceforge.pmd.PMD
                        
                        set JAVA8="C:\Program Files (x86)\Java\jre1.8.0_151\bin\java.exe"
                        
                        %JAVA8% -classpath "%TOPDIR%\lib\*" %OPTS% %MAIN_CLASS% %*
                        

                        In this way you'll just point it to run using the Java8, while the arguments structure will remain the same (as the IDE itself passes directory/file and ruleset).

                        I believe this should work for you, but in case if no please let me know what will happen in this case as wel.


                        Thank you for your patience and very active cooperation :)


                        Best regards,
                        Vladimir


                        Vladimir Gubanovich
                        Head of Product
                         
                        The Welkin Suite
                        skype id: vladimir.gubanovich
                        e-mail: vladimir.gubanovich@welkinsuite.com


                        #12

                        martin.vanputten

                          Posted 28 Nov 2017

                          Thank you so much! The PMD Report displays results now. Thanks again. Its finding soooo many issues with the apex code... this is wonderful!



                          #13

                          vlgubanovich

                            Posted 28 Nov 2017

                            Hi Martin,


                            Phew, I'm so happy that it is finally working for you! I believe that 95% of the issue resolution was your investigation, so thank you for it :)

                            Regarding the PMD itself - my general recommendation is go further (to the bright future of the absolutely clean code) slowly - setup priority threshold in the IDE to first highlight as errors only most critical ones for you (as you define priorities in the ruleset), so you won't scare yourself each time with the number of issues. Once you're happy with your codebase without critical issues - lower the threshold and start slowly changing the less critical items.

                            This way you can work on your codebase (almost) painless, while still increasing the code quality and resolving potential issues. With some time spent on the right priorities in the PMD ruleset and ont he right threshold we even managed to enable pre-build PMD scan for very old legacy project with not very significant performance drop of the team (measuered in the "time/feature") :)


                            Thank you once more for all your investigations on this case.


                            Best regards,

                            Vladimir


                            Vladimir Gubanovich
                            Head of Product
                             
                            The Welkin Suite
                            skype id: vladimir.gubanovich
                            e-mail: vladimir.gubanovich@welkinsuite.com


                            #14

                            tadeuszhyzy

                              Posted 11 Dec 2017

                              Hi there!

                              I also have problem with PMD inside Welking Suite. This is not related to PMD or Java version. I got problem wth access to cache file. Any suggestions? :)

                              PMD is working with Ant so it's not related to PMD or any issue above.

                              Error	1	gru 11, 2017 2:13:15 PM net.sourceforge.pmd.cache.FileAnalysisCache loadFromFile
                              SEVERE: Could not load analysis cache to file. C:\ProgramData\TheWelkinSuite (Odmowa dost?pu)
                              gru 11, 2017 2:13:15 PM net.sourceforge.pmd.cache.AbstractAnalysisCache checkValidity
                              INFO: Analysis cache invalidated, rulesets changed.
                              gru 11, 2017 2:13:15 PM apex.jorje.parser.impl.BaseApexLexer dedupe
                              INFO: Deduped array ApexLexer.DFA22_transition. Found 7403062 shorts which is 14MB not including array overhead. Removed 6746470 shorts which is 12MB not counting array overhead.Took 8ms.
                              Exception in thread "main" java.lang.IllegalAccessError: tried to access method apex.jorje.semantic.exception.Errors.<init>()V from class net.sourceforge.pmd.lang.apex.ast.ApexTreeBuilder
                              	at net.sourceforge.pmd.lang.apex.ast.ApexTreeBuilder.<init>(ApexTreeBuilder.java:208)
                              	at net.sourceforge.pmd.lang.apex.ast.ApexParser.parse(ApexParser.java:52)
                              	at net.sourceforge.pmd.lang.apex.ApexParser.parse(ApexParser.java:37)
                              	at net.sourceforge.pmd.SourceCodeProcessor.parse(SourceCodeProcessor.java:113)
                              	at net.sourceforge.pmd.SourceCodeProcessor.processSource(SourceCodeProcessor.java:163)
                              	at net.sourceforge.pmd.SourceCodeProcessor.processSourceCode(SourceCodeProcessor.java:97)
                              	at net.sourceforge.pmd.SourceCodeProcessor.processSourceCode(SourceCodeProcessor.java:52)
                              	at net.sourceforge.pmd.processor.PmdRunnable.call(PmdRunnable.java:88)
                              	at net.sourceforge.pmd.processor.PmdRunnable.call(PmdRunnable.java:27)
                              	at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
                              	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
                              	at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
                              	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
                              	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
                              	at java.base/java.lang.Thread.run(Unknown Source)
                              
                              Please check the global PMD settings		1	1	
                              

                              Tadeusz Hyży <tadeuszhyzy@gmail.com>

                              Salesforce Solution Architect

                              tadeuszhyzy.pl


                              #15

                              kate.dulko

                                Posted 13 Dec 2017

                                Hi Tadeusz,


                                Thank you for this post and for creating the separate topic since this is another issue related to PMD.

                                I'll continue discussing this with you on that topic.


                                Regards,

                                Kate


                                Kate Dulko
                                Customer Relations

                                The Welkin Suite

                                twitter: @KateDulko
                                skype id: d_katerina
                                e-mail: kate.dulko@welkinsuite.com

                                 

                                  





                                Boost Your Productivity. Get Started Today

                                Try Free Trial