|
11 | 11 | import com.sandwich.koan.Koan; |
12 | 12 | import com.sandwich.koan.KoanMethod; |
13 | 13 | import com.sandwich.koan.cmdline.behavior.AbstractArgumentBehavior; |
| 14 | +import com.sandwich.koan.constant.KoanConstants; |
14 | 15 | import com.sandwich.koan.path.PathToEnlightenment; |
15 | 16 | import com.sandwich.koan.path.PathToEnlightenment.Path; |
16 | 17 | import com.sandwich.koan.path.xmltransformation.KoanElementAttributes; |
17 | 18 | import com.sandwich.koan.result.KoanMethodResult; |
18 | 19 | import com.sandwich.koan.result.KoanSuiteResult; |
19 | 20 | import com.sandwich.koan.result.KoanSuiteResult.KoanResultBuilder; |
20 | 21 | import com.sandwich.koan.util.ApplicationUtils; |
| 22 | +import com.sandwich.util.ExceptionUtils; |
21 | 23 | import com.sandwich.util.KoanComparator; |
22 | 24 | import com.sandwich.util.io.CompilationListener; |
23 | 25 | import com.sandwich.util.io.DynamicClassLoader; |
| 26 | +import com.sandwich.util.io.FileUtils; |
24 | 27 | import com.sandwich.util.io.KoanSuiteCompilationListener; |
25 | 28 |
|
26 | 29 | public class RunKoans extends AbstractArgumentBehavior { |
@@ -53,13 +56,7 @@ KoanSuiteResult runKoans() { |
53 | 56 | for (Entry<String, Map<String, KoanElementAttributes>> e : packages.getValue().entrySet()) { |
54 | 57 | String name = e.getKey().substring(e.getKey().lastIndexOf('.')+1); |
55 | 58 | if(failure == null){ |
56 | | - Object suite = constructSuite(loader, e.getKey(), compilationListener); |
57 | | - while(compilationListener.isLastCompilationAttemptFailure()) { |
58 | | - try { |
59 | | - Thread.sleep(1000); |
60 | | - } catch (InterruptedException e1) {} |
61 | | - suite = constructSuite(loader, e.getKey(), compilationListener); |
62 | | - } |
| 59 | + Object suite = safelyConstructSuite(loader, compilationListener, e); |
63 | 60 | final List<KoanElementAttributes> attributes = new ArrayList<KoanElementAttributes>(e.getValue().values()); |
64 | 61 | final List<KoanMethod> methods = mergeJavaFilesMethodsAndThoseInXml(suite, attributes, pathToEnlightement.getOnlyMethodNameToRun()); |
65 | 62 | Collections.sort(methods, new KoanComparator()); |
@@ -90,6 +87,24 @@ KoanSuiteResult runKoans() { |
90 | 87 | .passingCases(passingSuites).remainingCases(failingSuites).build(); |
91 | 88 | } |
92 | 89 |
|
| 90 | + private Object safelyConstructSuite(DynamicClassLoader loader, |
| 91 | + KoanSuiteCompilationListener compilationListener, |
| 92 | + Entry<String, Map<String, KoanElementAttributes>> e) { |
| 93 | + // this is written strangely so stack trace will always be the same when constructSuite fails |
| 94 | + // this permits the app to only show the compilation failure once, despite the fact this |
| 95 | + // is getting hit every second. |
| 96 | + Object suite = null; |
| 97 | + while(suite == null || compilationListener.isLastCompilationAttemptFailure()) { |
| 98 | + suite = constructSuite(loader, e.getKey(), compilationListener); |
| 99 | + if(compilationListener.isLastCompilationAttemptFailure()){ |
| 100 | + try { |
| 101 | + Thread.sleep(1000); |
| 102 | + } catch (InterruptedException e1) {} |
| 103 | + } |
| 104 | + } |
| 105 | + return suite; |
| 106 | + } |
| 107 | + |
93 | 108 | private List<KoanMethod> mergeJavaFilesMethodsAndThoseInXml(Object suite, |
94 | 109 | final List<KoanElementAttributes> attributes, String onlyMethodNameToRun) { |
95 | 110 | final List<KoanMethod> methods = new ArrayList<KoanMethod>(); |
@@ -137,6 +152,16 @@ private Object constructSuite(DynamicClassLoader loader, String className, Compi |
137 | 152 | } |
138 | 153 | } catch (Exception e1) { |
139 | 154 | throw new RuntimeException(e1); |
| 155 | + } catch (Error e1) { |
| 156 | + if(e1.getClass() == Error.class && e1.getMessage().contains("Unresolved compilation problem")) { |
| 157 | + listener.compilationFailed(FileUtils.getSourceFileFromClass(className), |
| 158 | + new String[]{"(compilation yielded a class, but it cannot be cereated)"}, |
| 159 | + -1, "Unable to load class \""+className+"\"." + KoanConstants.EOL + |
| 160 | + ExceptionUtils.convertToPopulatedStackTraceString(e1), e1); |
| 161 | + return null; // just consume this exception, this will have been logged and is handled |
| 162 | + }else{ |
| 163 | + throw new RuntimeException(e1); |
| 164 | + } |
140 | 165 | } |
141 | 166 | return suite; |
142 | 167 | } |
|
0 commit comments