use of org.gradle.api.file.EmptyFileVisitor in project gradle by gradle.
the class AbstractFileTree method isEmpty.
@Override
public boolean isEmpty() {
final AtomicBoolean found = new AtomicBoolean();
visit(new EmptyFileVisitor() {
public void visitFile(FileVisitDetails fileDetails) {
found.set(true);
fileDetails.stopVisiting();
}
});
return !found.get();
}
use of org.gradle.api.file.EmptyFileVisitor 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.file.EmptyFileVisitor in project gradle by gradle.
the class DefaultHeaderDependenciesCollector method addIncludeRoots.
private void addIncludeRoots(String taskPath, List<File> includeRoots, final Set<File> headerDependencies) {
for (final File includeRoot : includeRoots) {
logger.info("adding files in {} to header dependencies for {}", includeRoot, taskPath);
directoryFileTreeFactory.create(includeRoot).visit(new EmptyFileVisitor() {
@Override
public void visitFile(FileVisitDetails fileDetails) {
headerDependencies.add(fileDetails.getFile());
}
});
}
}
Aggregations