Skip to content

Commit

Permalink
file monitor was taking effect even in non-interactive mode
Browse files Browse the repository at this point in the history
  • Loading branch information
matyb committed Apr 14, 2016
1 parent db98b66 commit 994ccac
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 16 deletions.
Binary file modified koans/app/lib/koans.jar
Binary file not shown.
20 changes: 11 additions & 9 deletions lib/src/main/java/com/sandwich/koan/runner/RunKoans.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,15 @@ public RunKoans(Path pathToEnlightenment){
}

public void run(String... values) {
ApplicationUtils.getPresenter().clearMessages();
KoanSuiteResult result = runKoans();
ApplicationUtils.getPresenter().displayResult(result);
if (!ApplicationSettings.isInteractive()) {
// could overflow past 255 resulting in 0 (ie all koans succeed) or misleading # of failed koans
int numberOfFailingKoans = Math.min(255, result.getTotalNumberOfKoans() - result.getNumberPassing());
System.err.println(numberOfFailingKoans);
AppLauncher.exit(numberOfFailingKoans);
ApplicationUtils.getPresenter().clearMessages();
KoanSuiteResult result = runKoans();
ApplicationUtils.getPresenter().displayResult(result);
if (!ApplicationSettings.isInteractive()) {
// could overflow past 255 resulting in 0 (ie all koans succeed)
// or otherwise misleading # of failed koans
AppLauncher.exit(Math.min(255, result.getTotalNumberOfKoans() - result.getNumberPassing()));
}
}
}

KoanSuiteResult runKoans() {
List<String> passingSuites = new ArrayList<String>();
Expand Down Expand Up @@ -109,6 +108,9 @@ private Object safelyConstructSuite(DynamicClassLoader loader,
while(suite == null || compilationListener.isLastCompilationAttemptFailure()) {
suite = constructSuite(loader, e.getKey(), compilationListener);
if(compilationListener.isLastCompilationAttemptFailure()){
if(!ApplicationSettings.isInteractive()){
AppLauncher.exit(255);
}
try {
Thread.sleep(1000);
} catch (InterruptedException e1) {}
Expand Down
20 changes: 13 additions & 7 deletions lib/src/main/java/com/sandwich/util/io/FileMonitorFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import java.util.Map;
import java.util.Map.Entry;

import com.sandwich.koan.ApplicationSettings;

public class FileMonitorFactory {

private static Map<String, FileMonitor> monitors = new LinkedHashMap<String, FileMonitor>();
Expand All @@ -22,22 +24,26 @@ public void run() {
Thread pollingThread = new Thread(new Runnable(){
public void run() {
do{
try {
Thread.sleep(SLEEP_TIME_IN_MS);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
if(ApplicationSettings.isInteractive()){
try {
Thread.sleep(SLEEP_TIME_IN_MS);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
for(Entry<String, FileMonitor> filePathAndMonitor : monitors.entrySet()){
FileMonitor monitor = filePathAndMonitor.getValue();
if(monitor != null){
monitor.notifyListeners();
}
}
}while(true);
}while(ApplicationSettings.isInteractive());
}
});
pollingThread.setName("FileMonitorPolling");
pollingThread.start();
if (ApplicationSettings.isInteractive()) {
pollingThread.start();
}
}

public static FileMonitor getInstance(File monitoredFile, File dataFile) {
Expand Down

0 comments on commit 994ccac

Please sign in to comment.