-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improved exception handling and return codes
- Loading branch information
Showing
4 changed files
with
117 additions
and
77 deletions.
There are no files selected for viewing
34 changes: 18 additions & 16 deletions
34
cli/src/main/java/com/devonfw/tools/ide/cli/CliAbortException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,18 @@ | ||
package com.devonfw.tools.ide.cli; | ||
|
||
/** | ||
* {@link CliException} that is thrown if the user aborted further processing due | ||
*/ | ||
public final class CliAbortException extends CliException { | ||
|
||
/** | ||
* The constructor. | ||
*/ | ||
public CliAbortException() { | ||
|
||
super("Aborted by end-user.", 22); | ||
} | ||
|
||
} | ||
package com.devonfw.tools.ide.cli; | ||
|
||
import com.devonfw.tools.ide.process.ProcessResult; | ||
|
||
/** | ||
* {@link CliException} that is thrown if the user aborted further processing due | ||
*/ | ||
public final class CliAbortException extends CliException { | ||
|
||
/** | ||
* The constructor. | ||
*/ | ||
public CliAbortException() { | ||
|
||
super("Aborted by end-user.", ProcessResult.ABORT); | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
cli/src/main/java/com/devonfw/tools/ide/cli/CliOfflineException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.devonfw.tools.ide.cli; | ||
|
||
import com.devonfw.tools.ide.process.ProcessResult; | ||
|
||
/** | ||
* {@link CliException} that is thrown if the user aborted further processing due | ||
*/ | ||
public final class CliOfflineException extends CliException { | ||
|
||
/** | ||
* The constructor. | ||
*/ | ||
public CliOfflineException() { | ||
|
||
super("You are offline but network connection is required to perform the operation.", ProcessResult.OFFLINE); | ||
} | ||
|
||
/** | ||
* The constructor. | ||
* | ||
* @param message the {@link #getMessage() message}. | ||
*/ | ||
public CliOfflineException(String message) { | ||
|
||
super(message, ProcessResult.OFFLINE); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 59 additions & 44 deletions
103
cli/src/main/java/com/devonfw/tools/ide/process/ProcessResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,59 @@ | ||
package com.devonfw.tools.ide.process; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Result of a {@link Process} execution. | ||
* | ||
* @see ProcessContext#run() | ||
*/ | ||
public interface ProcessResult { | ||
|
||
/** Exit code for success. */ | ||
int SUCCESS = 0; | ||
|
||
/** Exit code if tool was requested that is not installed. */ | ||
int TOOL_NOT_INSTALLED = 4; | ||
|
||
/** | ||
* @return the exit code. Will be {@link #SUCCESS} on successful completion of the {@link Process}. | ||
*/ | ||
int getExitCode(); | ||
|
||
/** | ||
* @return {@code true} if the {@link #getExitCode() exit code} indicates {@link #SUCCESS}, {@code false} otherwise | ||
* (an error occurred). | ||
*/ | ||
default boolean isSuccessful() { | ||
|
||
return getExitCode() == SUCCESS; | ||
} | ||
|
||
/** | ||
* @return the {@link List} with the lines captured on standard out. Will be {@code null} if not captured but | ||
* redirected. | ||
*/ | ||
List<String> getOut(); | ||
|
||
/** | ||
* @return the {@link List} with the lines captured on standard error. Will be {@code null} if not captured but | ||
* redirected. | ||
*/ | ||
List<String> getErr(); | ||
|
||
} | ||
package com.devonfw.tools.ide.process; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Result of a {@link Process} execution. | ||
* | ||
* @see ProcessContext#run() | ||
*/ | ||
public interface ProcessResult { | ||
|
||
/** Return code for success. */ | ||
int SUCCESS = 0; | ||
|
||
/** Return code if tool was requested that is not installed. */ | ||
int TOOL_NOT_INSTALLED = 4; | ||
|
||
/** | ||
* Return code to abort gracefully. | ||
* | ||
* @see com.devonfw.tools.ide.cli.CliAbortException | ||
*/ | ||
int ABORT = 22; | ||
|
||
/** | ||
* Return code if {@link com.devonfw.tools.ide.context.IdeContext#isOffline() offline} but network is required for | ||
* requested operation. | ||
* | ||
* @see com.devonfw.tools.ide.cli.CliOfflineException | ||
*/ | ||
int OFFLINE = 23; | ||
|
||
/** | ||
* @return the exit code. Will be {@link #SUCCESS} on successful completion of the {@link Process}. | ||
*/ | ||
int getExitCode(); | ||
|
||
/** | ||
* @return {@code true} if the {@link #getExitCode() exit code} indicates {@link #SUCCESS}, {@code false} otherwise | ||
* (an error occurred). | ||
*/ | ||
default boolean isSuccessful() { | ||
|
||
return getExitCode() == SUCCESS; | ||
} | ||
|
||
/** | ||
* @return the {@link List} with the lines captured on standard out. Will be {@code null} if not captured but | ||
* redirected. | ||
*/ | ||
List<String> getOut(); | ||
|
||
/** | ||
* @return the {@link List} with the lines captured on standard error. Will be {@code null} if not captured but | ||
* redirected. | ||
*/ | ||
List<String> getErr(); | ||
|
||
} |