Skip to content

Commit

Permalink
[#1975][#1976] minor enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
remkop committed Mar 24, 2023
1 parent a3e3172 commit d436940
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 10 deletions.
2 changes: 1 addition & 1 deletion gradle/release-tasks.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ Release procedure:
8. ./gradlew bumpReadmeVersion
9. update README.md (latest version, release notes)
10. (in new cmd prompt session)
cd picocli-legacy-tests & set JAVA_HOME=C:\apps\jdk1.5.0_22\&& echo ++%JAVA_HOME%++ && gradlew clean build --no-daemon
cd picocli-tests-java567 & set JAVA_HOME=C:\apps\jdk1.5.0_22\&& echo ++%JAVA_HOME%++ && gradlew clean build --no-daemon
11. commit -m "Release picocli version ..."
12. tag v$version
13 ./gradlew publishReleasePublicationToSonatypeRepository - creates a Sonatype staging repository, and uploads artifacts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,25 +360,38 @@ public void testAnsiAutoJansiConsoleInstalledOverridesHintDisabled() {
environmentVariables.clear(ANSI_ENVIRONMENT_VARIABLES);
environmentVariables.set("CLICOLOR", "0"); // hint disabled
System.setProperty("os.name", "Windows");
// Clear the globally cached jansiConsole value that might
// Clear the globally cached jansiInstalled value that might
// have been set in a previous test to force the
// Ansi#isJansiConsoleInstalled method to recalculate
// the cached value.
Ansi.jansiConsole = null;
Ansi.jansiInstalled = null;
assertTrue(Ansi.isWindows());
assertFalse(Ansi.isPseudoTTY());
assertFalse(Ansi.forceDisabled());
assertFalse(Ansi.forceEnabled());
assertTrue(Ansi.hintDisabled());
assertFalse(Ansi.hintEnabled());


// Clear the globally cached jansiInstalled value that might
// have been set in a previous test to force the
// Ansi#isJansiConsoleInstalled method to recalculate
// the cached value.
Ansi.jansiInstalled = null;
assertFalse(Ansi.isJansiConsoleInstalled());
AnsiConsole.systemInstall();
try {

// Clear the cached jansiInstalled value to force the
// Ansi#isJansiConsoleInstalled method to recalculate
Ansi.jansiInstalled = null;
assertTrue(Ansi.isJansiConsoleInstalled());
assertTrue(Ansi.AUTO.enabled());
} finally {
AnsiConsole.systemUninstall();

// Clear the cached jansiInstalled value
Ansi.jansiInstalled = null;
}
}

Expand All @@ -396,6 +409,12 @@ public void testAnsiAutoHintDisabledOverridesHintEnabled() {

assertFalse(Ansi.isJansiConsoleInstalled());

// Clear the globally cached jansiInstalled value that might
// have been set in a previous test to force the
// Ansi#isJansiConsoleInstalled method to recalculate
// the cached value.
Ansi.jansiInstalled = null;

assertFalse(Ansi.forceDisabled());
assertFalse(Ansi.forceEnabled());
assertTrue(Ansi.hintDisabled());
Expand All @@ -413,6 +432,12 @@ public void testAnsiAutoDisabledIfNoTty() {
assertFalse(Ansi.isPseudoTTY());
assertFalse(Ansi.isJansiConsoleInstalled());

// Clear the globally cached jansiInstalled value that might
// have been set in a previous test to force the
// Ansi#isJansiConsoleInstalled method to recalculate
// the cached value.
Ansi.jansiInstalled = null;

assertFalse(Ansi.forceDisabled());
assertFalse(Ansi.forceEnabled());
assertFalse(Ansi.hintDisabled());
Expand All @@ -430,6 +455,12 @@ public void testAnsiAutoEnabledIfNotWindows() {
assertFalse(Ansi.isPseudoTTY()); // TODO Mock this?
assertFalse(Ansi.isJansiConsoleInstalled());

// Clear the globally cached jansiInstalled value that might
// have been set in a previous test to force the
// Ansi#isJansiConsoleInstalled method to recalculate
// the cached value.
Ansi.jansiInstalled = null;

assertFalse(Ansi.forceDisabled());
assertFalse(Ansi.forceEnabled());
assertFalse(Ansi.hintDisabled());
Expand All @@ -445,6 +476,12 @@ public void testAnsiAutoEnabledIfWindowsPseudoTTY() {
assertTrue(Ansi.isWindows());
assertFalse(Ansi.isJansiConsoleInstalled());

// Clear the globally cached jansiInstalled value that might
// have been set in a previous test to force the
// Ansi#isJansiConsoleInstalled method to recalculate
// the cached value.
Ansi.jansiInstalled = null;

assertFalse(Ansi.forceDisabled());
assertFalse(Ansi.forceEnabled());
assertFalse(Ansi.hintDisabled());
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/picocli/CommandLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -17805,12 +17805,12 @@ static boolean ansiPossible() {
if (!isTTY() && !isPseudoTTY()) { return false; }
return hintEnabled() || !isWindows() || isXterm() || isCygwin() || hasOsType();
}
/** Cache the result for isJansiConsoleInstalled so it doesn't repeatedly
/** Caches the result of method isJansiConsoleInstalled so it doesn't repeatedly
* call Class#forName, which can cause performance issues. */
static Boolean jansiConsole;
static Boolean jansiInstalled;
static boolean isJansiConsoleInstalled() {
if (jansiConsole == null) { jansiConsole = calcIsJansiConsoleInstalled(); }
return jansiConsole;
if (jansiInstalled == null) { jansiInstalled = calcIsJansiConsoleInstalled(); }
return jansiInstalled;
}
static boolean calcIsJansiConsoleInstalled() {
try {
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/picocli/HelpAnsiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public void testAnsiEnabled() {

// The previous Ansi.enabled() call caches the result for whether or not jansi is enabled. Reset the cache value
// and force the Ansi.enabled() call to rescan the classpath for the jansi classes.
Ansi.jansiConsole = null;
Ansi.jansiInstalled = null;
try {
assertTrue(Ansi.AUTO.enabled());
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ public void testAmbiguousOptionsDefault() {
//-x -y=123
MyCommand obj = new MyCommand();
CommandLine cmdLine = new CommandLine(obj);
// Clear the globally cached jansiConsole value that might
// Clear the globally cached jansiInstalled value that might
// have been set in a previous test to force the
// Ansi#isJansiConsoleInstalled method to recalculate
// the cached value.
Ansi.jansiConsole = null;
Ansi.jansiInstalled = null;
int exitCode = cmdLine.execute("-x", "-y=123");
assertEquals(2, exitCode);
String expected = String.format("" +
Expand Down

0 comments on commit d436940

Please sign in to comment.