Search in sources :

Example 1 with UncheckedIOException

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());
}
Also used : UncheckedIOException(org.gradle.api.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(org.gradle.api.UncheckedIOException) MessageDigest(java.security.MessageDigest)

Example 2 with UncheckedIOException

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);
    }
}
Also used : OutputStream(java.io.OutputStream) UncheckedIOException(org.gradle.api.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(org.gradle.api.UncheckedIOException) Socket(java.net.Socket) ConnectException(java.net.ConnectException) PrintWriter(java.io.PrintWriter)

Example 3 with UncheckedIOException

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++;
                }
            }
        }
    };
}
Also used : ClosureBackedAction(org.gradle.api.internal.ClosureBackedAction) Action(org.gradle.api.Action) UncheckedIOException(org.gradle.api.UncheckedIOException) UncheckedIOException(org.gradle.api.UncheckedIOException) IOException(java.io.IOException)

Example 4 with UncheckedIOException

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);
    }
}
Also used : InvalidMavenPublicationException(org.gradle.api.publish.maven.InvalidMavenPublicationException) Model(org.apache.maven.model.Model) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) UncheckedIOException(org.gradle.api.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(org.gradle.api.UncheckedIOException) File(java.io.File)

Example 5 with UncheckedIOException

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);
    }
}
Also used : UncheckedIOException(org.gradle.api.UncheckedIOException) UncheckedIOException(org.gradle.api.UncheckedIOException)

Aggregations

UncheckedIOException (org.gradle.api.UncheckedIOException)82 IOException (java.io.IOException)60 File (java.io.File)25 InputStream (java.io.InputStream)7 OutputStream (java.io.OutputStream)6 FileOutputStream (java.io.FileOutputStream)5 FileInputStream (java.io.FileInputStream)4 URI (java.net.URI)4 URL (java.net.URL)4 ArrayList (java.util.ArrayList)4 Manifest (java.util.jar.Manifest)4 ZipInputStream (java.util.zip.ZipInputStream)4 FileVisitDetails (org.gradle.api.file.FileVisitDetails)4 FileVisitor (org.gradle.api.file.FileVisitor)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 FileReader (java.io.FileReader)3 URISyntaxException (java.net.URISyntaxException)3 Matcher (java.util.regex.Matcher)3 ZipEntry (java.util.zip.ZipEntry)3