필자는 개미 스크립트에서 사용할 수있는 속성으로 ini 파일을 구문 분석하려고합니다. 나는 다음과 같습니다개미 : 설정 속성이 작동하지 않습니까?
<project name="DeployScript" default="deploy-staging" basedir=".">
<taskdef resource="net/sf/antcontrib/antcontrib.properties" />
<!-- The location of the settings.ini file -->
<property name="ini-file" location="../settings.ini" />
<loadfile property="iniConfig" srcFile="${ini-file}"/>
<target name="deploy-staging"
description="Deploy project to staging environment" >
<echo message="Ini file: ${ini-file}" />
<echo message="${lib}" />
<echo message="${store_dir}" />
<echo message="${ant.home}" />
<!--- walk the ini file's lines -->
<foreach list="${iniConfig}"
target="echoMsg"
param="line"
delimiter="${line.separator}" />
<echo message="HERE: ${prevSection}" />
</target>
<property name="prevSection" value="" />
<!-- this is executed for every line in the ini file. -->
<target name="echoMsg">
<!-- strip out the section name, variable name and value (if exists on the line) -->
<propertyregex property="secm"
input="${line}"
regexp="^\[(.*)\]"
select="\1"
casesensitive="false" />
<propertyregex property="name"
input="${line}"
regexp="^([\S]+)\s*=\s*([^;]+)"
select="\1"
casesensitive="false"
defaultValue="" />
<propertyregex property="value"
input="${line}"
regexp="^([\S]+)\s*=\s*([^;]+)"
select="\2"
casesensitive="false"
defaultValue="" />
<!-- overwrite the previous section if we have found a new one. -->
<if>
<isset property="secm" />
<then>
<echo message="PREVSECTION IS SET" />
<property name="prevSection" value="${secm}" />
</then>
</if>
<!-- display the information about the found data -->
<echo message="line = ${line}" />
<echo message="section = ${secm}" />
<echo message="name = ${name}" />
<echo message="value = ${value}" />
<echo message="new last section: ${prevSection}" />
<echo message="----" />
</target>
</project>
내가 모든 이름 = 값 쌍을 구문 분석과 같은 속성을 넣어 수행하려고 : section.name = 값;
어떻게 든 섹션은 "echoMsg"타겟 내에 기억되지 않습니다. 섹션 이름을 기억하고 싶습니다.
그래서,
[global]
name=var
name2=val
[section2]
name=var
이 될해야 : 마지막으로 "$ {prevSection
echoMsg:
[echo] PREVSECTION IS SET
[echo] line = [global]
[echo] section = global
[echo] name =
[echo] value =
[echo] new last section: global
[echo] ----
echoMsg:
[echo] line = servername = my-server.local ; Server name
[echo] section = ${secm}
[echo] name = servername
[echo] value = mac-mini-van-Peter.local7
[echo] new last section: ${prevSection}
[echo] ----
당신이 볼 수 있듯이 :
global.name=var
global.name2=val
section2.name=var
이 내 개미 스크립트의 출력 } "설정되지 않았습니다. 나는 그것이 "글로벌"이 될 것으로 기대합니다.
속성 대신 사용하려고했지만 아무런 차이가 없습니다.
에서 [''] (http://ant.apache.org/manual/Tasks/echoproperties.html) 작업을 사용해보십시오 : 그냥 WWW과 공유하고 싶었다 파일. 그러면 모든 속성이 나열되고 실제로 Ant에서 속성으로 설정되는 내용을 볼 수 있습니다. 그러면 오류가 어디에 있는지 알 수 있습니다. 개미에서 INI 파일을 사용한 적은 한번도 없었습니다. 그래서 어떻게 읽는지 모르겠습니다. –