Skip to content

Commit

Permalink
Be lazier when configuring tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
liblit committed Mar 9, 2020
1 parent 01c37b2 commit 319e919
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 18 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Expand Up @@ -96,7 +96,7 @@ subprojects { subproject ->

// Stash the original Java compiler toolchain in case needed. This is actually only used by
// :com.ibm.wala.cast:compileTestJava, which requires JNI support that ECJ does not offer.
tasks.withType(JavaCompile) {
tasks.withType(JavaCompile).configureEach {
it.ext.originalToolChain = it.toolChain
options.encoding = 'UTF-8'
}
Expand All @@ -110,7 +110,7 @@ subprojects { subproject ->
case 'eclipse':
apply plugin: 'de.set.ecj'
ext.javaCompiler = 'ecj'
tasks.withType(JavaCompile) {
tasks.withType(JavaCompile).configureEach {
options.compilerArgs << '-properties' << "$projectDir/.settings/org.eclipse.jdt.core.prefs"
}
break
Expand Down Expand Up @@ -169,7 +169,7 @@ tasks.register('aggregatedJavadocs', Javadoc) {
options.author true

subprojects.each { proj ->
proj.tasks.withType(Javadoc).each { javadocTask ->
proj.tasks.withType(Javadoc).configureEach { javadocTask ->
source += javadocTask.source
classpath += javadocTask.classpath
excludes += javadocTask.excludes
Expand Down
2 changes: 1 addition & 1 deletion com.ibm.wala.cast.java.ecj/build.gradle
Expand Up @@ -28,7 +28,7 @@ dependencies {

mainClassName = 'com.ibm.wala.cast.java.ecj.util.SourceDirCallGraph'

run {
tasks.named('run') {
// this is for testing purposes
final def javaTestData = ':com.ibm.wala.cast.java.test.data'
evaluationDependsOn javaTestData
Expand Down
21 changes: 13 additions & 8 deletions com.ibm.wala.cast/smoke_main/build.gradle
Expand Up @@ -28,22 +28,27 @@ application {
}

// xlator Java bytecode + implementation of native methods
def pathElements = ['../build/classes/java/test', libxlator_test.parent]
final pathElements = project.objects.listProperty(File)
pathElements.addAll(files('../build/classes/java/test', libxlator_test.parent))

// "primordial.txt" resource loaded during test
def coreResources = project(':com.ibm.wala.core').processResources
dependsOn coreResources
pathElements << coreResources.destinationDir
final coreResources = project(':com.ibm.wala.core').tasks.named('processResources', Copy)
pathElements.add(coreResources.map { it.destinationDir })
inputs.files coreResources

// additional supporting Java class files
['cast', 'core', 'util'].each {
def compileJava = project(":com.ibm.wala.$it").compileJava
dependsOn compileJava
pathElements << compileJava.destinationDir
final compileJava = project(":com.ibm.wala.$it").tasks.named('compileJava', AbstractCompile)
pathElements.add(compileJava.map { it.destinationDir })
inputs.files compileJava
}

// all combined as a colon-delimited path list
args pathElements.join(':')
argumentProviders.add(new CommandLineArgumentProvider() {
Iterable<String> asArguments() {
return [pathElements.get().join(':')]
}
})

// log output to file, although we don't validate it
final def outFile = file("$temporaryDir/stdout-and-stderr.log")
Expand Down
6 changes: 4 additions & 2 deletions com.ibm.wala.core/build.gradle
Expand Up @@ -17,8 +17,10 @@ sourceSets {
testSubjects
}

final Provider<JavaCompile> compileTestSubjectsJava = tasks.named('compileTestSubjectsJava', JavaCompile)

if (javaCompiler == 'ecj') {
tasks.named('compileTestSubjectsJava', JavaCompile) {
compileTestSubjectsJava.configure {
options.compilerArgs << '-err:none'
options.compilerArgs << '-warn:none'
}
Expand All @@ -40,7 +42,7 @@ dependencies {
'org.hamcrest:hamcrest-core:2.2',
)
testRuntimeOnly(
files(compileTestSubjectsJava.outputs.files.first())
files(compileTestSubjectsJava.map { it.outputs.files.first() })
)
}

Expand Down
8 changes: 4 additions & 4 deletions gradle-mvn-push.gradle
Expand Up @@ -110,7 +110,7 @@ publishing {
from sourceSets.testFixtures.allSource
}

// For eachs subproject with test fixtures, the `artifact` calls below trigger
// For each subproject with test fixtures, the `artifact` calls below trigger
// creation of three tasks during configuration: `testFixturesJar`,
// `testFixturesJavadocJar`, and `testFixturesSourcesJar`. Configuring those lazily
// instead will require a fix to <https://github.com/gradle/gradle/issues/6246>.
Expand Down Expand Up @@ -158,7 +158,7 @@ signing {
}

// Only sign releases; snapshots are unsigned.
tasks.withType(Sign) {
tasks.withType(Sign).configureEach {
onlyIf {
!isSnapshot
}
Expand All @@ -170,14 +170,14 @@ java {
}

// Remote publication set goes to remote repositories, so we don't publicly publish test fixtures.
tasks.withType(PublishToMavenRepository) {
tasks.withType(PublishToMavenRepository).configureEach {
onlyIf {
publication == publishing.publications.remote
}
}

// Local publication set goes to local installations, so we can reuse test fixtures locally.
tasks.withType(PublishToMavenLocal) {
tasks.withType(PublishToMavenLocal).configureEach {
onlyIf {
publication == publishing.publications.local
}
Expand Down

0 comments on commit 319e919

Please sign in to comment.