{"id":13516720,"url":"https://github.com/jenkinsci/sloccount-plugin","last_synced_at":"2025-04-15T03:54:47.044Z","repository":{"id":545542,"uuid":"1163754","full_name":"jenkinsci/sloccount-plugin","owner":"jenkinsci","description":"Jenkins sloccount plugin","archived":false,"fork":false,"pushed_at":"2024-08-08T14:51:30.000Z","size":375,"stargazers_count":17,"open_issues_count":6,"forks_count":34,"subscribers_count":94,"default_branch":"master","last_synced_at":"2025-04-15T03:54:41.772Z","etag":null,"topics":["adopt-this-plugin"],"latest_commit_sha":null,"homepage":"https://plugins.jenkins.io/sloccount/","language":"Java","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jenkinsci.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2010-12-13T05:53:21.000Z","updated_at":"2025-04-04T04:18:39.000Z","dependencies_parsed_at":"2023-02-12T19:50:23.559Z","dependency_job_id":"fc272a5e-dc2f-42bb-bdea-d5e3e813f3f5","html_url":"https://github.com/jenkinsci/sloccount-plugin","commit_stats":null,"previous_names":[],"tags_count":29,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jenkinsci%2Fsloccount-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jenkinsci%2Fsloccount-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jenkinsci%2Fsloccount-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jenkinsci%2Fsloccount-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jenkinsci","download_url":"https://codeload.github.com/jenkinsci/sloccount-plugin/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249003954,"owners_count":21196794,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["adopt-this-plugin"],"created_at":"2024-08-01T05:01:25.217Z","updated_at":"2025-04-15T03:54:47.026Z","avatar_url":"https://github.com/jenkinsci.png","language":"Java","funding_links":[],"categories":["Java"],"sub_categories":[],"readme":"# SLOCCount Plugin\n\nThis plug-in generates trend report for [SLOCCount](http://www.dwheeler.com/sloccount/) and [cloc](http://cloc.sourceforge.net/) open source tools, that count number of code lines written in many programming languages.\n\n## Description\n\nThe SLOCCount plug-in scans for [SLOCCount](http://www.dwheeler.com/sloccount/) or [cloc](http://cloc.sourceforge.net/) report files in the build workspace directory and reports the number of lines they found.\n\nThe following features are provided by this plug-in:\n\n- Parsing of reports generated by [SLOCCount](http://www.dwheeler.com/sloccount/) tool.\n- Parsing of reports generated by [cloc](http://cloc.sourceforge.net/) tool.\n- Configuration of the files to scan after a build.\n- Trend reports showing the number of lines per language.\n- Trend reports showing the number of added or deleted lines per language.\n- Overview of the lines per file, folder or language.\n- [Dashboard View](https://wiki.jenkins.io/display/JENKINS/Dashboard+View) portlet showing number of lines, files and languages per job.\n- Remote access API ([REST API](https://wiki.jenkins-ci.org/display/JENKINS/Remote+access+API)).\n- Works with any project/job type.\n\nThis plug-in is developed and maintained by Nicolas Piguet. Please use\nthe [Mailing Lists](https://wiki.jenkins.io/display/JENKINS/Mailing+Lists)\nor [issue tracker](http://issues.jenkins-ci.org/) to ask questions,\ncreate feature request or bug reports, since I don't read the comment\nsection on this page regularly.\n\n## Usage\n\nIf you are not sure which type of report files to use, prefer **cloc**.\nIt is able to detect more programming languages than SLOCCount (Scala,\nAnt, CSS, ...) and is able to count also lines with comments that often\ncontain Javadoc or Doxygen documentation. Cloc is also better portable,\nSLOCCount requires [cygwin](https://www.cygwin.com/) or similar\nenvironment under MS Windows.\n\n**Never switch between SLOCCount and cloc inside one job.** You would\nend up with messy trend graph because they name programming languages\ndifferently. Delete all affected builds and rebuild the job in such case\nto fix the issue.\n\n### Linux\n\n- Install [SLOCCount](http://www.dwheeler.com/sloccount/) or [cloc](http://cloc.sourceforge.net/) on the build slave machine. Note they may be present in package repository of your distribution.\n    - Debian, Ubuntu, ...\n        - `apt-get install sloccount`\n        - `apt-get install cloc`\n    - Red Hat, CentOS, Fedora, ...\n        - `yum install sloccount`\n        - `yum install cloc`\n- For each job configuration page:\n    - Add a **execute shell** build step to generate the report files, or create them in your build scripts (Ant, Maven, Make, ...).\n        - `sloccount --duplicates --wide --details [source-folder] \u003e [output-folder]/sloccount.sc`\n        - `cloc --by-file --xml --out=[output-folder]/cloc.xml [source-folder]`\n    - Activate the checkbox **Publish SLOCCount analysis results** and provide the path to the generated report files.\n\n### Windows\n\n#### cloc\n\n- Download and install [cloc](http://cloc.sourceforge.net/) ([cloc.exe](http://sourceforge.net/projects/cloc/files/cloc/)) on the build slave machine. Optionally if you have Perl installed, you can run cloc as a standalone Perl Script.\n- For each job configuration page:\n    - Generate the report files\n        - `cloc.exe --by-file --xml --out=[output-folder]/cloc.xml [source-folder]`\n        - `perl cloc.pl --by-file --xml --out=[output-folder]/cloc.xml [source-folder]`\n    - Activate the checkbox **Publish SLOCCount analysis results** and provide the path to the generated cloc report.\n\n#### SLOCCount\n\nSince SLOCCount does not run on a native Windows machine the setup for\nWindows requires additional steps. Most of the setup is explained in\ndetail in the [SLOCCount\ndocumentation](http://www.dwheeler.com/sloccount/sloccount.html).\n\n- Install [Cygwin](https://www.cygwin.com/) on the build slave.\n- Compile and install SLOCCount within the Cygwin environment.\n- For each job configuration page:\n    - Add a build step to run Cygwin and SLOCCount. See the ANT example below to learn how to start Cygwin and run SLOCCount from an ANT script.\n        - `/usr/bin/sloccount --duplicates --wide --details [source-folder] \u003e[output-folder]/sloccount.sc` You must convert Windows paths that are passed as parameters to SLOCCount utility to Linux/Cygwin style (C:\\\\ becomes /cygdrive/c/).\n    - Convert the SLOCCount results in sloccount.sc back to windows paths.\n    - Activate the checkbox **Publish SLOCCount analysis results** and provide the path to the generated SLOCCount report.\n\nIf you uses sloccount for multiple jobs sometimes two jobs end at the\nsame time and sloccount is executed simultaneously. This will fail since\nSLOCCount (by default) uses one temp data folder in $HOME/.slocdata.\n\nEither change sloccount to not use a temp data directory or change the\nsetup explanation so novice users (like me) are explained to use the\n--datadir option in order to get a datadir per hudson job.\n\nThis seems to work:\n\\[ -d slocdata \\] \\|\\| mkdir slocdata\nsloccount --datadir slocdata --details \"your source path\" \\\u003e\nsloccount.sc\n\n##### ANT example for Windows build\n\nThe target converts Windows paths to Linux style cygdrive paths (C:\\\\\nbecomes /cygdrive/c/) before SLOCCount runs. The converted paths are\npassed as environment variables to Cygwin. After SLOCCount has been\nexecuted, the results in sloccount.sc are converted back to windows\npaths.\n\n##### ANT target\n\nAdd this target to your Jenkins build:\n\n**build.xml**\n\n```xml\n\u003ctarget name=\"sloccount\" depends=\"createAllSrc\"\u003e\n  \u003cscript language=\"javascript\"\u003e \u003c![CDATA[\n    function winToCygdrivePath(cygProp, winProp) {\n      winPath = project.getProperty(winProp);\n      cygPath = winPath.replaceAll(\"C:\", \"/cygdrive/c\").replace('\\\\', '/');\n      project.setProperty(cygProp, cygPath);\n    }\n    winToCygdrivePath(\"cygdrive.workspace.dir\", \"dir.workspace\");\n    winToCygdrivePath(\"cygdrive.allsrc.dir\", \"dir.allsrc\");\n    winToCygdrivePath(\"cygdrive.build.scripts.dir\", \"dir.build.scripts\");\n  ]]\u003e\u003c/script\u003e\n\n  \u003cexec executable=\"${cygwin.bin}\\bash.exe\"\u003e\n    \u003carg line=\"-li '${cygdrive.build.scripts.dir}/cygwin_sloccount.sh'\" /\u003e\n    \u003cenv key=\"SLOCCOUNT_SOURCE_DIR\" value=\"${cygdrive.allsrc.dir}\" /\u003e\n    \u003cenv key=\"SLOCCOUNT_OUTPUT_DIR\" value=\"${cygdrive.workspace.dir}\" /\u003e\n  \u003c/exec\u003e\n\n  \u003creplace file=\"${dir.workspace}/sloccount.sc\" token=\"/cygdrive/c\" value=\"C:\" /\u003e\n  \u003creplace file=\"${dir.workspace}/sloccount.sc\" token=\"/\" value=\"\\\" /\u003e\n\u003c/target\u003e\n```\n\nYou may have to adjust the paths used in the snippet, if your Jenkins\nworkspace is on another drive than C.\n\n##### Shell script\n\nThis shell script is called by Cygwin / ANT.\n\n**cygwin\\_sloccount.sh**\n\n```\nsloccount --duplicates --wide --details \"$SLOCCOUNT_SOURCE_DIR\" \u003e \"$SLOCCOUNT_OUTPUT_DIR/sloccount.sc\"\n```\n\n## Remote access API ([REST API](https://wiki.jenkins-ci.org/display/JENKINS/Remote+access+API))\n\nUse the URLs below to access the SLOCCount specific data.\n\nDescription of possibilities\n\n- [http://SERVER/job/JOB\\_NAME/BUILD\\_NUMBER/sloccountResult/api](http://server/job/JOB_NAME/BUILD_NUMBER/sloccountResult/api)\n\nData\n\n- [http://SERVER/job/JOB\\_NAME/BUILD\\_NUMBER/sloccountResult/api/xml](http://server/job/JOB_NAME/BUILD_NUMBER/sloccountResult/api/xml)\n- [http://SERVER/job/JOB\\_NAME/BUILD\\_NUMBER/sloccountResult/api/xml?depth=1](http://server/job/JOB_NAME/BUILD_NUMBER/sloccountResult/api/xml?depth=1)\n- [http://SERVER/job/JOB\\_NAME/BUILD\\_NUMBER/sloccountResult/api/json](http://server/job/JOB_NAME/BUILD_NUMBER/sloccountResult/api/json)\n- [http://SERVER/job/JOB\\_NAME/BUILD\\_NUMBER/sloccountResult/api/json?depth=1](http://server/job/JOB_NAME/BUILD_NUMBER/sloccountResult/api/json?depth=1)\n- etc.\n\nExample of XML data:\n\n```xml\n\u003csloccountReportStatistics\u003e\n    \u003clanguage\u003e\n        \u003cfiles\u003e7\u003c/files\u003e\n        \u003clines\u003e513\u003c/lines\u003e\n        \u003cname\u003exml\u003c/name\u003e\n    \u003c/language\u003e\n    \u003clanguage\u003e\n        \u003cfiles\u003e116\u003c/files\u003e\n        \u003clines\u003e8174\u003c/lines\u003e\n        \u003cname\u003ejava\u003c/name\u003e\n    \u003c/language\u003e\n    \u003ctotalFiles\u003e123\u003c/totalFiles\u003e\n    \u003ctotalLanguages\u003e2\u003c/totalLanguages\u003e\n    \u003ctotalLines\u003e8687\u003c/totalLines\u003e\n\u003c/sloccountReportStatistics\u003e\n```\n\nExample of JSON data:\n\n```json\n{\n    \"languages\":\n    [\n        {\"files\":7,\"lines\":513,\"name\":\"xml\"},\n        {\"files\":116,\"lines\":8174,\"name\":\"java\"},\n    ],\n    \"totalFiles\":123,\n    \"totalLanguages\":2,\n    \"totalLines\":8687\n}\n```\n\n## Support for cloc tool\n\nParsing of cloc XML reports is supported natively in the plugin from\nversion 1.20.\n\n[Cloc](http://cloc.sourceforge.net/) (Count Lines of Code) is a tool\nsimilar to SLOCCount. It provides output to a XML file that can be\nsimply transformed to the SLOCCount format and used in this plugin. Cloc\nis written in Perl and should be better portable than SLOCCount.\n\nThis howto was created and tested on Debian GNU/Linux, Jenkins 1.447,\nSLOCCount plugin 1.12, cloc 1.60 and xsltproc 1.1.28.\n\n#### Install cloc and xsltproc\n\nDownload cloc from \u003chttp://cloc.sourceforge.net/\u003e and install it. You\nneed also a whatever tool for XML transformations (xsltproc used) or you\ncan try [clokins](https://gitorious.org/clokins) tool (not tested at\nall). You can install the packages present in your GNU/Linux\ndistribution.\n\n```\n# Debian/Ubuntu specific\napt-get install cloc xsltproc\n```\n\n#### Script for XSLT transformation\n\nCopy-paste the script below and store it to cloc2sloccount.xsl file\naccessible by your Jenkins server. If you are using master and slave\nmachines, store the script to all slaves where the jobs are executed.\n\n**cloc2sloccount.xsl**\n\n```xml\n\u003cxsl:stylesheet version=\"1.0\" xmlns:de=\".\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\"\u003e\n\u003cxsl:output method=\"text\" version=\"4.0\" encoding=\"iso-8859-1\"\n  doctype-public=\"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n  doctype-system=\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"/\u003e\n\n\u003cxsl:template match=\"file\"\u003e\n  \u003cxsl:variable name=\"file_path\" select=\"translate(@name,'\\\\','/')\"/\u003e\n  \u003cxsl:variable name=\"file_path_part1\" select=\"substring-after($file_path,'/')\"/\u003e\n  \u003cxsl:variable name=\"module\" select=\"substring-before($file_path_part1,'/')\"/\u003e\n  \u003cxsl:value-of select=\"@code\"/\u003e\n  \u003cxsl:text\u003e\u0026#09;\u003c/xsl:text\u003e\n  \u003cxsl:value-of select=\"@language\"/\u003e\n  \u003cxsl:text\u003e\u0026#09;\u003c/xsl:text\u003e\n  \u003cxsl:value-of select=\"$module\"/\u003e\n  \u003cxsl:text\u003e\u0026#09;\u003c/xsl:text\u003e\n  \u003cxsl:value-of select=\"@name\"/\u003e\n  \u003cxsl:text\u003e\u0026#13;\u0026#10;\u003c/xsl:text\u003e\n\u003c/xsl:template\u003e\n\n\u003cxsl:template match=\"files\"\u003e\n\u003cxsl:apply-templates select=\"file\"/\u003e\n\u003c/xsl:template\u003e\n\n\u003cxsl:template match=\"cloc_url\"\u003eFor more details see: \u003cxsl:value-of select=\".\"/\u003e\n\u003cxsl:text\u003e\u0026#13;\u0026#10;\u003c/xsl:text\u003e\n\u003c/xsl:template\u003e\n\n\u003cxsl:template match=\"cloc_version\"\u003eThis report has been generated by cloc \u003cxsl:value-of select=\".\"/\u003e.\u003cxsl:text\u003e\u0026#13;\u0026#10;\u003c/xsl:text\u003e\n\u003c/xsl:template\u003e\n\n\u003cxsl:template match=\"header\"\u003e\n\u003cxsl:apply-templates select=\"cloc_version\"/\u003e\n\u003cxsl:apply-templates select=\"cloc_url\"/\u003e\n\u003c/xsl:template\u003e\n\n\u003cxsl:template match=\"results\"\u003e\n\u003cxsl:apply-templates select=\"header\"/\u003e\n\u003cxsl:text\u003e\u0026#13;\u0026#10;\u003c/xsl:text\u003e\n\u003cxsl:apply-templates select=\"files\"/\u003e\n\u003c/xsl:template\u003e\n\n\u003cxsl:template match=\"/\"\u003e\n\u003cxsl:apply-templates select=\"results\"/\u003e\n\u003c/xsl:template\u003e\n\n\u003c/xsl:stylesheet\u003e\n```\n\n### Execute cloc\n\nChange configuration of your job to execute the following shell script.\nUpdate the path to the directory where your source files are stored and\noptionally pass [additional\nparameters](http://cloc.sourceforge.net/#Options) to cloc. Then execute\nXSLT transformation on cloc output to get a SLOCCount compatible report.\n\n```\ncloc --by-file --xml -out=cloc.xml DIRECTORY\nxsltproc PATH/TO/cloc2sloccount.xsl cloc.xml \u003e sloccount.sc\n```\n\nEnable SLOCCount publisher, enter path to the generated SLOCCount report\nand that's all.\n\n![](docs/images/cloc_config.png)\n![](docs/images/cloc_trend.png)\n\n#### Using the plugin within a Jenkins pipeline\n\nConfigure your pipeline in a similar way to this example:\n\n**Jenkinsfile**\n\n```groovy\nnode('master') {\n    stage (\"Analyse\") {\n        sh 'sloccount --duplicates --wide --details path-to-code/ \u003e sloccount.sc'\n    }\n    stage (\"Publish reports\") {\n        sloccountPublish encoding: '', pattern: ''\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjenkinsci%2Fsloccount-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjenkinsci%2Fsloccount-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjenkinsci%2Fsloccount-plugin/lists"}