Skip to content

Commit

Permalink
devonfw#799: fix unzip with progressbar
Browse files Browse the repository at this point in the history
refactoring of progressbar and changing expected result of IJ and AStudio plugin
  • Loading branch information
hohwille committed Dec 6, 2024
1 parent d6c38c8 commit 917254f
Show file tree
Hide file tree
Showing 13 changed files with 226 additions and 139 deletions.
49 changes: 43 additions & 6 deletions cli/src/main/java/com/devonfw/tools/ide/context/IdeContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -399,13 +399,50 @@ default Path getSettingsTemplatePath() {
ProcessContext newProcess();

/**
* Prepares the {@link IdeProgressBar} initializes task name and maximum size as well as the behaviour and style.
*
* @param taskName name of the task.
* @param size of the content.
* @return {@link IdeProgressBar} to use.
* @param title the {@link IdeProgressBar#getTitle() title}.
* @param size the {@link IdeProgressBar#getMaxSize() expected maximum size}.
* @param unitName the {@link IdeProgressBar#getUnitName() unit name}.
* @param unitSize the {@link IdeProgressBar#getUnitSize() unit size}.
* @return the new {@link IdeProgressBar} to use.
*/
IdeProgressBar newProgressBar(String title, long size, String unitName, long unitSize);

/**
* @param title the {@link IdeProgressBar#getTitle() title}.
* @param size the {@link IdeProgressBar#getMaxSize() expected maximum size} in bytes.
* @return the new {@link IdeProgressBar} to use.
*/
IdeProgressBar prepareProgressBar(String taskName, long size);
default IdeProgressBar newProgressBarInMib(String title, long size) {

return newProgressBar(title, size, "MiB", 1048576);
}

/**
* @param size the {@link IdeProgressBar#getMaxSize() expected maximum size} in bytes.
* @return the new {@link IdeProgressBar} for copy.
*/
default IdeProgressBar newProgressBarForDownload(long size) {

return newProgressBarInMib(IdeProgressBar.TITLE_DOWNLOADING, size);
}

/**
* @param size the {@link IdeProgressBar#getMaxSize() expected maximum size} in bytes.
* @return the new {@link IdeProgressBar} for extracting.
*/
default IdeProgressBar newProgressbarForExtracting(long size) {

return newProgressBarInMib(IdeProgressBar.TITLE_EXTRACTING, size);
}

/**
* @param size the {@link IdeProgressBar#getMaxSize() expected maximum size} in bytes.
* @return the new {@link IdeProgressBar} for copy.
*/
default IdeProgressBar newProgressbarForCopying(long size) {

return newProgressBarInMib(IdeProgressBar.TITLE_COPYING, size);
}

/**
* @return the {@link DirectoryMerger} used to configure and merge the workspace for an {@link com.devonfw.tools.ide.tool.ide.IdeToolCommandlet IDE}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ protected String readLine() {
}

@Override
public IdeProgressBar prepareProgressBar(String taskName, long size) {
return new IdeProgressBarConsole(getSystemInfo(), taskName, size);
public IdeProgressBar newProgressBar(String title, long size, String unitName, long unitSize) {

return new IdeProgressBarConsole(getSystemInfo(), title, size, unitName, unitSize);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,59 @@
*/
public abstract class AbstractIdeProgressBar implements IdeProgressBar {

private long currentProgress;
/** @see #getTitle() */
protected final String title;

/** @see #getMaxSize() */
protected final long maxSize;

/** @see #getUnitName() */
protected final String unitName;

private final long maxLength;
/** @see #getUnitSize() */
protected final long unitSize;

private long currentProgress;

/**
* @param maxLength the maximum length of the progress bar.
* The constructor.
*
* @param title the {@link #getTitle() title}.
* @param maxSize the {@link #getMaxSize() maximum size}.
* @param unitName the {@link #getUnitName() unit name}.
* @param unitSize the {@link #getUnitSize() unit size}.
*/
public AbstractIdeProgressBar(long maxLength) {
public AbstractIdeProgressBar(String title, long maxSize, String unitName, long unitSize) {

super();
this.title = title;
this.maxSize = maxSize;
this.unitName = unitName;
this.unitSize = unitSize;
}

@Override
public String getTitle() {

return this.title;
}

@Override
public long getMaxSize() {

return this.maxSize;
}

@Override
public String getUnitName() {

this.maxLength = maxLength;
return this.unitName;
}

@Override
public long getMaxLength() {
public long getUnitSize() {

return maxLength;
return this.unitSize;
}

/**
Expand All @@ -38,8 +75,8 @@ public long getMaxLength() {
*/
protected void stepTo(long stepPosition) {

if ((this.maxLength > 0) && (stepPosition > this.maxLength)) {
stepPosition = this.maxLength; // clip to max avoiding overflow
if ((this.maxSize > 0) && (stepPosition > this.maxSize)) {
stepPosition = this.maxSize; // clip to max avoiding overflow
}
this.currentProgress = stepPosition;
doStepTo(stepPosition);
Expand All @@ -56,11 +93,11 @@ protected void stepTo(long stepPosition) {
public void stepBy(long stepSize) {

this.currentProgress += stepSize;
if (this.maxLength > 0) {
if (this.maxSize > 0) {
// check if maximum overflow
if (this.currentProgress > this.maxLength) {
this.currentProgress = this.maxLength;
stepTo(this.maxLength);
if (this.currentProgress > this.maxSize) {
this.currentProgress = this.maxSize;
stepTo(this.maxSize);
return;
}
}
Expand All @@ -76,12 +113,12 @@ public long getCurrentProgress() {

@Override
public void close() {
if (this.maxLength < 0) {
if (this.maxSize < 0) {
return;
}

if (this.currentProgress < this.maxLength) {
stepTo(this.maxLength);
if (this.currentProgress < this.maxSize) {
stepTo(this.maxSize);
}
}

Expand Down
Loading

0 comments on commit 917254f

Please sign in to comment.