summaryrefslogtreecommitdiff
path: root/buildscripts/phing/classes/phing/mappers
diff options
context:
space:
mode:
Diffstat (limited to 'buildscripts/phing/classes/phing/mappers')
-rw-r--r--buildscripts/phing/classes/phing/mappers/FileNameMapper.php59
-rw-r--r--buildscripts/phing/classes/phing/mappers/FlattenMapper.php55
-rw-r--r--buildscripts/phing/classes/phing/mappers/GlobMapper.php113
-rw-r--r--buildscripts/phing/classes/phing/mappers/IdentityMapper.php54
-rw-r--r--buildscripts/phing/classes/phing/mappers/MergeMapper.php69
-rw-r--r--buildscripts/phing/classes/phing/mappers/RegexpMapper.php97
6 files changed, 447 insertions, 0 deletions
diff --git a/buildscripts/phing/classes/phing/mappers/FileNameMapper.php b/buildscripts/phing/classes/phing/mappers/FileNameMapper.php
new file mode 100644
index 00000000..c8f1f8a9
--- /dev/null
+++ b/buildscripts/phing/classes/phing/mappers/FileNameMapper.php
@@ -0,0 +1,59 @@
+<?php
+/*
+ * $Id: FileNameMapper.php,v 1.7 2004/01/22 03:29:13 hlellelid Exp $
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * and is licensed under the LGPL. For more information please see
+ * <http://phing.info>.
+ */
+
+/**
+ * Interface for filename mapper classes.
+ *
+ * @author Andreas Aderhold, andi@binarycloud.com
+ * @author Hans Lellelid <hans@xmpl.org>
+ * @version $Revision: 1.7 $
+ * @package phing.mappers
+ */
+interface FileNameMapper {
+
+ /**
+ * The mapper implementation.
+ *
+ * @param mixed $sourceFileName The data the mapper works on.
+ * @return array The data after the mapper has been applied; must be in array format (for some reason).
+ */
+ public function main($sourceFileName);
+
+ /**
+ * Accessor. Sets the to property. The actual implementation
+ * depends on the child class.
+ *
+ * @param string $to To what this mapper should convert the from string
+ * @return void
+ */
+ public function setTo($to);
+
+ /**
+ * Accessor. Sets the from property. What this mapper should
+ * recognize. The actual implementation is dependent upon the
+ * child class
+ *
+ * @param string $from On what this mapper should work
+ * @return void
+ */
+ public function setFrom($from);
+
+}
diff --git a/buildscripts/phing/classes/phing/mappers/FlattenMapper.php b/buildscripts/phing/classes/phing/mappers/FlattenMapper.php
new file mode 100644
index 00000000..fea5c1e4
--- /dev/null
+++ b/buildscripts/phing/classes/phing/mappers/FlattenMapper.php
@@ -0,0 +1,55 @@
+<?php
+/*
+ * $Id: FlattenMapper.php,v 1.9 2005/05/26 13:10:51 mrook Exp $
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * and is licensed under the LGPL. For more information please see
+ * <http://phing.info>.
+ */
+
+require_once 'phing/mappers/FileNameMapper.php';
+
+/**
+ * Removes any directory information from the passed path.
+ *
+ * @author Andreas Aderhold <andi@binarycloud.com>
+ * @version $Revision: 1.9 $
+ * @package phing.mappers
+ */
+class FlattenMapper implements FileNameMapper {
+
+ /**
+ * The mapper implementation. Returns string with source filename
+ * but without leading directory information
+ *
+ * @param string $sourceFileName The data the mapper works on
+ * @return array The data after the mapper has been applied
+ */
+ function main($sourceFileName) {
+ $f = new PhingFile($sourceFileName);
+ return array($f->getName());
+ }
+
+ /**
+ * Ignored here.
+ */
+ function setTo($to) {}
+
+ /**
+ * Ignored here.
+ */
+ function setFrom($from) {}
+
+}
diff --git a/buildscripts/phing/classes/phing/mappers/GlobMapper.php b/buildscripts/phing/classes/phing/mappers/GlobMapper.php
new file mode 100644
index 00000000..3c178620
--- /dev/null
+++ b/buildscripts/phing/classes/phing/mappers/GlobMapper.php
@@ -0,0 +1,113 @@
+<?php
+/*
+ * $Id: GlobMapper.php,v 1.10 2004/01/22 03:29:13 hlellelid Exp $
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * and is licensed under the LGPL. For more information please see
+ * <http://phing.info>.
+ */
+
+include_once 'phing/mappers/FileNameMapper.php';
+
+/**
+ * description here
+ *
+ * @author Andreas Aderhold, andi@binarycloud.com
+ * @version $Revision: 1.10 $
+ * @package phing.mappers
+ */
+class GlobMapper implements FileNameMapper {
+
+ /**
+ * Part of &quot;from&quot; pattern before the *.
+ */
+ private $fromPrefix = null;
+
+ /**
+ * Part of &quot;from&quot; pattern after the *.
+ */
+ private $fromPostfix = null;
+
+ /**
+ * Length of the prefix (&quot;from&quot; pattern).
+ */
+ private $prefixLength;
+
+ /**
+ * Length of the postfix (&quot;from&quot; pattern).
+ */
+ private $postfixLength;
+
+ /**
+ * Part of &quot;to&quot; pattern before the *.
+ */
+ private $toPrefix = null;
+
+ /**
+ * Part of &quot;to&quot; pattern after the *.
+ */
+ private $toPostfix = null;
+
+
+ function main($_sourceFileName) {
+ if (($this->fromPrefix === null)
+ || !StringHelper::startsWith($this->fromPrefix, $_sourceFileName)
+ || !StringHelper::endsWith($this->fromPostfix, $_sourceFileName)) {
+ return null;
+ }
+ $varpart = $this->_extractVariablePart($_sourceFileName);
+ $substitution = $this->toPrefix.$varpart.$this->toPostfix;
+ return array($substitution);
+ }
+
+
+
+ function setFrom($from) {
+ $index = strrpos($from, '*');
+
+ if ($index === false) {
+ $this->fromPrefix = $from;
+ $this->fromPostfix = "";
+ } else {
+ $this->fromPrefix = substr($from, 0, $index);
+ $this->fromPostfix = substr($from, $index+1);
+ }
+ $this->prefixLength = strlen($this->fromPrefix);
+ $this->postfixLength = strlen($this->fromPostfix);
+ }
+
+ /**
+ * Sets the &quot;to&quot; pattern. Required.
+ */
+ function setTo($to) {
+ $index = strrpos($to, '*');
+ if ($index === false) {
+ $this->toPrefix = $to;
+ $this->toPostfix = "";
+ } else {
+ $this->toPrefix = substr($to, 0, $index);
+ $this->toPostfix = substr($to, $index+1);
+ }
+ }
+
+ private function _extractVariablePart($_name) {
+ // ergh, i really hate php's string functions .... all but natural
+ $start = ($this->prefixLength === 0) ? 0 : $this->prefixLength;
+ $end = ($this->postfixLength === 0) ? strlen($_name) : strlen($_name) - $this->postfixLength;
+ $len = $end-$start;
+ return substr($_name, $start, $len);
+ }
+
+}
diff --git a/buildscripts/phing/classes/phing/mappers/IdentityMapper.php b/buildscripts/phing/classes/phing/mappers/IdentityMapper.php
new file mode 100644
index 00000000..daf80c25
--- /dev/null
+++ b/buildscripts/phing/classes/phing/mappers/IdentityMapper.php
@@ -0,0 +1,54 @@
+<?php
+/*
+ * $Id: IdentityMapper.php,v 1.7 2004/01/22 03:29:13 hlellelid Exp $
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * and is licensed under the LGPL. For more information please see
+ * <http://phing.info>.
+ */
+
+require_once 'phing/mappers/FileNameMapper.php';
+
+/**
+ * This mapper does nothing ;)
+ *
+ * @author Andreas Aderhold <andi@binarycloud.com>
+ * @author Hans Lellelid <hans@xmpl.org>
+ * @version $Revision: 1.7 $
+ * @package phing.mappers
+ */
+class IdentityMapper implements FileNameMapper {
+
+ /**
+ * The mapper implementation. Basically does nothing in this case.
+ *
+ * @param string $sourceFileName The data the mapper works on.
+ * @return array The data after the mapper has been applied
+ */
+ function main($sourceFileName) {
+ return array($sourceFileName);
+ }
+
+ /**
+ * Ignored here.
+ */
+ function setTo($to) {}
+
+ /**
+ * Ignored here.
+ */
+ function setFrom($from) {}
+
+}
diff --git a/buildscripts/phing/classes/phing/mappers/MergeMapper.php b/buildscripts/phing/classes/phing/mappers/MergeMapper.php
new file mode 100644
index 00000000..f10f41c0
--- /dev/null
+++ b/buildscripts/phing/classes/phing/mappers/MergeMapper.php
@@ -0,0 +1,69 @@
+<?php
+/*
+ * $Id: MergeMapper.php,v 1.8 2004/01/22 03:29:13 hlellelid Exp $
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * and is licensed under the LGPL. For more information please see
+ * <http://phing.info>.
+ */
+
+include_once 'phing/mappers/FileNameMapper.php';
+
+/**
+ * For merging files into a single file. In practice just returns whatever value
+ * was set for "to".
+ *
+ * @author Andreas Aderhold <andi@binarycloud.com>
+ * @version $Revision: 1.8 $
+ * @package phing.mappers
+ */
+class MergeMapper implements FileNameMapper {
+
+ /** the merge */
+ private $mergedFile;
+
+ /**
+ * The mapper implementation. Basically does nothing in this case.
+ *
+ * @param mixed The data the mapper works on
+ * @returns mixed The data after the mapper has been applied
+ * @access public
+ * @author Andreas Aderhold, andi@binarycloud.com
+ */
+ function main($sourceFileName) {
+ if ($this->mergedFile === null) {
+ throw new BuildException("MergeMapper error, to attribute not set");
+ }
+ return array($this->mergedFile);
+ }
+
+ /**
+ * Accessor. Sets the to property
+ *
+ * @param string To what this mapper should convert the from string
+ * @returns boolean True
+ * @access public
+ * @author Andreas Aderhold, andi@binarycloud.com
+ */
+ function setTo($to) {
+ $this->mergedFile = $to;
+ }
+
+ /**
+ * Ignored.
+ */
+ function setFrom($from) {}
+
+}
diff --git a/buildscripts/phing/classes/phing/mappers/RegexpMapper.php b/buildscripts/phing/classes/phing/mappers/RegexpMapper.php
new file mode 100644
index 00000000..a3d51976
--- /dev/null
+++ b/buildscripts/phing/classes/phing/mappers/RegexpMapper.php
@@ -0,0 +1,97 @@
+<?php
+/*
+ * $Id: RegexpMapper.php,v 1.9 2004/03/15 17:11:15 hlellelid Exp $
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * and is licensed under the LGPL. For more information please see
+ * <http://phing.info>.
+ */
+
+require_once 'phing/mappers/FileNameMapper.php';
+include_once 'phing/util/StringHelper.php';
+include_once 'phing/util/regexp/Regexp.php';
+
+/**
+ * Uses regular expressions to perform filename transformations.
+ *
+ * @author Andreas Aderhold <andi@binarycloud.com>
+ * @author Hans Lellelid <hans@velum.net>
+ * @version $Revision: 1.9 $
+ * @package phing.mappers
+ */
+class RegexpMapper implements FileNameMapper {
+
+ /**
+ * @var string
+ */
+ private $to;
+
+ /**
+ * The Regexp engine.
+ * @var Regexp
+ */
+ private $reg;
+
+ function __construct() {
+ // instantiage regexp matcher here
+ $this->reg = new Regexp();
+ }
+
+ /**
+ * Sets the &quot;from&quot; pattern. Required.
+ */
+ function setFrom($from) {
+ $this->reg->SetPattern($from);
+ }
+
+ /**
+ * Sets the &quot;to&quot; pattern. Required.
+ */
+ function setTo($to) {
+
+ // [HL] I'm changing the way this works for now to just use string
+ //$this->to = StringHelper::toCharArray($to);
+
+ $this->to = $to;
+ }
+
+ function main($sourceFileName) {
+ if ($this->reg === null || $this->to === null || !$this->reg->matches((string) $sourceFileName)) {
+ return null;
+ }
+ return array($this->replaceReferences($sourceFileName));
+ }
+
+ /**
+ * Replace all backreferences in the to pattern with the matched groups.
+ * groups of the source.
+ * @param string $source The source filename.
+ */
+ private function replaceReferences($source) {
+
+ // FIXME
+ // Can't we just use engine->replace() to handle this? the Preg engine
+ // will automatically convert \1 references to $1
+
+ // the expression has already been processed (when ->matches() was run in Main())
+ // so no need to pass $source again to the engine.
+ $groups = (array) $this->reg->getGroups();
+
+ // replace \1 with value of $groups[1] and return the modified "to" string
+ return preg_replace('/\\\([\d]+)/e', "\$groups[$1]", $this->to);
+ }
+
+}
+