Skip to content

Latest commit

 

History

History
63 lines (52 loc) · 2.44 KB

README.md

File metadata and controls

63 lines (52 loc) · 2.44 KB

progress

Java CI with Gradle Known Vulnerabilities Quality Gate Status

Example console progress

An implementation agnostic Java library for reporting progress - with bindings for various logging and UI toolkits.

Think of it like SLF4J but for progress reporting, rather than logging.

If you are passed a ProgressMonitor instance into your code - it is very straightforward to use. Here is the most basic example:

public void someMethod(ProgressMonitor monitor) {
  monitor.setSize(100);
  monitor.setStatus("Starting to do some stuff");
  
  try {
    for(int i=0; i < 10; i++) {
      monitor.setStatus("Doing stuff " + i +" of 10");
      // do something sensible that takes time
      Thread.sleep(1000);
      monitor.worked(10);
      // Note we might also check if the monitor is cancelled?
      // if(monitor.isCancelled()) { break; }
    }
  }
  catch(InterruptedException e) {
    // could be any exception
    e.printStackTrace();
  }
  finally {
    // regardless what state of progress was when exception happened
    // we are now done!
    monitor.done();
  }
}

Whats most important is that this brings no other dependencies into the client code - however the underlying ProgressMonitor instance may be implemented (and mapped through to corresponding monitor classes) for Console, Swing, Eclipse ...

Getting Started

To use the library to report on progress (regardless of where it reports to) you need to add the dependency for the pure API as follows:

dependencies {
    implementation 'com.asteroid.duck.progress:api:1.1.0'
}

Applications that wish to render that progress would need to use one of the bindings for different destinations:

  • Console/terminal output (e.g. System.out)
  • SLF4J Loggers messages in some form
  • Java Logging framework
  • Swing progress reporting

More will be added in future.