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 62e82cb..7f555f7 100644 --- a/grease/src/main/kotlin/io/deepmedia/tools/grease/GreasePlugin.kt +++ b/grease/src/main/kotlin/io/deepmedia/tools/grease/GreasePlugin.kt @@ -27,11 +27,14 @@ import com.android.ide.common.symbols.parseManifest import com.android.manifmerger.ManifestMerger2 import com.android.manifmerger.ManifestProvider import com.android.utils.appendCapitalized +import com.github.jengelman.gradle.plugins.shadow.ShadowStats +import com.github.jengelman.gradle.plugins.shadow.relocation.RelocatePathContext 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.Directory import org.gradle.api.publish.maven.internal.publication.DefaultMavenPublication import org.gradle.api.publish.maven.tasks.PublishToMavenRepository import org.gradle.kotlin.dsl.support.unzipTo @@ -68,20 +71,25 @@ open class GreasePlugin : Plugin { createConfigurations(false) createConfigurations(true) - fun configure(variant: Variant, vararg configurations: Configuration) { - configureVariantManifest(target, variant, configurations, log) - configureVariantJniLibs(target, variant, configurations, log) - configureVariantResources(target, variant, configurations, log) - configureVariantSources(target, variant, configurations, greaseExtension, log) - configureVariantAssets(target, variant, configurations, log) - configureVariantProguardFiles(target, variant, configurations, log) + fun configure(variant: Variant, runtime: List, api: List) { + configureVariantManifest(target, variant, runtime, log) + configureVariantJniLibs(target, variant, runtime, log) + configureVariantAidlParcelables(target, variant, runtime + api, log) + configureVariantResources(target, variant, runtime, log) + configureVariantSources(target, variant, runtime, greaseExtension, log) + configureVariantAssets(target, variant, runtime, log) + configureVariantProguardFiles(target, variant, runtime, log) } // Configure all variants. androidComponents.onVariants { variant -> val childLog = log.child("configureVariant") childLog.d { "Configuring variant ${variant.name}..." } target.afterEvaluate { - configure(variant, target.greaseOf(variant), target.greaseOf(variant, true)) + configure( + variant = variant, + runtime = listOf(target.greaseOf(variant), target.greaseOf(variant, true)), + api = listOf(target.greaseApiOf(variant), target.greaseApiOf(variant, true)) + ) } } } @@ -110,7 +118,7 @@ open class GreasePlugin : Plugin { private fun configureVariantManifest( target: Project, variant: Variant, - configurations: Array, + configurations: List, logger: Logger ) { val log = logger.child("configureVariantManifest") @@ -210,7 +218,7 @@ open class GreasePlugin : Plugin { private fun configureVariantJniLibs( target: Project, variant: Variant, - configurations: Array, + configurations: List, logger: Logger ) { val log = logger.child("configureVariantJniLibs") @@ -248,6 +256,37 @@ open class GreasePlugin : Plugin { } } + private fun configureVariantAidlParcelables( + target: Project, + variant: Variant, + configurations: List, + logger: Logger + ) { + val log = logger.child("configureVariantAidlParcelables") + log.d { "Configuring variant ${variant.name}..." } + val creationConfig = variant.componentCreationConfigOrThrow() + creationConfig.taskContainer.aidlCompileTask?.configure { + val extraAidlFiles = configurations.artifactsOf(AndroidArtifacts.ArtifactType.AIDL) + dependsOn(extraAidlFiles) + fun injectAidlFiles() { + log.d { "Executing for variant ${variant.name} and ${extraAidlFiles.files.size} roots..." } + extraAidlFiles.files.forEach { inputRoot -> + log.d { "Found aidl parcelables files root: $inputRoot" } + val inputFiles = target.fileTree(inputRoot) + target.copy { + from(inputFiles) + into(packagedDir.get()) + } + } + } + if (sourceFiles.get().files.isNotEmpty()) { + doLast { injectAidlFiles() } + } else { + injectAidlFiles() + } + } + } + /** * AARs ship with a file called R.txt which already includes all resource ids from dependencies, * so we shouldn't probably do nothing about it as it comes for free. @@ -307,7 +346,7 @@ open class GreasePlugin : Plugin { private fun configureVariantResources( target: Project, variant: Variant, - configurations: Array, + configurations: List, logger: Logger ) { @@ -376,7 +415,7 @@ open class GreasePlugin : Plugin { private fun configureVariantSources( target: Project, variant: Variant, - configurations: Array, + configurations: List, greaseExtension: GreaseExtension, logger: Logger ) { @@ -386,6 +425,7 @@ open class GreasePlugin : Plugin { val creationConfig = variant.componentCreationConfigOrThrow() val workdir = target.greaseBuildDir.get().dir(variant.name) + workdir.asFile.deleteRecursively() val aarExtractWorkdir = workdir.dir("extract").dir("aar") val jarExtractWorkdir = workdir.dir("extract").dir("jar") val jarFileName = "classes.jar" @@ -475,8 +515,8 @@ open class GreasePlugin : Plugin { val relocationPrefix = greaseExtension.prefix.get() if (relocationPrefix.isNotEmpty()) { - greaseProcessTask.get().outputs.files - .asSequence() + val sequence = greaseProcessTask.get().outputs.files.asSequence() + aarExtractWorkdir.dir("aidl").asFile + sequence .flatMap { inputFile -> inputFile.packageNames } .distinct() .map { packageName -> packageName to "${relocationPrefix}.$packageName" } @@ -502,13 +542,20 @@ open class GreasePlugin : Plugin { into(aarExtractWorkdir) } - replacePackagesInFile( + replacePackagesInManifest( aarExtractWorkdir.file("AndroidManifest.xml").asFile, greaseShadowDir.file("AndroidManifest.xml").asFile, relocators, target, ) + relocateAidlFiles( + aarExtractWorkdir.dir("aidl"), + greaseShadowDir.dir("aidl"), + relocators, + target, + ) + val oldArchive = bundleAar.archiveFile.get().asFile val archiveParent = oldArchive.parentFile val archiveName = oldArchive.name @@ -544,7 +591,7 @@ open class GreasePlugin : Plugin { } } - private fun replacePackagesInFile( + private fun replacePackagesInManifest( input: File, output: File, relocators: List, @@ -573,6 +620,48 @@ open class GreasePlugin : Plugin { } } + + private fun relocateAidlFiles( + inputDir: Directory, + outputDir: Directory, + relocators: List, + target: Project, + ) { + if (inputDir.asFileTree.isEmpty) return + + inputDir.asFileTree.forEach { file -> + val relocatePathContext = RelocatePathContext().apply { + stats = ShadowStats() + } + val reader = file.bufferedReader() + val relocatedPath = relocators + .filterNot { it is RClassRelocator } + .fold(file.toRelativeString(inputDir.asFile)) { acc, relocator -> + relocator.relocatePath(relocatePathContext.apply { path = acc }) + } + val writer = outputDir.asFile.file(relocatedPath).bufferedWriter() + reader.useLines { strings -> + strings + .map { string -> + relocators + .filterNot { it is RClassRelocator } + .fold(string) { acc, relocator -> + relocator.applyToSourceContent(acc) + } + }.forEach { + writer.write(it) + writer.newLine() + } + } + writer.close() + } + inputDir.asFile.deleteRecursively() + target.copy { + from(outputDir) + into(inputDir) + } + } + /** * Interesting tasks: * 1. generate<>Assets: See [MutableTaskContainer]. @@ -585,7 +674,7 @@ open class GreasePlugin : Plugin { private fun configureVariantAssets( target: Project, variant: Variant, - configurations: Array, + configurations: List, logger: Logger ) { val log = logger.child("configureVariantAssets") @@ -639,7 +728,7 @@ open class GreasePlugin : Plugin { private fun configureVariantProguardFiles( target: Project, variant: Variant, - configurations: Array, + configurations: List, logger: Logger ) { val log = logger.child("configureVariantProguardFiles") 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 c5f166c..8ad2208 100644 --- a/grease/src/main/kotlin/io/deepmedia/tools/grease/configurations.kt +++ b/grease/src/main/kotlin/io/deepmedia/tools/grease/configurations.kt @@ -5,6 +5,7 @@ import com.android.build.api.variant.AndroidComponentsExtension import com.android.build.api.variant.Variant import com.android.build.gradle.internal.dsl.BuildType import com.android.build.gradle.internal.publishing.AndroidArtifacts +import com.android.build.gradle.internal.publishing.AndroidArtifacts.ArtifactType import org.gradle.api.NamedDomainObjectContainer import org.gradle.api.Project import org.gradle.api.artifacts.Configuration @@ -16,13 +17,13 @@ import org.gradle.kotlin.dsl.get import org.gradle.kotlin.dsl.named import java.util.function.Consumer -internal fun Configuration.artifactsOf(type: AndroidArtifacts.ArtifactType): FileCollection = incoming.artifactView { +internal fun Configuration.artifactsOf(type: ArtifactType): FileCollection = incoming.artifactView { attributes { attribute(AndroidArtifacts.ARTIFACT_TYPE, type.type) } }.files -internal fun Array.artifactsOf(type: AndroidArtifacts.ArtifactType): FileCollection = map { +internal fun List.artifactsOf(type: ArtifactType): FileCollection = map { it.incoming.artifactView { attributes { attribute(AndroidArtifacts.ARTIFACT_TYPE, type.type) @@ -32,7 +33,8 @@ internal fun Array.artifactsOf(type: AndroidArtifacts.Artifac ArtifactsFileCollection(it) } -private class ArtifactsFileCollection(private val fileCollections: List) : CompositeFileCollection() { +private class ArtifactsFileCollection(private val fileCollections: List) : + CompositeFileCollection() { override fun getDisplayName(): String = "grease file collection" override fun visitChildren(visitor: Consumer) { @@ -43,11 +45,17 @@ private class ArtifactsFileCollection(private val fileCollections: List log.d { "Creating product flavor configuration ${flavorName.greasify()}..." } val flavorConfiguration = createGrease(flavorName, isTransitive) - flavorConfiguration.extendsFromSafely(grease(isTransitive), log) + flavorConfiguration.extendsFromSafely(this, grease(isTransitive), log) variant.productFlavors.forEach { (_, subFlavor) -> log.d { "Creating sub product flavor configuration ${subFlavor.greasify()}..." } val config = createGrease(subFlavor, isTransitive) - config.extendsFromSafely(grease(isTransitive), log) - flavorConfiguration.extendsFromSafely(config, log) + config.extendsFromSafely(this, grease(isTransitive), log) + flavorConfiguration.extendsFromSafely(this, config, log) } variant.productFlavors.forEach { (_, subFlavor) -> val buildTypedSubFlavor = nameOf(subFlavor, variant.buildType.orEmpty()) @@ -121,10 +134,13 @@ internal fun Project.createProductFlavorConfigurations( config.attributes { attribute(BuildTypeAttr.ATTRIBUTE, objects.named(BuildTypeAttr::class, variant.buildType.orEmpty())) } - config.extendsFromSafely(grease(isTransitive), log) - config.extendsFromSafely(greaseOf(variant.buildType.orEmpty(), isTransitive), log) - config.extendsFromSafely(greaseOf(subFlavor, isTransitive), log) - config.extendsFromSafely(flavorConfiguration, log) + greaseApiOf(config).attributes { + attribute(BuildTypeAttr.ATTRIBUTE, objects.named(BuildTypeAttr::class, variant.buildType.orEmpty())) + } + config.extendsFromSafely(this, grease(isTransitive), log) + config.extendsFromSafely(this, greaseOf(variant.buildType.orEmpty(), isTransitive), log) + config.extendsFromSafely(this, greaseOf(subFlavor, isTransitive), log) + config.extendsFromSafely(this, flavorConfiguration, log) } } } @@ -140,10 +156,13 @@ internal fun Project.createBuildTypeConfigurations( val buildType = this log.d { "Creating build type configuration ${buildType.name.greasify()}..." } val config = createGrease(buildType.name, isTransitive) - config.extendsFromSafely(grease(isTransitive), log) + config.extendsFromSafely(this@createBuildTypeConfigurations, grease(isTransitive), log) config.attributes { attribute(BuildTypeAttr.ATTRIBUTE, objects.named(BuildTypeAttr::class, buildType.name)) } + greaseApiOf(config).attributes { + attribute(BuildTypeAttr.ATTRIBUTE, objects.named(BuildTypeAttr::class, buildType.name)) + } } } @@ -160,21 +179,25 @@ internal fun Project.createVariantConfigurations( config.attributes { attribute(BuildTypeAttr.ATTRIBUTE, objects.named(BuildTypeAttr::class, variant.buildType.orEmpty())) } - config.extendsFromSafely(grease(isTransitive), log) - config.extendsFromSafely(greaseOf(variant.buildType.orEmpty(), isTransitive), log) + greaseApiOf(config).attributes { + attribute(BuildTypeAttr.ATTRIBUTE, objects.named(BuildTypeAttr::class, variant.buildType.orEmpty())) + } + config.extendsFromSafely(this, grease(isTransitive), log) + config.extendsFromSafely(this, greaseOf(variant.buildType.orEmpty(), isTransitive), log) variant.flavorName?.let { flavor -> - config.extendsFromSafely(greaseOf(flavor, isTransitive), log) + config.extendsFromSafely(this, greaseOf(flavor, isTransitive), log) variant.productFlavors.forEach { (_, subFlavor) -> - config.extendsFromSafely(greaseOf(subFlavor, isTransitive), log) - config.extendsFromSafely(greaseOf(nameOf(subFlavor, variant.buildType.orEmpty()), isTransitive), log) + config.extendsFromSafely(this, greaseOf(subFlavor, isTransitive), log) + config.extendsFromSafely(this, greaseOf(nameOf(subFlavor, variant.buildType.orEmpty()), isTransitive), log) } } } -private fun Configuration.extendsFromSafely(configuration: Configuration, log: Logger? = null) { +private fun Configuration.extendsFromSafely(project: Project, configuration: Configuration, log: Logger? = null) { if (configuration.name != name) { log?.d { "Extend $name from ${configuration.name}..." } extendsFrom(configuration) + project.greaseApiOf(this).extendsFrom(project.greaseApiOf(configuration)) } } \ No newline at end of file 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..d2a8c39 100644 --- a/grease/src/main/kotlin/io/deepmedia/tools/grease/files.kt +++ b/grease/src/main/kotlin/io/deepmedia/tools/grease/files.kt @@ -39,7 +39,7 @@ val JarFile.packageNames: Set }.toSet() val File.packageNames: Set - get() = listFilesRecursive("class").mapNotNull { file -> + get() = (listFilesRecursive("class") + listFilesRecursive("aidl")).mapNotNull { file -> if (file.name != "module-info.class") { val cleanedPath = file.path.removePrefix(this.path).removePrefix("/") cleanedPath diff --git a/tests/gradle/wrapper/gradle-wrapper.jar b/tests/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..d64cd49 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..1af9e09 --- /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-8.5-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..1aa94a4 --- /dev/null +++ b/tests/gradlew @@ -0,0 +1,249 @@ +#!/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. +# + +############################################################################## +# +# 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/subprojects/plugins/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 "${APP_HOME:-./}" > /dev/null && pwd -P ) || 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, 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..93e3f59 --- /dev/null +++ b/tests/gradlew.bat @@ -0,0 +1,92 @@ +@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 + +@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. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +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..2c964ba --- /dev/null +++ b/tests/sample-dependency-library/build.gradle.kts @@ -0,0 +1,24 @@ +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 + } + + kotlinOptions { + jvmTarget = "1.8" + } + + buildFeatures { + aidl = true + } +} + +dependencies { + // Empty +} \ No newline at end of file diff --git a/tests/sample-dependency-library/src/main/AndroidManifest.xml b/tests/sample-dependency-library/src/main/AndroidManifest.xml new file mode 100644 index 0000000..972c3a8 --- /dev/null +++ b/tests/sample-dependency-library/src/main/AndroidManifest.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/tests/sample-dependency-library/src/main/aidl/io/deepmedia/tools/grease/sample/dependency/library/ILibraryAidlInterface.aidl b/tests/sample-dependency-library/src/main/aidl/io/deepmedia/tools/grease/sample/dependency/library/ILibraryAidlInterface.aidl new file mode 100644 index 0000000..178a018 --- /dev/null +++ b/tests/sample-dependency-library/src/main/aidl/io/deepmedia/tools/grease/sample/dependency/library/ILibraryAidlInterface.aidl @@ -0,0 +1,13 @@ +// IMyAidlInterface1.aidl +package io.deepmedia.tools.grease.sample.dependency.library; + +// Declare any non-default types here with import statements + +interface ILibraryAidlInterface { + /** + * Demonstrates some basic types that you can use as parameters + * and return values in AIDL. + */ + void basicTypes(int anInt, long aLong, boolean aBoolean, float aFloat, + double aDouble, String aString); +} \ No newline at end of file diff --git a/tests/sample-dependency-library/src/main/aidl/io/deepmedia/tools/grease/sample/dependency/library/LibraryActiveResultInfo.aidl b/tests/sample-dependency-library/src/main/aidl/io/deepmedia/tools/grease/sample/dependency/library/LibraryActiveResultInfo.aidl new file mode 100644 index 0000000..f59bf8f --- /dev/null +++ b/tests/sample-dependency-library/src/main/aidl/io/deepmedia/tools/grease/sample/dependency/library/LibraryActiveResultInfo.aidl @@ -0,0 +1,4 @@ +// LibraryActiveResultInfo.aidl +package io.deepmedia.tools.grease.sample.dependency.library; + +parcelable LibraryActiveResultInfo; \ No newline at end of file diff --git a/tests/sample-dependency-library/src/main/java/io/deepmedia/tools/grease/sample/dependency/library/LibraryDependencyClass.kt b/tests/sample-dependency-library/src/main/java/io/deepmedia/tools/grease/sample/dependency/library/LibraryDependencyClass.kt new file mode 100644 index 0000000..46e9ece --- /dev/null +++ b/tests/sample-dependency-library/src/main/java/io/deepmedia/tools/grease/sample/dependency/library/LibraryDependencyClass.kt @@ -0,0 +1,9 @@ +package io.deepmedia.tools.grease.sample.dependency.library + +object LibraryDependencyClass { + fun foo() = "bar" +} + +fun LibraryDependencyFunction() { + println("foo") +} \ No newline at end of file diff --git a/tests/sample-library/build.gradle.kts b/tests/sample-library/build.gradle.kts index 46c1896..a50d43f 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") } @@ -42,6 +43,10 @@ android { } } + kotlinOptions { + jvmTarget = "1.8" + } + buildTypes { release { isMinifyEnabled = true @@ -53,11 +58,18 @@ android { path = file("src/main/CMakeLists.txt") } } + + buildFeatures { + aidl = true + } } 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 +79,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/aidl/io/deepmedia/tools/grease/sample/library/ActiveResultInfo.aidl b/tests/sample-library/src/main/aidl/io/deepmedia/tools/grease/sample/library/ActiveResultInfo.aidl new file mode 100644 index 0000000..8979097 --- /dev/null +++ b/tests/sample-library/src/main/aidl/io/deepmedia/tools/grease/sample/library/ActiveResultInfo.aidl @@ -0,0 +1,4 @@ +// ActiveResultInfo.aidl +package io.deepmedia.tools.grease.sample.library; + +parcelable ActiveResultInfo; \ No newline at end of file diff --git a/tests/sample-library/src/main/aidl/io/deepmedia/tools/grease/sample/library/IMyAidlInterface.aidl b/tests/sample-library/src/main/aidl/io/deepmedia/tools/grease/sample/library/IMyAidlInterface.aidl new file mode 100644 index 0000000..4518e8b --- /dev/null +++ b/tests/sample-library/src/main/aidl/io/deepmedia/tools/grease/sample/library/IMyAidlInterface.aidl @@ -0,0 +1,13 @@ +// IMyAidlInterface1.aidl +package io.deepmedia.tools.grease.sample.library; + +import io.deepmedia.tools.grease.sample.library.ActiveResultInfo; + +interface IMyAidlInterface { + /** + * Demonstrates some basic types that you can use as parameters + * and return values in AIDL. + */ + void basicTypes(inout ActiveResultInfo info, long aLong, boolean aBoolean, float aFloat, + double aDouble, String aString); +} \ No newline at end of file diff --git a/tests/sample-library/src/main/java/io/deepmedia/tools/grease/sample/library/ActiveResultInfo.kt b/tests/sample-library/src/main/java/io/deepmedia/tools/grease/sample/library/ActiveResultInfo.kt new file mode 100644 index 0000000..9e9623b --- /dev/null +++ b/tests/sample-library/src/main/java/io/deepmedia/tools/grease/sample/library/ActiveResultInfo.kt @@ -0,0 +1,21 @@ +package io.deepmedia.tools.grease.sample.library + +import android.os.Parcel +import android.os.Parcelable + +class ActiveResultInfo() : Parcelable { + constructor(parcel: Parcel) : this() + + override fun writeToParcel(parcel: Parcel, flags: Int) { + } + + override fun describeContents(): Int = 0 + + fun readFromParcel(`in`: Parcel) { + } + + companion object CREATOR : Parcelable.Creator { + override fun createFromParcel(parcel: Parcel): ActiveResultInfo = ActiveResultInfo(parcel) + override fun newArray(size: Int): Array = arrayOfNulls(size) + } +} \ No newline at end of file diff --git a/tests/settings.gradle.kts b/tests/settings.gradle.kts index 844ebee..ca0ae1b 100644 --- a/tests/settings.gradle.kts +++ b/tests/settings.gradle.kts @@ -21,7 +21,8 @@ dependencyResolutionManagement { } } -rootProject.name = "Grease" +rootProject.name = "tests" 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