Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
GradlePlugin
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Gradle
GradlePlugin
Commits
a855bc43
Commit
a855bc43
authored
Oct 22, 2021
by
王雷
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
完善打包完后钉钉通知显示分支名
parent
c3210ae5
Changes
10
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
898 additions
and
55 deletions
+898
-55
build.gradle
build.gradle
+72
-32
PygerBuildAndUploadPlugin.groovy
...main/groovy/GradlePlugin/PygerBuildAndUploadPlugin.groovy
+14
-2
PygerUploadTask.groovy
src/main/groovy/GradlePlugin/PygerUploadTask.groovy
+34
-8
OssUploadTask.groovy
src/main/groovy/com/qmai/android/plugin/OssUploadTask.groovy
+33
-6
ZipUtils.kt
src/main/kotlin/com/qmai/android/plugin/ZipUtils.kt
+426
-0
ZipUtils1.kt
src/main/kotlin/com/qmai/android/plugin/ZipUtils1.kt
+122
-0
AliHotFixExtension.kt
...n/com/qmai/android/plugin/alihotfix/AliHotFixExtension.kt
+5
-0
AliHotFixPlugin.kt
...tlin/com/qmai/android/plugin/alihotfix/AliHotFixPlugin.kt
+11
-0
HotFixTask.kt
...in/kotlin/com/qmai/android/plugin/alihotfix/HotFixTask.kt
+148
-0
JiaGuTask.kt
src/main/kotlin/com/qmai/android/plugin/jg/JiaGuTask.kt
+33
-7
No files found.
build.gradle
View file @
a855bc43
/*
/*
* This file was generated by the Gradle 'init' task.
* This file was generated by the Gradle 'init' task.
*
*
...
@@ -6,7 +5,7 @@
...
@@ -6,7 +5,7 @@
* For more details take a look at the Writing Custom Plugins chapter in the Gradle
* For more details take a look at the Writing Custom Plugins chapter in the Gradle
* User Manual available at https://docs.gradle.org/6.6.1/userguide/custom_plugins.html
* User Manual available at https://docs.gradle.org/6.6.1/userguide/custom_plugins.html
*/
*/
buildscript
{
buildscript
{
ext
.
kotlin_version
=
'1.4.10'
ext
.
kotlin_version
=
'1.4.10'
repositories
{
repositories
{
...
@@ -103,61 +102,67 @@ dependencies {
...
@@ -103,61 +102,67 @@ dependencies {
implementation
'com.aliyun.oss:aliyun-sdk-oss:3.10.2'
implementation
'com.aliyun.oss:aliyun-sdk-oss:3.10.2'
implementation
"com.squareup.okhttp3:okhttp:4.9.1"
implementation
"com.squareup.okhttp3:okhttp:4.9.1"
implementation
'com.google.code.gson:gson:2.8.8'
implementation
'com.google.code.gson:gson:2.8.8'
}
}
gradlePlugin
{
gradlePlugin
{
// Define the plugin
// Define the plugin
/* plugins {
/* plugins {
greeting {
greeting {
id = 'GradlePlugin.greeting'
id = 'GradlePlugin.greeting'
implementationClass = 'GradlePlugin.GradlePluginPlugin'
implementationClass = 'GradlePlugin.GradlePluginPlugin'
}
}
jiagu{
jiagu{
id = 'GradlePlugin.jiagu'
id = 'GradlePlugin.jiagu'
implementationClass = 'com.qmai.android.plugin.jg.JiaGuPlugin'
implementationClass = 'com.qmai.android.plugin.jg.JiaGuPlugin'
}
}
}*/
}*/
plugins
{
plugins
{
buildAndOss
{
buildAndOss
{
id
=
'GradlePlugin.buildAndOss'
id
=
'GradlePlugin.buildAndOss'
implementationClass
=
'com.qmai.android.plugin.OssBuildAndUploadPlugin'
implementationClass
=
'com.qmai.android.plugin.OssBuildAndUploadPlugin'
}
}
}
}
plugins
{
plugins
{
buildAndPyger
{
buildAndPyger
{
id
=
'GradlePlugin.buildAndPyger'
id
=
'GradlePlugin.buildAndPyger'
implementationClass
=
'GradlePlugin.PygerBuildAndUploadPlugin'
implementationClass
=
'GradlePlugin.PygerBuildAndUploadPlugin'
}
}
}
}
plugins
{
plugins
{
OssFile
{
OssFile
{
id
=
'GradlePlugin.OssFile'
id
=
'GradlePlugin.OssFile'
implementationClass
=
'com.qmai.android.plugin.OssFileUploadPlugin'
implementationClass
=
'com.qmai.android.plugin.OssFileUploadPlugin'
}
}
}
}
plugins
{
plugins
{
pygerUpload
{
pygerUpload
{
id
=
'GradlePlugin.pygerUpload'
id
=
'GradlePlugin.pygerUpload'
implementationClass
=
'GradlePlugin.PygerUploadPlugin'
implementationClass
=
'GradlePlugin.PygerUploadPlugin'
}
}}
}
plugins
{
hotfix
{
id
=
'GradlePlugin.alihotfix'
implementationClass
=
'com.qmai.android.plugin.alihotfix.AliHotFixPlugin'
}
}
}
}
uploadArchives
{
uploadArchives
{
repositories
.
mavenDeployer
{
repositories
.
mavenDeployer
{
repository
(
url:
uri
(
'https://hub.zmcms.cn/repository/maven-releases/'
))
{
/*repository(url: uri('https://hub.zmcms.cn/repository/maven-releases/'))
{
authentication(userName: 'wanglei1', password: 'woshiwanglei123')
authentication(userName: 'wanglei1', password: 'woshiwanglei123')
}
// 本地仓库路径
}
*/
// 本地仓库路径
pom
.
groupId
=
"com.qmai.android.plugin"
// 唯一标识(通常为模块包名,也可以任意)
pom
.
groupId
=
"com.qmai.android.plugin"
// 唯一标识(通常为模块包名,也可以任意)
pom
.
artifactId
=
"AndroidPlugins"
// 项目名称(通常为类库模块名称,也可以任意)
pom
.
artifactId
=
"AndroidPlugins"
// 项目名称(通常为类库模块名称,也可以任意)
pom
.
version
=
"1.32"
// 版本号
//pom.version = "1.36" // 版本号
pom
.
version
=
"1.48-SNAPSHOT"
snapshotRepository
(
url:
'https://hub.zmcms.cn/repository/maven-snapshots/'
)
{
/* snapshotRepository(url: 'https://hub.zmcms.cn/repository/maven-snapshots/') {
authentication
(
userName:
'wanglei1'
,
password:
'woshiwanglei123'
)
authentication
(
userName:
'wanglei1'
,
password:
'woshiwanglei123'
)
}
*/
}
}
}
}
}
// Add a source set for the functional test suite
// Add a source set for the functional test suite
...
@@ -181,11 +186,46 @@ check {
...
@@ -181,11 +186,46 @@ check {
}
}
task
test11
{
task
test11
{
dependsOn
(
"printVersionInfo"
)
dependsOn
(
"printVersionInfo"
)
doLast
{
doLast
{
}
}
def
kkff
(){
exec
{
executable
()
}
}
}
task
hot
{
doLast
{
def
commond
=
"/Users/leiwang/project/newProject/qmshopassistant-android/app/hotfix/unzip/SophixPatchTool_macos/SophixPatchTool.app/Contents/MacOS/SophixPatchTool --profiles /Users/leiwang/project/newProject/qmshopassistant-android/app/hotfix/profiles.json"
exec
{
ExecSpec
execSpec
->
executable
"which"
args
"bash"
}
exec
{
ExecSpec
execSpec
->
executable
'chmod'
args
'-R'
,
'777'
,
"/Users/leiwang/project/newProject/qmshopassistant-android/app/hotfix/unzip/"
}
/* exec {
ExecSpec execSpec ->
executable 'chmod'
args '-R', '777', "/Users/leiwang/project/newProject/qmshopassistant-android/app/hotfix/profiles.json"
}*/
exec
{
ExecSpec
execSpec
->
executable
'bash'
args
'-c'
,
"/Users/leiwang/Downloads/SophixPatchTool_macos/SophixPatchTool.app/Contents/MacOS/SophixPatchTool"
,
"--profiles"
,
"./profiles.json"
}}
}
}
...
...
src/main/groovy/GradlePlugin/PygerBuildAndUploadPlugin.groovy
View file @
a855bc43
...
@@ -8,12 +8,24 @@ import org.gradle.api.Plugin
...
@@ -8,12 +8,24 @@ import org.gradle.api.Plugin
import
org.gradle.api.Project
import
org.gradle.api.Project
/***
/***
* 编译加上传到
oss
中
* 编译加上传到
pyger
中
*/
*/
class
PygerBuildAndUploadPlugin
implements
Plugin
<
Project
>
{
class
PygerBuildAndUploadPlugin
implements
Plugin
<
Project
>
{
@Override
@Override
void
apply
(
Project
project
)
{
void
apply
(
Project
project
)
{
def
map
=
System
.
getenv
()
map
.
entrySet
().
forEach
{
println
(
" name= "
+
it
.
key
+
"value= "
+
it
.
value
)
}
println
(
"000000---------------------------"
+
System
.
getenv
().
GIT_BRANCH
)
def
byteOut
=
new
ByteArrayOutputStream
(
)
project
.
exec
{
it
.
commandLine
(
"git"
,
"branch"
)
it
.
standardOutput
=
byteOut
}
def
response
=
new
String
(
byteOut
.
toByteArray
())
println
(
"---------git branch122"
+
response
)
PygerBean
PygerBean
=
project
.
getExtensions
().
create
(
"BuildAndPygerInfo"
,
PygerBean
.
class
)
PygerBean
PygerBean
=
project
.
getExtensions
().
create
(
"BuildAndPygerInfo"
,
PygerBean
.
class
)
project
.
afterEvaluate
{
project
.
afterEvaluate
{
// AppExtension app = project.
// AppExtension app = project.
...
...
src/main/groovy/GradlePlugin/PygerUploadTask.groovy
View file @
a855bc43
...
@@ -28,7 +28,7 @@ class PygerUploadTask extends DefaultTask {
...
@@ -28,7 +28,7 @@ class PygerUploadTask extends DefaultTask {
String
buildType
;
String
buildType
;
@Inject
@Inject
public
PygerUploadTask
(
File
file
,
PygerBean
pygerBean
,
String
buildType
)
{
public
PygerUploadTask
(
File
file
,
PygerBean
pygerBean
,
String
buildType
)
{
this
.
file
=
file
this
.
file
=
file
this
.
pygerBean
=
pygerBean
this
.
pygerBean
=
pygerBean
this
.
buildType
=
buildType
this
.
buildType
=
buildType
...
@@ -66,7 +66,7 @@ class PygerUploadTask extends DefaultTask {
...
@@ -66,7 +66,7 @@ class PygerUploadTask extends DefaultTask {
println
(
"下载地址为: downloadUrl:"
+
" https://www.pgyer.com/"
+
payInfoBean
.
data
.
buildShortcutUrl
)
println
(
"下载地址为: downloadUrl:"
+
" https://www.pgyer.com/"
+
payInfoBean
.
data
.
buildShortcutUrl
)
println
(
"二维码地址为:"
+
payInfoBean
.
data
.
buildQRCodeURL
)
println
(
"二维码地址为:"
+
payInfoBean
.
data
.
buildQRCodeURL
)
System
.
out
.
println
(
"upload result: "
+
result
)
System
.
out
.
println
(
"upload result: "
+
result
)
String
content
=
"qmshopassitant: 下载地址: "
+
" https://www.pgyer.com/"
+
payInfoBean
.
data
.
buildShortcutUrl
+
" \n二维码地址: "
+
payInfoBean
.
data
.
buildQRCodeURL
+
" 当前环境"
+
buildType
+
" 当前分支"
+
getBranch
()
String
content
=
file
.
name
+
": 下载地址: "
+
" https://www.pgyer.com/"
+
payInfoBean
.
data
.
buildShortcutUrl
+
" \n二维码地址: "
+
payInfoBean
.
data
.
buildQRCodeURL
+
" 当前环境"
+
buildType
+
" 当前分支"
+
getBranch
()
MediaType
JSON
=
MediaType
.
parse
(
"application/json; charset=utf-8"
);
MediaType
JSON
=
MediaType
.
parse
(
"application/json; charset=utf-8"
);
JSONObject
json
=
new
JSONObject
()
JSONObject
json
=
new
JSONObject
()
try
{
try
{
...
@@ -98,14 +98,40 @@ class PygerUploadTask extends DefaultTask {
...
@@ -98,14 +98,40 @@ class PygerUploadTask extends DefaultTask {
}
}
}
}
boolean
isInJenkins
()
{
Map
<
String
,
String
>
map
=
System
.
getenv
()
if
(
map
==
null
)
{
return
false
}
String
str
=
map
.
get
(
"Path"
)
if
(
str
!=
null
)
{
//it's windows
return
false
}
else
{
str
=
""
Iterator
it
=
map
.
iterator
()
while
(
it
.
hasNext
())
{
str
+=
it
.
next
()
}
return
str
.
contains
(
"jenkins"
)
}
}
//获取当前分支
//获取当前分支
String
getBranch
(){
String
getBranch
()
{
def
byteOut
=
new
ByteArrayOutputStream
()
if
(
isInJenkins
())
{
project
.
exec
{
return
System
.
getenv
().
GIT_BRANCH
it
.
commandLine
(
"git"
,
"rev-parse"
,
"--abbrev-ref"
,
"HEAD"
)
}
else
{
it
.
standardOutput
=
byteOut
def
byteOut
=
new
ByteArrayOutputStream
()
project
.
exec
{
it
.
commandLine
(
"git"
,
"rev-parse"
,
"--abbrev-ref"
,
"HEAD"
)
it
.
standardOutput
=
byteOut
}
def
response
=
new
String
(
byteOut
.
toByteArray
())
return
response
}
}
def
response
=
new
String
(
byteOut
.
toByteArray
())
return
response
return
response
}
}
}
}
src/main/groovy/com/qmai/android/plugin/OssUploadTask.groovy
View file @
a855bc43
...
@@ -101,13 +101,40 @@ class OssUploadTask extends DefaultTask {
...
@@ -101,13 +101,40 @@ class OssUploadTask extends DefaultTask {
}
}
}
}
String
getBranch
(){
def
byteOut
=
new
ByteArrayOutputStream
()
boolean
isInJenkins
()
{
project
.
exec
{
Map
<
String
,
String
>
map
=
System
.
getenv
()
it
.
commandLine
(
"git"
,
"rev-parse"
,
"--abbrev-ref"
,
"HEAD"
)
if
(
map
==
null
)
{
it
.
standardOutput
=
byteOut
return
false
}
String
str
=
map
.
get
(
"Path"
)
if
(
str
!=
null
)
{
//it's windows
return
false
}
else
{
str
=
""
Iterator
it
=
map
.
iterator
()
while
(
it
.
hasNext
())
{
str
+=
it
.
next
()
}
return
str
.
contains
(
"jenkins"
)
}
}
//获取当前分支
String
getBranch
()
{
if
(
isInJenkins
())
{
return
System
.
getenv
().
GIT_BRANCH
}
else
{
def
byteOut
=
new
ByteArrayOutputStream
()
project
.
exec
{
it
.
commandLine
(
"git"
,
"rev-parse"
,
"--abbrev-ref"
,
"HEAD"
)
it
.
standardOutput
=
byteOut
}
def
response
=
new
String
(
byteOut
.
toByteArray
())
return
response
}
}
def
response
=
new
String
(
byteOut
.
toByteArray
())
return
response
return
response
}
}
...
...
src/main/kotlin/com/qmai/android/plugin/ZipUtils.kt
0 → 100644
View file @
a855bc43
This diff is collapsed.
Click to expand it.
src/main/kotlin/com/qmai/android/plugin/ZipUtils1.kt
0 → 100644
View file @
a855bc43
package
com.qmai.android.plugin
import
java.io.*
import
java.util.*
import
java.util.zip.ZipEntry
import
java.util.zip.ZipFile
import
java.util.zip.ZipOutputStream
object
ZipUtils1
{
private
const
val
BUFFER_SIZE
=
2
*
1024
/**
* zip解压
* @param srcFile zip源文件
* @param destDirPath 解压后的目标文件夹
* @throws RuntimeException 解压失败会抛出运行时异常
*/
@Throws
(
RuntimeException
::
class
)
fun
unZip
(
srcFile
:
File
,
destDirPath
:
String
)
{
val
start
=
System
.
currentTimeMillis
()
// 判断源文件是否存在
if
(!
srcFile
.
exists
())
{
throw
RuntimeException
(
srcFile
.
getPath
().
toString
()
+
"所指文件不存在"
)
}
// 开始解压
var
zipFile
:
ZipFile
?
=
null
try
{
zipFile
=
ZipFile
(
srcFile
)
val
entries
:
Enumeration
<*>
=
zipFile
.
entries
()
/* while (zipFile.entries().hasMoreElements()){
val entry: ZipEntry = entries.nextElement() as ZipEntry
println("解压: " + entry.getName())
}*/
while
(
entries
.
hasMoreElements
())
{
val
entry
:
ZipEntry
=
entries
.
nextElement
()
as
ZipEntry
println
(
"解压"
+
entry
.
getName
())
val
name
=
entry
.
name
//__MACOSX/SophixPatchTool_macos/._.DS_Store
if
(
name
.
contains
(
"__MACOSX"
)||
name
.
contains
(
"/.DS_Store"
)){
continue
}
// 如果是文件夹,就创建个文件夹
if
(
entry
.
isDirectory
())
{
val
dirPath
=
destDirPath
+
"/"
+
entry
.
getName
()
val
dir
=
File
(
dirPath
)
dir
.
mkdirs
()
}
else
{
// 如果是文件,就先创建一个文件,然后用io流把内容copy过去
val
targetFile
=
File
(
destDirPath
+
"/"
+
entry
.
getName
())
// 保证这个文件的父文件夹必须要存在
if
(!
targetFile
.
getParentFile
().
exists
())
{
targetFile
.
getParentFile
().
mkdirs
()
}
targetFile
.
createNewFile
()
// 将压缩文件内容写入到这个文件中
val
`is`
:
InputStream
=
zipFile
.
getInputStream
(
entry
)
val
fos
=
FileOutputStream
(
targetFile
)
var
len
:
Int
=
0
val
buf
=
ByteArray
(
BUFFER_SIZE
)
while
(
`is`
.
read
(
buf
).
also
({
len
=
it
})
!=
-
1
)
{
fos
.
write
(
buf
,
0
,
len
)
}
// 关流顺序,先打开的后关闭
fos
.
close
()
`is`
.
close
()
}
}
val
end
=
System
.
currentTimeMillis
()
println
(
"解压完成,耗时:"
+
(
end
-
start
)
+
" ms"
)
}
catch
(
e
:
Exception
)
{
println
(
"uzip error = $e"
)
throw
RuntimeException
(
"unzip error from ZipUtils"
,
e
)
}
finally
{
if
(
zipFile
!=
null
)
{
try
{
zipFile
.
close
()
}
catch
(
e
:
IOException
)
{
e
.
printStackTrace
()
}
}
}
}
/**
* 压缩成ZIP 方法
* @param srcFiles 需要压缩的文件列表
* @param out 压缩文件输出流
* @throws RuntimeException 压缩失败会抛出运行时异常
*/
@Throws
(
Exception
::
class
)
fun
toZip
(
srcFiles
:
List
<
File
>,
out
:
OutputStream
?)
{
val
start
=
System
.
currentTimeMillis
()
var
zos
:
ZipOutputStream
?
=
null
try
{
zos
=
ZipOutputStream
(
out
)
for
(
srcFile
in
srcFiles
)
{
val
buf
=
ByteArray
(
BUFFER_SIZE
)
zos
.
putNextEntry
(
ZipEntry
(
srcFile
.
getName
()))
var
len
:
Int
val
`in`
=
FileInputStream
(
srcFile
)
while
(
`in`
.
read
(
buf
).
also
{
len
=
it
}
!=
-
1
)
{
zos
.
write
(
buf
,
0
,
len
)
}
zos
.
closeEntry
()
`in`
.
close
()
}
val
end
=
System
.
currentTimeMillis
()
println
(
"压缩完成,耗时:"
+
(
end
-
start
)
+
" ms"
)
}
catch
(
e
:
Exception
)
{
throw
RuntimeException
(
"zip error from ZipUtils"
,
e
)
}
finally
{
if
(
zos
!=
null
)
{
try
{
zos
.
close
()
}
catch
(
e
:
Exception
)
{
e
.
printStackTrace
()
}
}
}
}
}
\ No newline at end of file
src/main/kotlin/com/qmai/android/plugin/alihotfix/AliHotFixExtension.kt
0 → 100644
View file @
a855bc43
package
com.qmai.android.plugin.alihotfix
open
class
AliHotFixExtension
{
}
\ No newline at end of file
src/main/kotlin/com/qmai/android/plugin/alihotfix/AliHotFixPlugin.kt
0 → 100644
View file @
a855bc43
package
com.qmai.android.plugin.alihotfix
import
org.gradle.api.Project
open
class
AliHotFixPlugin
:
org
.
gradle
.
api
.
Plugin
<
Project
>
{
override
fun
apply
(
p0
:
Project
)
{
p0
.
tasks
.
create
(
"alihotfix"
,
HotFixTask
::
class
.
java
)
}
}
\ No newline at end of file
src/main/kotlin/com/qmai/android/plugin/alihotfix/HotFixTask.kt
0 → 100644
View file @
a855bc43
package
com.qmai.android.plugin.alihotfix
import
com.android.repository.util.InstallerUtil.unzip
import
com.qmai.android.plugin.ZipUtils
import
org.apache.tools.ant.taskdefs.condition.Os
import
org.gradle.api.DefaultTask
import
org.gradle.api.tasks.TaskAction
import
java.io.ByteArrayOutputStream
import
java.io.File
open
class
HotFixTask
:
DefaultTask
()
{
var
mZipPath
:
String
=
"./hotfix/zip/"
var
mUnzipPath
:
String
=
"./hotfix/unzip"
var
mZipName
:
String
?
=
null
var
mConfigPath
:
String
=
"./hotfix/profiles.json"
@TaskAction
fun
begin
()
{
group
=
"hotfix"
//判断是否存在加固文件
//先判断系统
val
osList
=
arrayOf
(
Os
.
FAMILY_MAC
,
Os
.
FAMILY_WINDOWS
,
Os
.
FAMILY_UNIX
)
val
osPath
=
osList
.
find
{
Os
.
isFamily
(
it
)
}
println
(
"当前系统是: $osPath"
)
val
downLoadUrl
=
when
(
osPath
)
{
Os
.
FAMILY_MAC
->
{
mZipName
=
"SophixPatchTool_macos.zip"
"http://ams-hotfix-repo.oss-cn-shanghai.aliyuncs.com/SophixPatchTool_macos.zip?spm=a2c4g.11186623.0.0.48c652ffVg1sh2&file=SophixPatchTool_macos.zip"
}
Os
.
FAMILY_DOS
->
{
mZipName
=
"SophixPatchTool_linux.zip"
"http://ams-hotfix-repo.oss-cn-shanghai.aliyuncs.com/SophixPatchTool_linux.zip?spm=a2c4g.11186623.0.0.48c652ffVg1sh2&file=SophixPatchTool_linux.zip"
}
Os
.
FAMILY_WINDOWS
->
{
mZipName
=
"SophixPatchTool_windows.zip"
"http://ams-hotfix-repo.oss-cn-shanghai.aliyuncs.com/SophixPatchTool_windows.zip?spm=a2c4g.11186623.0.0.48c652ffVg1sh2&file=SophixPatchTool_windows.zip"
}
else
->
{
null
}
}
mZipPath
=
StringBuilder
(
mZipPath
).
append
(
mZipName
).
toString
()
if
(
downLoadUrl
.
isNullOrEmpty
())
{
println
(
"当前系统不支持 $osPath"
)
}
else
{
val
zipPathDir
=
File
(
mZipPath
)
if
(
zipPathDir
.
exists
())
{
if
(
zipPathDir
.
list
().
isNotEmpty
())
{
}
else
{
//缺失文件
//下载文件
project
.
exec
{
it
.
commandLine
(
"curl"
,
"-o"
,
mZipPath
,
downLoadUrl
)
}
}
}
else
{
if
(!
zipPathDir
!!
.
parentFile
.
exists
())
{
zipPathDir
.
parentFile
.
mkdirs
()
}
//下载文件
project
.
exec
{
it
.
commandLine
(
"curl"
,
"-o"
,
mZipPath
,
downLoadUrl
)
}
}
val
unzipParentFile
=
File
(
mUnzipPath
)
if
(!
unzipParentFile
.
exists
())
{
unzipParentFile
.
mkdirs
()
}
try
{
val
list
=
ZipUtils
.
unzipFile
(
zipPathDir
!!
,
unzipParentFile
)
list
?.
forEach
{
println
(
"file name= ${it}"
)
}
val
path
=
when
(
osPath
)
{
Os
.
FAMILY_MAC
->
{
"./hotfix/unzip/SophixPatchTool_macos/SophixPatchTool.app/Contents/MacOS/SophixPatchTool"
}
Os
.
FAMILY_DOS
->
{
"http://ams-hotfix-repo.oss-cn-shanghai.aliyuncs.com/SophixPatchTool_linux.zip?spm=a2c4g.11186623.0.0.48c652ffVg1sh2&file=SophixPatchTool_linux.zip"
}
Os
.
FAMILY_WINDOWS
->
{
"http://ams-hotfix-repo.oss-cn-shanghai.aliyuncs.com/SophixPatchTool_windows.zip?spm=a2c4g.11186623.0.0.48c652ffVg1sh2&file=SophixPatchTool_windows.zip"
}
else
->
{
null
}
}
val
pathFile
=
File
(
path
)
val
configFile
=
File
(
mConfigPath
)
println
(
"pathFile= ${pathFile.absolutePath} configFile= ${configFile.absolutePath}"
)
project
.
exec
{
it
.
commandLine
(
"chmod"
,
"-R"
,
"777"
,
pathFile
.
absolutePath
)
}
println
(
"-------------------------"
)
val
byteOut
=
ByteArrayOutputStream
()
/* project.exec{
it.executable = "java -version"
it.standardOutput = byteOut
}*/
val
endResult
=
String
(
byteOut
.
toByteArray
())
println
(
"end resoponse = $endResult"
)
val
command
=
"${pathFile.absolutePath} --profiles ${configFile.absolutePath}"
project
.
exec
{
/*it.workingDir = pathFile.parentFile
// it.executable = "SophixPatchTool"
// it.executable = "${pathFile.absolutePath} --profiles ${configFile.absolutePath}"
val args = ArrayList<String>()
args.add("SophixPatchTool")
args.add("--profiles")
args.add(configFile.absolutePath)
it.setArgs(args)*/
it
.
executable
=
"bash"
val
args
=
ArrayList
<
String
>()
args
.
add
(
"-c"
)
args
.
add
(
"${pathFile.absolutePath}"
)
args
.
add
(
"--profiles"
)
args
.
add
(
configFile
.
absolutePath
)
it
.
args
=
args
}
/* project.exec {
it.commandLine("${pathFile.absolutePath}","--profiles","${configFile.absolutePath}")
}*/
}
catch
(
e
:
Exception
)
{
println
(
"E= $e"
)
}
}
}
}
\ No newline at end of file
src/main/kotlin/com/qmai/android/plugin/jg/JiaGuTask.kt
View file @
a855bc43
...
@@ -78,14 +78,40 @@ open class JiaGuTask(): DefaultTask() {
...
@@ -78,14 +78,40 @@ open class JiaGuTask(): DefaultTask() {
}
}
fun
getBranch
():
String
{
val
byteOut
=
ByteArrayOutputStream
()
fun
isInJenkins
()
:
Boolean
{
project
.
exec
{
val
map
=
System
.
getenv
()
it
.
commandLine
(
"git"
,
"rev-parse"
,
"--abbrev-ref"
,
"HEAD"
)
if
(
map
==
null
)
{
it
.
standardOutput
=
byteOut
return
false
}
var
str
=
map
.
get
(
"Path"
)
if
(
str
!=
null
)
{
//it's windows
return
false
}
else
{
str
=
""
val
it
=
map
.
iterator
()
while
(
it
.
hasNext
())
{
str
+=
it
.
next
()
}
return
str
.
contains
(
"jenkins"
)
}
}
val
response
=
String
(
byteOut
.
toByteArray
())
}
return
response
//获取当前分支
fun
getBranch
():
String
{
if
(
isInJenkins
())
{
return
System
.
getenv
().
get
(
"GIT_BRANCH"
).
toString
()
}
else
{
val
byteOut
=
ByteArrayOutputStream
()
project
.
exec
{
it
.
commandLine
(
"git"
,
"rev-parse"
,
"--abbrev-ref"
,
"HEAD"
)
it
.
standardOutput
=
byteOut
}
val
response
=
String
(
byteOut
.
toByteArray
())
return
response
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment