Map a list of strings to a collection of file resources for a dependset

后端 未结 1 1230
情话喂你
情话喂你 2021-01-28 17:35

Background: I read names from an XML file and want to map them to source and target paths for a build task. I am not an experienced Ant user and I\'m looking for a way to that

1条回答
  •  庸人自扰
    2021-01-28 18:11

    ANT is not a programming language. Easy to embed groovy.

    Example

    ├── build.xml
    ├── sample.xml
    ├── src
    │   ├── file1.txt
    │   ├── file2.txt
    │   └── file3.txt
    └── target
        ├── file1.txt
        └── file2.txt
    

    Run as follows

    $ ant
    Buildfile: /.../build.xml
    
    install-groovy:
    
    build:
         [copy] Copying 2 files to /.../target
         [copy] Copying /.../src/file1.txt to /.../target/file1.txt
         [copy] Copying /.../src/file2.txt to /.../target/file2.txt
    
    BUILD SUCCESSFUL
    

    sample.xml

    
    file1
    file2
    
    

    build.xml

    
    
        
        
        
        
    
         
    
            
        
            
            
            def xmllist = new XmlSlurper().parse(new File("sample.xml"))
    
            ant.copy(todir:properties["build.dir"], verbose:true, overwrite:true) {
               fileset(dir:properties["src.dir"]) {
                  xmllist.value.each {
                    include(name:"${it}.${properties["src.ext"]}") 
                  }
               }
            }
            
        
    
        
           
        
    
        
            
            
            
        
    
    
    

    0 讨论(0)
提交回复
热议问题