diff --git a/example/build.gradle b/example/build.gradle index f492f16..dd0d626 100644 --- a/example/build.gradle +++ b/example/build.gradle @@ -18,6 +18,9 @@ android { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + manifestPlaceholders = [ + app_icon: "@mipmap/used_in_gradle", + ] } } dataBinding { diff --git a/example/src/main/res/mipmap-hdpi/unused_in_gradle.png b/example/src/main/res/mipmap-hdpi/unused_in_gradle.png new file mode 100644 index 0000000..a2f5908 Binary files /dev/null and b/example/src/main/res/mipmap-hdpi/unused_in_gradle.png differ diff --git a/example/src/main/res/mipmap-hdpi/used_in_gradle.png b/example/src/main/res/mipmap-hdpi/used_in_gradle.png new file mode 100644 index 0000000..a2f5908 Binary files /dev/null and b/example/src/main/res/mipmap-hdpi/used_in_gradle.png differ diff --git a/example/src/main/res/mipmap-mdpi/used_in_gradle.png b/example/src/main/res/mipmap-mdpi/used_in_gradle.png new file mode 100644 index 0000000..ff10afd Binary files /dev/null and b/example/src/main/res/mipmap-mdpi/used_in_gradle.png differ diff --git a/example/src/main/res/mipmap-xhdpi/used_in_gradle.png b/example/src/main/res/mipmap-xhdpi/used_in_gradle.png new file mode 100644 index 0000000..dcd3cd8 Binary files /dev/null and b/example/src/main/res/mipmap-xhdpi/used_in_gradle.png differ diff --git a/example/src/main/res/mipmap-xxhdpi/used_in_gradle.png b/example/src/main/res/mipmap-xxhdpi/used_in_gradle.png new file mode 100644 index 0000000..8ca12fe Binary files /dev/null and b/example/src/main/res/mipmap-xxhdpi/used_in_gradle.png differ diff --git a/example/src/main/res/mipmap-xxxhdpi/used_in_gradle.png b/example/src/main/res/mipmap-xxxhdpi/used_in_gradle.png new file mode 100644 index 0000000..b824ebd Binary files /dev/null and b/example/src/main/res/mipmap-xxxhdpi/used_in_gradle.png differ diff --git a/plugin/src/main/groovy/com/github/konifar/gradle/remover/remover/AbstractRemover.groovy b/plugin/src/main/groovy/com/github/konifar/gradle/remover/remover/AbstractRemover.groovy index fc7497d..9c68a9f 100644 --- a/plugin/src/main/groovy/com/github/konifar/gradle/remover/remover/AbstractRemover.groovy +++ b/plugin/src/main/groovy/com/github/konifar/gradle/remover/remover/AbstractRemover.groovy @@ -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 */ @@ -23,8 +25,6 @@ abstract class AbstractRemover { */ final SearchPattern.Type type - final List moduleSrcDirs = [] - String scanTargetFileTexts = "" // Extension settings @@ -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 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 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