RSS

Objective-C copy paste detection using Jenkins

17 May

I recently configured a Jenkins job to execute CPD (copy paste detector) using PMD against an iOS project. For those of you who are not familiar with CPD, it is a tool which can analyze a code base to identify large chunks of code that have been duplicated.  CPD is capable of ignoring differences in whitespace and literal values so that you can find similar code and not just identical code.  Because of this, CPD is an invaluable ally in the constant battle against bad coding practices.

CPD supports Java, JSP, C, C++, Fortran and PHP out of the box and can be extended by writing language definitions in Java.  In order to get the best results for iOS projects, I have compiled a simple Objective-C language definition based on an Objective-C JavaCC grammar which was written by a fellow named Mike Hall.

If you would like to setup CPD execution within your Jenkins iOS builds, you will need to first download CPD from this link:  http://sourceforge.net/projects/pmd/files/pmd/4.2.5/

You will also need to download my generated Objective-C CPD language definition from github: https://github.com/jkennedy1980/Objective-C-CPD-Language.  NOTE: It is best to download the entire project as a zip file because I have seen issues when downloading the individual release jars from github.

Once you have all the jars extracted from their zip files, you’ll want to copy the PMD and ObjCLanguage-0.0.7-SNAPSHOT jars to a location on your Jenkins box.  Next, go into your Jenkins build’s configuration and add a new ‘execute shell’ build step.  You’ll need to tailor the actual command to your project, but here is an example of what the command should look like:

java
-Xmx512m
-classpath pmd-4.2.5.jar:ObjCLanguage-0.0.7-SNAPSHOT.jar
net.sourceforge.pmd.cpd.CPD
--minimum-tokens 100
--files [Path to XCode project classes]
--language ObjectiveC
--encoding UTF-8
--format net.sourceforge.pmd.cpd.XMLRenderer > cpd-output.xml

Command Breakdown

  • java – CPD is executed using the java application.  Make sure you Jenkins box has a JRE installed.
  • -Xmx512m - This parameter tells the JRE to allocate 512 Mb of memory for the JVM.  If your project is large and you are getting out of memory or heap errors, you may want to bump this number up.
  • –classpath pmd-4.2.5.jar:ObjCLanguage-0.0.7-SNAPSHOT.jar – This puts the PMD jar and the Objective C language definition onto the JVMs classpath.  The paths to the 2 jars may need to be absolute paths.
  • net.sourceforge.pmd.cpd.CPD — This is the main class (CPD itself) that is executed from inside the PMD jar by the java executable.
  • –minimum-tokens 100 – Configures the minimum size for blocks considered to be duplicate
  • –files [path] – This parameter tells CPD which files should be scanned for copy paste violations.  You can provide more than one –files parameter if needed.
  • –language ObjectiveC – This tells CPD to load my custom Objective-C language definition.
  • –encoding UTF-8 – This allows you to specify which encoding you would like to use.  [optional]
  • –format net.sourceforge.pmd.cpd.XMLRenderer – This tells CPD that you would like to output the results as XML.  You will need to use XML if you want to publish the results within Jenkins using the plugins mentioned below.
  • > cpd-output.xml – This takes all the XML output by CPD and writes it into a file named cpd-output.xml.  You can name the output file whatever you want.

Jenkins Plugins

Once you have tailored the command above, you can install the Violations or the DRY plugin from the Jenkins update center.  I used the Violations plugin which allows you to configure limits that define when the build should be unstable or cloudy within each job’s configuration.  You’ll need to be sure that you setup the Violations or DRY plugin’s configuration values so that they can find the output CPD XML file.

Once you have configured everything properly, you should see a Violations section within your job that lets you browse the duplicated code blocks that were found within your code base.

I hope you find this post helpful and that CPD helps you remove all your duplication…or your co-workers’ duplication :)

Troubleshooting

If you are receiving parsing errors in your output, you can now( as of version 0.0.5) add ‘-DObjC-CPD-LoggingEnabled=YES’ after java in the CPD command to enable some additional logging.  The new logging will print out each file’s name as they are processed and show files names when parsing exceptions are generated.   If you are redirecting the output to an XML file as I have shown in this post, you will have to open the XML file to see the logging output.  Here is an example with logging enabled:

java
-DObjC-CPD-LoggingEnabled=YES
-Xmx512m
-classpath pmd-4.2.5.jar:ObjCLanguage-0.0.7-SNAPSHOT.jar
net.sourceforge.pmd.cpd.CPD
--minimum-tokens 100
--files [Path to XCode project classes]
--language ObjectiveC
--encoding UTF-8
--format net.sourceforge.pmd.cpd.XMLRenderer > cpd-output.xml

WARNING: by enabling logging the XML output will be invalid. Logging should only enabled to assist in troubleshooting.

About these ads
 
47 Comments

Posted by on May 17, 2011 in Uncategorized

 

47 responses to “Objective-C copy paste detection using Jenkins

  1. Nikita Zhuk

    May 18, 2011 at 12:25 am

    Looks very interesting. There is a little bug in the tokenizer, though.

    If the input contains ObjC code like this:


    [NSString stringWithFormat:@"%.0f\xC2\xB0", someValue];

    Then CPD throws the following exception:

    com.deadmeta4.cpd.generated.TokenMgrError: Lexical error at line 438, column 84.  Encountered: "x" (120), after : "@\"%.0f\\"
    	at com.deadmeta4.cpd.generated.ObjCParserTokenManager.getNextToken(ObjCParserTokenManager.java:6153)
    	at com.deadmeta4.cpd.generated.ObjCParser.getNextToken(ObjCParser.java:7717)
    	at net.sourceforge.pmd.cpd.ObjectivecTokenizer.tokenize(ObjectivecTokenizer.java:31)
    	at net.sourceforge.pmd.cpd.CPD.add(CPD.java:106)
    	at net.sourceforge.pmd.cpd.CPD.add(CPD.java:72)
    	at net.sourceforge.pmd.cpd.CPD.addDirectory(CPD.java:82)
    	at net.sourceforge.pmd.cpd.CPD.addRecursively(CPD.java:67)
    	at net.sourceforge.pmd.cpd.CPD.main(CPD.java:180)
    

     
    • jkennedy1980

      May 18, 2011 at 12:40 am

      Hmmm…I’ll take a look at this. Did you still get CPD results?

       
      • Nikita Zhuk

        May 18, 2011 at 12:54 am

        Yup, I did (although not for that file with \x in format string.

         
  2. Nikita Zhuk

    May 18, 2011 at 12:53 am

    Running the CPD as an Ant task instead of from the command line allows for more versatile source file inclusion / exclusion and may be also more appropriate for some build setups.

    CPD Ant task hardcodes the supported languages so adding support for ObjectiveC requires a minor addition to the CPDTask.java (line 188):

    private static final String[] LANGUAGES = new String[]{“java”,”jsp”,”cpp”, “c”,”php”, “ruby”, “fortran”, “ObjectiveC”};

    After this code tweak (and recompiling the pmd-4.2.5.jar by running “ant jar” in PMD source directory root) you can use the following Ant build.xml file to run the duplicate detection: http://pastebin.com/np7d5G2r

    Running the ant task from command line:


    CLASSPATH="ObjCLanguage-0.0.1-SNAPSHOT.jar:pmd-4.2.5.jar" ant cpd

     
  3. nzhuk2

    May 18, 2011 at 4:20 am

    As for Jenkins plugins, I tried Violations plugin but it displayed only “duplicate tokens” report, which visualized single duplicated lines instead of duplicated blocks of lines.

    DRY plugin seems to do the right thing – displaying duplicated blocks of subsequent code lines over several source files.

     
  4. jkennedy1980

    May 18, 2011 at 7:15 am

    Awesome. I like this comment from the CPDTask source:


    /*
    FIXME Can't we do something cleaner and more dynamic ? Maybe externalise to a properties files that will be generated when building pmd ? This will not have to add manually new language here ?
    */

    If I have time I may see about fixing this in CPDTask.

    Good info on the DRY plugin…I’ll give it a try at work today. Thanks :)

     
  5. vincent daubry

    June 21, 2011 at 12:39 pm

    Very Interesting ! But i was unable to get the CPD report to work, i get an empty xml output.

    Here is the Jenkins logs :

    java -Xmx512m -classpath /Users/barbu/.hudson/plugins/CPD/pmd-4.2.5.jar:ObjCLanguage-0.0.1-SNAPSHOT.jar net.sourceforge.pmd.cpd.CPD –minimum-tokens 100 –files ‘/Users/barbu/Documents/Projets/Formations Mobiles/Training/Formation/Training’ –language ObjectiveC –encoding UTF-8 –format net.sourceforge.pmd.cpd.XMLRenderer
    Finished: SUCCESS

    The cpd-output.xml file is created but it only contains :

    Do you know what can be wrong ?

    P.S: Tried to put the minimum token at 1 but i got the same result

    Thanks,
    Vincent

     
    • jkennedy1980

      June 21, 2011 at 1:35 pm

      Hmm. Can you try adding a ‘-v’ to your command? This will generate additional output to the console. Make sure you see your files being reported in the output. You can also try taking off the ‘-format net.sourceforge.pmd.cpd.XMLRenderer’ and CPD should output the results to the console output. Otherwise…i guess your project is copy/paste free :)

       
  6. vincent daubry

    June 21, 2011 at 12:41 pm

    Sorry it seems XML is not working so weel in comments and not possible to edit… The content of the XML is :

    “”

     
    • Waseem

      April 19, 2012 at 3:18 pm

      Vincent,
      Did you get it working by any chance?
      I’m getting an empty output xml too.

      Thanks,
      –Waseem

       
  7. gurgeli

    September 9, 2011 at 6:47 am

    Hey there

    I get the command to complete but the xml file does not contain any violations:

    This is my command:

    java \
    -Xmx512m \
    -classpath ~/Desktop/pmd/pmd-4.2.5.jar:~/Desktop/pmd/ObjCLanguage-0.0.1-SNAPSHOT.jar \
    net.sourceforge.pmd.cpd.CPD \
    –minimum-tokens 10 \
    –files ~/MyApp/Classes \
    –language ObjectiveC \
    –encoding UTF-8 \
    –format net.sourceforge.pmd.cpd.XMLRenderer

    I think at a minimum-tokens of 10 should work to get some results…

    Do you have any idea how to fix / debug this?

     
  8. Roger Moffatt (@rogermoffatt)

    September 16, 2011 at 9:50 am

    Great find (and work on the language descriptor files)! I’ve just come in to a new project and am looking at some refactoring and code cleaning … I was able to install pmd and the language file first time and within a few minutes I now have a nice (and large!) xml report highlighting stuff it would have taken me days to find. This really should be part of any large project workflow and thanks again for writing about it.

     
    • jkennedy1980

      September 16, 2011 at 11:40 am

      Thank you very much for the kind words.

       
  9. gurgeli

    September 16, 2011 at 10:28 am

    I tried it with another project’s code base and got the following Exception.

    Any ideas how I can tackle this?

    com.deadmeta4.cpd.generated.TokenMgrError: Lexical error at line 148, column 67. Encountered: ” ” (32), after : “@”
    at com.deadmeta4.cpd.generated.ObjCParserTokenManager.getNextToken(ObjCParserTokenManager.java:6153)
    at com.deadmeta4.cpd.generated.ObjCParser.getNextToken(ObjCParser.java:7717)
    at net.sourceforge.pmd.cpd.ObjectivecTokenizer.tokenize(ObjectivecTokenizer.java:31)
    at net.sourceforge.pmd.cpd.CPD.add(CPD.java:106)
    at net.sourceforge.pmd.cpd.CPD.add(CPD.java:72)
    at net.sourceforge.pmd.cpd.CPD.addDirectory(CPD.java:82)
    at net.sourceforge.pmd.cpd.CPD.addRecursively(CPD.java:67)
    at net.sourceforge.pmd.cpd.CPD.main(CPD.java:180)

    Best regards

     
    • jkennedy1980

      September 16, 2011 at 11:35 am

      I have seen this before when I was developing the language definition. Can you reply with the few lines of code around the position mentioned: “Lexical error at line 148, column 67. Encountered: ” ” (32), after : “@””?

      The way that the error reads it sounds like there is a space directly after an @ which is tripping up the syntax tokenizer. If that is the case you could try removing the space.

       
      • Beat

        September 17, 2011 at 5:54 am

        But if I do something like this in my source file then it has obviously the string ‘@ ‘ which leads to the error.

        NSLog(@”Distance: %@ meters”, distance);

        Is there a way I can figure out which file leads to the problem?

         
      • jkennedy1980

        September 17, 2011 at 11:25 am

        I have tons of code with NSLog statements just like your example and CPD works fine. I am trying to determine if there is something special about the statement at line148 column 67. If I can figure out why it is complaining I can modify the grammar file to fix the problem.

         
      • jkennedy1980

        October 5, 2011 at 9:41 am

        If you add a -v to the command, CPD will output each filename as it crawls through the source. Then you should be able to see the exact line and character causing the problem. More than likely the objective-c grammar file needs updated. I just need to know how to reproduce this so I can test it myself.

         
  10. kenji21

    October 4, 2011 at 3:40 pm

    Hi,

    Got an issue, the cpd.xml file that has first line :
    And in the slave.log :
    org.xml.sax.SAXParseException: Invalid encoding name “MacRoman”.

    Maybe my env is misconfigured, but env returns : LANG=fr_FR.UTF-8

     
  11. kenji21

    October 4, 2011 at 3:43 pm

    By setting LANG=UTF-8 the generated first line is correct :

     
    • jkennedy1980

      October 5, 2011 at 9:37 am

      Is it working for you now? I recently had to solve this issue too. Thanks for the posts :)

       
      • kenji21

        October 5, 2011 at 9:39 am

        It works from my shell, but when jenkins do the job, I have to make an ugly change :

        sed -i .bak ‘s/MacRoman/UTF-8/’ $OUTFILE

         
  12. fly2never

    January 7, 2012 at 7:33 am

    another useful tool is simian(http://www.harukizaemon.com/simian/index.html)
    works fine with obj-c :)

     
  13. jkennedy1980

    February 11, 2012 at 1:52 pm

    Just released version 0.2. Thanks to github user SevInf(https://github.com/SevInf) for tidying up the pom.xml and adding support for the @autoreleasepool token.

     
  14. dpk

    July 15, 2012 at 1:39 pm

    New to Jenkins here, trying to follow this step:

    “You’ll need to be sure that you setup the Violations or DRY plugin’s configuration values so that they can find the output CPD XML file.”

    but I can’t find the Violations or DRY (or any) plugin configuration. I’ve checked the “Plugin Manager” and just about all the links under “Manage Jenkins”, to no avail. Searched the google, too. This page says to “activate the static code analyzers”:

    https://wiki.jenkins-ci.org/display/JENKINS/Violations

    but there’s no such option in the build.

    I am able to get the CPD XML file output, FWIW, so I think I’m just failing at Jenkins itself.

     
  15. feces

    July 15, 2012 at 1:46 pm

    You can delete my previous comment (if you want). I found it by searching the HTML source for the project configuration page, heh.

    FWIW, to configure Violations, you have to add a “Post-Build action” called “Report Violations”.

     
  16. huanling

    July 26, 2012 at 10:32 pm

    hi,jkennedy1980 :

    I use the following command to scan iPhone project classes:
    java -Xmx512m -classpath /data/ssa/pmd/lib/pmd-4.2.5.jar:/data/ssa/pmd/lib/ObjCLanguage-0.0.1-SNAPSHOT.jar net.sourceforge.pmd.cpd.CPD –minimum-tokens 10 –files $WORKSPACE/Classes/ –language ObjectiveC –encoding GB2312 -v –format net.sourceforge.pmd.cpd.XMLRenderer > cpd-output.xml

    then i get some errors like these:
    com.deadmeta4.cpd.generated.TokenMgrError: Lexical error at line 1, column 1. Encountered: “\u9518″ (38168), after : “”
    at com.deadmeta4.cpd.generated.ObjCParserTokenManager.getNextToken(ObjCParserTokenManager.java:6153)
    at com.deadmeta4.cpd.generated.ObjCParser.getNextToken(ObjCParser.java:7717)
    at net.sourceforge.pmd.cpd.ObjectivecTokenizer.tokenize(ObjectivecTokenizer.java:28)
    at net.sourceforge.pmd.cpd.CPD.add(CPD.java:106)
    at net.sourceforge.pmd.cpd.CPD.add(CPD.java:72)
    at net.sourceforge.pmd.cpd.CPD.addDirectory(CPD.java:82)
    at net.sourceforge.pmd.cpd.CPD.addRecursively(CPD.java:67)
    at net.sourceforge.pmd.cpd.CPD.main(CPD.java:180)
    com.deadmeta4.cpd.generated.TokenMgrError: Lexical error at line 226, column 56. Encountered: “\n” (10), after : “@\”\ufffd\ufffd\ufffd\u7ec0\u54c4\ufffd\ufffd\ufffd; ”
    at com.deadmeta4.cpd.generated.ObjCParserTokenManager.getNextToken(ObjCParserTokenManager.java:6153)
    at com.deadmeta4.cpd.generated.ObjCParser.getNextToken(ObjCParser.java:7717)
    at net.sourceforge.pmd.cpd.ObjectivecTokenizer.tokenize(ObjectivecTokenizer.java:31)
    at net.sourceforge.pmd.cpd.CPD.add(CPD.java:106)
    at net.sourceforge.pmd.cpd.CPD.add(CPD.java:72)
    at net.sourceforge.pmd.cpd.CPD.addDirectory(CPD.java:82)
    at net.sourceforge.pmd.cpd.CPD.addRecursively(CPD.java:67)
    at net.sourceforge.pmd.cpd.CPD.main(CPD.java:180)

    can you tell me how to fix it ?

    thanks a lot.

     
    • jkennedy1980

      August 8, 2012 at 10:53 am

      This looks like an issue in the Objective-C Language grammar. It looks like you have a file with some unicode characters in it (\u9518,\ufffd). If you send me a sample of the code containing these characters I may be able to modify the CPD grammar to accept these files.

       
      • huanling

        September 9, 2012 at 9:53 am

        hi,jkennedy1980 :
        Can you tell me your e-mail address,so i can send you some sample of the code
        these characters (\u9518,\ufffd).

         
  17. Cyril

    August 28, 2012 at 8:30 am

    @vincent daubry, @Waseem, @jkennedy1980,

    I had the same issue as you, I think. My solution was to give an absolute path to the different JARs in the class path.

    I explained this (and more) in this blog post: http://blog.octo.com/en/jenkins-quality-dashboard-ios-development/#step1-2

    Notice that I didn’t find the way to exclude particular directories (like for example third-party librairies), do you know how to do this?

     
    • jkennedy1980

      August 28, 2012 at 11:03 am

      I have had many people ask me about folder level exclusions but have not found a way to do it with PMD/CPD alone. I believe a custom tool would have to be written or CPD would have to be modified.

       
  18. Anonymous

    September 5, 2012 at 7:49 am

    Hi,

    This is my command:

    java -Xmx512m -classpath /Users/kishoren1/Desktop/UnitTest/pmd-bin-5.0.0/lib/pmd-5.0.0.jar:/Users/kishoren1/Desktop/UnitTest/CopyPasteDetection/ObjCLanguage-0.0.6-SNAPSHOT.jar net.sourceforge.pmd.cpd.CPD –minimum-tokens 100 –language ObjectiveC –encoding UTF-8 –format net.sourceforge.pmd.cpd.XMLRenderer –files /Users/kishoren1/Desktop/UnitTest/UnitTestSampleWithCodeCoverage –files $/Users/kishoren1/Desktop/UnitTest/UnitTestSampleWithCodeCoverage > /Users/kishoren1/Desktop/UnitTest/cpd-output.xml

    and i am getting an error message like this:
    Exception in thread “main” java.lang.NoClassDefFoundError: net/sourceforge/pmd/cpd/CPD
    Caused by: java.lang.ClassNotFoundException: net.sourceforge.pmd.cpd.CPD
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)

    could you please help?

    Thanks.

     
  19. jkennedy1980

    September 5, 2012 at 12:19 pm

    This has to be a classpath issue. Make sure the paths you are passing into the -classpath argument are valid. Check things like case sensitivity.

     
    • jkennedy1980

      September 5, 2012 at 12:21 pm

      This has to be a classpath issue. Make sure the paths you are passing into the -classpath argument are valid. Check things like case sensitivity. I just noticed you are using PMD 5.0. Maybe they have changed something. Try using PMD 4.x and see if you have any luck.

       
      • huanling

        September 10, 2012 at 8:08 pm

        Can you tell me your e-mail address?
        so i can send you some sample of the code
        these characters (\u9518,\ufffd).

         
      • Anonymous

        September 11, 2012 at 4:48 am

        I tried PMD 4.2.5 and it is working now. Thanks for your inputs

         
  20. LiohAu

    September 27, 2012 at 11:35 am

    Hi, i’m trying to follow your guide and Cyril’s one, and i’m getting the following error, any idea? :

    [DRY] Collecting duplicate code analysis files…
    [DRY] Finding all files that match the pattern build/cpd-output.xml
    [DRY] Parsing 1 files in /Users/X/Desktop/workspace/Y
    [DRY] Parsing of file /Users/X/Desktop/workspace/Y/build/cpd-output.xml failed due to an exception:

    java.io.IOException: No parser found for duplicated code results file /Users/X/Desktop/workspace/Y/build/cpd-output.xml
    at hudson.plugins.dry.parser.DuplicationParserRegistry.parse(DuplicationParserRegistry.java:93)
    at hudson.plugins.analysis.core.FilesParser.parseFile(FilesParser.java:261)
    at hudson.plugins.analysis.core.FilesParser.parseFiles(FilesParser.java:220)
    at hudson.plugins.analysis.core.FilesParser.invoke(FilesParser.java:169)
    at hudson.plugins.analysis.core.FilesParser.invoke(FilesParser.java:31)
    at hudson.FilePath$FileCallableWrapper.call(FilePath.java:2099)
    at hudson.remoting.UserRequest.perform(UserRequest.java:118)
    at hudson.remoting.UserRequest.perform(UserRequest.java:48)
    at hudson.remoting.Request$2.run(Request.java:287)
    at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:72)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:680)

    PS : the cpd-output.xml seems to be a correct (i just used my eyes ^^), but the first line is : “”, even if i’m using “–encoding UTF-8″ (i tried, utf8, utf-8, UTF8, UTF-8, –encoding, -encoding etc… :)). I also tried to replace the MacRoman by UTF-8 with a sed, and it does not change anything.

     
    • jkennedy1980

      September 27, 2012 at 11:45 am

      Are you sure that /Users/X/Desktop/workspace/Y/build/cpd-output.xml is the exact location of the output file? If it is, try the Violations plugin to see if it fails the same way.

       
      • LiohAu

        September 28, 2012 at 3:35 am

        Yes, it is, i will test with Violations.

         
  21. LiohAu

    September 28, 2012 at 4:11 am

    It finally with Violations and this command (added an iconv in case of + sed for the encoding name) :

    java -Xmx512m -classpath ${WORKSPACE}/../PMD/pmd-4.2.5/lib/pmd-4.2.5.jar:${WORKSPACE}/../PMD/Objective-C/releases/ObjCLanguage-0.0.7-SNAPSHOT.jar net.sourceforge.pmd.cpd.CPD –minimum-tokens 100 –language ObjectiveC –encoding UTF-8 –format net.sourceforge.pmd.cpd.XMLRenderer –files ${WORKSPACE}/${JOB_NAME} | iconv -f macRoman -t utf-8 | sed ‘s/MacRoman/UTF-8/g’ > build/cpd-output.xml

     
  22. rover

    February 5, 2013 at 1:29 pm

    I just cannot get this to show me the violations . I gave the full path for the jar files in my class path but fail to get any violations . It just gives me an empty xml every time . Its a really cool tool and can help us notify some violations
    java -Xmx512m -classpath /Users/n/PMD/pmd-4.2.5/lib/pmd-4.2.5.jar:/Users/n/PMD/ObjCLanguage-0.0.7-SNAPSHOT.jar net.sourceforge.pmd.cpd.CPD –minimum-tokens 100 –language ObjectiveC –encoding UTF-8 –format net.sourceforge.pmd.cpd.XMLRenderer –files GSolution

    All i get is an empty xml

     
  23. Nicolas

    March 19, 2013 at 12:01 pm

    Tried to manage PMD with Jenkins but still don’t work.
    Here is my command (tried in console too without much success)

    java -Xmx512m -classpath /Users/Shared/Jenkins/PMD/pmd-bin-5.0.2/lib/pmd-5.0.2.jar:/Users/Shared/Jenkins/PMD/ObjCLanguage-0.0.7-SNAPSHOT.jar net.sourceforge.pmd.cpd.CPD –minimum-tokens 100 –language ObjectiveC –encoding UTF-8 –format net.sourceforge.pmd.cpd.XMLRenderer –files TestJenkinsApp > build/cpd-output.xml

    No matter what parameters I tried, my build/cpd-output.xml file is always empty.

    Any ideas ?

    Thanks

     
  24. Thomas

    March 20, 2013 at 5:00 am

    Nice tutorial, I was trying it since yesterday evening but without success, I didn’t have any result even an empty xml. The thing is I installed the last version of pmd the 5.0.2. When trying with the one in this tutorial the 4.2.5. But still now the xml report is generated but there are no results in it:

     
  25. bkaur

    March 22, 2013 at 12:57 pm

    hi Joshua,

    I am trying to use your code with Jenkin. The cpd-output files is being created.However it starts with these lines:
    CPD Processing: /Users/testUser/Documents/tmp/iPad-2013.02.0/testFiles.h

    And i see a warning in the Jenkins dashboard:
    Module : Parsing of file /Users/zkmrwqd/.jenkins/jobs/BOFAMobileiPad/workspace/pmd/cpd-output.xml failed due to an exception: java.io.IOException: No parser found for duplicated code results file /Users/zkmrwqd/.jenkins/jobs/BOFAMobileiPad/workspace/pmd/cpd-output.xml at hudson.plugins.dry.parser.DuplicationParserRegistry.parse(DuplicationParserRegistry.java:102) at hudson.plugins.analysis.core.FilesParser.parseFile(FilesParser.java:306) at hudson.plugins.analysis.core.FilesParser.parseFiles(FilesParser.java:264) at hudson.plugins.analysis.core.FilesParser.parserCollectionOfFiles(FilesParser.java:215) at hudson.plugins.analysis.core.FilesParser.invoke(FilesParser.java:184) at hudson.plugins.analysis.core.FilesParser.invoke(FilesParser.java:31) at hudson.FilePath.act(FilePath.java:852) at hudson.FilePath.act(FilePath.java:834) at hudson.plugins.dry.DryPublisher.perform(DryPublisher.java:175) at hudson.plugins.analysis.core.HealthAwarePublisher.perform(HealthAwarePublisher.java:146) at hudson.plugins.analysis.core.HealthAwareRecorder.perform(HealthAwareRecorder.java:331) at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:19) at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:718) at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:693) at hudson.model.Build$BuildExecution.post2(Build.java:183) at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:640) at hudson.model.Run.execute(Run.java:1527) at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46) at hudson.model.ResourceController.execute(ResourceController.java:88) at hudson.model.Executor.run(Executor.java:237)

    can you please help.

     
  26. bkaur

    March 22, 2013 at 1:07 pm

    Never mind. It worked :) I was using the -DObjC-CPD-LoggingEnabled=YES flag in the command.

     
  27. Nestor

    June 5, 2013 at 1:02 pm

    Quick comment. It generates an empty result file with the latest PMD bin (5.0.4 now) but I made it work just using the version 4.2.5

     

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.

%d bloggers like this: