@@ -5,6 +5,7 @@ import StringCare.VariantApplicationId
5
5
import StringCare.Configuration
6
6
import StringCare.Extension
7
7
import groovy.json.StringEscapeUtils
8
+ import models.AssetsFile
8
9
import models.ResourceFile
9
10
import org.gradle.api.Project
10
11
import org.gradle.api.Task
@@ -74,9 +75,9 @@ fun String.androidTreatment(): String {
74
75
return values.joinToString(separator = " " )
75
76
}
76
77
77
- fun File.validForConfiguration (configuration : Configuration ): Boolean {
78
+ fun File.validForXMLConfiguration (configuration : Configuration ): Boolean {
78
79
var valid = this .absolutePath.contains(" ${File .separator}${configuration.name}${File .separator} " )
79
- && excluded ().not ()
80
+ && excludedForXML ().not ()
80
81
if (valid) {
81
82
valid = false
82
83
configuration.srcFolders.forEach { folder ->
@@ -105,19 +106,43 @@ fun File.validForConfiguration(configuration: Configuration): Boolean {
105
106
}
106
107
}
107
108
}
108
- if (configuration.debug && excluded ().not ()) {
109
+ if (configuration.debug && excludedForXML ().not ()) {
109
110
println (" ${if (valid) " ✔ " else " ❌ not" } valid file ${this .absolutePath} " )
110
111
}
111
112
return valid
112
113
}
113
114
114
- fun File.excluded (): Boolean {
115
- val exclude = listOf (
116
- " /build/" ,
117
- " /.git/" ,
118
- " /.gradle/" ,
119
- " /gradle/"
120
- )
115
+ fun File.validForAssetsConfiguration (configuration : Configuration ): Boolean {
116
+ var valid = this .absolutePath.contains(" ${File .separator}${configuration.name}${File .separator} " )
117
+ && excludedForAssets().not ()
118
+ if (valid) {
119
+ valid = false
120
+ if (configuration.assetsFiles.isEmpty()) {
121
+ valid = true
122
+ } else {
123
+ configuration.assetsFiles.forEach { file ->
124
+ if (this .absolutePath.normalizePath().endsWith(" ${File .separator}$file " .normalizePath())
125
+ || (file.contains(" *." )
126
+ && this .absolutePath.normalizePath().endsWith(file.replace(" *" ," " )))) {
127
+ valid = true
128
+ }
129
+ }
130
+ }
131
+ }
132
+ if (configuration.debug && excludedForAssets().not ()) {
133
+ println (" ${if (valid) " ✔ " else " ❌ not" } valid file ${this .absolutePath} " )
134
+ }
135
+ return valid
136
+ }
137
+
138
+ val exclude = listOf (
139
+ " /build/" ,
140
+ " /.git/" ,
141
+ " /.gradle/" ,
142
+ " /gradle/"
143
+ )
144
+
145
+ fun File.excludedForXML (): Boolean {
121
146
var valid = true
122
147
exclude.forEach { value ->
123
148
when {
@@ -127,6 +152,16 @@ fun File.excluded(): Boolean {
127
152
return (valid && this .isDirectory.not () && this .absolutePath.contains(" .xml" )).not ()
128
153
}
129
154
155
+ fun File.excludedForAssets (): Boolean {
156
+ var valid = true
157
+ exclude.forEach { value ->
158
+ when {
159
+ this .absolutePath.contains(value.normalizePath()) -> valid = false
160
+ }
161
+ }
162
+ return (valid && this .isDirectory.not () && this .absolutePath.contains(" ${File .separator} assets${File .separator} " )).not ()
163
+ }
164
+
130
165
fun File.resourceFile (configuration : Configuration ): ResourceFile ? {
131
166
var sourceFolder = " "
132
167
var validFile: File ? = null
@@ -161,6 +196,44 @@ fun File.resourceFile(configuration: Configuration): ResourceFile? {
161
196
return if (valid) ResourceFile (validFile!! , sourceFolder, configuration.name) else null
162
197
}
163
198
199
+ fun File.assetsFile (configuration : Configuration ): AssetsFile ? {
200
+ var sourceFolder = " "
201
+ var validFile: File ? = null
202
+ var valid = false
203
+ configuration.srcFolders.forEach { folder ->
204
+ if (this .absolutePath.contains(
205
+ " ${File .separator}$folder${File .separator} " .replace(
206
+ " ${File .separator}${File .separator} " ,
207
+ File .separator
208
+ )
209
+ )
210
+ ) {
211
+ sourceFolder = folder
212
+ valid = true
213
+ }
214
+ }
215
+ if (valid) {
216
+ valid = false
217
+ if (configuration.assetsFiles.isEmpty()) {
218
+ valid = true
219
+ validFile = this
220
+ } else {
221
+ configuration.assetsFiles.forEach { file ->
222
+ if (this .absolutePath.normalizePath().endsWith(" ${File .separator}$file " .normalizePath())
223
+ || (file.contains(" *." )
224
+ && this .absolutePath.normalizePath().endsWith(file.replace(" *" ," " )))) {
225
+ valid = true
226
+ validFile = this
227
+ }
228
+ }
229
+ }
230
+ }
231
+ if (configuration.debug && excludedForAssets().not ()) {
232
+ println (if (valid) validFile?.getContent() else " " )
233
+ }
234
+ return if (valid) AssetsFile (validFile!! , sourceFolder, configuration.name) else null
235
+ }
236
+
164
237
fun Project.absolutePath (): String = this .file(wrapperWindows).absolutePath.replace(
165
238
wrapperWindows,
166
239
emptyChar
0 commit comments