Skip to content
Merged
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
90 changes: 90 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: CI

on: [push, pull_request]

jobs:
build:
name: Build Java Pinning

runs-on: ubuntu-24.04
strategy:
matrix:
java:
- 17
- 21
env:
PRIMARY_JAVA_VERSION: 21

steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up JDK ${{ matrix.java }}
uses: actions/setup-java@v1
with:
java-version: ${{ matrix.java }}

# Caches
- name: Cache Maven
uses: actions/cache@v2
with:
path: ~/.m2/repository
key: maven-${{ hashFiles('**/build.gradle') }}
restore-keys: |
maven-
- name: Cache Gradle
uses: actions/cache@v2
with:
path: ~/.gradle/caches
key: gradle-caches-${{ hashFiles('**/build.gradle') }}
restore-keys:
gradle-caches
- name: Cache Android SDK
uses: actions/cache@v2
with:
path: |
~/.android/sdk
key: android-${{ hashFiles('build.gradle') }}
restore-keys: |
android-

# Pre-reqs
- name: Install Android SDK Manager
uses: android-actions/setup-android@v2
- name: Install Android SDK
run: |
sdkmanager "platforms;android-15" "platforms;android-30"

# Testing
- name: Gradle Check
run: ./gradlew check --stacktrace

# Test local publish
- name: Gradle publish
run: ./gradlew publishToMavenLocal --stacktrace

# Javadoc
- name: Javadoc
if: ${{ matrix.java == env.PRIMARY_JAVA_VERSION }}
run: ./gradlew javadocAll --stacktrace

# Test Coverage Report
- name: Jacoco Test Coverage
run: ./gradlew java-pinning-java11:testCodeCoverageReport

# Coveralls
- name: Report coverage stats to Coveralls
if: ${{ matrix.java == env.PRIMARY_JAVA_VERSION }}
uses: coverallsapp/github-action@v2
with:
format: jacoco
file: java-pinning-java11/build/reports/jacoco/testCodeCoverageReport/testCodeCoverageReport.xml

# Upload build artifacts
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: java-pinning-java-${{ matrix.java }}
path: |
java-pinning-*/build/libs/*.jar
!**/*-test-fixtures.jar
!**/*-tests.jar
26 changes: 26 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
GRADLE ?= ./gradlew

.PHONY: all
all: check codecov eclipse javadocAll show-dependency-updates

.PHONY: codecov
codecov:
$(GRADLE) java-pinning-java11:testCodeCoverageReport
echo "Code coverage report available at file://$(PWD)/java-pinnging-java11/build/reports/jacoco/testCodeCoverageReport/html/index.html"

.PHONY: check
check:
$(GRADLE) $@

.PHONY: eclipse
eclipse:
$(GRADLE) $@

.PHONY: javadocAll
javadocAll:
$(GRADLE) $@
echo "javadoc available at file://$(PWD)/build/javadoc/index.html"

.PHONY: show-dependency-updates
show-dependency-updates:
$(GRADLE) dependencyUpdates
16 changes: 16 additions & 0 deletions build-logic/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
plugins {
id 'groovy-gradle-plugin'
}

repositories {
gradlePluginPortal()
google()
}

dependencies {
implementation "biz.aQute.bnd:biz.aQute.bnd.gradle:7.0.0"
implementation "net.ltgt.gradle:gradle-errorprone-plugin:4.0.1"
implementation "ru.vyarus:gradle-animalsniffer-plugin:1.7.1"
implementation "com.github.ben-manes:gradle-versions-plugin:0.51.0"
implementation 'com.android.tools.build:gradle:8.7.0'
}
1 change: 1 addition & 0 deletions build-logic/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = 'javapinning-build-logic'
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
plugins {
id 'ru.vyarus.animalsniffer'
id 'eu.geekplace.javapinning.common-conventions'
}

dependencies {
signature "net.sf.androidscents.signature:android-api-level-${minAndroidSdk}:4.0.3_r5@signature"
}
animalsniffer {
sourceSets = [sourceSets.main]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
ext {
javaVersion = JavaVersion.VERSION_11
javaMajor = javaVersion.getMajorVersion()
minAndroidSdk = 15

isSnapshot = version.endsWith('-SNAPSHOT')

androidBootClasspath = getAndroidRuntimeJar(minAndroidSdk)

// Export the function by turning it into a closure.
// https://stackoverflow.com/a/23290820/194894
getAndroidRuntimeJar = this.&getAndroidRuntimeJar
}

repositories {
mavenCentral()
google()
mavenLocal()
}

def getAndroidRuntimeJar(androidApiLevel) {
def androidHome = getAndroidHome()
def androidJar = new File("$androidHome/platforms/android-${androidApiLevel}/android.jar")
if (androidJar.isFile()) {
return androidJar
} else {
throw new Exception("Can't find android.jar for API level ${androidApiLevel}. Please install corresponding SDK platform package")
}
}

def getAndroidHome() {
def androidHomeEnv = System.getenv("ANDROID_HOME")
if (androidHomeEnv == null) {
throw new Exception("ANDROID_HOME environment variable is not set")
}
def androidHome = new File(androidHomeEnv)
if (!androidHome.isDirectory()) throw new Exception("Environment variable ANDROID_HOME is not pointing to a directory")
return androidHome
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
plugins {
id 'biz.aQute.bnd.builder'
id 'checkstyle'
id 'eclipse'
id 'idea'
id 'jacoco'
id 'java'
id 'java-library'
id 'net.ltgt.errorprone'
id 'com.github.ben-manes.versions'

id 'jacoco-report-aggregation'
id 'test-report-aggregation'

id 'eu.geekplace.javapinning.common-conventions'
id 'eu.geekplace.javapinning.javadoc-conventions'
id 'eu.geekplace.javapinning.publish-conventions'
}

version readVersionFile()

ext {
gitCommit = getGitCommit()
documentationDir = new File(projectDir, 'documentation')
releasedocsDir = new File(buildDir, 'releasedocs')
rootConfigDir = new File(rootDir, 'config')
isReleaseVersion = !isSnapshot
junitVersion = '5.11.3'
}

group = 'eu.geekplace.javapinning'

java {
sourceCompatibility = javaVersion
targetCompatibility = sourceCompatibility
}

ext.sharedManifest = manifest {
attributes('Implementation-Version': version,
'Implementation-GitRevision': ext.gitCommit,
'Built-JDK': System.getProperty('java.version'),
'Built-Gradle': gradle.gradleVersion,
'Built-By': System.getProperty('user.name')
)
}

eclipse {
classpath {
downloadJavadoc = true
}
}

// Make all project's 'test' target depend on javadoc, so that
// javadoc is also linted.
test.dependsOn javadoc

tasks.withType(JavaCompile) {
// Some systems may not have set their platform default
// converter to 'utf8', but we use unicode in our source
// files. Therefore ensure that javac uses unicode
options.encoding = "utf8"
options.compilerArgs = [
'-Xlint:all',
// Set '-options' because a non-java7 javac will emit a
// warning if source/target is set to 1.7 and
// bootclasspath is *not* set.
'-Xlint:-options',
'-Werror',
]
options.release = Integer.valueOf(javaMajor)
}

jacoco {
toolVersion = "0.8.12"
}

jacocoTestReport {
dependsOn test
reports {
xml.required = true
}
}

dependencies {
testImplementation "org.junit.jupiter:junit-jupiter-api:$junitVersion"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junitVersion"

// https://stackoverflow.com/a/77274251/194894
testImplementation "org.junit.platform:junit-platform-launcher:1.11.3"

errorprone 'com.google.errorprone:error_prone_core:2.35.1'
}

test {
useJUnitPlatform()

maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1

// Enable full stacktraces of failed tests. Especially handy
// for environments like Travis.
testLogging {
events "failed"
exceptionFormat "full"
}
}

jar {
bundle {
bnd(
'-removeheaders': 'Tool, Bnd-*',
'-exportcontents': 'eu.geekplace.javapinning.*',
)
}
}
checkstyle {
toolVersion = '10.18.2'
}
task sourcesJar(type: Jar, dependsOn: classes) {
archiveClassifier = 'sources'
from sourceSets.main.allSource
}
task javadocJar(type: Jar, dependsOn: javadoc) {
archiveClassifier = 'javadoc'
from javadoc.destinationDir
}
task testsJar(type: Jar) {
archiveClassifier = 'tests'
from sourceSets.test.output
}
configurations {
testRuntime
}
artifacts {
// Add a 'testRuntime' configuration including the tests so that
// it can be consumed by other projects (smack-omemo-signal for
// example). See http://stackoverflow.com/a/21946676/194894
testRuntime testsJar
}

publishing {
publications {
mavenJava(MavenPublication) {
from components.java
artifact sourcesJar
artifact javadocJar
artifact testsJar
}
}
}

tasks.withType(JavaCompile) {
options.errorprone {
disableWarningsInGeneratedCode = true
excludedPaths = ".*/jmh_generated/.*"
error(
"UnusedVariable",
"UnusedMethod",
"MethodCanBeStatic",
)
errorproneArgs = [
// Disable MissingCasesInEnumSwitch error prone check
// because this check is already done by javac as incomplete-switch.
'-Xep:MissingCasesInEnumSwitch:OFF',
'-Xep:StringSplitter:OFF',
'-Xep:JavaTimeDefaultTimeZone:OFF',
'-Xep:InlineMeSuggester:OFF',
]
}
}

// TODO: Note sure what this does (did). Was there prior the build-logic conversion.
// dependencies {
// androidProjects.each { project ->
// api project
// }
// }

def getGitCommit() {
def projectDirFile = new File("$projectDir")
def dotGit = new File(projectDirFile, ".git")
if (!dotGit.isDirectory()) return 'non-git build'

def cmd = 'git describe --always --tags --dirty=+'
def proc = cmd.execute(null, projectDirFile)
def gitCommit = proc.text.trim()
assert !gitCommit.isEmpty()
gitCommit
}

def readVersionFile() {
def versionFile = new File(rootDir, 'version')
if (!versionFile.isFile()) {
throw new Exception("Could not find version file")
}
if (versionFile.text.isEmpty()) {
throw new Exception("Version file does not contain a version")
}
versionFile.text.trim()
}
Loading
Loading