+
+ /**
+ * An ECJ {@link CompilationProgress} printing a progress bar while compiling.
+ */
+ static class MakeCompilationProgress extends CompilationProgress {
+ private int totalWork;
+ private long currentChunk = 0;
+ private long chunksCount = 80;
+
+ @Override
+ public void worked(int workIncrement, int remainingWork) {
+ if (!logger.isLoggable(Level.INFO)) // progress bar only at INFO level
+ return;
+ long chunk = ((totalWork - remainingWork) * chunksCount) / totalWork;
+ if (chunk != currentChunk) {
+ currentChunk = chunk;
+ for (long i = 0; i < currentChunk; i++) {
+ System.out.print("#");
+ }
+ for (long i = currentChunk; i < chunksCount; i++) {
+ System.out.print("-");
+ }
+ System.out.print("\r");
+ }
+ if (remainingWork == 0)
+ System.out.print("\n");
+ }
+
+ @Override
+ public void setTaskName(String name) {
+ }
+
+ @Override
+ public boolean isCanceled() {
+ return false;
+ }
+
+ @Override
+ public void done() {
+ }
+
+ @Override
+ public void begin(int remainingWork) {
+ this.totalWork = remainingWork;
+ }
+ }