plugins {
  id 'com.gradle.enterprise' version '3.5'
  id 'com.github.burrunan.s3-build-cache' version '1.1'
}

def isCI = System.getenv("CI") != null
def skipBuildscan = Boolean.valueOf(System.getenv("SKIP_BUILDSCAN"))
gradleEnterprise {
  buildScan {
    termsOfServiceUrl = 'https://gradle.com/terms-of-service'
    termsOfServiceAgree = 'yes'

    if (isCI && !skipBuildscan) {
      publishAlways()
      tag 'CI'
    }
  }
}

apply plugin: 'com.github.burrunan.s3-build-cache'

def awsAccessKeyId = System.getenv("S3_BUILD_CACHE_ACCESS_KEY_ID")

buildCache {
  remote(com.github.burrunan.s3cache.AwsS3BuildCache) {
    region = 'us-west-2'
    bucket = 'opentelemetry-java-instrumentation-gradle-cache'
    push = isCI && awsAccessKeyId != null && !awsAccessKeyId.isEmpty()
  }
}

rootProject.name = 'opentelemetry-java-instrumentation'

// agent projects
include ':opentelemetry-api-shaded-for-instrumenting'
include ':opentelemetry-ext-annotations-shaded-for-instrumenting'
include ':javaagent-bootstrap'
include ':javaagent-spi'
include ':javaagent-tooling'
include ':javaagent'
include ':load-generator'

include ':bom-alpha'
include ':instrumentation-api'
include ':javaagent-api'

// misc
include ':testing:agent-exporter'
include ':testing:agent-for-testing'
include ':testing-common'
include ':testing-common:integration-tests'
include ':testing-common:library-for-integration-tests'

// smoke tests
include ':smoke-tests'

include ':instrumentation:akka-actor-2.5:javaagent'
include ':instrumentation:akka-http-10.0:javaagent'
include ':instrumentation:apache-camel-2.20:javaagent'
include ':instrumentation:apache-camel-2.20:javaagent-unittests'
include ':instrumentation:apache-httpasyncclient-4.1:javaagent'
include ':instrumentation:apache-httpclient:apache-httpclient-2.0:javaagent'
include ':instrumentation:apache-httpclient:apache-httpclient-4.0:javaagent'
include ':instrumentation:apache-httpclient:apache-httpclient-5.0:javaagent'
include ':instrumentation:armeria-1.3:javaagent'
include ':instrumentation:armeria-1.3:library'
include ':instrumentation:armeria-1.3:testing'
include ':instrumentation:async-http-client-1.9:javaagent'
include ':instrumentation:async-http-client-2.0:javaagent'
include ':instrumentation:aws-lambda-1.0:javaagent'
include ':instrumentation:aws-lambda-1.0:library'
include ':instrumentation:aws-lambda-1.0:testing'
include ':instrumentation:aws-sdk:aws-sdk-1.11:javaagent'
include ':instrumentation:aws-sdk:aws-sdk-2.2:javaagent'
include ':instrumentation:aws-sdk:aws-sdk-2.2:library'
include ':instrumentation:aws-sdk:aws-sdk-2.2:testing'
include ':instrumentation:cassandra:cassandra-3.0:javaagent'
include ':instrumentation:cassandra:cassandra-4.0:javaagent'
include ':instrumentation:cdi-testing'
include ':instrumentation:classloaders:javaagent'
include ':instrumentation:classloaders:javaagent:jboss-testing'
include ':instrumentation:classloaders:javaagent:osgi-testing'
include ':instrumentation:classloaders:javaagent:tomcat-testing'
include ':instrumentation:couchbase:couchbase-2.0:javaagent'
include ':instrumentation:couchbase:couchbase-2.6:javaagent'
include ':instrumentation:couchbase:couchbase-testing'
include ':instrumentation:dropwizard-views-0.7:javaagent'
include ':instrumentation:dropwizard-testing'
include ':instrumentation:apache-dubbo:apache-dubbo-2.7:library'
include ':instrumentation:apache-dubbo:apache-dubbo-2.7:testing'
include ':instrumentation:apache-dubbo:apache-dubbo-2.7:javaagent'
include ':instrumentation:elasticsearch:elasticsearch-rest-common:javaagent'
include ':instrumentation:elasticsearch:elasticsearch-rest-5.0:javaagent'
include ':instrumentation:elasticsearch:elasticsearch-rest-6.4:javaagent'
include ':instrumentation:elasticsearch:elasticsearch-transport-common:javaagent'
include ':instrumentation:elasticsearch:elasticsearch-transport-5.0:javaagent'
include ':instrumentation:elasticsearch:elasticsearch-transport-5.3:javaagent'
include ':instrumentation:elasticsearch:elasticsearch-transport-6.0:javaagent'
include ':instrumentation:executors:javaagent'
include ':instrumentation:external-annotations:javaagent'
include ':instrumentation:external-annotations:javaagent-unittests'
include ':instrumentation:finatra-2.9:javaagent'
include ':instrumentation:geode-1.4:javaagent'
include ':instrumentation:google-http-client-1.19:javaagent'
include ':instrumentation:grizzly-2.0:javaagent'
include ':instrumentation:grpc-1.5:javaagent'
include ':instrumentation:grpc-1.5:library'
include ':instrumentation:grpc-1.5:testing'
include ':instrumentation:guava-10.0:javaagent'
include ':instrumentation:hibernate:hibernate-3.3:javaagent'
include ':instrumentation:hibernate:hibernate-4.0:javaagent'
include ':instrumentation:hibernate:hibernate-4.3:javaagent'
include ':instrumentation:hibernate:hibernate-common:javaagent'
include ':instrumentation:http-url-connection:javaagent'
include ':instrumentation:hystrix-1.4:javaagent'
include ':instrumentation:java-httpclient:javaagent'
include ':instrumentation:jaxrs:jaxrs-1.0:javaagent'
include ':instrumentation:jaxrs:jaxrs-2.0:jaxrs-2.0-common:javaagent'
include ':instrumentation:jaxrs:jaxrs-2.0:jaxrs-2.0-cxf-3.2:javaagent'
include ':instrumentation:jaxrs:jaxrs-2.0:jaxrs-2.0-jersey-2.0:javaagent'
include ':instrumentation:jaxrs:jaxrs-2.0:jaxrs-2.0-resteasy-3.0:javaagent'
include ':instrumentation:jaxrs:jaxrs-2.0:jaxrs-2.0-resteasy-3.1:javaagent'
include ':instrumentation:jaxrs:jaxrs-2.0:jaxrs-2.0-testing'
include ':instrumentation:jaxrs:jaxrs-2.0:jaxrs-2.0-wildfly-testing'
include ':instrumentation:jaxrs-client:jaxrs-client-1.1:javaagent'
include ':instrumentation:jaxrs-client:jaxrs-client-2.0:jaxrs-client-2.0-common:javaagent'
include ':instrumentation:jaxrs-client:jaxrs-client-2.0:jaxrs-client-2.0-cxf-3.0:javaagent'
include ':instrumentation:jaxrs-client:jaxrs-client-2.0:jaxrs-client-2.0-jersey-2.0:javaagent'
include ':instrumentation:jaxrs-client:jaxrs-client-2.0:jaxrs-client-2.0-resteasy-2.0:javaagent'
include ':instrumentation:jaxws:jaxws-2.0:javaagent'
include ':instrumentation:jaxws:jaxws-2.0-axis2-1.6:javaagent'
include ':instrumentation:jaxws:jaxws-2.0-axis2-1.6:library'
include ':instrumentation:jaxws:jaxws-2.0-cxf-3.0:javaagent'
include ':instrumentation:jaxws:jaxws-2.0-cxf-3.0:library'
include ':instrumentation:jaxws:jaxws-2.0-metro-2.2:javaagent'
include ':instrumentation:jaxws:jaxws-2.0-testing'
include ':instrumentation:jaxws:jaxws-common:javaagent'
include ':instrumentation:jaxws:jws-1.1:javaagent'
include ':instrumentation:jdbc:javaagent'
include ':instrumentation:jdbc:javaagent-unittests'
include ':instrumentation:jedis:jedis-1.4:javaagent'
include ':instrumentation:jedis:jedis-3.0:javaagent'
include ':instrumentation:jetty-8.0:javaagent'
include ':instrumentation:jms-1.1:javaagent'
include ':instrumentation:jsf:jsf-common:library'
include ':instrumentation:jsf:jsf-testing-common'
include ':instrumentation:jsf:mojarra-1.2:javaagent'
include ':instrumentation:jsf:myfaces-1.2:javaagent'
include ':instrumentation:jsp-2.3:javaagent'
include ':instrumentation:kafka-clients-0.11:javaagent'
include ':instrumentation:kafka-streams-0.11:javaagent'
include ':instrumentation:khttp-0.1:javaagent'
include ':instrumentation:kotlinx-coroutines:javaagent'
include ':instrumentation:kubernetes-client-7.0:javaagent'
include ':instrumentation:kubernetes-client-7.0:javaagent-unittests'
include ':instrumentation:lettuce:lettuce-common:javaagent'
include ':instrumentation:lettuce:lettuce-4.0:javaagent'
include ':instrumentation:lettuce:lettuce-5.0:javaagent'
include ':instrumentation:lettuce:lettuce-5.1:javaagent'
include ':instrumentation:liberty:compile-stub'
include ':instrumentation:liberty:liberty:javaagent'
include ':instrumentation:liberty:liberty-dispatcher:javaagent'
include ':instrumentation:log4j:log4j-1.2:javaagent'
include ':instrumentation:log4j:log4j-2.7:javaagent'
include ':instrumentation:log4j:log4j-2.13.2:javaagent'
include ':instrumentation:log4j:log4j-2.13.2:library'
include ':instrumentation:log4j:log4j-2-testing'
include ':instrumentation:logback:logback-1.0:javaagent'
include ':instrumentation:logback:logback-1.0:library'
include ':instrumentation:logback:logback-1.0:testing'
include ':instrumentation:methods:javaagent'
include ':instrumentation:mongo:mongo-3.1:javaagent'
include ':instrumentation:mongo:mongo-3.7:javaagent'
include ':instrumentation:mongo:mongo-4.0-testing'
include ':instrumentation:mongo:mongo-async-3.3:javaagent'
include ':instrumentation:mongo:mongo-common:javaagent'
include ':instrumentation:mongo:mongo-testing'
include ':instrumentation:netty:netty-3.8:javaagent'
include ':instrumentation:netty:netty-4.0:javaagent'
include ':instrumentation:netty:netty-4.1:library'
include ':instrumentation:netty:netty-4.1:javaagent'
include ':instrumentation:okhttp:okhttp-2.2:javaagent'
include ':instrumentation:okhttp:okhttp-3.0:javaagent'
include ':instrumentation:opentelemetry-annotations-1.0:javaagent'
include ':instrumentation:opentelemetry-api-1.0:javaagent'
include ':instrumentation:opentelemetry-api-metrics-1.0:javaagent'
include ':instrumentation:oshi:javaagent'
include ':instrumentation:oshi:library'
include ':instrumentation:play:play-2.3:javaagent'
include ':instrumentation:play:play-2.4:javaagent'
include ':instrumentation:play:play-2.6:javaagent'
include ':instrumentation:play-ws:play-ws-1.0:javaagent'
include ':instrumentation:play-ws:play-ws-2.0:javaagent'
include ':instrumentation:play-ws:play-ws-2.1:javaagent'
include ':instrumentation:play-ws:play-ws-common:javaagent'
include ':instrumentation:play-ws:play-ws-testing'
include ':instrumentation:rabbitmq-2.7:javaagent'
include ':instrumentation:ratpack-1.4:javaagent'
include ':instrumentation:reactor-3.1:javaagent'
include ':instrumentation:reactor-3.1:library'
include ':instrumentation:reactor-3.1:testing'
include ':instrumentation:reactor-netty-0.9:javaagent'
include ':instrumentation:reactor-netty-1.0:javaagent'
include ':instrumentation:rediscala-1.8:javaagent'
include ':instrumentation:redisson-3.0:javaagent'
include ':instrumentation:rmi:javaagent'
include ':instrumentation:runtime-metrics:javaagent'
include ':instrumentation:runtime-metrics:library'
include ':instrumentation:rxjava-1.0:library'
include ':instrumentation:rxjava-2.0:library'
include ':instrumentation:rxjava-2.0:testing'
include ':instrumentation:rxjava-2.0:javaagent'
include ':instrumentation:scala-executors:javaagent'
include ':instrumentation:servlet:glassfish-testing'
include ':instrumentation:servlet:servlet-common:javaagent'
include ':instrumentation:servlet:servlet-2.2:javaagent'
include ':instrumentation:servlet:servlet-3.0:javaagent'
include ':instrumentation:spark-2.3:javaagent'
include ':instrumentation:spring:spring-batch-3.0:javaagent'
include ':instrumentation:spring:spring-core-2.0:javaagent'
include ':instrumentation:spring:spring-data-1.8:javaagent'
include ':instrumentation:spring:spring-scheduling-3.1:javaagent'
include ':instrumentation:spring:spring-web-3.1:library'
include ':instrumentation:spring:spring-webmvc-3.1:javaagent'
include ':instrumentation:spring:spring-webmvc-3.1:library'
include ':instrumentation:spring:spring-webflux-5.0:javaagent'
include ':instrumentation:spring:spring-webflux-5.0:library'
include ':instrumentation:spring:spring-ws-2.0:javaagent'
include ':instrumentation:spring:spring-boot-autoconfigure'
include ':instrumentation:spring:starters:spring-starter'
include ':instrumentation:spring:starters:jaeger-exporter-starter'
include ':instrumentation:spring:starters:otlp-exporter-starter'
include ':instrumentation:spring:starters:zipkin-exporter-starter'
include ':instrumentation:spymemcached-2.12:javaagent'
include ':instrumentation:struts-2.3:javaagent'
include ':instrumentation:tomcat-7.0:javaagent'
include ':instrumentation:twilio-6.6:javaagent'
include ':instrumentation:undertow:javaagent'
include ':instrumentation:vertx-web-3.0'
include ':instrumentation:vertx-reactive-3.5:javaagent'
include ':instrumentation:wicket-8.0:javaagent'

include ':instrumentation-core:servlet-2.2'

// benchmark
include ':benchmark'
include ':benchmark-integration'
include ':benchmark-integration:jetty-perftest'
include ':benchmark-e2e'

def setBuildFile(project) {
  // javaagent-unittests modules are needed until those projects have library modules
  // at which time those unittests can be moved to the library modules
  if (['javaagent', 'javaagent-unittests', 'library', 'testing'].contains(project.projectDir.name) && project.path != ':javaagent') {
    project.buildFileName = "${project.projectDir.parentFile.name}-${project.projectDir.name}.gradle"
  } else {
    project.buildFileName = "${project.name}.gradle"
  }
  project.children.each {
    setBuildFile(it)
  }
}

rootProject.children.each {
  setBuildFile(it)
}
