Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xiaoxuan_i809
AndroidUtilCode
提交
4a3c0808
A
AndroidUtilCode
项目概览
xiaoxuan_i809
/
AndroidUtilCode
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
AndroidUtilCode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
4a3c0808
编写于
8月 16, 2019
作者:
B
Blankj
浏览文件
操作
浏览文件
下载
差异文件
Merge branch '1.25.9'
上级
13de11ed
4565226d
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
329 addition
and
2 deletion
+329
-2
buildSrc/src/main/groovy/ConfigUtils.groovy
buildSrc/src/main/groovy/ConfigUtils.groovy
+1
-2
buildSrc/src/main/groovy/GitUtils.groovy
buildSrc/src/main/groovy/GitUtils.groovy
+88
-0
buildSrc/src/main/groovy/GitUtils.java
buildSrc/src/main/groovy/GitUtils.java
+12
-0
buildSrc/src/main/groovy/ShellUtils.java
buildSrc/src/main/groovy/ShellUtils.java
+228
-0
未找到文件。
buildSrc/src/main/groovy/ConfigUtils.groovy
浏览文件 @
4a3c0808
import
org.apache.commons.io.FileUtils
import
org.apache.groovy.json.internal.ArrayUtils
import
org.gradle.BuildListener
import
org.gradle.BuildResult
import
org.gradle.api.Project
...
...
@@ -10,7 +9,6 @@ import org.gradle.api.execution.TaskExecutionListener
import
org.gradle.api.initialization.Settings
import
org.gradle.api.invocation.Gradle
import
org.gradle.api.tasks.TaskState
import
org.gradle.internal.impldep.org.apache.commons.collections.MapUtils
import
java.text.SimpleDateFormat
...
...
@@ -63,6 +61,7 @@ class ConfigUtils {
static
addBuildListener
(
Gradle
gradle
)
{
gradle
.
addBuildListener
(
new
ConfigBuildListener
())
GitUtils
.
init
(
gradle
)
}
private
static
class
ConfigBuildListener
implements
BuildListener
{
...
...
buildSrc/src/main/groovy/GitUtils.groovy
0 → 100644
浏览文件 @
4a3c0808
import
org.gradle.api.Action
import
org.gradle.api.Project
import
org.gradle.api.Task
import
org.gradle.api.invocation.Gradle
import
java.text.SimpleDateFormat
/**
* <pre>
* author: blankj
* blog : http://blankj.com
* time : 2019/08/16
* desc :
* </pre>
*/
class
GitUtils
{
private
static
String
sCurBranchName
;
static
void
init
(
Gradle
gradle
)
{
gradle
.
rootProject
(
new
Action
<
Project
>()
{
@Override
void
execute
(
Project
project
)
{
sCurBranchName
=
getGitBranch
()
addGitPushTask
(
project
)
addGitPushAndMerge2MasterTask
(
project
)
addGitNewBranchTask
(
project
)
}
})
}
static
def
getGitBranch
()
{
return
ShellUtils
.
execCmd
(
'git symbolic-ref --short -q HEAD'
).
successMsg
}
static
void
addGitPushTask
(
Project
project
)
{
project
.
task
(
"gitPush"
,
new
Action
<
Task
>()
{
@Override
void
execute
(
Task
task
)
{
task
.
doLast
{
SimpleDateFormat
simpleDateFormat
=
new
SimpleDateFormat
(
"MM/dd"
)
String
date
=
simpleDateFormat
.
format
(
new
Date
())
GLog
.
d
(
ShellUtils
.
execCmd
([
"git add -A"
,
"git commit -m \"see $date log\""
,
"git push origin $sCurBranchName"
]
as
String
[]))
}
}
})
}
static
void
addGitPushAndMerge2MasterTask
(
Project
project
)
{
project
.
task
(
"gitPushAndMerge2Master"
,
new
Action
<
Task
>()
{
@Override
void
execute
(
Task
task
)
{
task
.
doLast
{
SimpleDateFormat
simpleDateFormat
=
new
SimpleDateFormat
(
"MM/dd"
)
String
date
=
simpleDateFormat
.
format
(
new
Date
())
GLog
.
d
(
ShellUtils
.
execCmd
([
"git add -A"
,
"git commit -m \"see $date log\""
,
"git push origin $sCurBranchName"
,
"git checkout master"
,
"git merge $sCurBranchName"
,
"git push origin master"
,
"git checkout $sCurBranchName"
,
]
as
String
[]))
}
}
})
}
static
void
addGitNewBranchTask
(
Project
project
)
{
project
.
task
(
"gitNewBranch"
,
new
Action
<
Task
>()
{
@Override
void
execute
(
Task
task
)
{
task
.
doLast
{
GLog
.
d
(
ShellUtils
.
execCmd
([
"git checkout master"
,
"git checkout -b ${Config.versionName}"
,
"git push origin ${Config.versionName}:${Config.versionName}"
,
]
as
String
[]))
}
}
})
}
}
buildSrc/src/main/groovy/GitUtils.java
0 → 100644
浏览文件 @
4a3c0808
package
PACKAGE_NAME
;
/**
* <pre>
* author: blankj
* blog : http://blankj.com
* time : 2019/08/16
* desc :
* </pre>
*/
public
class
GitUtils
{
}
buildSrc/src/main/groovy/ShellUtils.java
0 → 100644
浏览文件 @
4a3c0808
import
java.io.BufferedReader
;
import
java.io.DataOutputStream
;
import
java.io.IOException
;
import
java.io.InputStreamReader
;
import
java.util.List
;
/**
* <pre>
* author: Blankj
* blog : http://blankj.com
* time : 2016/08/07
* desc : utils about shell
* </pre>
*/
public
final
class
ShellUtils
{
private
static
final
String
LINE_SEP
=
System
.
getProperty
(
"line.separator"
);
private
ShellUtils
()
{
throw
new
UnsupportedOperationException
(
"u can't instantiate me..."
);
}
/**
* Execute the command.
*
* @param command The command.
* @return the single {@link CommandResult} instance
*/
public
static
CommandResult
execCmd
(
final
String
command
)
{
return
execCmd
(
new
String
[]{
command
},
false
,
true
);
}
/**
* Execute the command.
*
* @param command The command.
* @param isRooted True to use root, false otherwise.
* @return the single {@link CommandResult} instance
*/
public
static
CommandResult
execCmd
(
final
String
command
,
final
boolean
isRooted
)
{
return
execCmd
(
new
String
[]{
command
},
isRooted
,
true
);
}
/**
* Execute the command.
*
* @param commands The commands.
* @return the single {@link CommandResult} instance
*/
public
static
CommandResult
execCmd
(
final
List
<
String
>
commands
)
{
return
execCmd
(
commands
==
null
?
null
:
commands
.
toArray
(
new
String
[]{}),
false
,
true
);
}
/**
* Execute the command.
*
* @param commands The commands.
* @param isRooted True to use root, false otherwise.
* @return the single {@link CommandResult} instance
*/
public
static
CommandResult
execCmd
(
final
List
<
String
>
commands
,
final
boolean
isRooted
)
{
return
execCmd
(
commands
==
null
?
null
:
commands
.
toArray
(
new
String
[]{}),
isRooted
,
true
);
}
/**
* Execute the command.
*
* @param commands The commands.
* @return the single {@link CommandResult} instance
*/
public
static
CommandResult
execCmd
(
final
String
[]
commands
)
{
return
execCmd
(
commands
,
false
,
true
);
}
/**
* Execute the command.
*
* @param commands The commands.
* @param isRooted True to use root, false otherwise.
* @return the single {@link CommandResult} instance
*/
public
static
CommandResult
execCmd
(
final
String
[]
commands
,
final
boolean
isRooted
)
{
return
execCmd
(
commands
,
isRooted
,
true
);
}
/**
* Execute the command.
*
* @param command The command.
* @param isRooted True to use root, false otherwise.
* @param isNeedResultMsg True to return the message of result, false otherwise.
* @return the single {@link CommandResult} instance
*/
public
static
CommandResult
execCmd
(
final
String
command
,
final
boolean
isRooted
,
final
boolean
isNeedResultMsg
)
{
return
execCmd
(
new
String
[]{
command
},
isRooted
,
isNeedResultMsg
);
}
/**
* Execute the command.
*
* @param commands The commands.
* @param isRooted True to use root, false otherwise.
* @param isNeedResultMsg True to return the message of result, false otherwise.
* @return the single {@link CommandResult} instance
*/
public
static
CommandResult
execCmd
(
final
List
<
String
>
commands
,
final
boolean
isRooted
,
final
boolean
isNeedResultMsg
)
{
return
execCmd
(
commands
==
null
?
null
:
commands
.
toArray
(
new
String
[]{}),
isRooted
,
isNeedResultMsg
);
}
/**
* Execute the command.
*
* @param commands The commands.
* @param isRooted True to use root, false otherwise.
* @param isNeedResultMsg True to return the message of result, false otherwise.
* @return the single {@link CommandResult} instance
*/
public
static
CommandResult
execCmd
(
final
String
[]
commands
,
final
boolean
isRooted
,
final
boolean
isNeedResultMsg
)
{
int
result
=
-
1
;
if
(
commands
==
null
||
commands
.
length
==
0
)
{
return
new
CommandResult
(
result
,
""
,
""
);
}
Process
process
=
null
;
BufferedReader
successResult
=
null
;
BufferedReader
errorResult
=
null
;
StringBuilder
successMsg
=
null
;
StringBuilder
errorMsg
=
null
;
DataOutputStream
os
=
null
;
try
{
process
=
Runtime
.
getRuntime
().
exec
(
isRooted
?
"su"
:
"sh"
);
os
=
new
DataOutputStream
(
process
.
getOutputStream
());
for
(
String
command
:
commands
)
{
if
(
command
==
null
)
continue
;
os
.
write
(
command
.
getBytes
());
os
.
writeBytes
(
LINE_SEP
);
os
.
flush
();
}
os
.
writeBytes
(
"exit"
+
LINE_SEP
);
os
.
flush
();
result
=
process
.
waitFor
();
if
(
isNeedResultMsg
)
{
successMsg
=
new
StringBuilder
();
errorMsg
=
new
StringBuilder
();
successResult
=
new
BufferedReader
(
new
InputStreamReader
(
process
.
getInputStream
(),
"UTF-8"
)
);
errorResult
=
new
BufferedReader
(
new
InputStreamReader
(
process
.
getErrorStream
(),
"UTF-8"
)
);
String
line
;
if
((
line
=
successResult
.
readLine
())
!=
null
)
{
successMsg
.
append
(
line
);
while
((
line
=
successResult
.
readLine
())
!=
null
)
{
successMsg
.
append
(
LINE_SEP
).
append
(
line
);
}
}
if
((
line
=
errorResult
.
readLine
())
!=
null
)
{
errorMsg
.
append
(
line
);
while
((
line
=
errorResult
.
readLine
())
!=
null
)
{
errorMsg
.
append
(
LINE_SEP
).
append
(
line
);
}
}
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
finally
{
try
{
if
(
os
!=
null
)
{
os
.
close
();
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
try
{
if
(
successResult
!=
null
)
{
successResult
.
close
();
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
try
{
if
(
errorResult
!=
null
)
{
errorResult
.
close
();
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
if
(
process
!=
null
)
{
process
.
destroy
();
}
}
return
new
CommandResult
(
result
,
successMsg
==
null
?
""
:
successMsg
.
toString
(),
errorMsg
==
null
?
""
:
errorMsg
.
toString
()
);
}
/**
* The result of command.
*/
public
static
class
CommandResult
{
public
int
result
;
public
String
successMsg
;
public
String
errorMsg
;
public
CommandResult
(
final
int
result
,
final
String
successMsg
,
final
String
errorMsg
)
{
this
.
result
=
result
;
this
.
successMsg
=
successMsg
;
this
.
errorMsg
=
errorMsg
;
}
@Override
public
String
toString
()
{
return
"result: "
+
result
+
"\n"
+
"successMsg: "
+
successMsg
+
"\n"
+
"errorMsg: "
+
errorMsg
;
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录