protected function generateDomainObjectRelatedFiles()
 {
     if (count($this->extension->getDomainObjects()) > 0) {
         $this->classBuilder->initialize($this, $this->extension, $this->roundTripEnabled);
         // Generate Domain Model
         try {
             $domainModelDirectory = 'Classes/Domain/Model/';
             $this->mkdir_deep($this->extensionDirectory, $domainModelDirectory);
             $domainRepositoryDirectory = 'Classes/Domain/Repository/';
             $this->mkdir_deep($this->extensionDirectory, $domainRepositoryDirectory);
             $this->mkdir_deep($this->extensionDirectory, 'Tests/Unit/Domain/Model');
             $domainModelTestsDirectory = $this->extensionDirectory . 'Tests/Unit/Domain/Model/';
             $this->mkdir_deep($this->extensionDirectory, 'Tests/Unit/Controller');
             $crudEnabledControllerTestsDirectory = $this->extensionDirectory . 'Tests/Unit/Controller/';
             foreach ($this->extension->getDomainObjects() as $domainObject) {
                 $destinationFile = $domainModelDirectory . $domainObject->getName() . '.php';
                 if ($this->roundTripEnabled && Tx_ExtensionBuilder_Service_RoundTrip::getOverWriteSettingForPath($destinationFile, $this->extension) > 0) {
                     $mergeWithExistingClass = TRUE;
                 } else {
                     $mergeWithExistingClass = FALSE;
                 }
                 $fileContents = $this->generateDomainObjectCode($domainObject, $mergeWithExistingClass);
                 $this->writeFile($this->extensionDirectory . $destinationFile, $fileContents);
                 t3lib_div::devlog('Generated ' . $domainObject->getName() . '.php', 'extension_builder', 0);
                 $this->extension->setMD5Hash($this->extensionDirectory . $destinationFile);
                 if ($domainObject->isAggregateRoot()) {
                     $iconFileName = 'aggregate_root.gif';
                 } elseif ($domainObject->isEntity()) {
                     $iconFileName = 'entity.gif';
                 } else {
                     $iconFileName = 'value_object.gif';
                 }
                 $this->upload_copy_move(t3lib_extMgm::extPath('extension_builder') . 'Resources/Private/Icons/' . $iconFileName, $this->iconsDirectory . $domainObject->getDatabaseTableName() . '.gif');
                 if ($domainObject->isAggregateRoot()) {
                     $destinationFile = $domainRepositoryDirectory . $domainObject->getName() . 'Repository.php';
                     if ($this->roundTripEnabled && Tx_ExtensionBuilder_Service_RoundTrip::getOverWriteSettingForPath($destinationFile, $this->extension) > 0) {
                         $mergeWithExistingClass = TRUE;
                     } else {
                         $mergeWithExistingClass = FALSE;
                     }
                     $fileContents = $this->generateDomainRepositoryCode($domainObject, $mergeWithExistingClass);
                     $this->writeFile($this->extensionDirectory . $destinationFile, $fileContents);
                     t3lib_div::devlog('Generated ' . $domainObject->getName() . 'Repository.php', 'extension_builder', 0);
                     $this->extension->setMD5Hash($this->extensionDirectory . $destinationFile);
                 }
                 // Generate basic UnitTests
                 $fileContents = $this->generateDomainModelTests($domainObject);
                 $this->writeFile($domainModelTestsDirectory . $domainObject->getName() . 'Test.php', $fileContents);
             }
         } catch (Exception $e) {
             throw new Exception('Could not generate domain model, error: ' . $e->getMessage());
         }
         // Generate Action Controller
         try {
             $this->mkdir_deep($this->extensionDirectory, 'Classes/Controller');
             $controllerDirectory = 'Classes/Controller/';
             foreach ($this->extension->getDomainObjectsForWhichAControllerShouldBeBuilt() as $domainObject) {
                 $destinationFile = $controllerDirectory . $domainObject->getName() . 'Controller.php';
                 if ($this->roundTripEnabled && Tx_ExtensionBuilder_Service_RoundTrip::getOverWriteSettingForPath($destinationFile, $this->extension) > 0) {
                     $mergeWithExistingClass = TRUE;
                 } else {
                     $mergeWithExistingClass = FALSE;
                 }
                 $fileContents = $this->generateActionControllerCode($domainObject, $mergeWithExistingClass);
                 $this->writeFile($this->extensionDirectory . $destinationFile, $fileContents);
                 t3lib_div::devlog('Generated ' . $domainObject->getName() . 'Controller.php', 'extension_builder', 0);
                 $this->extension->setMD5Hash($this->extensionDirectory . $destinationFile);
                 // Generate basic UnitTests
                 $fileContents = $this->generateControllerTests($domainObject->getName() . 'Controller', $domainObject);
                 $this->writeFile($crudEnabledControllerTestsDirectory . $domainObject->getName() . 'ControllerTest.php', $fileContents);
             }
         } catch (Exception $e) {
             throw new Exception('Could not generate action controller, error: ' . $e->getMessage());
         }
         // Generate Domain Templates
         try {
             if ($this->extension->getPlugins()) {
                 $this->generateTemplateFiles();
             }
             if ($this->extension->getBackendModules()) {
                 $this->generateTemplateFiles('Backend/');
             }
         } catch (Exception $e) {
             throw new Exception('Could not generate domain templates, error: ' . $e->getMessage());
         }
         try {
             $settings = $this->extension->getSettings();
             if (isset($settings['createAutoloadRegistry']) && $settings['createAutoloadRegistry'] == TRUE) {
                 Tx_Extbase_Utility_Extension::createAutoloadRegistryForExtension($this->extension->getExtensionKey(), $this->extensionDirectory);
             }
         } catch (Exception $e) {
             throw new Exception('Could not generate ext_autoload.php, error: ' . $e->getMessage());
         }
     } else {
         t3lib_div::devlog('No domainObjects in this extension', 'extension_builder', 3, (array) $this->extension);
     }
 }
 /**
  * @test
  */
 public function conversionExtractsWholeExtensionMetadataWithRelations()
 {
     $input = array('modules' => array(0 => array('value' => array('name' => 'Blog', 'objectsettings' => array('description' => 'A blog object', 'aggregateRoot' => FALSE, 'type' => 'Entity'), 'propertyGroup' => array('properties' => array(0 => array('propertyName' => 'name', 'propertyType' => 'String'), 1 => array('propertyName' => 'description', 'propertyType' => 'String'))), 'relationGroup' => array('relations' => array(0 => array('relationName' => 'posts', 'relationType' => 'zeroToMany', 'propertyIsExcludeField' => 1))))), 1 => array('value' => array('name' => 'Post', 'objectsettings' => array('description' => 'A blog post', 'aggregateRoot' => FALSE, 'type' => 'Entity'), 'propertyGroup' => array('properties' => array()), 'relationGroup' => array('relations' => array(0 => array('relationName' => 'comments', 'relationType' => 'zeroToMany', 'propertyIsExcludeField' => 1))))), 2 => array('value' => array('name' => 'Comment', 'objectsettings' => array('description' => '', 'aggregateRoot' => FALSE, 'type' => 'Entity'), 'propertyGroup' => array('properties' => array()), 'relationGroup' => array('relations' => array())))), 'properties' => array('description' => 'Some description', 'extensionKey' => $this->extensionKey, 'name' => 'My ext name', 'emConf' => array('state' => 'beta')), 'wires' => array(0 => array('tgt' => array('moduleId' => 1, 'terminal' => 'SOURCES'), 'src' => array('moduleId' => 0, 'terminal' => 'relationWire_0')), 1 => array('tgt' => array('moduleId' => 2, 'terminal' => 'SOURCES'), 'src' => array('moduleId' => 1, 'terminal' => 'relationWire_0'))));
     $extension = new Tx_ExtensionBuilder_Domain_Model_Extension();
     $extension->setName('My ext name');
     $extension->setState(Tx_ExtensionBuilder_Domain_Model_Extension::STATE_BETA);
     $extension->setExtensionKey($this->extensionKey);
     $extension->setDescription('Some description');
     $extension->setExtensionDir('');
     $blog = new Tx_ExtensionBuilder_Domain_Model_DomainObject();
     $blog->setName('Blog');
     $blog->setDescription('A blog object');
     $blog->setEntity(TRUE);
     $blog->setAggregateRoot(FALSE);
     $property = new Tx_ExtensionBuilder_Domain_Model_DomainObject_StringProperty('name');
     $blog->addProperty($property);
     $property = new Tx_ExtensionBuilder_Domain_Model_DomainObject_StringProperty('description');
     $blog->addProperty($property);
     $extension->addDomainObject($blog);
     $post = new Tx_ExtensionBuilder_Domain_Model_DomainObject();
     $post->setName('Post');
     $post->setDescription('A blog post');
     $post->setEntity(TRUE);
     $post->setAggregateRoot(FALSE);
     $extension->addDomainObject($post);
     $comment = new Tx_ExtensionBuilder_Domain_Model_DomainObject();
     $comment->setName('Comment');
     $comment->setDescription('');
     $comment->setEntity(TRUE);
     $comment->setAggregateRoot(FALSE);
     $extension->addDomainObject($comment);
     $relation = new Tx_ExtensionBuilder_Domain_Model_DomainObject_Relation_ZeroToManyRelation('posts');
     $relation->setForeignModel($post);
     $relation->setExcludeField(1);
     $blog->addProperty($relation);
     $relation = new Tx_ExtensionBuilder_Domain_Model_DomainObject_Relation_ZeroToManyRelation('comments');
     $relation->setForeignModel($comment);
     $relation->setExcludeField(1);
     $post->addProperty($relation);
     $actualExtension = $this->extensionSchemaBuilder->build($input);
     $this->assertEquals($extension->getDomainObjects(), $actualExtension->getDomainObjects(), 'The extensions differ');
 }