Skip to content

Commit

Permalink
Merge pull request #26 from konifar/search_gradle_file
Browse files Browse the repository at this point in the history
Check gradle files too
  • Loading branch information
konifar authored May 19, 2018
2 parents 0f9018a + 09e0341 commit 1e87e12
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 23 deletions.
3 changes: 3 additions & 0 deletions example/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ android {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
manifestPlaceholders = [
app_icon: "@mipmap/used_in_gradle",
]
}
}
dataBinding {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import org.gradle.internal.impldep.com.google.common.annotations.VisibleForTesti

abstract class AbstractRemover {

private static final def FILE_TYPE_FILTER = ~/(.*\.xml)|(.*\.kt)|(.*\.java)|(.*\.gradle)/

/**
* directory/file name to find files like drawable, dimen, string
*/
Expand All @@ -23,8 +25,6 @@ abstract class AbstractRemover {
*/
final SearchPattern.Type type

final List<String> moduleSrcDirs = []

String scanTargetFileTexts = ""

// Extension settings
Expand Down Expand Up @@ -52,39 +52,50 @@ abstract class AbstractRemover {
this.dryRun = extension.dryRun
this.excludeNames = extension.excludeNames

moduleSrcDirs.clear()
moduleSrcDirs.addAll(
project.rootProject.allprojects
.findAll { it.name != project.rootProject.name }
.collect { "${it.projectDir.path}/src" }
)
List<String> moduleSrcDirs = project.rootProject.allprojects
.findAll { it.name != project.rootProject.name }
.collect { "${it.projectDir.path}" }

scanTargetFileTexts = createScanTargetFileTexts(moduleSrcDirs)

StringBuilder stringBuilder = new StringBuilder()
moduleSrcDirs.
collect { new File(it) }.
findAll { it.exists() }.
each { srcDirFile ->
srcDirFile.eachDirRecurse { dir ->
dir.eachFileMatch(~/(.*\.xml)|(.*\.kt)|(.*\.java)/) { f ->
stringBuilder.append(f.text.replaceAll('\n', '').replaceAll(' ', ''))
}
}
}
scanTargetFileTexts = stringBuilder.toString()

ColoredLogger.log "[${fileType}] ======== Start ${fileType} checking ========"

moduleSrcDirs.each {
String moduleSrcName = it - "${project.rootProject.projectDir.path}/" - "/src"
String moduleSrcName = it - "${project.rootProject.projectDir.path}/"
ColoredLogger.log "[${fileType}] ${moduleSrcName}"

File resDirFile = new File("${it}/main/res")
File resDirFile = new File("${it}/src/main/res")
if (resDirFile.exists()) {
removeEach(resDirFile)
}
}
}

private static String createScanTargetFileTexts(List<String> moduleSrcDirs) {
StringBuilder stringBuilder = new StringBuilder()

moduleSrcDirs.collect { new File(it) }
.findAll { it.exists() }
.each { srcDirFile ->
srcDirFile.eachFileMatch(FILE_TYPE_FILTER) { f ->
stringBuilder.append(f.text.replaceAll('\n', '').replaceAll(' ', ''))
}
}

moduleSrcDirs
.collect { new File("${it}/src") }
.findAll { it.exists() }
.each { srcDirFile ->
srcDirFile.eachDirRecurse { dir ->
dir.eachFileMatch(FILE_TYPE_FILTER) { f ->
stringBuilder.append(f.text.replaceAll('\n', '').replaceAll(' ', ''))
}
}
}

return stringBuilder.toString()
}

@VisibleForTesting
static boolean isPatternMatched(String fileText, GString pattern) {
return fileText =~ pattern
Expand Down

0 comments on commit 1e87e12

Please sign in to comment.