/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

def modules = ['gobblin-admin',
               'gobblin-all',
               'gobblin-api',
               'gobblin-compaction',
               'gobblin-completeness',
               'gobblin-config-management',
               'gobblin-core',
               'gobblin-core-base',
               'gobblin-distribution',
               'gobblin-example',
               'gobblin-hive-registration',
               'gobblin-iceberg',
               'gobblin-metrics-libs',
               'gobblin-metastore',
               'gobblin-modules',
               'gobblin-rest-service',
               'gobblin-runtime',
               'gobblin-temporal',
               'gobblin-runtime-hadoop',
               'gobblin-utility',
               'gobblin-salesforce',
               'gobblin-test-harness',
               'gobblin-tunnel',
               'gobblin-data-management',
               'gobblin-config-management',
               'gobblin-audit',
               'gobblin-yarn',
               'gobblin-cluster',
               'gobblin-aws',
               'gobblin-service',
               'gobblin-test-utils',
               'gobblin-binary-management']

// Disable jacoco for now as Kafka 0.8 is the default version and jacoco does not like the same classes
// being declared in different modules
def jacocoBlacklist =  new HashSet([
    "gobblin-modules:gobblin-kafka-09"
])

modules.each { module ->
  include "${module}"
  file(module).eachDir { submodule ->
    if (!submodule.name.startsWith('.') && !submodule.name.equals('src') && !submodule.name.equals('bin')
          && !submodule.name.equals('test-output') && !submodule.name.equals('jobconf')) {
        def submoduleId = "${module}:${submodule.name}"
        if (System.getProperty('jacocoBuild') == null || !jacocoBlacklist.contains(submoduleId.toString())) {
            include submoduleId
        }
        else {
            println "Ignoring blacklisted module ${submoduleId}"
        }
    }
  }
}

if (file('gobblin-restli').exists()) {
  def restliSubModules = ['api', 'server', 'client']
  include 'gobblin-restli:gobblin-restli-utils'
  include 'gobblin-restli'

  file('gobblin-restli').eachDir { submodule ->
    if (!submodule.name.startsWith('.') && !submodule.name.equals('src')) {
      def submoduleId = "gobblin-restli:${submodule.name}"
      include submoduleId
      restliSubModules.each { restliSubModule ->
        def subSubModuleName = submodule.name + '-' + restliSubModule
        if (new File(submodule, subSubModuleName).exists()) {
          include "gobblin-restli:${submodule.name}:${subSubModuleName}"
        }
      }
    }
  }
}
