Skip to content

Instantly share code, notes, and snippets.

@handersonbf
Created November 28, 2012 20:58
Show Gist options
  • Select an option

  • Save handersonbf/4164442 to your computer and use it in GitHub Desktop.

Select an option

Save handersonbf/4164442 to your computer and use it in GitHub Desktop.
ExemploBuildANT
<?xml version="1.0" encoding='UTF-8' ?>
<project name="NomeDoSistema" basedir="." default="all">
<property file="build.properties" />
<!-- Importa antcontrib lib -->
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<pathelement location="lib/build/ant/ant-contrib-1.0b3.jar" />
</classpath>
</taskdef>
<property name="yui-compressor.jar" location="${yuicompressorjar}" />
<property name="yui-compressor-ant-task.jar" location="${yuicompressoranttaskjar}" />
<!-- Verifica Sistema Operacional -->
<osfamily property="OSFamily" />
<condition property="isWindows">
<equals arg1="${OSFamily}" arg2="windows" casesensitive="false" />
</condition>
<path id="classpath">
<fileset dir="${lib.dir}">
<include name="**/*.jar" />
</fileset>
<!--
<fileset dir="${target.jar.dir}">
<include name="**/*.jar" />
</fileset>
-->
</path>
<path id="webinf-classpath">
<fileset dir="${webroot.dir}/WEB-INF/lib">
<include name="**/*.jar" />
</fileset>
</path>
<path id="build-classpath">
<fileset dir="${lib.dir}/build">
<include name="*.jar" />
</fileset>
</path>
<path id="acceptance-tests-classpath">
<fileset dir="${lib.dir}/build/jetty">
<include name="**/*.jar" />
</fileset>
<fileset dir="${lib.dir}/build/webdriver">
<include name="**/*.jar" />
</fileset>
</path>
<path id="task.classpath">
<pathelement location="${yui-compressor.jar}" />
<pathelement location="${yui-compressor-ant-task.jar}" />
</path>
<taskdef name="yui-compressor" classname="net.noha.tools.ant.yuicompressor.tasks.YuiCompressorTask">
<classpath refid="task.classpath" />
</taskdef>
<target name="selectEnvironment">
<input addproperty="environment" defaultvalue="test" validargs="test,homol,homolrpg,production" message="Selecione o environment(default:homol):" />
<property file="${environment}.properties" />
<echo>Selected Environment: ${environment}</echo>
</target>
<target name="clean">
<delete dir="${default.target.dir}" />
<mkdir dir="${test.classes.dir}" />
<mkdir dir="${classes.dir}" />
<mkdir dir="${war.dir}" />
</target>
<target name="compile" depends="clean">
<!-- Compila App classes -->
<copy todir="${classes.dir}">
<fileset dir="${source.dir}" excludes="**/*.java" />
</copy>
<javac destdir="${classes.dir}" srcdir="${source.dir}" debug="true" debuglevel="vars,lines,source" source="1.5" target="1.5" encoding="UTF-8">
<classpath>
<path refid="build-classpath" />
<path refid="webinf-classpath" />
</classpath>
</javac>
<!-- Compila Test classes -->
<copy todir="${test.classes.dir}">
<fileset dir="${test.source.dir}" excludes="**/*.java" />
</copy>
<javac destdir="${test.classes.dir}" srcdir="${test.source.dir}" debug="true" debuglevel="vars,lines,source" source="1.5" target="1.5" encoding="UTF-8">
<classpath>
<!-- path refid="classpath" / -->
<path refid="webinf-classpath" />
<path refid="build-classpath" />
<path refid="acceptance-tests-classpath" />
<pathelement path="${classes.dir}" />
</classpath>
</javac>
</target>
<path id="cobertura.classpath">
<fileset dir="${cobertura.dir}">
<include name="cobertura.jar" />
<include name="lib/**/*.jar" />
</fileset>
</path>
<taskdef classpathref="cobertura.classpath" resource="tasks.properties" />
<target name="instrument" depends="compile">
<mkdir dir="${instrumented.dir}" />
<mkdir dir="${coverage.xml.dir}" />
<cobertura-instrument datafile="${coverage.xml.dir}/cobertura.ser" todir="${instrumented.dir}">
<ignore regex="org.apache.log4j.*" />
<fileset dir="${classes.dir}">
<include name="**/*.class" />
<exclude name="**/*Test.class" />
</fileset>
</cobertura-instrument>
</target>
<target name="test" depends="instrument, test-mysql, test-jasmine">
</target>
<target name="test-mysql">
<echo>*******************************</echo>
<echo>Executando testes no MySQL</echo>
<echo>*******************************</echo>
<copy file="${env.test.dir}/configuracoes.properties" tofile="${test.classes.dir}/configuracoes-test.properties" overwrite="true" />
<antcall target="_test">
</antcall>
</target>
<target name="_test">
<!-- depends="instrument" -->
<mkdir dir="${test.report.dir}" />
<junit printsummary="on" fork="yes" forkmode="once" haltonfailure="true" haltonerror="true">
<sysproperty key="net.sourceforge.cobertura.datafile" file="${coverage.xml.dir}/cobertura.ser" />
<sysproperty key="basedir" value="." />
<formatter type="xml" />
<classpath>
<!-- Adiciona libs necessarias para o build -->
<path refid="build-classpath" />
<path refid="acceptance-tests-classpath" />
<!-- Adiciona libs da App -->
<path refid="webinf-classpath">
</path>
<!-- Cobertura -->
<fileset dir="${cobertura.dir}">
<include name="cobertura.jar" />
</fileset>
<!-- Classpaths -->
<pathelement path="${instrumented.dir}" />
<pathelement path="${classes.dir}" />
<pathelement path="${test.classes.dir}" />
</classpath>
<test name="${testcase}" todir="${test.report.dir}" if="testcase" />
<batchtest todir="${test.report.dir}" unless="testcase">
<!-- Unit Tests -->
<fileset dir="${test.source.dir}/unit">
<include name="${test.pattern}" />
</fileset>
<!-- Integration Tests -->
<fileset dir="${test.source.dir}/integration">
<include name="${test.pattern}" />
</fileset>
<!-- Acceptance Tests -->
<fileset dir="${test.source.dir}/acceptance">
<include name="${test.pattern}" />
</fileset>
</batchtest>
</junit>
</target>
<target name="test-jasmine">
<exec executable="java" failonerror="true">
<arg value="-jar" />
<arg value="${jasmine.dir}/lib/js.jar" />
<arg value="-opt" />
<arg value="-1" />
<arg value="${jasmine.dir}/lib/envjs.bootstrap.js" />
<arg value="${jasmine.dir}/SpecRunner.html" />
</exec>
</target>
<target name="coverage-check">
<cobertura-check branchrate="34" totallinerate="100" />
</target>
<target name="coverage" depends="test">
<cobertura-report datafile="${coverage.xml.dir}/cobertura.ser" srcdir="${source.dir}" destdir="${coverage.xml.dir}" format="xml" />
</target>
<target name="war" description="create war file" depends="coverage, js.minify">
<!--target name="war" description="create war file" depends="coverage" -->
<war destfile="${war.file}" webxml="${webroot.dir}/WEB-INF/web.xml">
<classes dir="${classes.dir}" />
<lib dir="${webroot.dir}/WEB-INF/lib">
</lib>
<fileset dir="${webroot.dir}/">
<include name="js/**" />
<include name="css/**" />
<include name="images/**" />
<include name="imagens/**" />
<include name="META-INF/**" />
<include name="*.jsp" />
<include name="*.html" />
<include name="decorators/**" />
</fileset>
<zipfileset file="${imports.servidorImagensProperties}" prefix="WEB-INF/classes" />
<zipfileset file="${imports.templateUsedProperties}" prefix="WEB-INF/classes" />
<zipfileset file="${imports.configuracaoBD}" prefix="WEB-INF/classes" />
<zipfileset dir="${webroot.dir}/WEB-INF/jsp" prefix="WEB-INF/jsp" />
<zipfileset file="${webroot.dir}/WEB-INF/decorators.xml" prefix="WEB-INF" />
<!--zipfileset dir="${webroot.dir}/WEB-INF/config" prefix="WEB-INF/config" excludes="**/*-test.xml" /-->
<zipfileset dir="${imports.config.spring}" prefix="WEB-INF/config/spring" />
<zipfileset file="${imports.main}" prefix="decorators/" />
<zipfileset file="${imports.calendarioFULL}" prefix="decorators/" />
<zipfileset file="${imports.main.google.analytics}" prefix="decorators/" />
<zipfileset dir="${webroot.dir}/WEB-INF/reports" prefix="WEB-INF/reports" />
<zipfileset dir="${webroot.dir}/WEB-INF/tags" prefix="WEB-INF/tags" />
<zipfileset file="${imports.fisioterapeuta}" prefix="WEB-INF/jsp/imports" />
<zipfileset file="${imports.franquia}" prefix="WEB-INF/jsp/imports" />
<zipfileset file="${imports.paciente}" prefix="WEB-INF/jsp/imports" />
<zipfileset file="${imports.pacienteAgenda}" prefix="WEB-INF/jsp/imports" />
<zipfileset file="${imports.perfil}" prefix="WEB-INF/jsp/imports" />
<zipfileset file="${imports.prontuario}" prefix="WEB-INF/jsp/imports" />
<zipfileset file="${imports.questionario}" prefix="WEB-INF/jsp/imports" />
</war>
</target>
<!-- Yui Compressor -->
<target name="js.concat">
<concat destfile="${js.dir.api}/app-jquery.js">
<filelist dir="${js.dir.api}/" files="jquery.tables.js, jquery.alerts.js, jquery.validate.min.js, jquery.alphanumeric.js,
jquery.ui.position.min.js, jquery.ui.widget.min.js, jquery.ui.dialog.min.js,
jquery.ui.datepicker.js, jquery.maskedinput-1.2.2.min.js, jquery.noisy.min.js,
jquery.ui.timepicker-0.1.3.js, jquery.Jcrop.min.js, imagepicker.jquery.js, jquery.scrollTo.js" />
</concat>
<concat destfile="${js.dir.ext}/app-ext.js">
<filelist dir="${js.dir.ext}/" files="ext-base-debug.js, ext-all-debug.js, extensible-all-debug.js, ext-InputTextMask.js" />
</concat>
<concat destfile="${js.dir.calendarioFULL}/app-calendarioFull.js">
<filelist dir="${js.dir.calendarioFULL}/" files="ITCdata-calendars.js, ITCdata-events.js, ITCCalendarStore.js, ITCMemoryEventStore.js, calendarioFull.js" />
</concat>
<concat destfile="${js.dir.api}/app-api.js">
<filelist dir="${js.dir.api}/" files="global.js, util.js" />
</concat>
<concat destfile="${js.dir}/app-fisioterapeuta.js">
<filelist dir="${js.dir}/" files="fisioterapeuta.js, fisioterapeutaValidacao.js, fisioterapeutaCalendario.js, agenda.js" />
</concat>
<concat destfile="${js.dir}/app-paciente.js">
<filelist dir="${js.dir}/" files="paciente.js, pacienteSessao.js, pacienteValidacao.js, pacienteImagem.js" />
</concat>
<concat destfile="${js.dir}/app-paciente-agenda.js">
<filelist dir="${js.dir}/" files="pacienteCalendario.js, agenda.js" />
</concat>
<concat destfile="${js.dir}/app-prontuario.js">
<filelist dir="${js.dir}/" files="prontuario.js" />
</concat>
<concat destfile="${js.dir}/app-rpg.js">
<filelist dir="${js.dir}/" files="rpg.js, rpg_objetos.js, rpg_pontuacao.js,rpg_pontuacao_resultado.js, rpg_msg.js" />
</concat>
</target>
<target name="js.minify" depends="js.concat">
<!-- Minificando apis: jquery, api, e util -->
<apply executable="java" parallel="false">
<fileset dir="${js.dir.api}/" includes="app-jquery.js, app-api.js, util.js" />
<arg line="-jar" />
<arg path="${yui-compressor.jar}" />
<srcfile />
<arg line="-o" />
<mapper type="glob" from="*.js" to="${js.dir.api}/*-min.js" />
<targetfile />
</apply>
<!-- Minificando api do EXT -->
<apply executable="java" parallel="false">
<fileset dir="${js.dir.ext}/" includes="app-ext.js" />
<arg line="-jar" />
<arg path="${yui-compressor.jar}" />
<srcfile />
<arg line="-o" />
<mapper type="glob" from="*.js" to="${js.dir.ext}/*-min.js" />
<targetfile />
</apply>
<!-- Minificando calendario ITC -->
<apply executable="java" parallel="false">
<fileset dir="${js.dir.calendarioFULL}/" includes="app-calendarioFull.js" />
<arg line="-jar" />
<arg path="${yui-compressor.jar}" />
<srcfile />
<arg line="-o" />
<mapper type="glob" from="*.js" to="${js.dir.calendarioFULL}/*-min.js" />
<targetfile />
</apply>
<!-- Minificando JS principal da aplicação -->
<apply executable="java" parallel="false">
<fileset dir="${js.dir}/" includes="NomeDoSistema.js, localidade.js, helpers.js" />
<arg line="-jar" />
<arg path="${yui-compressor.jar}" />
<srcfile />
<arg line="-o" />
<mapper type="glob" from="*.js" to="${js.dir}/*-min.js" />
<targetfile />
</apply>
<!-- Minificando JS's da aplicação -->
<apply executable="java" parallel="false">
<fileset dir="${js.dir}/" includes="app-fisioterapeuta.js, franquia.js, app-paciente.js,
app-paciente-agenda.js, perfil.js, questionario.js, app-prontuario.js, app-rpg.js" />
<arg line="-jar" />
<arg path="${yui-compressor.jar}" />
<srcfile />
<arg line="-o" />
<mapper type="glob" from="*.js" to="${js.dir}/*-min.js" />
<targetfile />
</apply>
</target>
<!-- Fim Yui Compressor -->
<!-- INICIO CONFIGURACAO DEPLOY EM HOMOLOGACAO -->
<target name="deploy.tomcat-stop">
<echo>** Stopping Tomcat **</echo>
<sshexec command="${deploy.tomcatstop}" host="${deploy.sshhost}" password="${deploy.sshpassword}" username="${deploy.sshuser}" />
</target>
<target name="deploy.apache-stop">
<echo>** Stopping Apache **</echo>
<sshexec command="${deploy.apachestop}" host="${deploy.sshhost}" password="${deploy.sshpassword}" username="${deploy.sshuser}" />
</target>
<target name="deploy.sendwar">
<echo>** Sending WAR **</echo>
<scp trust="true" verbose="true" file="${war.file}" todir="${deploy.sshuser}:${deploy.sshpassword}@${deploy.sshhost}:${deploy.wartarget}">
</scp>
</target>
<target name="deploy.backup">
<echo>**** Making Backup ****</echo>
<sshexec command="${deploy.backup.executeBackup}" host="${deploy.sshhost}" password="${deploy.sshpassword}" username="${deploy.sshuser}" />
</target>
<target name="deploy.tomcat-start">
<echo>** Starting Tomcat **</echo>
<sshexec command="${deploy.tomcatstart}" host="${deploy.sshhost}" password="${deploy.sshpassword}" username="${deploy.sshuser}" />
</target>
<target name="deploy.apache-start">
<echo>** Starting Apache **</echo>
<sleep seconds="30" />
<sshexec command="${deploy.apachestart}" host="${deploy.sshhost}" password="${deploy.sshpassword}" username="${deploy.sshuser}" />
</target>
<target name="deploy.verificandoApps">
<echo>** Verificando se a Aplicacao ${name.project} esta no ar.. **</echo>
<!-- Verifica se o Tomcat está no ar -->
<waitfor maxwait="60" maxwaitunit="second" timeoutproperty="app.nao.esta.no.ar">
<and>
<socket server="${deploy.sshhost}" port="${deploy.sshhostport}" />
<http url="http://${deploy.sshhost}:${deploy.sshhostport}/${name.project}" errorsBeginAt="404" />
</and>
</waitfor>
<fail if="app.nao.esta.no.ar" message="Aplicação ${name.project} não esta no ar" />
<echo message="Aplicacao ${name.project} esta no ar." />
</target>
<target name="deploy.verificandoAppsProduction">
<echo>** Verificando se a Aplicacao ${name.project} esta no ar.. **</echo>
<!-- Verifica se o Tomcat está no ar -->
<waitfor maxwait="60" maxwaitunit="second" timeoutproperty="app.nao.esta.no.ar">
<and>
<socket server="${deploy.sshhost}" port="${deploy.sshhostport}" />
<http url="http://www.sistemaitc.com.br" errorsBeginAt="404" />
</and>
</waitfor>
<fail if="app.nao.esta.no.ar" message="Aplicação ${name.project} não esta no ar" />
<echo message="Aplicacao ${name.project} esta no ar." />
</target>
<target name="deploy.limpandoProjetos">
<echo>** Limpando ${name.project} no Tomcat **</echo>
<sshexec command="${deploy.limpaArquivos}" host="${deploy.sshhost}" password="${deploy.sshpassword}" username="${deploy.sshuser}" />
</target>
<!-- FIM CONFIGURACAÇÃO DEPLOY -->
<target name="all" depends="war">
<delete dir="${test.classes.dir}" />
<delete dir="${test.selenium.classes.dir}" />
<delete dir="${classes.dir}" />
</target>
<target name="all-with-selenium" depends="war">
<delete dir="${test.classes.dir}" />
<delete dir="${test.selenium.classes.dir}" />
<delete dir="${classes.dir}" />
</target>
<target name="deploy" depends="selectEnvironment, war">
<echo>*************************************************************************</echo>
<echo>**** ITC Vertebral Deploy: Iniciando processo de deploy em ${environments.name}. ****</echo>
<echo>*************************************************************************</echo>
<echo>Caso queira alterar o ambiente de deploy, altere a propriedade "environment" no arquivo build.properties.</echo>
<echo>-homol para o ambiente de homologação e production para o ambiente de produção.</echo>
<echo>Realizando o Backup do arquivo ${deploy.wartarget}/${name.project}.war. </echo>
<antcall target="deploy.backup">
</antcall>
<echo>Parando ${deploy.sshhost}${deploy.tomcatlocation}</echo>
<antcall target="deploy.tomcat-stop">
</antcall>
<if>
<equals arg1="${environment}" arg2="production" />
<then>
<echo>Parando Apache</echo>
<antcall target="deploy.apache-stop">
</antcall>
</then>
</if>
<echo>Limpando tomcat: ${deploy.wartarget}/${name.project}.war, ${deploy.wartarget}/${name.project}, ${deploy.dir.work}/${name.project}</echo>
<antcall target="deploy.limpandoProjetos">
</antcall>
<echo>Enviando ${name.project}.war para ${deploy.sshhost}</echo>
<antcall target="deploy.sendwar">
</antcall>
<echo>Iniciando ${deploy.sshhost}${deploy.tomcatlocation}/${deploy.wartarget}</echo>
<antcall target="deploy.tomcat-start">
</antcall>
<echo>Iniciando Apache...</echo>
<antcall target="deploy.apache-start">
</antcall>
<if>
<equals arg1="${environment}" arg2="production" />
<then>
<echo>Testando aplicacao: http://${deploy.sshhost}:${deploy.sshhostport}/${name.project}</echo>
<antcall target="deploy.verificandoAppsProduction">
</antcall>
</then>
<else>
<echo>Testando aplicacao: http://${deploy.sshhost}:${deploy.sshhostport}/${name.project}</echo>
<antcall target="deploy.verificandoApps">
</antcall>
</else>
</if>
<echo>*************************************************************************</echo>
<echo>**** NomeDoSistema Deploy:: Deploy finalizado com sucesso ! ****</echo>
<echo>*************************************************************************</echo>
</target>
<target name="deployLocal" depends="selectEnvironment">
<echo>*************************************************************************</echo>
<echo>**** ITC Vertebral Deploy Local: Iniciando processo de deploy LOCAL em ${environments.name}. ****</echo>
<echo>*************************************************************************</echo>
<echo>Executando deploy sem enviar o war para o servidor.</echo>
<antcall target="war">
</antcall>
<echo>*************************************************************************</echo>
<echo>**** NomeDoSistema Deploy Local: Deploy finalizado com sucesso ! ****</echo>
<echo>*************************************************************************</echo>
</target>
<target name="restart-servidor" depends="selectEnvironment">
<echo>*************************************************************************</echo>
<echo>**** ITC Vertebral Deploy: Reiniciando servidor de ${environments.name}. ****</echo>
<echo>*************************************************************************</echo>
<echo>Caso queira alterar o ambiente de deploy, altere a propriedade "environment" no arquivo build.properties.</echo>
<echo>-homol para o ambiente de homologação e production para o ambiente de produção.</echo>
<echo>Parando ${deploy.sshhost}${deploy.tomcatlocation}</echo>
<antcall target="deploy.tomcat-stop">
</antcall>
<echo>Parando Apache</echo>
<antcall target="deploy.apache-stop">
</antcall>
<echo>Iniciando Apache...</echo>
<antcall target="deploy.apache-start">
</antcall>
<echo>Iniciando ${deploy.sshhost}${deploy.tomcatlocation}/${deploy.wartarget}</echo>
<antcall target="deploy.tomcat-start">
</antcall>
<if>
<equals arg1="${environment}" arg2="production" />
<then>
<echo>Testando aplicacao: http://${deploy.sshhost}:${deploy.sshhostport}/${name.project}</echo>
<antcall target="deploy.verificandoAppsProduction">
</antcall>
</then>
<else>
<echo>Testando aplicacao: http://${deploy.sshhost}:${deploy.sshhostport}/${name.project}</echo>
<antcall target="deploy.verificandoApps">
</antcall>
</else>
</if>
<echo>*************************************************************************</echo>
<echo>**** NomeDoSistema Deploy:: Servidor de ${environments.name} reinicializado com sucesso ! ****</echo>
<echo>*************************************************************************</echo>
</target>
<target name="restart-servidor-envia-war-jar-gerado" depends="selectEnvironment">
<echo>*************************************************************************</echo>
<echo>**** ITC Vertebral Deploy: Reiniciando servidor de ${environments.name} e enviando o war. ****</echo>
<echo>*************************************************************************</echo>
<echo>Caso queira alterar o ambiente de deploy, altere a propriedade "environment" no arquivo build.properties.</echo>
<echo>-homol para o ambiente de homologação e production para o ambiente de produção.</echo>
<antcall target="deploy.backup">
</antcall>
<echo>Parando ${deploy.sshhost}${deploy.tomcatlocation}</echo>
<antcall target="deploy.tomcat-stop">
</antcall>
<if>
<equals arg1="${environment}" arg2="production" />
<then>
<echo>Parando Apache</echo>
<antcall target="deploy.apache-stop">
</antcall>
</then>
</if>
<echo>Limpando tomcat: ${deploy.wartarget}/${name.project}.war, ${deploy.wartarget}/${name.project}, ${deploy.dir.work}/${name.project}</echo>
<antcall target="deploy.limpandoProjetos">
</antcall>
<echo>Enviando ${name.project}.war para ${deploy.sshhost}</echo>
<antcall target="deploy.sendwar">
</antcall>
<echo>Iniciando ${deploy.sshhost}${deploy.tomcatlocation}/${deploy.wartarget}</echo>
<antcall target="deploy.tomcat-start">
</antcall>
<if>
<equals arg1="${environment}" arg2="production" />
<then>
<echo>Iniciando Apache...</echo>
<antcall target="deploy.apache-start">
</antcall>
<echo>Testando aplicacao: http://${deploy.sshhost}:${deploy.sshhostport}/${name.project}</echo>
<antcall target="deploy.verificandoAppsProduction">
</antcall>
</then>
<else>
<echo>Testando aplicacao: http://${deploy.sshhost}:${deploy.sshhostport}/${name.project}</echo>
<antcall target="deploy.verificandoApps">
</antcall>
</else>
</if>
<echo>*************************************************************************</echo>
<echo>**** NomeDoSistema Deploy:: Servidor de ${environments.name} reinicializado com sucesso ! ****</echo>
<echo>*************************************************************************</echo>
</target>
<path id="completo">
<fileset dir="${classes.dir}">
<include name="**/*.*" />
</fileset>
<fileset dir="${webroot.dir}/WEB-INF/lib">
<include name="*.jar" />
</fileset>
<fileset dir="${lib.dir}/build">
<include name="*.jar" />
</fileset>
</path>
<target name="corretorDeDiaDaSemana">
<echo>${classes.dir}</echo>
<echo>${basedir}</echo>
<echo>${webroot.dir}/WEB-INF/lib</echo>
<java classname="CorretorDeDiaDaSemana" fork="true" classpathref="completo" dir="${classes.dir}">
</java>
</target>
<!-- ***************************************************************************** -->
<!-- TASKs PARA CONFIGURAÇÃO DO BANCO DE DADOS -->
<!-- db:create => dropa e cria banco "itc" vazio -->
<!-- db:schema => gera script delta de atualização ("/db/itc-schema.sql") entre o banco e as entidades do Hibernate -->
<!-- db:migrate => roda "/db/itc-schema.sql" e todos os arquivos "/db/migrate/*.sql" -->
<!-- -->
<!-- Execute na ordem => db:create e depois db:migrate -->
<!-- ***************************************************************************** -->
<path id="hibernatetools.classpath">
<fileset dir="${webroot.dir}/WEB-INF/lib">
<include name="**/*.jar" />
</fileset>
<fileset dir="db">
<include name="**/*.jar" />
</fileset>
</path>
<taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask" classpathref="hibernatetools.classpath" />
<!-- http://docs.jboss.org/tools/3.0.0.CR1/en/hibernatetools/html_single/index.html#ant -->
<target name="db:schema" depends="compile">
<hibernatetool destdir="db">
<classpath path="${classes.dir}" />
<jpaconfiguration propertyfile="db/hibernate.properties" />
<hbm2ddl drop="false" create="false" update="true" export="false" outputfilename="itc-schema.sql" delimiter=";" format="true" haltonerror="true" />
</hibernatetool>
</target>
<target name="db:migrate" depends="db:schema">
<sql driver="com.mysql.jdbc.Driver" url="jdbc:mysql://127.0.0.1:3306/itc" userid="root" password="root" classpathref="hibernatetools.classpath" print="true" expandproperties="false" delimiter=";" delimitertype="normal" onerror="continue">
<transaction src="db/itc-schema.sql" />
<sort>
<fileset dir="db/migrate">
<include name="*.sql" />
</fileset>
</sort>
</sql>
</target>
<target name="db:create">
<sql driver="com.mysql.jdbc.Driver" url="jdbc:mysql://127.0.0.1:3306" userid="root" password="root" classpathref="hibernatetools.classpath" print="true" expandproperties="false" delimiter=";" delimitertype="normal">
<transaction>
DROP DATABASE IF EXISTS itc;
CREATE DATABASE IF NOT EXISTS itc;
</transaction>
<!-- transaction src="db/brazil_locations.sql" / -->
</sql>
</target>
</project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment