Compiles the config files

@throws Exception
515168
public function compileConfigSource()
    {
        // compile template
        if (!is_object($this->compiler_object)) {
            // load compiler
            $this->compiler_object = new Smarty_Internal_Config_File_Compiler($this->smarty);
        }
        // compile locking
        if ($this->smarty->compile_locking) {
            if ($saved_timestamp = $this->getCompiledTimestamp()) {
                touch($this->getCompiledFilepath());
            }
        }
        // call compiler
        try {
            $this->compiler_object->compileSource($this);
        } catch (Exception $e) {
            // restore old timestamp in case of error
            if ($this->smarty->compile_locking && $saved_timestamp) {
                touch($this->getCompiledFilepath(), $saved_timestamp);
            }
            throw $e;
        }
        // compiling succeded
        // write compiled template
        Smarty_Internal_Write_File::writeFile($this->getCompiledFilepath(), $this->getCompiledConfig(), $this->smarty);
    }
381302
protected function validateConf()
    {
        foreach ($this->getRequiredConfParams() as $name => $type) {
            if (!isset($this->params[$name]) || gettype($this->params[$name]) !== $type) {
                throw new Exception("Parameter '{$name}' missing or not of type '{$type}' (adapter '{$this->name}')");
            }
            if (substr($name, -5) == '_path') {
                $path = $this->getConfParam($name);
                if (!is_file($path)) {
                    throw new Exception("File not found: $path");
                }
            }
        }
    }
581239
protected function initConfig(): void
    {
        $configFile = $this->getRootRelatedPath($this->getConfigFileName());

        $this->assertFileIsReadable($configFile);

        self::$config = (array)(include $configFile);
    }
483548
public function compile() {
		$this->start('Compiling to '. $this->host);

		// fix path
		$this->localProj	= self::path($this->localProj);
		$this->remoteProj	= rtrim($this->remoteProj, DIRECTORY_SEPARATOR);
		
		// Work from project
		if(isset($this->localProj) && is_dir($this->localProj))
			chdir($this->localProj);
		
		// documentation
		if(isset($this->localDoc))
			$this->start('Creating Documentation from ' . $this->localDoc)->makeDoc()->finish();
		
		// twig templates
		if(isset($this->localTpl))
			$this->start('Creating JS Templates from ' . $this->localTpl)->makeTpl()->finish();
		
		
		// static files
		$localStatic = self::path(sys_get_temp_dir()) . 'data' . time() . DIRECTORY_SEPARATOR;
		$this->wipe[] = $localStatic;
		
		foreach($this->remoteStatic as $type => $trash) {
			if(method_exists($this, $type)) {
				$this->tmp[ $type ] = $localStatic . $type . DIRECTORY_SEPARATOR;
				self::readyDir( $this->tmp[ $type ] );

				// process static files
				$this->start('Processing '. $type)->$type()->finish();
				
			} elseif(!empty($this->localStatic[ $type ])) {
					// just moved the folder
					$this->tmp[ $type ] = self::path(current ($this->localStatic[ $type ]));
					
					// remove if not there
					if(!file_exists($this->tmp[ $type ])) 
						unset ($this->remoteStatic[ $type ]);
			}
		}

		// run through static files then upload them
		$this->start('Uploading Static')->uploadStatic()->finish();

		// upload project
		$cmd = [
			'pscp',
			'-p',									// preserve attributes
			'-r',									// copy recursively
			'-q',									// silent
			//'-sftp',								// for use of SFTP protocal
			'-batch',								// non interactive
			'-C',									// enable compression
			'-i', static::safeDir($this->ppk),						// Private key file to access server
		];
		
		// Directory to upload
		foreach($this->localCopy as $name)
			$cmd[] = static::safeDir($this->localProj . $name);
		
		// host:path on server to save data
		$cmd[] = $this->host .':'. $this->remoteProj;
		
		$this->start('Uploading Project')->runLocal($cmd)->finish();

		// config
		if(!isset($this->s3) && !empty($this->remoteStatic)) {
			// reset file permissions
			$cmd = array();
			foreach($this->remoteStatic as $type => $path) {
				$cmd[] = 'chmod 774 -R '. $path;
				// $cmd[] = 'chown mo:www-data -R '. $path;
			}
			
			$this->start('Updating Server Enviroment')->runRemote( $cmd )->finish();
		}

		// clean up
		$this	->start('Cleaning up');
			foreach($this->wipe as $dir)
				self::wipeDir($dir, true);
		$this	->finish();
		
		// finally
		$this->finish();
	}
790096
private function config()
    {
        if (realpath($this->configPath) !== false) {
            $json = file_get_contents($this->configPath);
            $this->config = json_decode($json);
            $this->config->rootDir = $this->rootDir;
        } else {
            throw new \RuntimeException('Framework not initialized yet. Consider running composer install');
        }
    }
431922
public void compile(ModuleConfiguration configuration) {
        LOGGER.debug("Compiling module {}", configuration);
        FileReaderFactory fileReaderFactory = injector.getInstance(FileReaderFactory.class);
        Importer importer = injector.getInstance(Importer.class);
        CompilerRegistry registry = injector.getInstance(CompilerRegistry.class);
        ProtoCompiler compiler = registry.findCompiler(configuration.getGenerator());
        if (compiler == null) {
            throw new GeneratorException("Unknown template: %s | %s", configuration.getGenerator(), registry.availableCompilers());
        }
        FileReader fileReader = fileReaderFactory.create(configuration.getIncludePaths());
        Map<String, Proto> importedFiles = new HashMap<>();
        for (String path : configuration.getProtoFiles()) {
            LOGGER.info("Parse {}", path);
            ProtoContext context = importer.importFile(fileReader, path);
            Proto proto = context.getProto();
            importedFiles.put(path, proto);
        }
        ImmutableModule.Builder builder = ImmutableModule.builder();
        builder.name(configuration.getName());
        builder.output(configuration.getOutput());
        builder.options(configuration.getOptions());
        for (Proto proto : importedFiles.values()) {
            builder.addProtos(proto);
        }
        UsageIndex index = UsageIndex.build(importedFiles.values());
        builder.usageIndex(index);
        ImmutableModule module = builder.build();
        for (Proto proto : importedFiles.values()) {
            proto.setModule(module);
        }
        compiler.compile(module);
    }
1278093
protected void configureClassPath() throws Exception
    {
        //call each of the instances
        // first, configure the classpaths
        for (int i=0; i<_configurations.length;i++)
        {
            _configurations[i].setWebApplicationContext(this);
            _configurations[i].configureClassPath();
        }
    }
220552
protected function compile()
    {
        foreach ($this->patternCollection as $pattern) {
            $this->content = $pattern->setContent($this->content)
                ->render();
        }
    }
741686
protected function compile()
	{
		$buttons = new Helper\Buttons();
		$buttons->loadFromFieldset($this->buttons);
		$buttons->buttonStyle = $this->buttonStyle;

		$this->Template->buttons = $buttons;
	}
322540
public function main()
    {
        if ($this->file === null && empty($this->filesets)) {
            throw new BuildException("You must specify a file or fileset(s) for the <ReplaceRegexp> task.");
        }

        // compile a list of all files to modify, both file attrib and fileset elements
        // can be used.
        $files = [];

        if ($this->file !== null) {
            $files[] = $this->file;
        }

        if (!empty($this->filesets)) {
            $filenames = [];
            foreach ($this->filesets as $fs) {
                try {
                    $ds = $fs->getDirectoryScanner($this->project);
                    $filenames = $ds->getIncludedFiles(); // get included filenames
                    $dir = $fs->getDir($this->project);
                    foreach ($filenames as $fname) {
                        $files[] = new PhingFile($dir, $fname);
                    }
                } catch (BuildException $be) {
                    $this->log($be->getMessage(), Project::MSG_WARN);
                }
            }
        }

        $this->log("Applying Regexp processing to " . count($files) . " files.");

        // These "slots" allow filters to retrieve information about the currently-being-process files
        $slot = $this->getRegisterSlot("currentFile");
        $basenameSlot = $this->getRegisterSlot("currentFile.basename");

        $filter = new FilterChain($this->project);

        $r = new ReplaceRegexp();
        $r->setRegexps([$this->_regexp]);

        $filter->addReplaceRegexp($r);
        $filters = [$filter];

        foreach ($files as $file) {
            // set the register slots

            $slot->setValue($file->getPath());
            $basenameSlot->setValue($file->getName());

            // 1) read contents of file, pulling through any filters
            $in = null;
            try {
                $contents = "";
                $in = FileUtils::getChainedReader(new FileReader($file), $filters, $this->project);
                while (-1 !== ($buffer = $in->read())) {
                    $contents .= $buffer;
                }
                $in->close();
            } catch (Exception $e) {
                if ($in) {
                    $in->close();
                }
                $this->log("Error reading file: " . $e->getMessage(), Project::MSG_WARN);
            }

            try {
                // now create a FileWriter w/ the same file, and write to the file
                $out = new FileWriter($file);
                $out->write($contents);
                $out->close();
                $this->log("Applying regexp processing to " . $file->getPath(), Project::MSG_VERBOSE);
            } catch (Exception $e) {
                if ($out) {
                    $out->close();
                }
                $this->log("Error writing file back: " . $e->getMessage(), Project::MSG_WARN);
            }
        }
    }
796362
public function load() {
		if( !$this->path ) {
			throw new \Exception('Unable to load AppConfig from undefined path');
		}
		$this->data	= json_decode(file_get_contents($this->path), true);
	}
829810
public function getConfig()
    {
        if ($this->cache instanceof Cache\CacheInterface && !empty($configs = $this->cache->getConfig())) {
            return $configs;
        }

        $configs = $this->moduleHandler->getModulesConfig();
        foreach ($this->files as $file) {
            $config = require $file;
            if (!is_array($config)) {
                throw new Exception\RuntimeException(sprintf('The config in "%s" file must be array data type', $file));
            }
            $configs = ArrayUtils::merge($configs, require $file);
        }

        return $this->cleanUp($configs);
    }
1004623
public function actionCompile()
    {
        
        $extensionsToCreate = explode(',', $this->options['extension']);
        $extensionsToCreate = array_unique($extensionsToCreate);
        
		foreach ($extensionsToCreate as $extension){
			$language = $this->options['language'];
			$compiledTranslationFile = new tao_helpers_translation_TranslationFile();
			$compiledTranslationFile->setTargetLanguage($this->options['language']);
			
			$this->outVerbose("Compiling language '${language}' for extension '${extension}'...");
			
			// Get the dependencies of the target extension.
			// @todo Deal with dependencies at compilation time.
			$dependencies = array();
			if ($extension !== 'tao'){
				$dependencies[] = 'tao';
			}
			
			$this->outVerbose("Resolving Dependencies...");
			foreach ($dependencies as $depExtId){
				$this->outVerbose("Adding messages from extension '${depExtId}' in '${language}'...");
				// Does the locale exist for $depExtId?
				$depPath = $this->buildLanguagePath($depExtId, $language) . '/' . self::DEF_PO_FILENAME;
				if (!file_exists($depPath) || !is_readable($depPath)){
					$this->outVerbose("Dependency on extension '${depExtId}' in '${language}' does not exist. Trying to resolve default language...");
					$depPath = $this->buildLanguagePath($depExtId, tao_helpers_translation_Utils::getDefaultLanguage() . '/' . self::DEF_PO_FILENAME);

					if (!file_exists($depPath) || !is_readable($depPath)){
						$this->outVerbose("Dependency on extension '${depExtId}' in '${language}' does not exist.");
						continue;
					}
				}
				
				// Recompile the dependent extension (for the moment 'tao' meta-extension only).
				$oldVerbose = $this->options['verbose'];
				$this->parameters['verbose'] = false;
				$this->options['extension'] = $depExtId;
				$this->actionCompile();
				$this->options['extension'] = $extension;
				$this->parameters['verbose'] = $oldVerbose;
				
				$poFileReader = new tao_helpers_translation_POFileReader($depPath);
				$poFileReader->read();
				$poFile = $poFileReader->getTranslationFile();
				$poCount = $poFile->count();
				$compiledTranslationFile->addTranslationUnits($poFile->getTranslationUnits());
				
				$this->outVerbose("${poCount} messages added.");
			}

			if (($extDirectories = scandir(ROOT_PATH)) !== false){
						
				// Get all public messages accross extensions.
				foreach ($extDirectories as $extDir){
					$extPath = ROOT_PATH . '/' . $extDir;
					
					if (is_dir($extPath) && is_readable($extPath) && $extDir[0] != '.' && !in_array($extDir, $dependencies) && $extDir != $extension && $extDir != 'generis'){
						$this->outVerbose("Adding public messages from extension '${extDir}' in '${language}'...");
						
						$poPath = $this->buildLanguagePath($extDir, $language) . '/' . self::DEF_PO_FILENAME;
						if (!file_exists($poPath) || !is_readable($poPath)){
							$this->outVerbose("Extension '${extDir}' is not translated in language '${language}'. Trying to retrieve default language...");
							$poPath = $this->buildLanguagePath($extDir, tao_helpers_translation_Utils::getDefaultLanguage()) . '/' . self::DEF_PO_FILENAME;
							
							if (!file_exists($poPath) || !is_readable($poPath)){
								$this->outVerbose("Extension '${extDir}' in '${language}' does not exist.");
								continue;
							}
						}

						$poFileReader = new tao_helpers_translation_POFileReader($poPath);
						$poFileReader->read();
						$poFile = $poFileReader->getTranslationFile();
						$poUnits = $poFile->getByFlag('tao-public');
						$poCount = count($poUnits);
						$compiledTranslationFile->addTranslationUnits($poUnits);
						$this->outVerbose("${poCount} public messages added.");
					}
				}                
				
				// Finally, add the translation units related to the target extension.
				$path = $this->buildLanguagePath($extension, $language) . '/' . self::DEF_PO_FILENAME;
				if (file_exists($path) && is_readable($path)){
					$poFileReader = new tao_helpers_translation_POFileReader($path);
					$poFileReader->read();
					$poFile = $poFileReader->getTranslationFile();
					$compiledTranslationFile->addTranslationUnits($poFile->getTranslationUnits());
					
					// Sort the TranslationUnits.
					$sortingMethod = tao_helpers_translation_TranslationFile::SORT_ASC_I;
					$compiledTranslationFile->setTranslationUnits($compiledTranslationFile->sortBySource($sortingMethod));
					
					$jsPath = $this->buildLanguagePath($extension, $language) . '/' . self::DEF_JS_FILENAME;
					$jsFileWriter = new tao_helpers_translation_JSFileWriter($jsPath, $compiledTranslationFile);
					$jsFileWriter->write();
					$this->outVerbose("JavaScript compiled translations for extension '${extension}' with '${language}' written.");
				}
				else{
					$this->err("PO file '${path}' for extension '${extension}' with language '${language}' cannot be read.", true);
				}
			}
			else{
				$this->err("Cannot list TAO Extensions from root path. Check your system rights.", true);    
			}

			$this->outVerbose("Translations for '${extension}' with language '${language}' gracefully compiled.");

		}
        
    }
1146081
public function getCompiledConfig()
    {
        if ($this->compiled_config === null) {
            // see if template needs compiling.
            if ($this->mustCompile()) {
                $this->compileConfigSource();
            } else {
                $this->compiled_config = file_get_contents($this->getCompiledFilepath());
            }
        }

        return $this->compiled_config;
    }
310708
protected function initConfig()
    {
        if (!($this->config instanceof Repository)) {
            $filePath   = $this->configPath();
            if (!is_file($filePath)) {
                throw new Exception("Application config file can not found({$filePath}).");
            }

            $this->setConfig(new Repository(require $filePath));
            date_default_timezone_set($this->config['timezone']);
        }
    }
335060
public void compileAndRun() throws Exception {
		synchronized (this.monitor) {
			try {
				stop();
				Class<?>[] compiledSources = compile();
				monitorForChanges();
				// Run in new thread to ensure that the context classloader is setup
				this.runThread = new RunThread(compiledSources);
				this.runThread.start();
				this.runThread.join();
			}
			catch (Exception ex) {
				if (this.fileWatchThread == null) {
					throw ex;
				}
				else {
					ex.printStackTrace();
				}
			}
		}
	}
827157
public function compile($input_file, $output_file = false)
    {
        if (is_null($input_file) || empty($input_file)) {
            throw new Exception('No input file', 1);
        }

        $command = __DIR__.$this->executable;
        $command .= ' compile ';
        $command .= $input_file;

        if ($output_file !== false) {
            $command .= ' -o '.$output_file;
        }
        
        $this->the_command = escapeshellcmd($command);

        return $this;
    }