Search in sources :

Example 1 with Javadoc

use of org.gradle.api.tasks.javadoc.Javadoc in project gradle by gradle.

the class JavaPlugin method configureJavaDoc.

private void configureJavaDoc(JavaPluginConvention pluginConvention) {
    Project project = pluginConvention.getProject();
    SourceSet mainSourceSet = pluginConvention.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME);
    Javadoc javadoc = project.getTasks().create(JAVADOC_TASK_NAME, Javadoc.class);
    javadoc.setDescription("Generates Javadoc API documentation for the main source code.");
    javadoc.setGroup(JavaBasePlugin.DOCUMENTATION_GROUP);
    javadoc.setClasspath(mainSourceSet.getOutput().plus(mainSourceSet.getCompileClasspath()));
    javadoc.setSource(mainSourceSet.getAllJava());
    addDependsOnTaskInOtherProjects(javadoc, true, JAVADOC_TASK_NAME, COMPILE_CONFIGURATION_NAME);
}
Also used : Project(org.gradle.api.Project) SourceSet(org.gradle.api.tasks.SourceSet) Javadoc(org.gradle.api.tasks.javadoc.Javadoc)

Example 2 with Javadoc

use of org.gradle.api.tasks.javadoc.Javadoc in project curiostack by curioswitch.

the class CuriostackPlugin method setupJavaProject.

private static void setupJavaProject(Project project) {
    PluginContainer plugins = project.getPlugins();
    plugins.apply(AptPlugin.class);
    plugins.apply(AptIdeaPlugin.class);
    plugins.apply(BaselineIdea.class);
    plugins.apply(DependencyManagementPlugin.class);
    plugins.apply(ErrorPronePlugin.class);
    plugins.apply(LicensePlugin.class);
    plugins.apply(SpotlessPlugin.class);
    plugins.apply(VersionsPlugin.class);
    project.getTasks().withType(JavaCompile.class, task -> {
        task.getOptions().setIncremental(true);
        task.getOptions().getCompilerArgs().addAll(ImmutableList.of("-XepDisableWarningsInGeneratedCode", "-XepExcludedPaths:(.*/build/.*|.*/gen-src/.*)", "-Xep:AutoFactoryAtInject:ERROR", "-Xep:ClassName:ERROR", "-Xep:ComparisonContractViolated:ERROR", "-Xep:DepAnn:ERROR", "-Xep:DivZero:ERROR", "-Xep:EmptyIf:ERROR", "-Xep:FuzzyEqualsShouldNotBeUsedInEqualsMethod:ERROR", "-Xep:InjectInvalidTargetingOnScopingAnnotation:ERROR", "-Xep:InjectScopeAnnotationOnInterfaceOrAbstractClass:ERROR", "-Xep:InsecureCryptoUsage:ERROR", "-Xep:IterablePathParameter:ERROR", "-Xep:LongLiteralLowerCaseSuffix:ERROR", "-Xep:NumericEquality:ERROR", "-Xep:ParameterPackage:ERROR", "-Xep:ProtoStringFieldReferenceEquality:ERROR", "-Xep:AssistedInjectAndInjectOnConstructors:ERROR", "-Xep:BigDecimalLiteralDouble:ERROR", "-Xep:ConstructorLeaksThis:ERROR", "-Xep:InconsistentOverloads:ERROR", "-Xep:MissingDefault:ERROR", "-Xep:PrimitiveArrayPassedToVarargsMethod:ERROR", "-Xep:RedundantThrows:ERROR", "-Xep:StaticQualifiedUsingExpression:ERROR", "-Xep:StringEquality:ERROR", "-Xep:TestExceptionChecker:ERROR", "-Xep:FieldMissingNullable:ERROR", "-Xep:LambdaFunctionalInterface:ERROR", "-Xep:MethodCanBeStatic:ERROR", "-Xep:MixedArrayDimensions:ERROR", "-Xep:MultiVariableDeclaration:ERROR", "-Xep:MultipleTopLevelClasses:ERROR", "-Xep:MultipleUnaryOperatorsInMethodCall:ERROR", "-Xep:PackageLocation:ERROR", "-Xep:ParameterComment:ERROR", "-Xep:ParameterNotNullable:ERROR", "-Xep:PrivateConstructorForUtilityClass:ERROR", "-Xep:RemoveUnusedImports:ERROR", "-Xep:ReturnMissingNullable:ERROR", "-Xep:SwitchDefault:ERROR", "-Xep:ThrowsUncheckedException:ERROR", "-Xep:UngroupedOverloads:ERROR", "-Xep:UnnecessaryStaticImport:ERROR", "-Xep:UseBinds:ERROR", "-Xep:WildcardImport:ERROR"));
        project.getTasks().withType(SpotlessTask.class, spotlessTask -> spotlessTask.dependsOn(task));
    });
    JavaPluginConvention javaPlugin = project.getConvention().getPlugin(JavaPluginConvention.class);
    javaPlugin.setSourceCompatibility(JavaVersion.VERSION_1_9);
    javaPlugin.setTargetCompatibility(JavaVersion.VERSION_1_9);
    Test test = project.getTasks().withType(Test.class).getByName("test");
    if (project.getRootProject().hasProperty("updateSnapshots")) {
        test.jvmArgs(ImmutableList.of("-Dorg.curioswitch.testing.updateSnapshots=true"));
    }
    test.useJUnitPlatform(platform -> platform.includeEngines("junit-jupiter", "junit-vintage"));
    // While Gradle attempts to generate a unique module name automatically,
    // it doesn't seem to always work properly, so we just always use unique
    // module names.
    project.getPlugins().withType(IdeaPlugin.class, plugin -> {
        IdeaModule module = plugin.getModel().getModule();
        String moduleName = project.getName();
        Project ancestor = project.getParent();
        while (ancestor != null && ancestor != project.getRootProject()) {
            moduleName = ancestor.getName() + "-" + moduleName;
            ancestor = ancestor.getParent();
        }
        module.setName(moduleName);
        project.getTasks().getByName("clean").doLast(unused -> project.file(project.getName() + ".iml").delete());
        new DslObject(module).getConvention().getPlugin(ModuleAptConvention.class).getApt().setAddAptDependencies(false);
    });
    DependencyManagementExtension dependencyManagement = project.getExtensions().getByType(DependencyManagementExtension.class);
    dependencyManagement.dependencies(dependencies -> {
        for (DependencySet set : StandardDependencies.DEPENDENCY_SETS) {
            dependencies.dependencySet(ImmutableMap.of("group", set.group(), "version", set.version()), dependencySet -> set.modules().forEach(dependencySet::entry));
        }
        StandardDependencies.DEPENDENCIES.forEach(dependencies::dependency);
    });
    // Pretty much all java code needs at least the Generated annotation.
    project.getDependencies().add(JavaPlugin.IMPLEMENTATION_CONFIGURATION_NAME, "javax.annotation:javax.annotation-api");
    project.afterEvaluate(CuriostackPlugin::addStandardJavaTestDependencies);
    project.getConfigurations().all(configuration -> configuration.exclude(ImmutableMap.of("group", "com.google.guava", "module", "guava-jdk5")));
    Javadoc javadoc = (Javadoc) project.getTasks().getByName("javadoc");
    CoreJavadocOptions options = (CoreJavadocOptions) javadoc.getOptions();
    options.quiet();
    options.addBooleanOption("Xdoclint:all,-missing", true);
    project.getTasks().create("javadocJar", Jar.class, javadocJar -> {
        javadocJar.dependsOn(javadoc);
        javadocJar.setClassifier("javadoc");
        javadocJar.from(javadoc.getDestinationDir());
    });
    SourceSetContainer sourceSets = javaPlugin.getSourceSets();
    project.getTasks().create("sourceJar", Jar.class, sourceJar -> {
        sourceJar.setClassifier("sources");
        sourceJar.from(sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME).getAllSource());
    });
    SpotlessExtension spotless = project.getExtensions().getByType(SpotlessExtension.class);
    spotless.java((extension) -> extension.googleJavaFormat(GOOGLE_JAVA_FORMAT_VERSION));
    project.getTasks().create("resolveDependencies", resolveDependencies -> resolveDependencies.doLast(unused -> {
        project.getConfigurations().all(configuration -> {
            if (configuration.isCanBeResolved()) {
                configuration.resolve();
            }
        });
    }));
    // Protobuf plugin doesn't add proto sourceset to allSource, which seems like an omission.
    // We add it to make sure license plugin picks up the files.
    project.getPlugins().withType(ProtobufPlugin.class, unused -> {
        for (SourceSet sourceSet : sourceSets) {
            sourceSet.getAllSource().source(((ExtensionAware) sourceSet).getExtensions().getByType(ProtobufSourceDirectorySet.class));
        }
    });
    project.getPlugins().withType(JMHPlugin.class, unused -> {
        JMHPluginExtension jmh = project.getExtensions().getByType(JMHPluginExtension.class);
        // Benchmarks are usually very small and converge quickly. If this stops being the
        // case
        // these numbers can be adjusted.
        jmh.setFork(2);
        jmh.setIterations(5);
        jmh.setProfilers(ImmutableList.of("hs_comp"));
        jmh.setJmhVersion("1.19");
        Object jmhRegex = project.getRootProject().findProperty("jmhRegex");
        if (jmhRegex != null) {
            jmh.setInclude((String) jmhRegex);
        }
        // We will use the jmhManaged for any dependencies that should only be applied to JMH
        // but should be resolved by our managed dependencies. We need a separate
        // configuration
        // to be able to provide the resolution workaround described below.
        Configuration jmhManaged = project.getConfigurations().create("jmhManaged");
        Configuration jmhConfiguration = project.getConfigurations().getByName("jmh");
        jmhConfiguration.extendsFrom(jmhManaged);
        // JMH plugin uses a detached configuration to build an uber-jar, which
        // dependencyManagement
        // doesn't know about. Work around this by forcing parent configurations to be
        // resolved and
        // added directly to the jmh configuration, which overwrites the otherwise
        // unresolvable
        // dependency.
        project.afterEvaluate(p -> {
            jmhConfiguration.getExtendsFrom().forEach(parent -> {
                parent.getResolvedConfiguration().getFirstLevelModuleDependencies().forEach(dep -> {
                    project.getDependencies().add("jmh", dep.getModule().toString());
                });
            });
        });
    });
    project.getPlugins().withType(JooqPlugin.class, unused -> {
        project.getTasks().withType(JooqTask.class, t -> {
            for (String dependency : ImmutableList.of("javax.activation:activation", "javax.xml.bind:jaxb-api", "com.sun.xml.bind:jaxb-core", "com.sun.xml.bind:jaxb-impl", "mysql:mysql-connector-java", // Not sure why this isn't automatically added.
            "com.google.guava:guava", "com.google.cloud.sql:mysql-socket-factory")) {
                project.getDependencies().add("jooqRuntime", dependency);
            }
        });
    });
    // It is very common to want to pass in command line system properties to the binary, so just
    // always forward properties. It won't affect production since no one runs binaries via Gradle
    // in production.
    project.getTasks().withType(JavaExec.class, task -> System.getProperties().entrySet().stream().filter(entry -> !entry.getKey().equals("java.endorsed.dirs")).forEach(entry -> task.systemProperty((String) entry.getKey(), entry.getValue())));
}
Also used : AptIdeaPlugin(net.ltgt.gradle.apt.AptIdeaPlugin) Closure(groovy.lang.Closure) JavaPlugin(org.gradle.api.plugins.JavaPlugin) IdeaPlugin(org.gradle.plugins.ide.idea.IdeaPlugin) ModuleAptConvention(net.ltgt.gradle.apt.AptIdeaPlugin.ModuleAptConvention) DependencyManagementPlugin(io.spring.gradle.dependencymanagement.DependencyManagementPlugin) DslObject(org.gradle.api.internal.plugins.DslObject) Task(org.gradle.api.Task) Javadoc(org.gradle.api.tasks.javadoc.Javadoc) YarnTask(com.moowork.gradle.node.yarn.YarnTask) Map(java.util.Map) LicensePlugin(nl.javadude.gradle.plugins.license.LicensePlugin) ExtensionAware(org.gradle.api.plugins.ExtensionAware) Splitter(com.google.common.base.Splitter) Path(java.nio.file.Path) PythonEnvsExtension(com.jetbrains.python.envs.PythonEnvsExtension) IdeaModule(org.gradle.plugins.ide.idea.model.IdeaModule) Delete(org.gradle.api.tasks.Delete) ImmutableMap(com.google.common.collect.ImmutableMap) Project(org.gradle.api.Project) NodeTask(com.moowork.gradle.node.task.NodeTask) Predicate(java.util.function.Predicate) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ProtobufPlugin(com.google.protobuf.gradle.ProtobufPlugin) SetupGitHooks(org.curioswitch.gradle.plugins.curiostack.tasks.SetupGitHooks) SpotlessExtension(com.diffplug.gradle.spotless.SpotlessExtension) AptPlugin(net.ltgt.gradle.apt.AptPlugin) JavaVersion(org.gradle.api.JavaVersion) StandardCharsets(java.nio.charset.StandardCharsets) UncheckedIOException(java.io.UncheckedIOException) JavaLibraryPlugin(org.gradle.api.plugins.JavaLibraryPlugin) List(java.util.List) CoreJavadocOptions(org.gradle.external.javadoc.CoreJavadocOptions) VersionsPlugin(com.github.benmanes.gradle.versions.VersionsPlugin) YarnInstallTask(com.moowork.gradle.node.yarn.YarnInstallTask) BaselineIdea(com.palantir.baseline.plugins.BaselineIdea) ByteStreams(com.google.common.io.ByteStreams) Optional(java.util.Optional) PluginContainer(org.gradle.api.plugins.PluginContainer) ExecSpec(org.gradle.process.ExecSpec) DependencySet(org.curioswitch.gradle.plugins.curiostack.StandardDependencies.DependencySet) XmlProvider(org.gradle.api.XmlProvider) LicenseExtension(nl.javadude.gradle.plugins.license.LicenseExtension) JooqPlugin(nu.studer.gradle.jooq.JooqPlugin) CurioGenericCiPlugin(org.curioswitch.gradle.plugins.ci.CurioGenericCiPlugin) ErrorPronePlugin(net.ltgt.gradle.errorprone.ErrorPronePlugin) NodePlugin(com.moowork.gradle.node.NodePlugin) HashMap(java.util.HashMap) BasePlugin(org.gradle.api.plugins.BasePlugin) SourceSet(org.gradle.api.tasks.SourceSet) Configuration(org.gradle.api.artifacts.Configuration) JMHPluginExtension(me.champeau.gradle.JMHPluginExtension) ImmutableList(com.google.common.collect.ImmutableList) DependencyHandler(org.gradle.api.artifacts.dsl.DependencyHandler) DependencyManagementExtension(io.spring.gradle.dependencymanagement.dsl.DependencyManagementExtension) SourceSetContainer(org.gradle.api.tasks.SourceSetContainer) JooqTask(nu.studer.gradle.jooq.JooqTask) CreateShellConfigTask(org.curioswitch.gradle.plugins.curiostack.tasks.CreateShellConfigTask) NodeExtension(com.moowork.gradle.node.NodeExtension) Test(org.gradle.api.tasks.testing.Test) PythonEnvsPlugin(com.jetbrains.python.envs.PythonEnvsPlugin) JavaCompile(org.gradle.api.tasks.compile.JavaCompile) Resources(com.google.common.io.Resources) NpmTask(com.moowork.gradle.node.npm.NpmTask) JavaPluginConvention(org.gradle.api.plugins.JavaPluginConvention) Jar(org.gradle.jvm.tasks.Jar) FileOutputStream(java.io.FileOutputStream) JMHPlugin(me.champeau.gradle.JMHPlugin) SpotlessTask(com.diffplug.gradle.spotless.SpotlessTask) IOException(java.io.IOException) Node(groovy.util.Node) GcloudPlugin(org.curioswitch.gradle.plugins.gcloud.GcloudPlugin) File(java.io.File) SpotlessPlugin(com.diffplug.gradle.spotless.SpotlessPlugin) ProtobufSourceDirectorySet(com.google.protobuf.gradle.ProtobufSourceDirectorySet) Os(org.apache.tools.ant.taskdefs.condition.Os) Paths(java.nio.file.Paths) ResolutionRulesPlugin(nebula.plugin.resolutionrules.ResolutionRulesPlugin) CommandUtil(org.curioswitch.gradle.plugins.shared.CommandUtil) JavaExec(org.gradle.api.tasks.JavaExec) LambdaClosure(org.curioswitch.gradle.common.LambdaClosure) Plugin(org.gradle.api.Plugin) Copy(org.gradle.api.tasks.Copy) InputStream(java.io.InputStream) PluginContainer(org.gradle.api.plugins.PluginContainer) Configuration(org.gradle.api.artifacts.Configuration) DslObject(org.gradle.api.internal.plugins.DslObject) SpotlessExtension(com.diffplug.gradle.spotless.SpotlessExtension) DependencySet(org.curioswitch.gradle.plugins.curiostack.StandardDependencies.DependencySet) Javadoc(org.gradle.api.tasks.javadoc.Javadoc) DependencyManagementExtension(io.spring.gradle.dependencymanagement.dsl.DependencyManagementExtension) SourceSetContainer(org.gradle.api.tasks.SourceSetContainer) Project(org.gradle.api.Project) CoreJavadocOptions(org.gradle.external.javadoc.CoreJavadocOptions) SourceSet(org.gradle.api.tasks.SourceSet) IdeaModule(org.gradle.plugins.ide.idea.model.IdeaModule) JavaPluginConvention(org.gradle.api.plugins.JavaPluginConvention) Test(org.gradle.api.tasks.testing.Test) JMHPluginExtension(me.champeau.gradle.JMHPluginExtension) ExtensionAware(org.gradle.api.plugins.ExtensionAware) ProtobufSourceDirectorySet(com.google.protobuf.gradle.ProtobufSourceDirectorySet) DslObject(org.gradle.api.internal.plugins.DslObject)

Example 3 with Javadoc

use of org.gradle.api.tasks.javadoc.Javadoc in project rest.li by linkedin.

the class PegasusPlugin method configureGeneratedSourcesAndJavadoc.

@SuppressWarnings("deprecation")
protected void configureGeneratedSourcesAndJavadoc(Project project) {
    _generateJavadocTask = project.getTasks().create("generateJavadoc", Javadoc.class);
    if (_generateSourcesJarTask == null) {
        // 
        // configuration for publishing jars containing sources for generated classes
        // to the project artifacts for including in the ivy.xml
        // 
        ConfigurationContainer configurations = project.getConfigurations();
        Configuration generatedSources = configurations.maybeCreate("generatedSources");
        Configuration testGeneratedSources = configurations.maybeCreate("testGeneratedSources");
        testGeneratedSources.extendsFrom(generatedSources);
        _generateSourcesJarTask = project.getTasks().create("generateSourcesJar", Jar.class, jarTask -> {
            jarTask.setGroup(JavaBasePlugin.DOCUMENTATION_GROUP);
            jarTask.setDescription("Generates a jar file containing the sources for the generated Java classes.");
            // FIXME change to #getArchiveClassifier().set("sources"); breaks backwards-compatibility before 5.1
            jarTask.setClassifier("sources");
        });
        project.getArtifacts().add("generatedSources", _generateSourcesJarTask);
    }
    if (_generateJavadocJarTask == null) {
        // 
        // configuration for publishing jars containing Javadoc for generated classes
        // to the project artifacts for including in the ivy.xml
        // 
        ConfigurationContainer configurations = project.getConfigurations();
        Configuration generatedJavadoc = configurations.maybeCreate("generatedJavadoc");
        Configuration testGeneratedJavadoc = configurations.maybeCreate("testGeneratedJavadoc");
        testGeneratedJavadoc.extendsFrom(generatedJavadoc);
        _generateJavadocJarTask = project.getTasks().create("generateJavadocJar", Jar.class, jarTask -> {
            jarTask.dependsOn(_generateJavadocTask);
            jarTask.setGroup(JavaBasePlugin.DOCUMENTATION_GROUP);
            jarTask.setDescription("Generates a jar file containing the Javadoc for the generated Java classes.");
            // FIXME change to #getArchiveClassifier().set("sources"); breaks backwards-compatibility before 5.1
            jarTask.setClassifier("javadoc");
            jarTask.from(_generateJavadocTask.getDestinationDir());
        });
        project.getArtifacts().add("generatedJavadoc", _generateJavadocJarTask);
    } else {
        // TODO: Tighten the types so that _generateJavadocJarTask must be of type Jar.
        ((Jar) _generateJavadocJarTask).from(_generateJavadocTask.getDestinationDir());
        _generateJavadocJarTask.dependsOn(_generateJavadocTask);
    }
}
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) Configuration(org.gradle.api.artifacts.Configuration) ConfigurationContainer(org.gradle.api.artifacts.ConfigurationContainer) Javadoc(org.gradle.api.tasks.javadoc.Javadoc) Jar(org.gradle.api.tasks.bundling.Jar)

Example 4 with Javadoc

use of org.gradle.api.tasks.javadoc.Javadoc in project gradle by gradle.

the class JavaBasePlugin method configureJavaDoc.

private void configureJavaDoc(final Project project, final JavaPluginExtension javaPluginExtension) {
    project.getTasks().withType(Javadoc.class).configureEach(javadoc -> {
        javadoc.getConventionMapping().map("destinationDir", () -> new File(javaPluginExtension.getDocsDir().get().getAsFile(), "javadoc"));
        javadoc.getConventionMapping().map("title", () -> project.getExtensions().getByType(ReportingExtension.class).getApiDocTitle());
        javadoc.getJavadocTool().convention(getToolchainTool(project, JavaToolchainService::javadocToolFor));
    });
}
Also used : Javadoc(org.gradle.api.tasks.javadoc.Javadoc) File(java.io.File)

Example 5 with Javadoc

use of org.gradle.api.tasks.javadoc.Javadoc 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

Javadoc (org.gradle.api.tasks.javadoc.Javadoc)7 File (java.io.File)5 Project (org.gradle.api.Project)5 Plugin (org.gradle.api.Plugin)4 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Map (java.util.Map)3 SourceSet (org.gradle.api.tasks.SourceSet)3 SpotlessExtension (com.diffplug.gradle.spotless.SpotlessExtension)2 SpotlessPlugin (com.diffplug.gradle.spotless.SpotlessPlugin)2 VersionsPlugin (com.github.benmanes.gradle.versions.VersionsPlugin)2 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 Resources (com.google.common.io.Resources)2 InputStream (java.io.InputStream)2 Path (java.nio.file.Path)2 Task (org.gradle.api.Task)2 Configuration (org.gradle.api.artifacts.Configuration)2