IncludeCheckRemotePlugin.groovy 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * Copyright 2002-2022 the original author or authors.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * https://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package io.spring.gradle.convention
  17. import io.spring.gradle.IncludeRepoTask
  18. import org.gradle.api.Plugin
  19. import org.gradle.api.Project
  20. import org.gradle.api.tasks.GradleBuild
  21. import org.gradle.api.tasks.TaskProvider
  22. /**
  23. * Adds a set of tasks that make easy to clone a remote repository and perform some task
  24. *
  25. * @author Marcus Da Coregio
  26. */
  27. class IncludeCheckRemotePlugin implements Plugin<Project> {
  28. @Override
  29. void apply(Project project) {
  30. IncludeCheckRemoteExtension extension = project.extensions.create('includeCheckRemote', IncludeCheckRemoteExtension)
  31. TaskProvider<IncludeRepoTask> includeRepoTask = project.tasks.register('includeRepo', IncludeRepoTask) { IncludeRepoTask it ->
  32. it.repository = extension.repository
  33. it.ref = extension.ref
  34. }
  35. project.tasks.register('checkRemote', GradleBuild) {
  36. it.dependsOn 'includeRepo'
  37. it.dir = includeRepoTask.get().outputDirectory
  38. it.tasks = extension.getTasks()
  39. extension.getInitScripts().forEach {script ->
  40. it.startParameter.addInitScript(new File(script))
  41. }
  42. extension.getProjectProperties().entrySet().forEach { entry ->
  43. it.startParameter.projectProperties.put(entry.getKey(), entry.getValue())
  44. }
  45. }
  46. }
  47. abstract static class IncludeCheckRemoteExtension {
  48. /**
  49. * Git repository to clone
  50. */
  51. String repository;
  52. /**
  53. * Git ref to checkout
  54. */
  55. String ref
  56. /**
  57. * Task to run in the repository
  58. */
  59. List<String> tasks = ['check']
  60. /**
  61. * Init scripts for the build
  62. */
  63. List<String> initScripts = []
  64. /**
  65. * Map of properties for the build
  66. */
  67. Map<String, String> projectProperties = [:]
  68. }
  69. }