/*
 * 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.
 */

description = 'GoCD Test Utilities'

configurations {
  copyOnly {
    transitive = false
  }
}

dependencies {
  testFixturesApi(project(':base')) { capabilities { requireFeature('logging') } }
  testFixturesApi project(':util')
  testFixturesImplementation project.deps.logback

  testFixturesApi project.deps.assertJ
  testFixturesApi enforcedPlatform(project.deps.junit5Bom)
  testFixturesApi project.deps.junit5Api
  testFixturesApi project.deps.junit5Params

  copyOnly project(path: ':agent-launcher', configuration: 'fatJarConfig')
  copyOnly(testFixtures(project(':test:test-agent')))
  copyOnly project(path: ':tfs-impl:tfs-impl-14', configuration: 'fatJarConfig')
}

def generatedResourcesOutput = file("resources-generated")

sourceSets {
  testFixtures {
    resources {
      output.dir generatedResourcesOutput, builtBy: 'generateResources'
      srcDirs += generatedResourcesOutput
    }
  }
}

clean {
  delete(generatedResourcesOutput)
}

tasks.register('generateResources', Copy) {
  dependsOn configurations.copyOnly
  outputs.dir(generatedResourcesOutput)

  into "$generatedResourcesOutput/testdata/gen"
  from({ configurations.copyOnly }) {
    rename "(.*)-${project.version}(-.*)?.(jar|zip)", '$1.$3'
  }
}

processTestFixturesResources.dependsOn generateResources

tasks.register('prepare') {
  dependsOn generateResources
}

