Skip to content

Commit

Permalink
Bump to Gradle 8.10.2, require Java 11
Browse files Browse the repository at this point in the history
Bump Gradle from 6.8.3 to 8.10.2 and increase the minimum required
Java version from 8 to 11 (SMACK-953).

The switch from Java 8 to 11 caused some Bytecode portability issues
regarding NIO Buffers. Java changed with version 9 the return type of
some subclasses of Buffer to return the specific Buffer type instead
of the Buffer superclass [JDK-4774077]. For example, ByteBuffer.filp()
previously returned Buffer, while it does return ByteBuffer now.

This sensible change was not reflected by the Android API [1], which
means that AnimalSniffer rightfully started to complain that there is
no method "ByteBuffer ByteBuffer.flip()" in Android, there is only
"Buffer ByteBuffer.flip()", and those are incompatible methods on
Java's Bytecode layer.

As workaround, this changes

    return charBuffer.flip().toString();

to

    ((java.nio.Buffer) charBuffer).flip();
    return charBuffer.toString();

to restore the Bytecode portability between Android and Java.

Errorprone also got new checks, of which JavaUtilDate and JdkObsolete
are wroth mentioning.

JavaUtilData basically strongly recommends to use Java's newer time
API over java.util.Date. But since Smack was Java 8 until now,
j.u.Date is widely used.

Similar JdkObsolete mentions obsolete JDK APIs, like data structures
like Vector and Stack. But mostly LinkedList, which should usually be
replaced by ArrayList. And this is what this commit largely does.

JDK-4774077: https://bugs.openjdk.org/browse/JDK-4774077
1: https://issuetracker.google.com/issues/369219141
  • Loading branch information
Flowdalic committed Sep 25, 2024
1 parent d8d066b commit f3256a0
Show file tree
Hide file tree
Showing 136 changed files with 1,144 additions and 1,214 deletions.
21 changes: 15 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ jobs:
build:
name: Build Smack

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

steps:
- name: Checkout
Expand Down Expand Up @@ -72,10 +72,19 @@ jobs:

# Test Coverage Report
- name: Jacoco Test Coverage
if: ${{ matrix.java == env.PRIMARY_JAVA_VERSION }}
run: ./gradlew jacocoRootReport coveralls
env:
COVERALLS_REPO_TOKEN: S2ecSJja2cKJa9yv45C8ZFPohXuRrTXKd
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
if: |
${{ matrix.java == env.PRIMARY_JAVA_VERSION }} &&
${{ env.COVERALLS_REPO_TOKEN != '' }}
run: |
if [[ -z ${COVERALLS_REPO_TOKEN} ]]; then
echo WARNING: COVERALLS_REPO_TOKEN is empty
else
echo COVERALLS_REPO_TOKEN is not empty
fi
./gradlew smack-java8-full:testCodeCoverageReport
./gradlew smack-java8-full:coveralls
# Upload build artifacts
- name: Upload build artifacts
Expand Down
30 changes: 30 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
GRADLE ?= ./gradlew

.PHONY: all
all: check jacocoRootReport javadocAll sinttest

.PHONY: codecov
codecov:
$(GRADLE) smack-java8-full:testCodeCoverageReport
echo "Report available at smack-java8-full/build/reports/jacoco/testCodeCoverageReport/html/index.html"

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

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

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

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

.PHONY: javadocAll
javadocAll:
$(GRADLE) $@
echo "Smack javadoc available at build/javadoc/index.html"
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()
}

dependencies {
implementation "biz.aQute.bnd:biz.aQute.bnd.gradle:7.0.0"
implementation "io.freefair.gradle:maven-plugin:8.10" // for io.freefair.agregate-javadoc
implementation "me.champeau.jmh:jmh-gradle-plugin:0.7.2"
implementation "net.ltgt.gradle:gradle-errorprone-plugin:4.0.1"
implementation "gradle.plugin.org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.12.2"
implementation "ru.vyarus:gradle-animalsniffer-plugin:1.7.1"
}
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 = 'smack-build-logic'
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
compileJava {
options.bootstrapClasspath = files(androidBootClasspath)
}
javadoc {
classpath += files(androidBootClasspath)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
plugins {
id 'ru.vyarus.animalsniffer'
id 'org.igniterealtime.smack.global-conventions'
}
dependencies {
signature "net.sf.androidscents.signature:android-api-level-${smackMinAndroidSdk}:5.0.1_r2@signature"
}
animalsniffer {
sourceSets = [sourceSets.main]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
plugins {
id 'application'
}

application {
applicationDefaultJvmArgs = ["-enableassertions"]
}

run {
// Pass all system properties down to the "application" run
systemProperties System.getProperties()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
ext {
javaVersion = JavaVersion.VERSION_11
javaMajor = javaVersion.getMajorVersion()
smackMinAndroidSdk = 21

androidBootClasspath = { getAndroidRuntimeJar() }
}

repositories {
mavenLocal()
mavenCentral()
}

def getAndroidRuntimeJar() {
def androidApiLevel = ext.smackMinAndroidSdk
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 getAndroidJavadocOffline() {
def androidHome = getAndroidHome()
return androidHome.toString() + "/docs/reference"
}

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
}
Loading

0 comments on commit f3256a0

Please sign in to comment.