Propel Build Process With Eclipse

This document shows developers a way how to use PHPEclipse and the Eclipse workbench to run der Propel build process with Ant. It is assumed that you are working on several independent projects which use Propel.

Introduction

By default the Propel generator uses the path /propel/generator/projects to hold the files for a project, e.g. the build.properties, runtime-conf.xml and schema.xml as well as the build output.

In your Eclipse workbench you would want to edit these files, but Propel might be installed to a different path than your project path. There are three options how to edit the files Propel needs for the build process:

  1. Create a new project within Eclipse for your Propel installation
  2. Set a link to the corresponding Propel project path in each of your projects
  3. Keep the Propel build.properties, runtime-conf.xml and schema.xml files within your project

Even though the first two options are quite easy to setup they are both not very handy. With the third option you would be able to keep all files in the same Eclipse project which belong to a single project. Furthermore, it would be very nice to run the Propel build process within the Eclipse workbench.

Organize your projects

First, you have to organize your projects. Here is an example how you could organize the files for two projects and Propel:

# your propel and phing installation
/_system/phing/
/_system/propel/

# project 1
/project1/_model/    holds files for Propel build process
/project1/_php/cfg/   holds configuratin files
/project1/_php/dob/   holds generated Propel data object classes
/project1/_php/sql/   holds SQL files
/project1/website/    your website root path

# project 2
/project2/_model/    holds files for Propel build process e.g. build.properties
/project2/_php/cfg/   holds configuratin files
/project2/_php/dob/   holds generated Propel data object classes
/project2/_php/sql/   holds SQL files
/project2/website/    your website root path

Create your build.properties for Propel

We assume that your runtime-conf.xml and schema.xml are already set up properly and saved in the /project1/_model/ path. Next you can create the build.properties file in the /project1/_model/ path.

The build.properties file will contain the properties for the Propel build process as well as the properties needed by Ant. Here is an example of a build.properties file on a Windows environment.

#  A N T   P R O P E R T I E S

php.command = C:/wamp/php5/php.exe
phing.home = E:/_system/phing
propel.home = E:/_system/propel
project.home = E:/project1
project.build = ${project.home}/_model

#  B A S I C   P R O P E R T I E S

propel.project = project1
propel.database = mysql
propel.targetPackage = project1

#  D A T A B A S E   S E T T I N G S

propel.database.url = mysql://root:@localhost/project1
propel.mysql.tableType = InnoDB

#  D I R E C T O R I E S

propel.schema.dir = ${project.build}
propel.conf.dir = ${project.build}
propel.templatePath = ${propel.home}/generator/templates

propel.output.dir = ${project.home}
propel.php.dir = ${propel.output.dir}/_php/dob
propel.phpconf.dir = ${propel.output.dir}/_php/cfg
propel.sql.dir = ${propel.output.dir}/_php/sql

#  D E F A U L T   F I L E   N A M E S

propel.runtime.phpconf.file = config.php

The Ant properties will be used by Ant when processing the build.xml file. Please see below.

The Directory properties are the important part. With the propel.schema.dir and the propel.conf.dir properties Propel will know where to find the schema.xml and the runtime-conf.xml file. The property propel.templatePath needs to be set because otherwise Propel will not find the templates in the generator path. The other four directory properties are set for the output.

Create your build.xml for Ant

This build.xml is used by Ant and should not be confused with the build.xml which is needed by Propel. Now you can setup four targets:

  1. to create the schema.xml file from an existing database
  2. to build the application
  3. to create the database
  4. to run the created SQL file

The properties will be taken from the build.properties you created before. Here is our build.xml file:

<project name="Project1">
  <property file="build.properties" />
  <target name="Create Schema" description="creates schema.xml from DB">
    <exec dir="${propel.home}/generator" executable="${php.command}">
      <arg line="${phing.home}/bin/phing.php -Dproject.dir=${project.build} -Dproject=${propel.project} creole" />
    </exec>
  </target>
  <target name="Propel Build" description="build the application">
    <exec dir="${propel.home}/generator" executable="${php.command}">
      <arg line="${phing.home}/bin/phing.php -Dproject.dir=${project.build} -Dproject=${propel.project}" />
    </exec>
  </target>
  <target name="Create Database" description="create the database">
    <exec dir="${propel.home}/generator" executable="${php.command}">
      <arg line="${phing.home}/bin/phing.php -Dproject.dir=${project.build} -Dproject=${propel.project} -Dtarget=create-db" />
    </exec>
  </target>
  <target name="Run SQL" description="run the SQL file">
    <exec dir="${propel.home}/generator" executable="${php.command}">
      <arg line="${phing.home}/bin/phing.php -Dproject.dir=${project.build} -Dproject=${propel.project} -Dtarget=insert-sql" />
    </exec>
  </target>
</project>

Add buildfile to Ant

Next, you can open the Ant view in the Eclipse workbench with "Window > Show View > Other > Ant". In the Ant view you use the "Add Buildfiles" button and select the build.xml file from your project. No the build file is listed in your Ant view. Even the four targets are listed.

Run the build targets

Now, you can choose the "Propel Build" target and click the "Run" button. The build.xml file is processed by Ant and the Console view will be opened by Eclipse. You can watch the Propel build process and look out for any warnings or errors. If successful your output directories should be filled with the OM classes, the configuration file and the SQL files.

You can easily run the other build targets to create the database, run the SQL file or rebuild your schema.xml from an existing database.

Conclusion

Congratulations, you are done. Once setup, you can easily manage the Propel build process and edit the build.properties and your schema.xml now within your Eclipse projects.