diff --git a/.gitignore b/.gitignore
index 61d970a274b8dc1a573bf8fd31083ab984197bff..1dc24183ad30092742a351bd094b4ae5573052be 100644
--- a/.gitignore
+++ b/.gitignore
@@ -47,3 +47,4 @@ atlassian*
 /var/*
 !/var/.htaccess
 /vendor
+!/vendor/.htaccess
diff --git a/.htaccess b/.htaccess
index bef5869dd2fdf6a38d9769fee0c8e7ab8d683a2d..13564585ac2274e074728c844aa119b8df9d61a6 100644
--- a/.htaccess
+++ b/.htaccess
@@ -171,13 +171,83 @@
 </IfModule>
 
 ###########################################
-## Deny access to release notes to prevent disclosure of the installed Magento version
+## Deny access to root files to hide sensitive application information
+    RedirectMatch 404 /\.git
 
-    <Files RELEASE_NOTES.txt>
-        Order allow,deny
-        Deny from all
+    <Files composer.json>
+        order allow,deny
+        deny from all
     </Files>
-############################################
+    <Files composer.lock>
+        order allow,deny
+        deny from all
+    </Files>
+    <Files .gitignore>
+        order allow,deny
+        deny from all
+    </Files>
+    <Files .htaccess>
+        order allow,deny
+        deny from all
+    </Files>
+    <Files .htaccess.sample>
+        order allow,deny
+        deny from all
+    </Files>
+    <Files .php_cs>
+        order allow,deny
+        deny from all
+    </Files>
+    <Files .travis.yml>
+        order allow,deny
+        deny from all
+    </Files>
+    <Files CHANGELOG.md>
+        order allow,deny
+        deny from all
+    </Files>
+    <Files CONTRIBUTING.md>
+        order allow,deny
+        deny from all
+    </Files>
+    <Files CONTRIBUTOR_LICENSE_AGREEMENT.html>
+        order allow,deny
+        deny from all
+    </Files>
+    <Files COPYING.txt>
+        order allow,deny
+        deny from all
+    </Files>
+    <Files Gruntfile.js>
+        order allow,deny
+        deny from all
+    </Files>
+    <Files LICENSE.txt>
+        order allow,deny
+        deny from all
+    </Files>
+    <Files LICENSE_AFL.txt>
+        order allow,deny
+        deny from all
+    </Files>
+    <Files nginx.conf.sample>
+        order allow,deny
+        deny from all
+    </Files>
+    <Files package.json>
+        order allow,deny
+        deny from all
+    </Files>
+    <Files php.ini.sample>
+        order allow,deny
+        deny from all
+    </Files>
+    <Files README.md>
+        order allow,deny
+        deny from all
+    </Files>
+
+################################
 ## If running in cluster environment, uncomment this
 ## http://developer.yahoo.com/performance/rules.html#etags
 
diff --git a/.htaccess.sample b/.htaccess.sample
index 133ce7de2c59badd5df4a159bb921e8a99f05eb7..891dad19d642b5f958c9c33c71476dd4d39247c8 100644
--- a/.htaccess.sample
+++ b/.htaccess.sample
@@ -36,7 +36,7 @@
 ############################################
 ## adjust memory limit
 
-    php_value memory_limit 256M
+    php_value memory_limit 768M
     php_value max_execution_time 18000
 
 ############################################
@@ -65,13 +65,6 @@
     SecFilterScanPOST Off
 </IfModule>
 
-<IfModule mod_headers.c>
-############################################
-## prevent clickjacking
-
-    Header set X-Frame-Options SAMEORIGIN
-</IfModule>
-
 <IfModule mod_deflate.c>
 
 ############################################
@@ -136,9 +129,11 @@
     RewriteRule .* - [L,R=405]
 
 ############################################
-## always send 404 on missing files in these folders
+## redirect for mobile user agents
 
-    RewriteCond %{REQUEST_URI} !^/pub/(media|js)/
+    #RewriteCond %{REQUEST_URI} !^/mobiledirectoryhere/.*$
+    #RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC]
+    #RewriteRule ^(.*)$ /mobiledirectoryhere/ [L,R=302]
 
 ############################################
 ## never rewrite for existing files, directories and links
@@ -175,16 +170,84 @@
 </IfModule>
 
 ###########################################
-## Deny access to release notes to prevent disclosure of the installed Magento version
+## Deny access to root files to hide sensitive application information
+    RedirectMatch 404 /\.git
 
-    <Files RELEASE_NOTES.txt>
-        Order allow,deny
-        Deny from all
+    <Files composer.json>
+        order allow,deny
+        deny from all
+    </Files>
+    <Files composer.lock>
+        order allow,deny
+        deny from all
+    </Files>
+    <Files .gitignore>
+        order allow,deny
+        deny from all
+    </Files>
+    <Files .htaccess>
+        order allow,deny
+        deny from all
+    </Files>
+    <Files .htaccess.sample>
+        order allow,deny
+        deny from all
+    </Files>
+    <Files .php_cs>
+        order allow,deny
+        deny from all
+    </Files>
+    <Files .travis.yml>
+        order allow,deny
+        deny from all
+    </Files>
+    <Files CHANGELOG.md>
+        order allow,deny
+        deny from all
+    </Files>
+    <Files CONTRIBUTING.md>
+        order allow,deny
+        deny from all
+    </Files>
+    <Files CONTRIBUTOR_LICENSE_AGREEMENT.html>
+        order allow,deny
+        deny from all
+    </Files>
+    <Files COPYING.txt>
+        order allow,deny
+        deny from all
+    </Files>
+    <Files Gruntfile.js>
+        order allow,deny
+        deny from all
+    </Files>
+    <Files LICENSE.txt>
+        order allow,deny
+        deny from all
+    </Files>
+    <Files LICENSE_AFL.txt>
+        order allow,deny
+        deny from all
+    </Files>
+    <Files nginx.conf.sample>
+        order allow,deny
+        deny from all
+    </Files>
+    <Files package.json>
+        order allow,deny
+        deny from all
+    </Files>
+    <Files php.ini.sample>
+        order allow,deny
+        deny from all
+    </Files>
+    <Files README.md>
+        order allow,deny
+        deny from all
     </Files>
 
-############################################
+################################
 ## If running in cluster environment, uncomment this
 ## http://developer.yahoo.com/performance/rules.html#etags
 
     #FileETag none
-
diff --git a/app/code/Magento/CatalogRule/composer.json b/app/code/Magento/CatalogRule/composer.json
index 8abce05a972830229256bd5475aad5b4452b38ad..887ed8b40e83cf9513fb518be418a16b42bc284e 100644
--- a/app/code/Magento/CatalogRule/composer.json
+++ b/app/code/Magento/CatalogRule/composer.json
@@ -9,10 +9,12 @@
         "magento/module-customer": "1.0.0-beta",
         "magento/module-backend": "1.0.0-beta",
         "magento/module-eav": "1.0.0-beta",
-        "magento/module-import-export": "1.0.0-beta",
         "magento/framework": "1.0.0-beta",
         "magento/magento-composer-installer": "*"
     },
+    "suggest": {
+        "magento/module-import-export": "1.0.0-beta"
+    },
     "type": "magento2-module",
     "version": "1.0.0-beta",
     "license": [
diff --git a/app/code/Magento/CatalogRuleConfigurable/composer.json b/app/code/Magento/CatalogRuleConfigurable/composer.json
index c689ed54a3ca963774116d0b90c2b13073029c6a..fc6bea322d3c59aacb561c8b166823a5d3ea0720 100644
--- a/app/code/Magento/CatalogRuleConfigurable/composer.json
+++ b/app/code/Magento/CatalogRuleConfigurable/composer.json
@@ -3,11 +3,13 @@
     "description": "N/A",
     "require": {
         "php": "~5.5.0|~5.6.0|~7.0.0",
-        "magento/module-catalog-rule": "1.0.0-beta",
         "magento/module-configurable-product": "1.0.0-beta",
         "magento/framework": "1.0.0-beta",
         "magento/magento-composer-installer": "*"
     },
+    "suggest": {
+        "magento/module-catalog-rule": "1.0.0-beta"
+    },
     "type": "magento2-module",
     "version": "1.0.0-beta",
     "license": [
diff --git a/app/code/Magento/ConfigurableProduct/composer.json b/app/code/Magento/ConfigurableProduct/composer.json
index 1b6f0a5a8aea66ae6ccae51733bb3e4edac036fb..a90d56be9beb6ef47032c0d38dc8b6f22e724d28 100644
--- a/app/code/Magento/ConfigurableProduct/composer.json
+++ b/app/code/Magento/ConfigurableProduct/composer.json
@@ -6,7 +6,6 @@
         "magento/module-store": "1.0.0-beta",
         "magento/module-catalog": "1.0.0-beta",
         "magento/module-catalog-inventory": "1.0.0-beta",
-        "magento/module-sales": "1.0.0-beta",
         "magento/module-checkout": "1.0.0-beta",
         "magento/module-msrp": "1.0.0-beta",
         "magento/module-backend": "1.0.0-beta",
@@ -20,7 +19,8 @@
         "magento/magento-composer-installer": "*"
     },
     "suggest": {
-      "magento/module-webapi": "1.0.0-beta"
+      "magento/module-webapi": "1.0.0-beta",
+      "magento/module-sales": "1.0.0-beta"
     },
     "type": "magento2-module",
     "version": "1.0.0-beta",
diff --git a/app/code/Magento/Cron/composer.json b/app/code/Magento/Cron/composer.json
index b1afc6a19518bbc523a02f2c0db4f669510a0e67..653e1f8443cbba8f049eb397c299bde7ec9ac3f6 100644
--- a/app/code/Magento/Cron/composer.json
+++ b/app/code/Magento/Cron/composer.json
@@ -3,11 +3,13 @@
     "description": "N/A",
     "require": {
         "php": "~5.5.0|~5.6.0|~7.0.0",
-        "magento/module-config": "1.0.0-beta",
         "magento/module-store": "1.0.0-beta",
         "magento/framework": "1.0.0-beta",
         "magento/magento-composer-installer": "*"
     },
+    "suggest": {
+        "magento/module-config": "1.0.0-beta"
+    },
     "type": "magento2-module",
     "version": "1.0.0-beta",
     "license": [
diff --git a/app/code/Magento/Dhl/composer.json b/app/code/Magento/Dhl/composer.json
index 033291581ecafaa67d0cb60d76d38aa6f75b3c85..1f577af21d55cb1100238b9b8ce5a9bfc43ab029 100644
--- a/app/code/Magento/Dhl/composer.json
+++ b/app/code/Magento/Dhl/composer.json
@@ -9,7 +9,6 @@
         "magento/module-backend": "1.0.0-beta",
         "magento/module-directory": "1.0.0-beta",
         "magento/module-sales": "1.0.0-beta",
-        "magento/module-checkout": "1.0.0-beta",
         "magento/module-catalog": "1.0.0-beta",
         "magento/module-catalog-inventory": "1.0.0-beta",
         "magento/module-quote": "1.0.0-beta",
@@ -17,6 +16,9 @@
         "lib-libxml": "*",
         "magento/magento-composer-installer": "*"
     },
+    "suggest": {
+        "magento/module-checkout": "1.0.0-beta"
+    },
     "type": "magento2-module",
     "version": "1.0.0-beta",
     "license": [
diff --git a/app/code/Magento/GiftMessage/composer.json b/app/code/Magento/GiftMessage/composer.json
index c3662869435b747e9c1ebbfc828ed2e2316f1dc9..6230e36ff13e4051816047af7c4960e4b94dc0e5 100644
--- a/app/code/Magento/GiftMessage/composer.json
+++ b/app/code/Magento/GiftMessage/composer.json
@@ -6,7 +6,6 @@
         "magento/module-store": "1.0.0-beta",
         "magento/module-catalog": "1.0.0-beta",
         "magento/module-checkout": "1.0.0-beta",
-        "magento/module-multishipping": "1.0.0-beta",
         "magento/module-sales": "1.0.0-beta",
         "magento/module-backend": "1.0.0-beta",
         "magento/module-customer": "1.0.0-beta",
@@ -15,6 +14,9 @@
         "magento/framework": "1.0.0-beta",
         "magento/magento-composer-installer": "*"
     },
+    "suggest": {
+      "magento/module-multishipping": "1.0.0-beta"
+    },
     "type": "magento2-module",
     "version": "1.0.0-beta",
     "license": [
diff --git a/app/code/Magento/Msrp/composer.json b/app/code/Magento/Msrp/composer.json
index 14446581255e6b3fd52a7c5dce2fe32077a34a63..b5d603e700e321f17c6233a065f913d76782285c 100644
--- a/app/code/Magento/Msrp/composer.json
+++ b/app/code/Magento/Msrp/composer.json
@@ -4,7 +4,6 @@
     "require": {
         "php": "~5.5.0|~5.6.0|~7.0.0",
         "magento/module-store": "1.0.0-beta",
-        "magento/module-bundle": "1.0.0-beta",
         "magento/module-catalog": "1.0.0-beta",
         "magento/module-downloadable": "1.0.0-beta",
         "magento/module-eav": "1.0.0-beta",
@@ -14,6 +13,9 @@
         "magento/framework": "1.0.0-beta",
         "magento/magento-composer-installer": "*"
     },
+    "suggest": {
+        "magento/module-bundle": "1.0.0-beta"
+    },
     "type": "magento2-module",
     "version": "1.0.0-beta",
     "license": [
diff --git a/app/code/Magento/OfflineShipping/composer.json b/app/code/Magento/OfflineShipping/composer.json
index 8a0287dd1dc6496b18ae5742406cec7799c2a05b..88ac36533cbf5bd62183cb8722ef2613e241dd49 100644
--- a/app/code/Magento/OfflineShipping/composer.json
+++ b/app/code/Magento/OfflineShipping/composer.json
@@ -11,11 +11,13 @@
         "magento/module-sales": "1.0.0-beta",
         "magento/module-sales-rule": "1.0.0-beta",
         "magento/module-directory": "1.0.0-beta",
-        "magento/module-checkout": "1.0.0-beta",
         "magento/module-quote": "1.0.0-beta",
         "magento/framework": "1.0.0-beta",
         "magento/magento-composer-installer": "*"
     },
+    "suggest": {
+        "magento/module-checkout": "1.0.0-beta"
+    },
     "type": "magento2-module",
     "version": "1.0.0-beta",
     "license": [
diff --git a/app/code/Magento/Swagger/view/frontend/layout/swagger_index_index.xml b/app/code/Magento/Swagger/view/frontend/layout/swagger_index_index.xml
index a43a5c7885a96a19534c859bf0051cb225044c18..8ce4c95f94275746b0df6182cbf15052c4ff1934 100644
--- a/app/code/Magento/Swagger/view/frontend/layout/swagger_index_index.xml
+++ b/app/code/Magento/Swagger/view/frontend/layout/swagger_index_index.xml
@@ -37,9 +37,8 @@
     </head>
     <body>
         <!--Remove Magento page content-->
-        <remove name="page.wrapper"/>
-        <remove name="after.body.start"/>
-        <remove name="page.bottom"/>
+        <referenceContainer name="page.wrapper" remove="true"/>
+        <referenceBlock name="requirejs-config" remove="true"/>
         <referenceContainer name="root">
             <block name="swaggerUiContent" class="Magento\Framework\View\Element\Template" template="Magento_Swagger::swagger-ui/index.phtml"/>
         </referenceContainer>
diff --git a/app/code/Magento/Swagger/view/frontend/templates/swagger-ui/index.phtml b/app/code/Magento/Swagger/view/frontend/templates/swagger-ui/index.phtml
index b9c6e924b3dc9575ea6ed19f867810402f6bf4bc..16f25fd80861cd9e2918969aaa9036507a36de22 100644
--- a/app/code/Magento/Swagger/view/frontend/templates/swagger-ui/index.phtml
+++ b/app/code/Magento/Swagger/view/frontend/templates/swagger-ui/index.phtml
@@ -18,7 +18,7 @@ $schemaUrl = rtrim($block->getBaseUrl(), '/') . '/rest/default/schema?services=a
 ?>
 
 <!DOCTYPE html>
-<script language="text/javascript">
+<script>
     $(function () {
         var url = window.location.search.match(/url=([^&]+)/);
         if (url && url.length > 1) {
diff --git a/app/code/Magento/Swatches/composer.json b/app/code/Magento/Swatches/composer.json
index da38b6169f45d180cc72f4716ee5eae31b51a5d3..6cc94c567d3e8195cf6e7ded5d1d162b3fc193dc 100644
--- a/app/code/Magento/Swatches/composer.json
+++ b/app/code/Magento/Swatches/composer.json
@@ -11,11 +11,13 @@
         "magento/module-backend": "1.0.0-beta",
         "magento/module-media-storage": "1.0.0-beta",
         "magento/module-config": "1.0.0-beta",
-        "magento/module-layered-navigation": "1.0.0-beta",
         "magento/module-theme": "1.0.0-beta",
         "magento/framework": "1.0.0-beta",
         "magento/magento-composer-installer": "*"
     },
+    "suggest": {
+        "magento/module-layered-navigation": "1.0.0-beta"
+    },
     "type": "magento2-module",
     "version": "1.0.0-beta",
     "license": [
diff --git a/dev/tests/functional/composer.json b/dev/tests/functional/composer.json
index 1287f8a2f00f08d893cd3171baa9cb44eefa72bf..6514ced02709b700ad494d85a0b8dced6a798737 100644
--- a/dev/tests/functional/composer.json
+++ b/dev/tests/functional/composer.json
@@ -1,6 +1,6 @@
 {
     "require": {
-        "magento/mtf": "1.0.0-rc32",
+        "magento/mtf": "1.0.0-rc33",
         "php": "~5.5.0|~5.6.0|~7.0.0",
         "phpunit/phpunit": "4.1.0",
         "phpunit/phpunit-selenium": ">=1.2"
diff --git a/dev/tests/functional/phpunit.xml.dist b/dev/tests/functional/phpunit.xml.dist
index ec1748e20b13556da45e875c29870dcdd70f72b1..f5f293ffa39f5099974a754655166834d26eb9a2 100644
--- a/dev/tests/functional/phpunit.xml.dist
+++ b/dev/tests/functional/phpunit.xml.dist
@@ -38,6 +38,7 @@
         <env name="module_whitelist" value="Magento_Install" />
         <env name="basedir" value="var/log" />
         <env name="credentials_file_path" value="./credentials.xml.dist" />
+        <env name="mage_mode" value="developer" />
     </php>
 
 </phpunit>
diff --git a/dev/tests/functional/tests/app/Magento/Backend/Test/Block/Cache/Additional.php b/dev/tests/functional/tests/app/Magento/Backend/Test/Block/Cache/Additional.php
index 30f7194a98fe6ee74c2949c5adad9df2bf472160..605afd986421b6a62248c9c0719f59fd47d41402 100644
--- a/dev/tests/functional/tests/app/Magento/Backend/Test/Block/Cache/Additional.php
+++ b/dev/tests/functional/tests/app/Magento/Backend/Test/Block/Cache/Additional.php
@@ -31,4 +31,16 @@ class Additional extends Block
     {
         $this->_rootElement->find(sprintf($this->flushButton, $flushButtonName), Locator::SELECTOR_XPATH)->click();
     }
+
+    /**
+     * Check if button is visible in 'Additional Cache Management'.
+     *
+     * @param string $flushButtonName
+     * @return bool
+     */
+    public function isFlushCacheButtonVisible($flushButtonName)
+    {
+        return $this->_rootElement->find(sprintf($this->flushButton, $flushButtonName), Locator::SELECTOR_XPATH)
+            ->isVisible();
+    }
 }
diff --git a/dev/tests/functional/tests/app/Magento/Backend/Test/Constraint/AssertCacheFlushStaticFilesInProductionMode.php b/dev/tests/functional/tests/app/Magento/Backend/Test/Constraint/AssertCacheFlushStaticFilesInProductionMode.php
new file mode 100644
index 0000000000000000000000000000000000000000..dce65ed1bc54ab6d74b46962809f9a40c85e7681
--- /dev/null
+++ b/dev/tests/functional/tests/app/Magento/Backend/Test/Constraint/AssertCacheFlushStaticFilesInProductionMode.php
@@ -0,0 +1,42 @@
+<?php
+/**
+ * Copyright © 2015 Magento. All rights reserved.
+ * See COPYING.txt for license details.
+ */
+
+namespace Magento\Backend\Test\Constraint;
+
+use Magento\Backend\Test\Page\Adminhtml\AdminCache;
+use Magento\Mtf\Constraint\AbstractConstraint;
+
+/**
+ * Assert Flush Static Files Cache button not visible in production mode.
+ */
+class AssertCacheFlushStaticFilesInProductionMode extends AbstractConstraint
+{
+    const FLUSH_STATIC_FILES_CACHE = 'Flush Static Files Cache';
+
+    /**
+     * Assert Flush Static Files Cache button not visible in production mode.
+     *
+     * @param AdminCache $adminCache
+     * @return void
+     */
+    public function processAssert(AdminCache $adminCache)
+    {
+        \PHPUnit_Framework_Assert::assertFalse(
+            $adminCache->getAdditionalBlock()->isFlushCacheButtonVisible(self::FLUSH_STATIC_FILES_CACHE),
+            self::FLUSH_STATIC_FILES_CACHE . ' button should not be visible in production mode.'
+        );
+    }
+
+    /**
+     * Returns a string representation of the object.
+     *
+     * @return string
+     */
+    public function toString()
+    {
+        return self::FLUSH_STATIC_FILES_CACHE . ' button is not visible in production mode.';
+    }
+}
diff --git a/dev/tests/functional/tests/app/Magento/Backend/Test/Constraint/AssertCacheManagementAction.php b/dev/tests/functional/tests/app/Magento/Backend/Test/Constraint/AssertCacheManagementAction.php
index 30e7a986ba8e8f361f0d7d75517053777a5156e5..5ca1e4e677bbf7f3fa1ecf19f25114a19e547a2e 100644
--- a/dev/tests/functional/tests/app/Magento/Backend/Test/Constraint/AssertCacheManagementAction.php
+++ b/dev/tests/functional/tests/app/Magento/Backend/Test/Constraint/AssertCacheManagementAction.php
@@ -6,7 +6,6 @@
 
 namespace Magento\Backend\Test\Constraint;
 
-use Magento\Backend\Test\Fixture\GlobalSearch;
 use Magento\Backend\Test\Page\Adminhtml\AdminCache;
 use Magento\Mtf\Constraint\AbstractConstraint;
 
@@ -16,7 +15,7 @@ use Magento\Mtf\Constraint\AbstractConstraint;
 class AssertCacheManagementAction extends AbstractConstraint
 {
     /**
-     * Assert that backend page has correct title and 404 Error is absent on the page.
+     * Assert success message for cache flush.
      *
      * @param AdminCache $adminCache
      * @param string $successMessage
diff --git a/dev/tests/functional/tests/app/Magento/Backend/Test/TestCase/CacheFlushStaticFilesInProductionModeTest.php b/dev/tests/functional/tests/app/Magento/Backend/Test/TestCase/CacheFlushStaticFilesInProductionModeTest.php
new file mode 100644
index 0000000000000000000000000000000000000000..9777614e554e1c5eee2a6b6538a84ff00f62bfa7
--- /dev/null
+++ b/dev/tests/functional/tests/app/Magento/Backend/Test/TestCase/CacheFlushStaticFilesInProductionModeTest.php
@@ -0,0 +1,50 @@
+<?php
+/**
+ * Copyright © 2015 Magento. All rights reserved.
+ * See COPYING.txt for license details.
+ */
+
+namespace Magento\Backend\Test\TestCase;
+
+use Magento\Mtf\TestCase\Injectable;
+use Magento\Backend\Test\Page\Adminhtml\AdminCache;
+
+/**
+ * Steps:
+ * 1. Log in to backend.
+ * 2. Navigate through menu to cache management page.
+ * 3. Perform asserts.
+ *
+ * @ZephyrId MAGETWO-39934
+ */
+class CacheFlushStaticFilesInProductionModeTest extends Injectable
+{
+    /* tags */
+    const MVP = 'no';
+    const DOMAIN = 'PS';
+    /* end tags */
+
+    /**
+     * Test only for 'Flush Static Files Cache' in production mode.
+     *
+     * @return void
+     */
+    public function __prepare()
+    {
+        if ($_ENV['mage_mode'] !== 'production') {
+            $this->markTestSkipped('Skip "Flush Static Files Cache" button absence test when not in production mode.');
+        }
+    }
+
+    /**
+     * Check 'Flush Static Files Cache' not visible in production mode.
+     *
+     *
+     * @param AdminCache $adminCache
+     * @return void
+     */
+    public function test(AdminCache $adminCache)
+    {
+        $adminCache->open();
+    }
+}
diff --git a/dev/tests/functional/tests/app/Magento/Backend/Test/TestCase/CacheFlushStaticFilesInProductionModeTest.xml b/dev/tests/functional/tests/app/Magento/Backend/Test/TestCase/CacheFlushStaticFilesInProductionModeTest.xml
new file mode 100644
index 0000000000000000000000000000000000000000..7417721c749fb1f6accd5cda5c98375500a4e15c
--- /dev/null
+++ b/dev/tests/functional/tests/app/Magento/Backend/Test/TestCase/CacheFlushStaticFilesInProductionModeTest.xml
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/**
+ * Copyright © 2015 Magento. All rights reserved.
+ * See COPYING.txt for license details.
+ */
+ -->
+<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/variations.xsd">
+    <testCase name="Magento\Backend\Test\TestCase\CacheFlushStaticFilesInProductionModeTest" summary="Flush Static Files Cache button not in production mode" ticketId="MAGETWO-39934">
+        <variation name="FlushStaticFilesCacheInProductionTest">
+            <constraint name="Magento\Backend\Test\Constraint\AssertCacheFlushStaticFilesInProductionMode" />
+        </variation>
+    </testCase>
+</config>
diff --git a/dev/tests/functional/tests/app/Magento/Backend/Test/TestCase/CacheManagementTest.php b/dev/tests/functional/tests/app/Magento/Backend/Test/TestCase/CacheManagementTest.php
index 6817abe742c6d4917f8b80963f67df4d06b75e50..c25b3d8922e9f6f2e6c265ad00650634a7fdb779 100644
--- a/dev/tests/functional/tests/app/Magento/Backend/Test/TestCase/CacheManagementTest.php
+++ b/dev/tests/functional/tests/app/Magento/Backend/Test/TestCase/CacheManagementTest.php
@@ -12,11 +12,11 @@ use Magento\Backend\Test\Page\Adminhtml\AdminCache;
 /**
  * Steps:
  * 1. Log in to backend.
- * 2. Navigate throught menu to cache management page.
+ * 2. Navigate through menu to cache management page.
  * 3. Click a button.
  * 4. Perform asserts.
  *
- * @ZephyrId MAGETWO-34502, MAGETWO-34503, MAGETWO-39934
+ * @ZephyrId MAGETWO-34052, MAGETWO-34053, MAGETWO-39934
  */
 class CacheManagementTest extends Injectable
 {
@@ -26,7 +26,7 @@ class CacheManagementTest extends Injectable
     /* end tags */
 
     /**
-     * Open admin cache management page.
+     * Open admin cache management page and click button to flush cache.
      *
      * @param AdminCache $adminCache
      * @param string $flushButtonName
@@ -34,6 +34,12 @@ class CacheManagementTest extends Injectable
      */
     public function test(AdminCache $adminCache, $flushButtonName)
     {
+        /**
+         * Skip test for 'Flush Static Files Cache' in production mode.
+         */
+        if (($flushButtonName === 'Flush Static Files Cache') && $_ENV['mage_mode'] === 'production') {
+            $this->markTestSkipped('Skip flushing static files cache test when in production mode.');
+        }
         $adminCache->open();
         $adminCache->getAdditionalBlock()->clickFlushCache($flushButtonName);
     }
diff --git a/dev/tests/functional/tests/app/Magento/Backend/Test/TestCase/CacheManagementTest.xml b/dev/tests/functional/tests/app/Magento/Backend/Test/TestCase/CacheManagementTest.xml
index e970b3f71fa5484226e5c222e599bce7f4dd00f8..f575bedde68835011423a03a3e9ffa5af0683607 100644
--- a/dev/tests/functional/tests/app/Magento/Backend/Test/TestCase/CacheManagementTest.xml
+++ b/dev/tests/functional/tests/app/Magento/Backend/Test/TestCase/CacheManagementTest.xml
@@ -6,7 +6,7 @@
  */
  -->
 <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/variations.xsd">
-    <testCase name="Magento\Backend\Test\TestCase\CacheManagementTest" summary="Configuration option on backend for singleQuery mode" ticketId="MAGETWO-34502">
+    <testCase name="Magento\Backend\Test\TestCase\CacheManagementTest" summary="Additional Cache Management" ticketId="MAGETWO-34052">
         <variation name="FlushCatalogImagesCacheTest">
             <data name="flushButtonName" xsi:type="string">Flush Catalog Images Cache</data>
             <data name="successMessage" xsi:type="string">The image cache was cleaned.</data>
diff --git a/dev/tests/static/framework/Magento/TestFramework/Dependency/PhpRule.php b/dev/tests/static/framework/Magento/TestFramework/Dependency/PhpRule.php
index 163b4ab3cd019ec4410edaebf94492a10e38e05b..99cb701eec3f576499260a2fce7ab75acdcc3797 100644
--- a/dev/tests/static/framework/Magento/TestFramework/Dependency/PhpRule.php
+++ b/dev/tests/static/framework/Magento/TestFramework/Dependency/PhpRule.php
@@ -7,8 +7,25 @@
  */
 namespace Magento\TestFramework\Dependency;
 
-class PhpRule implements \Magento\TestFramework\Dependency\RuleInterface
+use Magento\Framework\App\Utility\Files;
+use Magento\TestFramework\Dependency\RuleInterface;
+
+class PhpRule implements RuleInterface
 {
+    /**
+     * List of filepaths for DI files
+     *
+     * @var array
+     */
+    private $diFiles;
+
+    /**
+     * Map from plugin classes to the subjects they modify
+     *
+     * @var array
+     */
+    private $pluginMap;
+
     /**
      * List of routers
      *
@@ -47,12 +64,14 @@ class PhpRule implements \Magento\TestFramework\Dependency\RuleInterface
      *
      * @param array $mapRouters
      * @param array $mapLayoutBlocks
+     * @param array $pluginMap
      */
-    public function __construct(array $mapRouters, array $mapLayoutBlocks)
+    public function __construct(array $mapRouters, array $mapLayoutBlocks, array $pluginMap = [])
     {
         $this->_mapRouters = $mapRouters;
         $this->_mapLayoutBlocks = $mapLayoutBlocks;
         $this->_namespaces = implode('|', \Magento\Framework\App\Utility\Files::init()->getNamespaces());
+        $this->pluginMap = $pluginMap ?: null;
     }
 
     /**
@@ -72,7 +91,7 @@ class PhpRule implements \Magento\TestFramework\Dependency\RuleInterface
 
         $pattern = '~\b(?<class>(?<module>(' . implode(
             '_|',
-            \Magento\Framework\App\Utility\Files::init()->getNamespaces()
+            Files::init()->getNamespaces()
         ) . '[_\\\\])[a-zA-Z0-9]+)[a-zA-Z0-9_\\\\]*)\b~';
 
         $dependenciesInfo = [];
@@ -83,10 +102,16 @@ class PhpRule implements \Magento\TestFramework\Dependency\RuleInterface
                 if ($currentModule == $referenceModule) {
                     continue;
                 }
+                $dependencyClass = trim($matches['class'][$i]);
+                $currentClass = $this->getClassFromFilepath($file, $currentModule);
+                $dependencyType = $this->isPluginDependency($currentClass, $dependencyClass)
+                    ? RuleInterface::TYPE_SOFT
+                    : RuleInterface::TYPE_HARD;
+
                 $dependenciesInfo[] = [
                     'module' => $referenceModule,
-                    'type' => \Magento\TestFramework\Dependency\RuleInterface::TYPE_HARD,
-                    'source' => trim($matches['class'][$i]),
+                    'type' => $dependencyType,
+                    'source' => $dependencyClass,
                 ];
             }
         }
@@ -102,6 +127,84 @@ class PhpRule implements \Magento\TestFramework\Dependency\RuleInterface
         return $dependenciesInfo;
     }
 
+    /**
+     * Get class name from filename based on class/file naming conventions
+     *
+     * @param string $filepath
+     * @param string $module
+     * @return string
+     */
+    private function getClassFromFilepath($filepath, $module)
+    {
+        $class = strstr($filepath, str_replace(['_', '\\', '/'], DIRECTORY_SEPARATOR, $module));
+        $class = str_replace(DIRECTORY_SEPARATOR, '\\', strstr($class, '.php', true));
+        return $class;
+    }
+
+    /**
+     * @return array
+     * @throws \Exception
+     */
+    private function loadDiFiles()
+    {
+        if (!$this->diFiles) {
+            $this->diFiles = Files::init()->getDiConfigs();
+        }
+        return $this->diFiles;
+    }
+
+    /**
+     * Generate an array of plugin info
+     *
+     * @return array
+     */
+    private function loadPluginMap()
+    {
+        if (!$this->pluginMap) {
+            foreach ($this->loadDiFiles() as $filepath) {
+                $dom = new \DOMDocument();
+                $dom->loadXML(file_get_contents($filepath));
+                $typeNodes = $dom->getElementsByTagName('type');
+                /** @var \DOMElement $type */
+                foreach ($typeNodes as $type) {
+                    /** @var \DOMElement $plugin */
+                    foreach ($type->getElementsByTagName('plugin') as $plugin) {
+                        $subject = $type->getAttribute('name');
+                        $pluginType = $plugin->getAttribute('type');
+                        $this->pluginMap[$pluginType] = $subject;
+                    }
+                }
+            }
+        }
+        return $this->pluginMap;
+    }
+
+    /**
+     * Determine whether a the dependency relation is because of a plugin
+     *
+     * True IFF the dependent is a plugin for some class in the same module as the dependency.
+     *
+     * @param string $dependent
+     * @param string $dependency
+     * @return bool
+     */
+    private function isPluginDependency($dependent, $dependency)
+    {
+        $pluginMap = $this->loadPluginMap();
+        $subject = isset($pluginMap[$dependent])
+            ? $pluginMap[$dependent]
+            : null;
+        if ($subject === $dependency) {
+            return true;
+        } else if ($subject) {
+            $subjectModule = substr($subject, 0, strpos($subject, '\\', 9)); // (strlen('Magento\\') + 1) === 9
+            return strpos($dependency, $subjectModule) === 0;
+        } else {
+            return false;
+        }
+    }
+
+
     /**
      * Check get URL method
      *
@@ -128,7 +231,7 @@ class PhpRule implements \Magento\TestFramework\Dependency\RuleInterface
                     foreach ($modules as $module) {
                         $dependencies[] = [
                             'module' => $module,
-                            'type' => \Magento\TestFramework\Dependency\RuleInterface::TYPE_HARD,
+                            'type' => RuleInterface::TYPE_HARD,
                             'source' => $item['source'],
                         ];
                     }
@@ -166,7 +269,7 @@ class PhpRule implements \Magento\TestFramework\Dependency\RuleInterface
             $module = isset($check['module']) ? $check['module'] : null;
             if ($module) {
                 $result[$module] = [
-                    'type' => \Magento\TestFramework\Dependency\RuleInterface::TYPE_HARD,
+                    'type' => RuleInterface::TYPE_HARD,
                     'source' => $match['source'],
                 ];
             }
diff --git a/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Dependency/PhpRuleTest.php b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Dependency/PhpRuleTest.php
index ed8660694377b51f79320972d79b3f50d4662adc..aa92d6ba72e0097ba2476ca0bbde8a9c2421d61a 100644
--- a/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Dependency/PhpRuleTest.php
+++ b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Dependency/PhpRuleTest.php
@@ -16,7 +16,11 @@ class PhpRuleTest extends \PHPUnit_Framework_TestCase
     {
         $mapRoutes = ['someModule' => ['Magento\SomeModule'], 'anotherModule' => ['Magento\OneModule']];
         $mapLayoutBlocks = ['area' => ['block.name' => ['Magento\SomeModule' => 'Magento\SomeModule']]];
-        $this->model = new PhpRule($mapRoutes, $mapLayoutBlocks);
+        $pluginMap = [
+            'Magento\Module1\Plugin1' => 'Magento\Module1\Subject',
+            'Magento\Module1\Plugin2' => 'Magento\Module2\Subject',
+        ];
+        $this->model = new PhpRule($mapRoutes, $mapLayoutBlocks, $pluginMap);
     }
 
     public function testNonPhpGetDependencyInfo()
@@ -26,22 +30,31 @@ class PhpRuleTest extends \PHPUnit_Framework_TestCase
     }
 
     /**
-     * @param string $module
+     * @param string $class
      * @param string $content
      * @param array $expected
      * @dataProvider getDependencyInfoDataProvider
      */
-    public function testGetDependencyInfo($module, $content, array $expected)
+    public function testGetDependencyInfo($class, $content, array $expected)
     {
-        $this->assertEquals($expected, $this->model->getDependencyInfo($module, 'php', 'any', $content));
+        $file = $this->makeMockFilepath($class);
+        $module = $this->getModuleFromClass($class);
+        $this->assertEquals($expected, $this->model->getDependencyInfo($module, 'php', $file, $content));
     }
 
+    /**
+     * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
+     */
     public function getDependencyInfoDataProvider()
     {
         return [
-            ['Magento\SomeModule', 'something extends \Magento\SomeModule\Any\ClassName {', []], //1
-            [
-                'Magento\AnotherModule',
+            'Extend class in same module' => [
+                'Magento\SomeModule\SomeClass',
+                'something extends \Magento\SomeModule\Any\ClassName {',
+                []
+            ],
+            'Extend class in different module' => [
+                'Magento\AnotherModule\SomeClass',
                 'something extends \Magento\SomeModule\Any\ClassName {',
                 [
                     [
@@ -50,14 +63,14 @@ class PhpRuleTest extends \PHPUnit_Framework_TestCase
                         'source' => 'Magento\SomeModule\Any\ClassName',
                     ]
                 ]
-            ], // 2
-            [
-                'Magento\SomeModule',
+            ],
+            'getViewFileUrl in same module' => [
+                'Magento\SomeModule\SomeClass',
                 '$this->getViewFileUrl("Magento_SomeModule::js/order-by-sku-failure.js")',
                 []
-            ], // 3
-            [
-                'Magento\AnotherModule',
+            ],
+            'getViewFileUrl in different module' => [
+                'Magento\AnotherModule\SomeClass',
                 '$this->getViewFileUrl("Magento_SomeModule::js/order-by-sku-failure.js")',
                 [
                     [
@@ -66,10 +79,14 @@ class PhpRuleTest extends \PHPUnit_Framework_TestCase
                         'source' => 'Magento_SomeModule',
                     ]
                 ]
-            ], //4
-            ['Magento\SomeModule', '$this->helper("Magento\SomeModule\Any\ClassName")', []], //5
-            [
-                'Magento\AnotherModule',
+            ],
+            'Helper class from same module' => [
+                'Magento\SomeModule\SomeClass',
+                '$this->helper("Magento\SomeModule\Any\ClassName")',
+                []
+            ],
+            'Helper class from another module' => [
+                'Magento\AnotherModule\SomeClass',
                 '$this->helper("Magento\SomeModule\Any\ClassName")',
                 [
                     [
@@ -78,10 +95,14 @@ class PhpRuleTest extends \PHPUnit_Framework_TestCase
                         'source' => 'Magento\SomeModule\Any\ClassName',
                     ]
                 ]
-            ], //6
-            ['Magento\SomeModule', '$this->getUrl("someModule")', []], // 7
-            [
-                'Magento\AnotherModule',
+            ],
+            'getUrl from same module' => [
+                'Magento\SomeModule\SomeClass',
+                '$this->getUrl("someModule")',
+                []
+            ],
+            'getUrl from another module' => [
+                'Magento\SomeModule\SomeClass',
                 '$this->getUrl("anotherModule")',
                 [
                     [
@@ -90,10 +111,13 @@ class PhpRuleTest extends \PHPUnit_Framework_TestCase
                         'source' => 'getUrl("anotherModule"',
                     ]
                 ]
-            ], //8
-            ['Magento\SomeModule', '$this->getLayout()->getBlock(\'block.name\');', []], // 9
-            [
-                'Magento\AnotherModule',
+            ],
+            'getBlock from same module' => [
+                'Magento\SomeModule\SomeClass',
+                '$this->getLayout()->getBlock(\'block.name\');', []
+            ],
+            'getBlock from another module' => [
+                'Magento\AnotherModule\SomeClass',
                 '$this->getLayout()->getBlock(\'block.name\');',
                 [
                     [
@@ -102,7 +126,50 @@ class PhpRuleTest extends \PHPUnit_Framework_TestCase
                         'source' => 'getBlock(\'block.name\')',
                     ]
                 ]
-            ] // 10
+            ],
+            'Plugin on class in same module' => [
+                'Magento\Module1\Plugin1',
+                ', \Magento\Module1\Subject $variable',
+                []
+            ],
+            'Plugin depends on arbitrary class in same module' => [
+                'Magento\Module1\Plugin1',
+                ', \Magento\Module1\NotSubject $variable',
+                []
+            ],
+            'Plugin on class in different module' => [
+                'Magento\Module1\Plugin2',
+                'Magento\Module2\Subject',
+                [
+                    [
+                        'module' => 'Magento\Module2',
+                        'type' => \Magento\TestFramework\Dependency\RuleInterface::TYPE_SOFT,
+                        'source' => 'Magento\Module2\Subject',
+                    ]
+                ],
+            ],
+            'Plugin depends on arbitrary class in same module as subject' => [
+                'Magento\Module1\Plugin2',
+                'Magento\Module2\NotSubject',
+                [
+                    [
+                        'module' => 'Magento\Module2',
+                        'type' => \Magento\TestFramework\Dependency\RuleInterface::TYPE_SOFT,
+                        'source' => 'Magento\Module2\NotSubject',
+                    ]
+                ]
+            ],
+            'Plugin depends on arbitrary class in arbitrary module' => [
+                'Magento\Module1\Plugin2',
+                'Magento\OtherModule\NotSubject',
+                [
+                    [
+                        'module' => 'Magento\OtherModule',
+                        'type' => \Magento\TestFramework\Dependency\RuleInterface::TYPE_HARD,
+                        'source' => 'Magento\OtherModule\NotSubject',
+                    ]
+                ]
+            ],
         ];
     }
 
@@ -141,4 +208,28 @@ class PhpRuleTest extends \PHPUnit_Framework_TestCase
             ]
         ];
     }
+
+
+    /**
+     * Make some fake filepath to correspond to the class name
+     *
+     * @param string $class
+     * @return string
+     */
+    private function makeMockFilepath($class)
+    {
+        return 'ClassRoot' . DIRECTORY_SEPARATOR . str_replace('\\', DIRECTORY_SEPARATOR, $class) . '.php';
+    }
+
+    /**
+     * Get the module name like Magento\Module out of a classname, assuming for test purpose that
+     * all modules are from "Magento" vendor
+     *
+     * @param string $class
+     * @return string
+     */
+    private function getModuleFromClass($class)
+    {
+        return substr($class, 0, strpos($class, '\\', 9)); // (strlen('Magento\\') + 1) === 9
+    }
 }
diff --git a/nginx.conf.sample b/nginx.conf.sample
index cab0b839ffe10f8c87a46dc97baccafa50f93a64..01b163498156956cb37f9ea99a5f5f9c9817981c 100644
--- a/nginx.conf.sample
+++ b/nginx.conf.sample
@@ -26,13 +26,32 @@ charset off;
 
 location /setup {
     root $MAGE_ROOT;
-
     location ~ ^/setup/index.php {
         fastcgi_pass   fastcgi_backend;
         fastcgi_index  index.php;
         fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
         include        fastcgi_params;
     }
+
+    location ~ /setup/(?!pub/). {
+        deny all;
+    }
+}
+
+location /update {
+    root $MAGE_ROOT;
+
+    location ~ /update/index.php {
+        fastcgi_pass   fastcgi_backend;
+        fastcgi_index  index.php;
+        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
+        include        fastcgi_params;
+    }
+
+    # deny everything but index.php
+    location ~ /update/(?!pub/). {
+        deny all;
+    }
 }
 
 location / {
@@ -40,6 +59,9 @@ location / {
 }
 
 location /pub {
+    location ~ ^/pub/media/(downloadable|customer|import|theme_customization/.*\.xml) {
+        deny all;
+    }
     alias $MAGE_ROOT/pub;
 }
 
@@ -70,6 +92,11 @@ location /static/ {
 
 location /media/ {
     try_files $uri $uri/ /get.php?$args;
+
+    location ~ ^/media/theme_customization/.*\.xml {
+        deny all;
+    }
+
     location ~* \.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2)$ {
         add_header Cache-Control "public";
         expires +1y;
@@ -90,15 +117,7 @@ location /media/downloadable/ {
     deny all;
 }
 
-location ~ /media/theme_customization/.*\.xml$ {
-    deny all;
-}
-
-location /errors/ {
-    try_files $uri =404;
-}
-
-location ~ ^/errors/.*\.(xml|phtml)$ {
+location /media/import/ {
     deny all;
 }
 
diff --git a/pub/errors/.htaccess b/pub/errors/.htaccess
index 5a3f0a15d124ed9f66b3fd0e97ad4d6ae7cce0f7..3692dd439e2ff90b141f4e2c362518e359e7079e 100644
--- a/pub/errors/.htaccess
+++ b/pub/errors/.htaccess
@@ -2,6 +2,3 @@ Options None
 <IfModule mod_rewrite.c>
     RewriteEngine Off
 </IfModule>
-<FilesMatch "\.(xml|phtml)$">
-    Deny from all
-</FilesMatch>
\ No newline at end of file
diff --git a/setup/config/.htaccess b/setup/config/.htaccess
new file mode 100644
index 0000000000000000000000000000000000000000..281d5c33db37cd1cc887dbb2d36897b897835071
--- /dev/null
+++ b/setup/config/.htaccess
@@ -0,0 +1,2 @@
+order allow,deny
+deny from all
diff --git a/setup/performance-toolkit/.htaccess b/setup/performance-toolkit/.htaccess
new file mode 100644
index 0000000000000000000000000000000000000000..281d5c33db37cd1cc887dbb2d36897b897835071
--- /dev/null
+++ b/setup/performance-toolkit/.htaccess
@@ -0,0 +1,2 @@
+order allow,deny
+deny from all
diff --git a/setup/src/.htaccess b/setup/src/.htaccess
new file mode 100644
index 0000000000000000000000000000000000000000..281d5c33db37cd1cc887dbb2d36897b897835071
--- /dev/null
+++ b/setup/src/.htaccess
@@ -0,0 +1,2 @@
+order allow,deny
+deny from all
diff --git a/setup/src/Magento/Setup/Console/Command/DiCompileCommand.php b/setup/src/Magento/Setup/Console/Command/DiCompileCommand.php
index 707c8ee9dae3296836b2a16a000298fded1c9359..05a46aac47dade5b0a8f9b40ad7eeb16ea175388 100644
--- a/setup/src/Magento/Setup/Console/Command/DiCompileCommand.php
+++ b/setup/src/Magento/Setup/Console/Command/DiCompileCommand.php
@@ -8,6 +8,7 @@ namespace Magento\Setup\Console\Command;
 
 use Magento\Framework\Filesystem;
 use Magento\Framework\App\Filesystem\DirectoryList;
+use Magento\Framework\Filesystem\DriverInterface;
 use Magento\Framework\ObjectManagerInterface;
 use Magento\Framework\App\DeploymentConfig;
 use Magento\Setup\Model\ObjectManagerProvider;
@@ -44,6 +45,9 @@ class DiCompileCommand extends Command
     /** @var array */
     private $excludedPathsList;
 
+    /** @var DriverInterface */
+    private $fileDriver;
+
     /**
      * Constructor
      *
@@ -52,19 +56,22 @@ class DiCompileCommand extends Command
      * @param Manager $taskManager
      * @param ObjectManagerProvider $objectManagerProvider
      * @param Filesystem $filesystem
+     * @param DriverInterface $fileDriver
      */
     public function __construct(
         DeploymentConfig $deploymentConfig,
         DirectoryList $directoryList,
         Manager $taskManager,
         ObjectManagerProvider $objectManagerProvider,
-        Filesystem $filesystem
+        Filesystem $filesystem,
+        DriverInterface $fileDriver
     ) {
         $this->deploymentConfig = $deploymentConfig;
         $this->directoryList    = $directoryList;
         $this->objectManager    = $objectManagerProvider->get();
         $this->taskManager      = $taskManager;
         $this->filesystem       = $filesystem;
+        $this->fileDriver       = $fileDriver;
         parent::__construct();
     }
 
@@ -80,18 +87,50 @@ class DiCompileCommand extends Command
         parent::configure();
     }
 
+    /**
+     * Checks that application is installed and DI resources are cleared
+     *
+     * @return string[]
+     */
+    private function checkEnvironment()
+    {
+        $messages = [];
+        if (!$this->deploymentConfig->isAvailable()) {
+            $messages[] = 'You cannot run this command because the Magento application is not installed.';
+        }
+
+        /**
+         * By the time the command is able to execute, the Object Management configuration is already contaminated
+         * by old config info, and it's too late to just clear the files in code.
+         *
+         * TODO: reconfigure OM in runtime so DI resources can be cleared after command launches
+         *
+         */
+        $path = $this->directoryList->getPath(DirectoryList::DI);
+        if ($this->fileDriver->isExists($path)) {
+            $messages[] = "DI configuration must be cleared before running compiler. Please delete '$path'.";
+        }
+
+        return $messages;
+    }
+
     /**
      * {@inheritdoc}
      */
     protected function execute(InputInterface $input, OutputInterface $output)
     {
+        $errors = $this->checkEnvironment();
+        if ($errors) {
+            foreach ($errors as $line) {
+                $output->writeln($line);
+            }
+            return;
+        }
+
         $appCodePath = $this->directoryList->getPath(DirectoryList::MODULES);
         $libraryPath = $this->directoryList->getPath(DirectoryList::LIB_INTERNAL);
         $generationPath = $this->directoryList->getPath(DirectoryList::GENERATION);
-        if (!$this->deploymentConfig->isAvailable()) {
-            $output->writeln('You cannot run this command because the Magento application is not installed.');
-            return;
-        }
+
         $this->objectManager->get('Magento\Framework\App\Cache')->clean();
         $compiledPathsList = [
             'application' => $appCodePath,
diff --git a/setup/src/Magento/Setup/Test/Unit/Console/Command/DiCompileCommandTest.php b/setup/src/Magento/Setup/Test/Unit/Console/Command/DiCompileCommandTest.php
index 2b9381b4783a495e0a179e6221734c0ac34e5895..205e0799436bb77e81fcda0bfed630df89874c55 100644
--- a/setup/src/Magento/Setup/Test/Unit/Console/Command/DiCompileCommandTest.php
+++ b/setup/src/Magento/Setup/Test/Unit/Console/Command/DiCompileCommandTest.php
@@ -28,6 +28,12 @@ class DiCompileCommandTest extends \PHPUnit_Framework_TestCase
     /** @var  \Magento\Framework\Filesystem|\PHPUnit_Framework_MockObject_MockObject */
     private $filesystem;
 
+    /** @var  \Magento\Framework\Filesystem\Driver\File | \PHPUnit_Framework_MockObject_MockObject*/
+    private $fileDriver;
+
+    /** @var  \Magento\Framework\App\Filesystem\DirectoryList | \PHPUnit_Framework_MockObject_MockObject*/
+    private $directoryList;
+
     public function setUp()
     {
         $this->deploymentConfig = $this->getMock('Magento\Framework\App\DeploymentConfig', [], [], '', false);
@@ -52,23 +58,39 @@ class DiCompileCommandTest extends \PHPUnit_Framework_TestCase
             ->method('get')
             ->willReturn($this->objectManager);
         $this->manager = $this->getMock('Magento\Setup\Module\Di\App\Task\Manager', [], [], '', false);
-        $directoryList = $this->getMock('Magento\Framework\App\Filesystem\DirectoryList', [], [], '', false);
+        $this->directoryList = $this->getMock('Magento\Framework\App\Filesystem\DirectoryList', [], [], '', false);
         $this->filesystem = $this->getMockBuilder('Magento\Framework\Filesystem')
             ->disableOriginalConstructor()
             ->getMock();
 
-        $directoryList->expects($this->exactly(3))->method('getPath');
+        $this->fileDriver = $this->getMockBuilder('Magento\Framework\Filesystem\Driver\File')
+            ->disableOriginalConstructor()
+            ->getMock();
+
         $this->command = new DiCompileCommand(
             $this->deploymentConfig,
-            $directoryList,
+            $this->directoryList,
             $this->manager,
             $objectManagerProvider,
-            $this->filesystem
+            $this->filesystem,
+            $this->fileDriver
         );
     }
 
+    public function testExecuteDiExists()
+    {
+        $diPath = '/root/magento/var/di';
+        $this->deploymentConfig->expects($this->once())->method('isAvailable')->willReturn(true);
+        $this->fileDriver->expects($this->atLeastOnce())->method('isExists')->with($diPath)->willReturn(true);
+        $this->directoryList->expects($this->atLeastOnce())->method('getPath')->willReturn($diPath);
+        $tester = new CommandTester($this->command);
+        $tester->execute([]);
+        $this->assertContains("delete '/root/magento/var/di'", $tester->getDisplay());
+    }
+
     public function testExecuteNotInstalled()
     {
+        $this->directoryList->expects($this->atLeastOnce())->method('getPath')->willReturn(null);
         $this->deploymentConfig->expects($this->once())->method('isAvailable')->willReturn(false);
         $tester = new CommandTester($this->command);
         $tester->execute([]);
@@ -80,6 +102,7 @@ class DiCompileCommandTest extends \PHPUnit_Framework_TestCase
 
     public function testExecute()
     {
+        $this->directoryList->expects($this->atLeastOnce())->method('getPath')->willReturn(null);
         $this->objectManager->expects($this->once())
             ->method('get')
             ->with('Magento\Framework\App\Cache')
diff --git a/setup/view/.htaccess b/setup/view/.htaccess
new file mode 100644
index 0000000000000000000000000000000000000000..281d5c33db37cd1cc887dbb2d36897b897835071
--- /dev/null
+++ b/setup/view/.htaccess
@@ -0,0 +1,2 @@
+order allow,deny
+deny from all
diff --git a/vendor/.htaccess b/vendor/.htaccess
new file mode 100644
index 0000000000000000000000000000000000000000..cb24fd7fc0b3a0e46f6cad19e834117476bd0341
--- /dev/null
+++ b/vendor/.htaccess
@@ -0,0 +1,2 @@
+Order allow,deny
+Deny from all