Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save petershin/c2082918fce6bc68015c0f7b4073b3f6 to your computer and use it in GitHub Desktop.
Save petershin/c2082918fce6bc68015c0f7b4073b3f6 to your computer and use it in GitHub Desktop.
<?xml version="1.0"?>
<project default="prepare-working-dir" xmlns:if="ant:if" xmlns:unless="ant:unless">
<property file="working.dir.${user.name}.properties" />
<property file="working.dir.${env.COMPUTERNAME}.properties" />
<property file="working.dir.${env.HOST}.properties" />
<property file="working.dir.${env.HOSTNAME}.properties" />
<property file="working.dir.properties" />
<condition property="prepare.working.dir.private">
<not>
<available file="git-commit-portal" />
</not>
</condition>
<macrodef name="fetch-portal">
<attribute name="fetch.portal.branch.name" />
<attribute name="fetch.portal.repository.name" />
<sequential>
<local name="fetch.portal.repository.url" />
<condition else="git@github.com:liferay/@{fetch.portal.repository.name}.git" property="fetch.portal.repository.url" value="git@github-dev.liferay.com:liferay/@{fetch.portal.repository.name}.git">
<isset property="env.JENKINS_HOME" />
</condition>
<echo>git fetch --force --no-tags ${fetch.portal.repository.url} @{fetch.portal.branch.name}</echo>
<exec executable="git">
<arg value="fetch" />
<arg value="--force" />
<arg value="--no-tags" />
<arg value="${fetch.portal.repository.url}" />
<arg value="@{fetch.portal.branch.name}" />
</exec>
</sequential>
</macrodef>
<macrodef name="prepare-working-dir">
<attribute name="from.branch.name" />
<attribute name="to.branch.name" />
<sequential>
<local name="replace.regex.tmp.file" />
<tempfile createfile="true" deleteonexit="true" property="replace.regex.tmp.file" />
<!-- build.properties -->
<replace
failOnNoReplacements="true"
file="build.properties"
if:set="build.repository.private.password[@{to.branch.name}]"
token="build.repository.private.password=${build.repository.private.password[@{from.branch.name}]}"
value="build.repository.private.password=${build.repository.private.password[@{to.branch.name}]}"
/>
<replace
failOnNoReplacements="true"
file="build.properties"
if:set="build.repository.private.url[@{to.branch.name}]"
token="build.repository.private.url=${build.repository.private.url[@{from.branch.name}]}"
value="build.repository.private.url=${build.repository.private.url[@{to.branch.name}]}"
/>
<replace
failOnNoReplacements="true"
file="build.properties"
if:set="build.repository.private.username[@{to.branch.name}]"
token="build.repository.private.username=${build.repository.private.username[@{from.branch.name}]}"
value="build.repository.private.username=${build.repository.private.username[@{to.branch.name}]}"
/>
<replace
failOnNoReplacements="true"
file="build.properties"
token="git.working.branch.name=@{from.branch.name}"
value="git.working.branch.name=@{to.branch.name}"
/>
<!-- release.properties -->
<replace
failOnNoReplacements="true"
file="release.properties"
token="lp.version=${lp.version[@{from.branch.name}]}"
value="lp.version=${lp.version[@{to.branch.name}]}"
/>
<replace
failOnNoReplacements="true"
file="release.properties"
token="lp.version.dtd=${lp.version.dtd[@{from.branch.name}]}"
value="lp.version.dtd=${lp.version.dtd[@{to.branch.name}]}"
/>
<!-- test.properties -->
<replace
failOnNoReplacements="true"
file="test.properties"
token="liferay.portal.branch=${liferay.portal.branch[@{from.branch.name}]}"
value="liferay.portal.branch=${liferay.portal.branch[@{to.branch.name}]}"
/>
<replace
failOnNoReplacements="true"
file="test.properties"
if:set="test.run.environment[@{to.branch.name}]"
token="test.run.environment=${test.run.environment[@{from.branch.name}]}"
value="test.run.environment=${test.run.environment[@{to.branch.name}]}"
/>
<replace
failOnNoReplacements="true"
file="test.properties"
if:set="testray.build.type[@{to.branch.name}]"
token="testray.build.type=${testray.build.type[@{from.branch.name}]}"
value="testray.build.type=${testray.build.type[@{to.branch.name}]}"
/>
<!-- portal-kernel/src/com/liferay/portal/kernel/util/ReleaseInfo.java -->
<replace-regex
replace.regex.file="portal-kernel/src/com/liferay/portal/kernel/util/ReleaseInfo.java"
replace.regex.pattern="${release.info.build[@{from.branch.name}]}"
replace.regex.replacement="${release.info.build[@{to.branch.name}]}"
replace.regex.tmp.file="${replace.regex.tmp.file}"
/>
<replace-regex
replace.regex.file="portal-kernel/src/com/liferay/portal/kernel/util/ReleaseInfo.java"
replace.regex.pattern="${release.info.date[@{from.branch.name}]}"
replace.regex.replacement="${release.info.date[@{to.branch.name}]}"
replace.regex.tmp.file="${replace.regex.tmp.file}"
/>
<replace
failOnNoReplacements="true"
file="portal-kernel/src/com/liferay/portal/kernel/util/ReleaseInfo.java"
if:set="release.info.name[@{to.branch.name}]"
token="${release.info.name[@{from.branch.name}]}"
value="${release.info.name[@{to.branch.name}]}"
/>
<replace-regex
replace.regex.file="portal-kernel/src/com/liferay/portal/kernel/util/ReleaseInfo.java"
replace.regex.pattern="${release.info.version[@{from.branch.name}]}"
replace.regex.replacement="${release.info.version[@{to.branch.name}]}"
replace.regex.tmp.file="${replace.regex.tmp.file}"
/>
<replace-regex
replace.regex.file="portal-kernel/src/com/liferay/portal/kernel/util/ReleaseInfo.java"
replace.regex.pattern="${release.info.version.display.name[@{from.branch.name}]}"
replace.regex.replacement="${release.info.version.display.name[@{to.branch.name}]}"
replace.regex.tmp.file="${replace.regex.tmp.file}"
/>
<!-- sql/portal-data-release.sql -->
<local name="replace.portal.data.release.sql" />
<condition property="replace.portal.data.release.sql">
<available file="sql/portal-data-release.sql" />
</condition>
<replace-regex
if:set="replace.portal.data.release.sql"
replace.regex.file="sql/portal-data-release.sql"
replace.regex.pattern="${portal.data.release[@{from.branch.name}]}"
replace.regex.replacement="${portal.data.release[@{to.branch.name}]}"
replace.regex.tmp.file="${replace.regex.tmp.file}"
/>
<!-- sql/sql.properties -->
<replace
failOnNoReplacements="true"
file="sql/sql.properties"
if:set="database.types[@{to.branch.name}]"
token="database.types=${database.types[@{from.branch.name}]}"
value="database.types=${database.types[@{to.branch.name}]}"
/>
</sequential>
</macrodef>
<macrodef name="prepare-working-dir-private">
<sequential>
<loadproperties srcFile="working.dir.properties">
<filterchain>
<linecontains>
<contains value="to.branch.name" />
</linecontains>
</filterchain>
</loadproperties>
<loadproperties srcFile="working.dir.properties">
<filterchain>
<tokenfilter>
<containsregex pattern="(build\.repository\.private\.\w+)\Q[${to.branch.name}]\E" replace="\1" />
</tokenfilter>
</filterchain>
</loadproperties>
<delete file="working.dir.properties" />
<propertyfile file="build.${user.name}.properties">
<entry key="build.repository.private.password" value="${build.repository.private.password}" />
<entry key="build.repository.private.url" value="${build.repository.private.url}" />
<entry key="build.repository.private.username" value="${build.repository.private.username}" />
</propertyfile>
</sequential>
</macrodef>
<macrodef name="replace-regex">
<attribute name="replace.regex.file" />
<attribute name="replace.regex.pattern" />
<attribute name="replace.regex.replacement" />
<attribute name="replace.regex.tmp.file" />
<sequential>
<local name="replace.regex.changed" />
<replaceregexp
file="@{replace.regex.file}"
match="@{replace.regex.pattern}"
replace="@{replace.regex.replacement}"
/>
<uptodate
property="replace.regex.changed"
srcfile="@{replace.regex.tmp.file}"
targetfile="@{replace.regex.file}"
/>
<fail message="Unable to replace pattern &quot;@{replace.regex.pattern}&quot; with &quot;@{replace.regex.replacement}&quot; in @{replace.regex.file}." unless="replace.regex.changed" />
</sequential>
</macrodef>
<target name="checkout-portal" unless="prepare.working.dir.private">
<loadfile
property="portal.git.commit"
srcFile="git-commit-portal"
>
<filterchain>
<striplinebreaks />
</filterchain>
</loadfile>
<local name="return.code" />
<exec executable="git" failonerror="false" resultproperty="return.code">
<arg value="log" />
<arg value="-n" />
<arg value="1" />
<arg value="${portal.git.commit}" />
</exec>
<condition property="portal.git.commit.available">
<equals arg1="${return.code}" arg2="0" />
</condition>
<fetch-portal
fetch.portal.branch.name="${public.branch.name}"
fetch.portal.repository.name="liferay-portal"
unless:set="portal.git.commit.available"
/>
<local name="return.code" />
<exec executable="git" failonerror="false" resultproperty="return.code">
<arg value="tag" />
<arg value="--force" />
<arg value="git-commit-portal" />
<arg value="${portal.git.commit}" />
</exec>
<fail message="Please fetch the public branch from upstream before using this command.">
<condition>
<not>
<equals arg1="${return.code}" arg2="0" />
</not>
</condition>
</fail>
<loadresource property="working.dir.checkout.excludes.git">
<propertyresource name="working.dir.checkout.excludes" />
<filterchain>
<replacestring from="," to=" :(exclude)" />
</filterchain>
</loadresource>
<exec executable="git" failonerror="true">
<arg value="checkout" />
<arg value="refs/tags/git-commit-portal" />
<arg value="." />
<arg line=":(exclude)${working.dir.checkout.excludes.git}" />
</exec>
<exec executable="git">
<arg value="reset" />
<arg value="HEAD" />
<arg value="." />
</exec>
<exec executable="git">
<arg value="tag" />
<arg value="--delete" />
<arg value="git-commit-portal" />
</exec>
</target>
<target if="prepare.working.dir.private" name="checkout-portal-private">
<loadfile
property="portal.private.git.commit"
srcFile="git-commit-portal-private"
>
<filterchain>
<striplinebreaks />
</filterchain>
</loadfile>
<exec executable="git" resultproperty="portal.private.git.commit.result">
<arg value="cat-file" />
<arg value="-e" />
<arg value="${portal.private.git.commit}" />
</exec>
<fail message="Please run this command from the liferay-portal-ee repository.">
<condition>
<not>
<equals arg1="${portal.private.git.commit.result}" arg2="0" />
</not>
</condition>
</fail>
<local name="return.code" />
<exec executable="git" failonerror="false" resultproperty="return.code">
<arg value="log" />
<arg value="-n" />
<arg value="1" />
<arg value="${portal.private.git.commit}" />
</exec>
<condition property="portal.private.git.commit.available">
<equals arg1="${return.code}" arg2="0" />
</condition>
<fetch-portal
fetch.portal.branch.name="${private.branch.name}"
fetch.portal.repository.name="liferay-portal-ee"
unless:set="portal.private.git.commit.available"
/>
<local name="return.code" />
<exec executable="git" failonerror="false" resultproperty="return.code">
<arg value="tag" />
<arg value="--force" />
<arg value="git-commit-portal-private" />
<arg value="${portal.private.git.commit}" />
</exec>
<fail message="Please fetch the private branch from upstream before using this command.">
<condition>
<not>
<equals arg1="${return.code}" arg2="0" />
</not>
</condition>
</fail>
<exec executable="git" failonerror="true">
<arg value="checkout" />
<arg value="refs/tags/git-commit-portal-private" />
<arg if:true="${checkout.portal.private.releng}" value="modules/.releng/private" />
<arg value="modules/private" />
<arg value="working.dir.properties" />
</exec>
<exec executable="git">
<arg value="reset" />
<arg value="HEAD" />
<arg if:true="${checkout.portal.private.releng}" value="modules/.releng/private" />
<arg value="modules/private" />
<arg value="working.dir.properties" />
</exec>
<exec executable="git">
<arg value="tag" />
<arg value="--delete" />
<arg value="git-commit-portal-private" />
</exec>
</target>
<target depends="checkout-portal,checkout-portal-private" name="prepare-working-dir">
<property name="from.branch.name" value="${public.branch.name}" />
<property name="to.branch.name" value="${private.branch.name}" />
<prepare-working-dir
from.branch.name="${from.branch.name}"
to.branch.name="${to.branch.name}"
unless:true="${prepare.working.dir.private}"
/>
<prepare-working-dir-private
if:true="${prepare.working.dir.private}"
/>
</target>
</project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment