Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-4836

SLOCCount plugin fails with Windows/Cygwin SLOCCount execution

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Critical
    • Resolution: Fixed
    • Component/s: sloccount-plugin
    • Labels:
      None
    • Environment:
      Platform: All, OS: Windows XP
    • Similar Issues:

      Description

      In our setup we have a master Hudson machine running on Linux with one slave
      macine running Windows XP. This last machine is responsible for any
      Windows-specific builds in our environment. To have some metrics, we make use of
      SLOCCount both for the Linux and Windows projects, the SLOCCount plugin works
      perfect for our Linux projects but fails to work on the Windows ones.

      On Windows SLOCCount itself has to be executed from CygWin (Linux Emulation)
      which works without problems and gives the proper output format. An extract of
      this file is as follows:

      Have a non-directory at the top, so creating directory top_dir
      Adding /cygdrive/h/###_Hudson/workspace/IvAp_v1.x/ivap/src/BetaUpdate.exe to
      top_dir
      Creating filelist for Config
      Creating filelist for FsInt
      Adding /cygdrive/h/###_Hudson/workspace/IvAp_v1.x/ivap/src/IvAp.sln to top_dir
      Adding /cygdrive/h/###_Hudson/workspace/IvAp_v1.x/ivap/src/IvAp.svnprops to
      top_dir
      Creating filelist for IvapMsgLib
      Creating filelist for NetInt
      Adding /cygdrive/h/###_Hudson/workspace/IvAp_v1.x/ivap/src/ResourceMerge.exe
      to top_dir
      Creating filelist for UsrHost
      Creating filelist for UsrInt
      Adding /cygdrive/h/###_Hudson/workspace/IvAp_v1.x/ivap/src/cppcheck.txt to top_dir
      Adding /cygdrive/h/###_Hudson/workspace/IvAp_v1.x/ivap/src/cppcheck.xml to top_dir
      Adding /cygdrive/h/###_Hudson/workspace/IvAp_v1.x/ivap/src/errors.h to top_dir
      Creating filelist for installtester
      Creating filelist for ivapconfig
      Creating filelist for libraries
      Creating filelist for mtlbuilder
      Adding /cygdrive/h/###_Hudson/workspace/IvAp_v1.x/ivap/src/version.h to top_dir
      Categorizing files.
      Finding a working MD5 command....
      Found a working MD5 command.
      Computing results.

      177 ansic FsInt
      /cygdrive/h/###_Hudson/workspace/IvAp_v1.x/ivap/src/FsInt/ModuleUser.c
      120 ansic FsInt
      /cygdrive/h/###_Hudson/workspace/IvAp_v1.x/ivap/src/FsInt/AdvWeather.h
      70 ansic FsInt
      /cygdrive/h/###_Hudson/workspace/IvAp_v1.x/ivap/src/FsInt/FSUIPCNewWeather.h
      57 ansic FsInt /cygdrive/h/###_Hudson/workspace/IvAp_v1.x/ivap/src

      As soon as Hudson starts collecting the results, we find this exception in our
      console log:

      java.lang.StringIndexOutOfBoundsException: String index out of range: -1
      at java.lang.String.substring(Unknown Source)
      at
      hudson.plugins.sloccount.model.SloccountReport.extractFolder(SloccountReport.java:64)
      at hudson.plugins.sloccount.model.SloccountReport.add(SloccountReport.java:42)
      at
      hudson.plugins.sloccount.model.SloccountParser.parseLine(SloccountParser.java:91)
      at hudson.plugins.sloccount.model.SloccountParser.parse(SloccountParser.java:58)
      at hudson.plugins.sloccount.model.SloccountParser.parse(SloccountParser.java:49)
      at hudson.plugins.sloccount.model.SloccountParser.invoke(SloccountParser.java:39)
      at hudson.plugins.sloccount.model.SloccountParser.invoke(SloccountParser.java:17)
      at hudson.FilePath$FileCallableWrapper.call(FilePath.java:2068)
      at hudson.remoting.UserRequest.perform(UserRequest.java:104)
      at hudson.remoting.UserRequest.perform(UserRequest.java:48)
      at hudson.remoting.Request$2.run(Request.java:250)
      at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
      at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
      at java.util.concurrent.FutureTask.run(Unknown Source)
      at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
      at hudson.remoting.Engine$1$1.run(Engine.java:58)
      at java.lang.Thread.run(Unknown Source)

      Based on a quick look at your source code I am assuming this is a problem
      related to the file separator. I.e. the data is collected on a Windows slave
      (separator = ), while the paths in the file are from CygWin (separator = /). I
      suggest to use both for detecting the paths.

        Attachments

          Activity

          Hide
          bjensen bjensen added a comment -

          I have attached a patch that more or the less fixes the issue for me. Additionally I have a small sed script that I use to post process the sloccount output that switches all "/" characters to "\" and changes "/cygdrive/c" to "C:". Now sloccount works on both my windows slave (under cygwin) and under my linux slave. Ideally the sloccount plugin should be able to easily detect whether the presence of cygwin (by checking for /cygdrive at the beginning of the path), but I best leave that change to the maintainers.

          cheers,
          Brian

          Show
          bjensen bjensen added a comment - I have attached a patch that more or the less fixes the issue for me. Additionally I have a small sed script that I use to post process the sloccount output that switches all "/" characters to "\" and changes "/cygdrive/c" to "C:". Now sloccount works on both my windows slave (under cygwin) and under my linux slave. Ideally the sloccount plugin should be able to easily detect whether the presence of cygwin (by checking for /cygdrive at the beginning of the path), but I best leave that change to the maintainers. cheers, Brian
          Hide
          jieryn jieryn added a comment -

          sloccount output from chris_labwork@

          Show
          jieryn jieryn added a comment - sloccount output from chris_labwork@
          Hide
          ben25 Karsten Brandt added a comment -

          This patch should solve this issue in a simple way.

          Show
          ben25 Karsten Brandt added a comment - This patch should solve this issue in a simple way.
          Hide
          scm_issue_link SCM/JIRA link daemon added a comment -

          Code changed in jenkins
          User: Karsten Brandt
          Path:
          src/main/java/hudson/plugins/sloccount/model/SloccountReport.java
          http://jenkins-ci.org/commit/sloccount-plugin/510d0a7611d8a31e2bccb0c7bbd7e21bcf6c600d
          Log:
          [FIXED JENKINS-4836] SLOCCount plugin fails with Windows/Cygwin SLOCCount execution

          Show
          scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Karsten Brandt Path: src/main/java/hudson/plugins/sloccount/model/SloccountReport.java http://jenkins-ci.org/commit/sloccount-plugin/510d0a7611d8a31e2bccb0c7bbd7e21bcf6c600d Log: [FIXED JENKINS-4836] SLOCCount plugin fails with Windows/Cygwin SLOCCount execution
          Hide
          mixalturek Michal Turek added a comment -

          Fixed in version 1.8 according to wiki, related changes in version 1.12 too.

          Show
          mixalturek Michal Turek added a comment - Fixed in version 1.8 according to wiki, related changes in version 1.12 too.

            People

            • Assignee:
              ben25 Karsten Brandt
              Reporter:
              kmmoens kmmoens
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: