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.
Map a repository in one step
Section titled “Map a repository in one step”npm i -g codecharta-analysisgit clone https://github.com/junit-team/junit4ccsh analyse junit4ccsh 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.
Build the map step by step
Section titled “Build the map step by step”To choose the parsers and their options yourself, run them one by one and merge the results with the Merge Filter:
ccsh unifiedparser junit4 -o junit4.source.cc.jsonccsh gitlogparser repo-scan --repo-path junit4 -o junit4.git.cc.jsonccsh merge junit4.source.cc.json.gz junit4.git.cc.json.gz -o junit4.cc.jsonEach 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:
ccsh inspect junit4.source.cc.json.gz --levels 1ccsh inspect junit4.git.cc.json.gz --levels 1When the structures differ, fix one of them with ccsh modify and its
--move-from/--move-to or --set-root options before you merge.
Count lines with Tokei
Section titled “Count lines with Tokei”The Tokei Importer reads the output of Tokei, which counts lines for over 200 languages but measures nothing else. Install Tokei first.
git clone https://github.com/apache/httpd.gitcd httpd && tokei -o json . > ../httpd.tokei.json && cd ..ccsh tokeiimporter httpd.tokei.json -o httpd.tokei.cc.jsonImport metrics from SonarQube
Section titled “Import metrics from SonarQube”Once SonarQube has analysed your project, the Sonar Importer turns its metrics into a map:
ccsh sonarimport http://localhost:9000 <project-key> --user-token=<token> -o project.sonar.cc.jsonAnalyze a project with SonarQube shows how to set up a local server and run the analysis.
Run in Docker
Section titled “Run in Docker”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:
docker compose pull && docker compose up --detachdocker exec -it codecharta-analysis bashInside 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:
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.
Next steps
Section titled “Next steps”- CodeCharta Shell: every parser, importer and filter
- Available metrics: the metrics worth starting with
- Web Studio: explore the map