Search in sources :

Example 76 with UncheckedIOException

use of org.gradle.api.UncheckedIOException in project gradle by gradle.

the class DefaultUserInputReader method readInput.

@Override
public String readInput() {
    Reader br = new InputStreamReader(System.in);
    StringBuilder out = new StringBuilder();
    while (true) {
        try {
            int c = br.read();
            if (isEOF(c)) {
                return null;
            }
            if (!isLineSeparator((char) c)) {
                out.append((char) c);
            } else {
                break;
            }
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        }
    }
    return out.toString();
}
Also used : InputStreamReader(java.io.InputStreamReader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) UncheckedIOException(org.gradle.api.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(org.gradle.api.UncheckedIOException)

Example 77 with UncheckedIOException

use of org.gradle.api.UncheckedIOException in project gradle by gradle.

the class ApplicationClassesInSystemClassLoaderWorkerImplementationFactory method prepareJavaCommand.

@Override
public void prepareJavaCommand(Object workerId, String displayName, DefaultWorkerProcessBuilder processBuilder, List<URL> implementationClassPath, Address serverAddress, JavaExecHandleBuilder execSpec, boolean publishProcessInfo) {
    Collection<File> applicationClasspath = processBuilder.getApplicationClasspath();
    LogLevel logLevel = processBuilder.getLogLevel();
    Set<String> sharedPackages = processBuilder.getSharedPackages();
    Object requestedSecurityManager = execSpec.getSystemProperties().get("java.security.manager");
    ClassPath workerMainClassPath = classPathRegistry.getClassPath("WORKER_MAIN");
    execSpec.setMain("worker." + GradleWorkerMain.class.getName());
    boolean useOptionsFile = shouldUseOptionsFile(execSpec);
    if (useOptionsFile) {
        // Use an options file to pass across application classpath
        File optionsFile = temporaryFileProvider.createTemporaryFile("gradle-worker-classpath", "txt");
        List<String> jvmArgs = writeOptionsFile(workerMainClassPath.getAsFiles(), applicationClasspath, optionsFile);
        execSpec.jvmArgs(jvmArgs);
    } else {
        // Use a dummy security manager, which hacks the application classpath into the system ClassLoader
        execSpec.classpath(workerMainClassPath.getAsFiles());
        execSpec.systemProperty("java.security.manager", "worker." + BootstrapSecurityManager.class.getName());
    }
    // Serialize configuration for the worker process to it stdin
    StreamByteBuffer buffer = new StreamByteBuffer();
    try {
        DataOutputStream outstr = new DataOutputStream(new EncodedStream.EncodedOutput(buffer.getOutputStream()));
        if (!useOptionsFile) {
            // Serialize the application classpath, this is consumed by BootstrapSecurityManager
            outstr.writeInt(applicationClasspath.size());
            for (File file : applicationClasspath) {
                outstr.writeUTF(file.getAbsolutePath());
            }
            // Serialize the actual security manager type, this is consumed by BootstrapSecurityManager
            outstr.writeUTF(requestedSecurityManager == null ? "" : requestedSecurityManager.toString());
        }
        // Serialize the shared packages, this is consumed by GradleWorkerMain
        outstr.writeInt(sharedPackages.size());
        for (String str : sharedPackages) {
            outstr.writeUTF(str);
        }
        // Serialize the worker implementation classpath, this is consumed by GradleWorkerMain
        outstr.writeInt(implementationClassPath.size());
        for (URL entry : implementationClassPath) {
            outstr.writeUTF(entry.toString());
        }
        // Serialize the worker config, this is consumed by SystemApplicationClassLoaderWorker
        OutputStreamBackedEncoder encoder = new OutputStreamBackedEncoder(outstr);
        encoder.writeSmallInt(logLevel.ordinal());
        encoder.writeBoolean(publishProcessInfo);
        encoder.writeString(gradleUserHomeDir.getAbsolutePath());
        new MultiChoiceAddressSerializer().write(encoder, (MultiChoiceAddress) serverAddress);
        // Serialize the worker, this is consumed by SystemApplicationClassLoaderWorker
        ActionExecutionWorker worker = new ActionExecutionWorker(processBuilder.getWorker(), workerId, displayName, gradleUserHomeDir);
        byte[] serializedWorker = GUtil.serialize(worker);
        encoder.writeBinary(serializedWorker);
        encoder.flush();
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
    execSpec.setStandardInput(buffer.getInputStream());
}
Also used : ClassPath(org.gradle.internal.classpath.ClassPath) EncodedStream(org.gradle.process.internal.streams.EncodedStream) DataOutputStream(java.io.DataOutputStream) StreamByteBuffer(org.gradle.internal.io.StreamByteBuffer) UncheckedIOException(org.gradle.api.UncheckedIOException) UncheckedIOException(org.gradle.api.UncheckedIOException) IOException(java.io.IOException) LogLevel(org.gradle.api.logging.LogLevel) URL(java.net.URL) OutputStreamBackedEncoder(org.gradle.internal.serialize.OutputStreamBackedEncoder) File(java.io.File) MultiChoiceAddressSerializer(org.gradle.internal.remote.internal.inet.MultiChoiceAddressSerializer)

Example 78 with UncheckedIOException

use of org.gradle.api.UncheckedIOException in project gradle by gradle.

the class HtmlReportRenderer method render.

/**
 * Renders a multi-page HTML report from the given model, into the given directory.
 */
public <T> void render(T model, ReportRenderer<T, HtmlReportBuilder> renderer, File outputDirectory) {
    try {
        outputDirectory.mkdirs();
        DefaultHtmlReportContext context = new DefaultHtmlReportContext(outputDirectory);
        renderer.render(model, context);
        for (Resource resource : context.resources.values()) {
            File destFile = new File(outputDirectory, resource.path);
            if (!destFile.exists()) {
                GFileUtils.copyURLToFile(resource.source, destFile);
            }
        }
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
Also used : UncheckedIOException(org.gradle.api.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(org.gradle.api.UncheckedIOException) File(java.io.File)

Example 79 with UncheckedIOException

use of org.gradle.api.UncheckedIOException in project gradle by gradle.

the class DefaultIvyModuleDescriptorWriter method write.

@Override
public void write(IvyModulePublishMetadata module, File output) {
    try {
        output.getParentFile().mkdirs();
        OutputStream outputStream = new FileOutputStream(output);
        try {
            SimpleXmlWriter xmlWriter = new SimpleXmlWriter(outputStream, "  ");
            writeTo(module, xmlWriter);
            xmlWriter.flush();
        } finally {
            outputStream.close();
        }
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
Also used : OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) UncheckedIOException(org.gradle.api.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(org.gradle.api.UncheckedIOException) SimpleXmlWriter(org.gradle.internal.xml.SimpleXmlWriter)

Example 80 with UncheckedIOException

use of org.gradle.api.UncheckedIOException in project gradle by gradle.

the class DefaultCacheAwareExternalResourceAccessor method getResourceSha1.

private HashValue getResourceSha1(ExternalResourceName location, boolean revalidate) {
    try {
        ExternalResourceName sha1Location = location.append(".sha1");
        ExternalResource resource = delegate.resource(sha1Location, revalidate);
        ExternalResourceReadResult<HashValue> result = resource.withContentIfPresent(new Transformer<HashValue, InputStream>() {

            @Override
            public HashValue transform(InputStream inputStream) {
                try {
                    String sha = IOUtils.toString(inputStream, "us-ascii");
                    return HashValue.parse(sha);
                } catch (IOException e) {
                    throw new UncheckedIOException(e);
                }
            }
        });
        return result == null ? null : result.getResult();
    } catch (Exception e) {
        throw new ResourceException(location.getUri(), String.format("Failed to download SHA1 for resource '%s'.", location), e);
    }
}
Also used : ExternalResourceName(org.gradle.internal.resource.ExternalResourceName) InputStream(java.io.InputStream) UncheckedIOException(org.gradle.api.UncheckedIOException) ResourceException(org.gradle.api.resources.ResourceException) UncheckedIOException(org.gradle.api.UncheckedIOException) IOException(java.io.IOException) HashValue(org.gradle.internal.hash.HashValue) LocallyAvailableExternalResource(org.gradle.internal.resource.local.LocallyAvailableExternalResource) ExternalResource(org.gradle.internal.resource.ExternalResource) CachedExternalResource(org.gradle.internal.resource.cached.CachedExternalResource) UncheckedIOException(org.gradle.api.UncheckedIOException) ResourceException(org.gradle.api.resources.ResourceException) IOException(java.io.IOException)

Aggregations

UncheckedIOException (org.gradle.api.UncheckedIOException)101 IOException (java.io.IOException)79 File (java.io.File)32 InputStream (java.io.InputStream)9 FileOutputStream (java.io.FileOutputStream)7 OutputStream (java.io.OutputStream)7 BufferedReader (java.io.BufferedReader)6 StringReader (java.io.StringReader)6 FileInputStream (java.io.FileInputStream)5 Matcher (java.util.regex.Matcher)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)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 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 FileReader (java.io.FileReader)3