설정되지 않은 경우에만 Ant 속성을 설정하는 방법
설정되지 않은 조건에서 Ant 속성을 설정하는 방법을 알아낼 수 없습니다 (즉, 속성 파일에 정의되어 있지 않고 자동으로 기본값이어야 함).
지금까지 다음 코드 만 있습니다.
<condition property="core.bin" value="../bin">
<isset property="core.bin"/>
</condition>
그러나 이것은 값이 <property>태그에 정의 된 경우에만 작동하는 것 같습니다 .
현재 설정되지 않은 경우 처음으로 속성을 조건부로 설정하는 방법을 아는 사람이 있습니까?
속성 작업으로 속성을 간단히 설정할 수 있습니다. 속성이 이미 설정된 경우 속성은 변경할 수 없기 때문에 값이 변경되지 않습니다.
그러나 상태에 'not'을 포함 할 수도 있습니다.
<condition property="core.bin" value="../bin">
<not>
<isset property="core.bin"/>
</not>
</condition>
Ant는 기본적으로이 작업을 수행합니다. 속성이 이미 설정된 경우; 다시 설정해도 효과가 없습니다.
<project name="demo" default="demo">
<target name="demo" >
<property name="aProperty" value="foo" />
<property name="aProperty" value="bar" /> <!-- already defined; no effect -->
<echo message="Property value is '${aProperty}'" /> <!-- Displays 'foo' -->
</target>
</project>
제공
/c/scratch> ant -f build.xml
Buildfile: build.xml
demo:
[echo] Property value is '${aProperty}'
BUILD SUCCESSFUL
Total time: 0 seconds
/c/scratch> ant -f build.xml
Buildfile: build.xml
demo:
[echo] Property value is 'foo'
BUILD SUCCESSFUL
속성은 재정의 할 수 없습니다. 이렇게하려면 ant-contrib 의 변수 작업 과 같은 것을 사용해야합니다 .
원하는 작업을 수행하는 가장 쉬운 방법 :
<if>
<not>
<isset property="your.property"/>
</not>
<then>
<property name="your.property" value="your.value"/>
</then>
</if>
정확한 목적을 달성하기 위해 https://ant.apache.org/manual/Tasks/condition.html 내에서 'else' 를 사용할 수 있습니다.
그밖에
The value to set the property to if the condition evaluates to false. By default the property will remain unset. Since Apache Ant 1.6.3
따라서 다음으로 변경하십시오.
<condition property="core.bin" else="../bin">
<isset property="core.bin"/>
</condition>
Ant의 속성은 변경할 수 없습니다. 정의 된 후에는 변경할 수 없습니다.
그러나 Ant Contrib 패키지는 variable작업을 제공합니다 . 속성처럼 작동하지만 값을 수정하고 설정을 해제 할 수 있습니다. 로부터 Exmaple 변수 작업 문서 :
<var name="x" value="6"/>
<if>
<equals arg1="${x}" arg2="6" />
<then>
<var name="x" value="12"/>
</then>
</if>
<echo>${x}</echo> <!-- will print 12 -->
참고 URL : https://stackoverflow.com/questions/828846/how-to-set-an-ant-property-only-if-it-is-unset
'Program Club' 카테고리의 다른 글
| PHP Try Catch 블록에서 예외 발생 (0) | 2020.11.06 |
|---|---|
| 모바일 웹에서 핀치 줌 비활성화 (0) | 2020.11.06 |
| grep에서 새 줄에 패턴을 제공하는 방법은 무엇입니까? (0) | 2020.11.06 |
| 사용자 'root'@ 'localhost'에 대한 액세스가 거부되었습니다 (비밀번호 사용 : YES)-권한이 없습니까? (0) | 2020.11.06 |
| UITextView에서 프로그래밍 방식으로 iOS8 Quicktype 키보드 비활성화 (0) | 2020.11.06 |