Skip to content

Commit

Permalink
Fix oshi latest dep test (#4993)
Browse files Browse the repository at this point in the history
  • Loading branch information
laurit authored Jan 3, 2022
1 parent 83c94e9 commit a45aaf3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,21 @@ public void afterAgent(Config config) {
// Oshi instrumentation will intercept this call and enable SystemMetrics.
Class<?> oshiSystemInfoClass =
ClassLoader.getSystemClassLoader().loadClass("oshi.SystemInfo");
Method getCurrentPlatformEnumMethod =
oshiSystemInfoClass.getMethod("getCurrentPlatformEnum");
Method getCurrentPlatformEnumMethod = getCurrentPlatformMethod(oshiSystemInfoClass);
getCurrentPlatformEnumMethod.invoke(null);
} catch (Throwable ex) {
// OK
}
}
}

private static Method getCurrentPlatformMethod(Class<?> oshiSystemInfoClass)
throws NoSuchMethodException {
try {
return oshiSystemInfoClass.getMethod("getCurrentPlatformEnum");
} catch (NoSuchMethodException exception) {
// renamed in oshi 6.0.0
return oshiSystemInfoClass.getMethod("getCurrentPlatform");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ public ElementMatcher<TypeDescription> typeMatcher() {
@Override
public void transform(TypeTransformer transformer) {
transformer.applyAdviceToMethod(
isMethod().and(isPublic()).and(isStatic()).and(named("getCurrentPlatformEnum")),
isMethod()
.and(isPublic())
.and(isStatic())
.and(named("getCurrentPlatformEnum").or(named("getCurrentPlatform"))),
this.getClass().getName() + "$GetCurrentPlatformEnumAdvice");
}

Expand Down

0 comments on commit a45aaf3

Please sign in to comment.