Search in sources :

Example 1 with FileSystemOperations

use of org.gradle.api.file.FileSystemOperations in project gradle by gradle.

the class AbstractTestTask method executeTests.

@TaskAction
public void executeTests() {
    LogLevel currentLevel = determineCurrentLogLevel();
    TestLogging levelLogging = getTestLogging().get(currentLevel);
    TestExceptionFormatter exceptionFormatter = getExceptionFormatter(levelLogging);
    TestEventLogger eventLogger = new TestEventLogger(getTextOutputFactory(), currentLevel, levelLogging, exceptionFormatter);
    addTestListener(eventLogger);
    addTestOutputListener(eventLogger);
    TestExecutionSpec executionSpec = createTestExecutionSpec();
    final File binaryResultsDir = getBinaryResultsDirectory().getAsFile().get();
    FileSystemOperations fs = getFileSystemOperations();
    fs.delete(new Action<DeleteSpec>() {

        @Override
        public void execute(DeleteSpec spec) {
            spec.delete(binaryResultsDir);
        }
    });
    binaryResultsDir.mkdirs();
    Map<String, TestClassResult> results = new HashMap<String, TestClassResult>();
    TestOutputStore testOutputStore = new TestOutputStore(binaryResultsDir);
    TestOutputStore.Writer outputWriter = testOutputStore.writer();
    TestReportDataCollector testReportDataCollector = new TestReportDataCollector(results, outputWriter);
    addTestListener(testReportDataCollector);
    addTestOutputListener(testReportDataCollector);
    TestCountLogger testCountLogger = new TestCountLogger(getProgressLoggerFactory());
    addTestListener(testCountLogger);
    getTestListenerInternalBroadcaster().add(new TestListenerAdapter(testListenerBroadcaster.getSource(), getTestOutputListenerBroadcaster().getSource()));
    ProgressLogger parentProgressLogger = getProgressLoggerFactory().newOperation(AbstractTestTask.class);
    parentProgressLogger.setDescription("Test Execution");
    parentProgressLogger.started();
    TestWorkerProgressListener testWorkerProgressListener = new TestWorkerProgressListener(getProgressLoggerFactory(), parentProgressLogger);
    getTestListenerInternalBroadcaster().add(testWorkerProgressListener);
    TestExecuter<TestExecutionSpec> testExecuter = Cast.uncheckedNonnullCast(createTestExecuter());
    TestListenerInternal resultProcessorDelegate = getTestListenerInternalBroadcaster().getSource();
    if (failFast) {
        resultProcessorDelegate = new FailFastTestListenerInternal(testExecuter, resultProcessorDelegate);
    }
    TestResultProcessor resultProcessor = new StateTrackingTestResultProcessor(resultProcessorDelegate);
    try {
        testExecuter.execute(executionSpec, resultProcessor);
    } finally {
        parentProgressLogger.completed();
        testWorkerProgressListener.completeAll();
        testListenerBroadcaster.removeAll();
        getTestOutputListenerBroadcaster().removeAll();
        getTestListenerInternalBroadcaster().removeAll();
        outputWriter.close();
    }
    new TestResultSerializer(binaryResultsDir).write(results.values());
    createReporting(results, testOutputStore);
    handleCollectedResults(testCountLogger);
}
Also used : TestResultSerializer(org.gradle.api.internal.tasks.testing.junit.result.TestResultSerializer) HashMap(java.util.HashMap) TestResultProcessor(org.gradle.api.internal.tasks.testing.TestResultProcessor) StateTrackingTestResultProcessor(org.gradle.api.internal.tasks.testing.results.StateTrackingTestResultProcessor) TestClassResult(org.gradle.api.internal.tasks.testing.junit.result.TestClassResult) TestCountLogger(org.gradle.api.internal.tasks.testing.logging.TestCountLogger) ProgressLogger(org.gradle.internal.logging.progress.ProgressLogger) StateTrackingTestResultProcessor(org.gradle.api.internal.tasks.testing.results.StateTrackingTestResultProcessor) TestExecutionSpec(org.gradle.api.internal.tasks.testing.TestExecutionSpec) FileSystemOperations(org.gradle.api.file.FileSystemOperations) LogLevel(org.gradle.api.logging.LogLevel) TestEventLogger(org.gradle.api.internal.tasks.testing.logging.TestEventLogger) TestWorkerProgressListener(org.gradle.api.internal.tasks.testing.logging.TestWorkerProgressListener) DeleteSpec(org.gradle.api.file.DeleteSpec) FailFastTestListenerInternal(org.gradle.api.internal.tasks.testing.FailFastTestListenerInternal) TestReportDataCollector(org.gradle.api.internal.tasks.testing.junit.result.TestReportDataCollector) TestLogging(org.gradle.api.tasks.testing.logging.TestLogging) TestListenerInternal(org.gradle.api.internal.tasks.testing.results.TestListenerInternal) FailFastTestListenerInternal(org.gradle.api.internal.tasks.testing.FailFastTestListenerInternal) TestListenerAdapter(org.gradle.api.internal.tasks.testing.results.TestListenerAdapter) TestOutputStore(org.gradle.api.internal.tasks.testing.junit.result.TestOutputStore) TestExceptionFormatter(org.gradle.api.internal.tasks.testing.logging.TestExceptionFormatter) File(java.io.File) TaskAction(org.gradle.api.tasks.TaskAction)

Example 2 with FileSystemOperations

use of org.gradle.api.file.FileSystemOperations in project gradle by gradle.

the class CompileGroovyScriptPluginsTask method compileScripts.

@TaskAction
void compileScripts() {
    ClassLoaderScope classLoaderScope = getClassLoaderScopeRegistry().getCoreAndPluginsScope();
    ClassLoader compileClassLoader = new URLClassLoader(DefaultClassPath.of(getClasspath()).getAsURLArray(), classLoaderScope.getLocalClassLoader());
    FileSystemOperations fileSystemOperations = getFileSystemOperations();
    fileSystemOperations.delete(spec -> spec.delete(intermediatePluginMetadataDirectory, intermediatePluginClassesDirectory));
    intermediatePluginMetadataDirectory.get().getAsFile().mkdirs();
    intermediatePluginClassesDirectory.get().getAsFile().mkdirs();
    // TODO: Use worker API?
    for (PrecompiledGroovyScript scriptPlugin : getScriptPlugins().get()) {
        compileBuildScript(scriptPlugin, compileClassLoader);
    }
    fileSystemOperations.sync(copySpec -> {
        copySpec.from(intermediatePluginClassesDirectory.get().getAsFileTree().getFiles());
        copySpec.into(getPrecompiledGroovyScriptsOutputDirectory());
    });
    ClassLoaderUtils.tryClose(compileClassLoader);
}
Also used : ClassLoaderScope(org.gradle.api.internal.initialization.ClassLoaderScope) URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader) FileSystemOperations(org.gradle.api.file.FileSystemOperations) TaskAction(org.gradle.api.tasks.TaskAction)

Example 3 with FileSystemOperations

use of org.gradle.api.file.FileSystemOperations in project gradle by gradle.

the class GradleJavadocsPlugin method generateJavadocs.

private void generateJavadocs(Project project, ProjectLayout layout, TaskContainer tasks, GradleDocumentationExtension extension) {
    // TODO: Staging directory should be a part of the Javadocs extension
    // TODO: Pull out more of this configuration into the extension if it makes sense
    // TODO: in a typical project, this may need to be the regular javadoc task vs javadocAll
    ObjectFactory objects = project.getObjects();
    // TODO: This breaks if version is changed later
    Object version = project.getVersion();
    TaskProvider<Javadoc> javadocAll = tasks.register("javadocAll", Javadoc.class, task -> {
        task.setGroup("documentation");
        task.setDescription("Generate Javadocs for all API classes");
        task.setTitle("Gradle API " + version);
        Javadocs javadocs = extension.getJavadocs();
        // TODO: This should be part of Javadoc task
        task.getInputs().file(javadocs.getJavadocCss()).withPropertyName("stylesheetFile").withPathSensitivity(PathSensitivity.NAME_ONLY);
        StandardJavadocDocletOptions options = (StandardJavadocDocletOptions) task.getOptions();
        options.setEncoding("utf-8");
        options.setDocEncoding("utf-8");
        options.setCharSet("utf-8");
        // TODO: This would be better to model as separate options
        options.addStringOption("Xdoclint:syntax,html,reference", "-quiet");
        // TODO: This breaks the provider
        options.addStringOption("stylesheetfile", javadocs.getJavadocCss().get().getAsFile().getAbsolutePath());
        options.addStringOption("source", "8");
        // TODO: This breaks the provider
        options.links(javadocs.getJavaApi().get().toString(), javadocs.getGroovyApi().get().toString());
        task.source(extension.getDocumentedSource());
        task.setClasspath(extension.getClasspath());
        // TODO: This should be in Javadoc task
        DirectoryProperty generatedJavadocDirectory = objects.directoryProperty();
        generatedJavadocDirectory.set(layout.getBuildDirectory().dir("javadoc"));
        task.getOutputs().dir(generatedJavadocDirectory);
        task.getExtensions().getExtraProperties().set("destinationDirectory", generatedJavadocDirectory);
        // TODO: This breaks the provider
        task.setDestinationDir(generatedJavadocDirectory.get().getAsFile());
        if (BuildEnvironment.INSTANCE.getJavaVersion().isJava11Compatible()) {
            options.addBooleanOption("html4", true);
            options.addBooleanOption("-no-module-directories", true);
            FileSystemOperations fs = getFs();
            // noinspection Convert2Lambda
            task.doLast(new Action<Task>() {

                @Override
                public void execute(Task task) {
                    fs.copy(copySpec -> {
                        // Commit http://hg.openjdk.java.net/jdk/jdk/rev/89dc31d7572b broke use of JSZip (https://bugs.openjdk.java.net/browse/JDK-8214856)
                        // fixed in Java 12 by http://hg.openjdk.java.net/jdk/jdk/rev/b4982a22926b
                        // TODO: Remove this script.js workaround when we distribute Gradle using JDK 12 or higher
                        copySpec.from(extension.getSourceRoot().dir("js/javadoc"));
                        // This is a work-around for https://bugs.openjdk.java.net/browse/JDK-8211194. Can be removed once that issue is fixed on JDK"s side
                        // Since JDK 11, package-list is missing from javadoc output files and superseded by element-list file, but a lot of external tools still need it
                        // Here we generate this file manually
                        copySpec.from(generatedJavadocDirectory.file("element-list"), sub -> {
                            sub.rename(t -> "package-list");
                        });
                        copySpec.into(generatedJavadocDirectory);
                    });
                }
            });
        }
    });
    extension.javadocs(javadocs -> {
        javadocs.getJavadocCss().convention(extension.getSourceRoot().file("css/javadoc.css"));
        // TODO: destinationDirectory should be part of Javadoc
        javadocs.getRenderedDocumentation().from(javadocAll.flatMap(task -> (DirectoryProperty) task.getExtensions().getExtraProperties().get("destinationDirectory")));
    });
    CheckstyleExtension checkstyle = project.getExtensions().getByType(CheckstyleExtension.class);
    tasks.register("checkstyleApi", Checkstyle.class, task -> {
        task.source(extension.getDocumentedSource());
        // TODO: This is ugly
        task.setConfig(project.getResources().getText().fromFile(checkstyle.getConfigDirectory().file("checkstyle-api.xml")));
        task.setClasspath(layout.files());
        task.getReports().getXml().setDestination(new File(checkstyle.getReportsDir(), "checkstyle-api.xml"));
    });
}
Also used : FileSystemOperations(org.gradle.api.file.FileSystemOperations) Checkstyle(org.gradle.api.plugins.quality.Checkstyle) Action(org.gradle.api.Action) Project(org.gradle.api.Project) StandardJavadocDocletOptions(org.gradle.external.javadoc.StandardJavadocDocletOptions) File(java.io.File) Inject(javax.inject.Inject) Task(org.gradle.api.Task) ProjectLayout(org.gradle.api.file.ProjectLayout) Javadoc(org.gradle.api.tasks.javadoc.Javadoc) ObjectFactory(org.gradle.api.model.ObjectFactory) TaskContainer(org.gradle.api.tasks.TaskContainer) TaskProvider(org.gradle.api.tasks.TaskProvider) DirectoryProperty(org.gradle.api.file.DirectoryProperty) PathSensitivity(org.gradle.api.tasks.PathSensitivity) CheckstyleExtension(org.gradle.api.plugins.quality.CheckstyleExtension) BuildEnvironment(gradlebuild.basics.BuildEnvironment) Plugin(org.gradle.api.Plugin) Task(org.gradle.api.Task) Javadoc(org.gradle.api.tasks.javadoc.Javadoc) FileSystemOperations(org.gradle.api.file.FileSystemOperations) CheckstyleExtension(org.gradle.api.plugins.quality.CheckstyleExtension) StandardJavadocDocletOptions(org.gradle.external.javadoc.StandardJavadocDocletOptions) DirectoryProperty(org.gradle.api.file.DirectoryProperty) ObjectFactory(org.gradle.api.model.ObjectFactory) File(java.io.File)

Aggregations

FileSystemOperations (org.gradle.api.file.FileSystemOperations)3 File (java.io.File)2 TaskAction (org.gradle.api.tasks.TaskAction)2 BuildEnvironment (gradlebuild.basics.BuildEnvironment)1 URLClassLoader (java.net.URLClassLoader)1 HashMap (java.util.HashMap)1 Inject (javax.inject.Inject)1 Action (org.gradle.api.Action)1 Plugin (org.gradle.api.Plugin)1 Project (org.gradle.api.Project)1 Task (org.gradle.api.Task)1 DeleteSpec (org.gradle.api.file.DeleteSpec)1 DirectoryProperty (org.gradle.api.file.DirectoryProperty)1 ProjectLayout (org.gradle.api.file.ProjectLayout)1 ClassLoaderScope (org.gradle.api.internal.initialization.ClassLoaderScope)1 FailFastTestListenerInternal (org.gradle.api.internal.tasks.testing.FailFastTestListenerInternal)1 TestExecutionSpec (org.gradle.api.internal.tasks.testing.TestExecutionSpec)1 TestResultProcessor (org.gradle.api.internal.tasks.testing.TestResultProcessor)1 TestClassResult (org.gradle.api.internal.tasks.testing.junit.result.TestClassResult)1 TestOutputStore (org.gradle.api.internal.tasks.testing.junit.result.TestOutputStore)1