grails“Scripts”目录中指定的目标下面的ant片段创建了一个包含所有类的校验和的文件,因此可以在目标服务器上检查它们。
ant的输出是这样的文件:
<?php $usertype=0; ?>
<?php require('check_if_logged_in.php'); ?>
<?php
require_once 'header.php';
require_once('my_connect.php');
$my_query="select * from loans order by date_return ASC";
$result= mysqli_query($connection, $my_query);
?>
<html>
<h2 align="center">All Existing Loans</h2>
<body>
<p align="center">Here are all the loans that have been entered on the Loan System</p>
<p align="center"><font color="blue"><i> * Blue - Active</i></font></p>
<p align="center"><font color="red"><i> * Red - Overdue</i></font></p>
<p align="center"><font color="green"><i> * Green - Completed</i></font> </p>
</body>
</html>
<table border=1 cellpadding=10>
<tr><th>Loan ID<th>Product<th>User<th>Expected Return Date?<th>Returned? <th>Edit?
<?php
//$dbdate = date('Y-m-d', $date_return);
while ($myrow = mysqli_fetch_array($result)):
$today = date('d-m-Y');
$loanid = $myrow["loanid"];
$product = $myrow["product"];
$user = $myrow["user"];
$dbdate = date('d-m-Y',$myrow["date_return"]);
$date_return = $myrow["date_return"];
$returned = $myrow["returned"];
$table = '<tr>';
$table.= '<td>'.$loanid.'</td>';
$table.= '<td>'.$product.'</td>';
$table.= '<td>'.$user.'</td>';
if ($returned == 'Yes'){
$table.= '<td><div style="color: green;">'.$date_return.'</div>';
}else if ($date_return <= $today){
$table.= '<td><b><div style="color: red;">'.$date_return.'</div></b>';
} else {
$table.= '<td><div style="color: blue;">'.$date_return.'</div>';
} //end if
$table.= '<td>'.$returned.'</td>';;
$table.= "<td><a onClick =\"return confirm('Are You Sure You Want To Edit This Loan?')\" href=editloaninfo.php?loanid=".$loanid."><img src=\"edit.png\"> </td>";
echo $table;
/*echo "
<tr>
<td>$loanid</td>
<td>$product</td>
<td>$user</td>
<td>$date_return</td>
<td>$returned</td>
<td><a onClick =\"return confirm('Are You Sure You Want To Edit This Loan?')\" href=editloaninfo.php?loanid=$loanid><img src=\"edit.png\">";*/
endwhile;
?>
</table>
问题是文件路径中的“目标”一词。当应用程序在webapp下部署到tomcat时,没有目标。
如何避免这种情况?例如。如果ant.concat函数采用了basedir:“target”,如果你可以执行ant.cd(“target”)或者类似它会解决问题,或者如果你可以为每个目标指定一个basedir,但这似乎不是可能的?
来源:
c9b1c71b31e53e99ff31b4be0a1284558aa019ec target/classes/bo/ApiRequestFilters$_closure1.class
ff936fddc1b99ba323493b131d271ca4feb0f5dd target/classes/bo/ApiRequestFilters.class
df7a12fe1182b5fc10177a2559a3a0cbb0709e29 target/classes/com/xxx/yyy/apiConstants.class
我发现了一种hacky方式 - 在使用后删除sha1文件中的“target /”:
ant.checksum(fileext:".sha1", algorithm: "SHA", forceoverwrite: "yes", pattern: "{0} {3}") {
fileset(dir: "target/classes") {
include(name:"**/*.class")
}
}
ant.concat(destfile:"target/classes.sha1") {
fileset(dir: "target/classes") {
include(name:"**/*.sha1")
}
}
有更好的方法吗?
答案 0 :(得分:1)
要进行小幅优化改进,请考虑通过在replace
下嵌套filterchain
来删除concat
任务。
在以下示例中,replaceregex
过滤器使用正则表达式来匹配以哈希值开头,后跟字符串target/
的行。如果该行的开头匹配,则将其替换为已删除的target/
部分:
ant.concat(destfile:"target/classes.sha1") {
fileset(dir: "target/classes") {
include(name:"**/*.sha1")
}
filterchain {
tokenfilter {
// Using the regex "pattern" to match:
//
// "^": from the start of each line...
// "[0-9a-f]+": ...match as many hexadecimal characters as possible...
// " ": ...followed by a space character...
// "target/": ...followed by the string "target/".
//
// "([0-9a-f]+ )": captures the matching characters in group 1
//
// Then in "replace":
// "\\1": inserts capture group 1
//
replaceregex(pattern: "^([0-9a-f]+ )target/", replace: "\\1")
}
}
}
上面的示例避免了concat
将文件写入磁盘,然后replace
任务重新打开文件并重新写入文件的I / O惩罚。