Last active
May 25, 2017 13:55
-
-
Save stephencroberts/7848386 to your computer and use it in GitHub Desktop.
Phing build file for Joomla! extensions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<project name="digitollsoftware" default="dist"> | |
<tstamp /> | |
<!-- Load local properties --> | |
<property file="./build.properties" override="true" /> | |
<!-- Get package version from the latest tag in git --> | |
<exec command="git describe --abbrev=0" outputProperty="version.value" /> | |
<!-- ============================================ --> | |
<!-- Target: build --> | |
<!-- ============================================ --> | |
<target name="build"> | |
<!-- Create build directory --> | |
<mkdir dir="./build" /> | |
<!-- Copy files to build directory, replacing properties --> | |
<copy todir="./build"> | |
<fileset dir="./"> | |
<exclude name="**/*.DS_Store" /> | |
<exclude name="**/*.git*" /> | |
<exclude name="build" /> | |
<exclude name="build.xml" /> | |
<exclude name="build.properties" /> | |
</fileset> | |
<filterchain> | |
<expandproperties /> | |
</filterchain> | |
</copy> | |
<!-- Process dependencies --> | |
<foreach list="${dependencies}" param="package" target="dependencies" /> | |
<!-- Copy the install script to admin --> | |
<copy todir="./build/admin"> | |
<fileset dir="./"> | |
<include name="script.*.php" /> | |
</fileset> | |
</copy> | |
</target> | |
<!-- ============================================ --> | |
<!-- (DEFAULT) Target: dist --> | |
<!-- ============================================ --> | |
<target name="dist" depends="build"> | |
<!-- Create archive --> | |
<tar destfile="./build/build.tar.gz" compression="gzip"> | |
<fileset dir="./build"> | |
<include name="*" /> | |
</fileset> | |
</tar> | |
<!-- Archive old package --> | |
<move todir="${paths.archives}/${package.value}" overwrite="true"> | |
<fileset dir="${paths.packages}"> | |
<include name="${package.value}*" /> | |
</fileset> | |
</move> | |
<!-- Move package to packages directory --> | |
<move file="./build/build.tar.gz" tofile="${paths.packages}/${package.filename}" overwrite="true" /> | |
<!-- Remove build directory --> | |
<delete dir="./build" /> | |
</target> | |
<!-- ============================================ --> | |
<!-- Target: pub --> | |
<!-- ============================================ --> | |
<target name="pub" depends="dist"> | |
<!-- Get type, folder, and element from package name --> | |
<joomla-extension extension="${package.value}" /> | |
<!-- Upload package to S3 --> | |
<echo msg="Uploading ${package.filename}..." /> | |
<s3put source="${paths.packages}/${package.filename}" object="${package.value}/${package.filename}" bucket="${aws.bucket}" key="${aws.accesskey}" secret="${aws.secretkey}" /> | |
<!-- Update version in remote database --> | |
<echo msg="Updating database..." /> | |
<ssh username="${server.username}" | |
pubkeyfile="${server.key}.pub" | |
privkeyfile="${server.key}" | |
host="${server.host}" | |
command="mysql --user=${server.dbu} --password='${server.dbp}' -e 'UPDATE `xegxr_digitolldownloads_downloads` SET `file_path`="${package.value}/${package.filename}" WHERE `file_path` LIKE "${package.value}_%"' ${server.dbn}" /> | |
</target> | |
<!-- ============================================ --> | |
<!-- Target: create --> | |
<!-- ============================================ --> | |
<target name="create" depends="dist"> | |
<!-- Create slug from application name --> | |
<slug value="${name.value}" /> | |
<!-- Upload package to S3 --> | |
<echo msg="Uploading ${package.filename}..." /> | |
<s3put source="${paths.packages}/${package.filename}" object="${package.value}/${package.filename}" bucket="${aws.bucket}" key="${aws.accesskey}" secret="${aws.secretkey}" /> | |
<!-- Create new download in remote database --> | |
<echo msg="Creating download..." /> | |
<ssh username="${server.username}" | |
pubkeyfile="${server.key}.pub" | |
privkeyfile="${server.key}" | |
host="${server.host}" | |
command="mysql --user=${server.dbu} --password='${server.dbp}' -e 'INSERT INTO `xegxr_digitolldownloads_downloads` (`shared`, `virtuemart_vendor_id`, `digitolldownloads_deliverymethod_id`, `file_path`, `expiration`, `available_date`, `download_limit`, `download_count`, `download_code`, `digitolldownloads_codemethod_id`, `codemethod_params`, `unlimited`, `is_product`, `published`, `created_on`, `created_by`, `modified_on`, `modified_by`, `locked_on`, `locked_by`) VALUES (0, 1, 4, "${package.value}/${package.filename}", "0000-00-00 00:00:00", "0000-00-00 00:00:00", 0, 0, "${downloadcode}", 10150, "", 1, 1, 1, "0000-00-00 00:00:00", 0, "2013-10-24 18:59:01", 42, "0000-00-00 00:00:00", 0); INSERT INTO `xegxr_digitolldownloads_downloads_en_gb` (`digitolldownloads_download_id`, `download_name`, `slug`) VALUES (LAST_INSERT_ID(), "${name.value}", "${package.slug}");' ${server.dbn}" /> | |
</target> | |
<!-- ============================================ --> | |
<!-- Target: dependencies --> | |
<!-- ============================================ --> | |
<target name="dependencies"> | |
<!-- Get the basename of the package directory --> | |
<exec command="basename '${paths.source}/${package}'" outputProperty="basename" /> | |
<!-- Run phing on dependency --> | |
<exec command="phing" dir="${paths.source}/${package}" /> | |
<!-- Extract package into build directory --> | |
<untar todir="./build/admin/extensions/${basename}"> | |
<fileset dir="${paths.packages}"> | |
<include name="${basename}*" /> | |
</fileset> | |
</untar> | |
</target> | |
<adhoc-task name="joomla-extension"><![CDATA[ | |
class JoomlaExtension extends Task { | |
private $extension = null; | |
public function setExtension($extension) { | |
$this->extension = $extension; | |
} | |
public function main() { | |
preg_match('/(?(?=plg)(.*?)_(.*?)_(.*)|(.*?)_(.*))/', $this->extension, $matches); | |
$type = $matches[1] . $matches[4]; | |
switch ($type) { | |
case 'com' : $typefull='component'; break; | |
case 'mod' : $typefull='module'; break; | |
case 'plg' : $typefull='plugin'; break; | |
case 'lib' : $typefull='library'; break; | |
case 'tmpl': $typefull='template'; break; | |
default: $typefull=''; | |
} | |
$this->project->setProperty('typefull', $typefull); | |
$this->project->setProperty('type', $type); | |
$this->project->setProperty('folder', $matches[2]); | |
$this->project->setProperty('element', $matches[3] . $matches[5]); | |
} | |
} | |
]]></adhoc-task> | |
<adhoc-task name="slug"><![CDATA[ | |
class Slug extends Task { | |
private $value = null; | |
public function setValue($value) { | |
$this->value = $value; | |
} | |
public function main() { | |
preg_match_all('/[A-Z,a-z,0-9, ,-]*/', $this->value, $matches); | |
$slug = preg_replace('/[-, ]+/', '-', strtolower(implode($matches[0]))); | |
$this->project->setProperty('package.slug', $slug); | |
} | |
} | |
]]></adhoc-task> | |
</project> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment