Skip to content

Instantly share code, notes, and snippets.

@enmaku
Created September 25, 2013 02:32
Show Gist options
  • Save enmaku/6694467 to your computer and use it in GitHub Desktop.
Save enmaku/6694467 to your computer and use it in GitHub Desktop.
broadleaf build.xml
<?xml version="1.0" encoding="UTF-8"?>
<project name="site" default="build-app" basedir="."
xmlns:artifact="antlib:org.apache.maven.artifact.ant"
xmlns:rsel="antlib:org.apache.tools.ant.types.resources.selectors">
<!-- import the ant / maven integration tasks -->
<path id="maven-ant-tasks.classpath" path="../lib/maven-ant-tasks-2.1.3.jar" />
<typedef resource="org/apache/maven/artifact/ant/antlib.xml" uri="antlib:org.apache.maven.artifact.ant" classpathref="maven-ant-tasks.classpath" />
<property name="project.root" location="../../"/>
<property name="project.name" value="site" />
<!-- See the following URL for a description of this property file strategy -->
<!-- The only difference is we prepend a . for the home directory property files -->
<!-- http://www.javaranch.com/ant/properties.jsp -->
<property file="${user.home}/.${project.name}.properties"/>
<property file="${user.home}/.build.properties"/>
<property name="config.filename" value="${user.name}.properties"/>
<property file="config/${config.filename}"/>
<property file="../build.properties"/>
<property name="runtime.environment" value="development"/>
<target name="tomcat-demo" depends="start-db">
<delete dir="war/WEB-INF/lib"/>
<artifact:mvn mavenHome="${maven.home}" fork="true" jvmargs="-DbroadleafCoreDirectory=${broadleafCoreDirectory} -DbroadleafWorkspaceDirectory=${broadleafWorkspaceDirectory} -XX:MaxPermSize=256M -Xmx512M">
<arg value="compile"/>
<arg value="war:exploded"/>
<arg value="tomcat6:run-war"/>
</artifact:mvn>
</target>
<target name="jetty-demo-no-db">
<delete dir="war/WEB-INF/lib"/>
<artifact:mvn mavenHome="${maven.home}" fork="true">
<jvmarg value="-XX:MaxPermSize=256M" />
<jvmarg value="-Xmx512M" />
<jvmarg value="-Xdebug" />
<jvmarg value="-Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n" />
<jvmarg value="-Druntime.environment=${runtime.environment}" />
<arg value="compile"/>
<arg value="war:exploded"/>
<arg value="jetty:run"/>
</artifact:mvn>
</target>
<target name="jetty-demo" depends="start-db">
<delete dir="war/WEB-INF/lib"/>
<artifact:mvn mavenHome="${maven.home}" fork="true">
<jvmarg value="-XX:MaxPermSize=256M" />
<jvmarg value="-Xmx512M" />
<jvmarg value="-Xdebug" />
<jvmarg value="-Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n" />
<jvmarg value="-Druntime.environment=${runtime.environment}" />
<arg value="compile"/>
<arg value="war:exploded"/>
<arg value="jetty:run"/>
</artifact:mvn>
</target>
<target name="jetty-demo-jrebel" depends="start-db">
<delete dir="war/WEB-INF/lib"/>
<artifact:mvn mavenHome="${maven.home}" fork="true">
<jvmarg value="-XX:MaxPermSize=256M" />
<jvmarg value="-Xmx512M" />
<jvmarg value="-Xdebug" />
<jvmarg value="-Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n" />
<jvmarg value="-Drebel.root=${project.root}" />
<jvmarg value="-Dlogs.dir=${logs.dir}" />
<jvmarg value="-noverify" />
<jvmarg value="-javaagent:${jrebel.path}" />
<jvmarg value="-Druntime.environment=${runtime.environment}" />
<arg value="compile"/>
<arg value="war:exploded"/>
<arg value="jetty:run"/>
</artifact:mvn>
</target>
<target name="jetty-stop">
<artifact:mvn mavenHome="${maven.home}" fork="true">
<jvmarg value="-XX:MaxPermSize=256M" />
<jvmarg value="-Xmx512M" />
<arg value="jetty:stop"/>
</artifact:mvn>
</target>
<target name="stop-all" depends="jetty-stop, stop-db"/>
<!-- Project Reference Targets -->
<!-- build the application and create the war artifact -->
<target name="build-app">
<delete dir="war/WEB-INF/lib"/>
<artifact:mvn mavenHome="${maven.home}" fork="true">
<arg value="-Dmaven.test.skip=true"/>
<arg value="install"/>
</artifact:mvn>
</target>
<target name="start-db">
<!-- retrieve the web project pom file and import its jar dependencies -->
<artifact:pom id="warPom" file="pom.xml"/>
<artifact:dependencies filesetId="warDeps" pomRefId="warPom" useScope="test" />
<path id="build.runtime.classpath">
<fileset refid="warDeps"/>
</path>
<echo message="Starting Data Base..." />
<java fork="true" spawn="true" classname="org.hsqldb.Server" classpathref="build.runtime.classpath">
<arg line="-database.0 file:data/broadleaf -dbname.0 broadleaf"/>
</java>
</target>
<target name="stop-db">
<echo message="Execute SQL on new Data Base..." />
<artifact:pom id="warPom" file="pom.xml"/>
<artifact:dependencies filesetId="warDeps" pomRefId="warPom" useScope="test" />
<path id="build.runtime.classpath">
<fileset refid="warDeps"/>
</path>
<sql
autocommit="true"
print="true"
classpathref="build.runtime.classpath"
driver="org.hsqldb.jdbcDriver"
url="jdbc:hsqldb:hsql://localhost/broadleaf;ifexists=true"
userid="sa"
password="">
<transaction>SHUTDOWN</transaction>
</sql>
<echo message="SQL Executed on data base..." />
</target>
<target name="build-create-sql" >
<!--wrapping spring instrument jar-->
<echo>
Creating schema insert files
</echo>
<mkdir dir="target/sql/create"/>
<java classname="org.apache.tools.ant.launch.Launcher"
fork="true"
failonerror="true"
dir="."
timeout="4000000"
taskname="startAnt">
<classpath>
<pathelement location="${ant.home}/lib/ant-launcher.jar"/>
</classpath>
<!--uncomment the following spring insturment jar argument if you require spring instrument-->
<!--<jvmarg value="-javaagent:${spring.instrument.path}"/>-->
<jvmarg value="-XX:MaxPermSize=512M" />
<jvmarg value="-Xmx1024M" />
<arg value="-buildfile"/>
<arg file="build.xml"/>
<arg value="create-sql"/>
</java>
</target>
<target name="create-sql">
<!--
You will need to run a mvn install on your project before attempting to execute this task.
Also, you will likely need to assign additional heap space to your ANT process. A setting
of -XX:MaxPermSize=256M -Xmx512M should be sufficient.
This can be done by populating the 'ANT_OPTS' environment variable:
export ANT_OPTS=-XX:MaxPermSize=256M -Xmx512M
which will ensure those settings for all ant processes. Alternatively you could use JAVA_OPTS which is for
the global JVM and will effect all Java processes.
-->
<mkdir dir="target/sql/create"/>
<artifact:pom id="myPom" file="pom.xml" />
<artifact:dependencies filesetId="pomDeps" pomRefId="myPom" useScope="compile" />
<property name="baseTarget" location="target/${myPom.build.finalName}/WEB-INF"/>
<fileset id="libDir" dir="${baseTarget}/lib"/>
<path id="build.runtime.classpath">
<!--There are some additional libraries needed at compile time that are not included
in WEB-INF/lib - find those libraries via a difference algorithm-->
<restrict>
<difference>
<fileset refid="pomDeps" />
<intersect>
<fileset refid="pomDeps" />
<fileset refid="libDir" />
</intersect>
</difference>
<rsel:not>
<rsel:name name="**/*.pom" />
</rsel:not>
</restrict>
<!--Add the lib directory to get all the dependencies required for the demo app-->
<fileset refid="libDir"/>
<dirset dir="src/main/resources" />
<!--Add the classes directory in the war project, if required-->
<!--<pathelement location="${baseTarget}/classes"/>-->
</path>
<!--If the war project does not contain custom entities (best practice), then it is not necessary to include application context from the WEB-INF directory-->
<!--<property name="my.app.context" location="src/main/webapp/WEB-INF/applicationContext.xml"/>-->
<taskdef name="hibernatetool" classname="org.broadleafcommerce.common.util.sql.HibernateToolTask" classpathref="build.runtime.classpath"/>
<hibernatetool destDir="target/sql/create" combinePersistenceUnits="false" refineFileNames="true">
<!--add in additional persistence configuration related to the cms -->
<classPathApplicationContext path="bl-cms-contentClient-applicationContext.xml"/>
<classPathApplicationContext path="bl-open-admin-contentClient-applicationContext.xml"/>
<!--add in additional persistence configuration for our core -->
<classPathApplicationContext path="applicationContext.xml"/>
<!--see description for my.app.context above -->
<fileSystemApplicationContext path="src/main/webapp/WEB-INF/applicationContext.xml"/>
<classPathApplicationContext path="bl-fake-applicationContext-ant.xml"/>
<!--select the dialects and persistence units to export-->
<jpaconfiguration persistenceUnit="blPU" dialect="${ant.hibernate.sql.ddl.dialect}" />
<jpaconfiguration persistenceUnit="blSecurePU" dialect="${ant.hibernate.sql.ddl.dialect}" />
<jpaconfiguration persistenceUnit="blCMSStorage" dialect="${ant.hibernate.sql.ddl.dialect}" />
<!--other required elements-->
<classpath refid="build.runtime.classpath" />
<hbm2ddl export="false" update="false" create="true"/>
</hibernatetool>
</target>
<target name="build-update-sql" >
<!--wrapping spring instrument jar-->
<echo>
Creating schema insert files
</echo>
<mkdir dir="target/sql/create"/>
<java classname="org.apache.tools.ant.launch.Launcher"
fork="true"
failonerror="true"
dir="."
timeout="4000000"
taskname="startAnt">
<classpath>
<pathelement location="${ant.home}/lib/ant-launcher.jar"/>
</classpath>
<!--uncomment the following spring insturment jar argument if you require spring instrument-->
<!--<jvmarg value="-javaagent:${spring.instrument.path}"/>-->
<jvmarg value="-XX:MaxPermSize=512M" />
<jvmarg value="-Xmx1024M" />
<arg value="-buildfile"/>
<arg file="build.xml"/>
<arg value="update-sql"/>
</java>
</target>
<target name="update-sql">
<!--
You will need to run a mvn install on your project before attempting to execute this task.
Also, you will likely need to assign additional heap space to your ANT process. A setting
of -XX:MaxPermSize=256M -Xmx512M should be sufficient.
This can be done by populating the 'ANT_OPTS' environment variable:
export ANT_OPTS=-XX:MaxPermSize=256M -Xmx512M
which will ensure those settings for all ant processes. Alternatively you could use JAVA_OPTS which is for
the global JVM and will effect all Java processes.
-->
<mkdir dir="target/sql/update"/>
<artifact:pom id="myPom" file="pom.xml" />
<artifact:dependencies filesetId="pomDeps" pomRefId="myPom" useScope="compile" />
<property name="baseTarget" location="target/${myPom.build.finalName}/WEB-INF"/>
<fileset id="libDir" dir="${baseTarget}/lib"/>
<path id="build.runtime.classpath">
<!--There are some additional libraries needed at compile time that are not included
in WEB-INF/lib - find those libraries via a difference algorithm-->
<restrict>
<difference>
<fileset refid="pomDeps" />
<intersect>
<fileset refid="pomDeps" />
<fileset refid="libDir" />
</intersect>
</difference>
<rsel:not>
<rsel:name name="**/*.pom" />
</rsel:not>
</restrict>
<!--Add the lib directory to get all the dependencies required for the demo app-->
<fileset refid="libDir"/>
<dirset dir="src/main/resources" />
<!--Add the classes directory in the war project, if required-->
<!--<pathelement location="${baseTarget}/classes"/>-->
</path>
<!--If the war project does not contain custom entities (best practice), then it is not necessary to include application context from the WEB-INF directory-->
<!--<property name="my.app.context" location="src/main/webapp/WEB-INF/applicationContext.xml"/>-->
<taskdef name="hibernatetool" classname="org.broadleafcommerce.common.util.sql.HibernateToolTask" classpathref="build.runtime.classpath" />
<hibernatetool destDir="target/sql/update" combinePersistenceUnits="false" refineFileNames="true">
<!--add in additional persistence configuration related to the cms -->
<classPathApplicationContext path="bl-cms-contentClient-applicationContext.xml"/>
<classPathApplicationContext path="bl-open-admin-contentClient-applicationContext.xml"/>
<!--add in additional persistence configuration for our core -->
<classPathApplicationContext path="applicationContext.xml"/>
<!--see description for my.app.context above -->
<fileSystemApplicationContext path="src/main/webapp/WEB-INF/applicationContext.xml"/>
<classPathApplicationContext path="bl-fake-applicationContext-ant.xml"/>
<!--select the dialects and persistence units to export-->
<jpaconfiguration persistenceUnit="blPU" dialect="${ant.hibernate.sql.ddl.dialect}"
url="${ant.blPU.url}"
userName="${ant.blPU.userName}"
password="${ant.blPU.password}"
driverClassName="${ant.blPU.driverClassName}"/>
<jpaconfiguration persistenceUnit="blSecurePU" dialect="${ant.hibernate.sql.ddl.dialect}"
url="${ant.blSecurePU.url}"
userName="${ant.blSecurePU.userName}"
password="${ant.blSecurePU.password}"
driverClassName="${ant.blSecurePU.driverClassName}"/>
<jpaconfiguration persistenceUnit="blCMSStorage" dialect="${ant.hibernate.sql.ddl.dialect}"
url="${ant.blCMSStorage.url}"
userName="${ant.blCMSStorage.userName}"
password="${ant.blCMSStorage.password}"
driverClassName="${ant.blCMSStorage.driverClassName}"/>
<!--other required elements-->
<classpath refid="build.runtime.classpath" />
<hbm2ddl export="false" update="true" create="false"/>
</hibernatetool>
</target>
</project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment