Exemple #1
0
 /**
  * "Exports" the local working copy to a fresh dir, without any SCM
  * artifacts like .git
  *
  * @see ScmConnectorInterface::export()
  */
 public function export($toDir)
 {
     //TODO: export a tag
     if (!Framework_Filesystem::copy($this->getLocal(), $toDir)) {
         SystemEvent::raise(SystemEvent::INFO, "Could not export local working copy. [LOCAL={$this->getLocal()}] [DIR={$toDir}]", __METHOD__);
     }
     return true;
 }
Exemple #2
0
 /**
  * Deletes a local dir used to manage a remote SCM repository. This is
  * tipically used for resetting the sources of a project (good for
  * when the user changes SCM settings).
  *
  * @param string $local
  */
 public static function delete($local)
 {
     $ret = false;
     if (!empty($local)) {
         $ret = Framework_Filesystem::removeDir($local);
     }
     #if DEBUG
     if ($ret) {
         SystemEvent::raise(SystemEvent::DEBUG, "Deleted local working copy. [DIR={$local}]", __METHOD__);
     } else {
         SystemEvent::raise(SystemEvent::DEBUG, "Could not delete local working copy. [DIR={$local}]", __METHOD__);
     }
     #endif
     return $ret;
 }
Exemple #3
0
 public function build($force = false)
 {
     //
     // Since some SCM operations might take a while, put the project on
     // BUILDING status right away
     //
     $status = $this->getStatus();
     $this->setStatus(self::STATUS_BUILDING);
     $this->_save(true);
     // We want the building status to update imediatelly
     $this->setStatus($status);
     $params = array();
     $scm = new ScmConnector($this->getScmConnectorType(), $this->getScmLocalWorkingCopy(), $this->getScmRemoteRepository(), $this->getScmUsername(), $this->getScmPassword(), $this->getScmEnvVars());
     if ($this->getStatus() == self::STATUS_ERROR && !$force) {
         $this->touchDateCheckedForChanges();
         SystemEvent::raise(SystemEvent::INFO, "Project is in error state, to build you need to force. [PROJECTID={$this->getId()}]", __METHOD__);
         return false;
     }
     if ($this->getStatus() == self::STATUS_BUILDING) {
         SystemEvent::raise(SystemEvent::INFO, "Project is currently building, or is queued for building. [PROJECTID={$this->getId()}]", __METHOD__);
         //$this->setStatus(self::STATUS_ERROR);
         return false;
     }
     if ($this->getStatus() != self::STATUS_MODIFIED) {
         //
         // Checkout required?
         //
         $this->touchDateCheckedForChanges();
         if ($this->getStatus() == self::STATUS_UNINITIALIZED || !file_exists($this->getScmLocalWorkingCopy())) {
             if (!$scm->checkout()) {
                 SystemEvent::raise(SystemEvent::INFO, "Couldn't checkout sources. [PROJECTID={$this->getId()}]", __METHOD__);
                 $this->setStatus(self::STATUS_UNINITIALIZED);
                 return false;
             }
         } else {
             if ($this->getStatus() == self::STATUS_UNBUILT) {
                 $force = true;
             }
             if (!$scm->isModified()) {
                 SystemEvent::raise(SystemEvent::INFO, "No modifications detected. [PROJECTID={$this->getId()}]", __METHOD__);
                 if (!$force) {
                     //$this->setStatus(self::STATUS_OK);
                     return false;
                 }
             }
         }
     }
     $this->setStatus(self::STATUS_MODIFIED);
     $rev = null;
     // Keep this for now, add it to the project build later.
     if (!$scm->update($rev)) {
         SystemEvent::raise(SystemEvent::INFO, "Couldn't update local sources. [PROJECTID={$this->getId()}]", __METHOD__);
         if (!$force) {
             $this->setStatus(self::STATUS_ERROR);
             return false;
         }
     }
     //
     // Clean up sources dir and fresh populate it with the new SCM sources
     //
     if (!Framework_Filesystem::emptyDir($this->getSourcesDir()) || !$scm->export($this->getSourcesDir())) {
         SystemEvent::raise(SystemEvent::INFO, "Couldn't refresh the sources dir. [PROJECTID={$this->getId()}]", __METHOD__);
         $this->setStatus(self::STATUS_ERROR);
         return false;
     }
     // We're now building
     $this->setStatus(self::STATUS_BUILDING);
     //$this->_save(true); // We want the building status to update imediatelly
     //
     // Scm stuff done, setup a new build for the project
     //
     $build = new Project_Build($this);
     $build->setScmRevision($rev);
     $this->triggerNotification(NotificationSettings::BUILD_STARTED);
     if (!$build->init()) {
         $this->setStatus(self::STATUS_FAILED);
         SystemEvent::raise(SystemEvent::INFO, "Integration build failed. [PROJECTID={$this->getId()}]", __METHOD__);
         $this->triggerNotification(NotificationSettings::BUILD_FAILED);
         return false;
     }
     $this->setStatus(self::STATUS_OK);
     $this->incrementStatsNumBuilds();
     $build->setLabel($this->getReleaseLabel());
     // make sure the project's release counter was incremented
     if ($this->getOptionReleasePackage()) {
         $build->generateReleasePackage();
     }
     SystemEvent::raise(SystemEvent::INFO, "Integration build successful. [PROJECTID={$this->getId()}]", __METHOD__);
     $this->triggerNotification(NotificationSettings::BUILD_SUCCESS);
     return true;
 }
Exemple #4
0
 public function generateReleasePackage()
 {
     $ret = false;
     if ($this->getStatus() != self::STATUS_FAIL) {
         $project = $this->getPtrProject();
         // Easier handling
         $filename = "{$project->getReleasesDir()}{$project->getReleaseLabel()}-{$this->getId()}";
         //
         // Rename the sources dir to the new dir that will be archived
         //
         $releaseDirName = "{$project->getReleaseLabel()}-{$this->getId()}";
         $releaseDirPath = "{$project->getTempDir()}{$releaseDirName}";
         if (!@rename($project->getSourcesDir(), $releaseDirPath)) {
             SystemEvent::raise(SystemEvent::ERROR, "Problems creating release dir. [BUILD={$this->getId()}] [PID={$project->getId()}]", __METHOD__);
             return false;
         }
         //
         // TODO: For now only tar is available. As soon as more are implemented,
         // it is required that Project keeps it's preferred archiver, so
         // that it can be fetched here and fed into getCmdForPackageGeneration()
         //
         $params = array('tmpDir' => $project->getTempDir(), 'archiverExecutable' => SystemSettings::EXECUTABLE_TAR, 'releaseLabel' => $filename, 'sourcesDir' => $releaseDirName);
         $command = $GLOBALS['settings']->getCmdForPackageGeneration($params);
         $command = str_replace('\\', '/', $command);
         $command = str_replace('//', '/', $command);
         if (preg_match("/({$project->getReleaseLabel()}-{$this->getId()}[.\\w]+) /", $command, $matches)) {
             $filename = $matches[1];
             // Get the filename extension
         }
         $proc = new Framework_Process();
         $proc->setExecutable($command, false);
         $proc->run();
         if ($proc->getReturnValue() == 0) {
             $this->setReleaseFile($filename);
             $this->setStatus(self::STATUS_OK_WITH_PACKAGE);
             $ret = true;
             SystemEvent::raise(SystemEvent::DEBUG, "Generated release package for build. [BUILD={$this->getId()}] [PID={$project->getId()}] [COMMAND={$command}]", __METHOD__);
         } else {
             SystemEvent::raise(SystemEvent::ERROR, "Problems generating release package for build. [BUILD={$this->getId()}] [PID={$project->getId()}] [COMMAND={$command}]", __METHOD__);
         }
         // Remove the release dir
         Framework_Filesystem::removeDir($releaseDirPath);
     }
     return $ret;
 }