use of org.gradle.api.UncheckedIOException in project gradle by gradle.
the class HashUtil method createHash.
public static HashValue createHash(InputStream instr, String algorithm) {
MessageDigest messageDigest;
try {
messageDigest = createMessageDigest(algorithm);
byte[] buffer = new byte[4096];
try {
while (true) {
int nread = instr.read(buffer);
if (nread < 0) {
break;
}
messageDigest.update(buffer, 0, nread);
}
} finally {
instr.close();
}
} catch (IOException e) {
throw new UncheckedIOException(e);
}
return new HashValue(messageDigest.digest());
}
use of org.gradle.api.UncheckedIOException in project gradle by gradle.
the class Snarl method send.
private void send(InetAddress host, final String title, final String message) {
Socket socket = null;
try {
try {
socket = new Socket(host, 9887);
} catch (ConnectException e) {
// Snarl is not running
throw new AnnouncerUnavailableException("Snarl is not running on host " + String.valueOf(host) + ".", e);
}
PrintWriter printWriter = null;
try {
final OutputStream outputStream = socket.getOutputStream();
printWriter = new PrintWriter(outputStream, true);
printWriter.println(formatMessage(title, message));
} catch (IOException e) {
throw new UncheckedIOException(e);
} finally {
IOUtils.closeQuietly(printWriter);
}
} catch (IOException ioException) {
throw new UncheckedIOException(ioException);
} finally {
IOUtils.closeQuietly(socket);
}
}
use of org.gradle.api.UncheckedIOException in project gradle by gradle.
the class AbstractGradleExecuter method getResultAssertion.
protected Action<ExecutionResult> getResultAssertion() {
return new Action<ExecutionResult>() {
int expectedDeprecationWarnings = AbstractGradleExecuter.this.expectedDeprecationWarnings;
boolean expectStackTraces = !AbstractGradleExecuter.this.stackTraceChecksOn;
boolean checkDeprecations = AbstractGradleExecuter.this.checkDeprecations;
@Override
public void execute(ExecutionResult executionResult) {
validate(executionResult.getNormalizedOutput(), "Standard output");
String error = executionResult.getError();
if (executionResult instanceof ExecutionFailure) {
// Axe everything after the expected exception
int pos = error.indexOf("* Exception is:\n");
if (pos >= 0) {
error = error.substring(0, pos);
}
}
validate(error, "Standard error");
}
private void validate(String output, String displayName) {
List<String> lines;
try {
lines = CharSource.wrap(output).readLines();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
int i = 0;
while (i < lines.size()) {
String line = lines.get(i);
if (line.matches(".*use(s)? or override(s)? a deprecated API\\.")) {
// A javac warning, ignore
i++;
} else if (line.matches(".*\\s+deprecated.*")) {
if (checkDeprecations && expectedDeprecationWarnings <= 0) {
throw new AssertionError(String.format("%s line %d contains a deprecation warning: %s%n=====%n%s%n=====%n", displayName, i + 1, line, output));
}
expectedDeprecationWarnings--;
// skip over stack trace
i++;
while (i < lines.size() && STACK_TRACE_ELEMENT.matcher(lines.get(i)).matches()) {
i++;
}
} else if (!expectStackTraces && STACK_TRACE_ELEMENT.matcher(line).matches() && i < lines.size() - 1 && STACK_TRACE_ELEMENT.matcher(lines.get(i + 1)).matches()) {
// 2 or more lines that look like stack trace elements
throw new AssertionError(String.format("%s line %d contains an unexpected stack trace: %s%n=====%n%s%n=====%n", displayName, i + 1, line, output));
} else {
i++;
}
}
}
};
}
use of org.gradle.api.UncheckedIOException in project gradle by gradle.
the class ValidatingMavenPublisher method parsePomFileIntoMavenModel.
private Model parsePomFileIntoMavenModel(MavenNormalizedPublication publication) {
File pomFile = publication.getPomFile();
try {
Model model = readModelFromPom(pomFile);
model.setPomFile(pomFile);
return model;
} catch (XmlPullParserException parseException) {
throw new InvalidMavenPublicationException(publication.getName(), "POM file is invalid. Check any modifications you have made to the POM file.", parseException);
} catch (IOException ex) {
throw new UncheckedIOException(ex);
}
}
use of org.gradle.api.UncheckedIOException in project gradle by gradle.
the class StreamBackedStandardOutputListener method onOutput.
public void onOutput(CharSequence output) {
try {
appendable.append(output);
flushable.flush();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
Aggregations