Skip to content

Commit

Permalink
Add classname to signature hash
Browse files Browse the repository at this point in the history
Signed-off-by: Florian Hotze <[email protected]>
  • Loading branch information
florian-h05 committed Nov 9, 2024
1 parent ca6bdfb commit 33ced98
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,14 @@ public void addThingActions(ThingActions thingActions) {
String scope = getScope(thingActions);
if (handler != null && scope != null) {
ThingUID thingUID = handler.getThing().getUID();
Method[] methods = thingActions.getClass().getDeclaredMethods();
Class<?> clazz = thingActions.getClass();
Method[] methods = clazz.getDeclaredMethods();
List<String> actionUIDs = new ArrayList<>();
for (Method method : methods) {
if (!method.isAnnotationPresent(RuleAction.class)) {
continue;
}
actionUIDs.add(annotationActionModuleTypeHelper.getModuleIdFromMethod(scope, method));
actionUIDs.add(annotationActionModuleTypeHelper.getModuleIdFromClassAndMethod(scope, clazz, method));
}
if (actionUIDs.isEmpty()) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public Collection<ModuleInformation> parseAnnotations(String name, Object action
List<Output> outputs = getOutputsFromAction(method);

RuleAction ruleAction = method.getAnnotation(RuleAction.class);
String uid = getModuleIdFromMethod(name, method);
String uid = getModuleIdFromClassAndMethod(name, clazz, method);
Set<String> tags = new HashSet<>(Arrays.asList(ruleAction.tags()));

ModuleInformation mi = new ModuleInformation(uid, actionProvider, method);
Expand All @@ -117,14 +117,15 @@ public Collection<ModuleInformation> parseAnnotations(String name, Object action
return moduleInformation;
}

public String getModuleIdFromMethod(String actionScope, Method method) {
public String getModuleIdFromClassAndMethod(String actionScope, Class<?> clazz, Method method) {
String uid = actionScope + "." + method.getName() + "#";
MessageDigest md5 = null;
try {
md5 = MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
md5.update(clazz.getName().getBytes());
for (Class<?> parameter : method.getParameterTypes()) {
md5.update(parameter.getName().getBytes());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ public class AnnotationActionModuleTypeProviderTest extends JavaTest {
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
for (Class<?> parameter : TestActionProvider.class.getDeclaredMethods()[0].getParameterTypes()) {
Class<?> clazz = AnnotationActionModuleTypeProviderTest.TestActionProvider.class;
md5.update(clazz.getName().getBytes());
for (Class<?> parameter : clazz.getDeclaredMethods()[0].getParameterTypes()) {
md5.update(parameter.getName().getBytes());
}
TEST_ACTION_SIGNATURE_HASH = String.format("%032x", new BigInteger(1, md5.digest()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@ public class AnnotatedThingActionModuleTypeProviderTest extends JavaTest {
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
for (Class<?> parameter : AnnotatedThingActionModuleTypeProviderTest.TestThingActionProvider.class
.getDeclaredMethods()[0].getParameterTypes()) {
Class<?> clazz = AnnotatedThingActionModuleTypeProviderTest.TestThingActionProvider.class;
md5.update(clazz.getName().getBytes());
for (Class<?> parameter : clazz.getDeclaredMethods()[0].getParameterTypes()) {
md5.update(parameter.getName().getBytes());
}
TEST_ACTION_SIGNATURE_HASH = String.format("%032x", new BigInteger(1, md5.digest()));
Expand Down

0 comments on commit 33ced98

Please sign in to comment.