2017-02-23 58 views
1

嗨在詹金斯/螞蟻/ groovy世界新的和谷歌無法幫助我解決我的問題。轉換爲groovy腳本的Ant腳本javac命令AntBuilder.javac

我的任務是擺脫構建過程中的螞蟻腳本(使用jenkins)並將它們包含到jenkins作業中(執行系統Groovy腳本)。

我腳本的大膽部分是失敗的原因,但我不知道如何解決這個問題。

我希望有人能幫助我解決這個問題。

這是我的「執行系統Groovy腳本」:

antbuild = new AntBuilder() 
projectHome = '...Homedirectory' 

projectDomainModel = projectHome + '/CSSDomainModel' 
projectPresentationBase = projectHome + '/CSSPresentationBase' 
projectServices = projectHome + '/CSSServices' 
projectResource = projectHome + '/src/main/resources' 

Sources = projectHome + '/Presentation/JavaSource' 
projectLibraries = 'lib/bin' 
projectWebContent = projectHome + '/Presentation/WebContent' 
projectWebInf = projectWebContent + '/WEB-INF' 

deployHome = projectHome + '/target/servicekundenportal' 
deployBuild = deployHome + '/build/classes' 
deployWebInf = deployHome + '/WEB-INF' 

foreignSources = 'src' 

deployWARFile = deployHome + '/serviceportal.war' 

j2eeLibraries = 'D:/Programme_x64/tomcat/8.0.21/Instanz_02/lib' 
compileTarget = '1.8' 

<b>compilerSourceFiles = antbuild.path{ 
     pathelement(path:Sources) 
     pathelement(path:projectDomainModel + '/' + foreignSources) 
     pathelement(path:projectPresentationBase + '/' + foreignSources) 
     pathelement(path:projectServices + '/' + foreignSources) 
     } 

compilerLibraryFiles = antbuild.path{ 
     fileset(dir:projectDomainModel + '/' + projectLibraries) {include name:'**/*.jar'} 
     fileset(dir:projectPresentationBase + '/' + projectLibraries) {include name:'**/*.jar'} 
     fileset(dir:projectServices + '/' + projectLibraries) {include name:'**/*.jar'} 
     fileset(dir:j2eeLibraries) {include name:'**/*.jar'} 
     }</b> 

antbuild.delete(dir:deployHome) 
antbuild.delete(file:deployWARFile) 
antbuild.mkdir(dir:deployBuild) 

build() { 

     antbuild.javac(
      destdir:deployBuild, 
      target:compileTarget, 
      debug:true, 
      fork:true, 
      executable:'D:/Programme_x64/Java/jdk1.8.0_45/bin/javac')<b>{ 
       src(path:compilerSourceFiles) 
       classpath(path:compilerLibraryFiles) 
       }</b> 
     } 

build() 

Ant腳本的一部分,我不能夠轉換:

<!-- Compiler Source File Definition --> 
    <path id="compilerSourceFiles"> 
     <pathelement path="${Sources}" /> 
     <pathelement path="${projectDomainModel}/${foreignSources}" /> 
     <pathelement path="${projectPresentationBase}/${foreignSources}" /> 
     <pathelement path="${projectServices}/${foreignSources}" /> 
    </path> 

    <!-- Compiler Library Definition --> 
    <path id="compilerLibraryFiles"> 
     <fileset id="librariesDomainModel" dir="${projectDomainModel}/${projectLibraries}"> 
      <include name="**/*.jar" /> 
     </fileset> 
     <fileset id="librariesPresentationBase" dir="${projectPresentationBase}/${projectLibraries}"> 
      <include name="**/*.jar" /> 
     </fileset> 
     <fileset id="librariesServices" dir="${projectServices}/${projectLibraries}"> 
      <include name="**/*.jar" /> 
     </fileset> 
     <fileset dir="${j2eeLibraries}"> 
      <include name="**/*.jar" /> 
     </fileset> 
    </path> 



    <target name="executeCompiler" depends="preCompile"> 
      <javac destdir="${deployBuild}" target="${compileTarget}" 
       debug="true" debuglevel="lines,vars" encoding="ISO8859-1"> 
       <src refid="compilerSourceFiles" /> 
       <classpath refid="compilerLibraryFiles" /> 
      </javac> 
     </target> 

回答

0

你比如有一些太多的依賴在本地目錄結構等進行全面複製,但使用類似下面的內容作爲模式應該讓你朝着正確的方向前進:

def ant = new AntBuilder() 

def projectHome = '...Homedirectory' 

ant.path(id: 'compilerSourceFiles') { 
    pathelement(path: "$projectHome/Presentation/JavaSource") 
    pathelement(path: "$projectHome/CSSDomainModel/src") 
    pathelement(path: "$projectHome/CSSPresentationBase/src") 
    pathelement(path: "$projectHome/CSSServices/src") 
} 

ant.path(id: "compilerSourceFiles") { 
    fileset(id: "librariesDomainModel", dir: "$projectHome/CSSDomainModel/lib/bin") { 
    include(name: "**/*.jar") 
    } 
    fileset(id: "librariesPresentationBase", dir: "....") { 
    include(name: "**/*.jar") 
    } 
    //... 
} 

ant.target(name: 'executeCompiler', depends: 'preCompile') { 
    javac(destDir: "...", target: "...", debug: true, debugLevel: "lines,vars", encoding: "...") { 
    src(refid: "compilerSourceFiles") 
    classpath(refid: "compilerLibraryFiles") 
    } 
} 

換言之,每個螞蟻XML片段:

<outerelement outerattribute="outervalue"> 
    <innerelement innerattribute="innervalue" /> 
</outerelement> 

被轉換爲:

ant.outerelement(outerattribute: "outervalue") { 
    innerelement(innerattribute: "innervalue") 
} 

使用AntBuilder時。

+0

我的評論太長了,所以我把它寫成了答案:)。順便說一句,我是否使用雙引號「和單引號」的權利? – Denyo

+0

兩個引號在Groovy中是有效的,如果你不需要任何$ {}表達式在你的字符串中,那麼兩個引號都是有效的。 –