From c152d662be9f4cba185860ed5a7596a8ba5b0785 Mon Sep 17 00:00:00 2001 From: simsun Date: Thu, 16 Feb 2017 00:36:32 +0800 Subject: [PATCH] style(plugin): clean up groovy code --- .gitignore | 1 - AndResGuard-example/gradle.properties | 16 ++++++++++++++ .../gradle/AndResGuardExtension.groovy | 6 ++--- .../tencent/gradle/AndResGuardPlugin.groovy | 5 ++--- .../com/tencent/gradle/AndResGuardTask.groovy | 22 +++++++++---------- .../com/tencent/gradle/BuildInfo.groovy | 4 ++-- .../tencent/gradle/ExecutorExtension.groovy | 14 ++++++------ gradle.properties | 18 +++++++++++++++ 8 files changed, 59 insertions(+), 27 deletions(-) create mode 100644 AndResGuard-example/gradle.properties create mode 100644 gradle.properties diff --git a/.gitignore b/.gitignore index e954af23..a58a12e6 100644 --- a/.gitignore +++ b/.gitignore @@ -37,5 +37,4 @@ local_repo tool_output/outapk node_modules/ -**/gradle.properties classes diff --git a/AndResGuard-example/gradle.properties b/AndResGuard-example/gradle.properties new file mode 100644 index 00000000..aca13db1 --- /dev/null +++ b/AndResGuard-example/gradle.properties @@ -0,0 +1,16 @@ +## Project-wide Gradle settings. +# +# For more details on how to configure your build environment visit +# http://www.gradle.org/docs/current/userguide/build_environment.html +# +# Specifies the JVM arguments used for the daemon process. +# The setting is particularly useful for tweaking memory settings. +# Default value: -Xmx1024m -XX:MaxPermSize=256m +# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 +# +# When configured, Gradle will run in incubating parallel mode. +# This option should only be used with decoupled projects. More details, visit +# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects +# org.gradle.parallel=true +#Tue Sep 06 04:33:31 CST 2016 +org.gradle.jvmargs=-Xmx2584M -DsocksProxyHost=127.0.0.1 -DsocksProxyPort=18030 diff --git a/AndResGuard-gradle-plugin/src/main/groovy/com/tencent/gradle/AndResGuardExtension.groovy b/AndResGuard-gradle-plugin/src/main/groovy/com/tencent/gradle/AndResGuardExtension.groovy index 4c8fd753..b07480c7 100644 --- a/AndResGuard-gradle-plugin/src/main/groovy/com/tencent/gradle/AndResGuardExtension.groovy +++ b/AndResGuard-gradle-plugin/src/main/groovy/com/tencent/gradle/AndResGuardExtension.groovy @@ -6,7 +6,7 @@ package com.tencent.gradle * @author sim sun (sunsj1231@gmail.com) */ -public class AndResGuardExtension { +class AndResGuardExtension { File mappingFile boolean use7zip @@ -16,7 +16,7 @@ public class AndResGuardExtension { Iterable whiteList Iterable compressFilePattern - public AndResGuardExtension() { + AndResGuardExtension() { use7zip = false useSign = false metaName = "META-INF" @@ -55,7 +55,7 @@ public class AndResGuardExtension { } @Override - public String toString() { + String toString() { """| use7zip = ${use7zip} | useSign = ${useSign} | metaName = ${metaName} diff --git a/AndResGuard-gradle-plugin/src/main/groovy/com/tencent/gradle/AndResGuardPlugin.groovy b/AndResGuard-gradle-plugin/src/main/groovy/com/tencent/gradle/AndResGuardPlugin.groovy index 12caf521..e2632650 100644 --- a/AndResGuard-gradle-plugin/src/main/groovy/com/tencent/gradle/AndResGuardPlugin.groovy +++ b/AndResGuard-gradle-plugin/src/main/groovy/com/tencent/gradle/AndResGuardPlugin.groovy @@ -12,7 +12,7 @@ import org.gradle.api.Project class AndResGuardPlugin implements Plugin { @Override - public void apply(Project project) { + void apply(Project project) { project.apply plugin: 'com.google.osdetector' project.extensions.create('andResGuard', AndResGuardExtension) project.extensions.add("sevenzip", new ExecutorExtension("sevenzip")) @@ -35,8 +35,7 @@ class AndResGuardPlugin implements Plugin { createTask(project, flavorName) } - def ExecutorExtension sevenzip = project.extensions.findByName("sevenzip") - sevenzip.loadArtifact(project) + project.extensions.findByName("sevenzip").loadArtifact(project) } } diff --git a/AndResGuard-gradle-plugin/src/main/groovy/com/tencent/gradle/AndResGuardTask.groovy b/AndResGuard-gradle-plugin/src/main/groovy/com/tencent/gradle/AndResGuardTask.groovy index c14270ab..eeea1350 100644 --- a/AndResGuard-gradle-plugin/src/main/groovy/com/tencent/gradle/AndResGuardTask.groovy +++ b/AndResGuard-gradle-plugin/src/main/groovy/com/tencent/gradle/AndResGuardTask.groovy @@ -12,8 +12,8 @@ import org.gradle.api.tasks.TaskAction * * @author Sim Sun (sunsj1231@gmail.com) */ -public class AndResGuardTask extends DefaultTask { - def AndResGuardExtension configuration +class AndResGuardTask extends DefaultTask { + AndResGuardExtension configuration def android def buildConfigs = [] @@ -43,7 +43,7 @@ public class AndResGuardTask extends DefaultTask { } } - static def isTargetFlavor(variantName, flavors, buildType) { + static isTargetFlavor(variantName, flavors, buildType) { if (flavors.size() > 0) { String flavor = flavors.get(0).name return variantName.equalsIgnoreCase(flavor) || variantName.equalsIgnoreCase([flavor, buildType].join("")) @@ -51,7 +51,7 @@ public class AndResGuardTask extends DefaultTask { return false } - static def useFolder(file) { + static useFolder(file) { //remove .apk from filename def fileName = file.name[0..-5] return "${file.parent}/AndResGuard_${fileName}/" @@ -62,17 +62,17 @@ public class AndResGuardTask extends DefaultTask { } @TaskAction - def run() { + run() { project.logger.info("[AndResGuard] configuartion:$configuration") project.logger.info("[AndResGuard] BuildConfigs:$buildConfigs") - def ExecutorExtension sevenzip = project.extensions.findByName("sevenzip") as ExecutorExtension + ExecutorExtension sevenzip = project.extensions.findByName("sevenzip") as ExecutorExtension buildConfigs.each { config -> - def String absPath = config.file.getAbsolutePath() + String absPath = config.file.getAbsolutePath() def signConfig = config.signConfig - def String packageName = config.packageName - ArrayList whiteListFullName = new ArrayList<>(); + String packageName = config.packageName + ArrayList whiteListFullName = new ArrayList<>() configuration.whiteList.each { res -> if (res.startsWith("R")) { whiteListFullName.add(packageName + "." + res) @@ -91,7 +91,7 @@ public class AndResGuardTask extends DefaultTask { .setSevenZipPath(sevenzip.path) .setOutBuilder(useFolder(config.file)) .setApkPath(absPath) - .setUseSign(configuration.useSign); + .setUseSign(configuration.useSign) if (configuration.useSign) { if (signConfig == null) { @@ -102,7 +102,7 @@ public class AndResGuardTask extends DefaultTask { .setStorealias(signConfig.keyAlias) .setStorepass(signConfig.storePassword) } - InputParam inputParam = builder.create(); + InputParam inputParam = builder.create() Main.gradleRun(inputParam) } } diff --git a/AndResGuard-gradle-plugin/src/main/groovy/com/tencent/gradle/BuildInfo.groovy b/AndResGuard-gradle-plugin/src/main/groovy/com/tencent/gradle/BuildInfo.groovy index a30ac275..ec06182f 100644 --- a/AndResGuard-gradle-plugin/src/main/groovy/com/tencent/gradle/BuildInfo.groovy +++ b/AndResGuard-gradle-plugin/src/main/groovy/com/tencent/gradle/BuildInfo.groovy @@ -9,14 +9,14 @@ class BuildInfo { def signConfig def packageName - public BuildInfo(file, sign, packageName) { + BuildInfo(file, sign, packageName) { this.file = file this.signConfig = sign this.packageName = packageName } @Override - public String toString() { + String toString() { """| file = ${file} | packageName = ${packageName} """.stripMargin() diff --git a/AndResGuard-gradle-plugin/src/main/groovy/com/tencent/gradle/ExecutorExtension.groovy b/AndResGuard-gradle-plugin/src/main/groovy/com/tencent/gradle/ExecutorExtension.groovy index 1700befb..d5a01e77 100644 --- a/AndResGuard-gradle-plugin/src/main/groovy/com/tencent/gradle/ExecutorExtension.groovy +++ b/AndResGuard-gradle-plugin/src/main/groovy/com/tencent/gradle/ExecutorExtension.groovy @@ -6,19 +6,19 @@ import org.gradle.api.Project import org.gradle.api.artifacts.Configuration import org.gradle.api.artifacts.Dependency -public class ExecutorExtension implements Named { +class ExecutorExtension implements Named { private final String name private String artifact private String path - public ExecutorExtension(String name) { + ExecutorExtension(String name) { this.name = name } @Override - public String getName() { + String getName() { return name } @@ -26,22 +26,22 @@ public class ExecutorExtension implements Named { * Specifies an artifact spec for downloading the executable from * repositories. spec format: '::' */ - public setArtifact(String spec) { + def setArtifact(String spec) { this.artifact = spec } /** * Specifies a local path. */ - public setPath(String path) { + def setPath(String path) { this.path = path } - public String getArtifact() { + String getArtifact() { return artifact } - public String getPath() { + String getPath() { return path } diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 00000000..89e0d99e --- /dev/null +++ b/gradle.properties @@ -0,0 +1,18 @@ +# Project-wide Gradle settings. + +# IDE (e.g. Android Studio) users: +# Gradle settings configured through the IDE *will override* +# any settings specified in this file. + +# For more details on how to configure your build environment visit +# http://www.gradle.org/docs/current/userguide/build_environment.html + +# Specifies the JVM arguments used for the daemon process. +# The setting is particularly useful for tweaking memory settings. +# Default value: -Xmx10248m -XX:MaxPermSize=256m +# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 + +# When configured, Gradle will run in incubating parallel mode. +# This option should only be used with decoupled projects. More details, visit +# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects +# org.gradle.parallel=true