Skip to content
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

Conversation

ndemirca
Copy link
Contributor

Closes #130

@coveralls
Copy link
Collaborator

coveralls commented Apr 12, 2024

Pull Request Test Coverage Report for Build 10665956719

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 173 unchanged lines in 4 files lost coverage.
  • Overall coverage increased (+0.1%) to 64.987%

Files with Coverage Reduction New Missed Lines %
com/devonfw/tools/ide/tool/mvn/Mvn.java 8 72.93%
com/devonfw/tools/ide/context/IdeContextConsole.java 11 0.0%
com/devonfw/tools/ide/io/IdeProgressBarConsole.java 36 0.0%
com/devonfw/tools/ide/io/FileAccessImpl.java 118 61.69%
Totals Coverage Status
Change from base Build 10636350223: 0.1%
Covered Lines: 5765
Relevant Lines: 8567

💛 - Coveralls

@ndemirca ndemirca marked this pull request as draft April 12, 2024 09:34
@ndemirca ndemirca marked this pull request as ready for review April 12, 2024 12:45
@ndemirca ndemirca requested a review from VinceHeu April 12, 2024 14:57
cli/pom.xml Outdated Show resolved Hide resolved
@VinceHeu VinceHeu removed their request for review April 15, 2024 09:30
@ndemirca ndemirca marked this pull request as draft April 15, 2024 14:43
Copy link
Contributor

@jan-vcapgemini jan-vcapgemini left a 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.

@ndemirca ndemirca marked this pull request as ready for review April 16, 2024 15:06
Copy link
Contributor

@jan-vcapgemini jan-vcapgemini left a 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.

@ndemirca ndemirca marked this pull request as draft May 16, 2024 11:02
@ndemirca ndemirca assigned jan-vcapgemini and unassigned ndemirca May 29, 2024
jan-vcapgemini and others added 8 commits July 8, 2024 15:45
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

@Override
public void close() {
if (this.currentProgress < this.maxLength) {
Copy link
Member

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

Copy link
Contributor

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.

Comment on lines 27 to 29
* @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);
Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed now.

Comment on lines 167 to 172
long size;
if (test) {
size = 0L;
} else {
size = source.toFile().length();
}
Copy link
Member

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.

Copy link
Contributor

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) {
Copy link
Member

@hohwille hohwille Aug 30, 2024

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...

Copy link
Contributor

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.

jan-vcapgemini and others added 4 commits September 2, 2024 10:46
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
@jan-vcapgemini jan-vcapgemini marked this pull request as ready for review September 2, 2024 11:08
@jan-vcapgemini
Copy link
Contributor

I'm closing this PR and continuing it in #575 for a fresh team review and less cluttering.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

ProgressBar AssertionError, if content-length not set
4 participants