/** * Checks whether the Subversion project has been modified. * * @return boolean */ public function checkModified() { $result = new Xinc_Plugin_Repos_ModificationSet_Result(); $result->setChanged(true); $result->setStatus(Xinc_Plugin_Repos_ModificationSet_AbstractTask::CHANGED); return $result; }
public function mergeResultSet(Xinc_Plugin_Repos_ModificationSet_Result $set) { foreach ($set->getConflictResources() as $res) { $key = md5('C' . $res['filename'] . $res['author']); if (!in_array($key, $this->_index)) { $this->_conflictResources[] = $res; $this->_index[] = $key; } } foreach ($set->getUpdatedResources() as $res) { $key = md5('U' . $res['filename'] . $res['author']); if (!in_array($key, $this->_index)) { $this->_updatedResources[] = $res; $this->_index[] = $key; } } foreach ($set->getNewResources() as $res) { $key = md5('A' . $res['filename'] . $res['author']); if (!in_array($key, $this->_index)) { $this->_newResources[] = $res; $this->_index[] = $key; } } foreach ($set->getMergedResources() as $res) { $key = md5('M' . $res['filename'] . $res['author']); if (!in_array($key, $this->_index)) { $this->_mergedResources[] = $res; $this->_index[] = $key; } } foreach ($set->getLogMessages() as $res) { $key = md5('LM' . $res['revision'] . $res['date'] . $res['author'] . $res['message']); if (!in_array($key, $this->_index)) { $this->_logMessages[] = $res; $this->_index[] = $key; } } }
/** * Updates local svn to the remoteRevision for this test. * * @param Xinc_Plugin_Repos_ModificationSet_Result $result The Result to get * Hash ids from and set modified files. * * @return void * @throw Xinc_Exception_ModificationSet */ protected function update(Xinc_Plugin_Repos_ModificationSet_Result $result) { $arUpdate = $this->svn->update->run(array($this->task->getDirectory()), array('r' => $result->getRemoteRevision())); if (false === $arUpdate) { throw new Xinc_Exception_ModificationSet('SVN update local working copy failed', 0); } }
public function checkModified(Xinc_Build_Interface $build, $dir, $prefix, $switch = false, $svnFolderProperty = null) { $modResult = new Xinc_Plugin_Repos_ModificationSet_Result(); if (!file_exists($dir)) { $build->error('Subversion checkout directory not present'); $modResult->setStatus(Xinc_Plugin_Repos_ModificationSet_AbstractTask::ERROR); return $modResult; } $cwd = getcwd(); chdir($dir); $output = ''; $result = 9; exec($this->_svnPath . ' info', $output, $result); $found = false; if ($result == 0) { $localSet = implode("\n", $output); $localRev = $this->getRevision($localSet); $remoteRev = 0; $url = $this->getRootURL(); $output = ''; $result = 9; exec($this->_svnPath . ' ls --xml ' . $url . '/' . $this->_getSvnSubDir(), $output, $result); $remoteSet = implode("\n", $output); if ($result != 0) { $build->setStatus(Xinc_Build_Interface::FAILED); $build->error('Problem with remote Subversion repository'); $modResult->setStatus(Xinc_Plugin_Repos_ModificationSet_AbstractTask::ERROR); return $modResult; } $xml = new SimplexmlElement($remoteSet); foreach ($xml->list as $i => $list) { foreach ($list->entry as $entry) { if (substr($entry->name, 0, strlen($prefix)) != $prefix && !preg_match('/' . $prefix . '/', $entry->name)) { continue; } $attributes = $entry->attributes(); if (strtolower((string) $attributes['kind']) != 'dir') { continue; } $attributes = $entry->commit->attributes(); $rev = (int) $attributes->revision; if ($rev > $localRev) { $tagName = (string) $entry->name; if ($svnFolderProperty != null) { $build->getProperties()->set($svnFolderProperty, $tagName); } // switch to the latest release if ($switch) { exec($this->_svnPath . ' switch ' . $url . '/' . $this->_getSvnSubDir() . '/' . $tagName, $switchOut, $switchRes); if ($switchRes != 0) { $build->error('Could not switch to tag :' . $tagName . ', result:' . implode("\n", $switchOut)); $build->setStatus(Xinc_Build_Interface::FAILED); $modResult->setStatus(Xinc_Plugin_Repos_ModificationSet_AbstractTask::FAILED); return $modResult; } } $remoteRev = $rev; $found = true; } } } if ($remoteRev <= 0) { $build->info('Subversion checkout dir is ' . $dir . ' ' . 'local revision @ ' . $localRev . ' ' . 'No remote revision with matching tag prefix (' . $prefix . ')'); } else { $build->info('Subversion checkout dir is ' . $dir . ' ' . 'local revision @ ' . $localRev . ' ' . 'Last remote revision with matching tag prefix @ ' . $remoteRev . ' (' . $prefix . ')'); } chdir($cwd); $modResult->setLocalRevision($localRev); $modResult->setRemoteRevision($remoteRev); if ($modResult->isChanged()) { $modResult->setStatus(Xinc_Plugin_Repos_ModificationSet_AbstractTask::CHANGED); } return $modResult; } else { chdir($cwd); throw new Xinc_Exception_ModificationSet('Subversion checkout directory ' . 'is not a working copy.'); } }
/** * Gets the changelog data between two revisions from git and puts this info * into the ModificationSet_Result. (This are author, date and commit message.) * * @param Xinc_Plugin_Repos_ModificationSet_Result $result The Result to get * Hash ids from and set change log data. * * @return void * @throw Xinc_Exception_ModificationSet */ protected function getChangeLog(Xinc_Plugin_Repos_ModificationSet_Result $result) { $command = $this->git->getCommand('log')->setOption('pretty', 'H:%H%nA:%aN%nD:%aD%nM:%s')->addArgument($result->getLocalRevision() . '..' . $result->getRemoteRevision()); try { $strResult = $command->execute(); } catch (VersionControl_Git_Exception $e) { throw new Xinc_Exception_ModificationSet('GIT get log failed: ' . $e->getMessage(), 0, $e); } $arCommandLines = explode(PHP_EOL, trim($strResult)); while (count($arCommandLines)) { $strHash = $this->getLogEntry('H', $arCommandLines); $strAuthor = $this->getLogEntry('A', $arCommandLines); $strDate = $this->getLogEntry('D', $arCommandLines); $strMessage = $this->getLogEntry('M', $arCommandLines); $result->addLogMessage($strHash, $strDate, $strAuthor, $strMessage); } }