Skip to content

Analysis examples

These examples take you from a cloned repository to a map you can open in the visualization. They use the JUnit 4 repository because it is small and quick to analyse, but any project works. Run every command from the folder you clone into.

Terminal window
npm i -g codecharta-analysis
git clone https://github.com/junit-team/junit4
ccsh analyse junit4

ccsh analyse runs every code parser that applies, adds the git history and writes junit4.cc.json.gz. Open it in the Web Studio, or start the desktop client with codecharta-visualization after npm i -g codecharta-visualization.

To choose the parsers and their options yourself, run them one by one and merge the results with the Merge Filter:

Terminal window
ccsh unifiedparser junit4 -o junit4.source.cc.json
ccsh gitlogparser repo-scan --repo-path junit4 -o junit4.git.cc.json
ccsh merge junit4.source.cc.json.gz junit4.git.cc.json.gz -o junit4.cc.json

Each command writes a gzip-compressed file and adds .gz to the name you give, so the merge reads the .gz files and writes junit4.cc.json.gz.

ccsh merge joins the files by path: the metrics of src/main/java/Foo.java from one file and from the other end up on the same building only when both files spell the path the same way. If they do not, the map shows the file twice, once with each set of metrics. Compare the top levels of both files to spot this:

Terminal window
ccsh inspect junit4.source.cc.json.gz --levels 1
ccsh inspect junit4.git.cc.json.gz --levels 1

When the structures differ, fix one of them with ccsh modify and its --move-from/--move-to or --set-root options before you merge.

The Tokei Importer reads the output of Tokei, which counts lines for over 200 languages but measures nothing else. Install Tokei first.

Terminal window
git clone https://github.com/apache/httpd.git
cd httpd && tokei -o json . > ../httpd.tokei.json && cd ..
ccsh tokeiimporter httpd.tokei.json -o httpd.tokei.cc.json

Once SonarQube has analysed your project, the Sonar Importer turns its metrics into a map:

Terminal window
ccsh sonarimport http://localhost:9000 <project-key> --user-token=<token> -o project.sonar.cc.json

Analyze a project with SonarQube shows how to set up a local server and run the analysis.

With Docker you can run the analysis and the visualization without installing Java or Node. Start the containers from the docker-compose.yml of the CodeCharta repository and open a shell in the analysis container:

Terminal window
docker compose pull && docker compose up --detach
docker exec -it codecharta-analysis bash

Inside the container, ccsh and simplecc.sh are ready to use (see the CodeCharta Shell). The containers share no volume, so copy a map out with docker cp:

Terminal window
docker cp codecharta-analysis:/path/to/project.cc.json.gz .

Then open localhost:9001 in your browser and load the file. Docker has the full setup.