Skip to content

Commit

Permalink
[scaladoc] provide aggregate tasks. Fixes #79
Browse files Browse the repository at this point in the history
  • Loading branch information
aalmiray committed Mar 2, 2019
1 parent f55a42d commit e2bba82
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ class ApidocPlugin extends AbstractKordampPlugin {
project.childProjects.values().each {
configureProject(it)
}
configureRootProject(project)
configureRootProject(project, true)
} else {
configureProject(project)
configureRootProject(project)
configureRootProject(project, false)
}
} else {
configureProject(project)
Expand All @@ -86,8 +86,8 @@ class ApidocPlugin extends AbstractKordampPlugin {
GroovydocPlugin.applyIfMissing(project)
}

private void configureRootProject(Project project) {
if (hasBeenVisited(project)) {
private void configureRootProject(Project project, boolean checkIfApplied) {
if (checkIfApplied && hasBeenVisited(project)) {
return
}
setVisited(project, true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class Scaladoc extends AbstractFeature {
Set<String> includes = new LinkedHashSet<>()
final ScaladocOptions options = new ScaladocOptions()

private final Set<Project> excludedProjects = new LinkedHashSet<>()

private final Set<Project> projects = new LinkedHashSet<>()
private final Set<ScalaDoc> scaladocTasks = new LinkedHashSet<>()
private final Set<Jar> scaladocJarTasks = new LinkedHashSet<>()
Expand All @@ -63,6 +65,10 @@ class Scaladoc extends AbstractFeature {
Map<String, Map<String, Object>> toMap() {
Map map = [enabled: enabled]

if(isRoot()) {
map.excludedProjects = excludedProjects
}

if (enabled) {
map.title = title
map.excludes = excludes
Expand Down Expand Up @@ -123,6 +129,11 @@ class Scaladoc extends AbstractFeature {
o1.projects().addAll(o2.projects())
o1.scaladocTasks().addAll(o2.scaladocTasks())
o1.scaladocJarTasks().addAll(o2.scaladocJarTasks())
o1.excludedProjects().addAll(o2.excludedProjects())
}

Set<Project> excludedProjects() {
excludedProjects
}

Set<Project> projects() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
*/
package org.kordamp.gradle.plugin.scaladoc

import org.gradle.BuildAdapter
import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.invocation.Gradle
import org.gradle.api.plugins.JavaBasePlugin
import org.gradle.api.plugins.scala.ScalaBasePlugin
import org.gradle.api.tasks.bundling.Jar
Expand All @@ -39,6 +41,8 @@ import static org.kordamp.gradle.plugin.base.BasePlugin.isRootProject
class ScaladocPlugin extends AbstractKordampPlugin {
static final String SCALADOC_TASK_NAME = 'scaladoc'
static final String SCALADOC_JAR_TASK_NAME = 'scaladocJar'
static final String AGGREGATE_SCALADOCS_TASK_NAME = 'aggregateScaladocs'
static final String AGGREGATE_SCALADOCS_JAR_TASK_NAME = 'aggregateScaladocsJar'

Project project

Expand All @@ -50,8 +54,10 @@ class ScaladocPlugin extends AbstractKordampPlugin {
project.childProjects.values().each {
configureProject(it)
}
configureRootProject(project, true)
} else {
configureProject(project)
configureRootProject(project, false)
}
} else {
configureProject(project)
Expand All @@ -64,6 +70,64 @@ class ScaladocPlugin extends AbstractKordampPlugin {
}
}

private void configureRootProject(Project project, boolean checkIfApplied) {
if (checkIfApplied && hasBeenVisited(project)) {
return
}
setVisited(project, true)

BasePlugin.applyIfMissing(project)

if (isRootProject(project) && !project.childProjects.isEmpty()) {
createAggregateScaladocsTask(project)

project.gradle.addBuildListener(new BuildAdapter() {
@Override
void projectsEvaluated(Gradle gradle) {
doConfigureRootProject(project)
}
})
}
}

private void doConfigureRootProject(Project project) {
ProjectConfigurationExtension effectiveConfig = resolveEffectiveConfig(project)
setEnabled(effectiveConfig.apidoc.enabled)

if (!enabled) {
return
}

if (!project.childProjects.isEmpty()) {
List<ScalaDoc> scaladocs = []
project.tasks.withType(ScalaDoc) { ScalaDoc scaladoc -> if (scaladoc.name != AGGREGATE_SCALADOCS_TASK_NAME && scaladoc.enabled) scaladocs << scaladoc }
project.childProjects.values().each { Project p ->
if (p in effectiveConfig.scaladoc.excludedProjects()) return
p.tasks.withType(ScalaDoc) { ScalaDoc scaladoc -> if (scaladoc.enabled) scaladocs << scaladoc }
}
scaladocs = scaladocs.unique()

ScalaDoc aggregateScaladocs = project.tasks.findByName(AGGREGATE_SCALADOCS_TASK_NAME)
Jar aggregateScaladocsJar = project.tasks.findByName(AGGREGATE_SCALADOCS_JAR_TASK_NAME)

if (scaladocs) {
aggregateScaladocs.configure { task ->
task.enabled true
task.dependsOn scaladocs
task.source scaladocs.source
task.classpath = project.files(scaladocs.classpath)

effectiveConfig.scaladoc.applyTo(task)
// task.options.footer = "Copyright &copy; ${effectiveConfig.info.copyrightYear} ${effectiveConfig.info.authors.join(', ')}. All rights reserved."
}
aggregateScaladocsJar.configure {
enabled true
from aggregateScaladocs.destinationDir
}
}
}
}

private void configureProject(Project project) {
if (hasBeenVisited(project)) {
return
Expand Down Expand Up @@ -140,4 +204,23 @@ class ScaladocPlugin extends AbstractKordampPlugin {

scaladocJarTask
}

private List<Task> createAggregateScaladocsTask(Project project) {
ScalaDoc aggregateScaladocs = project.tasks.create(AGGREGATE_SCALADOCS_TASK_NAME, ScalaDoc) {
enabled false
group JavaBasePlugin.DOCUMENTATION_GROUP
description 'Aggregates ScalaDoc API docs for all projects.'
destinationDir project.file("${project.buildDir}/docs/scaladoc")
}

Jar aggregateScaladocsJar = project.tasks.create(AGGREGATE_SCALADOCS_JAR_TASK_NAME, Jar) {
enabled false
dependsOn aggregateScaladocs
group JavaBasePlugin.DOCUMENTATION_GROUP
description 'An archive of the aggregate ScalaDoc API docs'
classifier 'scaladoc'
}

[aggregateScaladocs, aggregateScaladocsJar]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ config {
title
includes
excludes
excludedProjects
<<_scaladoc_options,options>> {
bottom
top
Expand All @@ -37,11 +38,12 @@ config {

[options="header", cols="5*"]
|===
| Name | Type | Required | Default Value | Description
| enabled | boolean | no | true | Disables `org.kordamp.gradle.scaladoc` plugin if `false`
| title | String | no | "${project.name} ${project.version}" |
| includes | Set<String> | no | [] |
| excludes | Set<String> | no | [] |
| Name | Type | Required | Default Value | Description
| enabled | boolean | no | true | Disables `org.kordamp.gradle.scaladoc` plugin if `false`
| title | String | no | "${project.name} ${project.version}" |
| includes | Set<String> | no | [] |
| excludes | Set<String> | no | [] |
| excludedProjects | Set<Project> | | [] | Projects in the set are excluded from aggregation
|===

[[_scaladoc_options]]
Expand Down Expand Up @@ -92,3 +94,33 @@ classifier:: scaladoc
destinationDir:: `${project.buildDir}/build/libs`
from:: `scaladoc.destinationDir`

[[_task_aggregate_scaladocs]]
=== AggregateScaladocs

Aggregates Scaladoc API docs for all projects. +
Consumes settings from `config.<<_org_kordamp_gradle_scaladoc,scaladoc>>` defined in the root project. +
This task is added to the root project.

[horizontal]
Name:: aggregateScaladocs
Type:: `org.gradle.api.tasks.scala.ScalaDoc`

.Properties
[horizontal]
destinationDir:: `${rootProject.buildDir}/docs/scaladoc`

[[_task_aggregate_scaladocs_jar]]
=== AggregateScaladocsJar

An archive of the aggregate Scaladoc API docs. +
This task is added to the root project.

[horizontal]
Name:: aggregateScaladocsJar
Type:: `org.gradle.api.tasks.bundling.Jar`

.Properties
[horizontal]
classifier:: scaladoc
destinationDir:: `${rootProject.buildDir}/build/libs`

0 comments on commit e2bba82

Please sign in to comment.