private function makeEntityNames($dirnames, PhingFile $rootDir) { if (empty($dirnames)) { return; } foreach ($dirnames as $dirname) { $this->output .= "<!-- dir: {$dirname} -->\n"; $ds = new DirectoryScanner(); $ds->setIncludes(array("**/*.xml")); $futil = new FileUtils(); $baseDir = $futil->resolveFile($rootDir, $dirname); $ds->setBasedir($baseDir->getPath()); $ds->scan(); $xmlFiles = $ds->getIncludedFiles(); $allEntities = ''; foreach ($xmlFiles as $xmlFilename) { $xmlFile = $futil->resolveFile($baseDir, $xmlFilename); $entityName = $this->fileToEntity($xmlFile, $rootDir); $this->output .= "<!-- {$dirname}/{$xmlFilename}-->\n"; $this->output .= "<!ENTITY {$entityName} SYSTEM \"{$dirname}/{$xmlFilename}\">\n"; $allEntities .= "&{$entityName};"; } $this->output .= "<!-- {$dirname} -->\n"; $this->output .= "<!ENTITY {$dirname}.all \"{$allEntities}\">\n"; } }
/** * Execute phing file. * * @return void */ private function processFile() { $buildFailed = false; $savedDir = $this->dir; $savedPhingFile = $this->phingFile; $savedTarget = $this->newTarget; $savedBasedirAbsPath = null; // this is used to save the basedir *if* we change it try { if ($this->newProject === null) { $this->reinit(); } $this->initializeProject(); if ($this->dir !== null) { $dirAbsPath = $this->dir->getAbsolutePath(); // BE CAREFUL! -- when the basedir is changed for a project, // all calls to getAbsolutePath() on a relative-path dir will // be made relative to the project's basedir! This means // that subsequent calls to $this->dir->getAbsolutePath() will be WRONG! // We need to save the current project's basedir first. $savedBasedirAbsPath = $this->getProject()->getBasedir()->getAbsolutePath(); $this->newProject->setBasedir($this->dir); // Now we must reset $this->dir so that it continues to resolve to the same // path. $this->dir = new PhingFile($dirAbsPath); if ($savedDir !== null) { // has been set explicitly $this->newProject->setInheritedProperty("project.basedir", $this->dir->getAbsolutePath()); } } else { // Since we're not changing the basedir here (for file resolution), // we don't need to worry about any side-effects in this scanrio. $this->dir = $this->getProject()->getBasedir(); } $this->overrideProperties(); if ($this->phingFile === null) { $this->phingFile = "build.xml"; } $fu = new FileUtils(); $file = $fu->resolveFile($this->dir, $this->phingFile); $this->phingFile = $file->getAbsolutePath(); $this->log("Calling Buildfile '" . $this->phingFile . "' with target '" . $this->newTarget . "'"); $this->newProject->setUserProperty("phing.file", $this->phingFile); ProjectConfigurator::configureProject($this->newProject, new PhingFile($this->phingFile)); if ($this->newTarget === null) { $this->newTarget = $this->newProject->getDefaultTarget(); } // Are we trying to call the target in which we are defined? if ($this->newProject->getBaseDir() == $this->project->getBaseDir() && $this->newProject->getProperty("phing.file") == $this->project->getProperty("phing.file") && $this->getOwningTarget() !== null && $this->newTarget == $this->getOwningTarget()->getName()) { throw new BuildException("phing task calling its own parent target"); } $this->addReferences(); $this->newProject->executeTarget($this->newTarget); } catch (Exception $e) { $buildFailed = true; $this->log($e->getMessage(), Project::MSG_ERR); if (Phing::getMsgOutputLevel() <= Project::MSG_DEBUG) { $lines = explode("\n", $e->getTraceAsString()); foreach ($lines as $line) { $this->log($line, Project::MSG_DEBUG); } } // important!!! continue on to perform cleanup tasks. } // reset environment values to prevent side-effects. $this->newProject = null; $pkeys = array_keys($this->properties); foreach ($pkeys as $k) { $this->properties[$k]->setProject(null); } $this->dir = $savedDir; $this->phingFile = $savedPhingFile; $this->newTarget = $savedTarget; // If the basedir for any project was changed, we need to set that back here. if ($savedBasedirAbsPath !== null) { chdir($savedBasedirAbsPath); } if ($this->haltOnFailure && $buildFailed) { throw new BuildException("Execution of the target buildfile failed. Aborting."); } }
/** * The heart of the matter. This is where the selector gets to decide * on the inclusion of a file in a particular fileset. * * @param PhingFile $basedir the base directory the scan is being done from * @param string $filename is the name of the file to check * @param PhingFile $file is a java.io.File object the selector can use * * @return bool whether the file should be selected or not * * @throws BuildException */ public function isSelected(PhingFile $basedir, $filename, PhingFile $file) { // throw BuildException on error $this->validate(); // Determine file whose out-of-dateness is to be checked $destfiles = $this->map->main($filename); // If filename does not match the To attribute of the mapper // then filter it out of the files we are considering if (empty($destfiles)) { return false; } // Sanity check if (count($destfiles) !== 1 || $destfiles[0] === null) { throw new BuildException('Invalid destination file results for ' . $this->targetdir->getName() . ' with filename ' . $filename); } $destname = $destfiles[0]; $fu = new FileUtils(); $destfile = $fu->resolveFile($this->targetdir, $destname); return $this->selectionTest($file, $destfile); }