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

Remove the legacy Gradle build lifecycle API #159

Merged
merged 1 commit into from
Feb 16, 2023
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 @@ -61,10 +61,6 @@ class DeployGatePlugin implements Plugin<Project> {
}

private void onProjectEvaluated(Project project) {
project.gradle.buildFinished { buildResult ->
project.deploygate.notifyServer('finished', [result: Boolean.toString(buildResult.failure == null)])
}

processor.registerLoginTask()
processor.registerLogoutTask()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,16 @@ class DeployGateExtension implements ExtensionSyntax {
return deployment
}

def notifyServer(String action, HashMap<String, String> data = null) {
/**
* Notify the plugin's action to the server. Never throw any exception.
*
* @param action an action name in plugin lifecycle.
* @param data a map of key-values
* @return true if the request has been processed regardless of its result, otherwise false.
*/
boolean notifyServer(String action, HashMap<String, String> data = null) {
if (!notifyKey) {
return
return false
}

def request = new NotifyActionRequest(notifyKey, action)
Expand All @@ -167,5 +174,7 @@ class DeployGateExtension implements ExtensionSyntax {
ApiClient.getInstance().notify(request)
} catch (Throwable ignore) {
}

return true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,16 @@ public static ApiClient getInstance() {
build();
}

/**
* Upload the application file to the app owner space
*
* @param appOwnerName an app owner name
* @param apiToken an authorization token
* @param request a request to the server that must contain a file
* @return a successful response that contains a typed json.
* @throws HttpResponseException is thrown if a request is an error inclduing 4xx and 5xx
* @throws NetworkFailure is thrown if a network trouble happens
*/
@SuppressWarnings("RedundantThrows")
@NotNull
public Response<UploadAppResponse> uploadApp(@NotNull String appOwnerName, @NotNull String apiToken, @NotNull UploadAppRequest request) throws HttpResponseException, NetworkFailure {
Expand All @@ -132,6 +142,13 @@ public Response<UploadAppResponse> uploadApp(@NotNull String appOwnerName, @NotN
}
}

/**
* Notify the plugin event to the server
*
* @param request a request to the server that must contain an action name
* @throws HttpResponseException is thrown if a request is an error inclduing 4xx and 5xx
* @throws NetworkFailure is thrown if a network trouble happens
*/
@SuppressWarnings("RedundantThrows")
public void notify(@NotNull NotifyActionRequest request) throws HttpResponseException, NetworkFailure {
HttpPost httpPost = new HttpPost(endpoint + "/cli/notify");
Expand All @@ -146,6 +163,13 @@ public void notify(@NotNull NotifyActionRequest request) throws HttpResponseExce
}
}

/**
* Get the credentials from the server
*
* @param notifyKey a notification key. In general, this is generated in the authentication flow.
* @throws HttpResponseException is thrown if a request is an error inclduing 4xx and 5xx
* @throws NetworkFailure is thrown if a network trouble happens
*/
@NotNull
public Response<GetCredentialsResponse> getCredentials(@NotNull String notifyKey) throws HttpResponseException, NetworkFailure {
URI uri;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,9 @@ abstract class UploadArtifactTask extends DefaultTask {
if (!sent && (Config.shouldOpenAppDetailAfterUpload() || response.typedResponse.application.revision == 1)) {
BrowserUtils.openBrowser "${project.deploygate.endpoint}${response.typedResponse.application.path}"
}
} catch (HttpResponseException e) {
} catch (Throwable e) {
Copy link
Member

Choose a reason for hiding this comment

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

I understand to this change behavior to send to server always.
So, I ask to reason to why aggregate to super class.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We never allow any failure when notifying lifecycle events to the server so it's better to suppress Throwable rather than specifying specific exceptions.

Copy link
Member

Choose a reason for hiding this comment

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

OK, I understand to this change is necessary 👍

logger.debug(e.message, e)
project.deploygate.notifyServer 'upload_finished', ['error': true, message: e.message]
throw new GradleException("${variantName} failed due to: ${e.message}", e)
} catch (NetworkFailure e) {
logger.debug(e.message, e)
throw new GradleException("${variantName} failed due to ${e.message}", e)
}
}
Expand Down