@@ -29,14 +29,27 @@ open class Desugar : AbstractBaseTask() {
2929 @InputFiles
3030 @NotNull
3131 fun getInJars (): ConfigurableFileCollection {
32- return project.files(getOrConvention(inJars, CONVENTION_IN_JARS ))
32+ return project.files(getOrConvention(inJars, CONVENTION_APP_IN_JARS ))
3333 }
3434
3535 @IgnoreUnused
3636 fun setInJars (inJars : Collection <Any >? ) {
3737 this .inJars = inJars?.toSet()
3838 }
3939
40+ private var rtInJars: Set <Any >? = null
41+
42+ @InputFiles
43+ @NotNull
44+ fun getRuntimeInJars (): ConfigurableFileCollection {
45+ return project.files(getOrConvention(rtInJars, CONVENTION_RUNTIME_IN_JARS ))
46+ }
47+
48+ @IgnoreUnused
49+ fun setRuntimeInJars (inJars : Collection <Any >? ) {
50+ this .rtInJars = inJars?.toSet()
51+ }
52+
4053 private var libraryJars: Set <Any >? = null
4154
4255 @InputFiles
@@ -50,17 +63,30 @@ open class Desugar : AbstractBaseTask() {
5063 this .libraryJars = libraryJars?.toSet()
5164 }
5265
53- private var outJar : Any? = null
66+ private var appOutJar : Any? = null
5467
5568 @OutputFile
5669 @NotNull
57- fun getOutJar (): File {
58- return project.file(getOrConvention(outJar, CONVENTION_OUT_JAR ))
70+ fun getAppOutJar (): File {
71+ return project.file(getOrConvention(appOutJar, CONVENTION_APP_OUT_JAR ))
5972 }
6073
6174 @IgnoreUnused
62- fun setOutJar (outJar : Any? ) {
63- this .outJar = outJar
75+ fun setAppOutJar (outJar : Any? ) {
76+ this .appOutJar = outJar
77+ }
78+
79+ private var rtOutJar: Any? = null
80+
81+ @OutputFile
82+ @NotNull
83+ fun getRuntimeOutJar (): File {
84+ return project.file(getOrConvention(rtOutJar, CONVENTION_RUNTIME_OUT_JAR ))
85+ }
86+
87+ @IgnoreUnused
88+ fun setRuntimeOutJar (outJar : Any? ) {
89+ this .rtOutJar = outJar
6490 }
6591
6692 private var composedCfgFile: Any? = null
@@ -77,7 +103,8 @@ open class Desugar : AbstractBaseTask() {
77103 }
78104
79105 override fun run () {
80- FileUtils .deleteFileOrFolder(getOutJar())
106+ FileUtils .deleteFileOrFolder(getAppOutJar())
107+ FileUtils .deleteFileOrFolder(getRuntimeOutJar())
81108
82109 composeConfigurationFile()
83110 javaexec { spec ->
@@ -89,19 +116,30 @@ open class Desugar : AbstractBaseTask() {
89116 private fun composeConfigurationFile () {
90117 val conf = StringBuilder ()
91118
92- // Add injars
93- ProGuard .startSection(conf, " Generating -injars " )
119+ // Backport App codes
120+ ProGuard .startSection(conf, " Processing app code & libraries " )
94121 getInJars().forEach {
95122 if (it.exists()) {
96123 conf.append(" -injars " ).append(it.absolutePath).append(" \n " )
97124 } else {
98125 LOG .debug(" inJars file doesn't exist: " + it.absolutePath)
99126 }
100127 }
101-
102- // Add outjar
103- ProGuard .startSection(conf, " Generating -outjars" )
104- conf.append(" -outjars \" " ).append(getOutJar().absolutePath).append(" \"\n " )
128+ conf.append(" -outjars \" " ).append(getAppOutJar().absolutePath).append(" \"\n " )
129+
130+ // Then process Runtime libs
131+ ProGuard .startSection(conf, " Processing MOE runtimes" )
132+ val rtInJars = getRuntimeInJars()
133+ if (! rtInJars.isEmpty) {
134+ rtInJars.forEach {
135+ if (it.exists()) {
136+ conf.append(" -injars " ).append(it.absolutePath).append(" \n " )
137+ } else {
138+ LOG .debug(" inJars file doesn't exist: " + it.absolutePath)
139+ }
140+ }
141+ conf.append(" -outjars \" " ).append(getRuntimeOutJar().absolutePath).append(" \"\n " )
142+ }
105143
106144 // Add libraryjars
107145 ProGuard .startSection(conf, " Generating -libraryjars" )
@@ -154,10 +192,9 @@ open class Desugar : AbstractBaseTask() {
154192 dependsOn(proGuardTask)
155193
156194 // Update convention mapping
157- addConvention(CONVENTION_IN_JARS ) {
195+ addConvention(CONVENTION_APP_IN_JARS ) { setOf (proGuardTask.outJar) }
196+ addConvention(CONVENTION_RUNTIME_IN_JARS ) {
158197 mutableSetOf<File >().apply {
159- add(proGuardTask.outJar)
160-
161198 when (moeExtension.proguard.levelRaw) {
162199 ProGuardOptions .LEVEL_APP -> {
163200 add(moeSDK.coreJar)
@@ -185,17 +222,20 @@ open class Desugar : AbstractBaseTask() {
185222 remove(moeSDK.java8SupportJar)
186223 }
187224 }
188- addConvention(CONVENTION_OUT_JAR ) { resolvePathInBuildDir(out , " output.jar" ) }
225+ addConvention(CONVENTION_APP_OUT_JAR ) { resolvePathInBuildDir(out , " output-app.jar" ) }
226+ addConvention(CONVENTION_RUNTIME_OUT_JAR ) { resolvePathInBuildDir(out , " output-rt.jar" ) }
189227 addConvention(CONVENTION_COMPOSED_CFG_FILE ) { resolvePathInBuildDir(out , " configuration.pro" ) }
190228 addConvention(CONVENTION_LOG_FILE ) { resolvePathInBuildDir(out , " Desugar.log" ) }
191229 }
192230
193231 companion object {
194232 private val LOG = Logging .getLogger(Desugar ::class .java)
195233
196- private const val CONVENTION_IN_JARS = " inJars"
234+ private const val CONVENTION_APP_IN_JARS = " appInJars"
235+ private const val CONVENTION_RUNTIME_IN_JARS = " runtimeInJars"
197236 private const val CONVENTION_LIBRARY_JARS = " libraryJars"
198- private const val CONVENTION_OUT_JAR = " outJar"
237+ private const val CONVENTION_APP_OUT_JAR = " appOutJar"
238+ private const val CONVENTION_RUNTIME_OUT_JAR = " runtimeOutJar"
199239 private const val CONVENTION_COMPOSED_CFG_FILE = " composedCfgFile"
200240 }
201241}
0 commit comments