Creates a new flutter command 'ide-config' and removes *.iml and .idea from tree. (#12958)

Creates a new (hidden) flutter command 'ide-config' that will create and/or update
existing .iml files and some files under the .idea directory, as well as
removing existing *.iml files and the .idea directory.

It also:

 * Adds *.iml to the .gitignore
 * Removes existing .iml files from the repo, and moves them to the
   packages/flutter_tools/ide_templates/intellij directory.
 * Adds a flag to ide-config ('--update-templates') that will take any new .iml
   files in the flutter tree and add them to the existing templates.
     - If --overwrite is also specified, then all existing templates will also
       be overwritten with the contents from the flutter tree, and any that have
       been deleted from the flutter tree will also be removed from the
       templates.
 * Added new run configurations for all existing app targets that will now also
   be automatically added to IntelliJ.
 * Setting up the environment also includes setting the coding style guidelines
   and the git VCS.
 * Note that after this PR lands, Flutter developers will need to run it once to
   re-create the .iml files and configuration files that have been removed.

After this PR lands, .iml files will no longer appear in the untracked files
section for git.
This commit is contained in:
Greg Spencer 2017-11-13 10:55:22 -08:00 committed by GitHub
parent 9be85b6b4b
commit 797b39e9b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
82 changed files with 842 additions and 334 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
.idea
.history
.DS_Store
*.iml

View File

@ -44,14 +44,17 @@ Getting the code and configuring your environment
* Run `flutter update-packages` This will fetch all the Dart packages that
Flutter depends on. You can replicate what this script does by running
`pub get` in each directory that contains a `pubspec.yaml` file.
* If you plan on using IntelliJ as your IDE, then also run
`flutter ide-config --overwrite` to create all of the IntelliJ configuration
files so you can open the main flutter directory as a project and run examples
from within the IDE.
Running the examples
--------------------
To run an example with a prebuilt binary from the cloud, switch to that
example's directory, run `pub get` to make sure its dependencies have been
downloaded, and use `flutter run`. Make sure you have a device connected over
USB and debugging enabled on that device.
To run an example, switch to that example's directory, and use `flutter run`.
Make sure you have an emulator running, or a device connected over USB and
debugging enabled on that device.
* `cd examples/hello_world`
* `flutter run`

View File

@ -1,26 +0,0 @@
<component name="libraryTable">
<library name="Dart SDK">
<CLASSES>
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/async" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/collection" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/convert" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/core" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/developer" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/html" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/indexed_db" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/io" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/isolate" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/js" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/js_util" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/math" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/mirrors" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/svg" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/typed_data" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/web_audio" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/web_gl" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/web_sql" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

View File

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/flutter_gallery.iml" filepath="$PROJECT_DIR$/flutter_gallery.iml" />
</modules>
</component>
</project>

View File

@ -1,6 +0,0 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="main.dart" type="FlutterRunConfigurationType" factoryName="Flutter">
<option name="filePath" value="$PROJECT_DIR$/lib/main.dart" />
<method />
</configuration>
</component>

View File

@ -1,26 +0,0 @@
<component name="libraryTable">
<library name="Dart SDK">
<CLASSES>
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/async" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/collection" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/convert" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/core" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/developer" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/html" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/indexed_db" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/io" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/isolate" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/js" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/js_util" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/math" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/mirrors" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/svg" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/typed_data" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/web_audio" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/web_gl" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/web_sql" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

View File

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/flutter_view.iml" filepath="$PROJECT_DIR$/flutter_view.iml" />
</modules>
</component>
</project>

View File

@ -1,6 +0,0 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="main.dart" type="FlutterRunConfigurationType" factoryName="Flutter">
<option name="filePath" value="$PROJECT_DIR$/lib/main.dart" />
<method />
</configuration>
</component>

View File

@ -1,26 +0,0 @@
<component name="libraryTable">
<library name="Dart SDK">
<CLASSES>
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/async" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/collection" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/convert" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/core" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/developer" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/html" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/indexed_db" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/io" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/isolate" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/js" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/js_util" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/math" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/mirrors" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/svg" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/typed_data" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/web_audio" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/web_gl" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/web_sql" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

View File

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/hello_world.iml" filepath="$PROJECT_DIR$/hello_world.iml" />
</modules>
</component>
</project>

View File

@ -1,6 +0,0 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="main.dart" type="FlutterRunConfigurationType" factoryName="Flutter">
<option name="filePath" value="$PROJECT_DIR$/lib/main.dart" />
<method />
</configuration>
</component>

View File

@ -1,26 +0,0 @@
<component name="libraryTable">
<library name="Dart SDK">
<CLASSES>
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/async" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/collection" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/convert" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/core" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/developer" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/html" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/indexed_db" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/io" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/isolate" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/js" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/js_util" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/math" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/mirrors" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/svg" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/typed_data" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/web_audio" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/web_gl" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/web_sql" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

View File

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/layers.iml" filepath="$PROJECT_DIR$/layers.iml" />
</modules>
</component>
</project>

View File

@ -1,26 +0,0 @@
<component name="libraryTable">
<library name="Dart SDK">
<CLASSES>
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/async" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/collection" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/convert" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/core" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/developer" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/html" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/indexed_db" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/io" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/isolate" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/js" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/js_util" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/math" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/mirrors" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/svg" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/typed_data" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/web_audio" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/web_gl" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/web_sql" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

View File

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/platform_channel.iml" filepath="$PROJECT_DIR$/platform_channel.iml" />
</modules>
</component>
</project>

View File

@ -1,6 +0,0 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="main.dart" type="FlutterRunConfigurationType" factoryName="Flutter">
<option name="filePath" value="$PROJECT_DIR$/lib/main.dart" />
<method />
</configuration>
</component>

View File

@ -1,26 +0,0 @@
<component name="libraryTable">
<library name="Dart SDK">
<CLASSES>
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/async" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/collection" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/convert" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/core" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/developer" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/html" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/indexed_db" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/io" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/isolate" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/js" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/js_util" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/math" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/mirrors" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/svg" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/typed_data" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/web_audio" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/web_gl" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/web_sql" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

View File

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/platform_channel_swift.iml" filepath="$PROJECT_DIR$/platform_channel_swift.iml" />
</modules>
</component>
</project>

View File

@ -1,6 +0,0 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="main.dart" type="FlutterRunConfigurationType" factoryName="Flutter">
<option name="filePath" value="$PROJECT_DIR$/lib/main.dart" />
<method />
</configuration>
</component>

View File

@ -1,15 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.idea" />
<excludeFolder url="file://$MODULE_DIR$/.pub" />
<excludeFolder url="file://$MODULE_DIR$/build" />
<excludeFolder url="file://$MODULE_DIR$/packages" />
</content>
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Dart Packages" level="project" />
<orderEntry type="library" name="Dart SDK" level="project" />
</component>
</module>

View File

@ -1,26 +0,0 @@
<component name="libraryTable">
<library name="Dart SDK">
<CLASSES>
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/async" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/collection" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/convert" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/core" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/developer" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/html" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/indexed_db" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/io" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/isolate" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/js" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/js_util" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/math" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/mirrors" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/svg" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/typed_data" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/web_audio" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/web_gl" />
<root url="file://$PROJECT_DIR$/../../bin/cache/dart-sdk/lib/web_sql" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

View File

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/stocks.iml" filepath="$PROJECT_DIR$/.idea/stocks.iml" />
</modules>
</component>
</project>

View File

@ -1,6 +0,0 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="main.dart" type="FlutterRunConfigurationType" factoryName="Flutter">
<option name="filePath" value="$PROJECT_DIR$/lib/main.dart" />
<method />
</configuration>
</component>

View File

@ -1,15 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.idea" />
<excludeFolder url="file://$MODULE_DIR$/.pub" />
<excludeFolder url="file://$MODULE_DIR$/build" />
<excludeFolder url="file://$MODULE_DIR$/packages" />
</content>
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Dart Packages" level="project" />
<orderEntry type="library" name="Dart SDK" level="project" />
</component>
</module>

View File

@ -2,7 +2,10 @@
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/examples/platform_view/android.iml" filepath="$PROJECT_DIR$/examples/platform_view/android.iml" />
<module fileurl="file://$PROJECT_DIR$/dev/bots/bots.iml" filepath="$PROJECT_DIR$/dev/bots/bots.iml" />
<module fileurl="file://$PROJECT_DIR$/examples/catalog/catalog.iml" filepath="$PROJECT_DIR$/examples/catalog/catalog.iml" />
<module fileurl="file://$PROJECT_DIR$/dev/benchmarks/complex_layout/complex_layout.iml" filepath="$PROJECT_DIR$/dev/benchmarks/complex_layout/complex_layout.iml" />
<module fileurl="file://$PROJECT_DIR$/dev/devicelab/devicelab.iml" filepath="$PROJECT_DIR$/dev/devicelab/devicelab.iml" />
<module fileurl="file://$PROJECT_DIR$/packages/flutter/flutter.iml" filepath="$PROJECT_DIR$/packages/flutter/flutter.iml" />
<module fileurl="file://$PROJECT_DIR$/packages/flutter_driver/flutter_driver.iml" filepath="$PROJECT_DIR$/packages/flutter_driver/flutter_driver.iml" />
@ -10,7 +13,14 @@
<module fileurl="file://$PROJECT_DIR$/packages/flutter_localizations/flutter_localizations.iml" filepath="$PROJECT_DIR$/packages/flutter_localizations/flutter_localizations.iml" />
<module fileurl="file://$PROJECT_DIR$/packages/flutter_test/flutter_test.iml" filepath="$PROJECT_DIR$/packages/flutter_test/flutter_test.iml" />
<module fileurl="file://$PROJECT_DIR$/packages/flutter_tools/flutter_tools.iml" filepath="$PROJECT_DIR$/packages/flutter_tools/flutter_tools.iml" />
<module fileurl="file://$PROJECT_DIR$/examples/flutter_view/flutter_view.iml" filepath="$PROJECT_DIR$/examples/flutter_view/flutter_view.iml" />
<module fileurl="file://$PROJECT_DIR$/examples/platform_view/full_platform_view.iml" filepath="$PROJECT_DIR$/examples/platform_view/full_platform_view.iml" />
<module fileurl="file://$PROJECT_DIR$/examples/hello_world/hello_world.iml" filepath="$PROJECT_DIR$/examples/hello_world/hello_world.iml" />
<module fileurl="file://$PROJECT_DIR$/examples/layers/layers.iml" filepath="$PROJECT_DIR$/examples/layers/layers.iml" />
<module fileurl="file://$PROJECT_DIR$/dev/manual_tests/manual_tests.iml" filepath="$PROJECT_DIR$/dev/manual_tests/manual_tests.iml" />
<module fileurl="file://$PROJECT_DIR$/examples/platform_channel/platform_channel.iml" filepath="$PROJECT_DIR$/examples/platform_channel/platform_channel.iml" />
<module fileurl="file://$PROJECT_DIR$/examples/platform_channel_swift/platform_channel_swift.iml" filepath="$PROJECT_DIR$/examples/platform_channel_swift/platform_channel_swift.iml" />
<module fileurl="file://$PROJECT_DIR$/examples/stocks/stocks.iml" filepath="$PROJECT_DIR$/examples/stocks/stocks.iml" />
<module fileurl="file://$PROJECT_DIR$/dev/tools/tools.iml" filepath="$PROJECT_DIR$/dev/tools/tools.iml" />
</modules>
</component>

View File

@ -0,0 +1,6 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="benchmarks - complex_layout" type="FlutterRunConfigurationType" factoryName="Flutter">
<option name="filePath" value="$PROJECT_DIR$/dev/benchmarks/complex_layout/lib/main.dart" />
<method />
</configuration>
</component>

View File

@ -0,0 +1,6 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="catalog" type="FlutterRunConfigurationType" factoryName="Flutter">
<option name="filePath" value="$PROJECT_DIR$/examples/catalog/lib/main.dart" />
<method />
</configuration>
</component>

View File

@ -0,0 +1,6 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="flutter_view" type="FlutterRunConfigurationType" factoryName="Flutter">
<option name="filePath" value="$PROJECT_DIR$/examples/flutter_view/lib/main.dart" />
<method />
</configuration>
</component>

View File

@ -0,0 +1,6 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="layers - custom_render_box" type="FlutterRunConfigurationType" factoryName="Flutter">
<option name="filePath" value="$PROJECT_DIR$/examples/layers/widgets/custom_render_box.dart" />
<method />
</configuration>
</component>

View File

@ -0,0 +1,6 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="layers - gestures" type="FlutterRunConfigurationType" factoryName="Flutter">
<option name="filePath" value="$PROJECT_DIR$/examples/layers/widgets/gestures.dart" />
<method />
</configuration>
</component>

View File

@ -0,0 +1,6 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="layers - hello_world" type="FlutterRunConfigurationType" factoryName="Flutter">
<option name="filePath" value="$PROJECT_DIR$/examples/layers/widgets/hello_world.dart" />
<method />
</configuration>
</component>

View File

@ -0,0 +1,6 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="layers - isolate" type="FlutterRunConfigurationType" factoryName="Flutter">
<option name="filePath" value="$PROJECT_DIR$/examples/layers/services/isolate.dart" />
<method />
</configuration>
</component>

View File

@ -0,0 +1,6 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="layers - lifecycle" type="FlutterRunConfigurationType" factoryName="Flutter">
<option name="filePath" value="$PROJECT_DIR$/examples/layers/services/lifecycle.dart" />
<method />
</configuration>
</component>

View File

@ -0,0 +1,6 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="layers - sectors" type="FlutterRunConfigurationType" factoryName="Flutter">
<option name="filePath" value="$PROJECT_DIR$/examples/layers/widgets/sectors.dart" />
<method />
</configuration>
</component>

View File

@ -0,0 +1,6 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="layers - spinning_square" type="FlutterRunConfigurationType" factoryName="Flutter">
<option name="filePath" value="$PROJECT_DIR$/examples/layers/widgets/spinning_square.dart" />
<method />
</configuration>
</component>

View File

@ -0,0 +1,6 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="layers - styled_text" type="FlutterRunConfigurationType" factoryName="Flutter">
<option name="filePath" value="$PROJECT_DIR$/examples/layers/widgets/styled_text.dart" />
<method />
</configuration>
</component>

View File

@ -0,0 +1,6 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="manual_tests - card_collection" type="FlutterRunConfigurationType" factoryName="Flutter">
<option name="filePath" value="$PROJECT_DIR$/dev/manual_tests/lib/card_collection.dart" />
<method />
</configuration>
</component>

View File

@ -0,0 +1,6 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="manual_tests - color_testing_demo" type="FlutterRunConfigurationType" factoryName="Flutter">
<option name="filePath" value="$PROJECT_DIR$/dev/manual_tests/lib/color_testing_demo.dart" />
<method />
</configuration>
</component>

View File

@ -0,0 +1,6 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="manual_tests - drag_and_drop" type="FlutterRunConfigurationType" factoryName="Flutter">
<option name="filePath" value="$PROJECT_DIR$/dev/manual_tests/lib/drag_and_drop.dart" />
<method />
</configuration>
</component>

View File

@ -0,0 +1,6 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="manual_tests - material_arc" type="FlutterRunConfigurationType" factoryName="Flutter">
<option name="filePath" value="$PROJECT_DIR$/dev/manual_tests/lib/material_arc.dart" />
<method />
</configuration>
</component>

View File

@ -0,0 +1,6 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="manual_tests - overlay_geometry" type="FlutterRunConfigurationType" factoryName="Flutter">
<option name="filePath" value="$PROJECT_DIR$/dev/manual_tests/lib/overlay_geometry.dart" />
<method />
</configuration>
</component>

View File

@ -0,0 +1,6 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="manual_tests - page_view" type="FlutterRunConfigurationType" factoryName="Flutter">
<option name="filePath" value="$PROJECT_DIR$/dev/manual_tests/lib/page_view.dart" />
<method />
</configuration>
</component>

View File

@ -0,0 +1,6 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="manual_tests - raw_keyboard" type="FlutterRunConfigurationType" factoryName="Flutter">
<option name="filePath" value="$PROJECT_DIR$/dev/manual_tests/lib/raw_keyboard.dart" />
<method />
</configuration>
</component>

View File

@ -0,0 +1,6 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="manual_tests - text" type="FlutterRunConfigurationType" factoryName="Flutter">
<option name="filePath" value="$PROJECT_DIR$/dev/manual_tests/lib/text.dart" />
<method />
</configuration>
</component>

View File

@ -0,0 +1,6 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="plaform_view" type="FlutterRunConfigurationType" factoryName="Flutter">
<option name="filePath" value="$PROJECT_DIR$/examples/platform_view/lib/main.dart" />
<method />
</configuration>
</component>

View File

@ -0,0 +1,6 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="platform_channel" type="FlutterRunConfigurationType" factoryName="Flutter">
<option name="filePath" value="$PROJECT_DIR$/examples/platform_channel/lib/main.dart" />
<method />
</configuration>
</component>

View File

@ -0,0 +1,6 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="platform_channel_swift" type="FlutterRunConfigurationType" factoryName="Flutter">
<option name="filePath" value="$PROJECT_DIR$/examples/platform_channel_swift/lib/main.dart" />
<method />
</configuration>
</component>

View File

@ -0,0 +1,6 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="stocks" type="FlutterRunConfigurationType" factoryName="Flutter">
<option name="filePath" value="$PROJECT_DIR$/examples/stocks/lib/main.dart" />
<method />
</configuration>
</component>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.idea" />
<excludeFolder url="file://$MODULE_DIR$/.pub" />
<excludeFolder url="file://$MODULE_DIR$/build" />
</content>
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Dart SDK" level="project" />
<orderEntry type="library" name="Dart Packages" level="project" />
<orderEntry type="library" name="Flutter Plugins" level="project" />
</component>
</module>

View File

@ -13,4 +13,4 @@
<orderEntry type="library" name="Dart SDK" level="project" />
<orderEntry type="library" name="Dart Packages" level="project" />
</component>
</module>
</module>

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.idea" />
<excludeFolder url="file://$MODULE_DIR$/.pub" />
<excludeFolder url="file://$MODULE_DIR$/bin/packages" />
<excludeFolder url="file://$MODULE_DIR$/build" />
<excludeFolder url="file://$MODULE_DIR$/packages" />
<excludeFolder url="file://$MODULE_DIR$/test/packages" />
</content>
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Dart SDK" level="project" />
<orderEntry type="library" name="Dart Packages" level="project" />
<orderEntry type="library" name="Flutter Plugins" level="project" />
</component>
</module>

View File

@ -12,4 +12,4 @@
<orderEntry type="library" name="Dart SDK" level="project" />
<orderEntry type="library" name="Dart Packages" level="project" />
</component>
</module>
</module>

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.idea" />
<excludeFolder url="file://$MODULE_DIR$/.pub" />
<excludeFolder url="file://$MODULE_DIR$/build" />
<excludeFolder url="file://$MODULE_DIR$/packages" />
<excludeFolder url="file://$MODULE_DIR$/test/packages" />
<excludeFolder url="file://$MODULE_DIR$/test/smoketests/lib/packages" />
<excludeFolder url="file://$MODULE_DIR$/test/smoketests/packages" />
<excludeFolder url="file://$MODULE_DIR$/test/smoketests/raw/packages" />
<excludeFolder url="file://$MODULE_DIR$/test/smoketests/rendering/packages" />
<excludeFolder url="file://$MODULE_DIR$/test/smoketests/services/packages" />
<excludeFolder url="file://$MODULE_DIR$/test/smoketests/widgets/packages" />
</content>
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Dart SDK" level="project" />
<orderEntry type="library" name="Dart Packages" level="project" />
</component>
</module>

View File

@ -6,10 +6,9 @@
<excludeFolder url="file://$MODULE_DIR$/.idea" />
<excludeFolder url="file://$MODULE_DIR$/.pub" />
<excludeFolder url="file://$MODULE_DIR$/build" />
<excludeFolder url="file://$MODULE_DIR$/packages" />
</content>
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Dart Packages" level="project" />
<orderEntry type="library" name="Dart SDK" level="project" />
<orderEntry type="library" name="Dart Packages" level="project" />
</component>
</module>
</module>

View File

@ -6,10 +6,9 @@
<excludeFolder url="file://$MODULE_DIR$/.idea" />
<excludeFolder url="file://$MODULE_DIR$/.pub" />
<excludeFolder url="file://$MODULE_DIR$/build" />
<excludeFolder url="file://$MODULE_DIR$/packages" />
</content>
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Dart Packages" level="project" />
<orderEntry type="library" name="Dart SDK" level="project" />
<orderEntry type="library" name="Dart Packages" level="project" />
</component>
</module>
</module>

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.idea" />
<excludeFolder url="file://$MODULE_DIR$/.pub" />
<excludeFolder url="file://$MODULE_DIR$/build" />
</content>
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Dart SDK" level="project" />
<orderEntry type="library" name="Dart Packages" level="project" />
</component>
</module>

View File

@ -7,9 +7,10 @@
<excludeFolder url="file://$MODULE_DIR$/.pub" />
<excludeFolder url="file://$MODULE_DIR$/build" />
<excludeFolder url="file://$MODULE_DIR$/packages" />
<excludeFolder url="file://$MODULE_DIR$/test/packages" />
</content>
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Dart Packages" level="project" />
<orderEntry type="library" name="Dart SDK" level="project" />
<orderEntry type="library" name="Dart Packages" level="project" />
</component>
</module>
</module>

View File

@ -22,7 +22,7 @@
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Dart Packages" level="project" />
<orderEntry type="library" name="Dart SDK" level="project" />
<orderEntry type="library" name="Dart Packages" level="project" />
</component>
</module>

View File

@ -17,6 +17,7 @@ import 'src/commands/doctor.dart';
import 'src/commands/drive.dart';
import 'src/commands/format.dart';
import 'src/commands/fuchsia_reload.dart';
import 'src/commands/ide_config.dart';
import 'src/commands/install.dart';
import 'src/commands/logs.dart';
import 'src/commands/packages.dart';
@ -52,6 +53,7 @@ Future<Null> main(List<String> args) async {
new DriveCommand(),
new FormatCommand(),
new FuchsiaReloadCommand(),
new IdeConfigCommand(hidden: !verboseHelp),
new InstallCommand(),
new LogsCommand(),
new PackagesCommand(),

View File

@ -0,0 +1,273 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import '../base/common.dart';
import '../base/file_system.dart';
import '../cache.dart';
import '../globals.dart';
import '../runner/flutter_command.dart';
import '../template.dart';
class IdeConfigCommand extends FlutterCommand {
IdeConfigCommand({this.hidden: false}) {
argParser.addFlag(
'overwrite',
negatable: true,
defaultsTo: false,
help: 'When performing operations, overwrite existing files.',
);
argParser.addFlag(
'update-templates',
negatable: false,
help: 'Update the templates in the template directory from the current '
'configuration files. This is the opposite of what $name usually does. '
'Will search the flutter tree for .iml files and copy any missing ones '
'into the template directory. If --overwrite is also specified, it will '
'update any out-of-date files, and remove any deleted files from the '
'template directory.',
);
}
@override
final String name = 'ide-config';
@override
final String description = 'Configure the IDE for use in the Flutter tree.\n\n'
'If run on a Flutter tree that is already configured for the IDE, this '
'command will add any new configurations, recreate any files that are '
'missing. If --overwrite is specified, will revert existing files to '
'the template versions, reset the module list, and return configuration '
'settings to the template versions.\n\n'
'This command is intended for Flutter developers to help them set up the'
"Flutter tree for development in an IDE. It doesn't affect other projects.\n\n"
'Currently, IntelliJ is the default (and only) IDE that may be configured.';
@override
final bool hidden;
@override
String get invocation => '${runner.executableName} $name';
static const String _ideName = 'intellij';
Directory get _templateDirectory {
return fs.directory(fs.path.join(
Cache.flutterRoot,
'packages',
'flutter_tools',
'ide_templates',
_ideName,
));
}
Directory get _createTemplatesDirectory {
return fs.directory(fs.path.join(
Cache.flutterRoot,
'packages',
'flutter_tools',
'templates',
));
}
Directory get _flutterRoot => fs.directory(fs.path.absolute(Cache.flutterRoot));
// Returns true if any entire path element is equal to dir.
bool _hasDirectoryInPath(FileSystemEntity entity, String dir) {
String path = entity.absolute.path;
while (path.isNotEmpty && fs.path.dirname(path) != path) {
if (fs.path.basename(path) == dir) {
return true;
}
path = fs.path.dirname(path);
}
return false;
}
// Returns true if child is anywhere underneath parent.
bool _isChildDirectoryOf(FileSystemEntity parent, FileSystemEntity child) {
return child.absolute.path.startsWith(parent.absolute.path);
}
// Checks the contents of the two files to see if they have changes.
bool _fileIsIdentical(File src, File dest) {
if (src.lengthSync() != dest.lengthSync()) {
return false;
}
// Test byte by byte. We're assuming that these are small files.
final List<int> srcBytes = src.readAsBytesSync();
final List<int> destBytes = dest.readAsBytesSync();
for (int i = 0; i < srcBytes.length; ++i) {
if (srcBytes[i] != destBytes[i]) {
return false;
}
}
return true;
}
// Discovers and syncs with existing configuration files in the Flutter tree.
void _handleTemplateUpdate() {
if (!_flutterRoot.existsSync()) {
return;
}
final Set<String> manifest = new Set<String>();
final List<FileSystemEntity> flutterFiles = _flutterRoot.listSync(recursive: true);
for (FileSystemEntity entity in flutterFiles) {
final String relativePath = fs.path.relative(entity.path, from: _flutterRoot.absolute.path);
if (entity is! File) {
continue;
}
final File srcFile = entity;
// Skip template files in both the ide_templates and templates
// directories to avoid copying onto themselves.
if (_isChildDirectoryOf(_templateDirectory, srcFile) ||
_isChildDirectoryOf(_createTemplatesDirectory, srcFile)) {
continue;
}
// Skip files we aren't interested in.
final RegExp _trackedIdeaFileRegExp = new RegExp(
r'(\.name|modules.xml|vcs.xml)$',
);
final bool isATrackedIdeaFile = _hasDirectoryInPath(srcFile, '.idea') &&
(_trackedIdeaFileRegExp.hasMatch(relativePath) ||
_hasDirectoryInPath(srcFile, 'runConfigurations'));
final bool isAnImlOutsideIdea = !isATrackedIdeaFile && srcFile.path.endsWith('.iml');
if (!isATrackedIdeaFile && !isAnImlOutsideIdea) {
continue;
}
final File finalDestinationFile = fs.file(fs.path.absolute(
_templateDirectory.absolute.path, '$relativePath${Template.copyTemplateExtension}'));
final String relativeDestination =
fs.path.relative(finalDestinationFile.path, from: _flutterRoot.absolute.path);
if (finalDestinationFile.existsSync()) {
if (_fileIsIdentical(srcFile, finalDestinationFile)) {
printTrace(' $relativeDestination (identical)');
manifest.add('$relativePath${Template.copyTemplateExtension}');
continue;
}
if (argResults['overwrite']) {
finalDestinationFile.deleteSync();
printStatus(' $relativeDestination (overwritten)');
} else {
printTrace(' $relativeDestination (existing - skipped)');
manifest.add('$relativePath${Template.copyTemplateExtension}');
continue;
}
} else {
printStatus(' $relativeDestination (added)');
}
final Directory finalDestinationDir = fs.directory(finalDestinationFile.dirname);
if (!finalDestinationDir.existsSync()) {
printTrace(" ${finalDestinationDir.path} doesn't exist, creating.");
finalDestinationDir.createSync(recursive: true);
}
srcFile.copySync(finalDestinationFile.path);
manifest.add('$relativePath${Template.copyTemplateExtension}');
}
// If we're not overwriting, then we're not going to remove missing items either.
if (!argResults['overwrite']) {
return;
}
// Look for any files under the template dir that don't exist in the manifest and remove
// them.
final List<FileSystemEntity> templateFiles = _templateDirectory.listSync(recursive: true);
for (FileSystemEntity entity in templateFiles) {
if (entity is! File) {
continue;
}
final File templateFile = entity;
final String relativePath = fs.path.relative(
templateFile.absolute.path,
from: _templateDirectory.absolute.path,
);
if (!manifest.contains(relativePath)) {
templateFile.deleteSync();
final String relativeDestination =
fs.path.relative(templateFile.path, from: _flutterRoot.absolute.path);
printStatus(' $relativeDestination (removed)');
}
// If the directory is now empty, then remove it, and do the same for its parent,
// until we escape to the template directory.
Directory parentDir = fs.directory(templateFile.dirname);
while (parentDir.listSync().isEmpty) {
parentDir.deleteSync();
printTrace(' ${fs.path.relative(parentDir.absolute.path)} (empty directory - removed)');
parentDir = fs.directory(parentDir.dirname);
if (fs.path.isWithin(_templateDirectory.absolute.path, parentDir.absolute.path)) {
break;
}
}
}
}
@override
Future<Null> runCommand() async {
if (argResults.rest.isNotEmpty) {
throwToolExit('Currently, the only supported IDE is IntelliJ\n$usage', exitCode: 2);
}
await Cache.instance.updateAll();
if (argResults['update-templates']) {
_handleTemplateUpdate();
return;
}
final String flutterRoot = fs.path.absolute(Cache.flutterRoot);
String dirPath = fs.path.normalize(
fs.directory(fs.path.absolute(Cache.flutterRoot)).absolute.path,
);
// TODO(goderbauer): Work-around for: https://github.com/dart-lang/path/issues/24
if (fs.path.basename(dirPath) == '.') {
dirPath = fs.path.dirname(dirPath);
}
final String error = _validateFlutterDir(dirPath, flutterRoot: flutterRoot);
if (error != null) {
throwToolExit(error);
}
printStatus('Updating IDE configuration for Flutter tree at $dirPath...');
int generatedCount = 0;
generatedCount += _renderTemplate(_ideName, dirPath, <String, dynamic>{});
printStatus('Wrote $generatedCount files.');
printStatus('');
printStatus('Your IntelliJ configuration is now up to date. It is prudent to '
'restart IntelliJ, if running.');
}
int _renderTemplate(String templateName, String dirPath, Map<String, dynamic> context) {
final Template template = new Template(_templateDirectory, _templateDirectory);
return template.render(
fs.directory(dirPath),
context,
overwriteExisting: argResults['overwrite'],
);
}
}
/// Return null if the flutter root directory is a valid destination. Return a
/// validation message if we should disallow the directory.
String _validateFlutterDir(String dirPath, {String flutterRoot}) {
final FileSystemEntityType type = fs.typeSync(dirPath);
if (type != FileSystemEntityType.NOT_FOUND) {
switch (type) {
case FileSystemEntityType.LINK:
// Do not overwrite links.
return "Invalid project root dir: '$dirPath' - refers to a link.";
}
}
return null;
}

View File

@ -8,10 +8,6 @@ import 'base/file_system.dart';
import 'cache.dart';
import 'globals.dart';
const String _kTemplateExtension = '.tmpl';
const String _kCopyTemplateExtension = '.copy.tmpl';
final Pattern _kTemplateLanguageVariant = new RegExp(r'(\w+)-(\w+)\.tmpl.*');
/// Expands templates in a directory to a destination. All files that must
/// undergo template expansion should end with the '.tmpl' extension. All other
/// files are ignored. In case the contents of entire directories must be copied
@ -45,7 +41,7 @@ class Template {
final String relativePath = fs.path.relative(entity.path,
from: baseDir.absolute.path);
if (relativePath.contains(_kTemplateExtension)) {
if (relativePath.contains(templateExtension)) {
// If '.tmpl' appears anywhere within the path of this entity, it is
// is a candidate for rendering. This catches cases where the folder
// itself is a template.
@ -56,10 +52,14 @@ class Template {
factory Template.fromName(String name) {
// All named templates are placed in the 'templates' directory
final Directory templateDir = _templateDirectoryInPackage(name);
final Directory templateDir = templateDirectoryInPackage(name);
return new Template(templateDir, templateDir);
}
static const String templateExtension = '.tmpl';
static const String copyTemplateExtension = '.copy.tmpl';
final Pattern _kTemplateLanguageVariant = new RegExp(r'(\w+)-(\w+)\.tmpl.*');
Map<String /* relative */, String /* absolute source */> _templateFilePaths;
int render(
@ -91,8 +91,8 @@ class Template {
final String pathSeparator = fs.path.separator;
String finalDestinationPath = fs.path
.join(destinationDirPath, relativeDestinationPath)
.replaceAll(_kCopyTemplateExtension, '')
.replaceAll(_kTemplateExtension, '');
.replaceAll(copyTemplateExtension, '')
.replaceAll(templateExtension, '');
if (androidIdentifier != null) {
finalDestinationPath = finalDestinationPath
@ -116,7 +116,7 @@ class Template {
if (finalDestinationFile.existsSync()) {
if (overwriteExisting) {
finalDestinationFile.delete(recursive: true);
finalDestinationFile.deleteSync(recursive: true);
printStatus(' $relativePathForLogging (overwritten)');
} else {
// The file exists but we cannot overwrite it, move on.
@ -124,7 +124,7 @@ class Template {
return;
}
} else {
printTrace(' $relativePathForLogging');
printStatus(' $relativePathForLogging (created)');
}
fileCount++;
@ -132,11 +132,11 @@ class Template {
finalDestinationFile.createSync(recursive: true);
final File sourceFile = fs.file(absoluteSourcePath);
// Step 2: If the absolute paths ends with a 'copy.tmpl', this file does
// Step 2: If the absolute paths ends with a '.copy.tmpl', this file does
// not need mustache rendering but needs to be directly copied.
if (sourceFile.path.endsWith(_kCopyTemplateExtension)) {
finalDestinationFile.writeAsBytesSync(sourceFile.readAsBytesSync());
if (sourceFile.path.endsWith(copyTemplateExtension)) {
sourceFile.copySync(finalDestinationFile.path);
return;
}
@ -144,7 +144,7 @@ class Template {
// Step 3: If the absolute path ends with a '.tmpl', this file needs
// rendering via mustache.
if (sourceFile.path.endsWith(_kTemplateExtension)) {
if (sourceFile.path.endsWith(templateExtension)) {
final String templateContents = sourceFile.readAsStringSync();
final String renderedContents = new mustache.Template(templateContents).renderString(context);
@ -163,7 +163,7 @@ class Template {
}
}
Directory _templateDirectoryInPackage(String name) {
Directory templateDirectoryInPackage(String name) {
final String templatesDir = fs.path.join(Cache.flutterRoot,
'packages', 'flutter_tools', 'templates');
return fs.directory(fs.path.join(templatesDir, name));

View File

@ -0,0 +1,311 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import 'package:args/command_runner.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/template.dart';
import 'package:flutter_tools/src/commands/ide_config.dart';
import 'package:test/test.dart';
import '../src/common.dart';
import '../src/context.dart';
void main() {
group('ide_config', () {
Directory temp;
Directory templateDir;
Directory intellijDir;
Directory toolsDir;
Map<String, String> _getFilesystemContents([Directory root]) {
final String tempPath = temp.absolute.path;
final List<String> paths =
(root ?? temp).listSync(recursive: true).map((FileSystemEntity entity) {
final String relativePath = fs.path.relative(entity.path, from: tempPath);
return relativePath;
}).toList();
final Map<String, String> contents = <String, String>{};
for (String path in paths) {
final String absPath = fs.path.join(tempPath, path);
if (fs.isDirectorySync(absPath)) {
contents[path] = 'dir';
} else if (fs.isFileSync(absPath)) {
contents[path] = fs.file(absPath).readAsStringSync();
}
}
return contents;
}
Map<String, String> _getManifest(Directory base, String marker, {bool isTemplate: false}) {
final String basePath = fs.path.relative(base.path, from: temp.absolute.path);
final String suffix = isTemplate ? Template.copyTemplateExtension : '';
return <String, String>{
fs.path.join(basePath, '.idea'): 'dir',
fs.path.join(basePath, '.idea', 'modules.xml$suffix'): 'modules $marker',
fs.path.join(basePath, '.idea', 'vcs.xml$suffix'): 'vcs $marker',
fs.path.join(basePath, '.idea', '.name$suffix'):
'codeStyleSettings $marker',
fs.path.join(basePath, '.idea', 'runConfigurations'): 'dir',
fs.path.join(basePath, '.idea', 'runConfigurations', 'hello_world.xml$suffix'):
'hello_world $marker',
fs.path.join(basePath, 'flutter.iml$suffix'): 'flutter $marker',
fs.path.join(basePath, 'packages', 'new', 'deep.iml$suffix'): 'deep $marker',
};
}
void _populateDir(Map<String, String> manifest) {
for (String key in manifest.keys) {
if (manifest[key] == 'dir') {
temp.childDirectory(key)..createSync(recursive: true);
}
}
for (String key in manifest.keys) {
if (manifest[key] != 'dir') {
temp.childFile(key)
..createSync(recursive: true)
..writeAsStringSync(manifest[key]);
}
}
}
bool _fileOrDirectoryExists(String path) {
final String absPath = fs.path.join(temp.absolute.path, path);
return fs.file(absPath).existsSync() || fs.directory(absPath).existsSync();
}
Future<Null> _updateIdeConfig({
Directory dir,
List<String> args = const <String>[],
Map<String, String> expectedContents = const <String, String>{},
List<String> unexpectedPaths = const <String>[],
}) async {
dir ??= temp;
final IdeConfigCommand command = new IdeConfigCommand();
final CommandRunner<Null> runner = createTestCommandRunner(command);
final List<String> finalArgs = <String>['--flutter-root=${temp.absolute.path}', 'ide-config'];
finalArgs.addAll(args);
await runner.run(finalArgs);
for (String path in expectedContents.keys) {
final String absPath = fs.path.join(temp.absolute.path, path);
expect(_fileOrDirectoryExists(fs.path.join(dir.path, path)), true,
reason: "$path doesn't exist");
if (fs.file(absPath).existsSync()) {
expect(fs.file(absPath).readAsStringSync(), equals(expectedContents[path]),
reason: "$path contents don't match");
}
}
for (String path in unexpectedPaths) {
expect(_fileOrDirectoryExists(fs.path.join(dir.path, path)), false, reason: '$path exists');
}
}
setUpAll(() {
Cache.disableLocking();
});
setUp(() {
temp = fs.systemTempDirectory.createTempSync('flutter_tools_');
final Directory packagesDir = temp.childDirectory('packages')..createSync(recursive: true);
toolsDir = packagesDir.childDirectory('flutter_tools')..createSync();
templateDir = toolsDir.childDirectory('ide_templates')..createSync();
intellijDir = templateDir.childDirectory('intellij')..createSync();
});
tearDown(() {
temp.deleteSync(recursive: true);
});
testUsingContext("doesn't touch existing files without --overwrite", () async {
final Map<String, String> templateManifest = _getManifest(
intellijDir,
'template',
isTemplate: true,
);
final Map<String, String> flutterManifest = _getManifest(
temp,
'existing',
);
_populateDir(templateManifest);
_populateDir(flutterManifest);
final Map<String, String> expectedContents = _getFilesystemContents();
return _updateIdeConfig(
expectedContents: expectedContents,
);
}, timeout: const Timeout.factor(2.0));
testUsingContext('creates non-existent files', () async {
final Map<String, String> templateManifest = _getManifest(
intellijDir,
'template',
isTemplate: true,
);
final Map<String, String> flutterManifest = _getManifest(
temp,
'template',
);
_populateDir(templateManifest);
final Map<String, String> expectedContents = templateManifest;
expectedContents.addAll(flutterManifest);
return _updateIdeConfig(
expectedContents: expectedContents,
);
}, timeout: const Timeout.factor(2.0));
testUsingContext('overwrites existing files with --overwrite', () async {
final Map<String, String> templateManifest = _getManifest(
intellijDir,
'template',
isTemplate: true,
);
final Map<String, String> flutterManifest = _getManifest(
temp,
'existing',
);
_populateDir(templateManifest);
_populateDir(flutterManifest);
final Map<String, String> overwrittenManifest = _getManifest(
temp,
'template',
);
final Map<String, String> expectedContents = templateManifest;
expectedContents.addAll(overwrittenManifest);
return _updateIdeConfig(
args: <String>['--overwrite'],
expectedContents: expectedContents,
);
}, timeout: const Timeout.factor(2.0));
testUsingContext('only adds new templates without --overwrite', () async {
final Map<String, String> templateManifest = _getManifest(
intellijDir,
'template',
isTemplate: true,
);
final String flutterIml = fs.path.join(
'packages',
'flutter_tools',
'ide_templates',
'intellij',
'flutter.iml${Template.copyTemplateExtension}',
);
templateManifest.remove(flutterIml);
_populateDir(templateManifest);
templateManifest[flutterIml] = 'flutter existing';
final Map<String, String> flutterManifest = _getManifest(
temp,
'existing',
);
_populateDir(flutterManifest);
final Map<String, String> expectedContents = flutterManifest;
expectedContents.addAll(templateManifest);
return _updateIdeConfig(
args: <String>['--update-templates'],
expectedContents: expectedContents,
);
}, timeout: const Timeout.factor(2.0));
testUsingContext('update all templates with --overwrite', () async {
final Map<String, String> templateManifest = _getManifest(
intellijDir,
'template',
isTemplate: true,
);
_populateDir(templateManifest);
final Map<String, String> flutterManifest = _getManifest(
temp,
'existing',
);
_populateDir(flutterManifest);
final Map<String, String> updatedTemplates = _getManifest(
intellijDir,
'existing',
isTemplate: true,
);
final Map<String, String> expectedContents = flutterManifest;
expectedContents.addAll(updatedTemplates);
return _updateIdeConfig(
args: <String>['--update-templates', '--overwrite'],
expectedContents: expectedContents,
);
}, timeout: const Timeout.factor(2.0));
testUsingContext('removes delted imls with --overwrite', () async {
final Map<String, String> templateManifest = _getManifest(
intellijDir,
'template',
isTemplate: true,
);
_populateDir(templateManifest);
final Map<String, String> flutterManifest = _getManifest(
temp,
'existing',
);
flutterManifest.remove('flutter.iml');
_populateDir(flutterManifest);
final Map<String, String> updatedTemplates = _getManifest(
intellijDir,
'existing',
isTemplate: true,
);
final String flutterIml = fs.path.join(
'packages',
'flutter_tools',
'ide_templates',
'intellij',
'flutter.iml${Template.copyTemplateExtension}',
);
updatedTemplates.remove(flutterIml);
final Map<String, String> expectedContents = flutterManifest;
expectedContents.addAll(updatedTemplates);
return _updateIdeConfig(
args: <String>['--update-templates', '--overwrite'],
expectedContents: expectedContents,
);
}, timeout: const Timeout.factor(2.0));
testUsingContext('removes delted imls with --overwrite, including empty parent dirs', () async {
final Map<String, String> templateManifest = _getManifest(
intellijDir,
'template',
isTemplate: true,
);
_populateDir(templateManifest);
final Map<String, String> flutterManifest = _getManifest(
temp,
'existing',
);
flutterManifest.remove(fs.path.join('packages', 'new', 'deep.iml'));
_populateDir(flutterManifest);
final Map<String, String> updatedTemplates = _getManifest(
intellijDir,
'existing',
isTemplate: true,
);
String deepIml = fs.path.join(
'packages',
'flutter_tools',
'ide_templates',
'intellij');
// Remove the all the dir entries too.
updatedTemplates.remove(deepIml);
deepIml = fs.path.join(deepIml, 'packages');
updatedTemplates.remove(deepIml);
deepIml = fs.path.join(deepIml, 'new');
updatedTemplates.remove(deepIml);
deepIml = fs.path.join(deepIml, 'deep.iml');
updatedTemplates.remove(deepIml);
final Map<String, String> expectedContents = flutterManifest;
expectedContents.addAll(updatedTemplates);
return _updateIdeConfig(
args: <String>['--update-templates', '--overwrite'],
expectedContents: expectedContents,
);
}, timeout: const Timeout.factor(2.0));
});
}