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();
}
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());
}
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);
}
}
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);
}
}
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);
}
}
Aggregations