From a73defdf59512ddfcc05758beb885c849fe3df74 Mon Sep 17 00:00:00 2001 From: himanshumahajan138 Date: Sat, 19 Oct 2024 17:53:05 +0000 Subject: [PATCH] Reviews Resolved ; Fixes: #3550 --- .../android/AndroidAppKotlinModule.scala | 67 +------------------ .../javalib/android/AndroidAppModule.scala | 34 +++++++++- .../src/mill/scalalib/JsonFormatters.scala | 11 ++- 3 files changed, 44 insertions(+), 68 deletions(-) diff --git a/kotlinlib/src/mill/kotlinlib/android/AndroidAppKotlinModule.scala b/kotlinlib/src/mill/kotlinlib/android/AndroidAppKotlinModule.scala index 8a32695a703..ddfaf985b9c 100644 --- a/kotlinlib/src/mill/kotlinlib/android/AndroidAppKotlinModule.scala +++ b/kotlinlib/src/mill/kotlinlib/android/AndroidAppKotlinModule.scala @@ -2,9 +2,6 @@ package mill.kotlinlib.android import mill.kotlinlib.KotlinModule import mill.javalib.android.AndroidAppModule -import mill._ -import coursier.Type -import upickle.default.ReadWriter /** * Trait for building Android applications using the Mill build tool. @@ -21,66 +18,4 @@ import upickle.default.ReadWriter * [[https://developer.android.com/studio Android Studio Documentation]] */ @mill.api.experimental -trait AndroidAppKotlinModule extends AndroidAppModule with KotlinModule { - - /** - * Implicit `ReadWriter` for serializing and deserializing `coursier.Type` values. - * Converts a `coursier.Type` to a `String` and vice versa. - */ - implicit val coursierTypeRW: ReadWriter[Type] = upickle.default.readwriter[String].bimap( - _.value, // Serialize coursier.Type to String - Type(_) // Deserialize String to coursier.Type - ) - - /** - * Implicit `ReadWriter` for handling `Set[coursier.Type]`, allowing conversion - * between a set of `coursier.Type` and a set of `String`. - */ - implicit val coursierTypeSetRW: ReadWriter[Set[Type]] = - upickle.default.readwriter[Set[String]].bimap( - _.map(_.value), // Serialize Set[coursier.Type] to Set[String] - _.map(Type(_)) // Deserialize Set[String] to Set[coursier.Type] - ) - - /** - * Adds the "aar" type to the set of artifact types handled by this module. - * - * @return A task that yields an updated set of artifact types including "aar". - */ - override def artifactTypes: T[Set[Type]] = - T { super.artifactTypes() + coursier.Type("aar") } - - /** - * Task to extract `classes.jar` files from AAR files in the classpath. - * - * @return A sequence of `PathRef` pointing to the extracted JAR files. - */ - def recompileAARs: T[Seq[PathRef]] = Task { - val aarFiles = super.compileClasspath().map(_.path).filter(_.ext == "aar").toSeq - - aarFiles.map { aarFile => - val extractDir = T.dest / aarFile.baseName - os.call(Seq("unzip", aarFile.toString, "-d", extractDir.toString)) - PathRef(extractDir / "classes.jar") - } - } - - /** - * Updates the compile classpath by removing `.aar` files and including the - * extracted `.jar` files from the AARs. - * - * @return A task yielding the updated classpath with `.jar` files. - */ - def updatedCompileClasspath: T[Agg[PathRef]] = Task { - super.compileClasspath().filter(_.path.ext == "jar") ++ Agg.from(recompileAARs()) - } - - /** - * Overrides the compile classpath to replace `.aar` files with the extracted - * `.jar` files. - * - * @return The updated classpath with `.jar` files only. - */ - override def compileClasspath: T[Agg[PathRef]] = updatedCompileClasspath() - -} +trait AndroidAppKotlinModule extends AndroidAppModule with KotlinModule {} diff --git a/scalalib/src/mill/javalib/android/AndroidAppModule.scala b/scalalib/src/mill/javalib/android/AndroidAppModule.scala index 64195f83d2d..15baa18d216 100644 --- a/scalalib/src/mill/javalib/android/AndroidAppModule.scala +++ b/scalalib/src/mill/javalib/android/AndroidAppModule.scala @@ -1,9 +1,9 @@ package mill.javalib.android import mill._ +import mill.scalalib._ import mill.api.PathRef import mill.define.ModuleRef -import mill.scalalib.JavaModule /** * Trait for building Android applications using the Mill build tool. @@ -35,6 +35,38 @@ trait AndroidAppModule extends JavaModule { */ def androidManifest: Task[PathRef] = Task.Source(millSourcePath / "AndroidManifest.xml") + /** + * Adds the "aar" type to the set of artifact types handled by this module. + * + * @return A task that yields an updated set of artifact types including "aar". + */ + def artifactTypes: T[Set[coursier.Type]] = Task { super.artifactTypes() + coursier.Type("aar") } + + /** + * Task to extract `classes.jar` files from AAR files in the classpath. + * + * @return A sequence of `PathRef` pointing to the extracted JAR files. + */ + def androidUnpackArchives: T[Seq[PathRef]] = Task { + val aarFiles = super.compileClasspath().map(_.path).filter(_.ext == "aar").toSeq + + aarFiles.map { aarFile => + val extractDir = T.dest / aarFile.baseName + os.unzip(aarFile, extractDir) + PathRef(extractDir / "classes.jar") + } + } + + /** + * Overrides the compile classpath to replace `.aar` files with the extracted + * `.jar` files. + * + * @return The updated classpath with `.jar` files only. + */ + override def compileClasspath: T[Agg[PathRef]] = Task { + super.compileClasspath().filter(_.path.ext == "jar") ++ Agg.from(androidUnpackArchives()) + } + /** * Generates the Android resources (such as layouts, strings, and other assets) needed * for the application. diff --git a/scalalib/src/mill/scalalib/JsonFormatters.scala b/scalalib/src/mill/scalalib/JsonFormatters.scala index 751ebcc60b3..255237e6222 100644 --- a/scalalib/src/mill/scalalib/JsonFormatters.scala +++ b/scalalib/src/mill/scalalib/JsonFormatters.scala @@ -20,8 +20,17 @@ trait JsonFormatters { implicit lazy val orgFormat: RW[coursier.Organization] = upickle.default.macroRW implicit lazy val modNameFormat: RW[coursier.ModuleName] = upickle.default.macroRW implicit lazy val configurationFormat: RW[coursier.core.Configuration] = upickle.default.macroRW - implicit lazy val typeFormat: RW[coursier.core.Type] = upickle.default.macroRW implicit lazy val classifierFormat: RW[coursier.core.Classifier] = upickle.default.macroRW + implicit lazy val coursierTypeRW: RW[coursier.core.Type] = + upickle.default.readwriter[String].bimap( + _.value, + coursier.core.Type(_) + ) + implicit lazy val coursierTypeSetRW: RW[Set[coursier.core.Type]] = + upickle.default.readwriter[Set[String]].bimap( + _.map(_.value), + _.map(coursier.core.Type(_)) + ) } object JsonFormatters extends JsonFormatters