-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#130: Add default content length to progress bar #286
#130: Add default content length to progress bar #286
Conversation
Pull Request Test Coverage Report for Build 10665956719Details
💛 - Coveralls |
cli/src/test/java/com/devonfw/tools/ide/io/FileAccessImplTest.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fix looks quite solid, thanks. I've added some small CR's. After these, the PR should be ready for review.
cli/src/test/java/com/devonfw/tools/ide/io/IdeProgressBarTest.java
Outdated
Show resolved
Hide resolved
cli/src/test/java/com/devonfw/tools/ide/io/IdeProgressBarTest.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your last adjustments. I've added some very small CR's.
cli/src/test/java/com/devonfw/tools/ide/io/IdeProgressBarTest.java
Outdated
Show resolved
Hide resolved
applied code reformat added missing Javadoc param
…ssBar # Conflicts: # cli/src/main/java/com/devonfw/tools/ide/io/FileAccess.java # cli/src/test/java/com/devonfw/tools/ide/context/AbstractIdeTestContext.java # cli/src/test/java/com/devonfw/tools/ide/io/IdeProgressBarTest.java
…ssBar # Conflicts: # cli/src/test/java/com/devonfw/tools/ide/context/AbstractIdeTestContext.java
added AbstractIdeProgressBar implementing IdeProgressBar moved prepareProgressbar logic to IdeProgressBarConsole replaced stepByOne with stepBy and introduced doStepBy adjusted tests
…ssBar # Conflicts: # cli/src/test/java/com/devonfw/tools/ide/context/AbstractIdeTestContext.java
cli/src/main/java/com/devonfw/tools/ide/io/AbstractIdeProgressBar.java
Outdated
Show resolved
Hide resolved
|
||
@Override | ||
public void close() { | ||
if (this.currentProgress < this.maxLength) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
handle maxLength < 0
(-1) case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added a check for maxLength < 0
which will simply return and not change the progress bar anymore.
* @param test boolean indicating if this is used in a test or not. | ||
*/ | ||
void download(String url, Path targetFile); | ||
void download(String url, Path targetFile, boolean test); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we need this parameter? This seems odd to have in a regular API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a left over from the first draft and should be removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed now.
long size; | ||
if (test) { | ||
size = 0L; | ||
} else { | ||
size = source.toFile().length(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you need to test this somehow, extract to protected method long getFileSize(Path)
create a subclass of FileAccessImpl
for test that overrides and returns 0
instead. Then in your JUnit replace the real FileAccess
with the test instance... Seems a little bit more complicated but adding this test
flag to our official API seems odd to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've implemented this as you've suggested, thanks.
private void informAboutSettingDefaultContentLength(long contentLength, String url, Path path) { | ||
|
||
String source; | ||
if (contentLength == 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are you using 0
for undefined? IMHO -1
would make more sense also here...
Files can be 0
bytes large and then the user should not get this warning for every file that was empty but gets copied.
Also if the file size is know but smaller than e.g. 1k we should not give a progress bar.
What is good is that we have a dedicated method copyFileWithProgressBar
for this use-case so we do not do this for every file. However, I assume this is used when we get a tool release package from a custom tool repository using a file URL and that can also be a network mount that is slower so already copying 1MB could take some seconds...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've set the default for undefined to -1 now.
cli/src/main/java/com/devonfw/tools/ide/io/IdeProgressBarConsole.java
Outdated
Show resolved
Hide resolved
…Bar.java Co-authored-by: Jörg Hohwiller <[email protected]>
…le.java Co-authored-by: Jörg Hohwiller <[email protected]>
set size for unknown length to -1 instead of 0 added FileAccessTestImpl (for new getFileSize mock returning always -1) added getFileSize to FileAccessImpl removed test param from download and download*WithProgressBar methods added check for unknown size to close method
I'm closing this PR and continuing it in #575 for a fresh team review and less cluttering. |
Closes #130