Search in sources :

Example 91 with Project

use of org.gradle.api.Project in project rest.li by linkedin.

the class PegasusPlugin method configureAvroSchemaGeneration.

@SuppressWarnings("deprecation")
protected void configureAvroSchemaGeneration(Project project, SourceSet sourceSet) {
    File dataSchemaDir = project.file(getDataSchemaPath(project, sourceSet));
    File avroDir = project.file(getGeneratedDirPath(project, sourceSet, AVRO_SCHEMA_GEN_TYPE) + File.separatorChar + "avro");
    // generate avro schema files from data schema
    Task generateAvroSchemaTask = project.getTasks().create(sourceSet.getTaskName("generate", "avroSchema"), GenerateAvroSchemaTask.class, task -> {
        task.setInputDir(dataSchemaDir);
        task.setDestinationDir(avroDir);
        task.setResolverPath(getDataModelConfig(project, sourceSet));
        task.setCodegenClasspath(project.getConfigurations().getByName(PEGASUS_PLUGIN_CONFIGURATION));
        if (isPropertyTrue(project, ENABLE_ARG_FILE)) {
            task.setEnableArgFile(true);
        }
        task.onlyIf(t -> {
            if (task.getInputDir().exists()) {
                @SuppressWarnings("unchecked") Map<String, PegasusOptions> pegasusOptions = (Map<String, PegasusOptions>) project.getExtensions().getExtraProperties().get("pegasus");
                if (pegasusOptions.get(sourceSet.getName()).hasGenerationMode(PegasusOptions.GenerationMode.AVRO)) {
                    return true;
                }
            }
            return !project.getConfigurations().getByName("avroSchemaGenerator").isEmpty();
        });
        task.doFirst(new CacheableAction<>(t -> deleteGeneratedDir(project, sourceSet, AVRO_SCHEMA_GEN_TYPE)));
    });
    project.getTasks().getByName(sourceSet.getCompileJavaTaskName()).dependsOn(generateAvroSchemaTask);
    // create avro schema jar file
    Task avroSchemaJarTask = project.getTasks().create(sourceSet.getName() + "AvroSchemaJar", Jar.class, task -> {
        // add path prefix to each file in the data schema directory
        task.from(avroDir, copySpec -> copySpec.eachFile(fileCopyDetails -> fileCopyDetails.setPath("avro" + File.separatorChar + fileCopyDetails.getPath())));
        // FIXME change to #getArchiveAppendix().set(...); breaks backwards-compatibility before 5.1
        task.setAppendix(getAppendix(sourceSet, "avro-schema"));
        task.setDescription("Generate an avro schema jar");
    });
    if (!isTestSourceSet(sourceSet)) {
        project.getArtifacts().add("avroSchema", avroSchemaJarTask);
    } else {
        project.getArtifacts().add("testAvroSchema", avroSchemaJarTask);
    }
}
Also used : CompatibilityLogChecker(com.linkedin.pegasus.gradle.internal.CompatibilityLogChecker) Arrays(java.util.Arrays) PublishRestModelTask(com.linkedin.pegasus.gradle.tasks.PublishRestModelTask) ValidateExtensionSchemaTask(com.linkedin.pegasus.gradle.tasks.ValidateExtensionSchemaTask) JavaPlugin(org.gradle.api.plugins.JavaPlugin) IdeaPlugin(org.gradle.plugins.ide.idea.IdeaPlugin) CheckSnapshotTask(com.linkedin.pegasus.gradle.tasks.CheckSnapshotTask) EclipsePlugin(org.gradle.plugins.ide.eclipse.EclipsePlugin) Task(org.gradle.api.Task) PublishingExtension(org.gradle.api.publish.PublishingExtension) Javadoc(org.gradle.api.tasks.javadoc.Javadoc) JavaBasePlugin(org.gradle.api.plugins.JavaBasePlugin) ConfigurationContainer(org.gradle.api.artifacts.ConfigurationContainer) TaskProvider(org.gradle.api.tasks.TaskProvider) Locale(java.util.Locale) Map(java.util.Map) TranslateSchemasTask(com.linkedin.pegasus.gradle.tasks.TranslateSchemasTask) CheckPegasusSnapshotTask(com.linkedin.pegasus.gradle.tasks.CheckPegasusSnapshotTask) Method(java.lang.reflect.Method) Path(java.nio.file.Path) GradleVersion(org.gradle.util.GradleVersion) IdeaModule(org.gradle.plugins.ide.idea.model.IdeaModule) Delete(org.gradle.api.tasks.Delete) Project(org.gradle.api.Project) Collection(java.util.Collection) ChangedFileReportTask(com.linkedin.pegasus.gradle.tasks.ChangedFileReportTask) Set(java.util.Set) IvyPublishPlugin(org.gradle.api.publish.ivy.plugins.IvyPublishPlugin) GeneratePegasusSnapshotTask(com.linkedin.pegasus.gradle.tasks.GeneratePegasusSnapshotTask) Collectors(java.util.stream.Collectors) IvyPublication(org.gradle.api.publish.ivy.IvyPublication) List(java.util.List) IdlOptions(com.linkedin.pegasus.gradle.PegasusOptions.IdlOptions) JavaPluginExtension(org.gradle.api.plugins.JavaPluginExtension) Pattern(java.util.regex.Pattern) ProcessResources(org.gradle.language.jvm.tasks.ProcessResources) GenerateRestClientTask(com.linkedin.pegasus.gradle.tasks.GenerateRestClientTask) GenerateRestModelTask(com.linkedin.pegasus.gradle.tasks.GenerateRestModelTask) HashMap(java.util.HashMap) Function(java.util.function.Function) FileCollection(org.gradle.api.file.FileCollection) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) SourceSet(org.gradle.api.tasks.SourceSet) HashSet(java.util.HashSet) Configuration(org.gradle.api.artifacts.Configuration) LifecycleBasePlugin(org.gradle.language.base.plugins.LifecycleBasePlugin) Sync(org.gradle.api.tasks.Sync) SourceSetContainer(org.gradle.api.tasks.SourceSetContainer) CheckRestModelTask(com.linkedin.pegasus.gradle.tasks.CheckRestModelTask) JavaCompile(org.gradle.api.tasks.compile.JavaCompile) Properties(java.util.Properties) Jar(org.gradle.api.tasks.bundling.Jar) Action(org.gradle.api.Action) Files(java.nio.file.Files) JavaPluginConvention(org.gradle.api.plugins.JavaPluginConvention) ValidateSchemaAnnotationTask(com.linkedin.pegasus.gradle.tasks.ValidateSchemaAnnotationTask) IOException(java.io.IOException) EclipseModel(org.gradle.plugins.ide.eclipse.model.EclipseModel) File(java.io.File) CheckIdlTask(com.linkedin.pegasus.gradle.tasks.CheckIdlTask) GenerateDataTemplateTask(com.linkedin.pegasus.gradle.tasks.GenerateDataTemplateTask) GenerateAvroSchemaTask(com.linkedin.pegasus.gradle.tasks.GenerateAvroSchemaTask) GradleException(org.gradle.api.GradleException) Collections(java.util.Collections) Plugin(org.gradle.api.Plugin) Copy(org.gradle.api.tasks.Copy) InputStream(java.io.InputStream) PublishRestModelTask(com.linkedin.pegasus.gradle.tasks.PublishRestModelTask) ValidateExtensionSchemaTask(com.linkedin.pegasus.gradle.tasks.ValidateExtensionSchemaTask) CheckSnapshotTask(com.linkedin.pegasus.gradle.tasks.CheckSnapshotTask) Task(org.gradle.api.Task) TranslateSchemasTask(com.linkedin.pegasus.gradle.tasks.TranslateSchemasTask) CheckPegasusSnapshotTask(com.linkedin.pegasus.gradle.tasks.CheckPegasusSnapshotTask) ChangedFileReportTask(com.linkedin.pegasus.gradle.tasks.ChangedFileReportTask) GeneratePegasusSnapshotTask(com.linkedin.pegasus.gradle.tasks.GeneratePegasusSnapshotTask) GenerateRestClientTask(com.linkedin.pegasus.gradle.tasks.GenerateRestClientTask) GenerateRestModelTask(com.linkedin.pegasus.gradle.tasks.GenerateRestModelTask) CheckRestModelTask(com.linkedin.pegasus.gradle.tasks.CheckRestModelTask) ValidateSchemaAnnotationTask(com.linkedin.pegasus.gradle.tasks.ValidateSchemaAnnotationTask) CheckIdlTask(com.linkedin.pegasus.gradle.tasks.CheckIdlTask) GenerateDataTemplateTask(com.linkedin.pegasus.gradle.tasks.GenerateDataTemplateTask) GenerateAvroSchemaTask(com.linkedin.pegasus.gradle.tasks.GenerateAvroSchemaTask) File(java.io.File) Map(java.util.Map) HashMap(java.util.HashMap)

Example 92 with Project

use of org.gradle.api.Project in project rest.li by linkedin.

the class PegasusPlugin method configureConversionUtilities.

protected void configureConversionUtilities(Project project, SourceSet sourceSet) {
    File dataSchemaDir = project.file(getDataSchemaPath(project, sourceSet));
    boolean reverse = isPropertyTrue(project, CONVERT_TO_PDL_REVERSE);
    boolean keepOriginal = isPropertyTrue(project, CONVERT_TO_PDL_KEEP_ORIGINAL);
    boolean skipVerification = isPropertyTrue(project, CONVERT_TO_PDL_SKIP_VERIFICATION);
    String preserveSourceCmd = getNonEmptyProperty(project, CONVERT_TO_PDL_PRESERVE_SOURCE_CMD);
    // Utility task for migrating between PDSC and PDL.
    project.getTasks().create(sourceSet.getTaskName("convert", "ToPdl"), TranslateSchemasTask.class, task -> {
        task.setInputDir(dataSchemaDir);
        task.setDestinationDir(dataSchemaDir);
        task.setResolverPath(getDataModelConfig(project, sourceSet));
        task.setCodegenClasspath(project.getConfigurations().getByName(PEGASUS_PLUGIN_CONFIGURATION));
        task.setPreserveSourceCmd(preserveSourceCmd);
        if (reverse) {
            task.setSourceFormat(SchemaFileType.PDL);
            task.setDestinationFormat(SchemaFileType.PDSC);
        } else {
            task.setSourceFormat(SchemaFileType.PDSC);
            task.setDestinationFormat(SchemaFileType.PDL);
        }
        task.setKeepOriginal(keepOriginal);
        task.setSkipVerification(skipVerification);
        if (isPropertyTrue(project, ENABLE_ARG_FILE)) {
            task.setEnableArgFile(true);
        }
        task.onlyIf(t -> task.getInputDir().exists());
        task.doLast(new CacheableAction<>(t -> {
            project.getLogger().lifecycle("Pegasus schema conversion complete.");
            project.getLogger().lifecycle("All pegasus schema files in " + dataSchemaDir + " have been converted");
            project.getLogger().lifecycle("You can use '-PconvertToPdl.reverse=true|false' to change the direction of conversion.");
        }));
    });
    // Helper task for reformatting existing PDL schemas by generating them again.
    project.getTasks().create(sourceSet.getTaskName("reformat", "Pdl"), TranslateSchemasTask.class, task -> {
        task.setInputDir(dataSchemaDir);
        task.setDestinationDir(dataSchemaDir);
        task.setResolverPath(getDataModelConfig(project, sourceSet));
        task.setCodegenClasspath(project.getConfigurations().getByName(PEGASUS_PLUGIN_CONFIGURATION));
        task.setSourceFormat(SchemaFileType.PDL);
        task.setDestinationFormat(SchemaFileType.PDL);
        task.setKeepOriginal(true);
        task.setSkipVerification(true);
        if (isPropertyTrue(project, ENABLE_ARG_FILE)) {
            task.setEnableArgFile(true);
        }
        task.onlyIf(t -> task.getInputDir().exists());
        task.doLast(new CacheableAction<>(t -> project.getLogger().lifecycle("PDL reformat complete.")));
    });
}
Also used : CompatibilityLogChecker(com.linkedin.pegasus.gradle.internal.CompatibilityLogChecker) Arrays(java.util.Arrays) PublishRestModelTask(com.linkedin.pegasus.gradle.tasks.PublishRestModelTask) ValidateExtensionSchemaTask(com.linkedin.pegasus.gradle.tasks.ValidateExtensionSchemaTask) JavaPlugin(org.gradle.api.plugins.JavaPlugin) IdeaPlugin(org.gradle.plugins.ide.idea.IdeaPlugin) CheckSnapshotTask(com.linkedin.pegasus.gradle.tasks.CheckSnapshotTask) EclipsePlugin(org.gradle.plugins.ide.eclipse.EclipsePlugin) Task(org.gradle.api.Task) PublishingExtension(org.gradle.api.publish.PublishingExtension) Javadoc(org.gradle.api.tasks.javadoc.Javadoc) JavaBasePlugin(org.gradle.api.plugins.JavaBasePlugin) ConfigurationContainer(org.gradle.api.artifacts.ConfigurationContainer) TaskProvider(org.gradle.api.tasks.TaskProvider) Locale(java.util.Locale) Map(java.util.Map) TranslateSchemasTask(com.linkedin.pegasus.gradle.tasks.TranslateSchemasTask) CheckPegasusSnapshotTask(com.linkedin.pegasus.gradle.tasks.CheckPegasusSnapshotTask) Method(java.lang.reflect.Method) Path(java.nio.file.Path) GradleVersion(org.gradle.util.GradleVersion) IdeaModule(org.gradle.plugins.ide.idea.model.IdeaModule) Delete(org.gradle.api.tasks.Delete) Project(org.gradle.api.Project) Collection(java.util.Collection) ChangedFileReportTask(com.linkedin.pegasus.gradle.tasks.ChangedFileReportTask) Set(java.util.Set) IvyPublishPlugin(org.gradle.api.publish.ivy.plugins.IvyPublishPlugin) GeneratePegasusSnapshotTask(com.linkedin.pegasus.gradle.tasks.GeneratePegasusSnapshotTask) Collectors(java.util.stream.Collectors) IvyPublication(org.gradle.api.publish.ivy.IvyPublication) List(java.util.List) IdlOptions(com.linkedin.pegasus.gradle.PegasusOptions.IdlOptions) JavaPluginExtension(org.gradle.api.plugins.JavaPluginExtension) Pattern(java.util.regex.Pattern) ProcessResources(org.gradle.language.jvm.tasks.ProcessResources) GenerateRestClientTask(com.linkedin.pegasus.gradle.tasks.GenerateRestClientTask) GenerateRestModelTask(com.linkedin.pegasus.gradle.tasks.GenerateRestModelTask) HashMap(java.util.HashMap) Function(java.util.function.Function) FileCollection(org.gradle.api.file.FileCollection) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) SourceSet(org.gradle.api.tasks.SourceSet) HashSet(java.util.HashSet) Configuration(org.gradle.api.artifacts.Configuration) LifecycleBasePlugin(org.gradle.language.base.plugins.LifecycleBasePlugin) Sync(org.gradle.api.tasks.Sync) SourceSetContainer(org.gradle.api.tasks.SourceSetContainer) CheckRestModelTask(com.linkedin.pegasus.gradle.tasks.CheckRestModelTask) JavaCompile(org.gradle.api.tasks.compile.JavaCompile) Properties(java.util.Properties) Jar(org.gradle.api.tasks.bundling.Jar) Action(org.gradle.api.Action) Files(java.nio.file.Files) JavaPluginConvention(org.gradle.api.plugins.JavaPluginConvention) ValidateSchemaAnnotationTask(com.linkedin.pegasus.gradle.tasks.ValidateSchemaAnnotationTask) IOException(java.io.IOException) EclipseModel(org.gradle.plugins.ide.eclipse.model.EclipseModel) File(java.io.File) CheckIdlTask(com.linkedin.pegasus.gradle.tasks.CheckIdlTask) GenerateDataTemplateTask(com.linkedin.pegasus.gradle.tasks.GenerateDataTemplateTask) GenerateAvroSchemaTask(com.linkedin.pegasus.gradle.tasks.GenerateAvroSchemaTask) GradleException(org.gradle.api.GradleException) Collections(java.util.Collections) Plugin(org.gradle.api.Plugin) Copy(org.gradle.api.tasks.Copy) InputStream(java.io.InputStream) File(java.io.File)

Example 93 with Project

use of org.gradle.api.Project in project rest.li by linkedin.

the class TestPegasusPlugin method test.

@Test
public void test() {
    Project project = ProjectBuilder.builder().build();
    project.getPlugins().apply(PegasusPlugin.class);
    assertTrue(project.getPlugins().hasPlugin(JavaPlugin.class));
    // if any configuration is resolved in configuration phase, user script that tries to exclude certain dependencies will fail
    for (Configuration configuration : project.getConfigurations()) {
        assertSame(configuration.getState(), Configuration.State.UNRESOLVED);
    }
    assertNotNull(project.getConfigurations().findByName("dataTemplate"));
    assertNotNull(project.getConfigurations().findByName("restClient"));
    assertTrue(project.getExtensions().getExtraProperties().get("PegasusGenerationMode") instanceof Map);
    @SuppressWarnings("unchecked") Map<String, PegasusOptions> pegasusOptions = (Map<String, PegasusOptions>) project.getExtensions().getExtraProperties().get("pegasus");
    assertFalse(pegasusOptions.get("main").hasGenerationMode(PegasusOptions.GenerationMode.AVRO));
    assertTrue(pegasusOptions.get("main").hasGenerationMode(PegasusOptions.GenerationMode.PEGASUS));
}
Also used : Project(org.gradle.api.Project) Configuration(org.gradle.api.artifacts.Configuration) JavaPlugin(org.gradle.api.plugins.JavaPlugin) Map(java.util.Map) Test(org.testng.annotations.Test)

Example 94 with Project

use of org.gradle.api.Project in project gradle by gradle.

the class GradleUserManualPlugin method generateUserManual.

private void generateUserManual(Project project, TaskContainer tasks, ProjectLayout layout, GradleDocumentationExtension extension) {
    tasks.withType(AsciidoctorTask.class).configureEach(task -> {
        if (task.getName().equals("asciidoctor")) {
            // ignore this task
            task.setEnabled(false);
            return;
        }
        task.outputOptions(options -> {
            options.setSeparateOutputDirs(false);
            options.setBackends(singletonList("html5"));
        });
        // TODO: Break the paths assumed here
        TaskInputs inputs = task.getInputs();
        inputs.files(extension.getCssFiles()).withPropertyName("manual").withPathSensitivity(PathSensitivity.RELATIVE);
        inputs.dir("src/main/resources").withPropertyName("resources").withPathSensitivity(PathSensitivity.RELATIVE);
        inputs.dir(extension.getUserManual().getSnippets()).withPropertyName("snippets").withPathSensitivity(PathSensitivity.RELATIVE);
        inputs.dir(extension.getUserManual().getSamples()).withPropertyName("samples").withPathSensitivity(PathSensitivity.RELATIVE);
        Provider<Directory> stylesDir = extension.getUserManual().getStagedDocumentation().dir("css");
        inputs.dir(stylesDir).withPropertyName("stylesdir").withPathSensitivity(PathSensitivity.RELATIVE);
        // TODO: Break the paths assumed here
        Map<String, Object> attributes = new HashMap<>();
        // TODO: This breaks the provider
        attributes.put("stylesdir", stylesDir.get().getAsFile().getAbsolutePath());
        attributes.put("stylesheet", "manual.css");
        attributes.put("doctype", "book");
        attributes.put("imagesdir", "img");
        attributes.put("nofooter", true);
        attributes.put("sectanchors", true);
        attributes.put("sectlinks", true);
        attributes.put("linkattrs", true);
        attributes.put("reproducible", "");
        attributes.put("docinfo", "");
        attributes.put("lang", "en-US");
        attributes.put("encoding", "utf-8");
        attributes.put("idprefix", "");
        attributes.put("website", "https://gradle.org");
        // TODO: This breaks the provider
        attributes.put("javaApi", extension.getJavadocs().getJavaApi().get().toString());
        attributes.put("jdkDownloadUrl", "https://jdk.java.net/");
        // TODO: This is coupled to extension.getJavadocs().getJavaApi()
        attributes.put("javadocReferenceUrl", "https://docs.oracle.com/javase/8/docs/technotes/tools/windows/javadoc.html");
        // TODO: This is coupled to extension.getJavadocs().getJavaApi()
        attributes.put("minJdkVersion", "8");
        attributes.put("antManual", "https://ant.apache.org/manual");
        attributes.put("docsUrl", "https://docs.gradle.org");
        // TODO: This breaks if the version is changed later.
        attributes.put("gradleVersion", project.getVersion().toString());
        attributes.put("snippetsPath", "snippets");
        // Make sure the 'raw' location of the samples is available in all AsciidoctorTasks to access files with expected outputs in the 'tests' folder for inclusion in READMEs
        attributes.put("samplesPath", extension.getUserManual().getStagingRoot().dir("raw/samples").get().getAsFile());
        task.attributes(attributes);
    });
    TaskProvider<GenerateDocInfo> generateDocinfo = tasks.register("generateDocInfo", GenerateDocInfo.class, task -> {
        task.getDocumentationFiles().from(extension.getUserManual().getRoot());
        task.getDocumentationRoot().convention(extension.getUserManual().getRoot());
        task.getDestinationDirectory().convention(layout.getBuildDirectory().dir("tmp/" + task.getName()));
    });
    TaskProvider<Sync> userguideFlattenSources = tasks.register("stageUserguideSource", Sync.class, task -> {
        task.setDuplicatesStrategy(DuplicatesStrategy.FAIL);
        // TODO: This doesn't allow adoc files to be generated?
        task.from(extension.getUserManual().getRoot(), sub -> {
            sub.include("**/*.adoc");
            // Flatten adocs into a single directory
            sub.eachFile(fcd -> fcd.setRelativePath(RelativePath.parse(true, fcd.getName())));
        });
        // From the snippets and the samples, filter out files generated if the build contained was ever executed
        task.from(extension.getUserManual().getSnippets(), sub -> {
            sub.into("snippets");
            sub.exclude("**/.gradle/**");
            sub.exclude("**/build/**");
            sub.setIncludeEmptyDirs(false);
        });
        task.from(extension.getUserManual().getSamples(), sub -> {
            sub.into("samples");
            sub.exclude("**/*.adoc");
            sub.exclude("**/.gradle/**");
            sub.exclude("**/build/**");
            sub.setIncludeEmptyDirs(false);
        });
        task.from(extension.getCssFiles(), sub -> sub.into("css"));
        task.from(extension.getUserManual().getRoot().dir("img"), sub -> {
            sub.include("**/*.png", "**/*.gif", "**/*.jpg", "**/*.svg");
            sub.into("img");
        });
        task.from(extension.getUserManual().getResources());
        task.from(generateDocinfo);
        // TODO: This should be available on a Copy task.
        DirectoryProperty flattenedAsciidocDirectory = project.getObjects().directoryProperty();
        flattenedAsciidocDirectory.set(extension.getUserManual().getStagingRoot().dir("raw"));
        task.getOutputs().dir(flattenedAsciidocDirectory);
        task.getExtensions().getExtraProperties().set("destinationDirectory", flattenedAsciidocDirectory);
        task.into(flattenedAsciidocDirectory);
    });
    TaskProvider<AsciidoctorTask> userguideSinglePageHtml = tasks.register("userguideSinglePageHtml", AsciidoctorTask.class, task -> {
        task.setDescription("Generates HTML single-page user manual.");
        configureForUserGuideSinglePage(task, extension, project);
        task.outputOptions(options -> options.setBackends(singletonList("html5")));
        // TODO: This breaks the provider
        task.setOutputDir(extension.getUserManual().getStagingRoot().dir("render-single-html").get().getAsFile());
    });
    TaskProvider<AsciidoctorTask> userguideSinglePagePdf = tasks.register("userguideSinglePagePdf", AsciidoctorTask.class, task -> {
        task.setDescription("Generates PDF single-page user manual.");
        configureForUserGuideSinglePage(task, extension, project);
        task.outputOptions(options -> options.setBackends(singletonList("pdf")));
        // TODO: This breaks the provider
        task.setOutputDir(extension.getUserManual().getStagingRoot().dir("render-single-pdf").get().getAsFile());
    });
    TaskProvider<AsciidoctorTask> userguideMultiPage = tasks.register("userguideMultiPage", AsciidoctorTask.class, task -> {
        task.setGroup("documentation");
        task.setDescription("Generates multi-page user manual.");
        task.dependsOn(extension.getUserManual().getStagedDocumentation());
        task.sources(patternSet -> {
            patternSet.include("**/*.adoc");
            patternSet.exclude("javaProject*Layout.adoc");
            patternSet.exclude("userguide_single.adoc");
            patternSet.exclude("snippets/**/*.adoc");
        });
        // TODO: This breaks the provider
        task.setSourceDir(extension.getUserManual().getStagedDocumentation().get().getAsFile());
        // TODO: This breaks the provider
        task.setOutputDir(extension.getUserManual().getStagingRoot().dir("render-multi").get().getAsFile());
        Map<String, Object> attributes = new HashMap<>();
        attributes.put("icons", "font");
        attributes.put("source-highlighter", "prettify");
        attributes.put("toc", "auto");
        attributes.put("toclevels", 1);
        attributes.put("toc-title", "Contents");
        attributes.put("groovyDslPath", "../dsl");
        attributes.put("javadocPath", "../javadoc");
        attributes.put("kotlinDslPath", "https://gradle.github.io/kotlin-dsl-docs/api");
        // Used by SampleIncludeProcessor from `gradle/dotorg-docs`
        // TODO: This breaks the provider
        // TODO:
        attributes.put("samples-dir", extension.getUserManual().getStagedDocumentation().get().getAsFile());
        task.attributes(attributes);
    });
    // Avoid overlapping outputs by copying exactly what we want from other intermediate tasks
    TaskProvider<Sync> userguide = tasks.register("userguide", Sync.class, task -> {
        task.setGroup("documentation");
        task.setDescription("Stages rendered user manual documentation.");
        task.from(userguideSinglePageHtml);
        task.from(userguideSinglePagePdf);
        task.from(userguideMultiPage);
        task.into(extension.getUserManual().getStagingRoot().dir("final"));
        // TODO: Eliminate this duplication with the flatten task
        task.from(extension.getUserManual().getRoot().dir("img"), sub -> {
            sub.include("**/*.png", "**/*.gif", "**/*.jpg", "**/*.svg");
            sub.into("img");
        });
        task.rename("userguide_single.pdf", "userguide.pdf");
    });
    extension.userManual(userManual -> {
        userManual.getRoot().convention(extension.getSourceRoot().dir("userguide"));
        userManual.getStagingRoot().convention(extension.getStagingRoot().dir("usermanual"));
        // TODO: These should be generated too
        userManual.getSnippets().convention(layout.getProjectDirectory().dir("src/snippets"));
        userManual.getSamples().convention(layout.getProjectDirectory().dir("src/samples"));
        userManual.getStagedDocumentation().convention(userguideFlattenSources.flatMap(task -> (DirectoryProperty) task.getExtensions().getExtraProperties().get("destinationDirectory")));
        userManual.getRenderedDocumentation().from(userguide);
    });
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) LifecycleBasePlugin(org.gradle.language.base.plugins.LifecycleBasePlugin) Provider(org.gradle.api.provider.Provider) RelativePath(org.gradle.api.file.RelativePath) Sync(org.gradle.api.tasks.Sync) AsciidoctorTask(org.asciidoctor.gradle.jvm.AsciidoctorTask) TaskProvider(org.gradle.api.tasks.TaskProvider) DirectoryProperty(org.gradle.api.file.DirectoryProperty) SourceSetContainer(org.gradle.api.tasks.SourceSetContainer) Arrays.asList(java.util.Arrays.asList) PathSensitivity(org.gradle.api.tasks.PathSensitivity) Map(java.util.Map) DuplicatesStrategy(org.gradle.api.file.DuplicatesStrategy) Collections.singletonMap(java.util.Collections.singletonMap) Directory(org.gradle.api.file.Directory) TaskInputs(org.gradle.api.tasks.TaskInputs) Project(org.gradle.api.Project) List(java.util.List) ProjectLayout(org.gradle.api.file.ProjectLayout) TaskContainer(org.gradle.api.tasks.TaskContainer) GenerateApiMapping(gradlebuild.docs.dsl.source.GenerateApiMapping) GenerateDefaultImports(gradlebuild.docs.dsl.source.GenerateDefaultImports) Plugin(org.gradle.api.Plugin) HashMap(java.util.HashMap) TaskInputs(org.gradle.api.tasks.TaskInputs) DirectoryProperty(org.gradle.api.file.DirectoryProperty) Sync(org.gradle.api.tasks.Sync) AsciidoctorTask(org.asciidoctor.gradle.jvm.AsciidoctorTask) Directory(org.gradle.api.file.Directory)

Example 95 with Project

use of org.gradle.api.Project in project gradle by gradle.

the class GradleUserManualPlugin method generateDefaultImports.

// TODO: This doesn't really make sense to be part of the user manual generation, but it's so tied up into it
// it's left here for a future project.
private void generateDefaultImports(Project project, TaskContainer tasks, GradleDocumentationExtension extension) {
    List<String> excludedPackages = getDefaultExcludedPackages();
    Provider<Directory> generatedDirectory = extension.getUserManual().getStagingRoot().dir("generated");
    TaskProvider<GenerateApiMapping> apiMapping = tasks.register("apiMapping", GenerateApiMapping.class, task -> {
        task.getMetaDataFile().convention(extension.getDslReference().getGeneratedMetaDataFile());
        task.getMappingDestFile().convention(generatedDirectory.map(dir -> dir.file("api-mapping.txt")));
        task.getExcludedPackages().convention(excludedPackages);
    });
    TaskProvider<GenerateDefaultImports> defaultImports = tasks.register("defaultImports", GenerateDefaultImports.class, task -> {
        task.getMetaDataFile().convention(extension.getDslReference().getGeneratedMetaDataFile());
        task.getImportsDestFile().convention(generatedDirectory.map(dir -> dir.file("default-imports.txt")));
        task.getExcludedPackages().convention(excludedPackages);
    });
    SourceSetContainer sourceSets = project.getExtensions().getByType(SourceSetContainer.class);
    sourceSets.getByName("main", main -> main.getOutput().dir(singletonMap("builtBy", asList(apiMapping, defaultImports)), generatedDirectory));
    extension.getUserManual().getResources().from(apiMapping);
    extension.getUserManual().getResources().from(defaultImports);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) LifecycleBasePlugin(org.gradle.language.base.plugins.LifecycleBasePlugin) Provider(org.gradle.api.provider.Provider) RelativePath(org.gradle.api.file.RelativePath) Sync(org.gradle.api.tasks.Sync) AsciidoctorTask(org.asciidoctor.gradle.jvm.AsciidoctorTask) TaskProvider(org.gradle.api.tasks.TaskProvider) DirectoryProperty(org.gradle.api.file.DirectoryProperty) SourceSetContainer(org.gradle.api.tasks.SourceSetContainer) Arrays.asList(java.util.Arrays.asList) PathSensitivity(org.gradle.api.tasks.PathSensitivity) Map(java.util.Map) DuplicatesStrategy(org.gradle.api.file.DuplicatesStrategy) Collections.singletonMap(java.util.Collections.singletonMap) Directory(org.gradle.api.file.Directory) TaskInputs(org.gradle.api.tasks.TaskInputs) Project(org.gradle.api.Project) List(java.util.List) ProjectLayout(org.gradle.api.file.ProjectLayout) TaskContainer(org.gradle.api.tasks.TaskContainer) GenerateApiMapping(gradlebuild.docs.dsl.source.GenerateApiMapping) GenerateDefaultImports(gradlebuild.docs.dsl.source.GenerateDefaultImports) Plugin(org.gradle.api.Plugin) GenerateDefaultImports(gradlebuild.docs.dsl.source.GenerateDefaultImports) GenerateApiMapping(gradlebuild.docs.dsl.source.GenerateApiMapping) SourceSetContainer(org.gradle.api.tasks.SourceSetContainer) Directory(org.gradle.api.file.Directory)

Aggregations

Project (org.gradle.api.Project)269 File (java.io.File)98 Task (org.gradle.api.Task)71 Plugin (org.gradle.api.Plugin)69 Configuration (org.gradle.api.artifacts.Configuration)53 List (java.util.List)40 ArrayList (java.util.ArrayList)39 SourceSet (org.gradle.api.tasks.SourceSet)38 TaskProvider (org.gradle.api.tasks.TaskProvider)38 IOException (java.io.IOException)35 Map (java.util.Map)35 Action (org.gradle.api.Action)34 Set (java.util.Set)32 JavaPlugin (org.gradle.api.plugins.JavaPlugin)31 FileCollection (org.gradle.api.file.FileCollection)30 Provider (org.gradle.api.provider.Provider)27 HashMap (java.util.HashMap)26 Collectors (java.util.stream.Collectors)26 ObjectFactory (org.gradle.api.model.ObjectFactory)25 Collections (java.util.Collections)24