use of org.gradle.api.file.Directory 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);
});
}
use of org.gradle.api.file.Directory 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);
}
use of org.gradle.api.file.Directory in project gradle by gradle.
the class CheckstylePlugin method createExtension.
@Override
protected CodeQualityExtension createExtension() {
extension = project.getExtensions().create("checkstyle", CheckstyleExtension.class, project);
extension.setToolVersion(DEFAULT_CHECKSTYLE_VERSION);
Directory directory = project.getRootProject().getLayout().getProjectDirectory().dir(CONFIG_DIR_NAME);
extension.getConfigDirectory().convention(directory);
extension.setConfig(project.getResources().getText().fromFile(extension.getConfigDirectory().file("checkstyle.xml").orElse(directory.file("checkstyle.xml"))));
return extension;
}
use of org.gradle.api.file.Directory in project gradle by gradle.
the class DefaultJvmLanguageGeneratedSourceDirectoryBuilder method build.
void build() {
if (taskBuilder == null) {
throw new IllegalStateException("You must specify how sources will be compiled either by calling compiledWithJava or compiledBy");
}
if (mapping == null) {
throw new IllegalStateException("You must specify the mapping function from your source generating task to a directory property");
}
if (sourceTaskProvider == null) {
throw new IllegalStateException("You must specify the source generation task");
}
Provider<Directory> sourceDirectory = sourceTaskProvider.flatMap(task -> mapping.apply(Cast.uncheckedCast(task)));
DefaultCompileTaskDetails details = createTaskDetails(project.getObjects().directoryProperty().convention(sourceDirectory));
DefaultSourceSetOutput sourceSetOutput = Cast.cast(DefaultSourceSetOutput.class, sourceSet.getOutput());
sourceSetOutput.addClassesDir(details.compileTask.flatMap(task -> details.compileMapping.apply(Cast.uncheckedCast(task))));
sourceSetOutput.registerClassesContributor(details.compileTask);
sourceSetOutput.getGeneratedSourcesDirs().from(sourceDirectory);
project.getTasks().matching(DefaultJvmLanguageGeneratedSourceDirectoryBuilder::isClassesTask).configureEach(classes -> classes.dependsOn(details.compileTask));
if (includeInAllJava) {
sourceSet.getAllJava().srcDir(sourceDirectory);
}
sourceSet.getAllSource().srcDir(sourceDirectory);
}
use of org.gradle.api.file.Directory in project gradle by gradle.
the class LifecycleBasePlugin method addClean.
private void addClean(final ProjectInternal project) {
Provider<Directory> buildDir = project.getLayout().getBuildDirectory();
// Register at least the project buildDir as a directory to be deleted.
final BuildOutputCleanupRegistry buildOutputCleanupRegistry = project.getServices().get(BuildOutputCleanupRegistry.class);
buildOutputCleanupRegistry.registerOutputs(buildDir);
final Provider<Delete> clean = project.getTasks().register(CLEAN_TASK_NAME, Delete.class, cleanTask -> {
cleanTask.setDescription("Deletes the build directory.");
cleanTask.setGroup(BUILD_GROUP);
cleanTask.delete(buildDir);
});
buildOutputCleanupRegistry.registerOutputs(clean.map(cl -> cl.getTargetFiles()));
}
Aggregations