/**
  * [REQUIRED] Set the output directory. It will be
  * created if it doesn't exist.
  * @param  PhingFile $outputDirectory
  * @return void
  * @throws Exception
  */
 public function setOutputDirectory(PhingFile $outputDirectory)
 {
     try {
         if (!$outputDirectory->exists()) {
             $this->log("Output directory does not exist, creating: " . $outputDirectory->getPath(), Project::MSG_VERBOSE);
             if (!$outputDirectory->mkdirs()) {
                 throw new IOException("Unable to create Ouptut directory: " . $outputDirectory->getAbsolutePath());
             }
         }
         $this->outputDirectory = $outputDirectory->getCanonicalPath();
     } catch (IOException $ioe) {
         throw new BuildException($ioe);
     }
 }
Example #2
0
 /**
  * The main entry point method.
  */
 public function main()
 {
     $project = $this->getProject();
     require_once 'Net/FTP.php';
     $ftp = new Net_FTP($this->host, $this->port);
     if ($this->ssl) {
         $ret = $ftp->setSsl();
         if (@PEAR::isError($ret)) {
             throw new BuildException('SSL connection not supported by php' . ': ' . $ret->getMessage());
         } else {
             $this->log('Use SSL connection', $this->logLevel);
         }
     }
     $ret = $ftp->connect();
     if (@PEAR::isError($ret)) {
         throw new BuildException('Could not connect to FTP server ' . $this->host . ' on port ' . $this->port . ': ' . $ret->getMessage());
     } else {
         $this->log('Connected to FTP server ' . $this->host . ' on port ' . $this->port, $this->logLevel);
     }
     $ret = $ftp->login($this->username, $this->password);
     if (@PEAR::isError($ret)) {
         throw new BuildException('Could not login to FTP server ' . $this->host . ' on port ' . $this->port . ' with username ' . $this->username . ': ' . $ret->getMessage());
     } else {
         $this->log('Logged in to FTP server with username ' . $this->username, $this->logLevel);
     }
     if ($this->passive) {
         $this->log('Setting passive mode', $this->logLevel);
         $ret = $ftp->setPassive();
         if (@PEAR::isError($ret)) {
             $ftp->disconnect();
             throw new BuildException('Could not set PASSIVE mode: ' . $ret->getMessage());
         }
     }
     // append '/' to the end if necessary
     $dir = substr($this->dir, -1) == '/' ? $this->dir : $this->dir . '/';
     if ($this->clearFirst) {
         // TODO change to a loop through all files and directories within current directory
         $this->log('Clearing directory ' . $dir, $this->logLevel);
         $ftp->rm($dir, true);
     }
     // Create directory just in case
     $ret = $ftp->mkdir($dir, true);
     if (@PEAR::isError($ret)) {
         $ftp->disconnect();
         throw new BuildException('Could not create directory ' . $dir . ': ' . $ret->getMessage());
     }
     $ret = $ftp->cd($dir);
     if (@PEAR::isError($ret)) {
         $ftp->disconnect();
         throw new BuildException('Could not change to directory ' . $dir . ': ' . $ret->getMessage());
     } else {
         $this->log('Changed directory ' . $dir, $this->logLevel);
     }
     $fs = FileSystem::getFileSystem();
     $convert = $fs->getSeparator() == '\\';
     foreach ($this->filesets as $fs) {
         // Array for holding directory content informations
         $remoteFileInformations = array();
         $ds = $fs->getDirectoryScanner($project);
         $fromDir = $fs->getDir($project);
         $srcFiles = $ds->getIncludedFiles();
         $srcDirs = $ds->getIncludedDirectories();
         foreach ($srcDirs as $dirname) {
             if ($convert) {
                 $dirname = str_replace('\\', '/', $dirname);
             }
             // Read directory informations, if file exists, else create the directory
             if (!$this->_directoryInformations($ftp, $remoteFileInformations, $dirname)) {
                 $this->log('Will create directory ' . $dirname, $this->logLevel);
                 $ret = $ftp->mkdir($dirname, true);
                 if (@PEAR::isError($ret)) {
                     $ftp->disconnect();
                     throw new BuildException('Could not create directory ' . $dirname . ': ' . $ret->getMessage());
                 }
             }
             if ($this->dirmode) {
                 if ($this->dirmode == 'inherit') {
                     $mode = fileperms($dirname);
                 } else {
                     $mode = $this->dirmode;
                 }
                 // Because Net_FTP does not support a chmod call we call ftp_chmod directly
                 ftp_chmod($ftp->_handle, $mode, $dirname);
             }
         }
         foreach ($srcFiles as $filename) {
             $file = new PhingFile($fromDir->getAbsolutePath(), $filename);
             if ($convert) {
                 $filename = str_replace('\\', '/', $filename);
             }
             $local_filemtime = filemtime($file->getCanonicalPath());
             if (isset($remoteFileInformations[$filename]['stamp'])) {
                 $remoteFileModificationTime = $remoteFileInformations[$filename]['stamp'];
             } else {
                 $remoteFileModificationTime = 0;
             }
             if (!$this->depends || $local_filemtime > $remoteFileModificationTime) {
                 if ($this->skipOnSameSize === true && $file->length() === $ftp->size($filename)) {
                     $this->log('Skipped ' . $file->getCanonicalPath(), $this->logLevel);
                     continue;
                 }
                 $this->log('Will copy ' . $file->getCanonicalPath() . ' to ' . $filename, $this->logLevel);
                 $ret = $ftp->put($file->getCanonicalPath(), $filename, true, $this->mode);
                 if (@PEAR::isError($ret)) {
                     $ftp->disconnect();
                     throw new BuildException('Could not deploy file ' . $filename . ': ' . $ret->getMessage());
                 }
             }
             if ($this->filemode) {
                 if ($this->filemode == 'inherit') {
                     $mode = fileperms($filename);
                 } else {
                     $mode = $this->filemode;
                 }
                 // Because Net_FTP does not support a chmod call we call ftp_chmod directly
                 ftp_chmod($ftp->_handle, $mode, $filename);
             }
         }
     }
     $ftp->disconnect();
     $this->log('Disconnected from FTP server', $this->logLevel);
 }
Example #3
0
 /**
  * @param PhingFile $compressedArchiveFile
  * @throws BuildException
  * @internal param array $files array of filenames
  * @internal param PhingFile $dir
  * @return boolean
  */
 protected function isDestinationUpToDate(PhingFile $compressedArchiveFile)
 {
     if (!$compressedArchiveFile->exists()) {
         throw new BuildException("Could not find file " . $compressedArchiveFile->__toString() . " to extract.");
     }
     $compressedArchiveContent = $this->listArchiveContent($compressedArchiveFile);
     if (is_array($compressedArchiveContent)) {
         $fileSystem = FileSystem::getFileSystem();
         foreach ($compressedArchiveContent as $compressArchivePathInfo) {
             $compressArchiveFilename = $compressArchivePathInfo['filename'];
             if (!empty($this->removepath) && strlen($compressArchiveFilename) >= strlen($this->removepath)) {
                 $compressArchiveFilename = preg_replace('/^' . $this->removepath . '/', '', $compressArchiveFilename);
             }
             $compressArchivePath = new PhingFile($this->todir, $compressArchiveFilename);
             if (!$compressArchivePath->exists() || $fileSystem->compareMTimes($compressedArchiveFile->getCanonicalPath(), $compressArchivePath->getCanonicalPath()) == 1) {
                 return false;
             }
         }
     }
     return true;
 }
Example #4
0
 /**
  * The main entry point method.
  */
 public function main()
 {
     $project = $this->getProject();
     require_once 'Net/FTP.php';
     $ftp = new Net_FTP($this->host, $this->port);
     $ret = $ftp->connect();
     if (@PEAR::isError($ret)) {
         throw new BuildException('Could not connect to FTP server ' . $this->host . ' on port ' . $this->port . ': ' . $ret->getMessage());
     } else {
         $this->log('Connected to FTP server ' . $this->host . ' on port ' . $this->port, $this->logLevel);
     }
     $ret = $ftp->login($this->username, $this->password);
     if (@PEAR::isError($ret)) {
         throw new BuildException('Could not login to FTP server ' . $this->host . ' on port ' . $this->port . ' with username ' . $this->username . ': ' . $ret->getMessage());
     } else {
         $this->log('Logged in to FTP server with username ' . $this->username, $this->logLevel);
     }
     if ($this->passive) {
         $this->log('Setting passive mode', $this->logLevel);
         $ret = $ftp->setPassive();
         if (@PEAR::isError($ret)) {
             $ftp->disconnect();
             throw new BuildException('Could not set PASSIVE mode: ' . $ret->getMessage());
         }
     }
     // append '/' to the end if necessary
     $dir = substr($this->dir, -1) == '/' ? $this->dir : $this->dir . '/';
     if ($this->clearFirst) {
         // TODO change to a loop through all files and directories within current directory
         $this->log('Clearing directory ' . $dir, $this->logLevel);
         $ftp->rm($dir, true);
     }
     // Create directory just in case
     $ret = $ftp->mkdir($dir, true);
     if (@PEAR::isError($ret)) {
         $ftp->disconnect();
         throw new BuildException('Could not create directory ' . $dir . ': ' . $ret->getMessage());
     }
     $ret = $ftp->cd($dir);
     if (@PEAR::isError($ret)) {
         $ftp->disconnect();
         throw new BuildException('Could not change to directory ' . $dir . ': ' . $ret->getMessage());
     } else {
         $this->log('Changed directory ' . $dir, $this->logLevel);
     }
     $fs = FileSystem::getFileSystem();
     $convert = $fs->getSeparator() == '\\';
     foreach ($this->filesets as $fs) {
         $ds = $fs->getDirectoryScanner($project);
         $fromDir = $fs->getDir($project);
         $srcFiles = $ds->getIncludedFiles();
         $srcDirs = $ds->getIncludedDirectories();
         foreach ($srcDirs as $dirname) {
             if ($convert) {
                 $dirname = str_replace('\\', '/', $dirname);
             }
             $this->log('Will create directory ' . $dirname, $this->logLevel);
             $ret = $ftp->mkdir($dirname, true);
             if (@PEAR::isError($ret)) {
                 $ftp->disconnect();
                 throw new BuildException('Could not create directory ' . $dirname . ': ' . $ret->getMessage());
             }
         }
         foreach ($srcFiles as $filename) {
             $file = new PhingFile($fromDir->getAbsolutePath(), $filename);
             if ($convert) {
                 $filename = str_replace('\\', '/', $filename);
             }
             $this->log('Will copy ' . $file->getCanonicalPath() . ' to ' . $filename, $this->logLevel);
             $ret = $ftp->put($file->getCanonicalPath(), $filename, true, $this->mode);
             if (@PEAR::isError($ret)) {
                 $ftp->disconnect();
                 throw new BuildException('Could not deploy file ' . $filename . ': ' . $ret->getMessage());
             }
         }
     }
     $ftp->disconnect();
     $this->log('Disconnected from FTP server', $this->logLevel);
 }
Example #5
0
 /**
  * The heart of the matter. This is where the selector gets to decide
  * on the inclusion of a file in a particular fileset.
  *
  * @param  PhingFile $basedir  the base directory the scan is being done from
  * @param  string    $filename is the name of the file to check
  * @param  PhingFile $file     is a PhingFile object the selector can use
  * @return boolean   Whether the file should be selected or not
  */
 public function isSelected(PhingFile $basedir, $filename, PhingFile $file)
 {
     // throw BuildException on error
     $this->validate();
     if ($file->isLink()) {
         if ($this->type == 'link') {
             return true;
         }
         $this->log($file->getAbsolutePath() . " is a link, proceeding with " . $file->getCanonicalPath() . " instead.", Project::MSG_DEBUG);
         $file = new PhingFile($file->getCanonicalPath());
     }
     if ($file->isDirectory()) {
         return $this->type === 'dir';
     } else {
         return $this->type === 'file';
     }
 }