use of org.gradle.api.Transformer in project gradle by gradle.
the class JUnitTestClassExecuter method runTestClass.
private void runTestClass(String testClassName) throws ClassNotFoundException {
final Class<?> testClass = Class.forName(testClassName, false, applicationClassLoader);
List<Filter> filters = new ArrayList<Filter>();
if (options.hasCategoryConfiguration()) {
verifyJUnitCategorySupport();
Transformer<Class<?>, String> transformer = new Transformer<Class<?>, String>() {
public Class<?> transform(final String original) {
try {
return applicationClassLoader.loadClass(original);
} catch (ClassNotFoundException e) {
throw new InvalidUserDataException(String.format("Can't load category class [%s].", original), e);
}
}
};
filters.add(new CategoryFilter(CollectionUtils.collect(options.getIncludeCategories(), transformer), CollectionUtils.collect(options.getExcludeCategories(), transformer)));
}
Request request = Request.aClass(testClass);
Runner runner = request.getRunner();
if (!options.getIncludedTests().isEmpty()) {
TestSelectionMatcher matcher = new TestSelectionMatcher(options.getIncludedTests());
// matches the filter, run the entire suite instead of filtering away its contents.
if (!runner.getDescription().isSuite() || !matcher.matchesTest(testClassName, null)) {
filters.add(new MethodNameFilter(matcher));
}
}
if (runner instanceof Filterable) {
Filterable filterable = (Filterable) runner;
for (Filter filter : filters) {
try {
filterable.filter(filter);
} catch (NoTestsRemainException e) {
// Ignore
return;
}
}
} else if (allTestsFiltered(runner, filters)) {
return;
}
RunNotifier notifier = new RunNotifier();
notifier.addListener(listener);
runner.run(notifier);
}
use of org.gradle.api.Transformer in project gradle by gradle.
the class WatchServicePoller method handleWatchKey.
private List<FileWatcherEvent> handleWatchKey(WatchKey watchKey) {
final Path watchedPath = (Path) watchKey.watchable();
Transformer<FileWatcherEvent, WatchEvent<?>> watchEventTransformer = new Transformer<FileWatcherEvent, WatchEvent<?>>() {
@Override
public FileWatcherEvent transform(WatchEvent<?> event) {
WatchEvent.Kind kind = event.kind();
File file = null;
if (kind.type() == Path.class) {
WatchEvent<Path> ev = Cast.uncheckedCast(event);
file = watchedPath.resolve(ev.context()).toFile();
}
return toEvent(kind, file);
}
};
List<WatchEvent<?>> watchEvents = watchKey.pollEvents();
watchKey.reset();
if (watchEvents.isEmpty()) {
return Collections.singletonList(FileWatcherEvent.delete(watchedPath.toFile()));
} else {
return CollectionUtils.collect(watchEvents, watchEventTransformer);
}
}
use of org.gradle.api.Transformer in project gradle by gradle.
the class GenerateModuleMapFile method generateFile.
public static void generateFile(File moduleMapFile, String moduleName, List<String> publicHeaderDirs) {
List<String> lines = Lists.newArrayList("module " + moduleName + " {");
List<String> validHeaderDirs = filter(publicHeaderDirs, new Spec<String>() {
@Override
public boolean isSatisfiedBy(String path) {
return new File(path).exists();
}
});
lines.addAll(collect(validHeaderDirs, new Transformer<String, String>() {
@Override
public String transform(String path) {
return "\tumbrella \"" + path + "\"";
}
}));
lines.add("\texport *");
lines.add("}");
try {
Files.createParentDirs(moduleMapFile);
FileUtils.writeLines(moduleMapFile, lines);
} catch (IOException e) {
throw new UncheckedIOException("Could not generate a module map for " + moduleName, e);
}
}
use of org.gradle.api.Transformer in project gradle by gradle.
the class PCHUtils method getHeaderToSourceFileTransformer.
public static <T extends NativeCompileSpec> Transformer<T, T> getHeaderToSourceFileTransformer(Class<T> type) {
return new Transformer<T, T>() {
@Override
public T transform(T original) {
List<File> newSourceFiles = Lists.newArrayList();
for (File sourceFile : original.getSourceFiles()) {
newSourceFiles.add(generatePCHSourceFile(original, sourceFile));
}
original.setSourceFiles(newSourceFiles);
return original;
}
};
}
use of org.gradle.api.Transformer in project gradle by gradle.
the class DefaultIdeArtifactRegistry method getIdeProjectFiles.
@Override
public FileCollection getIdeProjectFiles(final Class<? extends IdeProjectMetadata> type) {
return fileOperations.immutableFiles(new Callable<List<FileCollection>>() {
@Override
public List<FileCollection> call() {
return CollectionUtils.collect(getIdeProjects(type), new Transformer<FileCollection, Reference<?>>() {
@Override
public FileCollection transform(Reference<?> result) {
ConfigurableFileCollection singleton = fileOperations.configurableFiles(result.get().getFile());
singleton.builtBy(result.get().getGeneratorTasks());
return singleton;
}
});
}
});
}
Aggregations