我有一个gradle任务,我要从扫描服务器中提取csv文件,但问题是当我将文件上传到扫描服务器上进行扫描时,它并没有很快进行扫描。扫描服务器至少要花几分钟才35分钟完全完成它。在扫描期间二进制文件的状态更改为“ B”忙之间,以及完成扫描后,将状态更改为“ R”。我能够使用API从json输出中获取状态,但想做点什么等待状态至少为30分钟,然后每5分钟检查一次,状态是否从B更改为R,然后拉出csv文件。
task exportfile {
doLast {
String groupId = getGroupId(serverName, Port, User, Password, groupName)
JSONArray prods = getProductIdList(serverName, Port, User, Password, groupId)
mkdir "${buildDir}/comp"
for (int i = 0; i < products.size(); i++)
{
String name = prods.getJSONObject(i).get("name")
if ( name.matches("$project.ext.baseVersion(.*)")) {
String dest = "${buildDir}/components/${name}.csv"
String prodId = prods.getJSONObject(i).get("id")
String status = prods.getJSONObject(i).get("status")
if("B") {
Process.wait()////not sure how to do this step
exportComponents(serverName, Port, User, Password, prodId, dest)
}
}
}
}
def exportComponents(String host, int port, String user, String pass, String productId, String art) {
CredentialsProvider credsProvider = new BasicCredentialsProvider()
credsProvider.setCredentials(new AuthScope(host, port),
new UsernamePasswordCredentials(user, pass))
CloseableHttpClient httpclient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build()
try {
HttpGet httpget = new HttpGet("https://${host}/api/products/${productId}/csv-libs")
System.out.println("Executing request " + httpget.getRequestLine())
CloseableHttpResponse response = httpclient.execute(httpget)
int status = response.getStatusLine().getStatusCode()
if ( status != 200)
throw new RuntimeException("Something wrong status: " + status)
try {
System.out.println("----------------------------------------")
System.out.println(response.getStatusLine())
String csv = EntityUtils.toString(response.getEntity())
file(artifact).text = csv
} catch(IOException e) {
System.out.println(e.getMessage())}
finally {
response.close()
}
} catch(HTTPException e) {
System.err.println("Fatal Error: " + e.getMessage())
e.printStackTrace() }
finally {
httpclient.close()
}
}