/**
  * Load the requested artifacts file and output it to the browser
  *
  * @param array $params
  */
 private function _getDocumentationFile($params)
 {
     /**$projectName = $params['p'];
        $buildTime = $params['buildtime'];
        $file = $params['file'];*/
     $query = urldecode($_SERVER['REQUEST_URI']);
     preg_match("/\\/(.*?)\\/(.*?)\\/(.*?)\\/(.*?)\\/(.*?)\\/(.*?)\\/(.*)/", $query, $matches);
     if (count($matches) != 8) {
         echo "Could not find documentation 1";
         die;
     }
     $projectName = $matches[5];
     $buildTime = $matches[6];
     // if buildtime==latest, get latest build
     // latest
     // Xinc_Build_History::get()
     $file = $matches[7];
     //$file = urldecode($file);
     $file = str_replace('/', DIRECTORY_SEPARATOR, $file);
     $project = new Xinc_Project();
     $project->setName($projectName);
     try {
         /**$build = Xinc_Build::unserialize($project,
            $buildTime,
            Xinc_Gui_Handler::getInstance()->getStatusDir());*/
         if ($buildTime == 'latest-successful') {
             $build = Xinc_Build_Repository::getLastSuccessfulBuild($project);
             $statusDir = Xinc_Build_History::getLastSuccessfulBuildDir($project);
         } else {
             if ($buildTime == 'latest') {
                 $build = Xinc_Build_Repository::getLastBuild($project);
                 $statusDir = Xinc_Build_History::getLastBuildDir($project);
             } else {
                 $build = Xinc_Build_Repository::getBuild($project, $buildTime);
                 $statusDir = Xinc_Build_History::getBuildDir($project, $buildTime);
             }
         }
         $statusDir .= DIRECTORY_SEPARATOR . Xinc_Plugin_Repos_Documentation::DOCUMENTATION_DIR . DIRECTORY_SEPARATOR;
         /**
          * Replace multiple / slashes with just one
          */
         $fileName = $statusDir . $file;
         $fileName = preg_replace('/\\' . DIRECTORY_SEPARATOR . '+/', DIRECTORY_SEPARATOR, $fileName);
         $realfile = realpath($fileName);
         if ($realfile != $fileName) {
             echo "Could not find documentation 2";
             die;
         } else {
             if (file_exists($fileName) && is_file($realfile)) {
                 return $this->_outputDoc($fileName);
             } else {
                 echo "Could not find documentation 3";
                 die;
             }
         }
     } catch (Exception $e) {
         echo "Could not find any documentation";
         die;
     }
 }
 /**
  * Load the requested artifacts file and output it to the browser
  *
  * @param array $params
  */
 private function _getDeliverableFile($params)
 {
     /**$projectName = $params['p'];
        $buildTime = $params['buildtime'];
        $file = $params['file'];*/
     $query = urldecode($_SERVER['REQUEST_URI']);
     preg_match("/\\/(.*?)\\/(.*?)\\/(.*?)\\/(.*?)\\/(.*?)\\/(.*?)\\/(.*)/", $query, $matches);
     if (count($matches) != 8) {
         echo "Could not find deliverable";
         die;
     }
     $projectName = $matches[5];
     $buildTime = $matches[6];
     // if buildtime==latest, get latest build
     // latest
     // Xinc_Build_History::get()
     $file = $matches[7];
     $file = str_replace('/', DIRECTORY_SEPARATOR, $file);
     $project = new Xinc_Project();
     $project->setName($projectName);
     try {
         /**$build = Xinc_Build::unserialize($project,
            $buildTime,
            Xinc_Gui_Handler::getInstance()->getStatusDir());*/
         if ($buildTime == 'latest-successful') {
             $build = Xinc_Build_Repository::getLastSuccessfulBuild($project);
             $statusDir = Xinc_Build_History::getLastSuccessfulBuildDir($project);
         } else {
             if ($buildTime == 'latest') {
                 $build = Xinc_Build_Repository::getLastBuild($project);
                 $statusDir = Xinc_Build_History::getLastBuildDir($project);
             } else {
                 $build = Xinc_Build_Repository::getBuild($project, $buildTime);
                 $statusDir = Xinc_Build_History::getBuildDir($project, $buildTime);
             }
         }
         $statusDir .= DIRECTORY_SEPARATOR . Xinc_Plugin_Repos_Deliverable::DELIVERABLE_DIR . DIRECTORY_SEPARATOR;
         /**
          * Replace multiple / slashes with just one
          */
         $fileName = $statusDir . $file;
         $fileName = preg_replace('/\\' . DIRECTORY_SEPARATOR . '+/', DIRECTORY_SEPARATOR, $fileName);
         $realfile = realpath($fileName);
         if ($realfile != $fileName) {
             // check if we have an alias name
             $deliverables = $build->getInternalProperties()->get('deliverables');
             if (is_array($deliverables)) {
                 $aliasTest = basename($file);
                 if (isset($deliverables['aliases']) && isset($deliverables['aliases'][$aliasTest])) {
                     $aliasFile = $deliverables['deliverables'][$deliverables['aliases'][$aliasTest]];
                     if (file_exists($aliasFile) && is_file($aliasFile)) {
                         return $this->_outputDeliverable($aliasFile);
                     }
                 }
             }
             echo "Could not find artifact";
             die;
         } else {
             if (file_exists($fileName) && is_file($realfile)) {
                 return $this->_outputDeliverable($fileName);
             } else {
                 echo "Could not find deliverable";
                 die;
             }
         }
     } catch (Exception $e) {
         echo "Could not find any deliverable";
         die;
     }
 }
 /**
  * Load the requested artifacts file and output it to the browser
  *
  * @param array $params
  */
 private function _getArtifactFile($params)
 {
     /**$projectName = $params['p'];
        $buildTime = $params['buildtime'];
        $file = $params['file'];*/
     $query = urldecode($_SERVER['REQUEST_URI']);
     preg_match("/\\/(.*?)\\/(.*?)\\/(.*?)\\/(.*?)\\/(.*?)\\/(.*?)\\/([\\w\\-\\.\\/]+[^#?]+)/", $query, $matches);
     if (count($matches) != 8) {
         echo "Could not find artifact";
         die;
     }
     $projectName = $matches[5];
     $buildTime = $matches[6];
     // if buildtime==latest, get latest build
     // latest
     // Xinc_Build_History::get()
     $file = $matches[7];
     $file = str_replace('/', DIRECTORY_SEPARATOR, $file);
     $project = new Xinc_Project();
     $project->setName($projectName);
     try {
         /**$build = Xinc_Build::unserialize($project,
            $buildTime,
            Xinc_Gui_Handler::getInstance()->getStatusDir());*/
         if ($buildTime == 'latest-successful') {
             $build = Xinc_Build_Repository::getLastSuccessfulBuild($project);
             $statusDir = Xinc_Build_History::getLastSuccessfulBuildDir($project);
         } else {
             if ($buildTime == 'latest') {
                 $build = Xinc_Build_Repository::getLastBuild($project);
                 $statusDir = Xinc_Build_History::getLastBuildDir($project);
             } else {
                 $build = Xinc_Build_Repository::getBuild($project, $buildTime);
                 $statusDir = Xinc_Build_History::getBuildDir($project, $buildTime);
             }
         }
         $statusDir .= DIRECTORY_SEPARATOR . Xinc_Plugin_Repos_Artifacts::ARTIFACTS_DIR . DIRECTORY_SEPARATOR;
         /**
          * Replace multiple / slashes with just one
          */
         $fileName = $statusDir . $file;
         $fileName = preg_replace('/\\' . DIRECTORY_SEPARATOR . '+/', DIRECTORY_SEPARATOR, $fileName);
         $realfile = realpath($fileName);
         if ($realfile != $fileName) {
             echo "Could not find artifact";
             die;
         } else {
             if (file_exists($fileName) && is_file($realfile)) {
                 //echo "here";
                 $contentType = $this->mime_content_type2($fileName);
                 if (!empty($contentType)) {
                     header("Content-Type: " . $contentType);
                 }
                 readfile($fileName);
                 die;
             } else {
                 echo "Could not find artifact";
                 die;
             }
         }
     } catch (Exception $e) {
         echo "Could not find any artifacts";
         die;
     }
 }