Load buildfile location

@param string $buildfile

@return $this
@throws \Jawira\PhingVisualizer\DiagramException
962848
protected function setBuildfile(string $buildfile): self
    {
        // Buildfile must exist
        if (!is_file($buildfile)) {
            throw new DiagramException(sprintf('File "%s" is invalid.', $buildfile));
        }

        $this->buildfile = $buildfile;

        return $this;
    }
14077
public function setOnDiskConfiguration(?string $configFile = null): ConfigurationBuilder
    {
        $this->configFile = $configFile;

        if ($this->configFile) {
            if (file_exists($path = getcwd() . '/' . $this->configFile)) {
                $this->configFile = $path;
            }

            if (!file_exists($this->configFile)) {
                throw new \InvalidArgumentException('The specified config file is not a valid file.');
            }

            $info = pathinfo($this->configFile);

            $fileExt = strtolower($info['extension']);

            switch ($fileExt) {
                case 'xml':
                    $diskConfig = $this->loadXmlFile($this->configFile);
                    break;

                case 'yml':
                case 'yaml':
                    $diskConfig = Yaml::parse(file_get_contents($this->configFile));
                    break;

                default:
                    throw new \InvalidArgumentException(
                        sprintf(
                            'The specified config file should end in .xml or .yml/.yaml. Unrecognized extension [%s]',
                            $fileExt
                        )
                    );
            }

            $this->configParams = array_merge($this->configParams, $diskConfig);
        }

        return $this;
    }
725850
protected function _simulateInstall($updateFile)
    {
        $this->log->addNotice('[SIMULATE] Install new version');
        clearstatcache();

        // Check if zip file could be opened
        $zip = zip_open($updateFile);
        if (!is_resource($zip)) {
            $this->log->addError(sprintf('Could not open zip file "%s", error: %d', $updateFile, $zip));

            return false;
        }

        $i = -1;
        $files = [];
        $simulateSuccess = true;

        while ($file = zip_read($zip)) {
            $i++;

            $filename = zip_entry_name($file);
            $foldername = $this->installDir . dirname($filename);
            $absoluteFilename = $this->installDir . $filename;

            $files[$i] = [
                'filename' => $filename,
                'foldername' => $foldername,
                'absolute_filename' => $absoluteFilename,
            ];

            $this->log->addDebug(sprintf('[SIMULATE] Updating file "%s"', $filename));

            // Check if parent directory is writable
            if (!is_dir($foldername)) {
                mkdir($foldername);
                $this->log->addDebug(sprintf('[SIMULATE] Create directory "%s"', $foldername));
                $files[$i]['parent_folder_exists'] = false;

                $parent = dirname($foldername);
                if (!is_writable($parent)) {
                    $files[$i]['parent_folder_writable'] = false;

                    $simulateSuccess = false;
                    $this->log->addWarning(sprintf('[SIMULATE] Directory "%s" has to be writeable!', $parent));
                } else {
                    $files[$i]['parent_folder_writable'] = true;
                }
            }

            // Skip if entry is a directory
            if (substr($filename, -1, 1) == DIRECTORY_SEPARATOR) {
                continue;
            }

            // Read file contents from archive
            $contents = zip_entry_read($file, zip_entry_filesize($file));
            if ($contents === false) {
                $files[$i]['extractable'] = false;

                $simulateSuccess = false;
                $this->log->addWarning(sprintf('[SIMULATE] Coud not read contents of file "%s" from zip file!', $filename));
            }

            // Write to file
            if (file_exists($absoluteFilename)) {
                $files[$i]['file_exists'] = true;
                if (!is_writable($absoluteFilename)) {
                    $files[$i]['file_writable'] = false;

                    $simulateSuccess = false;
                    $this->log->addWarning(sprintf('[SIMULATE] Could not overwrite "%s"!', $absoluteFilename));
                }
            } else {
                $files[$i]['file_exists'] = false;

                if (is_dir($foldername)) {
                    if (!is_writable($foldername)) {
                        $files[$i]['file_writable'] = false;

                        $simulateSuccess = false;
                        $this->log->addWarning(sprintf('[SIMULATE] The file "%s" could not be created!', $absoluteFilename));
                    } else {
                        $files[$i]['file_writable'] = true;
                    }
                } else {
                    $files[$i]['file_writable'] = true;

                    $this->log->addDebug(sprintf('[SIMULATE] The file "%s" could be created', $absoluteFilename));
                }
            }

            if ($filename == $this->updateScriptName) {
                $this->log->addDebug(sprintf('[SIMULATE] Update script "%s" found', $absoluteFilename));
                $files[$i]['update_script'] = true;
            } else {
                $files[$i]['update_script'] = false;
            }
        }

        $this->simulationResults = $files;

        return $simulateSuccess;
    }
766779
public function addBuildToQueue(Build $build)
    {
        $buildId = $build->getId();

        if (empty($buildId)) {
            return;
        }

        $config = Config::getInstance();
        $settings = $config->get('phpci.worker', []);

        if (!empty($settings['host']) && !empty($settings['queue'])) {
            try {
                $jobData = array(
                    'type' => 'phpci.build',
                    'build_id' => $build->getId(),
                );

                if ($config->get('using_custom_file')) {
                    $jobData['config'] = $config->getArray();
                }

                $pheanstalk = new Pheanstalk($settings['host']);
                $pheanstalk->useTube($settings['queue']);
                $pheanstalk->put(
                    json_encode($jobData),
                    PheanstalkInterface::DEFAULT_PRIORITY,
                    PheanstalkInterface::DEFAULT_DELAY,
                    $config->get('phpci.worker.job_timeout', 600)
                );
            } catch (\Exception $ex) {
                $this->queueError = true;
            }
        }
    }
86423
public function load($file)
    {
        if (file_exists($file)) {
            $this->feed = ZendReader::importFile($file);
        } else {
            $this->feed = ZendReader::import($file);
        }

        return $this;
    }
848511
public function main()
    {
        if ($this->tarFile === null) {
            throw new BuildException("tarfile attribute must be set!", $this->getLocation());
        }

        if ($this->tarFile->exists() && $this->tarFile->isDirectory()) {
            throw new BuildException("tarfile is a directory!", $this->getLocation());
        }

        if ($this->tarFile->exists() && !$this->tarFile->canWrite()) {
            throw new BuildException("Can not write to the specified tarfile!", $this->getLocation());
        }

        // shouldn't need to clone, since the entries in filesets
        // themselves won't be modified -- only elements will be added
        $savedFileSets = $this->filesets;

        try {
            if ($this->baseDir !== null) {
                if (!$this->baseDir->exists()) {
                    throw new BuildException(
                        "basedir '" . (string) $this->baseDir . "' does not exist!",
                        $this->getLocation()
                    );
                }
                if (empty($this->filesets)) { // if there weren't any explicit filesets specivied, then
                    // create a default, all-inclusive fileset using the specified basedir.
                    $mainFileSet = new TarFileSet($this->fileset);
                    $mainFileSet->setDir($this->baseDir);
                    $mainFileSet->setProject($this->project);
                    $this->filesets[] = $mainFileSet;
                }
            }

            if (empty($this->filesets)) {
                throw new BuildException(
                    "You must supply either a basedir "
                    . "attribute or some nested filesets.",
                    $this->getLocation()
                );
            }

            // check if tar is out of date with respect to each fileset
            if ($this->tarFile->exists() && $this->isArchiveUpToDate()) {
                $this->log("Nothing to do: " . $this->tarFile->__toString() . " is up to date.", Project::MSG_INFO);
                return;
            }

            $this->log("Building tar: " . $this->tarFile->__toString(), Project::MSG_INFO);

            $tar = new Archive_Tar($this->tarFile->getAbsolutePath(), $this->compression);
            $pear = new PEAR();

            if ($pear::isError($tar->error_object)) {
                throw new BuildException($tar->error_object->getMessage());
            }

            foreach ($this->filesets as $fs) {
                $files = $fs->getIterator($this->includeEmpty);
                if (count($files) > 1 && strlen($fs->getFullpath()) > 0) {
                    throw new BuildException(
                        "fullpath attribute may only "
                        . "be specified for "
                        . "filesets that specify a "
                        . "single file."
                    );
                }
                $fsBasedir = $fs->getDir($this->project);
                $filesToTar = [];
                for ($i = 0, $fcount = count($files); $i < $fcount; $i++) {
                    $f = new PhingFile($fsBasedir, $files[$i]);
                    $filesToTar[] = $f->getAbsolutePath();
                    $this->log("Adding file " . $f->getPath() . " to archive.", Project::MSG_VERBOSE);
                }
                $tar->addModify($filesToTar, $this->prefix, $fsBasedir->getAbsolutePath());

                if ($pear::isError($tar->error_object)) {
                    throw new BuildException($tar->error_object->getMessage());
                }
            }
        } catch (IOException $ioe) {
            $msg = "Problem creating TAR: " . $ioe->getMessage();
            $this->filesets = $savedFileSets;
            throw new BuildException($msg, $ioe, $this->getLocation());
        }

        $this->filesets = $savedFileSets;
    }
813961
protected function loadXmlFile(string $xmlFile): SimpleXMLElement
    {
        $xmlContent = (new FileReader($xmlFile))->read();
        $xml = simplexml_load_string($xmlContent);

        if (!($xml instanceof SimpleXMLElement)) {
            $message = "Error loading XML file: $xmlFile";
            $this->log($message, Project::MSG_ERR);
            throw new BuildException($message);
        }

        return $xml;
    }
964229
private function open($pathToFile)
    {
        $this->pathToFile = $pathToFile;
        if (!file_exists($this->pathToFile)) {
            throw new ImageException("File " . ($this->pathToFile) . " not found.", ImageException::AccessException);
        }
        $tmpImageSize = getimagesize($this->pathToFile);
        $this->width = (int)$tmpImageSize[0];
        $this->height = (int)$tmpImageSize[1];
        $this->type = (int)$tmpImageSize[2];
        switch ($this->type) {
            case self::GIF:
                $this->resource = imagecreatefromgif($this->pathToFile);
                break;
            case self::JPG:
                $this->resource = imagecreatefromjpeg($this->pathToFile);
                break;
            case self::PNG:
                $this->resource = imagecreatefrompng($this->pathToFile);
                break;
            case self::BMP:
                $this->resource = imagecreatefromwbmp($this->pathToFile);
                break;
            default:
                throw new ImageException("Unknown type of file " . ($this->pathToFile) . ".", ImageException::UnsupportedFormatException);
                break;
        }
    }
86631
public function loadConfiguration($configurationFile)
    {
        if (is_file($configurationFile)) {
            $dom = new DOMDocument('1.0', 'UTF-8');
            $dom->load($configurationFile);

            $this->setDOMDocument($dom);
        } elseif ($configurationFile !== $this->defaultConfigurationFile && is_file($this->defaultConfigurationFile)) {
            $this->loadConfiguration($this->defaultConfigurationFile);
        }
    }
292976
public function compile($outputfile)
    {
        if (empty($this->index)) {
            throw new \LogicException('Cannot compile when no index files are defined.');
        }

        if (file_exists($outputfile)) {
            unlink($outputfile);
        }

        $name = basename($outputfile);
        $phar = new \Phar($outputfile, 0, $name);
        $phar->setSignatureAlgorithm(\Phar::SHA1);
        $phar->startBuffering();

        foreach ($this->files as $virtualfile => $fileinfo) {
            list($realfile, $strip) = $fileinfo;
            $content = file_get_contents($realfile);

            if ($strip) {
                $content = $this->stripWhitespace($content);
            }

            $phar->addFromString($virtualfile, $content);
        }

        foreach ($this->index as $type => $fileinfo) {
            list($virtualfile, $realfile) = $fileinfo;
            $content = file_get_contents($realfile);

            if ($type == 'cli') {
                $content = preg_replace('{^#!/usr/bin/env php\s*}', '', $content);
            }

            $phar->addFromString($virtualfile, $content);
        }

        $stub = $this->generateStub($name);
        $phar->setStub($stub);

        $phar->stopBuffering();
        unset($phar);
    }
979483
private function loadProperties()
    {
        try {
            $properties = new Properties();
            $properties->load($this->file);
        } catch (IOException $ioe) {
            throw new BuildException($ioe);
        }
        return $properties;
    }
726035
protected function executeBuild($method, $build_path)
    {
        $this->say('Build has initialized!');
        $this->executeCommandHook($method, 'before_build');
        $this->projectInstance()->onDeployBuild($build_path);
        $this->executeCommandHook($method, 'after_build');
        $this->say('Build has completed!');

        return $this;
    }
1307018
public function main()
    {
        if ($this->property === null) {
            throw new BuildException("property attribute required", $this->getLocation());
        }

        if ($this->file === null) {
            throw new BuildException("file attribute required", $this->getLocation());
        }

        $this->getProject()->setNewProperty(
            $this->property,
            $this->removeExtension($this->file->getName(), $this->suffix)
        );
    }
65357
protected function getMap()
    {

        if ($this->_prefix != null && $this->_regex != null) {
            throw new BuildException("Please specify either prefix or regex, but not both", $this->getLocation());
        }

        if (empty($this->_targetDir)) {
            throw new BuildException("Please specify the target directory to put the symlinks in.", $this->getLocation());
        }

        // copy the properties file
        $allProps = $this->getProject()->getProperties();

        ksort($allProps);
        $props = new Properties();

        if ($this->_regex !== '') {
            $a        = new ArrayIterator($allProps);
            $i        = new RegexIterator($a, $this->_regex, RegexIterator::MATCH, RegexIterator::USE_KEY);
            $allProps = iterator_to_array($i);
        }

        if ($this->_prefix !== '') {
            $a        = new ArrayIterator($allProps);
            $i        = new RegexIterator(
                $a,
                '~^'.preg_quote($this->_prefix, '~').'.*~',
                RegexIterator::MATCH,
                RegexIterator::USE_KEY
            );
            $allProps = iterator_to_array($i);
        }

        $targets = array();
        foreach ($allProps as $name => $value) {
            $dir = new PhingFile($value);
            if ($dir->isFile()) {
                $filename = basename($value);
                $targets[$this->_originDir][] = array(
                    'target' => $this->_originDir.DIRECTORY_SEPARATOR.$filename,
                    'link'   => $this->_targetDir.DIRECTORY_SEPARATOR.$filename,
                );
            }

            if ($dir->isDirectory()) {
                $subdirectories = preg_grep('~'.preg_quote($value).'~', array_values($allProps));
                if (count($subdirectories) == 1) {
                    $directoryToCreate = str_replace(
                        $this->_originDir,
                        $this->_targetDir,
                        $value
                    );

                    $ds = new DirectoryScanner();
                    $ds->setBasedir($dir);
                    $ds->setIncludes("*");
                    $ds->scan();

                    $dsIncludedDirectories = (array) $ds->getIncludedDirectories();
                    $dsIncludedFiles       = (array) $ds->getIncludedFiles();

                    $fsTargets = array_merge(
                        $dsIncludedDirectories,
                        $dsIncludedFiles
                    );
                    // Add each target to the map
                    foreach ($fsTargets as $target) {
                        if (!empty($target)) {
                            $targets[$directoryToCreate][] = array(
                                'target' => $dir.DIRECTORY_SEPARATOR.$target,
                                'link'   => $directoryToCreate.DIRECTORY_SEPARATOR.$target,
                            );
                        }
                    }
                }//end if
            }//end if
        }//end foreach

        return $targets;

    }
926495
public function main()
    {
        if (empty($this->file)) {
            throw new BuildException("Attribute 'file' required", $this->getLocation());
        }

        if (empty($this->property)) {
            throw new BuildException("Attribute 'property' required", $this->getLocation());
        }
        if ($this->quiet && $this->failOnError) {
            throw new BuildException("quiet and failonerror cannot both be set to true");
        }

        try {
            if (is_string($this->file)) {
                $this->file = new PhingFile($this->file);
            }
            if (!$this->file->exists()) {
                $message = (string) $this->file . ' doesn\'t exist';
                if ($this->failOnError) {
                    throw new BuildException($message);
                } else {
                    $this->log($message, $this->quiet ? Project::MSG_WARN : Project::MSG_ERR);
                    return;
                }
            }

            $this->log("loading " . (string) $this->file . " into property " . $this->property, Project::MSG_VERBOSE);
            // read file (through filterchains)
            $contents = "";

            if ($this->file->length() > 0) {
                $reader = FileUtils::getChainedReader(new FileReader($this->file), $this->filterChains, $this->project);
                while (-1 !== ($buffer = $reader->read())) {
                    $contents .= $buffer;
                }
                $reader->close();
            } else {
                $this->log(
                    "Do not set property " . $this->property . " as its length is 0.",
                    $this->quiet ? Project::MSG_VERBOSE : Project::MSG_INFO
                );
            }

            // publish as property
            if ($contents !== '') {
                $this->project->setNewProperty($this->property, $contents);
                $this->log("loaded " . strlen($contents) . " characters", Project::MSG_VERBOSE);
                $this->log($this->property . " := " . $contents, Project::MSG_DEBUG);
            }
        } catch (IOException $ioe) {
            $message = "Unable to load resource: " . $ioe->getMessage();
            if ($this->failOnError) {
                throw new BuildException($message, $ioe, $this->getLocation());
            } else {
                $this->log($message, $this->quiet ? Project::MSG_VERBOSE : Project::MSG_ERR);
            }
        } catch (BuildException $be) {
            if ($this->failOnError) {
                throw $be;
            } else {
                $this->log($be->getMessage(), $this->quiet ? Project::MSG_VERBOSE : Project::MSG_ERR);
            }
        }
    }
296326
public function open($pdfFile)
    {
        $real_path = H::parseFileRealPath($pdfFile);

        if (is_file($real_path)) {
            $this->source_pdf = $real_path;

            if (!Config::isKeySet(C::OUTPUT_DIR)) {
                Config::setOutputDirectory(dirname($pdfFile));
            }

            return $this;
        }
        throw new PopplerPhpException("File not found: ".$real_path);
    }
1277569
protected function loadFile(PhingFile $file)
    {
        $this->log("Loading " . $file->getAbsolutePath(), Project::MSG_INFO);
        try { // try to load file
            if ($file->exists()) {
                $parser = new XmlFileParser();
                $parser->setCollapseAttr($this->_collapseAttr);
                $parser->setKeepRoot($this->_keepRoot);
                $parser->setDelimiter($this->_delimiter);

                $properties = $parser->parseFile($file);

                return new Properties($properties);
            } else {
                if ($this->getRequired()) {
                    throw new BuildException("Could not load required properties file.");
                } else {
                    $this->log(
                        "Unable to find property file: " . $file->getAbsolutePath() . "... skipped",
                        Project::MSG_WARN
                    );
                }
            }
        } catch (IOException $ioe) {
            throw new BuildException("Could not load properties from file.", $ioe);
        }
    }