Search in sources :

Example 11 with ProjectLayout

use of org.gradle.api.file.ProjectLayout 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)

Example 12 with ProjectLayout

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

the class GradleUserManualPlugin method apply.

@Override
public void apply(Project project) {
    ProjectLayout layout = project.getLayout();
    TaskContainer tasks = project.getTasks();
    GradleDocumentationExtension extension = project.getExtensions().getByType(GradleDocumentationExtension.class);
    generateDefaultImports(project, tasks, extension);
    generateUserManual(project, tasks, layout, extension);
    checkXrefLinksInUserManualAreValid(layout, tasks, extension);
}
Also used : TaskContainer(org.gradle.api.tasks.TaskContainer) ProjectLayout(org.gradle.api.file.ProjectLayout)

Example 13 with ProjectLayout

use of org.gradle.api.file.ProjectLayout in project SpongeCommon by SpongePowered.

the class TemplatedResourcesPlugin method withJavaBase.

private void withJavaBase(final Project target) {
    final SourceSetContainer sourceSets = target.getExtensions().getByType(SourceSetContainer.class);
    final TaskContainer tasks = target.getTasks();
    final ProjectLayout layout = target.getLayout();
    sourceSets.all(set -> {
        final Provider<Directory> destination = layout.getBuildDirectory().dir("generated/templateResources/" + set.getName());
        final Directory srcDir = layout.getProjectDirectory().dir("src/" + set.getName() + "/resourceTemplates");
        final TaskProvider<?> generateTask = tasks.register(set.getTaskName("template", "resources"), GenerateResourceTemplates.class, copy -> {
            copy.into(destination);
            copy.from(srcDir);
        });
        set.getResources().srcDir(generateTask.map(Task::getOutputs));
    });
    final TaskProvider<?> generateAllTask = tasks.register("allTemplateResource", t -> {
        t.dependsOn(tasks.withType(GenerateResourceTemplates.class));
    });
    this.configureIdeIntegrations(target, generateAllTask);
}
Also used : TaskContainer(org.gradle.api.tasks.TaskContainer) ProjectLayout(org.gradle.api.file.ProjectLayout) SourceSetContainer(org.gradle.api.tasks.SourceSetContainer) Directory(org.gradle.api.file.Directory)

Aggregations

ProjectLayout (org.gradle.api.file.ProjectLayout)13 TaskContainer (org.gradle.api.tasks.TaskContainer)10 Plugin (org.gradle.api.Plugin)5 Configuration (org.gradle.api.artifacts.Configuration)5 ProviderFactory (org.gradle.api.provider.ProviderFactory)5 File (java.io.File)4 Project (org.gradle.api.Project)4 ObjectFactory (org.gradle.api.model.ObjectFactory)4 Provider (org.gradle.api.provider.Provider)4 TaskProvider (org.gradle.api.tasks.TaskProvider)4 Directory (org.gradle.api.file.Directory)3 RegularFile (org.gradle.api.file.RegularFile)3 ConventionMapping (org.gradle.api.internal.ConventionMapping)3 SerializableLambdas.action (org.gradle.api.internal.lambdas.SerializableLambdas.action)3 AbstractCodeQualityPlugin (org.gradle.api.plugins.quality.internal.AbstractCodeQualityPlugin)3 SourceSet (org.gradle.api.tasks.SourceSet)3 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 Map (java.util.Map)2 Inject (javax.inject.Inject)2