-
Notifications
You must be signed in to change notification settings - Fork 328
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1433 from jplag/feature/rework-logging
Implemented progress bars for the cli
- Loading branch information
Showing
14 changed files
with
301 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
cli/src/main/java/de/jplag/cli/logger/TongfeiProgressBar.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package de.jplag.cli.logger; | ||
|
||
import de.jplag.logging.ProgressBar; | ||
|
||
/** | ||
* A ProgressBar, that used the tongfei progress bar library underneath, to show progress bars on the cli. | ||
*/ | ||
public class TongfeiProgressBar implements ProgressBar { | ||
private final me.tongfei.progressbar.ProgressBar progressBar; | ||
|
||
public TongfeiProgressBar(me.tongfei.progressbar.ProgressBar progressBar) { | ||
this.progressBar = progressBar; | ||
} | ||
|
||
@Override | ||
public void step(int number) { | ||
this.progressBar.stepBy(number); | ||
} | ||
|
||
@Override | ||
public void dispose() { | ||
this.progressBar.close(); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
cli/src/main/java/de/jplag/cli/logger/TongfeiProgressBarProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package de.jplag.cli.logger; | ||
|
||
import de.jplag.logging.ProgressBar; | ||
import de.jplag.logging.ProgressBarProvider; | ||
import de.jplag.logging.ProgressBarType; | ||
|
||
import me.tongfei.progressbar.ProgressBarBuilder; | ||
import me.tongfei.progressbar.ProgressBarStyle; | ||
|
||
/** | ||
* A ProgressBar provider, that used the tongfei progress bar library underneath, to show progress bars on the cli. | ||
*/ | ||
public class TongfeiProgressBarProvider implements ProgressBarProvider { | ||
@Override | ||
public ProgressBar initProgressBar(ProgressBarType type, int totalSteps) { | ||
me.tongfei.progressbar.ProgressBar progressBar = new ProgressBarBuilder().setTaskName(type.getDefaultText()).setInitialMax(totalSteps) | ||
.setStyle(ProgressBarStyle.UNICODE_BLOCK).build(); | ||
return new TongfeiProgressBar(progressBar); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package de.jplag; | ||
|
||
import java.io.File; | ||
|
||
/** | ||
* Contains the information about a single file in a submission. For single file submissions the submission file is the | ||
* same as the root. | ||
* @param submissionFile The file, that is part of a submission | ||
* @param root The root of the submission | ||
* @param isNew Indicates weather this follows the new or the old syntax | ||
*/ | ||
public record SubmissionFileData(File submissionFile, File root, boolean isNew) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package de.jplag.logging; | ||
|
||
/** | ||
* Exposed interactions for a running progress bar. | ||
*/ | ||
public interface ProgressBar { | ||
/** | ||
* Advances the progress bar by a single step | ||
*/ | ||
default void step() { | ||
step(1); | ||
} | ||
|
||
/** | ||
* Advances the progress bar by amount steps | ||
* @param number The number of steps | ||
*/ | ||
void step(int number); | ||
|
||
/** | ||
* Closes the progress bar. After this method has been called the behaviour of the other methods is undefined. | ||
*/ | ||
void dispose(); | ||
} |
68 changes: 68 additions & 0 deletions
68
core/src/main/java/de/jplag/logging/ProgressBarLogger.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package de.jplag.logging; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* Provides static access to the creation of progress bars. | ||
*/ | ||
public class ProgressBarLogger { | ||
private static ProgressBarProvider progressBarProvider = new DummyProvider(); | ||
|
||
private ProgressBarLogger() { | ||
// Hides default constructor | ||
} | ||
|
||
/** | ||
* Creates a new {@link ProgressBar} | ||
* @param type The type of the progress bar | ||
* @param totalSteps The total number of steps | ||
* @return The newly created progress bar | ||
*/ | ||
public static ProgressBar createProgressBar(ProgressBarType type, int totalSteps) { | ||
return progressBarProvider.initProgressBar(type, totalSteps); | ||
} | ||
|
||
/** | ||
* Sets the {@link ProgressBarProvider}. Should be used by the ui before calling JPlag, if progress bars should be | ||
* shown. | ||
* @param progressBarProvider The provider | ||
*/ | ||
public static void setProgressBarProvider(ProgressBarProvider progressBarProvider) { | ||
ProgressBarLogger.progressBarProvider = progressBarProvider; | ||
} | ||
|
||
private static class DummyProvider implements ProgressBarProvider { | ||
@Override | ||
public ProgressBar initProgressBar(ProgressBarType type, int totalSteps) { | ||
return new DummyBar(type, totalSteps); | ||
} | ||
} | ||
|
||
private static class DummyBar implements ProgressBar { | ||
private static final Logger logger = LoggerFactory.getLogger(DummyBar.class); | ||
private int currentStep; | ||
|
||
public DummyBar(ProgressBarType type, int totalSteps) { | ||
this.currentStep = 0; | ||
logger.info("{} ({})", type.getDefaultText(), totalSteps); | ||
} | ||
|
||
@Override | ||
public void step() { | ||
logger.info("Now at step {}", this.currentStep++); | ||
} | ||
|
||
@Override | ||
public void step(int number) { | ||
for (int i = 0; i < number; i++) { | ||
step(); | ||
} | ||
} | ||
|
||
@Override | ||
public void dispose() { | ||
logger.info("Progress bar done."); | ||
} | ||
} | ||
} |
Oops, something went wrong.