Code Monkey home page Code Monkey logo

jcloc's Introduction

jcloc · GitHub Workflow Status (with event) Maven Central javadoc MIT license

Java wrapper for the cloc CLI tool. You can use the library by including the following dependency in your Maven project:

<dependency>
  <groupId>ch.usi.si.seart</groupId>
  <artifactId>jcloc</artifactId>
  <version>0.1.0</version>
</dependency>

Requirements

This library requires a minimum of Java 8. You don't need to have cloc installed on your system, as the JAR comes bundled with the necessary script. Since it is written in Perl, it should be executable out of the box on most systems (as the majority of Unix-like systems have it installed by default).

Example

import ch.usi.si.seart.cloc.CLOC;
import ch.usi.si.seart.cloc.CLOCException;

import java.nio.file.Path;
import java.nio.file.Paths;

public class Main {

    public static void main(String[] args) throws CLOCException {
        Path path = Paths.get("path", "to", "target");
        String result = CLOC.command()
                .timeout(30)
                .target(path)
                .linesByLanguage()
                .toPrettyString();
        System.out.println(result);
    }
}

For more usage examples, take a look at the tests.

Options

The API currently maps only a subset of the cloc command-line options:

import ch.usi.si.seart.cloc.CLOC;

CLOC.command()             // `cloc` equivalent:
    .cores(4)              // --cores
    .docstringAsCode(true) // --docstring-as-code
    .followLinks(true)     // --follow-links
    .maxFileSize(10)       // --max-file-size
    .noRecurse(true)       // --no-recurse
    .readBinaryFiles(true) // --read-binary-files
    .skipUniqueness(true); // --skip-uniqueness

Support for other flags and parameters will be added as development progresses.

Output

Once the command has been built, you can execute it using one of the following methods:

import ch.usi.si.seart.cloc.CLOC;

CLOC cloc = CLOC.command().target(path);

cloc.linesByLanguage();        // Count lines of code by language (default `cloc` behaviour)
cloc.linesByFile();            // Count lines of code by file (equivalent to `cloc --by-file`)
cloc.linesByFileAndLanguage(); // Count lines of code by file and language (equivalent to `cloc --by-file-by-lang`)
cloc.countFiles();             // Count files by language (equivalent to `cloc --only-count-files`)

Results returned by all cloc command variants are parsed courtesy of Jackson. Since all methods return an ObjectNode, you can convert results to a String, or map them to a custom POJO.

You can also customise the command output mapper used by the library like so:

import ch.usi.si.seart.cloc.CLOC;
import com.fasterxml.jackson.databind.json.JsonMapper;

public class Main {

    public static void main(String[] args) {
        JsonMapper mapper = JsonMapper.builder()
                .enable(/* FEATURES */)
                .build();
        CLOC.setOutputMapper(mapper);
        // Use the library as usual
    }
}

FAQ

How can I request a feature or ask a question?

If you have ideas for a feature that you would like to see implemented or if you have any questions, we encourage you to create a new discussion. By initiating a discussion, you can engage with the community and our team, and we will respond promptly to address your queries or consider your feature requests.

How can I report a bug?

To report any issues or bugs you encounter, create a new issue. Providing detailed information about the problem you're facing will help us understand and address it more effectively. Rest assured, we're committed to promptly reviewing and responding to the issues you raise, working collaboratively to resolve any bugs and improve the overall user experience.

How do I contribute to the project?

Refer to CONTRIBUTING.md for more information.

jcloc's People

Contributors

dabico avatar dependabot[bot] avatar

Watchers

Lucian avatar Gabriele Bavota avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.