use of org.jruby.exceptions.RaiseException in project gocd by gocd.
the class HtmlSaxPushParser method native_write.
@JRubyMethod
public IRubyObject native_write(ThreadContext context, IRubyObject chunk, IRubyObject isLast) {
try {
initialize_task(context);
} catch (IOException e) {
throw context.getRuntime().newRuntimeError(e.getMessage());
}
byte[] data = null;
if (chunk instanceof RubyString || chunk.respondsTo("to_str")) {
data = chunk.convertToString().getBytes();
} else {
terminateTask(context);
XmlSyntaxError xmlSyntaxError = (XmlSyntaxError) NokogiriService.XML_SYNTAXERROR_ALLOCATOR.allocate(context.getRuntime(), getNokogiriClass(context.getRuntime(), "Nokogiri::HTML::SyntaxError"));
throw new RaiseException(xmlSyntaxError);
}
int errorCount0 = parserTask.getErrorCount();
;
if (isLast.isTrue()) {
IRubyObject document = invoke(context, this, "document");
invoke(context, document, "end_document");
terminateTask(context);
} else {
try {
Future<Void> task = stream.addChunk(new ByteArrayInputStream(data));
task.get();
} catch (ClosedStreamException ex) {
// this means the stream is closed, ignore this exception
} catch (Exception e) {
throw context.getRuntime().newRuntimeError(e.getMessage());
}
}
if (!options.recover && parserTask.getErrorCount() > errorCount0) {
terminateTask(context);
throw new RaiseException(parserTask.getLastError(), true);
}
return this;
}
use of org.jruby.exceptions.RaiseException in project gocd by gocd.
the class XmlSaxPushParser method native_write.
@JRubyMethod
public IRubyObject native_write(ThreadContext context, IRubyObject chunk, IRubyObject isLast) {
try {
initialize_task(context);
} catch (IOException e) {
throw context.getRuntime().newRuntimeError(e.getMessage());
}
byte[] data = null;
if (chunk instanceof RubyString || chunk.respondsTo("to_str")) {
data = chunk.convertToString().getBytes();
} else {
terminateTask(context);
XmlSyntaxError xmlSyntaxError = (XmlSyntaxError) NokogiriService.XML_SYNTAXERROR_ALLOCATOR.allocate(context.getRuntime(), getNokogiriClass(context.getRuntime(), "Nokogiri::XML::SyntaxError"));
throw new RaiseException(xmlSyntaxError);
}
int errorCount0 = parserTask.getErrorCount();
;
if (isLast.isTrue()) {
IRubyObject document = invoke(context, this, "document");
invoke(context, document, "end_document");
terminateTask(context);
} else {
try {
Future<Void> task = stream.addChunk(new ByteArrayInputStream(data));
task.get();
} catch (ClosedStreamException ex) {
// this means the stream is closed, ignore this exception
} catch (Exception e) {
throw context.getRuntime().newRuntimeError(e.getMessage());
}
}
if (!options.recover && parserTask.getErrorCount() > errorCount0) {
terminateTask(context);
throw new RaiseException(parserTask.getLastError(), true);
}
return this;
}
use of org.jruby.exceptions.RaiseException in project gocd by gocd.
the class XmlSchema method from_document.
/*
* call-seq:
* from_document(doc)
*
* Create a new Schema from the Nokogiri::XML::Document +doc+
*/
@JRubyMethod(meta = true)
public static IRubyObject from_document(ThreadContext context, IRubyObject klazz, IRubyObject document) {
XmlDocument doc = ((XmlDocument) ((XmlNode) document).document(context));
RubyArray errors = (RubyArray) doc.getInstanceVariable("@errors");
if (!errors.isEmpty()) {
throw new RaiseException((XmlSyntaxError) errors.first());
}
DOMSource source = new DOMSource(doc.getDocument());
IRubyObject uri = doc.url(context);
if (!uri.isNil()) {
source.setSystemId(uri.convertToString().asJavaString());
}
return getSchema(context, (RubyClass) klazz, source);
}
use of org.jruby.exceptions.RaiseException in project gocd by gocd.
the class XmlNode method process_xincludes.
/**
* call-seq:
* process_xincludes(options)
*
* Loads and substitutes all xinclude elements below the node. The
* parser context will be initialized with +options+.
*
*/
@JRubyMethod(visibility = Visibility.PRIVATE)
public IRubyObject process_xincludes(ThreadContext context, IRubyObject options) {
XmlDocument xmlDocument = (XmlDocument) document(context);
RubyArray errors = (RubyArray) xmlDocument.getInstanceVariable("@errors");
while (errors.getLength() > 0) {
XmlSyntaxError error = (XmlSyntaxError) errors.shift(context);
if (error.toString().contains("Include operation failed")) {
throw new RaiseException(error);
}
}
return this;
}
use of org.jruby.exceptions.RaiseException in project enumerable by hraberg.
the class RubySpecTestBase method mspec.
void mspec(List<String> files) throws Exception {
StringWriter stdout = new StringWriter();
StringWriter stderr = new StringWriter();
Writer originalOut = rb.getContext().getWriter();
Writer originalErr = rb.getContext().getErrorWriter();
if (!specdoc)
rb.getContext().setWriter(stdout);
if (!debug)
rb.getContext().setErrorWriter(stderr);
try {
// We need to trick MSpec into thinking we're running a real ruby
eval("RUBY_EXE = '/usr/bin/jruby'");
// While telling it we're not, to skip specs for our "platform"
eval("RUBY_PLATFORM = 'enumerable_java'");
// We support Enumerable from 1.8.8
eval("RUBY_VERSION = '1.8.8'");
require("mspec");
require("mspec/utils/script");
// Identity won't work as JRuby will turn Ruby objects into Java
// and then back again.
eval("class EqualMatcher; def matches?(actual); @actual = actual; @actual == @expected; end; end");
eval("formatter = SpecdocFormatter.new; formatter.register;");
eval("MSpec.store :formatter, formatter");
eval("MSpec.register_files " + files);
eval("MSpec.process");
try {
eval("raise formatter.exceptions[0] unless MSpec.exit_code == 0");
} catch (RaiseException e) {
try {
fail(e.getException().message.asJavaString());
} catch (AssertionError error) {
error.setStackTrace(e.getStackTrace());
throw error;
}
}
} catch (ScriptException e) {
out.println(stdout.toString());
err.println(stderr.toString());
throw uncheck(e);
} finally {
rb.getContext().setWriter(originalOut);
rb.getContext().setErrorWriter(originalErr);
eval("MSpec.unregister :exception, formatter; MSpec.unregister :before, formatter; " + "MSpec.unregister :after, formatter; MSpec.unregister :finish, formatter; " + "MSpec.unregister :enter, formatter; MSpec.register_exit(nil); " + "MSpec.clear_current; MSpec.clear_modes; MSpec.clear_expectations");
}
}
Aggregations