Commit 0965ac6e authored by maweidong's avatar maweidong

feat:新增APP版本

parent 9f92431c
import javax.net.ssl.HostnameVerifier
import javax.net.ssl.HttpsURLConnection
import javax.net.ssl.SSLSession
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.util.regex.Matcher import java.util.regex.Matcher
import java.util.regex.Pattern import java.util.regex.Pattern
...@@ -94,37 +91,34 @@ def isSnapshot() { ...@@ -94,37 +91,34 @@ def isSnapshot() {
return "SNAPSHOT" == getChannelString() return "SNAPSHOT" == getChannelString()
} }
//task printenv() { task printenv() {
//// for (Map.Entry<String, String> entry : System.getenv()) { getBizModuleLastVersion()
//// println("key:${entry.key},value:${entry.value}") }
//// }
// getBizModuleLastVersion()
//}
def getBizModuleLastVersion() { def getBizModuleLastVersion() {
def modules = [ def modules = [
"yit_shell", "yit_shell",
"yit_shop", // "yit_shop",
"yit_live", // "yit_live",
"yit_cms", // "yit_cms",
"yit_base", // "yit_base",
"yit_food", // "yit_food",
"yit_browser", // "yit_browser",
"yit_category", // "yit_category",
"yit_qr", // "yit_qr",
"yit_productinfo", // "yit_productinfo",
"yit_mine", // "yit_mine",
"yit_search", // "yit_search",
"yit_cart", // "yit_cart",
"yit_post", // "yit_post",
"yit_login", // "yit_login",
"yit_auction", // "yit_auction",
"yit_social", // "yit_social",
"yit_imagepicker", // "yit_imagepicker",
"yit_share", // "yit_share",
"yit_picker", // "yit_picker",
"yit_flutter" // "yit_flutter"
] ]
def group = "com.yitlib.module" def group = "com.yitlib.module"
for (def module : modules) { for (def module : modules) {
...@@ -139,41 +133,27 @@ def getHttpVersion(def group, def module) { ...@@ -139,41 +133,27 @@ def getHttpVersion(def group, def module) {
HttpURLConnection connection = null HttpURLConnection connection = null
InputStream is = null InputStream is = null
BufferedReader br = null BufferedReader br = null
String result = null// 返回结果字符串 StringBuilder builder = new StringBuilder("\n")// 返回结果字符串
try { try {
// 创建远程url连接对象
URL url = new URL("https://nexus3.yit.com/repository/maven-public/$group_path/$module/maven-metadata.xml") URL url = new URL("https://nexus3.yit.com/repository/maven-public/$group_path/$module/maven-metadata.xml")
println(url)
// 通过远程url连接对象打开一个连接 , 强转成httpURLConnection类
connection = (HttpURLConnection) url.openConnection() connection = (HttpURLConnection) url.openConnection()
// 设置连接方式:get
connection.setRequestMethod("GET") connection.setRequestMethod("GET")
// 设置连接主机服务器的超时时间:15000毫秒
connection.setConnectTimeout(15000) connection.setConnectTimeout(15000)
// 设置读取远程返回的数据时间:60000毫秒
connection.setReadTimeout(60000) connection.setReadTimeout(60000)
// 发送请求
connection.connect() connection.connect()
// 通过connection连接,获取输入流
if (connection.getResponseCode() == 200) { if (connection.getResponseCode() == 200) {
is = connection.getInputStream() is = connection.getInputStream()
// 封装输入流is,并指定字符集
br = new BufferedReader(new InputStreamReader(is, "UTF-8")) br = new BufferedReader(new InputStreamReader(is, "UTF-8"))
// 存放数据 String temp
StringBuffer sbf = new StringBuffer()
String temp = null
while ((temp = br.readLine()) != null) { while ((temp = br.readLine()) != null) {
sbf.append(temp) builder.append(temp).append("\n")
sbf.append("\r\n")
} }
result = sbf.toString()
} }
} catch (MalformedURLException e) { } catch (Exception e) {
e.printStackTrace()
} catch (IOException e) {
e.printStackTrace() e.printStackTrace()
} finally { } finally {
// 关闭资源
if (null != br) { if (null != br) {
try { try {
br.close() br.close()
...@@ -189,12 +169,31 @@ def getHttpVersion(def group, def module) { ...@@ -189,12 +169,31 @@ def getHttpVersion(def group, def module) {
e.printStackTrace() e.printStackTrace()
} }
} }
connection.disconnect()// 关闭远程连接 connection.disconnect()// 关闭远程连接
} }
def xmlSlurper = new XmlSlurper()
def response = xmlSlurper.parseText(result) Pattern pattern = Pattern.compile("<versions>(.|\n)+</versions>")
println("$module=${response.versioning.latest}") Matcher matcher = pattern.matcher(builder)
List<String> dataSet = new ArrayList<>()
try {
if (matcher.find()) {
def versions = matcher.group()
.replaceAll("<version>", "")
.replaceAll("</version>", "")
.replaceAll("<versions>", "")
.replaceAll("</versions>", "")
.split("\n")
for (String version : versions) {
dataSet.add(version)
}
}
} catch (Exception e) {
e.printStackTrace()
}
// dataSet.each { it -> println(it) }
} }
......
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