Commit a855bc43 authored by 王雷's avatar 王雷

完善打包完后钉钉通知显示分支名

parent c3210ae5
/*
* This file was generated by the Gradle 'init' task.
*
......@@ -6,7 +5,7 @@
* 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
*/
buildscript{
buildscript {
ext.kotlin_version = '1.4.10'
repositories {
......@@ -103,61 +102,67 @@ dependencies {
implementation 'com.aliyun.oss:aliyun-sdk-oss:3.10.2'
implementation "com.squareup.okhttp3:okhttp:4.9.1"
implementation 'com.google.code.gson:gson:2.8.8'
}
gradlePlugin {
// Define the plugin
/* plugins {
greeting {
id = 'GradlePlugin.greeting'
implementationClass = 'GradlePlugin.GradlePluginPlugin'
}
jiagu{
id = 'GradlePlugin.jiagu'
implementationClass = 'com.qmai.android.plugin.jg.JiaGuPlugin'
}
}*/
plugins {
buildAndOss {
id = 'GradlePlugin.buildAndOss'
implementationClass = 'com.qmai.android.plugin.OssBuildAndUploadPlugin'
}
/* plugins {
greeting {
id = 'GradlePlugin.greeting'
implementationClass = 'GradlePlugin.GradlePluginPlugin'
}
jiagu{
id = 'GradlePlugin.jiagu'
implementationClass = 'com.qmai.android.plugin.jg.JiaGuPlugin'
}
}*/
plugins {
buildAndOss {
id = 'GradlePlugin.buildAndOss'
implementationClass = 'com.qmai.android.plugin.OssBuildAndUploadPlugin'
}
}
plugins {
buildAndPyger {
id = 'GradlePlugin.buildAndPyger'
implementationClass = 'GradlePlugin.PygerBuildAndUploadPlugin'
}
}
plugins {
OssFile {
id = 'GradlePlugin.OssFile'
implementationClass = 'com.qmai.android.plugin.OssFileUploadPlugin'
}
plugins {
OssFile {
id = 'GradlePlugin.OssFile'
implementationClass = 'com.qmai.android.plugin.OssFileUploadPlugin'
}
}
plugins {
pygerUpload {
id = 'GradlePlugin.pygerUpload'
implementationClass = 'GradlePlugin.PygerUploadPlugin'
}
}
}}
plugins {
hotfix {
id = 'GradlePlugin.alihotfix'
implementationClass = 'com.qmai.android.plugin.alihotfix.AliHotFixPlugin'
}
}
}
uploadArchives {
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')
} // 本地仓库路径
} */ // 本地仓库路径
pom.groupId = "com.qmai.android.plugin"// 唯一标识(通常为模块包名,也可以任意)
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')
}*/
}
}
}
// Add a source set for the functional test suite
......@@ -181,11 +186,46 @@ check {
}
task test11{
task test11 {
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"
}}
}
......
......@@ -8,12 +8,24 @@ import org.gradle.api.Plugin
import org.gradle.api.Project
/***
* 编译加上传到oss
* 编译加上传到pyger
*/
class PygerBuildAndUploadPlugin implements Plugin<Project> {
@Override
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)
project.afterEvaluate {
// AppExtension app = project.
......
......@@ -28,7 +28,7 @@ class PygerUploadTask extends DefaultTask {
String buildType;
@Inject
public PygerUploadTask(File file, PygerBean pygerBean,String buildType) {
public PygerUploadTask(File file, PygerBean pygerBean, String buildType) {
this.file = file
this.pygerBean = pygerBean
this.buildType = buildType
......@@ -66,7 +66,7 @@ class PygerUploadTask extends DefaultTask {
println("下载地址为: downloadUrl:" + " https://www.pgyer.com/" + payInfoBean.data.buildShortcutUrl)
println("二维码地址为:" + payInfoBean.data.buildQRCodeURL)
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");
JSONObject json = new JSONObject()
try {
......@@ -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(){
def byteOut = new ByteArrayOutputStream()
project.exec {
it.commandLine("git", "rev-parse", "--abbrev-ref", "HEAD")
it.standardOutput = byteOut
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
}
}
......@@ -101,13 +101,40 @@ class OssUploadTask extends DefaultTask {
}
}
String getBranch(){
def byteOut = new ByteArrayOutputStream()
project.exec {
it.commandLine("git", "rev-parse", "--abbrev-ref", "HEAD")
it.standardOutput = byteOut
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() {
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
}
......
This diff is collapsed.
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
package com.qmai.android.plugin.alihotfix
open class AliHotFixExtension{
}
\ No newline at end of file
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
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
......@@ -78,14 +78,40 @@ open class JiaGuTask(): DefaultTask() {
}
fun getBranch():String{
val byteOut = ByteArrayOutputStream()
project.exec {
it.commandLine("git", "rev-parse", "--abbrev-ref", "HEAD")
it.standardOutput = byteOut
fun isInJenkins() :Boolean{
val map = System.getenv()
if (map == null) {
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
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment