Carlovan/github-java-class-names-counter

This simple project retrieves and counts class names from Java-based repositories on GitHub

★ 0Forks 1KotlinGitHub ↗Compare

README

Github Java class names counter

‘There are only two hard things in Computer Science: cache invalidation and naming things.’
— Phil Karlton

The aim of this project is to try to verify the correctness of the second part of this statement.
To do so it extracts the class names in Java based repositories hosted on GitHub.

Project description

This is a Gradle-based project written in Kotlin.

How it works

  1. First we need to obtain the list of the repository and filter them to keep only Java-based ones.
  2. To determine if a repository is "Java-based" we check if Java is one of the two most used languages inside that repository.
  3. We the obtain the list of all files for every repository and keep only the ones with .java extension.
  4. Finally we can parse the source code to get the class names and count them.

All the information is requested from the GitHub API and saved in a cache for faster subsequent usage.
Cache is automatically saved when the program terminates correctly and every three new repositories are stored.

Dependencies

Dependency libraries are used only to handle data or processes based on some kind of standard:

Usage

Execute ./gradlew run [--args="arguments..."] to run the project.

A cache file cache.json will be created or updated if necessary.
While running it will print the repositories being analyzed, and at the end it will write a file output.csv containing the number of times each class name has been encountered.

Arguments

You can specify some command line arguments. If the same argument is present several times, the last one is used.

  • --token=TOKEN: GitHub auth token (see below)
  • --ignore-cache=(all|repos|files): ignore some values from the cache (all = everything, repos = list of repositories, files = files list and content for every repository)

Github Authentication

Since GitHub API applies strict limitation to unauthorized requests, is recommended to supply an OAuth2 token as the first parameter of the application. With Gradle this can be done as show above.

Cache

Since there are a lot of repositories on GitHub, using a cache speeds up subsequent runs of the program.
An interrupted run will also be resumed from where it was left.

Cached data are saved in a file called cache.json; if you want to clean the cache just remove that file.
Cache data is written to file every three retrieved repositories.

Contributors

Carlovan

Issues