-
Notifications
You must be signed in to change notification settings - Fork 576
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
Display a warning message for Beta and Exerimental tools. #4429
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,10 +24,9 @@ | |
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.net.InetAddress; | ||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
import java.net.URLClassLoader; | ||
import java.text.DecimalFormat; | ||
import java.lang.Thread; | ||
import java.time.Duration; | ||
import java.time.ZonedDateTime; | ||
import java.util.ArrayList; | ||
|
@@ -175,6 +174,8 @@ public Object instanceMainPostParseArgs() { | |
printStartupMessage(startDateTime); | ||
} | ||
|
||
printProductionWarning(); | ||
|
||
try { | ||
return runTool(); | ||
} finally { | ||
|
@@ -278,6 +279,61 @@ protected void printStartupMessage(final ZonedDateTime startDateTime) { | |
catch (final Exception e) { /* Unpossible! */ } | ||
} | ||
|
||
/** | ||
* If this tool is either Experimental or Beta, return a warning message advising against use in production | ||
* environment. | ||
* @param useTerminalColor true if the message should include highlighting terminal colorization | ||
* @return a warning message if the tool is Beta or Experimental, otherwise null | ||
*/ | ||
protected String getProductionWarning(final boolean useTerminalColor) { | ||
final String KNRM = "\u001B[0m"; // reset | ||
final String BOLDRED = "\u001B[1m\u001B[31m"; | ||
final int BORDER_LENGTH = 60; | ||
|
||
String warningMessage = null; | ||
if (isBetaFeature()) { | ||
warningMessage = String.format( | ||
"\n\n%s %s\n\n Warning: %s is a BETA tool and is not yet ready for use in production\n\n %s%s\n\n", | ||
useTerminalColor ? BOLDRED : "", | ||
Utils.dupChar('!', BORDER_LENGTH), | ||
this.getClass().getSimpleName(), | ||
Utils.dupChar('!', BORDER_LENGTH), | ||
useTerminalColor ? KNRM : "" | ||
); | ||
} | ||
else if (isExperimentalFeature()) { | ||
warningMessage = String.format( | ||
"\n\n%s %s\n\n Warning: %s is an EXPERIMENTAL tool and should not be used for production\n\n %s%s\n\n", | ||
useTerminalColor ? BOLDRED : "", | ||
Utils.dupChar('!', BORDER_LENGTH), | ||
this.getClass().getSimpleName(), | ||
Utils.dupChar('!', BORDER_LENGTH), | ||
useTerminalColor ? KNRM : "" | ||
); | ||
} | ||
return warningMessage; | ||
} | ||
|
||
/** | ||
* If a tool is either Experimental or Beta, log a warning against use in production a environment. | ||
*/ | ||
protected void printProductionWarning() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
final String warningMessage = getProductionWarning(!(System.console() == null)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this check isn't 100% reliable, I would take it out. Printing the literal codes in non-interactive use is not that big of a deal. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
if (warningMessage != null) { | ||
logger.warn(warningMessage); | ||
} | ||
} | ||
|
||
/** | ||
* @return true if this tool has {@code BetaFeature} status. | ||
*/ | ||
public boolean isBetaFeature() { return this.getClass().getAnnotation(BetaFeature.class) != null; } | ||
|
||
/** | ||
* @return true if this tool has {@code ExperimentalFeature} status. | ||
*/ | ||
public boolean isExperimentalFeature() { return this.getClass().getAnnotation(ExperimentalFeature.class) != null; } | ||
|
||
/** | ||
* @return The name of this toolkit. The default implementation uses "Implementation-Title" from the | ||
* jar manifest, or (if that's not available) the package name. | ||
|
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.
getToolStatusWarning()
might be clearer?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.
Done.