Skip to content

Commit

Permalink
Merge branch 'swimmesberger-osgi_metadata' into master
Browse files Browse the repository at this point in the history
* swimmesberger-osgi_metadata:
  Publish OSGi metadata for OkHttp
  • Loading branch information
squarejesse committed Oct 7, 2020
2 parents f692f07 + b4d66af commit 74f9781
Show file tree
Hide file tree
Showing 10 changed files with 274 additions and 26 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,4 @@ Committer's Guides
[releasing]: http://square.github.io/okhttp/releasing/
[security]: http://square.github.io/okhttp/security/
[works_with_okhttp]: http://square.github.io/okhttp/works_with_okhttp/
[okhttp_build]: https://github.com/square/okhttp/blob/master/okhttp/build.gradle
32 changes: 28 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import net.ltgt.gradle.errorprone.CheckSeverity

buildscript {
ext.versions = [
'animalSniffer': '1.19',
Expand All @@ -20,7 +18,9 @@ buildscript {
'okio': '2.9.0',
'ktlint': '0.38.0',
'picocli': '4.5.1',
'openjsse': '1.1.0'
'openjsse': '1.1.0',
'bnd': '5.1.2',
'equinox': '3.16.0'
]

ext.deps = [
Expand All @@ -43,13 +43,18 @@ buildscript {
'moshi': "com.squareup.moshi:moshi:${versions.moshi}",
'moshiKotlin': "com.squareup.moshi:moshi-kotlin-codegen:${versions.moshi}",
'okio': "com.squareup.okio:okio:${versions.okio}",
'openjsse': "org.openjsse:openjsse:${versions.openjsse}"
'openjsse': "org.openjsse:openjsse:${versions.openjsse}",
'bnd': "biz.aQute.bnd:biz.aQute.bnd.gradle:${versions.bnd}",
'bndResolve': "biz.aQute.bnd:biz.aQute.resolve:${versions.bnd}",
'equinox': "org.eclipse.platform:org.eclipse.osgi:${versions.equinox}",
'kotlinStdlibOsgi': "org.jetbrains.kotlin:kotlin-osgi-bundle:${versions.kotlin}"
]

dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.10"
classpath "org.jetbrains.dokka:dokka-gradle-plugin:0.10.1"
classpath "com.android.tools.build:gradle:4.0.1"
classpath deps.bnd
}

repositories {
Expand Down Expand Up @@ -107,6 +112,23 @@ allprojects {
}
}

ext.applyOsgi = { project ->
project.apply plugin: 'biz.aQute.bnd.builder'

project.sourceSets {
osgi
}

project.jar { t ->
t.setClasspath(project.sourceSets.osgi['compileClasspath'] + project.sourceSets.main['compileClasspath'])
}

project.dependencies {
// The OSGi kotlin-stdlib lets bnd infer bundle versions.
osgiApi deps.kotlinStdlibOsgi
}
}

/** Configure building for Java+Kotlin projects. */
subprojects { project ->
if (project.name == 'android-test') return
Expand All @@ -118,6 +140,8 @@ subprojects { project ->
apply plugin: 'checkstyle'
apply plugin: 'ru.vyarus.animalsniffer'
apply plugin: 'org.jetbrains.dokka'
apply plugin: 'biz.aQute.bnd.builder'

sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8

Expand Down
11 changes: 8 additions & 3 deletions okhttp-brotli/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
applyOsgi(this)

jar {
manifest {
attributes('Automatic-Module-Name': 'okhttp3.brotli')
}
// MANIFEST.MF, including OSGi bnd instructions.
bnd '''
Export-Package: okhttp3.brotli
Automatic-Module-Name: okhttp3.brotli
Bundle-SymbolicName: com.squareup.okhttp3.brotli
'''
}

dependencies {
Expand Down
11 changes: 8 additions & 3 deletions okhttp-dnsoverhttps/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
applyOsgi(this)

jar {
manifest {
attributes('Automatic-Module-Name': 'okhttp3.dnsoverhttps')
}
// MANIFEST.MF, including OSGi bnd instructions.
bnd '''
Export-Package: okhttp3.dnsoverhttps
Automatic-Module-Name: okhttp3.dnsoverhttps
Bundle-SymbolicName: com.squareup.okhttp3.dnsoverhttps
'''
}

dependencies {
Expand Down
10 changes: 7 additions & 3 deletions okhttp-logging-interceptor/build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
apply plugin: 'me.champeau.gradle.japicmp'
applyOsgi(this)

jar {
manifest {
attributes('Automatic-Module-Name': 'okhttp3.logging')
}
// MANIFEST.MF, including OSGi bnd instructions.
bnd '''
Export-Package: okhttp3.logging
Automatic-Module-Name: okhttp3.logging
Bundle-SymbolicName: com.squareup.okhttp3.logging
'''
}

dependencies {
Expand Down
10 changes: 7 additions & 3 deletions okhttp-sse/build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
apply plugin: 'me.champeau.gradle.japicmp'
applyOsgi(this)

jar {
manifest {
attributes('Automatic-Module-Name': 'okhttp3.sse')
}
// MANIFEST.MF, including OSGi bnd instructions.
bnd '''
Export-Package: okhttp3.sse
Automatic-Module-Name: okhttp3.sse
Bundle-SymbolicName: com.squareup.okhttp3.sse
'''
}

dependencies {
Expand Down
10 changes: 7 additions & 3 deletions okhttp-tls/build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
apply plugin: 'me.champeau.gradle.japicmp'
applyOsgi(this)

jar {
manifest {
attributes('Automatic-Module-Name': 'okhttp3.tls')
}
// MANIFEST.MF, including OSGi bnd instructions.
bnd '''
Export-Package: okhttp3.tls
Automatic-Module-Name: okhttp3.tls
Bundle-SymbolicName: com.squareup.okhttp3.tls
'''
}

dependencies {
Expand Down
15 changes: 11 additions & 4 deletions okhttp-urlconnection/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
apply plugin: 'me.champeau.gradle.japicmp'
applyOsgi(this)

def mainProj = project(':okhttp')
jar {
manifest {
attributes('Automatic-Module-Name': 'okhttp3.urlconnection')
}
// MANIFEST.MF, including OSGi bnd instructions.
// urlconnection needs to be an OSGi fragment because its package name is the same as okhttp3's.
bnd """
Fragment-Host: com.squareup.okhttp3; bundle-version="\${range;[==,+);\${version_cleanup;${mainProj.version}}}"
Automatic-Module-Name: okhttp3.urlconnection
Bundle-SymbolicName: com.squareup.okhttp3.urlconnection
-removeheaders: Private-Package
"""
}

dependencies {
api project(':okhttp')
api mainProj
compileOnly deps.jsr305
compileOnly deps.animalSniffer

Expand Down
41 changes: 38 additions & 3 deletions okhttp/build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
apply plugin: 'me.champeau.gradle.japicmp'
applyOsgi(this)

jar {
manifest {
attributes('Automatic-Module-Name': 'okhttp3')
}
// MANIFEST.MF, including OSGi bnd instructions.
// We export okhttp3.internal for our own modules use.
// The packages of all optional dependencies must be explicitly specified.
bnd '''
Export-Package: \
okhttp3,\
okhttp3.internal.*;okhttpinternal=true;mandatory:=okhttpinternal
Import-Package: \
android.*;resolution:=optional,\
com.oracle.svm.core.annotate;resolution:=optional,\
dalvik.system;resolution:=optional,\
org.conscrypt;resolution:=optional,\
org.bouncycastle.*;resolution:=optional,\
org.openjsse.*;resolution:=optional,\
sun.security.ssl;resolution:=optional,\
*
Automatic-Module-Name: okhttp3
Bundle-SymbolicName: com.squareup.okhttp3
'''
}

sourceSets {
Expand All @@ -21,9 +38,21 @@ task copyJavaTemplates(type: Copy) {
filteringCharset = 'UTF-8'
}

// Expose OSGi jars to the test environment.
configurations {
osgiTestDeploy
}
task copyOsgiTestDeployment(type: Copy) {
from configurations.osgiTestDeploy
into "${buildDir}/resources/test/okhttp3/osgi/deployments"
}
tasks.test.dependsOn(copyOsgiTestDeployment)

dependencies {
api deps.okio
api deps.kotlinStdlib

// These compileOnly dependencies must also be listed in the OSGi configuration above.
compileOnly deps.android
compileOnly deps.bouncycastle
compileOnly deps.bouncycastletls
Expand All @@ -47,10 +76,16 @@ dependencies {
testImplementation project(':okhttp-urlconnection')
testImplementation project(':mockwebserver')
testImplementation project(':okhttp-logging-interceptor')
testImplementation project(':okhttp-brotli')
testImplementation project(':okhttp-dnsoverhttps')
testImplementation project(':okhttp-sse')
testImplementation deps.conscrypt
testImplementation deps.junit
testImplementation deps.assertj
testImplementation deps.openjsse
testImplementation deps.bndResolve
osgiTestDeploy deps.equinox
osgiTestDeploy deps.kotlinStdlibOsgi
testCompileOnly deps.jsr305
}

Expand Down
Loading

0 comments on commit 74f9781

Please sign in to comment.