1

I am trying to do the following in ANT but I am stuck.


  1. Read which projects are installed in my project workspace.

    workspace
        buildtools
            build.xml
        project1
            build.xml
                project.name = "project1"
                IP = "44.55.66.77"
                SERVER_NAME = "project1.local"
                DOCUMENT_ROOT = "c:\inetpub\project1"
        project2
            build.xml
                project.name = "project2"
                IP = "44.55.66.77"
                SERVER_NAME = "project2.local"
                DOCUMENT_ROOT = "c:\inetpub\project2"
        ....
    
  2. Create an Apache virtualhost directive for each project.

    <VirtualHost 44.55.66.77>
       DocumentRoot "c:\inetpub\project1"
       ServerName project1.local
    </VirtualHost>
    
    <VirtualHost 44.55.66.77>
       DocumentRoot "c:\inetpub\project2"
       ServerName project2.local
    </VirtualHost>
    ....
    
  3. Concatenate the virtualhost directives into an Apache configuration file.


I have spent many hours studying the different tasks that I could use. Concat, loadproperties, fileset, filterreaders, etc.. I get overwhelmed with all the possibilities and my head spins.

Here is my horrible guess at how this might be done:

<concat destfile={$apache.config.file}>
    <fileset>
        <include name="**/build.xml"/>
        <loadproperties resource="fileset.item.project.name???"/>
        <filterchain>       
            <replacetokens>
                <token key="IP"
                       value="${p.IP}"/>
                <token key="DOCUMENT_ROOT"
                       value="${p.DOCUMENT_ROOT}"/>
                <token key="SERVER_NAME"
                       value="${p.SERVER_NAME}"/>                   
            </replacetokens>        
        </filterchain>
    </fileset>
<concat>

Thanks for the help!

dbasch
  • 1,698
  • 1
  • 15
  • 31
  • don't follow exactly: where are the IP/DOCUMENT_ROOT/SERVER_NAME values defined - in a properties file under each project? Or in the build.xml under each project? It looks like buildtools shouldn't generate a virtual host directive - is that right? – martin clayton Jul 20 '10 at 20:59
  • You are correct. Sorry, I should have been clearer. Question edited. – dbasch Jul 20 '10 at 23:21
  • To be clearer; I usually have my per project properties defined in files under each project. I show them as part of build.xml above for brevity. – dbasch Jul 20 '10 at 23:23

1 Answers1

0

I think basically you shouldn't load build.xml files containing properties as standard property files as they are not property files (I mean key=value per line files). You should import them if you need the stuff from them.

I suggest you doing such things with a Groovy snippet.

<!-- this is only a sketch, not a working solution -->
<path id="gr">
  <pathelement location="/path/to/groovy-all.jar"/>
</path>

<taskdef name="groovy"
             classname="org.codehaus.groovy.ant.Groovy"
             classpathref="gr"/>


<groovy>
def b1 = new XmlParser().parse(new File("project1/build.xml")));
def b2 = new XmlParser().parse(new File("project2/build.xml")));

def f = new File("output.xml");
def ip1 = b2.property.find { it.name == 'IP'}.text();
def ip2 = ..
// get out all the stuff you need from the build.xml files with GPath

f.write("<VirtualHost ${ip1}>");
f.write("  DocumentRoot ${r1}");
f.write("  ServerName ${s1}");
f.write("<VirtualHost>");

</groovy>
jabal
  • 11,987
  • 12
  • 51
  • 99