{"id":25777070,"url":"https://github.com/cqfn/jpeek","last_synced_at":"2025-05-05T06:11:22.655Z","repository":{"id":44858788,"uuid":"107155405","full_name":"cqfn/jpeek","owner":"cqfn","description":"Hosted and command-line calculator of cohesion metrics for Java code","archived":false,"fork":false,"pushed_at":"2025-03-27T07:31:46.000Z","size":13169,"stargazers_count":210,"open_issues_count":82,"forks_count":83,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-03-27T08:31:38.447Z","etag":null,"topics":["cohesion","java","metrics","oop","quality","static-analysis"],"latest_commit_sha":null,"homepage":"https://i.jpeek.org","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cqfn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-10-16T16:42:26.000Z","updated_at":"2025-03-27T07:31:50.000Z","dependencies_parsed_at":"2022-08-29T23:50:24.475Z","dependency_job_id":"240b83a0-4c79-495f-9b75-98e2a840650c","html_url":"https://github.com/cqfn/jpeek","commit_stats":null,"previous_names":["yegor256/jpeek"],"tags_count":66,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cqfn%2Fjpeek","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cqfn%2Fjpeek/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cqfn%2Fjpeek/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cqfn%2Fjpeek/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cqfn","download_url":"https://codeload.github.com/cqfn/jpeek/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252448587,"owners_count":21749495,"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":["cohesion","java","metrics","oop","quality","static-analysis"],"created_at":"2025-02-27T06:01:35.963Z","updated_at":"2025-05-05T06:11:22.647Z","avatar_url":"https://github.com/cqfn.png","language":"Java","funding_links":[],"categories":["静态分析","java"],"sub_categories":[],"readme":"\u003cimg alt=\"logo\" src=\"https://www.jpeek.org/logo.svg\" height=\"92px\"/\u003e\n\n[![EO principles respected here](https://www.elegantobjects.org/badge.svg)](https://www.elegantobjects.org)\n[![DevOps By Rultor.com](https://www.rultor.com/b/cqfn/jpeek)](https://www.rultor.com/p/cqfn/jpeek)\n[![We recommend IntelliJ IDEA](https://www.elegantobjects.org/intellij-idea.svg)](https://www.jetbrains.com/idea/)\n\n[![mvn](https://github.com/cqfn/jpeek/actions/workflows/mvn.yml/badge.svg)](https://github.com/cqfn/jpeek/actions/workflows/mvn.yml)\n[![Javadoc](https://www.javadoc.io/badge/org.jpeek/jpeek.svg)](https://www.javadoc.io/doc/org.jpeek/jpeek)\n[![PDD status](https://www.0pdd.com/svg?name=cqfn/jpeek)](https://www.0pdd.com/p?name=cqfn/jpeek)\n[![Maven Central](https://img.shields.io/maven-central/v/org.jpeek/jpeek.svg)](https://maven-badges.herokuapp.com/maven-central/org.jpeek/jpeek)\n[![License](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/cqfn/jpeek/blob/master/LICENSE.txt)\n[![codecov](https://codecov.io/gh/cqfn/jpeek/branch/master/graph/badge.svg)](https://codecov.io/gh/cqfn/jpeek)\n[![jpeek report](https://i.jpeek.org/org.jpeek/jpeek/badge.svg)](https://i.jpeek.org/org.jpeek/jpeek/)\n[![SonarQube](https://img.shields.io/badge/sonar-ok-green.svg)](https://sonarcloud.io/dashboard?id=org.jpeek%3Ajpeek)\n[![Hits-of-Code](https://hitsofcode.com/github/cqfn/jpeek)](https://hitsofcode.com/view/github/cqfn/jpeek)\n\njPeek is a static collector of Java code metrics.\n\n**Motivation**:\n[Class cohesion](http://www.jot.fm/issues/issue_2008_07/article1.pdf), for example,\nis considered as one of most important object-oriented software attributes.\nThere are\n[over 30](http://www.math.md/files/csjm/v25-n1/v25-n1-(pp44-74).pdf)\ndifferent cohesion metrics invented so far, but almost none of them\nhave calculators available. The situation with other metrics is very similar.\nWe want to create such a tool that will make it\npossible to analyze code quality more or less formally (with hundreds of metrics). Then, we will\napply this analysis to different Java libraries with an intent to prove\nthat the ideas from [Elegant Objects](https://www.yegor256.com/elegant-objects.html)\nbook series make sense.\n\n## How to use?\n\nLoad the latest `jar-with-dependencies.jar` file from\n[here](https://repo1.maven.org/maven2/org/jpeek/jpeek/)\nand then:\n\n```bash\njava -jar jpeek-jar-with-dependencies.jar --sources . --target ./jpeek\n```\n\njPeek will analyze Java files in the current directory.\nXML reports will be generated in the `./jpeek` directory. Enjoy.\n\n\u003cdetails\u003e\n\u003csummary\u003eAvailable CLI options\u003c/summary\u003e\n\n| Option                      | Description                                                                        |\n|-----------------------------|------------------------------------------------------------------------------------|\n| `-s, --sources \u003cpath\u003e`      | **Required.** Path to directory with the class files                               |\n| `-t, --target \u003cpath\u003e`       | **Required.** Path to directory where the reports will be generated                |\n| `--include-ctors`           | Include constructors into all formulas                                             |\n| `--include-static-methods`  | Include static methods into all formulas                                           |\n| `--include-private-methods` | Include private methods into all formulas                                          |\n| `--metrics \u003cmetrics\u003e`       | Comma-separated list of metrics to include (default: `\"LCOM5,NHD,MMAC,SCOM,CAMC\"`) |\n| `--overwrite`               | Overwrite the target directory, if it exists, or exit with error                   |\n| `--quiet`                   | Turn off logging                                                                   |\n| `--help`                    | Display help message                                                               |\n\u003c/details\u003e\n\nYou can also deploy it as a web service to your own platform. Just compile it\nwith `mvn clean package --settings settings.xml` and then run, as `Procfile` suggests.\nYou will need to have `settings.xml` with the following data:\n\n```xml\n\u003csettings\u003e\n  \u003cprofiles\u003e\n    \u003cprofile\u003e\n      \u003cid\u003ejpeek-heroku\u003c/id\u003e\n      \u003cactivation\u003e\n        \u003cactiveByDefault\u003etrue\u003c/activeByDefault\u003e\n      \u003c/activation\u003e\n      \u003cproperties\u003e\n        \u003csentry.dsn\u003ehttps://...\u003c/sentry.dsn\u003e\n        \u003cdynamo.key\u003eAKIAI..........LNN6A\u003c/dynamo.key\u003e\n        \u003cdynamo.secret\u003e6560KMv5+8Ti....................Qdwob63Z\u003c/dynamo.secret\u003e\n      \u003c/properties\u003e\n    \u003c/profile\u003e\n  \u003c/profiles\u003e\n\u003c/settings\u003e\n```\n\nYou will also need these tables in DynamoDB (all indexes must deliver `ALL` attributes):\n\n```\njpeek-mistakes:\n  metric (HASH/String)\n  version (RANGE/String)\n  indexes:\n    mistakes (GSI):\n      version (HASH/String),\n      avg (RANGE/Number)\njpeek-results:\n  artifact (HASH/String)\n  indexes:\n    ranks (GSI):\n      version (HASH/String)\n      rank (RANGE/Number)\n    scores (GSI):\n      version (HASH/String)\n      score (RANGE/Number)\n    recent (GSI):\n      good (HASH/String)\n      added (RANGE/Number)\n```\n\n## Cohesion Metrics\n\nThese papers provide a pretty good summary of cohesion metrics:\n\n[`izadkhah17`]\nHabib Izadkhah et al.,\u003cbr/\u003e\n_Class Cohesion Metrics for Software Engineering: A Critical Review_,\u003cbr/\u003e\nComputer Science Journal of Moldova, vol.25, no.1(73), 2017,\n[PDF](http://www.math.md/files/csjm/v25-n1/v25-n1-(pp44-74).pdf).\n\n[`badri08`]\nLinda Badri et al.,\u003cbr/\u003e\n_Revisiting Class Cohesion: An empirical investigation on several systems_,\u003cbr/\u003e\nJournal of Object Technology, vol.7, no.6, 2008,\n[PDF](http://www.jot.fm/issues/issue_2008_07/article1.pdf).\n\n### Here is a list of metrics we have already implemented (in order or their appearance):\n\n[`chidamber94`]\nLack of Cohesion in Methods (**LCOM**).\u003cbr/\u003e\nShyam Chidamber et al.,\u003cbr/\u003e\n_A metrics suite for object oriented design_,\u003cbr/\u003e\nIEEE Transactions on Software Engineering, vol.20, no.6, 1994,\n[PDF](papers/chidamber94_LCOM.pdf).\n\n[`bieman95`]\nTight Class Cohesion (**TCC**) and Loose Class Cohesion (**LCC**).\u003cbr/\u003e\nJames M. Bieman et al.,\u003cbr/\u003e\n_Cohesion and Reuse in an Object-Oriented System_,\u003cbr/\u003e\nDepartment of Computer Science, Colorado State University, 1995,\n[PDF](papers/bieman95_TCC.pdf).\n\n[`hitz95`]\nLack of Cohesion in Methods 4 (**LCOM4**).\u003cbr/\u003e\nMartin Hitz et al.,\u003cbr/\u003e\n_Measuring Coupling and Cohesion In Object-Oriented Systems_,\u003cbr/\u003e\nInstitute of Applied Computer Science and Systems Analysis, University of Vienna, 1995,\n[PDF](papers/hitz95_LCOM4.pdf).\n\n[`sellers96`]\nLack of Cohesion in Methods 2-3 (**LCOM 2, 3 and 5**).\u003cbr/\u003e\nB. Henderson-Sellers et al.,\u003cbr/\u003e\n_Coupling and cohesion (towards a valid metrics suite for object-oriented analysis and design)_,\u003cbr/\u003e\nObject Oriented Systems 3, 1996,\n[PDF](papers/sellers96_LCOM2_LCOM3_LCOM5.pdf).\n\n[`bansiya99`]\nCohesion Among Methods of Classes (**CAMC**).\u003cbr/\u003e\nJagdish Bansiya et al.,\u003cbr/\u003e\n_A class cohesion metric for object-oriented designs_,\u003cbr/\u003e\nJournal of Object-Oriented Programming, vol. 11, no. 8, 1999,\n[PDF](papers/bansiya99_CAMC.pdf).\n\n[`etzkorn00`]\nLOgical Relatedness of Methods (**LORM**).\u003cbr/\u003e\nL. Etzkorn and H. Delugach,\u003cbr/\u003e\n_Towards a semantic metrics suite for object-oriented design_,\u003cbr/\u003e\nTechnology of Object-Oriented Languages and Systems, 2000. TOOLS 34. Proceedings. 34th International Conference on. IEEE, 2000, pp. 71–80,\n[PDF](papers/etzkorn00_LORM.pdf)\n\n[`wasiq01`]\nClass Connection Metric (**CCM**).\u003cbr/\u003e\nM. Wasiq\u003cbr/\u003e\n_Measuring Class Cohesion in Object-Oriented Systems_,\u003cbr/\u003e\nMaster Thesis at the King Fahd University of Petroleum \u0026 Minerals, 2001,\n[PDF](papers/wasiq01_CCM.pdf).\n\n[`aman04`]\nOptimistic Class Cohesion (**OCC**) and Pessimistic Class Cohesion (**PCC**).\u003cbr/\u003e\nHirohisa Aman et al.,\u003cbr/\u003e\n_A proposal of class cohesion metrics using sizes of cohesive parts_,\u003cbr/\u003e\nProc. of Fifth Joint Conference on Knowledge-based Software Engineering, 2002,\n[PDF](papers/aman04_OCC_PCC.pdf).\n\n[`marcus05`]\nConceptual Cohesion of Classes (**C3**).\u003cbr/\u003e\nA. Marcus and D. Poshyvanyk,\u003cbr/\u003e\n_The conceptual cohesion of classes_,\u003cbr/\u003e\n21st IEEE International Conference on Software Maintenance (ICSM'05), Budapest, Hungary, 2005, pp. 133-142,\n[PDF](papers/marcus05_C3.pdf)\n\n[`counsell06`]\nNormalized Hamming Distance (**NHD**).\u003cbr/\u003e\nSteve Counsell et al.,\u003cbr/\u003e\n_The interpretation and utility of three cohesion metrics for object-oriented design_,\u003cbr/\u003e\nACM TOSEM, April 2006,\n[PDF](papers/counsell06_NHD.pdf).\n\n[`fernandez06`]\nA Sensitive Metric of Class Cohesion (**SCOM**).\u003cbr/\u003e\nLuis Fernández et al.,\u003cbr/\u003e\n_[A] new metric [...] yielding meaningful values [...] more sensitive than those previously reported_,\u003cbr/\u003e\nInternational Journal \"Information Theories \u0026 Applications\", Volume 13, 2006,\n[PDF](papers/fernandez06_SCOM.pdf).\n\n[`dallal07`]\nMethod-Method through Attributes Cohesion (**MMAC**).\u003cbr/\u003e\nJehad Al Dallal,\u003cbr/\u003e\n_A Design-Based Cohesion Metric for Object-Oriented Classes_,\u003cbr/\u003e\nWorld Academy of Science, Engineering and Technology International Journal of Computer and Information Engineering Vol:1, No:10, 2007,\n[PDF](papers/dallal07_MMAC.pdf).\n\n[`liu09`]\nMaximal Weighted Entropy (**MWE**).\u003cbr/\u003e\nY. Liu, D. Poshyvanyk, R. Ferenc, T. Gyim´othy, and N. Chrisochoides,\u003cbr/\u003e\n_Modeling class cohesion as mixtures of latent topics_,\u003cbr/\u003e\nSoftware Maintenance, 2009. ICSM 2009. IEEE International Conference on. IEEE, 2009, pp. 233–242,\n[PDF](papers/liu09_MWE.pdf)\n\n[`dallal11`]\nTransitive Lack of Cohesion in Methods (**TLCOM**).\u003cbr/\u003e\nJehad Al Dallal,\u003cbr/\u003e\n_Transitive-based object-oriented lack-of-cohesion metric_,\u003cbr/\u003e\nDepartment of Information Science, Kuwait University, 2011,\n[PDF](papers/dallal11_TLCOM.pdf).\n\n## How it works?\n\nFirst, `Skeleton` parses Java bytecode using Javaassit and ASM, in order to produce\n`skeleton.xml`. This XML document contains information about each class, which\nis necessary for the metrics calculations. For example, this simple Java\nclass:\n\n```java\nclass Book {\n  private int id;\n  int getId() {\n    return this.id;\n  }\n}\n```\n\nWill look like this in the `skeleton.xml`:\n\n```xml\n\u003cclass id='Book'\u003e\n  \u003cattributes\u003e\n   \u003cattribute public='false' static='false' type='I'\u003eid\u003c/attribute\u003e\n  \u003c/attributes\u003e\n  \u003cmethods\u003e\n    \u003cmethod abstract='false' ctor='true' desc='()I' name='getId' public='true' static='false'\u003e\n      \u003creturn\u003eI\u003c/return\u003e\n      \u003cargs/\u003e\n    \u003c/method\u003e\n  \u003c/methods\u003e\n\u003c/class\u003e\n```\n\nThen, we have a collection of XSL stylesheets, one per each metric. For example,\n`LCOM.xsl` transforms `skeleton.xml` into `LCOM.xml`, which may look like this:\n\n```xml\n\u003cmetric\u003e\n  \u003ctitle\u003eMMAC\u003c/title\u003e\n  \u003capp\u003e\n    \u003cclass id='InstantiatorProvider' value='1'/\u003e\n    \u003cclass id='InstantationException' value='0'/\u003e\n    \u003cclass id='AnswersValidator' value='0.0583'/\u003e\n    \u003cclass id='ClassNode' value='0.25'/\u003e\n    [... skipped ...]\n  \u003c/app\u003e\n\u003c/metric\u003e\n```\n\nThus, all calculations happen inside the XSLT files. We decided to implement\nit this way after a less successful attempt to do it all in Java. It seems\nthat XSL is much more suitable for manipulations with data than Java.\n\n### jPeek maven plugin\nWe are developing a jPeek plugin for Maven, see [jPeek Maven plugin](https://github.com/yegor256/jpeek-maven-plugin) project.\n\n## Known Limitations\n\n* The java compiler is known to inline constant variables as per [JLS 13.1](https://docs.oracle.com/javase/specs/jls/se8/html/jls-13.html#jls-13.1). This affects the results calculated by metrics that take into account access to class attributes if these are `final` constants. For instance, all LCOM and COM metrics are affected.\n\n## How to contribute?\n\nJust fork, make changes, run `mvn clean install -Pqulice` and submit\na pull request; read [this](http://www.yegor256.com/2014/04/15/github-guidelines.html),\nif lost.\n\n## Contributors\n\n  - [@yegor256](https://github.com/yegor256) as Yegor Bugayenko ([Blog](https://www.yegor256.com))\n  - [@alayor](https://github.com/alayor) as Alonso A. Ortega ([Blog](http://www.alayor.com))\n  - [@memoyil](https://github.com/memoyil) as Mehmet Yildirim\n  - [@sergey-karazhenets](https://github.com/sergey-karazhenets) as Sergey Karazhenets\n  - [@llorllale](https://github.com/llorllale) as George Aristy\n  - [@mesut](https://github.com/mesut) as Mesut Özen\n  - [@serranya](https://github.com/serranya) as Peter Lamby\n  - [@humb1t](https://github.com/humb1t) as Nikita Puzankov\n  - [@stepanov-dmitry](https://github.com/stepanov-dmitry) as Dmitry Stepanov\n  - [@GnusinPavel](https://github.com/GnusinPavel) as Gnusin Pavel\n  - [@mohamednizar](https://github.com/mohamednizar) as Mohamed Nizar\n\nDon't hesitate to add your name to this list in your next pull request.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcqfn%2Fjpeek","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcqfn%2Fjpeek","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcqfn%2Fjpeek/lists"}