diff --git a/README-CN.md b/README-CN.md index 6af73af..52f9b40 100644 --- a/README-CN.md +++ b/README-CN.md @@ -41,7 +41,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.smallsoho.mobcase:McImage:0.0.4' + classpath 'com.smallsoho.mobcase:McImage:0.1.0' } } ``` diff --git a/README.md b/README.md index ac9d2cb..e56dec2 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.smallsoho.mobcase:McImage:0.0.4' + classpath 'com.smallsoho.mobcase:McImage:0.1.0' } } ``` diff --git a/bintray.gradle b/bintray.gradle index 0d940bc..1fd78b7 100644 --- a/bintray.gradle +++ b/bintray.gradle @@ -4,7 +4,7 @@ apply plugin: 'com.jfrog.bintray' def siteUrl = 'https://github.com/Aweme/McImage' def gitUrl = 'https://github.com/Aweme/McImage.git' group = "com.smallsoho.mobcase" -version = "0.0.4" +version = "0.1.0" Properties properties = new Properties() properties.load(project.rootProject.file('local.properties').newDataInputStream()) diff --git a/src/main/groovy/com/smallsoho/mcplugin/image/ImagePlugin.groovy b/src/main/groovy/com/smallsoho/mcplugin/image/ImagePlugin.groovy index ec601c8..c47a166 100644 --- a/src/main/groovy/com/smallsoho/mcplugin/image/ImagePlugin.groovy +++ b/src/main/groovy/com/smallsoho/mcplugin/image/ImagePlugin.groovy @@ -36,13 +36,13 @@ class ImagePlugin implements Plugin { for (int index = 0; index < taskNames.size(); ++index) { def taskName = taskNames[index] if (taskName.contains("assemble") || taskName.contains("resguard")) { + if (taskName.toLowerCase().endsWith("debug") && + taskName.toLowerCase().contains("debug")) { + isDebugTask = true + } isContainAssembleTask = true break } - if (taskName.endsWith("Debug") && taskName.contains("Debug")) { - isDebugTask = true - break - } } //export build clean @@ -66,49 +66,55 @@ class ImagePlugin implements Plugin { //debug enable if (isDebugTask && !mConfig.enableWhenDebug) { + println 'Debug not run !' return } def processResourceTask = project.tasks.findByName("process${variant.name.capitalize()}Resources") def mcPicPlugin = "McImage${variant.name.capitalize()}" - project.task(mcPicPlugin) << { + project.task(mcPicPlugin) { + doLast { - String resPath = "${project.projectDir}/build/intermediates/res/${imgDir}/" + println '---- McImage Plugin Start ----' - def dir = new File("${resPath}") + String resPath = "${project.projectDir}/build/intermediates/res/${imgDir}/" - ArrayList bigImgList = new ArrayList<>() + def dir = new File("${resPath}") - dir.eachDir() { channelDir -> - channelDir.eachDir { drawDir -> - def file = new File("${drawDir}") - if (file.name.contains('drawable') || file.name.contains('mipmap')) { - file.eachFile { imgFile -> + ArrayList bigImgList = new ArrayList<>() - if (mConfig.isCheck && ImageUtil.isBigImage(imgFile, mConfig.maxSize)) { - bigImgList.add(file.getPath() + file.getName()) - } - if (mConfig.isCompress) { - CompressUtil.compressImg(imgFile) - } - if (mConfig.isWebpConvert) { - WebpUtils.securityFormatWebp(imgFile, mConfig, mProject) - } + dir.eachDir() { channelDir -> + channelDir.eachDir { drawDir -> + def file = new File("${drawDir}") + if (file.name.contains('drawable') || file.name.contains('mipmap')) { + file.eachFile { imgFile -> + if (mConfig.isCheck && ImageUtil.isBigImage(imgFile, mConfig.maxSize)) { + bigImgList.add(file.getPath() + file.getName()) + } + if (mConfig.isCompress) { + CompressUtil.compressImg(imgFile) + } + if (mConfig.isWebpConvert) { + WebpUtils.securityFormatWebp(imgFile, mConfig, mProject) + } + + } } } } - } - if (bigImgList.size() != 0) { - StringBuffer stringBuffer = new StringBuffer("You have big Img!!!! \n") - for (int i = 0; i < bigImgList.size(); i++) { - stringBuffer.append(bigImgList.get(i)) - stringBuffer.append("\n") + if (bigImgList.size() != 0) { + StringBuffer stringBuffer = new StringBuffer("You have big Img!!!! \n") + for (int i = 0; i < bigImgList.size(); i++) { + stringBuffer.append(bigImgList.get(i)) + stringBuffer.append("\n") + } + throw new GradleException(stringBuffer.toString()) } - throw new GradleException(stringBuffer.toString()) - } + println '---- McImage Plugin End ----' + } } //inject plugin