diff --git a/build.gradle b/build.gradle index 5a8256a78..e0945db82 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,7 @@ /* * Nextcloud Android Common Library * + * SPDX-FileCopyrightText: 2026 Alper Ozturk * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2023 Unpublished * SPDX-FileCopyrightText: 2022 Tobias Kaminsky @@ -28,17 +29,11 @@ subprojects { repositories { google() mavenCentral() - maven { - url = "https://jitpack.io" - content { - includeGroup "com.github.bitfireAT" - } - } } } tasks.register('clean', Delete) { - delete rootProject.buildDir + delete rootProject.layout.buildDirectory } tasks.register('installGitHooks', Copy) { diff --git a/gradle.properties b/gradle.properties index 38ac26b7a..c553afc57 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,7 @@ # SPDX-FileCopyrightText: 2018-2024 Nextcloud GmbH and Nextcloud contributors # SPDX-FileCopyrightText: 2018-2023 Tobias Kaminsky # SPDX-FileCopyrightText: 2023 Andy Scherzinger -# SPDX-FileCopyrightText: 2023 Alper Ozturk +# SPDX-FileCopyrightText: 2023-2026 Alper Ozturk # SPDX-License-Identifier: MIT # can be overriden by ~/.gradle/gradle.properties @@ -10,22 +10,12 @@ NC_TEST_SERVER_USERNAME=test NC_TEST_SERVER_PASSWORD=test NC_TEST_SERVER_USERNAME2=admin NC_TEST_SERVER_PASSWORD2=admin -android.useAndroidX=true -# android.defaults.buildfeatures.buildconfig=true -android.nonTransitiveRClass=false -android.nonFinalResIds=false -# JVM arguments to optimize heap usage, enable heap dump on out-of-memory errors, and set the file encoding -org.gradle.jvmargs=-Xmx3g -XX:MaxMetaspaceSize=1g -Dfile.encoding=UTF-8 +android.useAndroidX=true +org.gradle.jvmargs=-Xmx3g -XX:MaxMetaspaceSize=1g -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 org.gradle.dependency.verification.console=verbose kotlin.daemon.jvmargs=-Xmx3072m org.gradle.caching=true org.gradle.parallel=true -org.gradle.configureondemand=true -android.defaults.buildfeatures.resvalues=true -android.usesSdkInManifest.disallowed=false -android.uniquePackageNames=false -android.dependency.useConstraints=true - -# Enabled parallel sync for Gradle 9.4+ +org.gradle.configuration-cache=true org.gradle.tooling.parallel=true diff --git a/jacoco.gradle b/jacoco.gradle index 32cf00719..73f3159ff 100644 --- a/jacoco.gradle +++ b/jacoco.gradle @@ -1,6 +1,7 @@ /* * Nextcloud Android Common Library * + * SPDX-FileCopyrightText: 2026 Alper Ozturk * SPDX-FileCopyrightText: 2023-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2023 Andy Scherzinger * SPDX-License-Identifier: MIT @@ -9,34 +10,19 @@ apply plugin: 'jacoco' jacoco { - toolVersion = "$jacoco_version" -} - -// Force Jacoco Version - -subprojects { - configurations.all { - resolutionStrategy { - eachDependency { details -> - if ('org.jacoco' == details.requested.group) { - details.useVersion "$jacocoVersion" - } - } - } - } + toolVersion = "${rootProject.ext.jacoco_version}" } project.afterEvaluate { project -> - tasks.withType(Test) { + tasks.withType(Test).configureEach { jacoco.includeNoLocationClasses = true jacoco.excludes = ['jdk.internal.*'] } - final flavor = "Gplay" final buildType = "Debug" - final variant = "$flavor${buildType.capitalize()}" - final taskName = "jacocoTest${variant.capitalize()}UnitTestReport" + final variant = buildType.toLowerCase() + final taskName = "jacocoTest${buildType}UnitTestReport" task "$taskName"(type: JacocoReport, dependsOn: "test${buildType.capitalize()}UnitTest") { @@ -99,19 +85,16 @@ project.afterEvaluate { project -> /* INSERT ANY OTHER JUNK YOU WANT FILTERED OUT HERE */ ] - final androidKotlinTree = fileTree(dir: "${project.buildDir}/tmp/kotlin-classes/${variant}", excludes: fileFilter) - final kotlinTree = fileTree(dir: "${project.buildDir}/classes/kotlin/main", excludes: fileFilter) - final javacTree = fileTree(dir: "${project.buildDir}/intermediates/javac/${variant}/classes", excludes: fileFilter) + final kotlinTree = fileTree(dir: project.layout.buildDirectory.dir("intermediates/built_in_kotlinc/${variant}/compile${buildType}Kotlin/classes"), excludes: fileFilter) + final javacTree = fileTree(dir: project.layout.buildDirectory.dir("intermediates/javac/${variant}/compile${buildType}JavaWithJavac/classes"), excludes: fileFilter) final mainSrc = "${project.projectDir}/src/main/java" - final productFlavorSrc = "${project.projectDir}/src/${flavor}/java" - final buildTypeSrc = "${project.projectDir}/src/${buildType}/java" + final buildTypeSrc = "${project.projectDir}/src/${variant}/java" - sourceDirectories.setFrom files([mainSrc, productFlavorSrc, buildTypeSrc]) - classDirectories.setFrom files([androidKotlinTree, kotlinTree, javacTree]) - executionData.setFrom fileTree(dir: project.buildDir, includes: [ - "jacoco/test${variant.capitalize()}UnitTest.exec", - "outputs/unit_test_code_coverage/${variant}UnitTest/test${variant.capitalize()}UnitTest.exec", + sourceDirectories.setFrom files([mainSrc, buildTypeSrc]) + classDirectories.setFrom files([kotlinTree, javacTree]) + executionData.setFrom fileTree(dir: project.layout.buildDirectory, includes: [ + "outputs/unit_test_code_coverage/${variant}UnitTest/test${buildType}UnitTest.exec" ]) } } diff --git a/library/build.gradle b/library/build.gradle index 66be9ee39..5736669e8 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -4,7 +4,7 @@ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2023 Andy Scherzinger * SPDX-FileCopyrightText: 2023 Tobias Kaminsky - * SPDX-FileCopyrightText: 2023 Alper Ozturk + * SPDX-FileCopyrightText: 2023-2026 Alper Ozturk * SPDX-FileCopyrightText: 2022 Álvaro Brey Vilas * SPDX-License-Identifier: MIT */ @@ -12,6 +12,7 @@ import com.github.spotbugs.snom.Confidence import com.github.spotbugs.snom.Effort import com.github.spotbugs.snom.SpotBugsTask +import io.gitlab.arturbosch.detekt.Detekt buildscript { ext { @@ -20,12 +21,12 @@ buildscript { dependencies { classpath 'com.android.tools.build:gradle:9.4.1' classpath 'com.github.spotbugs.snom:spotbugs-gradle-plugin:6.5.13' - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version" + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${rootProject.ext.kotlin_version}" + classpath "org.jetbrains.kotlin:kotlin-serialization:${rootProject.ext.kotlin_version}" classpath "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.23.8" - classpath "org.jacoco:org.jacoco.core:$jacoco_version" - classpath "org.jacoco:org.jacoco.report:$jacoco_version" - classpath "org.jacoco:org.jacoco.agent:$jacoco_version" + classpath "org.jacoco:org.jacoco.core:${rootProject.ext.jacoco_version}" + classpath "org.jacoco:org.jacoco.report:${rootProject.ext.jacoco_version}" + classpath "org.jacoco:org.jacoco.agent:${rootProject.ext.jacoco_version}" } } @@ -42,7 +43,7 @@ apply plugin: 'io.gitlab.arturbosch.detekt' apply plugin: 'maven-publish' // needed for JitPack.io configurations { - all { + configureEach { exclude group: 'com.google.firebase', module: 'firebase-core' exclude group: 'org.ogce', module: 'xpp3' // xpp3 is for plain java, Android uses kxml2 @@ -51,7 +52,7 @@ configurations { cacheChangingModulesFor 0, 'seconds' eachDependency { details -> if ('org.jacoco' == details.requested.group) { - details.useVersion "$jacoco_version" + details.useVersion "${rootProject.ext.jacoco_version}" } } @@ -64,15 +65,12 @@ dependencies { implementation 'org.apache.jackrabbit:jackrabbit-webdav:2.13.5' api 'com.squareup.okhttp3:okhttp:5.5.1' - implementation 'com.github.bitfireAT:dav4jvm:3.0.2' // in transition phase, we use old and new libs - implementation group: 'com.google.code.gson', name: 'gson', version: '2.15.0' + implementation 'com.google.code.gson:gson:2.15.0' implementation 'androidx.annotation:annotation:1.11.0' compileOnly 'com.google.code.findbugs:annotations:3.0.1' implementation "androidx.core:core-ktx:1.19.1" - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" - implementation 'com.google.guava:guava:33.7.2-jre' implementation 'org.bouncycastle:bcpkix-jdk18on:1.86' @@ -88,13 +86,9 @@ dependencies { // JUnit4 Rules androidTestImplementation "junit:junit:$junit_version" androidTestImplementation 'androidx.test.ext:junit:1.3.0' - androidTestImplementation 'androidx.test:rules:1.7.0' // Android JUnit Runner androidTestImplementation 'androidx.test:runner:1.7.0' - - androidTestImplementation 'androidx.test.espresso:espresso-core:3.7.0' - androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.7.0' androidTestImplementation 'commons-io:commons-io:2.22.0' } @@ -104,12 +98,12 @@ spotbugs { reportLevel = Confidence.valueOf('MEDIUM') } -tasks.withType(SpotBugsTask){task -> +tasks.withType(SpotBugsTask).configureEach { task -> String variantNameCap = task.name.replace("spotbugs", "") String variantName = variantNameCap.substring(0, 1).toLowerCase() + variantNameCap.substring(1) dependsOn "compile${variantNameCap}Sources" - classes = files("$project.buildDir/intermediates/javac/${variantName}") + classes = files(layout.buildDirectory.dir("intermediates/javac/${variantName}")) excludeFilter = file("${project.rootDir}/scripts/analysis/spotbugs-filter.xml") reports { xml { @@ -117,7 +111,7 @@ tasks.withType(SpotBugsTask){task -> } html { required = true - outputLocation = file("$project.buildDir/reports/spotbugs/spotbugs.html") + outputLocation = layout.buildDirectory.file("reports/spotbugs/spotbugs.html") stylesheet = 'fancy.xsl' } } @@ -128,8 +122,8 @@ android { buildTypes { debug { - enableUnitTestCoverage true - enableAndroidTestCoverage true + enableUnitTestCoverage = true + enableAndroidTestCoverage = true } } @@ -137,7 +131,7 @@ android { lint { abortOnError = true disable 'MissingTranslation', 'GradleDependency', 'VectorPath', 'IconMissingDensityFolder', 'IconDensities', 'GoogleAppIndexingWarning', 'MissingDefaultResource', 'StringFormatInvalid', 'MissingQuantity', 'InvalidPackage' - htmlOutput = file("$project.buildDir/reports/lint/lint.html") + htmlOutput = layout.buildDirectory.file("reports/lint/lint.html").get().asFile htmlReport = true warningsAsErrors = true targetSdk 36 @@ -201,22 +195,28 @@ tasks.register("combinedTestReport", JacocoReport) { html.required = Boolean.TRUE } - additionalSourceDirs.setFrom files(subprojects.sourceSets.main.allSource.srcDirs) - sourceDirectories.setFrom files(subprojects.sourceSets.main.allSource.srcDirs) - classDirectories.setFrom files(subprojects.sourceSets.main.output) - executionData.setFrom project.fileTree(dir: project.buildDir, includes: [ - 'jacoco/testDebugUnitTest.exec', 'outputs/code-coverage/debugAndroidTest/connected/*coverage.ec' + final classExcludes = ['**/R.class', '**/R$*.class', '**/BuildConfig.*', '**/Manifest*.*'] + + sourceDirectories.setFrom files("$projectDir/src/main/java") + classDirectories.setFrom files( + fileTree(dir: layout.buildDirectory.dir("intermediates/built_in_kotlinc/debug/compileDebugKotlin/classes"), excludes: classExcludes), + fileTree(dir: layout.buildDirectory.dir("intermediates/javac/debug/compileDebugJavaWithJavac/classes"), excludes: classExcludes) + ) + executionData.setFrom project.fileTree(dir: project.layout.buildDirectory, includes: [ + 'outputs/unit_test_code_coverage/debugUnitTest/testDebugUnitTest.exec', + 'outputs/code_coverage/debugAndroidTest/connected/**/*.ec' ]) } detekt { + config.setFrom(files("detekt.yml")) + source.setFrom(files("$projectDir/src/")) +} + +tasks.withType(Detekt).configureEach { reports { - xml { - enabled = false - } + xml.required = false } - config = files("detekt.yml") - input = files("$projectDir/src/") } afterEvaluate { @@ -233,7 +233,7 @@ afterEvaluate { } jacoco { - toolVersion = "$jacoco_version" + toolVersion = "${rootProject.ext.jacoco_version}" } spotless { diff --git a/library/detekt.yml b/library/detekt.yml index 8a72eb844..c2d899836 100644 --- a/library/detekt.yml +++ b/library/detekt.yml @@ -1,4 +1,5 @@ # Nextcloud Android Library +# SPDX-FileCopyrightText: 2026 Alper Ozturk # SPDX-FileCopyrightText: 2022-2024 Nextcloud GmbH and Nextcloud contributors # SPDX-FileCopyrightText: 2023 Tobias Kaminsky # SPDX-FileCopyrightText: 2022 Álvaro Brey @@ -56,14 +57,14 @@ complexity: active: false threshold: 10 includeStaticDeclarations: false - ComplexMethod: + CyclomaticComplexMethod: active: true - threshold: 10 + threshold: 15 ignoreSingleWhenExpression: false ignoreSimpleWhenEntries: false LabeledExpression: active: false - ignoredLabels: "" + ignoredLabels: [] LargeClass: active: true threshold: 600 @@ -135,7 +136,11 @@ exceptions: active: true ExceptionRaisedInUnexpectedLocation: active: false - methodNames: 'toString,hashCode,equals,finalize' + methodNames: + - 'toString' + - 'hashCode' + - 'equals' + - 'finalize' InstanceOfCheckForException: active: false NotImplementedDeclaration: @@ -148,14 +153,21 @@ exceptions: active: false SwallowedException: active: false - ignoredExceptionTypes: 'InterruptedException,NumberFormatException,ParseException,MalformedURLException' + ignoredExceptionTypes: + - 'InterruptedException' + - 'NumberFormatException' + - 'ParseException' + - 'MalformedURLException' ThrowingExceptionFromFinally: active: false ThrowingExceptionInMain: active: false ThrowingExceptionsWithoutMessageOrCause: active: false - exceptions: 'IllegalArgumentException,IllegalStateException,IOException' + exceptions: + - 'IllegalArgumentException' + - 'IllegalStateException' + - 'IOException' ThrowingNewInstanceOfSameException: active: false TooGenericExceptionCaught: @@ -193,7 +205,7 @@ naming: enumEntryPattern: '^[A-Z][_a-zA-Z0-9]*' ForbiddenClassName: active: false - forbiddenName: '' + forbiddenName: [] FunctionMaxLength: active: false maximumFunctionNameLength: 30 @@ -204,13 +216,11 @@ naming: active: true functionPattern: '^([a-z$][a-zA-Z$0-9]*)|(`.*`)$' excludeClassPattern: '$^' - ignoreOverridden: true excludes: "**/*Test.kt" FunctionParameterNaming: active: true parameterPattern: '[a-z][A-Za-z0-9]*' excludeClassPattern: '$^' - ignoreOverridden: true MatchingDeclarationName: active: true MemberNameEqualsClassName: @@ -240,7 +250,6 @@ naming: variablePattern: '[a-z][A-Za-z0-9]*' privateVariablePattern: '(_)?[a-z][A-Za-z0-9]*' excludeClassPattern: '$^' - ignoreOverridden: true performance: active: true @@ -255,8 +264,6 @@ performance: potential-bugs: active: true - DuplicateCaseInWhenExpression: - active: true EqualsAlwaysReturnsTrueOrFalse: active: false EqualsWithHashCodeExist: @@ -292,7 +299,8 @@ style: active: false DataClassContainsFunctions: active: false - conversionFunctionPrefix: 'to' + conversionFunctionPrefix: + - 'to' EqualsNullCall: active: false EqualsOnSignatureLine: @@ -304,22 +312,30 @@ style: includeLineWrapping: false ForbiddenComment: active: true - values: 'TODO:,FIXME:,STOPSHIP:' + comments: + - 'TODO:' + - 'FIXME:' + - 'STOPSHIP:' ForbiddenImport: active: false - imports: '' + imports: [] ForbiddenVoid: active: false FunctionOnlyReturningConstant: active: false ignoreOverridableFunction: true - excludedFunctions: 'describeContents' + excludedFunctions: + - 'describeContents' LoopWithTooManyJumpStatements: active: false maxJumpCount: 1 MagicNumber: active: true - ignoreNumbers: '-1,0,1,2' + ignoreNumbers: + - '-1' + - '0' + - '1' + - '2' ignoreHashCodeFunction: true ignorePropertyDeclaration: false ignoreConstantDeclaration: true @@ -328,8 +344,6 @@ style: ignoreNamedArgument: true ignoreEnums: false excludes: "**/*Test.kt" - MandatoryBracesIfStatements: - active: false MaxLineLength: active: true maxLineLength: 120 @@ -350,8 +364,6 @@ style: active: true OptionalUnit: active: false - OptionalWhenBraces: - active: false PreferToOverPairSyntax: active: false ProtectedMemberInFinalClass: @@ -361,7 +373,8 @@ style: ReturnCount: active: true max: 2 - excludedFunctions: "equals" + excludedFunctions: + - 'equals' excludeLabeled: false excludeReturnFromLambda: true SafeCast: @@ -377,7 +390,7 @@ style: active: false UnderscoresInNumericLiterals: active: false - acceptableDecimalLength: 5 + acceptableLength: 4 UnnecessaryAbstractClass: active: false ignoreAnnotated: @@ -408,4 +421,6 @@ style: active: false WildcardImport: active: true - excludeImports: 'java.util.*,kotlinx.android.synthetic.*' + excludeImports: + - 'java.util.*' + - 'kotlinx.android.synthetic.*' diff --git a/sample_client/build.gradle b/sample_client/build.gradle index 72292da6c..d08991113 100644 --- a/sample_client/build.gradle +++ b/sample_client/build.gradle @@ -4,7 +4,7 @@ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2022-2023 Tobias Kaminsky * SPDX-FileCopyrightText: 2023 Andy Scherzinger - * SPDX-FileCopyrightText: 2023 Alper Ozturk + * SPDX-FileCopyrightText: 2023-2026 Alper Ozturk * SPDX-FileCopyrightText: 2014 Marcello Steiner * SPDX-License-Identifier: MIT */ @@ -12,10 +12,7 @@ buildscript { dependencies { classpath 'com.android.tools.build:gradle:9.4.1' - classpath 'com.github.spotbugs.snom:spotbugs-gradle-plugin:6.5.13' - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - classpath "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.23.8" - classpath "commons-httpclient:commons-httpclient:3.1@jar" // remove after entire switch to lib v2 + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${rootProject.ext.kotlin_version}" } } @@ -55,7 +52,7 @@ android { namespace = 'com.owncloud.android.lib.sampleclient' lint { - abortOnError false + abortOnError = false } } @@ -63,8 +60,6 @@ dependencies { implementation project(path: ':library') implementation "commons-httpclient:commons-httpclient:3.1@jar" // remove after entire switch to lib v2 - implementation "org.jacoco:org.jacoco.agent:$jacoco_version:runtime" - implementation 'androidx.test:monitor:1.8.0' androidTestImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test:monitor:1.8.0' androidTestImplementation 'androidx.test.ext:junit:1.3.0'