Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a sub-project for the common sources. #1155

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 47 additions & 28 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ buildscript {
}
}

plugins {
id 'digital.wup.android-maven-publish' version '3.6.2'
}

description = 'Conscrypt: Android'

ext {
Expand All @@ -28,10 +24,6 @@ ext {
if (androidSdkInstalled) {
apply plugin: 'com.android.library'

// Since we're not taking a direct dependency on the constants module, we need to add an
// explicit task dependency to make sure the code is generated.
evaluationDependsOn(':conscrypt-constants')

android {
namespace "org.conscrypt"

Expand Down Expand Up @@ -66,7 +58,6 @@ if (androidSdkInstalled) {
'-D_XOPEN_SOURCE=700',
'-Wno-unused-parameter'
targets 'conscrypt_jni'
version androidCmakeVersion
}
}
ndk {
Expand All @@ -81,16 +72,12 @@ if (androidSdkInstalled) {
}
sourceSets.main {
java {
srcDirs = [
"${rootDir}/common/src/main/java",
"src/main/java"
]
// Requires evaluationDependsOn(':conscrypt-constants') above.
srcDirs += project(':conscrypt-constants').sourceSets.main.java.srcDirs
srcDirs = [ "src/main/java" ]
}
resources {
srcDirs += "build/generated/resources"
}
project(':conscrypt-common').sourceSets.main
}
externalNativeBuild {
cmake {
Expand All @@ -112,7 +99,10 @@ if (androidSdkInstalled) {
}

dependencies {
compileOnly project(':conscrypt-common')

publicApiDocs project(':conscrypt-api-doclet')

androidTestImplementation('androidx.test.espresso:espresso-core:3.1.1', {
exclude module: 'support-annotations'
exclude module: 'support-v4'
Expand All @@ -121,10 +111,9 @@ if (androidSdkInstalled) {
exclude module: 'appcompat-v7'
exclude module: 'design'
})
compileOnly project(':conscrypt-android-stub')

// Adds the constants module as a dependency so that we can include its generated source
compileOnly project(':conscrypt-constants')
compileOnly project(':conscrypt-android-stub'),
project(':conscrypt-constants')
}

def configureJavaDocs = tasks.register("configureJavadocs") {
Expand All @@ -136,36 +125,66 @@ if (androidSdkInstalled) {

def javadocs = tasks.register("javadocs", Javadoc) {
dependsOn configureJavadocs
source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) + project(':conscrypt-android-stub').sourceSets.main.output
dependsOn generateProperties
source = project(':conscrypt-common').sourceSets.main.java

classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
classpath += project(':conscrypt-android-stub').sourceSets.main.output
classpath += project(':conscrypt-constants').sourceSets.main.output
classpath += project(':conscrypt-platform-stub').sourceSets.main.output

// TODO(nmittler): Fix the javadoc errors.
failOnError false
options {
encoding = 'UTF-8'
links "https://docs.oracle.com/javase/7/docs/api/"
links "https://docs.oracle.com/javase/8/docs/api/"
// TODO(prb): Update doclet to Java 11.
// doclet = "org.conscrypt.doclet.FilterDoclet"
}
}

def javadocsJar = tasks.register("javadocsJar", Jar) {
dependsOn javadocs
classifier = 'javadoc'
archiveClassifier = 'javadoc'
from {
javadocs.get().destinationDir
}
}

def sourcesJar = tasks.register("sourcesJar", Jar) {
classifier = 'sources'
archiveClassifier = 'sources'
from android.sourceSets.main.java.srcDirs
from project(":conscrypt-common").sourceSets.main.java.srcDirs
}

apply from: "$rootDir/gradle/publishing.gradle"
publishing.publications.maven {
from components.android
artifact sourcesJar.get()
artifact javadocsJar.get()
// This is ugly but works: For both release and debug builds copy the classes from the
// common compilation before the final AAR is built.
def copyDebugCommon = tasks.register('copyDebugCommon', Copy) {
from project(':conscrypt-common').sourceSets.main.output
into buildDir.absolutePath + '/intermediates/javac/debug/classes'
dependsOn ':conscrypt-common:compileJava'
}

def copyReleaseCommon = tasks.register('copyReleaseCommon', Copy) {
from project(':conscrypt-common').sourceSets.main.output
into buildDir.absolutePath + '/intermediates/javac/release/classes'
dependsOn ':conscrypt-common:compileJava'
}

afterEvaluate {
tasks.named('javaPreCompileDebug') {
dependsOn copyDebugCommon
}
tasks.named('javaPreCompileRelease') {
dependsOn copyReleaseCommon
}

apply from: "$rootDir/gradle/publishing.gradle"
publishing.publications.maven {
from components.release
artifact sourcesJar.get()
artifact javadocsJar.get()
}
}
} else {
logger.warn('Android SDK has not been detected. The Android module will not be built.')
Expand Down
7 changes: 4 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ subprojects {
}
}
}
apply plugin: "idea"
apply plugin: "jacoco"
apply plugin: "net.ltgt.errorprone"

Expand Down Expand Up @@ -201,13 +200,15 @@ subprojects {
}

tasks.register("javadocJar", Jar) {
classifier = 'javadoc'
archiveClassifier = 'javadoc'
from javadoc
}

tasks.register("sourcesJar", Jar) {
classifier = 'sources'
archiveClassifier = 'sources'
from sourceSets.main.allSource
from project(":conscrypt-common").sourceSets.main.java.srcDirs

}

// At a test failure, log the stack trace to the console so that we don't
Expand Down
46 changes: 46 additions & 0 deletions common/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
sourceSets {
main {
java {
srcDirs = [
"src/main/java",
]
}
}
test {
java {
srcDirs = [
"src/test/java",
]
}
resources {
srcDirs [
"src/test/resources",
]
}
}
}

dependencies {
compileOnly project(':conscrypt-constants'),
project(':conscrypt-platform-stub')

testImplementation project(path: ':conscrypt-testing', configuration: 'shadow'),
libraries.junit,
libraries.mockito
}

// Always tested from one of the other subprojects.
tasks.withType(Test).configureEach {
enabled = false
}

// Only export source as part of other sub-projects' source jars.
tasks.named("sourcesJar") {
enabled = false
}

// Whhyyyyyyyyyyyyyyyyyyyyyyyy!
// For some reason Gradle seems to be copying all the resources twice, so errors without this.
tasks.named("processTestResources") {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
55 changes: 25 additions & 30 deletions openjdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -129,34 +129,24 @@ ext {
}

sourceSets {

main {
java {
srcDirs += "${rootDir}/common/src/main/java"
srcDirs += project(':conscrypt-constants').sourceSets.main.java.srcDirs
srcDirs = [ "src/main/java" ]
}
resources {
srcDirs += "build/generated/resources"
}
}

platform {
java {
srcDirs = [ "src/main/java" ]
includes = [ "org/conscrypt/Platform.java" ]
}
}
project(':conscrypt-common').sourceSets.main
}

test {
java {
srcDirs += "${rootDir}/common/src/test/java"
srcDirs = [ "src/test/java" ]
}
resources {
srcDirs += "${rootDir}/common/src/test/resources"
// This shouldn't be needed but seems to help IntelliJ locate the native artifact.
// srcDirs += preferredNativeFileDir
srcDirs += buildToTest.nativeResourcesDir()
srcDirs = [ "src/test/resources" ]
}
project(':conscrypt-common').sourceSets.test
}

// Add the source sets for each of the native builds
Expand All @@ -179,16 +169,16 @@ processResources {
dependsOn generateProperties
}

tasks.register("platformJar", Jar) {
from sourceSets.platform.output
}

tasks.register("testJar", ShadowJar) {
classifier = 'tests'
archiveClassifier = 'tests'
configurations = [project.configurations.testRuntimeClasspath]
from sourceSets.test.output
}

tasks.named("sourcesJar") {
dependsOn generateProperties
}

if (isExecutableOnPath('cpplint')) {
def cpplint = tasks.register("cpplint", Exec) {
executable = 'cpplint'
Expand Down Expand Up @@ -244,11 +234,6 @@ if (isExecutableOnPath('cpplint')) {

configurations {
publicApiDocs
platform
}

artifacts {
platform platformJar
}

apply from: "$rootDir/gradle/publishing.gradle"
Expand All @@ -268,17 +253,18 @@ dependencies {
// This is used for the @Internal annotation processing in JavaDoc
publicApiDocs project(':conscrypt-api-doclet')

api project(':conscrypt-common')

// This is listed as compile-only, but we absorb its contents.
compileOnly project(':conscrypt-constants')
testCompileOnly project(':conscrypt-constants')

testImplementation project(':conscrypt-constants'),
testImplementation project(':conscrypt-common').sourceSets.test.output,
project(path: ':conscrypt-testing', configuration: 'shadow'),
libraries.junit,
libraries.mockito

testRuntimeOnly sourceSets["$preferredSourceSet"].output

platformCompileOnly sourceSets.main.output
}

nativeBuilds.each { nativeBuild ->
Expand Down Expand Up @@ -345,7 +331,16 @@ jacocoTestReport {
}

javadoc {
dependsOn(configurations.publicApiDocs)
dependsOn configurations.publicApiDocs
dependsOn generateProperties
source = project(':conscrypt-common').sourceSets.main.java

failOnError false
options {
encoding = 'UTF-8'
links "https://docs.oracle.com/javase/8/docs/api/"
}

// TODO(prb): Update doclet to Java 11.
// options.doclet = "org.conscrypt.doclet.FilterDoclet"
// options.docletpath = configurations.publicApiDocs.files as List
Expand Down
14 changes: 14 additions & 0 deletions platform-stub/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
sourceSets {
main {
java {
srcDirs = [
"src/main/java",
]
}
}
}

// Nope.
tasks.named("sourcesJar") {
enabled = false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2023 The Android Open Source Project
*
* 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.
*/

/*
* Copyright 2013 The Netty Project
*
* The Netty Project licenses this file to you 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.
*/

package org.conscrypt;

public class AbstractConscryptSocket {
}
Loading
Loading