Search in sources :

Example 1 with Transformer

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);
}
Also used : Runner(org.junit.runner.Runner) Transformer(org.gradle.api.Transformer) RunNotifier(org.junit.runner.notification.RunNotifier) ArrayList(java.util.ArrayList) Request(org.junit.runner.Request) NoTestsRemainException(org.junit.runner.manipulation.NoTestsRemainException) TestSelectionMatcher(org.gradle.api.internal.tasks.testing.filter.TestSelectionMatcher) Filter(org.junit.runner.manipulation.Filter) InvalidUserDataException(org.gradle.api.InvalidUserDataException) Filterable(org.junit.runner.manipulation.Filterable)

Example 2 with Transformer

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);
    }
}
Also used : Path(java.nio.file.Path) Transformer(org.gradle.api.Transformer) WatchEvent(java.nio.file.WatchEvent) File(java.io.File) FileWatcherEvent(org.gradle.internal.filewatch.FileWatcherEvent)

Example 3 with Transformer

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);
    }
}
Also used : Transformer(org.gradle.api.Transformer) UncheckedIOException(org.gradle.api.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(org.gradle.api.UncheckedIOException) File(java.io.File)

Example 4 with Transformer

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;
        }
    };
}
Also used : Transformer(org.gradle.api.Transformer) File(java.io.File)

Example 5 with Transformer

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;
                }
            });
        }
    });
}
Also used : Transformer(org.gradle.api.Transformer) ConfigurableFileCollection(org.gradle.api.file.ConfigurableFileCollection) List(java.util.List)

Aggregations

Transformer (org.gradle.api.Transformer)13 File (java.io.File)6 List (java.util.List)5 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 UncheckedIOException (org.gradle.api.UncheckedIOException)2 ConfigurableFileCollection (org.gradle.api.file.ConfigurableFileCollection)2 FileCollection (org.gradle.api.file.FileCollection)2 HeaderExportingSourceSet (org.gradle.language.nativeplatform.HeaderExportingSourceSet)2 SharedLibraryBinarySpec (org.gradle.nativeplatform.SharedLibraryBinarySpec)2 PrintWriter (java.io.PrintWriter)1 Path (java.nio.file.Path)1 WatchEvent (java.nio.file.WatchEvent)1 Collection (java.util.Collection)1 LinkedHashSet (java.util.LinkedHashSet)1 Set (java.util.Set)1 Action (org.gradle.api.Action)1 InvalidUserDataException (org.gradle.api.InvalidUserDataException)1 Project (org.gradle.api.Project)1 Task (org.gradle.api.Task)1