Skip to content

Commit

Permalink
style(plugin): clean up groovy code
Browse files Browse the repository at this point in the history
  • Loading branch information
simpleton committed Feb 15, 2017
1 parent 6cc6473 commit c152d66
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 27 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,4 @@ local_repo
tool_output/outapk

node_modules/
**/gradle.properties
classes
16 changes: 16 additions & 0 deletions AndResGuard-example/gradle.properties
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package com.tencent.gradle
* @author sim sun ([email protected])
*/

public class AndResGuardExtension {
class AndResGuardExtension {

File mappingFile
boolean use7zip
Expand All @@ -16,7 +16,7 @@ public class AndResGuardExtension {
Iterable<String> whiteList
Iterable<String> compressFilePattern

public AndResGuardExtension() {
AndResGuardExtension() {
use7zip = false
useSign = false
metaName = "META-INF"
Expand Down Expand Up @@ -55,7 +55,7 @@ public class AndResGuardExtension {
}

@Override
public String toString() {
String toString() {
"""| use7zip = ${use7zip}
| useSign = ${useSign}
| metaName = ${metaName}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import org.gradle.api.Project
class AndResGuardPlugin implements Plugin<Project> {

@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"))
Expand All @@ -35,8 +35,7 @@ class AndResGuardPlugin implements Plugin<Project> {
createTask(project, flavorName)
}

def ExecutorExtension sevenzip = project.extensions.findByName("sevenzip")
sevenzip.loadArtifact(project)
project.extensions.findByName("sevenzip").loadArtifact(project)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import org.gradle.api.tasks.TaskAction
*
* @author Sim Sun ([email protected])
*/
public class AndResGuardTask extends DefaultTask {
def AndResGuardExtension configuration
class AndResGuardTask extends DefaultTask {
AndResGuardExtension configuration
def android
def buildConfigs = []

Expand Down Expand Up @@ -43,15 +43,15 @@ 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(""))
}
return false
}

static def useFolder(file) {
static useFolder(file) {
//remove .apk from filename
def fileName = file.name[0..-5]
return "${file.parent}/AndResGuard_${fileName}/"
Expand All @@ -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<String> whiteListFullName = new ArrayList<>();
String packageName = config.packageName
ArrayList<String> whiteListFullName = new ArrayList<>()
configuration.whiteList.each { res ->
if (res.startsWith("R")) {
whiteListFullName.add(packageName + "." + res)
Expand All @@ -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) {
Expand All @@ -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)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,42 @@ 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
}

/**
* Specifies an artifact spec for downloading the executable from
* repositories. spec format: '<groupId>:<artifactId>:<version>'
*/
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
}

Expand Down
18 changes: 18 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit c152d66

Please sign in to comment.