Skip to content

Commit

Permalink
Display destination file name in progress message
Browse files Browse the repository at this point in the history
Refers to #138
  • Loading branch information
michel-kraemer committed Jan 16, 2022
1 parent 0f07235 commit e11dd7c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,9 @@ private void execute(URL src, HttpClientFactory clientFactory,
upToDate.incrementAndGet();
return;
}


progressLogger.setDestFileName(destFile.getName());

// in case offline mode is enabled don't try to download if
// destination already exists
if (isOffline) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@

package de.undercouch.gradle.tasks.download.internal;

import org.gradle.api.logging.Logger;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;

import org.gradle.api.logging.Logger;

/**
* Wraps around Gradle's internal progress logger. Uses reflection
* to provide as much compatibility to different Gradle versions
Expand All @@ -32,6 +32,7 @@ public class ProgressLoggerWrapper {
private Object progressLogger;

private String size;
private String destFileName;
private long processedBytes = 0;
private long loggedKb = 0;

Expand Down Expand Up @@ -186,6 +187,14 @@ public void setSize(long size) {
loggedKb = 0;
}

/**
* Set the name of the destination file
* @param destFileName the file name
*/
public void setDestFileName(String destFileName) {
this.destFileName = destFileName;
}

/**
* Increment the number of bytes processed
* @param increment the increment
Expand All @@ -199,12 +208,18 @@ public void incrementProgress(long increment) {

long processedKb = processedBytes / 1024;
if (processedKb > loggedKb) {
String msg = toLengthText(processedBytes);
StringBuilder sb = new StringBuilder();
if (destFileName != null) {
sb.append(destFileName);
sb.append(" > ");
}
sb.append(toLengthText(processedBytes));
if (size != null) {
msg += "/" + size;
sb.append("/");
sb.append(size);
}
msg += " downloaded";
progress(msg);
sb.append(" downloaded");
progress(sb.toString());
loggedKb = processedKb;
}
}
Expand Down

0 comments on commit e11dd7c

Please sign in to comment.