Groovy 是適用於 Java™ 平台的動態 Scripting 語言(類似於 Python、Ruby 和 Perl)。大部分 Java 程式碼也是語法上有效的 Groovy,這讓 Groovy 很受 Java 程式設計師歡迎。Groovy 為正規表示式提供了原生支援。
如果要從使用者介面擷取內容並將內容提供給 Script,請如下列程式碼 Snippet 中所示匯入 AirPluginTool:
import com.urbancode.air.*
final def workDir = new File('.').canonicalFile
def apTool = new AirPluginTool(this.args[0], this.args[1]);
def props = apTool.getStepProperties();
AirPluginTool 程式碼在 Jazz.net 上隨 groovy-plugin-utils 專案一起提供。 您還可以在 http://search.maven.org 網站上搜尋 com.ibm.urbancode.plugins 以下載包含 groovy-plugin-utils 專案的 .jar 檔案。
匯入 AirPluginTool 之後,可透過下列語法依名稱存取內容:props['propertyName']。
依預設下列內容可用:
預設內容顯示於下列程式碼 Snippet 中:
this.integrationProviderID = props['releaseIntegrationProvider'];
this.releaseToken = props['releaseToken'];
this.serverUrl = props['releaseServerUrl'];
下列程式碼 Snippet 顯示如何存取 property-group 元素中的對映值。property-group 元素由下列程式碼定義:
<property-group depends="oslcUrl,oslcKey,oslcSecret,projectArea,query" name="mappingRelease" title="Release Mapping" description="Select a release and planned-for items" type="mappingBox" >
<property parent="mappingRelease" name="timelines">
<property-ui description="Timelines from Rational Team Concert" label="Timelines" type="scriptedCheckedMultiSelectBox"/>
<scripted-prop-info source="Timelines" labelPath="label" valuePath="value" basePath="" dataFormat="JSON" dataSourceType="COMMAND" />
</property>
<property parent="mappingRelease" name="releases">
<property-ui description="UrbanCode Releases" label="Releases" type="httpCheckedMultiSelectBox"/>
<http-prop-info username="${releaseUser}" password="${releasePassword}" url="${releaseUrl}/releases?format=list" labelPath="name" valuePath="id" basePath="" dataFormat="JSON" />
</property>
</property-group>
下列程式碼 Snippet 用於存取對映值:
//Main constructor
this.mappingStatuses = props['mappingStatuses']
this.mappingRelease = props['mappingRelease']
this.mappingApplication = props['mappingApplication']
this.mappingSeverities = props['mappingSeverities']
this.mappingTypes = props['mappingTypes']
this.initiatives = props['initiatives']
如果要從儲存對映值的 JSON 陣列存取對映值,則使用類似下列 Snippet 的程式碼:
def slurper = new groovy.json.JsonSlurper()
def fullMapping = slurper.parseText(mappingRelease)
fullMapping.each {
def timelineId = it.timelines
def releaseId = it.releases
}
如果要進一步瞭解使用 REST API,請參閱 Java 用戶端檔案庫。