This repository has been archived by the owner on Feb 20, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add dynamic link for byte-buddy-agent in exception message
relates to #326
- Loading branch information
Felix Barnsteiner
committed
Sep 25, 2017
1 parent
22ca415
commit bca5cd5
Showing
4 changed files
with
69 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
stagemonitor-core/src/main/java/org/stagemonitor/core/util/VersionUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package org.stagemonitor.core.util; | ||
|
||
import org.stagemonitor.configuration.source.PropertyFileConfigurationSource; | ||
|
||
import java.util.Properties; | ||
|
||
public final class VersionUtils { | ||
|
||
private VersionUtils() { | ||
} | ||
|
||
public static String getVersionFromPomProperties(Class clazz, String groupId, String artifactId) { | ||
final String classpathLocation = "META-INF/maven/" + groupId + "/" + artifactId + "/pom.properties"; | ||
final Properties pomProperties = PropertyFileConfigurationSource.getFromClasspath(classpathLocation, clazz.getClassLoader()); | ||
if (pomProperties != null) { | ||
return pomProperties.getProperty("version"); | ||
} | ||
return null; | ||
} | ||
|
||
public static String getMavenCentralDownloadLink(String groupId, String artifactId, String version) { | ||
return String.format("http://central.maven.org/maven2/%s/%s/%s/%s-%s.jar", groupId.replace('.', '/'), artifactId, version, artifactId, version); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
stagemonitor-core/src/test/java/org/stagemonitor/core/util/VersionUtilsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.stagemonitor.core.util; | ||
|
||
import net.bytebuddy.ByteBuddy; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class VersionUtilsTest { | ||
|
||
private static final String BYTEBUDDY_GROUP = "net.bytebuddy"; | ||
private static final String VERSION_PATTERN = "\\d\\.\\d+\\.\\d+"; | ||
|
||
@Test | ||
public void getVersionFromPomProperties() throws Exception { | ||
assertThat(VersionUtils.getVersionFromPomProperties(ByteBuddy.class, BYTEBUDDY_GROUP, "byte-buddy")).matches(VERSION_PATTERN); | ||
} | ||
|
||
@Test | ||
public void testGetMavenCentralDownloadLink() throws Exception { | ||
assertThat(VersionUtils.getMavenCentralDownloadLink(BYTEBUDDY_GROUP, "byte-buddy-agent", "1.7.5")) | ||
.isEqualTo("http://central.maven.org/maven2/net/bytebuddy/byte-buddy-agent/1.7.5/byte-buddy-agent-1.7.5.jar"); | ||
} | ||
|
||
@Test | ||
public void testByteBuddyDownloadUrl() throws Exception { | ||
final String byteBuddyVersion = VersionUtils.getVersionFromPomProperties(ByteBuddy.class, BYTEBUDDY_GROUP, "byte-buddy"); | ||
final String mavenCentralDownloadLink = VersionUtils.getMavenCentralDownloadLink(BYTEBUDDY_GROUP, "byte-buddy-agent", byteBuddyVersion); | ||
assertThat(mavenCentralDownloadLink) | ||
.isEqualTo("http://central.maven.org/maven2/net/bytebuddy/byte-buddy-agent/" + byteBuddyVersion + "/byte-buddy-agent-" + byteBuddyVersion + ".jar"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters