Skip to content

Commit

Permalink
Merge pull request #29 from jujiale/main
Browse files Browse the repository at this point in the history
fix: release resource and some other optimize
  • Loading branch information
stateIs0 authored Mar 13, 2024
2 parents a8cd4bf + c5bb69a commit 33c85b6
Showing 1 changed file with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Properties;
Expand Down Expand Up @@ -54,16 +54,16 @@ public void execute() throws MojoExecutionException {
throw new MojoExecutionException("Jar file does not exist: " + jarFile);
}

URLClassLoader urlClassLoader = null;
try {
urlClassLoader = new URLClassLoader(new URL[]{jarFile.toURL()}, Thread.currentThread().getContextClassLoader());
} catch (MalformedURLException e) {
URL resource;
try (URLClassLoader urlClassLoader = new URLClassLoader(new URL[]{jarFile.toURI().toURL()}, Thread.currentThread().getContextClassLoader())) {
resource = urlClassLoader.findResource(PLUGIN_META_FILE_NAME);
} catch (IOException e) {
throw new RuntimeException(e);
}
URL resource = urlClassLoader.findResource(PLUGIN_META_FILE_NAME);

Properties properties = new Properties();
try {
properties.load(resource.openStream());
try(InputStream resourceStream = resource.openStream()) {
properties.load(resourceStream);
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand All @@ -84,14 +84,22 @@ void tryUninstall(String pluginId) throws MojoExecutionException {
return;
}
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
HttpGet uploadFile = new HttpGet(uninstallUrl + "?pluginid=" + pluginId);
HttpGet uploadFile = new HttpGet(uninstallUrl + "?pluginId=" + pluginId);

CloseableHttpResponse response = httpClient.execute(uploadFile);
HttpEntity responseEntity = response.getEntity();

int statusCode = response.getStatusLine().getStatusCode();
if (statusCode != 200) {
String reasonPhrase = response.getStatusLine().getReasonPhrase();
getLog().info("卸载失败. Server response: " + EntityUtils.toString(responseEntity));
throw new MojoExecutionException("Failed to uninstall plugin. Server returned status code: " + statusCode
+ ", reasonPhrase = " + reasonPhrase + ", pluginId = " + pluginId);
}

getLog().info("卸载结束. Server response: " + EntityUtils.toString(responseEntity));
} catch (Exception e) {
throw new MojoExecutionException("Error uploading file", e);
throw new MojoExecutionException("Error uninstall plugin", e);
}

}
Expand Down

0 comments on commit 33c85b6

Please sign in to comment.