2017-08-17 4 views
3

WAR Webアプリケーションを含むJava EARプロジェクトがあります。現在のWARファイル名を使用してアプリケーションを更新します。

私は、EARファイルを構築するのGradleを使用しています。

uberApp 
| 
\---> WarA 
|  | 
|  ...<src and config> 
| 
\---> WarB 
|  | 
|  ...<src and config> 
| 
\--> config/META-INF/application.xml 

これはuberAppのbuild.gradleですので、結果のファイル名は必ず手書きのバージョン番号が含まれていると...

war { 
    baseName = 'WarA' 
    version = '1.2.3_rev' + getSvnRevision() // provided by SvnKit 
} 

apply plugin: 'ear' 


dependencies { 
    deploy project(path: ':WarA/trunk', configuration: 'archives') 
    deploy project(path: ':WarB/trunk', configuration: 'archives') 

} 

ear { 
    appDirName 'config' 
} 

これは、WARのbuild.gradleですSVNコミット数:WarA-1.2.3_rev31337.war

は、しかし、私は私のを更新する必要がありますEARを組み込む前に、正しいWARファイル名のタグを含むを組み立ててください。

<?xml version="1.0"?> 
<application xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_6.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="6"> 
    <module> 
    <web> 
     <web-uri>WarA.war</web-uri> 
     <context-root>/WarA</context-root> 
    </web> 
    </module> 
    <module> 
    <web> 
     <web-uri>WarB.war</web-uri> 
     <context-root>/WarB</context-root> 
    </web> 
    </module> 
    <library-directory>lib</library-directory> 
</application> 

どのように私はこれを達成することができます

これはEAR application.xmlのですか?

答えて

1

が、より良いアプローチがあるが、私は私の目標はearビルド中に仕事をするためにグルーヴィーな機能を書いて実現することに。

これは私の完全なbuild.gradleです:

buildscript { 
    repositories { 
     mavenCentral() 
    } 
    dependencies { 
     // SvnKit from https://gist.github.com/thombergs/9279728 
     classpath group: 'org.tmatesoft.svnkit', name: 'svnkit', version: '1.8.14' 
    } 
} 


// SvnKit get svn revision 
import org.tmatesoft.svn.core.wc.* 
def getSvnRevision(){ 
     ISVNOptions options = SVNWCUtil.createDefaultOptions(true); 
     SVNClientManager clientManager = SVNClientManager.newInstance(options); 
     SVNStatusClient statusClient = clientManager.getStatusClient(); 
     SVNStatus status = statusClient.doStatus(projectDir, false); 
     SVNRevision revision = status.getRevision(); 
     return revision.getNumber(); 
     } 




// extract from file 
def extractfromfile(source, pattern) { 
    (source.text =~ pattern) [0] 
} 

// extract from string 
def extract(source, pattern) { 
    (source =~ pattern) [0] 
} 

// replace 
def ReplaceText(source, targetText, replaceText){ 
    source.write(source.text.replaceAll(targetText, replaceText)) 
} 


def updateApplicationXml() { 
    def applicationXml = new File('config/META-INF/application.xml') 
    def settingsGradle = new File('settings.gradle') 
    def prjRegex = "'(.*)'" 
    def prj = settingsGradle.text.split(',') 



    //for every project 
    List<String> list = new ArrayList<String>(Arrays.asList(prj)) 

    for(String item: list){ 

    def prjPath = extract(item, prjRegex)[1] 
    //println prjPath 


    //search for build.gradle 
    def buildGradle = new File(prjPath+'/build.gradle') 
    def basenamePattern = "baseName = '(.*)'" 
    def versionPattern = "version = '(.*)'" 

    //extract basename 
    def basename 
    try { 
     basename = extractfromfile(buildGradle, basenamePattern) 
    } catch (Exception ex){ 
     continue 
    } 

    //extract version 
    def version 
    try { 
     version = extractfromfile(buildGradle, versionPattern) 
    } catch (Exception ex){ 
     continue 
    } 

    def warname = basename[1] + "-" + version[1] + getSvnRevision() 

    // println basename[1] 
    // println version[1] 
    // println warname 
    // println applicationXml 


    // do the replace 
    ReplaceText(applicationXml, "<web-uri>"+basename[1]+"(.*).war</web-uri>", "<web-uri>"+warname+".war</web-uri>") 

    } 
} 

apply plugin: 'ear' 

dependencies { 
    deploy project(path: ':WarA/trunk', configuration: 'archives') 
    deploy project(path: ':WarB/trunk', configuration: 'archives') 

} 



ear { 
    updateApplicationXml() 
    appDirName 'config' 
} 
関連する問題