use of org.gradle.api.tasks.TaskProvider in project gradle by gradle.
the class GradleBuildDocumentationPlugin method applyConventions.
private void applyConventions(Project project, TaskContainer tasks, ObjectFactory objects, ProjectLayout layout, GradleDocumentationExtension extension) {
TaskProvider<Sync> stageDocs = tasks.register("stageDocs", Sync.class, task -> {
// release notes goes in the root of the docs
task.from(extension.getReleaseNotes().getRenderedDocumentation());
// DSL reference goes into dsl/
task.from(extension.getDslReference().getRenderedDocumentation(), sub -> sub.into("dsl"));
// Javadocs reference goes into javadoc/
task.from(extension.getJavadocs().getRenderedDocumentation(), sub -> sub.into("javadoc"));
// User manual goes into userguide/ (for historical reasons)
task.from(extension.getUserManual().getRenderedDocumentation(), sub -> sub.into("userguide"));
task.into(extension.getDocumentationRenderedRoot());
});
extension.getSourceRoot().convention(layout.getProjectDirectory().dir("src/docs"));
extension.getDocumentationRenderedRoot().convention(layout.getBuildDirectory().dir("docs"));
extension.getStagingRoot().convention(layout.getBuildDirectory().dir("working"));
ConfigurableFileTree css = objects.fileTree();
css.from(extension.getSourceRoot().dir("css"));
css.include("*.css");
extension.getCssFiles().from(css);
extension.getRenderedDocumentation().from(stageDocs);
Configuration runtimeClasspath = project.getConfigurations().getByName("runtimeClasspath");
Configuration sourcesPath = project.getConfigurations().create("sourcesPath");
sourcesPath.attributes(a -> {
a.attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage.class, Usage.JAVA_RUNTIME));
a.attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.class, Category.DOCUMENTATION));
a.attribute(DocsType.DOCS_TYPE_ATTRIBUTE, objects.named(DocsType.class, "gradle-source-folders"));
});
sourcesPath.setCanBeConsumed(false);
sourcesPath.setCanBeResolved(true);
sourcesPath.setVisible(false);
sourcesPath.extendsFrom(runtimeClasspath);
extension.getClasspath().from(runtimeClasspath);
extension.getDocumentedSource().from(sourcesPath.getIncoming().artifactView(v -> v.lenient(true)).getFiles().getAsFileTree().matching(f -> {
// Filter out any non-public APIs
f.include(PublicApi.INSTANCE.getIncludes());
f.exclude(PublicApi.INSTANCE.getExcludes());
}));
}
use of org.gradle.api.tasks.TaskProvider 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"));
});
}
use of org.gradle.api.tasks.TaskProvider in project curiostack by curioswitch.
the class GolangPlugin method apply.
@Override
public void apply(Project project) {
project.getRootProject().getPlugins().apply(GolangSetupPlugin.class);
project.getPlugins().apply(BasePlugin.class);
var golang = GolangExtension.createAndAdd(project);
var toolManager = DownloadedToolManager.get(project);
project.getTasks().addRule(new Rule() {
@Override
public String getDescription() {
return "Pattern: \"go_<command>\": Executes a go command.";
}
@Override
public void apply(String taskName) {
if (taskName.startsWith("go_")) {
project.getTasks().register(taskName, GoTask.class, t -> {
List<String> tokens = TASK_NAME_SPLITTER.splitToList(taskName);
t.args(tokens.subList(1, tokens.size()));
});
}
}
});
var setupGo = DownloadToolUtil.getSetupTask(project, "go");
setupGo.configure(t -> t.dependsOn(DownloadToolUtil.getSetupTask(project, "miniconda-build")));
project.getTasks().withType(GoTask.class).configureEach(t -> t.dependsOn(setupGo));
project.getRootProject().mkdir("build");
project.getExtensions().getByType(ExtraPropertiesExtension.class).set("gopath", project.getGradle().getGradleUserHomeDir().toPath().resolve("curiostack").resolve("gopath"));
var downloadDeps = project.getTasks().register("goDownloadDeps", GoTask.class, t -> {
t.args("mod", "download");
project.getRootProject().mkdir("build");
});
project.getTasks().register("goUpdateDeps", GoTask.class, t -> {
t.args("get", "-u");
// Go get often has a failed status code yet still basically worked so we let it go.
t.execCustomizer(exec -> exec.setIgnoreExitValue(true));
});
var checkFormat = project.getTasks().register("goCheck", GoTask.class, t -> {
t.command("gofmt");
t.args("-s", "-d", ".");
ByteArrayOutputStream stdOut = new ByteArrayOutputStream();
t.doLast(unused -> {
if (stdOut.size() > 0) {
throw new GradleException("There were formatting violations. Run :goFormat to fix.\n" + stdOut.toString());
}
});
t.execCustomizer(exec -> exec.setStandardOutput(stdOut));
});
var check = project.getTasks().named(LifecycleBasePlugin.CHECK_TASK_NAME);
check.configure(t -> t.dependsOn(checkFormat));
project.getTasks().register("goFormat", GoTask.class, t -> {
t.command("gofmt");
t.args("-s", "-w", ".");
});
var goTest = project.getTasks().register("goTest", GoTestTask.class, t -> {
t.execCustomizer(exec -> CondaExecUtil.condaExec(exec, toolManager, golang.getConda().get()));
t.dependsOn(DownloadToolUtil.getSetupTask(project, golang.getConda().get()), downloadDeps);
});
var goBuildAll = project.getTasks().register("goBuildAll");
project.getTasks().named(LifecycleBasePlugin.ASSEMBLE_TASK_NAME).configure(t -> t.dependsOn(goBuildAll));
project.afterEvaluate(unused -> {
TaskProvider<Task> test;
try {
test = project.getTasks().named("test");
} catch (UnknownTaskException e) {
test = project.getTasks().register("test");
TaskProvider<Task> testCopy = test;
check.configure(t -> t.dependsOn(testCopy));
}
test.configure(t -> t.dependsOn(goTest));
List<String> goOses = golang.getGoOses().get();
if (goOses.isEmpty()) {
goOses = ImmutableList.of("");
}
List<String> goArchs = golang.getGoArchs().get();
if (goArchs.isEmpty()) {
goArchs = ImmutableList.of("");
}
var goBuildDir = project.file("build/exe").toPath();
var exeName = golang.getExecutableName().getOrElse(project.getProjectDir().getName());
for (String goOs : goOses) {
for (String goArch : goArchs) {
String outputDir = goOs.isEmpty() ? "current" : goOs;
if (!goArch.isEmpty()) {
outputDir += '-' + goArch;
}
String outPath = goBuildDir.resolve(outputDir).resolve(exeName).toString() + (goOs.equals("windows") ? ".exe" : "");
var goBuild = project.getTasks().register("goBuild" + toTaskSuffix(goOs) + toTaskSuffix(goArch), GoTask.class, t -> {
t.args("build", "-o", outPath);
t.execCustomizer(exec -> {
if (!goOs.isEmpty()) {
exec.environment("GOOS", goOs);
}
if (!goArch.isEmpty()) {
exec.environment("GOARCH", goArch);
}
CondaExecUtil.condaExec(exec, DownloadedToolManager.get(project), golang.getConda().get());
});
t.dependsOn(DownloadToolUtil.getSetupTask(project, golang.getConda().get()), downloadDeps);
});
project.getTasks().register("jib" + toTaskSuffix(goOs) + toTaskSuffix(goArch), JibTask.class, t -> {
t.dependsOn(goBuild);
t.setExePath(Paths.get(outPath));
});
goBuildAll.configure(t -> t.dependsOn(goBuild));
}
}
});
}
Aggregations