Skip to content

Commit

Permalink
Fix getting hibernate version hazelcast#286
Browse files Browse the repository at this point in the history
  • Loading branch information
ldziedziul committed May 29, 2024
1 parent b94bf40 commit cdad27d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.net.URLClassLoader;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.Properties;
import java.util.jar.Attributes;
import java.util.jar.Manifest;

/**
* Creates query string according to plugin properties to be sent to phone home
Expand Down Expand Up @@ -73,11 +77,24 @@ private String buildQueryString(boolean isLocalRegion) {
// especially for the parameter keys.
return new QueryStringBuilder()
.addParam("version", version)
.addParam("hibernate-version", Hibernate.class.getPackage().getImplementationVersion())
.addParam("hibernate-version", getHibernateVersion())
.addParam("region-type", isLocalRegion ? "local" : "distributed")
.build();
}

private static String getHibernateVersion() {
URL hibernateJar = Hibernate.class.getProtectionDomain().getCodeSource().getLocation();
try (URLClassLoader classLoader = new URLClassLoader(new URL[]{hibernateJar})) {
URL url = classLoader.findResource("META-INF/MANIFEST.MF");
Manifest manifest = new Manifest(url.openStream());
Attributes mainAttributes = manifest.getMainAttributes();
return mainAttributes.getValue("Implementation-Version");

} catch (IOException e) {
throw new RuntimeException(e);
}
}

/**
* Constructs query string using the added parameters.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import static java.util.stream.Collectors.toMap;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

Expand Down Expand Up @@ -63,6 +64,7 @@ private void verifyQueryString(boolean isLocalRegion, String queryString) {
assertEquals(3, parameters.size());
assertEquals(isLocalRegion ? "local" : "distributed", parameters.get("region-type"));
assertEquals(resolvedPluginVersion, parameters.get("version"));
assertNotNull(Hibernate.class.getPackage().getImplementationVersion());
assertEquals(Hibernate.class.getPackage().getImplementationVersion(), parameters.get("hibernate-version"));
assertNotEquals("N/A", resolvedPluginVersion);
}
Expand Down

0 comments on commit cdad27d

Please sign in to comment.