Skip to content

Commit 1c12c8a

Browse files
committed
classloading updated to permit method signature changes at runtime
1 parent e9262cd commit 1c12c8a

5 files changed

Lines changed: 15 additions & 142 deletions

File tree

‎koans-lib/src/PathToEnlightment.xml‎

Lines changed: 0 additions & 68 deletions
This file was deleted.

‎koans-lib/src/com/sandwich/koan/path/PathToEnlightenment.java‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import java.util.Map;
1111
import java.util.Map.Entry;
1212

13+
import com.sandwich.koan.Koan;
1314
import com.sandwich.koan.KoanMethod;
1415
import com.sandwich.koan.constant.KoanConstants;
1516
import com.sandwich.koan.path.xmltransformation.XmlToPathTransformer;
@@ -171,9 +172,18 @@ private static List<KoanMethod> copyMethods(Class<?> cls, List<KoanMethod> metho
171172
Map<String, Method> methodByName = new HashMap<String, Method>();
172173
for(Method method : cls.getDeclaredMethods()){
173174
methodByName.put(method.getName(), method);
174-
}
175-
for(KoanMethod method : methodsBySuite){
176-
newMethods.add(method.clone(methodByName.get(method.getMethod().getName())));
175+
KoanMethod equivalentKoanMethod = null;
176+
for(KoanMethod koanMethod : methodsBySuite){
177+
if(koanMethod.getMethod().getName().equals(method.getName())){
178+
equivalentKoanMethod = koanMethod;
179+
break;
180+
}
181+
}
182+
if(equivalentKoanMethod != null && method.getAnnotation(Koan.class) != null){
183+
newMethods.add(equivalentKoanMethod.clone(method));
184+
}else if(method.getAnnotation(Koan.class) != null){
185+
newMethods.add(new KoanMethod("", method));
186+
}
177187
}
178188
} catch (Exception e2) {
179189
throw new RuntimeException(e2);

‎koans-lib/src/com/sandwich/koan/path/xmltransformation/XmlToPathTransformerImpl.java‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ Map<Object, List<KoanMethod>> createSuitesAndKoans(String pkg,
7070
NodeList childNodes) throws DOMException, ClassNotFoundException,
7171
InstantiationException, IllegalAccessException {
7272
Map<Object, List<KoanMethod>> suitesAndKoans = new LinkedHashMap<Object, List<KoanMethod>>();
73+
DynamicClassLoader dynamicClassLoader = new DynamicClassLoader();
7374
for (int i = 0; i < childNodes.getLength(); i++) {
7475
Node node = childNodes.item(i);
7576
if ("suite".equalsIgnoreCase(node.getNodeName())) {
@@ -78,9 +79,7 @@ Map<Object, List<KoanMethod>> createSuitesAndKoans(String pkg,
7879
+ node.getAttributes().getNamedItem("class")
7980
.getNodeValue();
8081
if (suiteName == null || suiteName.equalsIgnoreCase(className)) {
81-
DynamicClassLoader dynamicClassLoader = new DynamicClassLoader();
82-
Class<?> koanSuiteClass = dynamicClassLoader
83-
.loadClass(className);
82+
Class<?> koanSuiteClass = dynamicClassLoader.loadClass(className);
8483
suitesAndKoans.put(koanSuiteClass.newInstance(),
8584
Collections.unmodifiableList(createKoanMethods(
8685
koanSuiteClass, node.getChildNodes())));

‎koans-tests/PathToEnlightment.xml‎

Lines changed: 0 additions & 68 deletions
This file was deleted.

‎koans/lib/koans.jar‎

-973 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)