/*
 * Copyright Thoughtworks, Inc.
 *
 * Licensed 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.
 */

// As of Gradle 6 we can no longer allows settings.gradle to use the `buildSrc` project
// we need to manually import the Distro class.
//
// See:
//   https://docs.gradle.org/current/userguide/upgrading_version_5.html#classes_from_buildsrc_are_no_longer_visible_to_settings_scripts
def Distro = new GroovyScriptEngine(file('buildSrc/src/main/groovy').absolutePath).with {
  loadScriptByName('com/thoughtworks/go/build/docker/Distro.groovy')
}

Distro.values().each { distro ->
  distro.supportedVersions.each { version ->
    dynamicProjectForPath(':docker:gocd-agent', distro.projectName(version) as String)
  }
}

dynamicProjectForPath(':docker:gocd-server', Distro.wolfi.projectName(Distro.wolfi.getVersion('latest')) as String)

def dynamicProjectForPath(String parentPath, String subProjectName) {
  def subProjectPath = "$parentPath:$subProjectName"
  include subProjectPath
  project(subProjectPath).projectDir = project(parentPath).projectDir
}