public function scan()
    {
        if (empty($this->basedir)) {
            return false;
        } else {
            $exception = null;

            if (!@file_exists($this->basedir)) {
                if ($this->errorOnMissingDir) {
                    $exception = new BuildException(
                        "basedir  $this->basedir does not exist."
                    );
                } else {
                    return false;
                }
            } elseif (!@is_dir($this->basedir)) {
                $exception = new BuildException(
                    "basedir $this->basedir is not a directory."
                );
            }
            if ($exception !== null) {
                throw $exception;
            }
        }

        if ($this->includes === null) {
            // No includes supplied, so set it to 'matches all'
            $this->includes = ["**"];
        }
        if (null === $this->excludes) {
            $this->excludes = [];
        }

        $this->filesIncluded = [];
        $this->filesNotIncluded = [];
        $this->filesExcluded = [];
        $this->dirsIncluded = [];
        $this->dirsNotIncluded = [];
        $this->dirsExcluded = [];
        $this->dirsDeselected = [];
        $this->filesDeselected = [];

        if ($this->isIncluded("")) {
            if (!$this->isExcluded("")) {
                if ($this->isSelected("", $this->basedir)) {
                    $this->dirsIncluded[] = "";
                } else {
                    $this->dirsDeselected[] = "";
                }
            } else {
                $this->dirsExcluded[] = "";
            }
        } else {
            $this->dirsNotIncluded[] = "";
        }

        $this->scandir($this->basedir, "", true);

        return true;
    }