use of org.gradle.api.UncheckedIOException in project gradle by gradle.
the class DaemonStartupCommunication method readDiagnostics.
public DaemonStartupInfo readDiagnostics(String message) {
// Assuming the message has correct format. Not bullet proof, but seems to work ok for now.
if (!message.startsWith(daemonGreeting())) {
throw new IllegalArgumentException(String.format("Unexpected daemon startup message: %s", message));
}
try {
String encoded = message.substring(daemonGreeting().length()).trim();
InputStream inputStream = new EncodedStream.EncodedInput(new ByteArrayInputStream(encoded.getBytes()));
Decoder decoder = new InputStreamBackedDecoder(inputStream);
String pidString = decoder.readNullableString();
String uid = decoder.readString();
Long pid = pidString == null ? null : Long.valueOf(pidString);
Address address = new MultiChoiceAddressSerializer().read(decoder);
File daemonLog = new File(decoder.readString());
return new DaemonStartupInfo(uid, address, new DaemonDiagnostics(daemonLog, pid));
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
use of org.gradle.api.UncheckedIOException in project gradle by gradle.
the class DefaultDaemonStarter method startDaemon.
public DaemonStartupInfo startDaemon(boolean singleUse) {
String daemonUid = UUID.randomUUID().toString();
GradleInstallation gradleInstallation = CurrentGradleInstallation.get();
ModuleRegistry registry = new DefaultModuleRegistry(gradleInstallation);
ClassPath classpath;
List<File> searchClassPath;
if (gradleInstallation == null) {
// When not running from a Gradle distro, need runtime impl for launcher plus the search path to look for other modules
classpath = ClassPath.EMPTY;
for (Module module : registry.getModule("gradle-launcher").getAllRequiredModules()) {
classpath = classpath.plus(module.getClasspath());
}
searchClassPath = registry.getAdditionalClassPath().getAsFiles();
} else {
// When running from a Gradle distro, only need launcher jar. The daemon can find everything from there.
classpath = registry.getModule("gradle-launcher").getImplementationClasspath();
searchClassPath = Collections.emptyList();
}
if (classpath.isEmpty()) {
throw new IllegalStateException("Unable to construct a bootstrap classpath when starting the daemon");
}
versionValidator.validate(daemonParameters);
List<String> daemonArgs = new ArrayList<String>();
daemonArgs.add(daemonParameters.getEffectiveJvm().getJavaExecutable().getAbsolutePath());
List<String> daemonOpts = daemonParameters.getEffectiveJvmArgs();
daemonArgs.addAll(daemonOpts);
daemonArgs.add("-cp");
daemonArgs.add(CollectionUtils.join(File.pathSeparator, classpath.getAsFiles()));
if (Boolean.getBoolean("org.gradle.daemon.debug")) {
daemonArgs.add("-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005");
}
LOGGER.debug("Using daemon args: {}", daemonArgs);
daemonArgs.add(GradleDaemon.class.getName());
// Version isn't used, except by a human looking at the output of jps.
daemonArgs.add(GradleVersion.current().getVersion());
// Serialize configuration to daemon via the process' stdin
StreamByteBuffer buffer = new StreamByteBuffer();
FlushableEncoder encoder = new KryoBackedEncoder(new EncodedStream.EncodedOutput(buffer.getOutputStream()));
try {
encoder.writeString(daemonParameters.getGradleUserHomeDir().getAbsolutePath());
encoder.writeString(daemonDir.getBaseDir().getAbsolutePath());
encoder.writeSmallInt(daemonParameters.getIdleTimeout());
encoder.writeSmallInt(daemonParameters.getPeriodicCheckInterval());
encoder.writeBoolean(singleUse);
encoder.writeString(daemonUid);
encoder.writeSmallInt(daemonOpts.size());
for (String daemonOpt : daemonOpts) {
encoder.writeString(daemonOpt);
}
encoder.writeSmallInt(searchClassPath.size());
for (File file : searchClassPath) {
encoder.writeString(file.getAbsolutePath());
}
encoder.flush();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
InputStream stdInput = buffer.getInputStream();
return startProcess(daemonArgs, daemonDir.getVersionedDir(), stdInput);
}
use of org.gradle.api.UncheckedIOException in project gradle by gradle.
the class ValidateTaskProperties method validateTaskClasses.
private void validateTaskClasses(final ClassLoader classLoader) throws IOException {
final Map<String, Boolean> taskValidationProblems = Maps.newTreeMap();
final Class<?> taskInterface;
final Method validatorMethod;
try {
taskInterface = classLoader.loadClass(Task.class.getName());
Class<?> validatorClass = classLoader.loadClass("org.gradle.api.internal.tasks.properties.PropertyValidationAccess");
validatorMethod = validatorClass.getMethod("collectTaskValidationProblems", Class.class, Map.class);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
} catch (NoSuchMethodException e) {
throw new RuntimeException(e);
}
getClasses().getAsFileTree().visit(new EmptyFileVisitor() {
@Override
public void visitFile(FileVisitDetails fileDetails) {
if (!fileDetails.getPath().endsWith(".class")) {
return;
}
ClassReader reader;
try {
reader = new PatchedClassReader(Files.asByteSource(fileDetails.getFile()).read());
} catch (IOException e) {
throw new UncheckedIOException(e);
}
List<String> classNames = Lists.newArrayList();
reader.accept(new TaskNameCollectorVisitor(classNames), ClassReader.SKIP_CODE);
for (String className : classNames) {
Class<?> clazz;
try {
clazz = classLoader.loadClass(className);
} catch (IllegalAccessError e) {
throw new GradleException("Could not load class: " + className, e);
} catch (ClassNotFoundException e) {
throw new GradleException("Could not load class: " + className, e);
} catch (NoClassDefFoundError e) {
throw new GradleException("Could not load class: " + className, e);
}
if (!Modifier.isPublic(clazz.getModifiers())) {
continue;
}
if (Modifier.isAbstract(clazz.getModifiers())) {
continue;
}
if (!taskInterface.isAssignableFrom(clazz)) {
continue;
}
Class<? extends Task> taskClass = Cast.uncheckedCast(clazz);
try {
validatorMethod.invoke(null, taskClass, taskValidationProblems);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
} catch (InvocationTargetException e) {
throw new RuntimeException(e);
}
}
}
});
List<String> problemMessages = toProblemMessages(taskValidationProblems);
storeResults(problemMessages);
communicateResult(problemMessages, taskValidationProblems.values().contains(Boolean.TRUE));
}
use of org.gradle.api.UncheckedIOException in project gradle by gradle.
the class SwiftcMetadataProvider method parseCompilerOutput.
@Override
protected SwiftcMetadata parseCompilerOutput(String stdout, String stderr, File swiftc) {
BufferedReader reader = new BufferedReader(new StringReader(stdout));
try {
String line;
while ((line = reader.readLine()) != null) {
if (line.contains("Swift version")) {
String[] tokens = line.split(" ");
// Assuming format: 'Swift version 4.0.2 (...)'
int i = 2;
if ("Apple".equals(tokens[0])) {
// Actual format: 'Apple Swift version 4.0.2 (...)'
i++;
}
VersionNumber version = VersionNumber.parse(tokens[i]);
return new DefaultSwiftcMetadata(line, version);
}
}
throw new BrokenResultException(String.format("Could not determine %s metadata: %s produced unexpected output.", getCompilerType().getDescription(), swiftc.getName()));
} catch (IOException e) {
// Should not happen when reading from a StringReader
throw new UncheckedIOException(e);
}
}
use of org.gradle.api.UncheckedIOException in project gradle by gradle.
the class FileBackedBlockStore method open.
public void open(Runnable runnable, Factory factory) {
this.factory = factory;
try {
cacheFile.getParentFile().mkdirs();
file = new RandomAccessFile(cacheFile, "rw");
output = new ByteOutput(file);
input = new ByteInput(file);
currentFileSize = file.length();
nextBlock = currentFileSize;
if (currentFileSize == 0) {
runnable.run();
}
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
Aggregations