@@ -61,7 +61,7 @@ abstract class ExportTask : DefaultTask() {
6161 val buildFile = File (dir, path)
6262
6363 val resValuesDel = mutableListOf<String >()
64- for (resId in PackageRecordUtils .getExposeResAssets ()) {
64+ for (resId in IncrementalRecordUtils .getExposeAssets ()) {
6565 resValuesDel.add(resId)
6666 }
6767 if (resValuesDel.isNotEmpty()){
@@ -70,9 +70,9 @@ abstract class ExportTask : DefaultTask() {
7070 for (srcDir in assets.srcDirs) {
7171 if (srcDir.exists()){
7272 for (resValue in resValuesDel) {
73- val file = File (" ${srcDir .absolutePath} /$resValue " )
74- if (file .exists()){
75- file .deleteRecursively()
73+ val targetFile = File (" ${buildFile .absolutePath} /$resValue " )
74+ if (targetFile .exists()){
75+ targetFile .deleteRecursively()
7676 }
7777 }
7878 }
@@ -94,14 +94,16 @@ abstract class ExportTask : DefaultTask() {
9494 for (resValue in resValues) {
9595 val targetFile = File (" ${buildFile.absolutePath} /$resValue " )
9696 val file = File (" ${srcDir.absolutePath} /$resValue " )
97- file.copyRecursively(targetFile,true )
97+ if (file.exists()){
98+ file.copyRecursively(targetFile,true )
99+ }
98100 }
99101
100102
101103 }
102104 }
103105 }
104- PackageRecordUtils .recordExposeAssets(communicationConfig.exposeResIds )
106+ IncrementalRecordUtils .recordExposeAssets(communicationConfig.exposeAssets )
105107 }
106108
107109 fun searchResFileAndCopy (curProject : Project ){
@@ -114,70 +116,8 @@ abstract class ExportTask : DefaultTask() {
114116 val path = " build$codePath "
115117 val buildFile = File (dir, path)
116118
117- val resValuesPreDel = mutableListOf<ResValue >()
118- for (resId in PackageRecordUtils .getExposeResIds()) {
119- val res = ResValue (resId,resId.substring(resId.indexOf(" ." )+ 1 ,resId.lastIndexOf(" ." )),resId.substring(resId.lastIndexOf(" ." )+ 1 ))
120- resValuesPreDel.add(res)
121- }
122- val resValuesDel = resValuesPreDel.filter {
123- it.id.startsWith(" R." )
124- }
125- if (resValuesDel.isNotEmpty()){
126- for (name in variantNames) {
127- val res = libraryExtension.sourceSets.getByName(name).res
128- for (srcDir in res.srcDirs) {
129- if (srcDir.exists()){
130- val genFile = srcDir.listFiles()
131- for (resValue in resValuesDel) {
132- if (Dom4jData .fileRes.contains(resValue.dir)){// 复制文件的
133- val dirs = genFile.filter {
134- it.name.startsWith(resValue.dir)
135- }
136- val collection = curProject.files(dirs).asFileTree.filter { it.name.startsWith(resValue.fileName) }
137-
138- for (file in collection.files) {
139- val copyPath = " ${file.parentFile.name} /${file.name} "
140- val targetFile = File (" ${buildFile.absolutePath} /$copyPath " )
141- if (targetFile.exists()){
142- targetFile.delete()
143- }
144- }
145- }else {// 复制xml里边的值
146- val dirs = genFile.filter {
147- it.name.startsWith(" values" )
148- }
149- val collection = curProject.files(dirs).asFileTree.filter { it.name.endsWith(" .xml" ) }
150-
151- for (file in collection.files) {
152- val elements = Dom4jData .getXmlFileElements(file) ? : continue
153- for (element in elements) {
154- val nodeName: String = element.name
155- val name: String = element.attribute(" name" ).value
156- if (name == resValue.fileName && nodeName != " item" ){
157- val targetFile = File (" ${buildFile.absolutePath} /${file.parentFile.name} " ,file.name)
158- if (! targetFile.exists()){
159- targetFile.parentFile?.mkdirs()
160- targetFile.createNewFile()
161- targetFile.writeText(" <?xml version=\" 1.0\" encoding=\" utf-8\" ?>\n " +
162- " <resources xmlns:tools=\" http://schemas.android.com/tools\" xmlns:android=\" http://schemas.android.com/apk/res/android\" xmlns:app=\" http://schemas.android.com/apk/res-auto\" >\n " +
163- " </resources>" , Charset .forName(" utf-8" ))
164- }
165- val resMapValue = Dom4jData .resMap[resValue.dir]
166- if ((resMapValue != null && nodeName == resMapValue)|| resValue.dir == nodeName){
167- Dom4jData .deleteElementLabel(targetFile,resValue)
168- }
169- }
170- }
171- }
172- }
173- }
174-
175-
176-
177- }
178- }
179- }
180- }
119+ IncrementalRecordUtils .clearResFile(moduleKey, buildFile)
120+ IncrementalRecordUtils .clearResValue(moduleKey, buildFile)
181121
182122 val resValuesPre = mutableListOf<ResValue >()
183123 for (resId in communicationConfig.exposeResIds) {
@@ -206,6 +146,7 @@ abstract class ExportTask : DefaultTask() {
206146 val copyPath = " ${file.parentFile.name} /${file.name} "
207147 val targetFile = File (" ${buildFile.absolutePath} /$copyPath " )
208148 file.copyTo(targetFile,true )
149+ IncrementalRecordUtils .recordResFile(moduleKey,copyPath)
209150 }
210151 }else {// 复制xml里边的值
211152 val dirs = genFile.filter {
@@ -229,8 +170,12 @@ abstract class ExportTask : DefaultTask() {
229170 }
230171 val resMapValue = Dom4jData .resMap[resValue.dir]
231172 if ((resMapValue != null && nodeName == resMapValue)|| resValue.dir == nodeName){
232- val resValueRecord = ResValueRecord (targetFile,resValue)
233173 Dom4jData .addElementLabel(targetFile,element,resValue.fileName)
174+ val resValueRecord = ResValueRecord (targetFile,resValue)
175+ IncrementalRecordUtils .recordResValue(moduleKey, resValueRecord)
176+
177+ val text = targetFile.readText(Charset .forName(" utf-8" )).replace(" \\ s*[\r\n ]+" , " " );
178+ targetFile.writeText(text,Charset .forName(" utf-8" ))
234179 }
235180 }
236181 }
@@ -243,7 +188,6 @@ abstract class ExportTask : DefaultTask() {
243188 }
244189 }
245190 }
246- PackageRecordUtils .recordExposeResIds(communicationConfig.exposeResIds)
247191 }
248192
249193 private fun searchApiFileAndCopy (curProject : Project ){
@@ -257,7 +201,7 @@ abstract class ExportTask : DefaultTask() {
257201 val buildFile = File (dir, path)
258202
259203 val moduleKey = curProject.buildDir.absolutePath
260- val isClear = PackageRecordUtils .clearCodeFile(moduleKey,buildFile)
204+ val isClear = IncrementalRecordUtils .clearCodeFile(moduleKey,buildFile)
261205 if (isClear){
262206 val recordPackageSet = mutableSetOf<String >()
263207 for (file in collection.files) {
@@ -276,7 +220,7 @@ abstract class ExportTask : DefaultTask() {
276220 for (file in collection.files) {
277221 val packageName = getPackageName(file)
278222 packageName?.let {
279- PackageRecordUtils .recordCodeFile(moduleKey,it)
223+ IncrementalRecordUtils .recordCodeFile(moduleKey,it)
280224 val packagePath = buildFile.absolutePath + " /" + it.replace(" ." ," /" )
281225 val targetFile = File (packagePath,file.name.replace(" .api" ," " ))
282226 file.copyTo(targetFile,true )
0 commit comments