├── .gitignore ├── .travis.yml ├── README.md ├── build.gradle ├── build.publish.gradle ├── example ├── build.gradle └── gradle.properties.sample ├── gradle.properties.sample ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── src ├── main ├── groovy │ └── org │ │ └── quanqi │ │ └── pgyer │ │ └── gradle │ │ └── plugins │ │ ├── Apk.groovy │ │ ├── ApkTarget.groovy │ │ ├── Pgyer.groovy │ │ ├── PgyerAllUploadTask.groovy │ │ ├── PgyerExtension.groovy │ │ ├── PgyerTask.groovy │ │ └── PgyerUserUploadTask.groovy └── resources │ └── META-INF │ └── gradle-plugins │ └── org.quanqi.pgyer.properties └── test ├── groovy └── com │ └── deploygate │ └── gradle │ └── plugins │ ├── ApkTest.groovy │ └── ApplyPluginTest.groovy └── project └── build.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | # built application files 2 | *.apk 3 | 4 | # generated files 5 | bin/ 6 | gen/ 7 | out/ 8 | build/ 9 | 10 | # Local configuration file (sdk path, etc) 11 | local.properties 12 | 13 | # Eclipse project files 14 | .classpath 15 | .project 16 | 17 | # Windows thumbnail db 18 | .DS_Store 19 | Thumbs.db 20 | 21 | # Proguard folder generated by Eclipse 22 | proguard/ 23 | 24 | # IDEA/Android Studio project files, because 25 | # the project can be imported from settings.gradle 26 | .idea 27 | *.iml 28 | 29 | # Old-style IDEA project files 30 | *.ipr 31 | *.iws 32 | 33 | # Gradle cache 34 | .gradle 35 | 36 | # Sandbox stuff 37 | _sandbox 38 | 39 | # Backup files 40 | *~ 41 | *.bak 42 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | jdk: 3 | - openjdk7 4 | 5 | script: 6 | - ./gradlew build test 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This is the Pugongying plugin for the Gradle. 2 | This plugin, you can use the Pugongying API from Gradle easily. 3 | 4 | 5 | ## Usage 6 | ### Tasks 7 | * uploadPgyer - Uploads the APK file. Also updates the distribution specified by distributionKey if configured 8 | * uploadPgyer[FlavorName] - Upload an APK file of [FlavorName] 9 | 10 | ### Edit build.gradle 11 | 12 | ``` 13 | buildscript { 14 | repositories { 15 | jcenter() 16 | } 17 | 18 | dependencies { 19 | classpath 'org.quanqi:pgyer:0.1.2' 20 | } 21 | } 22 | apply plugin: 'org.quanqi.pgyer' 23 | 24 | pgyer { 25 | _api_key = "" 26 | // (必填)应用安装方式,值为(2,3)。2:密码安装,3:邀请安装 27 | buildInstallType = "" 28 | // (必填) 设置App安装密码 29 | buildPassword = "" 30 | } 31 | 32 | apks { 33 | release { 34 | sourceFile = file("[apk1 file path]") 35 | } 36 | } 37 | } 38 | ``` 39 | 40 | ### Run 41 | 42 | ``` 43 | $ ./gradlew uploadPgyer 44 | ``` 45 | 46 | ## License 47 | Copyright 2012-2014 DeployGate, henteko 48 | Copyright 2015 Cindy, Jing Quanqi 49 | 50 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 51 | 52 | ``` 53 | http://www.apache.org/licenses/LICENSE-2.0 54 | ``` 55 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 56 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'groovy' 2 | apply plugin: 'maven' 3 | apply plugin: 'signing' 4 | 5 | group = 'org.quanqi' 6 | archivesBaseName = 'pgyer' 7 | version = '0.2' 8 | sourceCompatibility = 1.6 9 | 10 | repositories { 11 | mavenCentral() 12 | } 13 | 14 | dependencies { 15 | compile gradleApi() 16 | //groovy localGroovy() 17 | compile 'org.json:json:20090211' 18 | compile 'com.squareup.okhttp:okhttp:2.2.0' 19 | compile 'commons-lang:commons-lang:2.6' 20 | runtime 'com.squareup.okhttp:okhttp:2.2.0' 21 | 22 | compile 'com.squareup.okhttp:okhttp-urlconnection:2.2.0' 23 | } 24 | 25 | task javadocJar(type: Jar, dependsOn: groovydoc) { 26 | classifier = 'javadoc' 27 | from "${buildDir}/javadoc" 28 | } 29 | 30 | task sourcesJar(type: Jar) { 31 | from sourceSets.main.allSource 32 | classifier = 'sources' 33 | } 34 | 35 | artifacts { 36 | archives jar 37 | archives javadocJar 38 | archives sourcesJar 39 | } 40 | 41 | // local upload 42 | 43 | uploadArchives { 44 | repositories { 45 | mavenDeployer { 46 | repository(url: 'file://' + new File(System.getProperty('user.home'), '.m2/repository').absolutePath) 47 | } 48 | } 49 | } 50 | 51 | 52 | signing { 53 | required { gradle.taskGraph.hasTask("uploadArchives") && hasProperty('signing.keyId') } 54 | sign configurations.archives 55 | } 56 | 57 | //uploadArchives { 58 | // repositories { 59 | // mavenDeployer { 60 | // 61 | // beforeDeployment { deployment -> signing.signPom(deployment) } 62 | // 63 | // if (project.hasProperty('NEXUS_USERNAME')) { 64 | // snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots") { 65 | // authentication(userName: project.getProperty('NEXUS_USERNAME'), 66 | // password: project.getProperty('NEXUS_PASSWORD')) 67 | // } 68 | // 69 | // repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2") { 70 | // authentication(userName: project.getProperty('NEXUS_USERNAME'), 71 | // password: project.getProperty('NEXUS_PASSWORD')) 72 | // } 73 | // } 74 | // uniqueVersion = false 75 | // 76 | // pom.project { 77 | // 78 | // parent { 79 | // groupId 'org.sonatype.oss' 80 | // artifactId 'oss-parent' 81 | // version '7' 82 | // } 83 | // 84 | // name 'Gradle Pugongying Upload Plugin' 85 | // packaging 'jar' 86 | // description 'A plugin used for upload Pugongying apk.' 87 | // url 'https://github.com/dodocat/gradle-pgyer-plugin' 88 | // 89 | // scm { 90 | // url 'https://github.com/dodocat/gradle-pgyer-plugin' 91 | // connection 'scm:git:https://github.com/dodocat/gradle-pgyer-plugin.git' 92 | // developerConnection 'scm:git:https://github.com/dodocat/gradle-pgyer-plugin.git' 93 | // } 94 | // 95 | // licenses { 96 | // license { 97 | // name 'The Apache Software License, Version 2.0' 98 | // url 'http://www.apache.org/licenses/LICENSE-2.0.txt' 99 | // distribution 'repo' 100 | // } 101 | // } 102 | // 103 | // developers { 104 | // developer { 105 | // id 'dodocat' 106 | // name 'Cindy' 107 | // } 108 | // } 109 | // } 110 | // } 111 | // } 112 | //} 113 | -------------------------------------------------------------------------------- /build.publish.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'signing' 2 | apply plugin: 'maven' 3 | 4 | boolean validProperty(propertyName) { 5 | try { project.property(propertyName) != null } 6 | catch (MissingPropertyException) { false } 7 | } 8 | assert validProperty('signing.keyId'), 'properties for signing must be provided' 9 | assert validProperty('signing.secretKeyRingFile'), 'properties for signing must be provided' 10 | assert validProperty('sonatypeUsername'), 'properties for publish must be provided' 11 | assert validProperty('sonatypeFullname'), 'properties for publish must be provided' 12 | 13 | String askPassword(prompt) { 14 | "${System.console().readPassword(prompt)}" 15 | } 16 | ext.'signing.password' = askPassword("Enter password for PGP key ${property('signing.keyId')}: ") 17 | ext.'sonatypePassword' = askPassword("Enter password for ${sonatypeUsername}@oss.sonatype.org: ") 18 | 19 | signing { 20 | sign configurations.archives 21 | } 22 | 23 | uploadArchives { 24 | repositories.mavenDeployer { 25 | repository(url: 'https://oss.sonatype.org/service/local/staging/deploy/maven2/') { 26 | authentication(userName: sonatypeUsername, password: sonatypePassword) 27 | } 28 | beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } 29 | pom.project { 30 | name 'Gradle DeployGate Plugin' 31 | packaging 'jar' 32 | description project.description 33 | url 'https://github.com/DeployGate/gradle-deploygate-plugin' 34 | scm { 35 | url 'git@github.com:DeployGate/gradle-deploygate-plugin.git' 36 | connection 'scm:git:git@github.com:DeployGate/gradle-deploygate-plugin.git' 37 | developerConnection 'scm:git:git@github.com:DeployGate/gradle-deploygate-plugin.git' 38 | } 39 | licenses { 40 | license { 41 | name 'The Apache Software License, Version 2.0' 42 | url 'http://www.apache.org/licenses/LICENSE-2.0.txt' 43 | distribution 'repo' 44 | } 45 | } 46 | developers { 47 | developer { 48 | id sonatypeUsername 49 | name sonatypeFullname 50 | } 51 | } 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /example/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | jcenter() 4 | } 5 | 6 | dependencies { 7 | classpath 'com.deploygate:gradle:0.6.2' 8 | } 9 | } 10 | apply plugin: 'deploygate' 11 | 12 | deploygate { 13 | userName = ownerName 14 | token = myToken 15 | 16 | apks { 17 | example { 18 | sourceFile = file("./DeployGateSample.apk") 19 | 20 | //Below is optional 21 | message = "example upload deploygate sample apk" 22 | visibility = "public" // public or private 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /example/gradle.properties.sample: -------------------------------------------------------------------------------- 1 | ownerName=yourName 2 | myToken=yourToken 3 | 4 | // set proxy 5 | systemProp.https.proxyHost=proxyHost 6 | systemProp.https.proxyPort=proxyPort 7 | -------------------------------------------------------------------------------- /gradle.properties.sample: -------------------------------------------------------------------------------- 1 | signing.keyId=keyID 2 | signing.secretKeyRingFile=filePath 3 | sonatypeUsername=yourName 4 | sonatypeFullname=yourFullName 5 | 6 | jdkVersion=1.7 7 | projectUrl=https://github.com/DeployGate/gradle-deploygate-plugin 8 | github=git@github.com:DeployGate/gradle-deploygate-plugin.git 9 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dodocat/pgyer/107bce47137876b41b8923a9e80bc03e3c913242/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Jan 14 23:10:25 JST 2014 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" >&- 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" >&- 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /src/main/groovy/org/quanqi/pgyer/gradle/plugins/Apk.groovy: -------------------------------------------------------------------------------- 1 | package org.quanqi.pgyer.gradle.plugins 2 | 3 | import org.gradle.api.Project 4 | 5 | class Apk { 6 | String name 7 | File file 8 | 9 | /** 10 | * (ipa上传时为必填) 填写发布范围,值为(1,2,3),1:企业发布,2:直接发布,3:只有我安装 11 | */ 12 | int publishRange 13 | /** 14 | * (选填) 是否发布到广场,值为(1,2),1:发布到广场,2:不发布到广场。默认为不发布到广场 15 | */ 16 | int isPublishToPublic 17 | 18 | /** 19 | * (当用户上传的文件为开发者签名的ipa并且publishRange为1时,为必填。否则为选填) 设置App安装密码,为空或不传则应用无下载密码 20 | */ 21 | String password 22 | 23 | Apk(String name, File file, int publishRange, int isPublishToPublic, String password) { 24 | this.name = name 25 | this.file = file 26 | this.publishRange = publishRange 27 | this.isPublishToPublic = isPublishToPublic 28 | this.password = password 29 | } 30 | 31 | 32 | public HashMap getParams() { 33 | HashMap params = new HashMap() 34 | if (publishRange > 0) { 35 | params.put("publishRange", publishRange as String) 36 | } 37 | if(isPublishToPublic > 0) { 38 | params.put("isPublishToPublic", isPublishToPublic as String) 39 | } 40 | 41 | return params 42 | } 43 | 44 | public static List getApks(Project project, String searchApkName = "") { 45 | List apks = [] 46 | for (_apk in project.deploygateApks) { 47 | String name = _apk.name 48 | if(searchApkName != "" && searchApkName != name) continue 49 | 50 | File file = null 51 | 52 | Apk apk = new Apk(name, file, 0, 0, null); 53 | 54 | if(_apk.hasProperty("sourceFile") && _apk.sourceFile != null) { 55 | apk.file = _apk.sourceFile 56 | } 57 | if (_apk.hasProperty("publishRange") && _apk.publishRange > 0) { 58 | apk.publishRange = _apk.publishRange 59 | } 60 | if(_apk.hasProperty("isPublishToPublic")) { 61 | apk.isPublishToPublic = _apk.isPublishToPublic 62 | } 63 | apks.add(apk) 64 | } 65 | return apks 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/main/groovy/org/quanqi/pgyer/gradle/plugins/ApkTarget.groovy: -------------------------------------------------------------------------------- 1 | package org.quanqi.pgyer.gradle.plugins 2 | 3 | import org.gradle.api.Named 4 | import org.gradle.api.internal.project.ProjectInternal 5 | 6 | class ApkTarget implements Named { 7 | String name 8 | ProjectInternal target 9 | File sourceFile 10 | 11 | String distributionKey 12 | /** 13 | * (ipa上传时为必填) 填写发布范围,值为(1,2,3),1:企业发布,2:直接发布,3:只有我安装 14 | */ 15 | int publishRange 16 | /** 17 | * (选填) 是否发布到广场,值为(1,2),1:发布到广场,2:不发布到广场。默认为不发布到广场 18 | */ 19 | int isPublishToPublic 20 | 21 | public ApkTarget(String name) { 22 | super() 23 | this.name = name 24 | this.target = target 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/groovy/org/quanqi/pgyer/gradle/plugins/Pgyer.groovy: -------------------------------------------------------------------------------- 1 | package org.quanqi.pgyer.gradle.plugins 2 | 3 | import org.gradle.api.Plugin 4 | import org.gradle.api.Project 5 | import org.apache.commons.lang.WordUtils 6 | 7 | class Pgyer implements Plugin { 8 | void apply(Project project) { 9 | def apks = project.container(ApkTarget) { 10 | String apkName = WordUtils.capitalize(it.toString()) 11 | def userTask = project.task("uploadPgyer${apkName}", type: PgyerUserUploadTask) 12 | userTask.group = 'Pgyer' 13 | userTask.description = "Upload an APK file of ${apkName}" 14 | userTask.apkName = apkName 15 | 16 | project.extensions.create(it, ApkTarget, apkName) 17 | } 18 | 19 | def pgyer = new PgyerExtension(apks) 20 | project.convention.plugins.deploygate = pgyer 21 | project.extensions.pgyer = pgyer 22 | 23 | def apkUpload = project.task('uploadPgyer', type: PgyerAllUploadTask) 24 | apkUpload.group = 'Pgyer' 25 | apkUpload.description = 'Uploads the APK file. Also updates the distribution specified by distributionKey if configured' 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/groovy/org/quanqi/pgyer/gradle/plugins/PgyerAllUploadTask.groovy: -------------------------------------------------------------------------------- 1 | package org.quanqi.pgyer.gradle.plugins 2 | 3 | import org.gradle.api.tasks.TaskAction 4 | 5 | class PgyerAllUploadTask extends PgyerTask { 6 | @TaskAction 7 | def uploadDeployGate() { 8 | List apks = Apk.getApks(project) 9 | super.upload(project, apks) 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/groovy/org/quanqi/pgyer/gradle/plugins/PgyerExtension.groovy: -------------------------------------------------------------------------------- 1 | package org.quanqi.pgyer.gradle.plugins 2 | 3 | import org.gradle.api.NamedDomainObjectContainer 4 | 5 | public class PgyerExtension { 6 | final private NamedDomainObjectContainer deploygateApks 7 | String _api_key 8 | /** 9 | * (必填)应用安装方式,值为(2,3)。2:密码安装,3:邀请安装 10 | */ 11 | String buildInstallType 12 | /** 13 | * (必填) 设置App安装密码 14 | */ 15 | String buildPassword 16 | 17 | public PgyerExtension(NamedDomainObjectContainer apks) { 18 | deploygateApks = apks 19 | } 20 | 21 | public apks(Closure closure) { 22 | deploygateApks.configure(closure) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/groovy/org/quanqi/pgyer/gradle/plugins/PgyerTask.groovy: -------------------------------------------------------------------------------- 1 | package org.quanqi.pgyer.gradle.plugins 2 | 3 | import com.squareup.okhttp.MediaType 4 | import com.squareup.okhttp.MultipartBuilder 5 | import com.squareup.okhttp.OkHttpClient 6 | import com.squareup.okhttp.Request 7 | import com.squareup.okhttp.RequestBody 8 | import com.squareup.okhttp.Response 9 | import org.gradle.api.DefaultTask 10 | import org.gradle.api.GradleException 11 | import org.gradle.api.Project 12 | import org.json.JSONObject 13 | 14 | import java.util.concurrent.TimeUnit 15 | 16 | class PgyerTask extends DefaultTask { 17 | private final String API_END_POINT = "http://www.pgyer.com/apiv2" 18 | 19 | void upload(Project project, List apks) { 20 | String endPoint = getEndPoint(project) 21 | 22 | HashMap result = httpPost(endPoint, apks) 23 | for (Apk apk in apks) { 24 | JSONObject json = result.get(apk.name) 25 | errorHandling(apk, json) 26 | println "${apk.name} result: ${json.toString()}" 27 | } 28 | } 29 | 30 | private void errorHandling(Apk apk, JSONObject json) { 31 | print(json) 32 | } 33 | 34 | private String getEndPoint(Project project) { 35 | String _api_key = project.pgyer._api_key 36 | String buildInstallType = project.pgyer.buildInstallType 37 | String buildPassword = project.pgyer.buildPassword 38 | if (_api_key == null 39 | || buildInstallType == null 40 | || buildPassword == null) { 41 | throw new GradleException("apiKey, buildInstallType or buildPassword is missing") 42 | } 43 | String endPoint = API_END_POINT + "/app/upload" 44 | return endPoint 45 | } 46 | 47 | private HashMap httpPost(String endPoint, List apks) { 48 | HashMap result = new HashMap() 49 | OkHttpClient client = new OkHttpClient(); 50 | client.setConnectTimeout(10, TimeUnit.SECONDS); 51 | client.setReadTimeout(60, TimeUnit.SECONDS); 52 | 53 | for (Apk apk in apks) { 54 | MultipartBuilder multipartBuilder = new MultipartBuilder() 55 | .type(MultipartBuilder.FORM) 56 | 57 | 58 | multipartBuilder.addFormDataPart("_api_key", new String(project.pgyer._api_key)) 59 | multipartBuilder.addFormDataPart("buildInstallType", new String(project.pgyer.buildInstallType)) 60 | multipartBuilder.addFormDataPart("buildPassword", new String(project.pgyer.buildPassword)) 61 | 62 | 63 | multipartBuilder.addFormDataPart("file", 64 | apk.file.name, 65 | RequestBody.create( 66 | MediaType.parse("application/vnd.android.package-archive"), 67 | apk.file) 68 | ) 69 | 70 | HashMap params = apk.getParams() 71 | for (String key : params.keySet()) { 72 | println("add part key: " + key + " value: " + params.get(key)) 73 | multipartBuilder.addFormDataPart(key, params.get(key)) 74 | } 75 | 76 | Request request = new Request.Builder().url(getEndPoint(project)). 77 | post(multipartBuilder.build()). 78 | build() 79 | 80 | Response response = client.newCall(request).execute(); 81 | 82 | if (response == null || response.body() == null) return null; 83 | InputStream is = response.body().byteStream(); 84 | BufferedReader reader = new BufferedReader(new InputStreamReader(is)) 85 | JSONObject json = new JSONObject(reader.readLine()) 86 | result.put(apk.name, json) 87 | is.close() 88 | } 89 | return result 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/main/groovy/org/quanqi/pgyer/gradle/plugins/PgyerUserUploadTask.groovy: -------------------------------------------------------------------------------- 1 | package org.quanqi.pgyer.gradle.plugins 2 | 3 | import org.gradle.api.tasks.TaskAction 4 | 5 | class PgyerUserUploadTask extends PgyerTask { 6 | String apkName 7 | @TaskAction 8 | def userUploadTasks() { 9 | List apks = Apk.getApks(project, apkName) 10 | Object.upload(project, apks) 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/gradle-plugins/org.quanqi.pgyer.properties: -------------------------------------------------------------------------------- 1 | implementation-class=org.quanqi.pgyer.gradle.plugins.Pgyer 2 | -------------------------------------------------------------------------------- /src/test/groovy/com/deploygate/gradle/plugins/ApkTest.groovy: -------------------------------------------------------------------------------- 1 | package com.deploygate.gradle.plugins 2 | 3 | import org.gradle.testfixtures.ProjectBuilder 4 | import org.junit.Test 5 | import org.quanqi.pgyer.gradle.plugins.Apk 6 | 7 | import static org.junit.Assert.assertTrue 8 | 9 | /** 10 | * Created by kenta.imai on 2014/11/25. 11 | */ 12 | class ApkTest { 13 | @Test 14 | public void apkTest() { 15 | String name = "name" 16 | File file = null 17 | String message = "test message" 18 | String distributionKey = "test distribution key" 19 | String releaseNote = "test release note" 20 | String visibility = "public" 21 | 22 | Apk apk = new Apk(name, file, message, distributionKey, releaseNote, visibility) 23 | checkApk(apk, name, file, message, distributionKey, releaseNote, visibility) 24 | checkParams(apk, message, distributionKey, releaseNote, visibility) 25 | } 26 | 27 | @Test 28 | public void argsNullTest() { 29 | String name = "name" 30 | File file = null 31 | String message = "" 32 | String distributionKey = null 33 | String releaseNote = null 34 | String visibility = "private" 35 | 36 | Apk apk = new Apk(name, file) 37 | checkApk(apk, name, file, message, distributionKey, releaseNote, visibility) 38 | checkParams(apk, message, distributionKey, releaseNote, visibility) 39 | } 40 | 41 | @Test 42 | public void projectTest() { 43 | def project = new ProjectBuilder().withProjectDir(new File('src/test/project')).build() 44 | project.apply plugin: 'deploygate' 45 | project.deploygate {} 46 | project.evaluate() 47 | 48 | def apks = Apk.getApks(project) 49 | 50 | String testApkName = "Test" 51 | File testApkFile = null 52 | String testApkMessage = "test message" 53 | String testApkDistributionKey = "key" 54 | String testApkReleaseNote = "release note" 55 | String testApkVisibility = "private" 56 | Apk testApk = apks.get(0) 57 | checkApk(testApk, testApkName, testApkFile, testApkMessage, testApkDistributionKey, testApkReleaseNote, testApkVisibility) 58 | checkParams(testApk, testApkMessage, testApkDistributionKey, testApkReleaseNote, testApkVisibility) 59 | 60 | String test2ApkName = "Test2" 61 | File test2ApkFile = null 62 | String test2ApkMessage = "" 63 | String test2ApkDistributionKey = null 64 | String test2ApkReleaseNote = null 65 | String test2ApkVisibility = "public" 66 | Apk test2Apk = apks.get(1) 67 | checkApk(test2Apk, test2ApkName, test2ApkFile, test2ApkMessage, test2ApkDistributionKey, test2ApkReleaseNote, test2ApkVisibility) 68 | checkParams(test2Apk, test2ApkMessage, test2ApkDistributionKey, test2ApkReleaseNote, test2ApkVisibility) 69 | } 70 | 71 | public void checkApk(Apk apk, String name, File file, String message, String distributionKey, String releaseNote, String visibility) { 72 | assertTrue(apk instanceof Apk) 73 | assertTrue(apk.name == name) 74 | assertTrue(apk.file == file) 75 | assertTrue(apk.message == message) 76 | assertTrue(apk.distributionKey == distributionKey) 77 | assertTrue(apk.releaseNote == releaseNote) 78 | assertTrue(apk.visibility == visibility) 79 | } 80 | 81 | public void checkParams(Apk apk, String message, String distributionKey, String releaseNote, String visibility) { 82 | HashMap params = apk.getParams() 83 | assertTrue(params["message"] == message) 84 | assertTrue(params["distribution_key"] == distributionKey) 85 | assertTrue(params["release_note"] == releaseNote) 86 | assertTrue(params["visibility"] == visibility) 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/test/groovy/com/deploygate/gradle/plugins/ApplyPluginTest.groovy: -------------------------------------------------------------------------------- 1 | package com.deploygate.gradle.plugins 2 | 3 | import org.gradle.api.Project 4 | import org.gradle.testfixtures.ProjectBuilder 5 | import org.junit.Test 6 | import org.quanqi.pgyer.gradle.plugins.PgyerTask 7 | 8 | import static org.junit.Assert.assertTrue 9 | 10 | class ApplyPluginTest { 11 | @Test 12 | public void checkTask() { 13 | Project target = ProjectBuilder.builder().build() 14 | target.apply plugin: 'deploygate' 15 | 16 | assertTrue(target.tasks.uploadDeployGate instanceof PgyerTask) 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/project/build.gradle: -------------------------------------------------------------------------------- 1 | deploygate { 2 | userName = 'owner name' 3 | token = 'apiKey' 4 | 5 | apks { 6 | test { 7 | sourceFile = null 8 | message = 'test message' 9 | distributionKey = 'key' 10 | releaseNote = 'release note' 11 | } 12 | 13 | test2 { 14 | sourceFile = null 15 | visibility = 'public' 16 | } 17 | } 18 | } --------------------------------------------------------------------------------