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

Fix timeout cast exception #685

Merged
merged 5 commits into from
Jan 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import org.gradle.api.logging.LogLevel
import org.gradle.api.tasks.TaskAction
import org.w3c.dom.Element

import java.lang.NumberFormatException
import java.nio.file.Files
import java.nio.file.StandardCopyOption
import java.text.MessageFormat
Expand Down Expand Up @@ -642,8 +643,12 @@ class DeployTask extends AbstractServerTask {
}

long appTimeout = 30 * 1000
if (server.timeout != null && !server.timeout.isEmpty()) {
appTimeout = server.timeout * 1000
try {
if (server.timeout != null && !server.timeout.isEmpty()) {
appTimeout = Long.valueOf(server.timeout) * 1000
}
} catch (NumberFormatException nfe) {
throw new GradleException("The server.timeout parameter " + server.timeout + " could not be parsed into a long value. Ensure the value is formatted correctly.")
}

ServerTask serverTask = createServerTask(project, null) //Using a server task without an opertation to check logs for app start
Expand Down
19 changes: 12 additions & 7 deletions src/main/groovy/io/openliberty/tools/gradle/tasks/DevTask.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class DevTask extends AbstractFeatureTask {
@Option(option = 'libertyDebugPort', description = 'The debug port that you can attach a debugger to. The default value is 7777.')
void setLibertyDebugPort(String libertyDebugPort) {
try {
this.libertyDebugPort = libertyDebugPort.toInteger();
this.libertyDebugPort = Integer.valueOf(libertyDebugPort);
} catch (NumberFormatException e) {
logger.error(String.format("Unexpected value: %s for dev mode option libertyDebugPort. libertyDebugPort should be a valid integer.", libertyDebugPort));
throw e;
Expand All @@ -129,7 +129,7 @@ class DevTask extends AbstractFeatureTask {
@Option(option = 'compileWait', description = 'Time in seconds to wait before processing Java changes and deletions. The default value is 0.5 seconds.')
void setCompileWait(String compileWait) {
try {
this.compileWait = compileWait.toDouble();
this.compileWait = Double.valueOf(compileWait);
} catch (NumberFormatException e) {
logger.error(String.format("Unexpected value: %s for dev mode option compileWait. compileWait should be a valid number.", compileWait));
throw e;
Expand All @@ -141,7 +141,7 @@ class DevTask extends AbstractFeatureTask {
@Option(option = 'verifyAppStartTimeout', description = 'Maximum time to wait (in seconds) to verify that the application has started or updated before running tests. The default value is 30 seconds.')
void setVerifyAppStartTimeout(String verifyAppStartTimeout) {
try {
this.verifyAppStartTimeout = verifyAppStartTimeout.toInteger();
this.verifyAppStartTimeout = Integer.valueOf(verifyAppStartTimeout);
} catch (NumberFormatException e) {
logger.error(String.format("Unexpected value: %s for dev mode option verifyAppStartTimeout. verifyAppStartTimeout should be a valid integer.", verifyAppStartTimeout));
throw e;
Expand All @@ -153,7 +153,7 @@ class DevTask extends AbstractFeatureTask {
@Option(option = 'serverStartTimeout', description = 'Time in seconds to wait while verifying that the server has started. The default value is 90 seconds.')
void setServerStartTimeout(String serverStartTimeout) {
try {
this.serverStartTimeout = serverStartTimeout.toInteger();
this.serverStartTimeout = Integer.valueOf(serverStartTimeout);
} catch (NumberFormatException e) {
logger.error(String.format("Unexpected value: %s for dev mode option serverStartTimeout. serverStartTimeout should be a valid integer.", serverStartTimeout));
throw e;
Expand Down Expand Up @@ -230,7 +230,7 @@ class DevTask extends AbstractFeatureTask {
@Option(option = 'dockerBuildTimeout', description = 'Specifies the amount of time to wait (in seconds) for the completion of the Docker operation to build the image.')
void setDockerBuildTimeout(String inputValue) {
try {
this.dockerBuildTimeout = inputValue.toInteger();
this.dockerBuildTimeout = Integer.valueOf(inputValue);
} catch (NumberFormatException e) {
logger.error(String.format("Unexpected value: %s for dev mode option dockerBuildTimeout. dockerBuildTimeout should be a valid integer.", inputValue));
throw e;
Expand Down Expand Up @@ -924,8 +924,13 @@ class DevTask extends AbstractFeatureTask {
}

if (serverStartTimeout == null) {
if (server.timeout != null && server.timeout.isInteger()) {
serverStartTimeout = server.timeout.toInteger();
if (server.timeout != null && !server.timeout.isEmpty()) {
try {
Copy link
Member

Choose a reason for hiding this comment

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

I don't believe isInteger() is valid on the line before this either. Probably should just check that the string is notEmpty().

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, missed that. Fixed it.

serverStartTimeout = Integer.valueOf(server.timeout);
} catch (NumberFormatException e) {
logger.error(String.format("Unexpected value: %s for dev mode option server.timeout. server.timeout should be a valid integer.", server.timeout));
throw e;
}
} else {
serverStartTimeout = DEFAULT_SERVER_TIMEOUT;
}
Expand Down