Skip to content

Commit 38995b0

Browse files
committed
Import sources for javadoc through a dependency (#1461)
Add configurations for importing and exporting source directories Add an additionalSources configuration to add another project's source to the current project's javadoc. Add a sourceElements configuration to register all java source directories in the project under so they may be picked up by other projects.
1 parent d4b315b commit 38995b0

File tree

6 files changed

+73
-41
lines changed

6 files changed

+73
-41
lines changed

buildSrc/src/main/groovy/org/elasticsearch/hadoop/gradle/BuildPlugin.groovy

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,15 @@ import org.gradle.api.artifacts.ProjectDependency
1717
import org.gradle.api.artifacts.ResolutionStrategy
1818
import org.gradle.api.artifacts.maven.MavenPom
1919
import org.gradle.api.artifacts.maven.MavenResolver
20+
import org.gradle.api.attributes.LibraryElements
21+
import org.gradle.api.attributes.Usage
2022
import org.gradle.api.file.CopySpec
23+
import org.gradle.api.file.FileCollection
2124
import org.gradle.api.java.archives.Manifest
2225
import org.gradle.api.plugins.JavaPlugin
2326
import org.gradle.api.plugins.MavenPlugin
2427
import org.gradle.api.plugins.MavenPluginConvention
28+
import org.gradle.api.tasks.SourceSet
2529
import org.gradle.api.tasks.SourceSetContainer
2630
import org.gradle.api.tasks.TaskProvider
2731
import org.gradle.api.tasks.Upload
@@ -84,6 +88,32 @@ class BuildPlugin implements Plugin<Project> {
8488
}
8589

8690
private static void configureConfigurations(Project project) {
91+
if (project != project.rootProject) {
92+
// Set up avenues for sharing source files between projects in order to create embedded Javadocs
93+
// Import source configuration
94+
Configuration sources = project.configurations.create("additionalSources")
95+
sources.canBeConsumed = false
96+
sources.canBeResolved = true
97+
sources.attributes {
98+
// Changing USAGE is required when working with Scala projects, otherwise the source dirs get pulled
99+
// into incremental compilation analysis.
100+
attribute(Usage.USAGE_ATTRIBUTE, project.objects.named(Usage, 'java-source'))
101+
attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, project.objects.named(LibraryElements, 'sources'))
102+
}
103+
104+
// Export source configuration
105+
Configuration sourceElements = project.configurations.create("sourceElements")
106+
sourceElements.canBeConsumed = true
107+
sourceElements.canBeResolved = false
108+
sourceElements.extendsFrom(sources)
109+
sourceElements.attributes {
110+
// Changing USAGE is required when working with Scala projects, otherwise the source dirs get pulled
111+
// into incremental compilation analysis.
112+
attribute(Usage.USAGE_ATTRIBUTE, project.objects.named(Usage, 'java-source'))
113+
attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, project.objects.named(LibraryElements, 'sources'))
114+
}
115+
}
116+
87117
if (project.path.startsWith(":qa")) {
88118
return
89119
}
@@ -186,6 +216,15 @@ class BuildPlugin implements Plugin<Project> {
186216
project.sourceCompatibility = '1.8'
187217
project.targetCompatibility = '1.8'
188218

219+
// TODO: Remove all root project distribution logic. It should exist in a separate dist project.
220+
if (project != project.rootProject) {
221+
SourceSet mainSourceSet = project.sourceSets.main
222+
FileCollection javaSourceDirs = mainSourceSet.java.sourceDirectories
223+
javaSourceDirs.each { File srcDir ->
224+
project.getArtifacts().add('sourceElements', srcDir)
225+
}
226+
}
227+
189228
JavaCompile compileJava = project.tasks.getByName('compileJava') as JavaCompile
190229
compileJava.getOptions().setCompilerArgs(['-Xlint:unchecked', '-Xlint:options'])
191230

@@ -221,6 +260,10 @@ class BuildPlugin implements Plugin<Project> {
221260
sourcesJar.dependsOn(project.tasks.classes)
222261
sourcesJar.classifier = 'sources'
223262
sourcesJar.from(project.sourceSets.main.allSource)
263+
// TODO: Remove when root project does not handle distribution
264+
if (project != project.rootProject) {
265+
sourcesJar.from(project.configurations.additionalSources)
266+
}
224267

225268
// Configure javadoc
226269
Javadoc javadoc = project.tasks.getByName('javadoc') as Javadoc
@@ -232,6 +275,10 @@ class BuildPlugin implements Plugin<Project> {
232275
"org/elasticsearch/hadoop/util/**",
233276
"org/apache/hadoop/hive/**"
234277
]
278+
// TODO: Remove when root project does not handle distribution
279+
if (project != project.rootProject) {
280+
javadoc.source = project.files(project.configurations.additionalSources)
281+
}
235282
// Set javadoc executable to runtime Java (1.8)
236283
javadoc.executable = new File(project.ext.runtimeJavaHome, 'bin/javadoc')
237284

hive/build.gradle

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ dependencies {
3333
itestImplementation("org.apache.hive:hive-jdbc:$hiveVersion") {
3434
exclude module: "log4j-slf4j-impl"
3535
}
36+
37+
additionalSources(project(":elasticsearch-hadoop-mr"))
3638
}
3739

3840
jar {
@@ -42,12 +44,3 @@ jar {
4244
include "META-INF/services/*"
4345
}
4446
}
45-
46-
javadoc {
47-
source += project(":elasticsearch-hadoop-mr").sourceSets.main.allJava
48-
classpath += files(project(":elasticsearch-hadoop-mr").sourceSets.main.compileClasspath)
49-
}
50-
51-
sourcesJar {
52-
from project(":elasticsearch-hadoop-mr").sourceSets.main.allJava.srcDirs
53-
}

pig/build.gradle

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ dependencies {
3131

3232
itestImplementation(project(":test:shared"))
3333
itestImplementation("dk.brics.automaton:automaton:1.11-8")
34+
35+
additionalSources(project(":elasticsearch-hadoop-mr"))
3436
}
3537

3638
jar {
@@ -40,12 +42,3 @@ jar {
4042
include "META-INF/services/*"
4143
}
4244
}
43-
44-
javadoc {
45-
source += project(":elasticsearch-hadoop-mr").sourceSets.main.allJava
46-
classpath += files(project(":elasticsearch-hadoop-mr").sourceSets.main.compileClasspath)
47-
}
48-
49-
sourcesJar {
50-
from project(":elasticsearch-hadoop-mr").sourceSets.main.allJava.srcDirs
51-
}

spark/sql-13/build.gradle

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,15 @@ dependencies {
163163
testImplementation("org.apache.spark:spark-sql_${project.ext.scalaMajorVersion}:$sparkVersion") {
164164
exclude group: 'org.apache.hadoop'
165165
}
166+
167+
additionalSources(project(":elasticsearch-hadoop-mr"))
168+
}
169+
170+
// Export generated Java code from the genjavadoc compiler plugin
171+
artifacts {
172+
sourceElements(project.file("$buildDir/generated/java")) {
173+
builtBy compileScala
174+
}
166175
}
167176

168177
jar {
@@ -178,12 +187,6 @@ javadoc {
178187
dependsOn compileScala
179188
source += "$buildDir/generated/java"
180189
}
181-
source += project(":elasticsearch-hadoop-mr").sourceSets.main.allJava
182-
classpath += files(project(":elasticsearch-hadoop-mr").sourceSets.main.compileClasspath)
183-
}
184-
185-
sourcesJar {
186-
from project(":elasticsearch-hadoop-mr").sourceSets.main.allJava.srcDirs
187190
}
188191

189192
scaladoc {
@@ -199,4 +202,4 @@ tasks.withType(ScalaCompile) {
199202
]
200203
}
201204
}
202-
}
205+
}

spark/sql-20/build.gradle

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,15 @@ dependencies {
158158
itestImplementation("org.apache.spark:spark-streaming_${project.ext.scalaMajorVersion}:$sparkVersion") {
159159
exclude group: 'org.apache.hadoop'
160160
}
161+
162+
additionalSources(project(":elasticsearch-hadoop-mr"))
163+
}
164+
165+
// Export generated Java code from the genjavadoc compiler plugin
166+
artifacts {
167+
sourceElements(project.file("$buildDir/generated/java")) {
168+
builtBy compileScala
169+
}
161170
}
162171

163172
jar {
@@ -173,12 +182,6 @@ javadoc {
173182
dependsOn compileScala
174183
source += "$buildDir/generated/java"
175184
}
176-
source += project(":elasticsearch-hadoop-mr").sourceSets.main.allJava
177-
classpath += files(project(":elasticsearch-hadoop-mr").sourceSets.main.compileClasspath)
178-
}
179-
180-
sourcesJar {
181-
from project(":elasticsearch-hadoop-mr").sourceSets.main.allJava.srcDirs
182185
}
183186

184187
scaladoc {
@@ -194,4 +197,4 @@ tasks.withType(ScalaCompile) {
194197
]
195198
}
196199
}
197-
}
200+
}

storm/build.gradle

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ dependencies {
2727
itestImplementation(project(":test:shared"))
2828
itestImplementation("com.google.guava:guava:16.0.1")
2929
itestImplementation("com.twitter:carbonite:1.4.0")
30+
31+
additionalSources(project(":elasticsearch-hadoop-mr"))
3032
}
3133

3234
jar {
@@ -37,13 +39,4 @@ jar {
3739
}
3840
}
3941

40-
javadoc {
41-
source += project(":elasticsearch-hadoop-mr").sourceSets.main.allJava
42-
classpath += files(project(":elasticsearch-hadoop-mr").sourceSets.main.compileClasspath)
43-
}
44-
45-
sourcesJar {
46-
from project(":elasticsearch-hadoop-mr").sourceSets.main.allJava.srcDirs
47-
}
48-
4942
tasks.getByName('integrationTest').enabled = false

0 commit comments

Comments
 (0)