Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

We need to flush our FileWriter's created in cucumber-core #173

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions core/src/main/java/cucumber/formatter/FormatterFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.util.HashMap;
import java.util.Map;

Expand Down Expand Up @@ -36,6 +38,24 @@ private Formatter createFormatterFromClassName(String className, Object out) {
out = new FileWriter(file);
}
}

//Only create a hook if it's a writer that we created.
if (out instanceof Writer) {
final Object hookable = out;
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
Writer writer = (Writer) hookable;
try {
writer.flush();
} catch (IOException e) {
//Oh well? We're kind of shutting down now
}
}
});

}

Class<Formatter> formatterClass = getFormatterClass(className);
// TODO: Remove these if statements. We should fix PrettyFormatter and ProgressFormatter to only take a single Appendable arg.
// Whether or not to use Monochrome is tricky. Maybe always enforce another 2nd argument for that
Expand Down
4 changes: 4 additions & 0 deletions jruby/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@
<java jar="${maven.dependency.org.jruby.jruby-complete.jar.path}" fork="true" failonerror="true" newenvironment="true" maxmemory="512m">
<arg value="-S" />
<arg value="bin/cucumber-jvm" />
<arg value="-f" />
<arg value="json" />
<arg value="-o"/>
<arg value="target/jruby.json"/>
<arg value="--glue" />
<arg value="src/test/resources" />
<arg value="src/test/resources" />
Expand Down