/**
  * If a JSON file is found in the extensions directory the previous version
  * of the extension is build to compare it with the new configuration coming
  * from the extension builder input
  *
  * @param Tx_ExtensionBuilder_Domain_Model_Extension $extension
  */
 public function initialize(Tx_ExtensionBuilder_Domain_Model_Extension $extension)
 {
     $this->extension = $extension;
     $this->extensionDirectory = $this->extension->getExtensionDir();
     $this->extClassPrefix = 'Tx_' . t3lib_div::underscoredToUpperCamelCase($this->extension->getExtensionKey());
     if (!$this->classParser instanceof Tx_ExtensionBuilder_Utility_ClassParser) {
         $this->injectClassParser(t3lib_div::makeInstance('Tx_ExtensionBuilder_Utility_ClassParser'));
     }
     $this->settings = $this->configurationManager->getExtensionBuilderSettings();
     // defaults
     $this->previousExtensionDirectory = $this->extensionDirectory;
     $this->previousExtensionKey = $this->extension->getExtensionKey();
     if ($extension->isRenamed()) {
         $this->previousExtensionDirectory = $extension->getPreviousExtensionDirectory();
         $this->previousExtensionKey = $extension->getOriginalExtensionKey();
         $this->extensionRenamed = TRUE;
         t3lib_div::devlog('Extension renamed: ' . $this->previousExtensionKey . ' => ' . $this->extension->getExtensionKey(), 'extension_builder', 1, array('$previousExtensionDirectory ' => $this->previousExtensionDirectory));
     }
     // Rename the old kickstarter.json file to ExtensionBuilder.json
     if (file_exists($this->previousExtensionDirectory . 'kickstarter.json')) {
         rename($this->previousExtensionDirectory . 'kickstarter.json', $this->previousExtensionDirectory . Tx_ExtensionBuilder_Configuration_ConfigurationManager::EXTENSION_BUILDER_SETTINGS_FILE);
     }
     if (file_exists($this->previousExtensionDirectory . Tx_ExtensionBuilder_Configuration_ConfigurationManager::EXTENSION_BUILDER_SETTINGS_FILE)) {
         $extensionSchemaBuilder = t3lib_div::makeInstance('Tx_ExtensionBuilder_Service_ExtensionSchemaBuilder');
         $jsonConfig = $this->configurationManager->getExtensionBuilderConfiguration($this->previousExtensionKey, FALSE);
         t3lib_div::devlog('old JSON:' . $this->previousExtensionDirectory . 'ExtensionBuilder.json', 'extension_builder', 0, $jsonConfig);
         $this->previousExtension = $extensionSchemaBuilder->build($jsonConfig);
         $oldDomainObjects = $this->previousExtension->getDomainObjects();
         foreach ($oldDomainObjects as $oldDomainObject) {
             $this->oldDomainObjects[$oldDomainObject->getUniqueIdentifier()] = $oldDomainObject;
             t3lib_div::devlog('Old domain object: ' . $oldDomainObject->getName() . ' - ' . $oldDomainObject->getUniqueIdentifier(), 'extension_builder');
         }
         // now we store all renamed domainObjects in an array to enable detection of renaming in
         // relationProperties (property->getForeignModel)
         // we also build an array with the new unique identifiers to detect deleting of domainObjects
         $currentDomainsObjects = array();
         foreach ($this->extension->getDomainObjects() as $domainObject) {
             if (isset($this->oldDomainObjects[$domainObject->getUniqueIdentifier()])) {
                 if ($this->oldDomainObjects[$domainObject->getUniqueIdentifier()]->getName() != $domainObject->getName()) {
                     $renamedDomainObjects[$domainObject->getUniqueIdentifier()] = $domainObject;
                 }
             }
             $currentDomainsObjects[$domainObject->getUniqueIdentifier()] = $domainObject;
         }
         // remove deleted objects
         foreach ($oldDomainObjects as $oldDomainObject) {
             if (!isset($currentDomainsObjects[$oldDomainObject->getUniqueIdentifier()])) {
                 $this->removeDomainObjectFiles($oldDomainObject);
             }
         }
     }
     spl_autoload_register('Tx_ExtensionBuilder_Utility_ClassLoader::loadClass', FALSE, TRUE);
 }