Skip to content

Commit

Permalink
DWR-660 retain member order in generated scripts between runs
Browse files Browse the repository at this point in the history
- sort method names inside dwr interfaces so that content doesn't
  change between application runs
- allows consistent content hashing
  • Loading branch information
Jiří Pejchal committed Nov 17, 2020
1 parent c1d9375 commit 0968905
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions core/impl/main/java/org/directwebremoting/impl/DefaultRemoter.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.directwebremoting.impl;

import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Map;
import java.util.Map.Entry;

Expand Down Expand Up @@ -64,6 +66,18 @@ public String generateInterfaceJavaScript(String scriptName, String indent, Stri
Module module = moduleManager.getModule(scriptName, false);

MethodDeclaration[] methods = module.getMethods();
Arrays.sort(methods, new Comparator<MethodDeclaration>()
{
@Override
public int compare(MethodDeclaration m1, MethodDeclaration m2)
{
int i = m1.getName().compareTo(m2.getName());
if (i != 0) {
return i;
}
return Integer.compare(m1.getParameterTypes().length, m2.getParameterTypes().length);
}
});
for (MethodDeclaration method : methods)
{
String methodName = method.getName();
Expand Down

0 comments on commit 0968905

Please sign in to comment.