我的第一个 Augeas 脚本如下所示:
set /augeas/load/Properties/lens Properties.lns
set /augeas/load/Properties/incl /firstapp/WEB-INF/classes/some.properties
load
set /files/firstapp/WEB-INF/classes/some.properties/PROPERTY_1 "VALUE A"
set /files/firstapp/WEB-INF/classes/some.properties/PROPERTY_2 "VALUE B"
set /files/firstapp/WEB-INF/classes/some.properties/PROPERTY_3 "VALUE C"
save
set /augeas/load/Properties/lens Properties.lns
set /augeas/load/Properties/incl /secondapp/WEB-INF/classes/more.properties
load
set /files/secondapp/WEB-INF/classes/more.properties/PROPERTY_4 "VALUE D"
set /files/secondapp/WEB-INF/classes/more.properties/PROPERTY_5 "VALUE E"
set /files/secondapp/WEB-INF/classes/more.properties/PROPERTY_6 "VALUE F"
save
我用例如运行它:
augtool -LeAf adjust-properties.aug -r $WEB_SERVER_ROOT/
现在我想知道是否可以通过不一直重复重复出现的路径元素来缩短脚本。
解决方案
根据这个答案,我可以将我的脚本更新为:
transform Properties.lns incl /firstapp/WEB-INF/classes/some.properties
transform Properties.lns incl /secondapp/WEB-INF/classes/more.properties
load
set /augeas/context /files/firstapp/WEB-INF/classes/some.properties
set PROPERTY_1 "VALUE A"
set PROPERTY_2 "VALUE B"
set PROPERTY_3 "VALUE C"
set /augeas/context /files/secondapp/WEB-INF/classes/more.properties
set PROPERTY_4 "VALUE D"
set PROPERTY_5 "VALUE E"
set PROPERTY_6 "VALUE F"
save