tampe125
tampe125

Reputation: 8511

Exclude files with Ant

i'm creating a PHP project and i'd wish to distribuite 2 version: a free one and a pro one.

Enhanced features are all inside some files, so i only have to "skip" them to create the free version.
My question is: which is the best way to achieve that?
i can list every file in the build.xml file (they are 20 at max), but it's pretty ugly, moreover if i forgot to update the list i will ad these files...

i thought about using the contains keyword, but it will slow my build?

EDIT
This is my build.xml file:

<project name="MyProject" default="build" basedir=".">
<property name="buildDir"   value="${basedir}/build"/>
<property name="componente" value="${basedir}/trunk/componente"/>
<property name="backend"    value="${componente}/backend"/>
<property name="frontend"   value="${componente}/frontend"/>

<target name="build" depends="cleanup, pro, free" />

<!-- Clean up the build directory output -->
<target name="cleanup">
    <echo>Clean up build directory</echo>
    <delete includeemptydirs="true">
        <fileset dir="${buildDir}" includes="**/*"/>
    </delete>
</target>

<!-- Create the pro package (no file exclusion) -->
<target name="pro">
    <echo>Build pro version</echo>
    <zip destfile="${buildDir}/pro.zip" basedir="${componente}" />
</target>

<!-- Create the free package (file exclusion) -->
<target name="free">
    <echo>Build free version</echo>
</target>

EDIT 2 My pro files are in different folders and i can't move them since i'm using the MVC pattern

Upvotes: 2

Views: 755

Answers (3)

tampe125
tampe125

Reputation: 8511

ok, i found it. i added a PHPDoc tag into my exclude files:
@category ProPackage

then i added these rules in my build.xml

<target name="free">
    <zip destfile="${buildDir}/pro.zip">
        <fileset dir="${componente}">
            <not>
                <containsregexp expression="@category[ \t]+ProPackage"/>
            </not>
        </fileset>
    </zip>
</target>

And it's done!

Upvotes: 0

Gordon
Gordon

Reputation: 316939

Quoting the Ant Manual:

The zip task forms an implicit FileSet and supports most attributes of <fileset> (dir becomes basedir) as well as the nested <include>, <exclude> and <patternset> elements.

Which means you can do

<zip destfile="${buildDir}/free.zip"
     basedir="${componente}"
     excludes="**/features/pro/**, **/other/**"/>

Regarding

EDIT 2 My pro files are in different folders and i can't move them since i'm using the MVC pattern

MVC is not about folder layout at all. It's about roles and responsibilities. It says nothing about where to put files. Some frameworks conventionalize where to put class files, but as long as your autoloader can find the class files, it really doesnt matter where they are: so yes, you can move them.

Upvotes: 1

FailedDev
FailedDev

Reputation: 26920

You can simply use filesets :

http://ant.apache.org/manual/Types/fileset.html

<fileset dir="${files.directory}" casesensitive="yes">
  <include name="**/*free.php"/>
  <exclude name="**/*pro.php"/>
</fileset>

Of course you have to provide different names in the include/exclude elements. Ideally you could separate the pro stuff to a different file and simply exclude the whole directory.

Upvotes: 0

Related Questions