okhttp

Форк
0
67 строк · 2.2 Кб
1
/*
2
 * Copyright (C) 2021 Square, Inc.
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of 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,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16

17
import aQute.bnd.gradle.BundleTaskExtension
18
import org.gradle.api.Project
19
import org.gradle.api.artifacts.VersionCatalogsExtension
20
import org.gradle.api.plugins.ExtensionAware
21
import org.gradle.api.tasks.SourceSetContainer
22
import org.gradle.api.tasks.bundling.Jar
23
import org.gradle.kotlin.dsl.dependencies
24
import org.gradle.kotlin.dsl.findByType
25
import org.gradle.kotlin.dsl.get
26
import org.gradle.kotlin.dsl.getByName
27

28
fun Project.applyOsgi(vararg bndProperties: String) {
29
  plugins.withId("org.jetbrains.kotlin.jvm") {
30
    applyOsgi("jar", "osgiApi", bndProperties)
31
  }
32
}
33

34
private fun Project.applyOsgi(
35
  jarTaskName: String,
36
  osgiApiConfigurationName: String,
37
  bndProperties: Array<out String>,
38
) {
39
  val osgi = project.sourceSets.create("osgi")
40
  val osgiApi = project.configurations.getByName(osgiApiConfigurationName)
41
  val kotlinOsgi =
42
    extensions.getByType(VersionCatalogsExtension::class.java).named("libs")
43
      .findLibrary("kotlin.stdlib.osgi").get().get()
44

45
  project.dependencies {
46
    osgiApi(kotlinOsgi)
47
  }
48

49
  val jarTask = tasks.getByName<Jar>(jarTaskName)
50
  val bundleExtension =
51
    jarTask.extensions.findByType() ?: jarTask.extensions.create(
52
      BundleTaskExtension.NAME,
53
      BundleTaskExtension::class.java,
54
      jarTask,
55
    )
56
  bundleExtension.run {
57
    setClasspath(osgi.compileClasspath + sourceSets["main"].compileClasspath)
58
    bnd(*bndProperties)
59
  }
60
  // Call the convention when the task has finished, to modify the jar to contain OSGi metadata.
61
  jarTask.doLast {
62
    bundleExtension.buildAction().execute(this)
63
  }
64
}
65

66
val Project.sourceSets: SourceSetContainer
67
  get() = (this as ExtensionAware).extensions["sourceSets"] as SourceSetContainer
68

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.