summaryrefslogtreecommitdiff
path: root/buildscripts/phing/classes/phing/tasks/ext/liquibase
diff options
context:
space:
mode:
Diffstat (limited to 'buildscripts/phing/classes/phing/tasks/ext/liquibase')
-rwxr-xr-xbuildscripts/phing/classes/phing/tasks/ext/liquibase/AbstractLiquibaseTask.php184
-rwxr-xr-xbuildscripts/phing/classes/phing/tasks/ext/liquibase/LiquibaseChangeLogTask.php39
-rwxr-xr-xbuildscripts/phing/classes/phing/tasks/ext/liquibase/LiquibaseDbDocTask.php86
-rwxr-xr-xbuildscripts/phing/classes/phing/tasks/ext/liquibase/LiquibaseDiffTask.php137
-rwxr-xr-xbuildscripts/phing/classes/phing/tasks/ext/liquibase/LiquibaseRollbackTask.php72
-rwxr-xr-xbuildscripts/phing/classes/phing/tasks/ext/liquibase/LiquibaseTagTask.php75
-rwxr-xr-xbuildscripts/phing/classes/phing/tasks/ext/liquibase/LiquibaseUpdateTask.php39
7 files changed, 632 insertions, 0 deletions
diff --git a/buildscripts/phing/classes/phing/tasks/ext/liquibase/AbstractLiquibaseTask.php b/buildscripts/phing/classes/phing/tasks/ext/liquibase/AbstractLiquibaseTask.php
new file mode 100755
index 00000000..fbda3ecc
--- /dev/null
+++ b/buildscripts/phing/classes/phing/tasks/ext/liquibase/AbstractLiquibaseTask.php
@@ -0,0 +1,184 @@
+<?php
+
+/**
+ * Copyright (c) 2007-2011 bitExpert AG
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+require_once 'phing/Task.php';
+require_once 'phing/tasks/system/ExecTask.php';
+
+/**
+ * Abstract Liquibase task. Base class for all Liquibase Phing tasks.
+ *
+ * @author Stephan Hochdoerfer <S.Hochdoerfer@bitExpert.de>
+ * @version $Id$
+ * @since 2.4.10
+ * @package phing.tasks.ext.liquibase
+ */
+abstract class AbstractLiquibaseTask extends Task
+{
+ protected $jar;
+ protected $changeLogFile;
+ protected $username;
+ protected $password;
+ protected $url;
+ protected $classpathref;
+
+
+ /**
+ * Sets the absolute path to liquibase jar.
+ *
+ * @param string the absolute path to the liquibase jar.
+ */
+ public function setJar($jar)
+ {
+ $this->jar = $jar;
+ }
+
+
+ /**
+ * Sets the absolute path to the changelog file to use.
+ *
+ * @param string the absolute path to the changelog file
+ */
+ public function setChangeLogFile($changelogFile)
+ {
+ $this->changeLogFile = $changelogFile;
+ }
+
+
+ /**
+ * Sets the username to connect to the database.
+ *
+ * @param string the username
+ */
+ public function setUsername($username)
+ {
+ $this->username = $username;
+ }
+
+
+ /**
+ * Sets the password to connect to the database.
+ *
+ * @param string the password
+ */
+ public function setPassword($password)
+ {
+ $this->password = $password;
+ }
+
+
+ /**
+ * Sets the url to connect to the database in jdbc style, e.g.
+ * <code>
+ * jdbc:postgresql://psqlhost/mydatabase
+ * </code>
+ *
+ * @param string jdbc connection string
+ */
+ public function setUrl($url)
+ {
+ $this->url = $url;
+ }
+
+
+ /**
+ * Sets the Java classpathref.
+ *
+ * @param string A reference to the classpath that contains the database
+ * driver, liquibase.jar, and the changelog.xml file
+ */
+ public function setclasspathref($classpathref)
+ {
+ $this->classpathref = $classpathref;
+ }
+
+
+ /**
+ * Ensure that correct parameters were passed in.
+ *
+ * @return void
+ */
+ protected function checkParams()
+ {
+ if((null === $this->jar) or !file_exists($this->jar))
+ {
+ throw new BuildException(
+ sprintf(
+ 'Specify the name of the LiquiBase.jar. "%s" does not exist!',
+ $this->jar
+ )
+ );
+ }
+
+ if((null === $this->changeLogFile) or !file_exists($this->changeLogFile))
+ {
+ throw new BuildException(
+ sprintf(
+ 'Specify the name of the Changelog file. "%s" does not exist!',
+ $this->changeLogFile
+ )
+ );
+ }
+
+ if(null === $this->classpathref)
+ {
+ throw new BuildException('Please provide a classpath!');
+ }
+
+ if(null === $this->username)
+ {
+ throw new BuildException('Please provide a username for database acccess!');
+ }
+
+ if(null === $this->password)
+ {
+ throw new BuildException('Please provide a password for database acccess!');
+ }
+
+ if(null === $this->url)
+ {
+ throw new BuildException('Please provide a url for database acccess!');
+ }
+ }
+
+
+ /**
+ * Executes the given command and returns the output.
+ *
+ * @param string the command to execute
+ * @param string additional parameters
+ * @return string the output of the executed command
+ */
+ protected function execute($lbcommand, $lbparams = '')
+ {
+ $command = sprintf(
+ 'java -jar %s --changeLogFile=%s --url=%s --username=%s --password=%s --classpath=%s %s %s',
+ escapeshellarg($this->jar),
+ escapeshellarg($this->changeLogFile),
+ escapeshellarg($this->url),
+ escapeshellarg($this->username),
+ escapeshellarg($this->password),
+ escapeshellarg($this->classpathref),
+ escapeshellarg($lbcommand),
+ $lbparams
+ );
+
+ passthru($command);
+
+ return;
+ }
+} \ No newline at end of file
diff --git a/buildscripts/phing/classes/phing/tasks/ext/liquibase/LiquibaseChangeLogTask.php b/buildscripts/phing/classes/phing/tasks/ext/liquibase/LiquibaseChangeLogTask.php
new file mode 100755
index 00000000..77fb97d2
--- /dev/null
+++ b/buildscripts/phing/classes/phing/tasks/ext/liquibase/LiquibaseChangeLogTask.php
@@ -0,0 +1,39 @@
+<?php
+
+/**
+ * Copyright (c) 2007-2011 bitExpert AG
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+require_once 'phing/tasks/ext/liquibase/AbstractLiquibaseTask.php';
+
+/**
+ * Task to create a changelog file.
+ *
+ * @author Stephan Hochdoerfer <S.Hochdoerfer@bitExpert.de>
+ * @version $Id$
+ * @since 2.4.10
+ * @package phing.tasks.ext.liquibase
+ */
+class LiquibaseChangeLogTask extends AbstractLiquibaseTask
+{
+ /**
+ * @see Task::main()
+ */
+ public function main()
+ {
+ $this->checkParams();
+ $this->execute('generateChangeLog');
+ }
+} \ No newline at end of file
diff --git a/buildscripts/phing/classes/phing/tasks/ext/liquibase/LiquibaseDbDocTask.php b/buildscripts/phing/classes/phing/tasks/ext/liquibase/LiquibaseDbDocTask.php
new file mode 100755
index 00000000..e79fae92
--- /dev/null
+++ b/buildscripts/phing/classes/phing/tasks/ext/liquibase/LiquibaseDbDocTask.php
@@ -0,0 +1,86 @@
+<?php
+
+/**
+ * Copyright (c) 2007-2011 bitExpert AG
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+require_once 'phing/tasks/ext/liquibase/AbstractLiquibaseTask.php';
+
+/**
+ * Task to create a javadoc-like documentation based on current database and
+ * changelog.
+ *
+ * @author Stephan Hochdoerfer <S.Hochdoerfer@bitExpert.de>
+ * @version $Id$
+ * @since 2.4.10
+ * @package phing.tasks.ext.liquibase
+ */
+class LiquibaseDbDocTask extends AbstractLiquibaseTask
+{
+ protected $outputDir;
+
+
+ /**
+ * Sets the output directory where the documentation gets generated to.
+ *
+ * @param string the output directory
+ */
+ public function setOutputDir($outputDir)
+ {
+ $this->outputDir = $outputDir;
+ }
+
+
+ /**
+ * @see AbstractTask::checkParams()
+ */
+ protected function checkParams()
+ {
+ parent::checkParams();
+
+ if((null === $this->outputDir) or !is_dir($this->outputDir))
+ {
+ if(!mkdir($this->outputDir, 0777, true))
+ {
+ throw new BuildException(
+ sprintf(
+ 'The directory "%s" does not exist and could not be created!',
+ $this->outputDir
+ )
+ );
+ }
+ }
+
+ if(!is_writable($this->outputDir))
+ {
+ throw new BuildException(
+ sprintf(
+ 'The directory "%s" is not writable!',
+ $this->outputDir
+ )
+ );
+ }
+ }
+
+
+ /**
+ * @see Task::main()
+ */
+ public function main()
+ {
+ $this->checkParams();
+ $this->execute('dbdoc', escapeshellarg($this->outputDir));
+ }
+} \ No newline at end of file
diff --git a/buildscripts/phing/classes/phing/tasks/ext/liquibase/LiquibaseDiffTask.php b/buildscripts/phing/classes/phing/tasks/ext/liquibase/LiquibaseDiffTask.php
new file mode 100755
index 00000000..847f1401
--- /dev/null
+++ b/buildscripts/phing/classes/phing/tasks/ext/liquibase/LiquibaseDiffTask.php
@@ -0,0 +1,137 @@
+<?php
+
+/**
+ * Copyright (c) 2007-2011 bitExpert AG
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+require_once 'phing/tasks/ext/liquibase/AbstractLiquibaseTask.php';
+
+/**
+ * Task to create the diff between two databases. Will output the changes needed
+ * to convert the reference database to the database.
+ *
+ * @author Stephan Hochdoerfer <S.Hochdoerfer@bitExpert.de>
+ * @version $Id$
+ * @since 2.4.10
+ * @package phing.tasks.ext.liquibase
+ */
+class LiquibaseDiffTask extends AbstractLiquibaseTask
+{
+ protected $referenceUsername;
+ protected $referencePassword;
+ protected $referenceUrl;
+
+
+ /**
+ * Sets the username to connect to the reference database.
+ *
+ * @param string the username
+ */
+ public function setReferenceUsername($username)
+ {
+ $this->referenceUsername = $username;
+ }
+
+
+ /**
+ * Sets the password to connect to the refernce database.
+ *
+ * @param string the password
+ */
+ public function setReferencePassword($password)
+ {
+ $this->referencePassword = $password;
+ }
+
+
+ /**
+ * Sets the url to connect to the reference database in jdbc style, e.g.
+ * <code>
+ * jdbc:postgresql://psqlhost/myrefdatabase
+ * </code>
+ *
+ * @param string jdbc connection string
+ */
+ public function setReferenceUrl($url)
+ {
+ $this->referenceUrl = $url;
+ }
+
+
+ /**
+ * @see AbstractTask::checkParams()
+ */
+ protected function checkParams()
+ {
+ parent::checkParams();
+
+ if(null === $this->referenceUsername)
+ {
+ throw new BuildException('Please provide a username for the reference database acccess!');
+ }
+
+ if(null === $this->referencePassword)
+ {
+ throw new BuildException('Please provide a password for the reference database acccess!');
+ }
+
+ if(null === $this->referenceUrl)
+ {
+ throw new BuildException('Please provide a url for the reference database acccess!');
+ }
+ }
+
+
+ /**
+ * @see Task::main()
+ */
+ public function main()
+ {
+ $this->checkParams();
+
+ $refparams = sprintf(
+ '--referenceUsername=%s --referencePassword=%s --referenceUrl=%s',
+ escapeshellarg($this->referenceUsername),
+ escapeshellarg($this->referencePassword),
+ escapeshellarg($this->referenceUrl)
+ );
+
+ // save main changelog file
+ $changelogFile = $this->changeLogFile;
+
+ // set the name of the new generated changelog file
+ $this->setChangeLogFile(dirname($changelogFile).'/diffs/'.date('YmdHis').'.xml');
+ if(!is_dir(dirname($changelogFile).'/diffs/'))
+ {
+ mkdir(dirname($changelogFile).'/diffs/', 0777, true);
+ }
+ $this->execute('diffChangeLog', $refparams);
+
+ $xmlFile = new DOMDocument();
+ $xmlFile->load($changelogFile);
+
+ // create the new node
+ $rootNode = $xmlFile->getElementsByTagName('databaseChangeLog')->item(0);
+ $includeNode = $rootNode->appendChild($xmlFile->createElement('include'));
+
+ // set the attributes for the new node
+ $includeNode->setAttribute('file', str_replace(dirname($changelogFile).'/', '', $this->changeLogFile));
+ $includeNode->setAttribute('relativeToChangelogFile', 'true');
+ file_put_contents($changelogFile, $xmlFile->saveXML());
+
+ $this->setChangeLogFile($changelogFile);
+ $this->execute('markNextChangeSetRan');
+ }
+} \ No newline at end of file
diff --git a/buildscripts/phing/classes/phing/tasks/ext/liquibase/LiquibaseRollbackTask.php b/buildscripts/phing/classes/phing/tasks/ext/liquibase/LiquibaseRollbackTask.php
new file mode 100755
index 00000000..ec5584e6
--- /dev/null
+++ b/buildscripts/phing/classes/phing/tasks/ext/liquibase/LiquibaseRollbackTask.php
@@ -0,0 +1,72 @@
+<?php
+
+/**
+ * Copyright (c) 2007-2011 bitExpert AG
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+require_once 'phing/tasks/ext/liquibase/AbstractLiquibaseTask.php';
+
+/**
+ * Rollbacks the database changes.
+ *
+ * @author Stephan Hochdoerfer <S.Hochdoerfer@bitExpert.de>
+ * @version $Id$
+ * @since 2.4.10
+ * @package phing.tasks.ext.liquibase
+ */
+class LiquibaseRollbackTask extends AbstractLiquibaseTask
+{
+ protected $rollbackTag;
+
+
+ /**
+ * Sets the name of the tag to roll back to.
+ *
+ * @param string the name to roll back to
+ */
+ public function setRollbackTag($rollbackTag)
+ {
+ $this->rollbackTag = $rollbackTag;
+ }
+
+
+ /**
+ * @see AbstractTask::checkParams()
+ */
+ protected function checkParams()
+ {
+ parent::checkParams();
+
+ if(null === $this->rollbackTag)
+ {
+ throw new BuildException(
+ sprintf(
+ 'Please specify the tag to rollback to!',
+ $this->rollbackTag
+ )
+ );
+ }
+ }
+
+
+ /**
+ * @see Task::main()
+ */
+ public function main()
+ {
+ $this->checkParams();
+ $this->execute('rollback', escapeshellarg($this->rollbackTag));
+ }
+} \ No newline at end of file
diff --git a/buildscripts/phing/classes/phing/tasks/ext/liquibase/LiquibaseTagTask.php b/buildscripts/phing/classes/phing/tasks/ext/liquibase/LiquibaseTagTask.php
new file mode 100755
index 00000000..07b0e72e
--- /dev/null
+++ b/buildscripts/phing/classes/phing/tasks/ext/liquibase/LiquibaseTagTask.php
@@ -0,0 +1,75 @@
+<?php
+
+/**
+ * Copyright (c) 2007-2011 bitExpert AG
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+require_once 'phing/tasks/ext/liquibase/AbstractLiquibaseTask.php';
+
+/**
+ * Task to tag the current database state. In case you tag the database multiple
+ * times without applying a new changelog before, the tags will overwrite each
+ * other!
+ *
+ * @author Stephan Hochdoerfer <S.Hochdoerfer@bitExpert.de>
+ * @version $Id$
+ * @since 2.4.10
+ * @package phing.tasks.ext.liquibase
+ */
+class LiquibaseTagTask extends AbstractLiquibaseTask
+{
+ protected $tag;
+
+
+ /**
+ * Sets the name of tag which is used to mark the database state for
+ * possible future rollback.
+ *
+ * @param string the name to tag the database with
+ */
+ public function setTag($tag)
+ {
+ $this->tag = $tag;
+ }
+
+
+ /**
+ * @see AbstractTask::checkParams()
+ */
+ protected function checkParams()
+ {
+ parent::checkParams();
+
+ if(null === $this->tag)
+ {
+ throw new BuildException(
+ sprintf(
+ 'Please specify the tag!',
+ $this->tag
+ )
+ );
+ }
+ }
+
+
+ /**
+ * @see Task::main()
+ */
+ public function main()
+ {
+ $this->checkParams();
+ $this->execute('tag', escapeshellarg($this->tag));
+ }
+} \ No newline at end of file
diff --git a/buildscripts/phing/classes/phing/tasks/ext/liquibase/LiquibaseUpdateTask.php b/buildscripts/phing/classes/phing/tasks/ext/liquibase/LiquibaseUpdateTask.php
new file mode 100755
index 00000000..35162e4d
--- /dev/null
+++ b/buildscripts/phing/classes/phing/tasks/ext/liquibase/LiquibaseUpdateTask.php
@@ -0,0 +1,39 @@
+<?php
+
+/**
+ * Copyright (c) 2007-2011 bitExpert AG
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+require_once 'phing/tasks/ext/liquibase/AbstractLiquibaseTask.php';
+
+/**
+ * Task to update the database to latest version of the changelog file.
+ *
+ * @author Stephan Hochdoerfer <S.Hochdoerfer@bitExpert.de>
+ * @version $Id$
+ * @since 2.4.10
+ * @package phing.tasks.ext.liquibase
+ */
+class LiquibaseUpdateTask extends AbstractLiquibaseTask
+{
+ /**
+ * @see Task::main()
+ */
+ public function main()
+ {
+ $this->checkParams();
+ $this->execute('update');
+ }
+} \ No newline at end of file