Skip to content

Commit 3c3a545

Browse files
committed
only log tasks when necessary
1 parent c0b58bd commit 3c3a545

File tree

5 files changed

+30
-8
lines changed

5 files changed

+30
-8
lines changed

plugin/src/main/java/io/github/cichlidmc/cichlid_gradle/cache/storage/AssetStorage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public AssetStorage(Path root) {
2020

2121
public void submitInitialTasks(AssetIndex index, TaskContext context) {
2222
AssetsTask task = new AssetsTask(context, this, index);
23-
context.submit(task);
23+
context.submitSilently(task);
2424
}
2525

2626
public Path index(AssetIndex index) {

plugin/src/main/java/io/github/cichlidmc/cichlid_gradle/cache/storage/VersionStorage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public VersionStorage(Path root, String version) {
3333

3434
public void submitInitialTasks(FullVersion version, TaskContext context) {
3535
SetupTask task = new SetupTask(context, this, version);
36-
context.submit(task);
36+
context.submitSilently(task);
3737
}
3838

3939
public boolean isComplete() {

plugin/src/main/java/io/github/cichlidmc/cichlid_gradle/cache/task/TaskContext.java

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,32 @@ public class TaskContext {
1717
private final Set<CacheTask> incompleteTasks = Collections.synchronizedSet(new HashSet<>());
1818
private final Map<CacheTask, Throwable> errors = Collections.synchronizedMap(new IdentityHashMap<>());
1919

20+
private boolean hasLoudTasks = false;
21+
2022
public CompletableFuture<Void> submit(CacheTask task) {
21-
logger.quiet("Starting new task: {} - {}", task.name, task.description);
23+
return this.doSubmit(task, true);
24+
}
25+
26+
public CompletableFuture<Void> submitSilently(CacheTask task) {
27+
return this.doSubmit(task, false);
28+
}
29+
30+
private CompletableFuture<Void> doSubmit(CacheTask task, boolean log) {
31+
if (log) {
32+
logger.quiet("Starting new task: {} - {}", task.name, task.description);
33+
}
2234

2335
CompletableFuture<Void> future = CompletableFuture.runAsync(task)
24-
.thenRun(() -> this.finishTask(task))
36+
.thenRun(() -> this.finishTask(task, log))
2537
.exceptionally(error -> {
26-
this.finishTask(task);
38+
this.finishTask(task, log);
2739
this.errors.put(task, error);
2840
return null;
2941
});
3042

3143
this.futures.put(task, future);
3244
this.incompleteTasks.add(task);
45+
this.hasLoudTasks |= log;
3346
return future;
3447
}
3548

@@ -47,7 +60,10 @@ public void report() {
4760
this.join();
4861

4962
if (this.errors.isEmpty()) {
50-
logger.quiet("All tasks finished successfully.");
63+
if (this.hasLoudTasks) {
64+
logger.quiet("All tasks finished successfully.");
65+
}
66+
5167
return;
5268
}
5369

@@ -58,8 +74,10 @@ public void report() {
5874
throw root;
5975
}
6076

61-
private void finishTask(CacheTask task) {
62-
logger.quiet("Task complete: {}", task.name);
77+
private void finishTask(CacheTask task, boolean log) {
6378
this.incompleteTasks.remove(task);
79+
if (log) {
80+
logger.quiet("Task complete: {}", task.name);
81+
}
6482
}
6583
}

plugin/src/main/java/io/github/cichlidmc/cichlid_gradle/cache/task/impl/AssetsTask.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ public void doRun() throws IOException {
3636
if (this.storage.isComplete(this.index))
3737
return;
3838

39+
this.logger.quiet("Asset index {} is not cached, downloading", this.index.id);
40+
3941
Path indexFile = this.storage.index(this.index);
4042
new Download(this.index, indexFile).run();
4143
// read downloaded file to avoid downloading again with expand()

plugin/src/main/java/io/github/cichlidmc/cichlid_gradle/cache/task/impl/SetupTask.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ protected void doRun() throws IOException {
6666
if (this.storage.isComplete())
6767
return;
6868

69+
this.logger.quiet("Minecraft version {} is not cached, setting up for the first time", this.version.id);
70+
6971
if (Files.exists(this.storage.root)) {
7072
this.logger.warn("Found existing incomplete files for version {}, overwriting", this.version.id);
7173
FileUtils.deleteRecursively(this.storage.root);

0 commit comments

Comments
 (0)