diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index ed70656..357f787 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -20,7 +20,7 @@ jobs: java-version: 17 distribution: temurin cache: gradle - - name: Publish to Maven Central - run: ./gradlew deployNexus + - name: Publish to Central Portal + run: ./gradlew deployCentralPortal - name: Publish to GitHub Packages run: ./gradlew deployGithub \ No newline at end of file diff --git a/.gitignore b/.gitignore index cbef6a3..b965499 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ *.iml .gradle +.kotlin **/local.properties **/.idea/ .DS_Store diff --git a/README.md b/README.md index 1b29569..752c280 100644 --- a/README.md +++ b/README.md @@ -18,11 +18,11 @@ pluginManagement { // build.gradle.kts plugins { id("com.android.library") - id("io.deepmedia.tools.grease") version "0.3.1" + id("io.deepmedia.tools.grease") version "0.3.7" } ``` -Note: it is important that Grease is applied *after* the Android library plugin. +Note: The minimum required version of Gradle is 8.3 ## Usage diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index ca28f45..434e691 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,11 +1,11 @@ [versions] -agp = "8.1.4" +agp = "8.13.0" apache-ant = "1.10.14" asm-commons = "9.6" android-tools = "31.1.4" kotlin = "2.0.0" shadow = "8.3.0" -publisher = "0.14.0" +publisher = "0.18.0" kotlinx-metadata = "0.9.0" [libraries] diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 8838ba9..7705927 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-all.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/grease/build.gradle.kts b/grease/build.gradle.kts index 6192b4c..592ef30 100644 --- a/grease/build.gradle.kts +++ b/grease/build.gradle.kts @@ -1,10 +1,27 @@ +@file:Suppress("UnstableApiUsage") + plugins { + `jvm-test-suite` `kotlin-dsl` alias(libs.plugins.publisher) } group = "io.deepmedia.tools" -version = "0.3.1" +version = "0.3.7" + +testing { + suites { + register("functionalTest") { + useJUnit() + + dependencies { + implementation(gradleTestKit()) + implementation(project.dependencies.kotlin("test") as String) + implementation(project.dependencies.kotlin("test-junit") as String) + } + } + } +} gradlePlugin { plugins { @@ -13,6 +30,8 @@ gradlePlugin { implementationClass = "io.deepmedia.tools.grease.GreasePlugin" } } + + testSourceSets(sourceSets["functionalTest"]) } dependencies { @@ -53,18 +72,17 @@ deployer { } } - // use "deployNexus" to deploy to OSSRH / maven central - nexusSpec { - auth.user = secret("SONATYPE_USER") - auth.password = secret("SONATYPE_PASSWORD") - syncToMavenCentral = true + // use "deployCentralPortal" to deploy to central portal + centralPortalSpec { + auth.user.set(secret("SONATYPE_USER")) + auth.password.set(secret("SONATYPE_PASSWORD")) } // use "deployNexusSnapshot" to deploy to sonatype snapshots repo nexusSpec("snapshot") { auth.user = secret("SONATYPE_USER") auth.password = secret("SONATYPE_PASSWORD") - repositoryUrl = ossrhSnapshots1 + repositoryUrl = "https://central.sonatype.com/repository/maven-snapshots/" release.version = "latest-SNAPSHOT" } @@ -77,4 +95,4 @@ deployer { token = secret("GHUB_PERSONAL_ACCESS_TOKEN") } } -} \ No newline at end of file +} diff --git a/grease/src/functionalTest/kotlin/io/deepmedia/tools/grease/GeneratedPomFileTest.kt b/grease/src/functionalTest/kotlin/io/deepmedia/tools/grease/GeneratedPomFileTest.kt new file mode 100644 index 0000000..98a15da --- /dev/null +++ b/grease/src/functionalTest/kotlin/io/deepmedia/tools/grease/GeneratedPomFileTest.kt @@ -0,0 +1,104 @@ +package io.deepmedia.tools.grease + +import org.gradle.testkit.runner.GradleRunner +import java.nio.file.Path +import kotlin.io.path.ExperimentalPathApi +import kotlin.io.path.createTempDirectory +import kotlin.io.path.deleteRecursively +import kotlin.io.path.readText +import kotlin.io.path.writeText +import kotlin.test.AfterTest +import kotlin.test.BeforeTest +import kotlin.test.Test +import kotlin.test.assertContains +import kotlin.test.assertFails +import kotlin.test.assertFalse + +class GeneratedPomFileTest { + + private var testProjectDir = createTempDirectory("tmp") + private lateinit var settingsFile: Path + private lateinit var buildFile: Path + + @BeforeTest + fun setup() { + settingsFile = testProjectDir.resolve("settings.gradle.kts") + buildFile = testProjectDir.resolve("build.gradle.kts") + } + + @Test + fun test() { + buildFile.writeText( + """ + plugins { + `maven-publish` + id("com.android.library") version "8.1.4" + } + + apply() + + android { + namespace = "io.deepmedia.tools.grease.sample" + compileSdk = 34 + defaultConfig { + minSdk = 21 + } + publishing { + singleVariant("debug") { + withSourcesJar() + } + } + } + + repositories { + google() + gradlePluginPortal() + mavenCentral() + } + + publishing { + publications { + create("Test", MavenPublication::class.java) { + afterEvaluate { + from(components["debug"]) + } + } + } + } + dependencies { + "grease"("com.otaliastudios:cameraview:2.7.2") + "greaseTree"("androidx.core:core:1.0.0") + } + """.trimIndent() + ) + + settingsFile.writeText(""" + pluginManagement { + repositories { + google() + gradlePluginPortal() + mavenCentral() + } + } + + rootProject.name = "Sample" + """.trimIndent()) + + GradleRunner.create() + .withPluginClasspath() + .withProjectDir(testProjectDir.toFile()) + .forwardOutput() + .withArguments("generatePomFileForTestPublication") + .build() + + val pomContent = testProjectDir.resolve("build/publications/Test/pom-default.xml").readText() + assertFalse(pomContent.contains("androidx.core") ) + assertFalse(pomContent.contains("com.otaliastudios") ) + } + + @OptIn(ExperimentalPathApi::class) + @AfterTest + fun teardown() { + testProjectDir.deleteRecursively() + } +} \ No newline at end of file diff --git a/grease/src/main/kotlin/io/deepmedia/tools/grease/GreasePlugin.kt b/grease/src/main/kotlin/io/deepmedia/tools/grease/GreasePlugin.kt index 3af5679..9a3991c 100644 --- a/grease/src/main/kotlin/io/deepmedia/tools/grease/GreasePlugin.kt +++ b/grease/src/main/kotlin/io/deepmedia/tools/grease/GreasePlugin.kt @@ -9,7 +9,6 @@ import com.android.build.gradle.internal.LibraryTaskManager import com.android.build.gradle.internal.LoggerWrapper import com.android.build.gradle.internal.TaskManager import com.android.build.gradle.internal.component.ComponentCreationConfig -import com.android.build.gradle.internal.manifest.parseManifest import com.android.build.gradle.internal.publishing.AndroidArtifacts import com.android.build.gradle.internal.res.GenerateLibraryRFileTask import com.android.build.gradle.internal.res.ParseLibraryResourcesTask @@ -23,21 +22,23 @@ import com.android.build.gradle.internal.tasks.manifest.mergeManifests import com.android.build.gradle.tasks.BundleAar import com.android.build.gradle.tasks.MergeResources import com.android.build.gradle.tasks.ProcessLibraryManifest -import com.android.builder.errors.DefaultIssueReporter import com.android.ide.common.resources.CopyToOutputDirectoryResourceCompilationService +import com.android.ide.common.symbols.parseManifest import com.android.manifmerger.ManifestMerger2 import com.android.manifmerger.ManifestProvider -import com.android.utils.StdLogger +import com.android.utils.appendCapitalized import com.github.jengelman.gradle.plugins.shadow.relocation.Relocator import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.artifacts.Configuration +import org.gradle.api.file.FileCollection import org.gradle.api.publish.maven.internal.publication.DefaultMavenPublication import org.gradle.api.publish.maven.tasks.PublishToMavenRepository import org.gradle.kotlin.dsl.support.unzipTo import org.gradle.kotlin.dsl.support.zipTo import java.io.File +import kotlin.reflect.full.functions /** * Adds grease configurations for bundling dependencies in AAR files. @@ -50,8 +51,6 @@ import java.io.File */ open class GreasePlugin : Plugin { - private val defaultIssueReporter = DefaultIssueReporter(StdLogger(StdLogger.Level.WARNING)) - override fun apply(target: Project) { target.plugins.withId("com.android.library") { val log = Logger(target, "grease") @@ -121,7 +120,7 @@ open class GreasePlugin : Plugin { val componentConfig = variant.componentCreationConfigOrThrow() - target.locateTask(componentConfig.computeTaskName("process", "Manifest"))?.configure { + target.locateTask(componentConfig.resolveTaskName("process", "Manifest"))?.configure { val processManifestTask = this as ProcessLibraryManifest val extraManifests = configurations.artifactsOf(AndroidArtifacts.ArtifactType.MANIFEST) @@ -176,7 +175,7 @@ open class GreasePlugin : Plugin { /* Extra outputs that can probably be null. */ outAaptSafeManifestLocation = null, /* Either LIBRARY or APPLICATION. When using LIBRARY we can't add lib dependencies */ - mergeType = ManifestMerger2.MergeType.FUSED_LIBRARY, + mergeType = ManifestMerger2.MergeType.LIBRARY, /* Manifest placeholders. Doing this the way the library manifest does. */ placeHolders = mergedFlavor?.manifestPlaceholders.orEmpty() + variant.manifestPlaceholders.get(), /* Optional features to be enabled. */ @@ -221,7 +220,7 @@ open class GreasePlugin : Plugin { val creationConfig = variant.componentCreationConfigOrThrow() - target.locateTask(creationConfig.computeTaskName("copy", "JniLibsProjectAndLocalJars"))?.configure { + target.locateTask(creationConfig.resolveTaskName("copy", "JniLibsProjectAndLocalJars"))?.configure { val copyJniTask = this as LibraryJniLibsTask val extraJniLibs = configurations.artifactsOf(AndroidArtifacts.ArtifactType.JNI) dependsOn(extraJniLibs) @@ -242,7 +241,15 @@ open class GreasePlugin : Plugin { } } - val files = projectNativeLibs.get().files().files + localJarsNativeLibs?.files.orEmpty() + // In agp 8.8.0 return type of `localJarsNativeLibs` property was changed + // So its starts to throw `NoSuchMethodError` when we applied older version of agp + // To prevent that we simply find this function by reflection, call it + // and casting result to proper type + fun LibraryJniLibsTask.localJarsNativeLibs() = this::class.functions + .find { it.name == "localJarsNativeLibs" } + ?.let { it.call() as? FileCollection } + + val files = projectNativeLibs.get().files().files + localJarsNativeLibs()?.files.orEmpty() if (files.isNotEmpty()) { doLast { injectJniLibs() } } else { @@ -318,11 +325,12 @@ open class GreasePlugin : Plugin { log.d { "Configuring variant ${variant.name}..." } val creationConfig = variant.componentCreationConfigOrThrow() - target.locateTask(creationConfig.computeTaskName("package", "Resources"))?.configure { + target.locateTask(creationConfig.resolveTaskName("package", "Resources"))?.configure { this as MergeResources val resourcesMergingWorkdir = target.greaseBuildDir.get().dir(variant.name).dir("resources") val mergedResourcesDir = resourcesMergingWorkdir.dir("merged") + val currentResourcesDir = resourcesMergingWorkdir.dir("current") val blameDir = resourcesMergingWorkdir.dir("blame") val extraAndroidRes = configurations.artifactsOf(AndroidArtifacts.ArtifactType.ANDROID_RES) dependsOn(extraAndroidRes) @@ -331,6 +339,11 @@ open class GreasePlugin : Plugin { fun injectResources() { target.delete(resourcesMergingWorkdir) + target.delete(currentResourcesDir) + target.copy { + from(outputDir.asFileTree) + into(currentResourcesDir) + } val executorFacade = Workers.withGradleWorkers( creationConfig.services.projectInfo.path, @@ -343,7 +356,7 @@ open class GreasePlugin : Plugin { resCompilerService = CopyToOutputDirectoryResourceCompilationService, incrementalMergedResources = mergedResourcesDir.asFile, mergedResources = outputDir.asFile.get(), - resourceSets = extraAndroidRes.files.toList(), + resourceSets = currentResourcesDir.asFileTree.files.toList() + extraAndroidRes.files, minSdk = minSdk.get(), aaptWorkerFacade = executorFacade, blameLogOutputFolder = blameDir.asFile, @@ -396,7 +409,7 @@ open class GreasePlugin : Plugin { val bundleLibraryTask = creationConfig.taskContainer.bundleLibraryTask val greaseExpandTask = target.tasks.locateOrRegisterTask( - creationConfig.computeTaskName("extract", "Aar").greasify(), + creationConfig.resolveTaskName("extract", "Aar").greasify(), ) { val bundleAar = bundleLibraryTask?.get() as BundleAar @@ -412,7 +425,7 @@ open class GreasePlugin : Plugin { } val greaseProcessTask = target.tasks.locateOrRegisterTask( - creationConfig.computeTaskName("process", "Jar").greasify(), + creationConfig.resolveTaskName("process", "Jar").greasify(), ) { // There are many options here. PROCESSED_JAR, PROCESSED_AAR, CLASSES, CLASSES_JAR ... @@ -427,7 +440,8 @@ open class GreasePlugin : Plugin { fun injectClasses(inputJar: File) { log.d { "Processing inputJar=$inputJar outputDir=${jarExtractWorkdir}..." } - val inputFiles = target.zipTree(inputJar).matching { include("**/*.class", "**/*.kotlin_module") } + //keep java resources from jar + val inputFiles = target.zipTree(inputJar) target.copy { from(inputFiles) into(jarExtractWorkdir) @@ -443,7 +457,7 @@ open class GreasePlugin : Plugin { } val greaseShadowTask = target.tasks.locateOrRegisterTask( - creationConfig.computeTaskName("shadow", "Aar").greasify(), + creationConfig.resolveTaskName("shadow", "Aar").greasify(), ShadowJar::class.java ) { val compileTask = creationConfig.taskContainer.javacTask @@ -469,8 +483,8 @@ open class GreasePlugin : Plugin { log.d { "Executing shadowing for variant ${variant.name} and ${extraManifests.files.size} roots with namespace ${variant.namespace.get()}..." } extraManifests.forEach { inputFile -> - val manifestData = parseManifest(inputFile, true, { true }, defaultIssueReporter) - manifestData.packageName?.let { fromPackageName -> + val manifestData = parseManifest(inputFile) + manifestData.`package`?.let { fromPackageName -> log.d { "Processing R class from $fromPackageName manifestInput=${inputFile.path} outputDir=${compileTask.get().destinationDirectory.get()}..." } relocate(RClassRelocator(fromPackageName, variant.namespace.get(), log)) } @@ -648,7 +662,7 @@ open class GreasePlugin : Plugin { val log = logger.child("configureVariantProguardFiles") log.d { "Configuring variant ${variant.name}..." } val creationConfig = variant.componentCreationConfigOrThrow() - target.locateTask(creationConfig.computeTaskName("merge", "ConsumerProguardFiles"))?.configure { + target.locateTask(creationConfig.resolveTaskName("merge", "ConsumerProguardFiles"))?.configure { val mergeFileTask = this as MergeFileTask // UNFILTERED_PROGUARD_RULES, FILTERED_PROGUARD_RULES, AAPT_PROGUARD_RULES, ... // UNFILTERED_PROGUARD_RULES is output of the AarTransform. FILTERED_PROGUARD_RULES @@ -664,6 +678,9 @@ open class GreasePlugin : Plugin { } } +private fun ComponentCreationConfig.resolveTaskName(prefix: String, suffix: String): String = + prefix.appendCapitalized(name, suffix) + private fun Variant.componentCreationConfigOrThrow(): ComponentCreationConfig { return when (this) { is ComponentCreationConfig -> this diff --git a/grease/src/main/kotlin/io/deepmedia/tools/grease/configurations.kt b/grease/src/main/kotlin/io/deepmedia/tools/grease/configurations.kt index abf86fe..34dec9f 100644 --- a/grease/src/main/kotlin/io/deepmedia/tools/grease/configurations.kt +++ b/grease/src/main/kotlin/io/deepmedia/tools/grease/configurations.kt @@ -80,7 +80,7 @@ private fun Project.createGrease(name: String, isTransitive: Boolean): Configura } configurations.configureEach { val other = this - if (other.name == nameOf(name, "compileClasspath")) { + if (other.name == nameOf(name, "compileOnly")) { other.extendsFrom(configuration) } } @@ -132,7 +132,7 @@ internal fun Project.createProductFlavorConfigurations( // Create one configuration per build type. // Make it extend the root configuration so that artifacts are inherited. internal fun Project.createBuildTypeConfigurations( - buildTypes: NamedDomainObjectContainer, + buildTypes: NamedDomainObjectContainer, isTransitive: Boolean, log: Logger ) { diff --git a/grease/src/main/kotlin/io/deepmedia/tools/grease/files.kt b/grease/src/main/kotlin/io/deepmedia/tools/grease/files.kt index 73b9241..2879515 100644 --- a/grease/src/main/kotlin/io/deepmedia/tools/grease/files.kt +++ b/grease/src/main/kotlin/io/deepmedia/tools/grease/files.kt @@ -43,7 +43,7 @@ val File.packageNames: Set if (file.name != "module-info.class") { val cleanedPath = file.path.removePrefix(this.path).removePrefix("/") cleanedPath - .substring(0 until cleanedPath.lastIndexOf('/')) - .replace('/', '.') + .substring(0 until cleanedPath.lastIndexOf('/').coerceAtLeast(0)) + .replace('/', '.').takeIf { it.isNotBlank() } } else null }.toSet() \ No newline at end of file diff --git a/tests/build.gradle.kts b/tests/build.gradle.kts new file mode 100644 index 0000000..dbd2cdc --- /dev/null +++ b/tests/build.gradle.kts @@ -0,0 +1,4 @@ +plugins { + alias(libs.plugins.android.library) apply false + alias(libs.plugins.kotlin.android) apply false +} diff --git a/tests/gradle/wrapper/gradle-wrapper.jar b/tests/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..980502d Binary files /dev/null and b/tests/gradle/wrapper/gradle-wrapper.jar differ diff --git a/tests/gradle/wrapper/gradle-wrapper.properties b/tests/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..128196a --- /dev/null +++ b/tests/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-9.0-milestone-1-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/tests/gradlew b/tests/gradlew new file mode 100755 index 0000000..faf9300 --- /dev/null +++ b/tests/gradlew @@ -0,0 +1,251 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# 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 +# +# https://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. +# +# SPDX-License-Identifier: Apache-2.0 +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/tests/gradlew.bat b/tests/gradlew.bat new file mode 100644 index 0000000..9d21a21 --- /dev/null +++ b/tests/gradlew.bat @@ -0,0 +1,94 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/tests/sample-dependency-library/.gitignore b/tests/sample-dependency-library/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/tests/sample-dependency-library/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/tests/sample-dependency-library/build.gradle.kts b/tests/sample-dependency-library/build.gradle.kts new file mode 100644 index 0000000..61dc50d --- /dev/null +++ b/tests/sample-dependency-library/build.gradle.kts @@ -0,0 +1,25 @@ +plugins { + alias(libs.plugins.android.library) + alias(libs.plugins.kotlin.android) +} + +android { + namespace = "io.deepmedia.tools.grease.sample.dependency.library" + compileSdk = 34 + defaultConfig { + minSdk = 21 + } + + compileOptions { + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 + } + + kotlinOptions { + jvmTarget = "17" + } +} + +dependencies { + // Empty +} diff --git a/tests/sample-dependency-library/src/main/res/values/strings.xml b/tests/sample-dependency-library/src/main/res/values/strings.xml new file mode 100644 index 0000000..f254287 --- /dev/null +++ b/tests/sample-dependency-library/src/main/res/values/strings.xml @@ -0,0 +1,5 @@ + + + library_dependency + library2 + \ No newline at end of file diff --git a/tests/sample-dependency-pure/build.gradle.kts b/tests/sample-dependency-pure/build.gradle.kts index e221e25..fb59388 100644 --- a/tests/sample-dependency-pure/build.gradle.kts +++ b/tests/sample-dependency-pure/build.gradle.kts @@ -10,11 +10,16 @@ android { minSdk = 21 } + compileOptions { + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 + } + kotlinOptions { - jvmTarget = "1.8" + jvmTarget = "17" } } dependencies { // Empty -} \ No newline at end of file +} diff --git a/tests/sample-library/build.gradle.kts b/tests/sample-library/build.gradle.kts index 46c1896..f56e7b0 100644 --- a/tests/sample-library/build.gradle.kts +++ b/tests/sample-library/build.gradle.kts @@ -1,5 +1,6 @@ plugins { alias(libs.plugins.android.library) + alias(libs.plugins.kotlin.android) id("io.deepmedia.tools.grease") } @@ -53,11 +54,23 @@ android { path = file("src/main/CMakeLists.txt") } } + + compileOptions { + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 + } + + kotlinOptions { + jvmTarget = "17" + } } dependencies { grease("androidx.core:core:1.0.0") + grease(project(":sample-dependency-pure")) + grease(project(":sample-dependency-library")) + // include deps to pom when publishing api("com.google.android.material:material:1.0.0") // Includes resource and some manifest changes @@ -67,6 +80,4 @@ dependencies { grease("org.tensorflow:tensorflow-lite:2.3.0") // Manifest changes, layout resources grease("com.otaliastudios:cameraview:2.7.2") - - grease(project(":sample-dependency-pure")) -} \ No newline at end of file +} diff --git a/tests/sample-library/src/main/java/io/deepmedia/tools/grease/sample/library/spi/CommandHandler.kt b/tests/sample-library/src/main/java/io/deepmedia/tools/grease/sample/library/spi/CommandHandler.kt new file mode 100644 index 0000000..c5fe393 --- /dev/null +++ b/tests/sample-library/src/main/java/io/deepmedia/tools/grease/sample/library/spi/CommandHandler.kt @@ -0,0 +1,5 @@ +package io.deepmedia.tools.grease.sample.library.spi + +interface CommandHandler { + fun handle() +} diff --git a/tests/sample-library/src/main/java/io/deepmedia/tools/grease/sample/library/spi/SimpleHandler.kt b/tests/sample-library/src/main/java/io/deepmedia/tools/grease/sample/library/spi/SimpleHandler.kt new file mode 100644 index 0000000..05aa897 --- /dev/null +++ b/tests/sample-library/src/main/java/io/deepmedia/tools/grease/sample/library/spi/SimpleHandler.kt @@ -0,0 +1,7 @@ +package io.deepmedia.tools.grease.sample.library.spi + +class SimpleHandler : CommandHandler { + override fun handle() { + println("SPI simple handler") + } +} diff --git a/tests/sample-library/src/main/res/values/strings.xml b/tests/sample-library/src/main/res/values/strings.xml new file mode 100644 index 0000000..d5cddaa --- /dev/null +++ b/tests/sample-library/src/main/res/values/strings.xml @@ -0,0 +1,4 @@ + + + library + \ No newline at end of file diff --git a/tests/sample-library/src/main/resources/META-INF/services/io.deepmedia.tools.grease.sample.library.spi.CommandHandler b/tests/sample-library/src/main/resources/META-INF/services/io.deepmedia.tools.grease.sample.library.spi.CommandHandler new file mode 100644 index 0000000..7e8c49a --- /dev/null +++ b/tests/sample-library/src/main/resources/META-INF/services/io.deepmedia.tools.grease.sample.library.spi.CommandHandler @@ -0,0 +1 @@ +io.deepmedia.tools.grease.sample.library.spi.SimpleHandler diff --git a/tests/settings.gradle.kts b/tests/settings.gradle.kts index 844ebee..a575555 100644 --- a/tests/settings.gradle.kts +++ b/tests/settings.gradle.kts @@ -24,4 +24,5 @@ dependencyResolutionManagement { rootProject.name = "Grease" include(":sample-library") -include(":sample-dependency-pure") \ No newline at end of file +include(":sample-dependency-pure") +include(":sample-dependency-library") \ No newline at end of file