am 4f842f00: am a7d5ca6b: Stop errors being logged erroneously on event predispatch

* commit '4f842f0072b0dc271a93f848d080aa01fcca0643':
  Stop errors being logged erroneously on event predispatch
diff --git a/ide/intellij/codestyles/AndroidStyle.xml b/ide/intellij/codestyles/AndroidStyle.xml
index cd6beb4..672c4e5 100644
--- a/ide/intellij/codestyles/AndroidStyle.xml
+++ b/ide/intellij/codestyles/AndroidStyle.xml
@@ -9,40 +9,49 @@
       <option name="SMART_TABS" value="false" />
       <option name="LABEL_INDENT_SIZE" value="0" />
       <option name="LABEL_INDENT_ABSOLUTE" value="false" />
+      <option name="USE_RELATIVE_INDENTS" value="false" />
     </value>
   </option>
-  <option name="KEEP_CONTROL_STATEMENT_IN_ONE_LINE" value="false" />
-  <option name="ALIGN_MULTILINE_PARAMETERS" value="false" />
-  <option name="ALIGN_MULTILINE_FOR" value="false" />
-  <option name="KEEP_BLANK_LINES_IN_CODE" value="1" />
-  <option name="BLANK_LINES_AROUND_FIELD" value="1" />
-  <option name="BLANK_LINES_AFTER_CLASS_HEADER" value="1" />
   <option name="FIELD_NAME_PREFIX" value="m" />
   <option name="STATIC_FIELD_NAME_PREFIX" value="m" />
-  <option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="99" />
-  <option name="NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND" value="99" />
+  <option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="9999" />
+  <option name="NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND" value="9999" />
   <option name="IMPORT_LAYOUT_TABLE">
     <value>
-      <package name="com.google" withSubpackages="true" />
+      <package name="com.google" withSubpackages="true" static="false" />
       <emptyLine />
-      <package name="com" withSubpackages="true" />
+      <package name="com" withSubpackages="true" static="false" />
       <emptyLine />
-      <package name="junit" withSubpackages="true" />
+      <package name="junit" withSubpackages="true" static="false" />
       <emptyLine />
-      <package name="net" withSubpackages="true" />
+      <package name="net" withSubpackages="true" static="false" />
       <emptyLine />
-      <package name="org" withSubpackages="true" />
+      <package name="org" withSubpackages="true" static="false" />
       <emptyLine />
-      <package name="android" withSubpackages="true" />
+      <package name="android" withSubpackages="true" static="false" />
       <emptyLine />
-      <package name="java" withSubpackages="true" />
+      <package name="java" withSubpackages="true" static="false" />
       <emptyLine />
-      <package name="javax" withSubpackages="true" />
+      <package name="javax" withSubpackages="true" static="false" />
       <emptyLine />
-      <package name="" withSubpackages="true" />
+      <package name="" withSubpackages="true" static="false" />
+      <emptyLine />
+      <package name="" withSubpackages="true" static="true" />
     </value>
   </option>
   <option name="RIGHT_MARGIN" value="100" />
+  <option name="JD_P_AT_EMPTY_LINES" value="false" />
+  <option name="JD_DO_NOT_WRAP_ONE_LINE_COMMENTS" value="true" />
+  <option name="JD_KEEP_EMPTY_PARAMETER" value="false" />
+  <option name="JD_KEEP_EMPTY_EXCEPTION" value="false" />
+  <option name="JD_KEEP_EMPTY_RETURN" value="false" />
+  <option name="JD_PRESERVE_LINE_FEEDS" value="true" />
+  <option name="KEEP_CONTROL_STATEMENT_IN_ONE_LINE" value="false" />
+  <option name="KEEP_BLANK_LINES_IN_CODE" value="1" />
+  <option name="BLANK_LINES_AROUND_FIELD" value="1" />
+  <option name="BLANK_LINES_AFTER_CLASS_HEADER" value="1" />
+  <option name="ALIGN_MULTILINE_PARAMETERS" value="false" />
+  <option name="ALIGN_MULTILINE_FOR" value="false" />
   <option name="CALL_PARAMETERS_WRAP" value="1" />
   <option name="METHOD_PARAMETERS_WRAP" value="1" />
   <option name="EXTENDS_LIST_WRAP" value="1" />
@@ -63,9 +72,104 @@
   <option name="DOWHILE_BRACE_FORCE" value="3" />
   <option name="WHILE_BRACE_FORCE" value="3" />
   <option name="FOR_BRACE_FORCE" value="3" />
-  <option name="JD_P_AT_EMPTY_LINES" value="false" />
-  <option name="JD_KEEP_EMPTY_PARAMETER" value="false" />
-  <option name="JD_KEEP_EMPTY_EXCEPTION" value="false" />
-  <option name="JD_KEEP_EMPTY_RETURN" value="false" />
+  <ADDITIONAL_INDENT_OPTIONS fileType="css">
+    <option name="INDENT_SIZE" value="4" />
+    <option name="CONTINUATION_INDENT_SIZE" value="8" />
+    <option name="TAB_SIZE" value="4" />
+    <option name="USE_TAB_CHARACTER" value="false" />
+    <option name="SMART_TABS" value="false" />
+    <option name="LABEL_INDENT_SIZE" value="0" />
+    <option name="LABEL_INDENT_ABSOLUTE" value="false" />
+    <option name="USE_RELATIVE_INDENTS" value="false" />
+  </ADDITIONAL_INDENT_OPTIONS>
+  <ADDITIONAL_INDENT_OPTIONS fileType="java">
+    <option name="INDENT_SIZE" value="4" />
+    <option name="CONTINUATION_INDENT_SIZE" value="8" />
+    <option name="TAB_SIZE" value="8" />
+    <option name="USE_TAB_CHARACTER" value="false" />
+    <option name="SMART_TABS" value="false" />
+    <option name="LABEL_INDENT_SIZE" value="0" />
+    <option name="LABEL_INDENT_ABSOLUTE" value="false" />
+    <option name="USE_RELATIVE_INDENTS" value="false" />
+  </ADDITIONAL_INDENT_OPTIONS>
+  <ADDITIONAL_INDENT_OPTIONS fileType="js">
+    <option name="INDENT_SIZE" value="4" />
+    <option name="CONTINUATION_INDENT_SIZE" value="4" />
+    <option name="TAB_SIZE" value="4" />
+    <option name="USE_TAB_CHARACTER" value="false" />
+    <option name="SMART_TABS" value="false" />
+    <option name="LABEL_INDENT_SIZE" value="0" />
+    <option name="LABEL_INDENT_ABSOLUTE" value="false" />
+    <option name="USE_RELATIVE_INDENTS" value="false" />
+  </ADDITIONAL_INDENT_OPTIONS>
+  <ADDITIONAL_INDENT_OPTIONS fileType="jsp">
+    <option name="INDENT_SIZE" value="4" />
+    <option name="CONTINUATION_INDENT_SIZE" value="8" />
+    <option name="TAB_SIZE" value="4" />
+    <option name="USE_TAB_CHARACTER" value="false" />
+    <option name="SMART_TABS" value="false" />
+    <option name="LABEL_INDENT_SIZE" value="0" />
+    <option name="LABEL_INDENT_ABSOLUTE" value="false" />
+    <option name="USE_RELATIVE_INDENTS" value="false" />
+  </ADDITIONAL_INDENT_OPTIONS>
+  <ADDITIONAL_INDENT_OPTIONS fileType="sql">
+    <option name="INDENT_SIZE" value="2" />
+    <option name="CONTINUATION_INDENT_SIZE" value="8" />
+    <option name="TAB_SIZE" value="4" />
+    <option name="USE_TAB_CHARACTER" value="false" />
+    <option name="SMART_TABS" value="false" />
+    <option name="LABEL_INDENT_SIZE" value="0" />
+    <option name="LABEL_INDENT_ABSOLUTE" value="false" />
+    <option name="USE_RELATIVE_INDENTS" value="false" />
+  </ADDITIONAL_INDENT_OPTIONS>
+  <ADDITIONAL_INDENT_OPTIONS fileType="xml">
+    <option name="INDENT_SIZE" value="4" />
+    <option name="CONTINUATION_INDENT_SIZE" value="8" />
+    <option name="TAB_SIZE" value="4" />
+    <option name="USE_TAB_CHARACTER" value="false" />
+    <option name="SMART_TABS" value="false" />
+    <option name="LABEL_INDENT_SIZE" value="0" />
+    <option name="LABEL_INDENT_ABSOLUTE" value="false" />
+    <option name="USE_RELATIVE_INDENTS" value="false" />
+  </ADDITIONAL_INDENT_OPTIONS>
+  <ADDITIONAL_INDENT_OPTIONS fileType="yml">
+    <option name="INDENT_SIZE" value="2" />
+    <option name="CONTINUATION_INDENT_SIZE" value="8" />
+    <option name="TAB_SIZE" value="4" />
+    <option name="USE_TAB_CHARACTER" value="false" />
+    <option name="SMART_TABS" value="false" />
+    <option name="LABEL_INDENT_SIZE" value="0" />
+    <option name="LABEL_INDENT_ABSOLUTE" value="false" />
+    <option name="USE_RELATIVE_INDENTS" value="false" />
+  </ADDITIONAL_INDENT_OPTIONS>
+  <codeStyleSettings language="JavaScript">
+    <option name="KEEP_CONTROL_STATEMENT_IN_ONE_LINE" value="false" />
+    <option name="KEEP_BLANK_LINES_IN_CODE" value="1" />
+    <option name="BLANK_LINES_AROUND_FIELD" value="1" />
+    <option name="BLANK_LINES_AFTER_CLASS_HEADER" value="1" />
+    <option name="ALIGN_MULTILINE_PARAMETERS" value="false" />
+    <option name="ALIGN_MULTILINE_FOR" value="false" />
+    <option name="CALL_PARAMETERS_WRAP" value="1" />
+    <option name="METHOD_PARAMETERS_WRAP" value="1" />
+    <option name="EXTENDS_LIST_WRAP" value="1" />
+    <option name="THROWS_LIST_WRAP" value="1" />
+    <option name="EXTENDS_KEYWORD_WRAP" value="1" />
+    <option name="THROWS_KEYWORD_WRAP" value="1" />
+    <option name="METHOD_CALL_CHAIN_WRAP" value="1" />
+    <option name="BINARY_OPERATION_WRAP" value="1" />
+    <option name="BINARY_OPERATION_SIGN_ON_NEXT_LINE" value="true" />
+    <option name="TERNARY_OPERATION_WRAP" value="1" />
+    <option name="TERNARY_OPERATION_SIGNS_ON_NEXT_LINE" value="true" />
+    <option name="FOR_STATEMENT_WRAP" value="1" />
+    <option name="ARRAY_INITIALIZER_WRAP" value="1" />
+    <option name="ASSIGNMENT_WRAP" value="1" />
+    <option name="PLACE_ASSIGNMENT_SIGN_ON_NEXT_LINE" value="true" />
+    <option name="WRAP_COMMENTS" value="true" />
+    <option name="IF_BRACE_FORCE" value="3" />
+    <option name="DOWHILE_BRACE_FORCE" value="3" />
+    <option name="WHILE_BRACE_FORCE" value="3" />
+    <option name="FOR_BRACE_FORCE" value="3" />
+    <option name="PARENT_SETTINGS_INSTALLED" value="true" />
+  </codeStyleSettings>
 </code_scheme>
 
diff --git a/tools/idegen/Android.mk b/tools/idegen/Android.mk
index d424ab6..8771160 100644
--- a/tools/idegen/Android.mk
+++ b/tools/idegen/Android.mk
@@ -2,8 +2,7 @@
 
 include $(CLEAR_VARS)
 
-LOCAL_STATIC_JAVA_LIBRARIES := \
-        guavalib \
+LOCAL_STATIC_JAVA_LIBRARIES := guavalib
 
 LOCAL_SRC_FILES := $(call all-subdir-java-files)
 
diff --git a/tools/idegen/index-gen.sh b/tools/idegen/index-gen.sh
index eadaa98..5b9e24b 100755
--- a/tools/idegen/index-gen.sh
+++ b/tools/idegen/index-gen.sh
@@ -14,12 +14,14 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 #
-# Generates a module index file by searching through android source tree for make files.  The
-# intellij-gen.sh script automatically calls this script the first time or if you delete the
-# generated indexed file.  The only time you need to run this manually is if modules are added or
-# deleted.
+# Generates a module index file by searching through android source
+# tree for make files.  The intellij-gen.sh script automatically calls
+# this script the first time or if you delete the generated indexed
+# file.  The only time you need to run this manually is if modules are
+# added or deleted.
 #
-# To use:
+# To use, run the following command from either your repo root or
+# development/tools/idegen:
 #   index-gen.sh
 #
 # Only tested on linux.  Should work for macs but have not tried.
@@ -27,7 +29,15 @@
 set -e
 
 script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
-root_dir=`readlink -f -n $script_dir/../../..`
+#root_dir=`readlink -f -n $script_dir/../../..`
+root_dir=$PWD
+if [ ! -e $root_dir/.repo ]; then
+  root_dir=$PWD/../../..
+  if [ ! -e $root_dir/.repo ]; then
+    echo "Repo root not found. Run this script from your repo root or the idegen directory."
+    exit 1
+  fi
+fi
 tmp_file=tmp.txt
 dest_file=module-index.txt
 
diff --git a/tools/idegen/intellij-gen.sh b/tools/idegen/intellij-gen.sh
index 7f00eba..d67c1f8 100755
--- a/tools/idegen/intellij-gen.sh
+++ b/tools/idegen/intellij-gen.sh
@@ -14,7 +14,8 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 #
-# To use:
+# To use, run the following command from either your repo root or
+# development/tools/idegen:
 #   intellij-gen.sh <module name>
 #
 # where module name is the LOCAL_PACKAGE_NAME in Android.mk for the project.
@@ -22,27 +23,38 @@
 # For example, to generate a project for Contacts, use:
 #   intellij-gen.sh Contacts
 #
-# The project directory (.idea) will be put in the root directory of the module.  Sharable iml
-# files will be put into each respective module directory.
+# The project directory (.idea) will be put in the root directory of
+# the module.  Sharable iml files will be put into each respective
+# module directory.
 #
 # Only tested on linux.  Should work for macs but have not tried.
 #
 set -e
 
-script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
-root_dir=`readlink -f -n $script_dir/../../..`
-index_file=$script_dir/module-index.txt
-idegenjar=$root_dir/out/host/common/obj/JAVA_LIBRARIES/idegen_intermediates/javalib.jar
-
 progname=`basename $0`
 if [ $# -ne 1 ]
 then
     echo "Usage: $progname <module_name>"
     exit 1
 fi
-
 module_name=$1
 
+script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+root_dir=$PWD
+if [ ! -e $root_dir/.repo ]; then
+  root_dir=$PWD/../../..
+  if [ ! -e $root_dir/.repo ]; then
+    echo "Repo root not found. Run this script from your repo root or the idegen directory."
+    exit 1
+  fi
+fi
+index_file=$root_dir/module-index.txt
+idegenjar=$script_dir/idegen.jar
+if [ ! -e $idegenjar ]; then
+  # See if the jar is in the build directory.
+  idegenjar=$root_dir/out/host/linux-x86/framework/idegen.jar
+fi
+
 if [ ! -e "$index_file" ]; then
   echo "Module index file missing; generating this is only done the first time."
   echo "If any dependencies change, you should generate a new index file by running index-gen.sh."
diff --git a/tools/idegen/src/com/android/idegen/Constants.java b/tools/idegen/src/com/android/idegen/Constants.java
deleted file mode 100644
index f541dd4..0000000
--- a/tools/idegen/src/com/android/idegen/Constants.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.idegen;
-
-import java.nio.charset.Charset;
-
-/**
- * Constants
- */
-public class Constants {
-
-    public static final Charset CHARSET = Charset.forName("UTF-8");
-
-    public static final String REL_TEMPLATE_DIR = "development/tools/idegen/templates";
-    public static final String REL_MODULES_TEMPLATE = REL_TEMPLATE_DIR + "/idea/modules.xml";
-    public static final String REL_VCS_TEMPLATE = REL_TEMPLATE_DIR + "/idea/vcs.xml";
-    public static final String REL_IML_TEMPLATE = REL_TEMPLATE_DIR + "/module-template.iml";
-
-    public static final String REL_OUT_APP_DIR = "out/target/common/obj/APPS";
-
-    public static final String FRAMEWORK_MODULE = "framework";
-    public static final String[] AUTO_DEPENDENCIES = new String[]{
-            FRAMEWORK_MODULE, "libcore"
-    };
-    public static final String[] DIRS_WITH_AUTO_DEPENDENCIES = new String[] {
-      "packages", "vendor", "frameworks/ex", "frameworks/opt", "frameworks/support"
-    };
-
-    // Framework needs a special constant for it's intermediates because it does not follow
-    // normal conventions.
-    public static final String FRAMEWORK_INTERMEDIATES = "framework-res_intermediates";
-}
diff --git a/tools/idegen/src/com/android/idegen/DirectorySearch.java b/tools/idegen/src/com/android/idegen/DirectorySearch.java
index 1bbf99f..2ff23e3 100644
--- a/tools/idegen/src/com/android/idegen/DirectorySearch.java
+++ b/tools/idegen/src/com/android/idegen/DirectorySearch.java
@@ -21,8 +21,12 @@
 import com.google.common.collect.Sets;
 
 import java.io.File;
+import java.io.FileNotFoundException;
 import java.io.FilenameFilter;
+import java.net.URISyntaxException;
 import java.util.HashSet;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
@@ -31,6 +35,8 @@
  */
 public class DirectorySearch {
 
+    private static final Logger logger = Logger.getLogger(DirectorySearch.class.getName());
+
     private static final HashSet<String> SOURCE_DIRS = Sets.newHashSet();
     static {
         SOURCE_DIRS.add("src");
@@ -40,6 +46,9 @@
     private static final Pattern EXCLUDE_PATTERN = Pattern.compile("values-..(-.*)*");
 
     private static File repoRoot = null;
+    public static final String REL_TEMPLATE_DIR = "templates";
+    public static final String REL_TEMPLATE_PATH_FROM_ROOT = "development/tools/idegen/"
+            + REL_TEMPLATE_DIR;
 
     /**
      * Find the repo root.  This is the root branch directory of a full repo checkout.
@@ -138,4 +147,38 @@
 
         return builder.build();
     }
+
+    private static File templateDirCurrent = null;
+    private static File templateDirRoot = null;
+
+    public static File findTemplateDir() throws FileNotFoundException {
+        // Cache optimization.
+        if (templateDirCurrent != null && templateDirCurrent.exists()) return templateDirCurrent;
+        if (templateDirRoot != null && templateDirRoot.exists()) return templateDirRoot;
+
+        File currentDir = null;
+        try {
+            currentDir = new File(IntellijProject.class.getProtectionDomain().getCodeSource()
+                    .getLocation().toURI().getPath()).getParentFile();
+        } catch (URISyntaxException e) {
+            logger.log(Level.SEVERE, "Could not get jar location.", e);
+            return null;
+        }
+
+        // First check relative to current run directory.
+        templateDirCurrent = new File(currentDir, REL_TEMPLATE_DIR);
+        if (templateDirCurrent.exists()) {
+            return templateDirCurrent;
+        } else {
+            // Then check relative to root directory.
+            templateDirRoot = new File(repoRoot, REL_TEMPLATE_PATH_FROM_ROOT);
+            if (templateDirRoot.exists()) {
+                return templateDirRoot;
+            }
+        }
+        throw new FileNotFoundException(
+                "Unable to find template dir. Tried the following locations:\n" +
+                templateDirCurrent.getAbsolutePath() + "\n" +
+                templateDirRoot.getAbsolutePath());
+    }
 }
diff --git a/tools/idegen/src/com/android/idegen/FrameworkModule.java b/tools/idegen/src/com/android/idegen/FrameworkModule.java
index bfcd1fa..8743925 100644
--- a/tools/idegen/src/com/android/idegen/FrameworkModule.java
+++ b/tools/idegen/src/com/android/idegen/FrameworkModule.java
@@ -25,15 +25,19 @@
  */
 public class FrameworkModule extends StandardModule {
 
+    // Framework needs a special constant for it's intermediates because it does not follow
+    // normal conventions.
+    private static final String FRAMEWORK_INTERMEDIATES = "framework-res_intermediates";
+
     public FrameworkModule(String moduleName, String makeFile) {
-        super(Constants.FRAMEWORK_MODULE, makeFile, true);
+        super(IntellijProject.FRAMEWORK_MODULE, makeFile, true);
     }
 
     @Override
     protected String buildIntermediates() {
         StringBuilder sb = new StringBuilder();
         File intermediates = new File(repoRoot,
-                Constants.REL_OUT_APP_DIR + File.separator +  Constants.FRAMEWORK_INTERMEDIATES);
+                REL_OUT_APP_DIR + File.separator +  FRAMEWORK_INTERMEDIATES);
         ImmutableList<File> intermediateSrcDirs = DirectorySearch.findSourceDirs(intermediates);
         sb.append("    <content url=\"file://").append(intermediates).append("\">\n");
         for (File src : intermediateSrcDirs) {
diff --git a/tools/idegen/src/com/android/idegen/IntellijProject.java b/tools/idegen/src/com/android/idegen/IntellijProject.java
index d5564d5..e49a12b 100644
--- a/tools/idegen/src/com/android/idegen/IntellijProject.java
+++ b/tools/idegen/src/com/android/idegen/IntellijProject.java
@@ -22,6 +22,7 @@
 
 import java.io.File;
 import java.io.IOException;
+import java.nio.charset.Charset;
 import java.util.Arrays;
 import java.util.Set;
 import java.util.logging.Logger;
@@ -31,9 +32,16 @@
  */
 public class IntellijProject {
 
+    public static final String FRAMEWORK_MODULE = "framework";
+    public static final Charset CHARSET = Charset.forName("UTF-8");
+
     private static final Logger logger = Logger.getLogger(IntellijProject.class.getName());
 
+    private static final String MODULES_TEMPLATE_FILE_NAME = "modules.xml";
+    private static final String VCS_TEMPLATE_FILE_NAME = "vcs.xml";
+
     ModuleCache cache = ModuleCache.getInstance();
+
     File indexFile;
     File repoRoot;
     File projectIdeaDir;
@@ -55,6 +63,11 @@
 
         // First pass, find all dependencies and cache them.
         Module module = cache.getAndCache(moduleName);
+        if (module == null) {
+            logger.info("Module '" + moduleName + "' not found." +
+                    " Module names are case senstive.");
+            return;
+        }
         projectIdeaDir = new File(module.getDir(), ".idea");
         projectIdeaDir.mkdir();
         copyTemplates();
@@ -104,19 +117,27 @@
 
     /**
      * Framework module needs special handling due to one off resource path:
-     *   frameworks/base/Android.mk
+     * frameworks/base/Android.mk
      */
     private void buildFrameWorkModule() throws IOException {
-        String makeFile = cache.getMakeFile(Constants.FRAMEWORK_MODULE);
-        logger.info("makefile: " + makeFile);
-        StandardModule frameworkModule = new FrameworkModule(Constants.FRAMEWORK_MODULE, makeFile);
-        frameworkModule.build();
-        cache.put(frameworkModule);
+        String makeFile = cache.getMakeFile(FRAMEWORK_MODULE);
+        if (makeFile == null) {
+            logger.warning("Unable to find framework module: " + FRAMEWORK_MODULE +
+                    ". Skipping.");
+        } else {
+            logger.info("makefile: " + makeFile);
+            StandardModule frameworkModule = new FrameworkModule(FRAMEWORK_MODULE,
+                    makeFile);
+            frameworkModule.build();
+            cache.put(frameworkModule);
+        }
     }
 
     private void createModulesFile(Module module) throws IOException {
-        String modulesContent = Files.toString(new File(repoRoot, Constants.REL_MODULES_TEMPLATE),
-                Constants.CHARSET);
+        String modulesContent = Files.toString(
+                new File(DirectorySearch.findTemplateDir(),
+                        "idea" + File.separator + MODULES_TEMPLATE_FILE_NAME),
+                CHARSET);
         StringBuilder sb = new StringBuilder();
         File moduleIml = module.getImlFile();
         sb.append("      <module fileurl=\"file://").append(moduleIml.getAbsolutePath())
@@ -131,12 +152,14 @@
 
         File out = new File(projectIdeaDir, "modules.xml");
         logger.info("Creating " + out.getAbsolutePath());
-        Files.write(modulesContent, out, Constants.CHARSET);
+        Files.write(modulesContent, out, CHARSET);
     }
 
     private void createVcsFile(Module module) throws IOException {
-        String vcsTemplate = Files.toString(new File(module.getRepoRoot(),
-                Constants.REL_VCS_TEMPLATE), Constants.CHARSET);
+        String vcsTemplate = Files.toString(
+                new File(DirectorySearch.findTemplateDir(),
+                        "idea" + File.separator + VCS_TEMPLATE_FILE_NAME),
+                CHARSET);
 
         StringBuilder sb = new StringBuilder();
         for (String name : module.getAllDependencies()) {
@@ -149,18 +172,17 @@
             }
         }
         vcsTemplate = vcsTemplate.replace("@VCS@", sb.toString());
-        Files.write(vcsTemplate, new File(projectIdeaDir, "vcs.xml"), Constants.CHARSET);
+        Files.write(vcsTemplate, new File(projectIdeaDir, "vcs.xml"), CHARSET);
     }
 
     private void createNameFile(String name) throws IOException {
-        File out =  new File(projectIdeaDir, ".name");
-        Files.write(name, out, Constants.CHARSET);
+        File out = new File(projectIdeaDir, ".name");
+        Files.write(name, out, CHARSET);
     }
 
     private void copyTemplates() throws IOException {
-        File templateDir = new File(repoRoot,
-                Constants.REL_TEMPLATE_DIR + File.separatorChar + "idea");
-        copyTemplates(templateDir, projectIdeaDir);
+        File templateDir = DirectorySearch.findTemplateDir();
+        copyTemplates(new File(templateDir, "idea"), projectIdeaDir);
     }
 
     private void copyTemplates(File fromDir, File toDir) throws IOException {
diff --git a/tools/idegen/src/com/android/idegen/Module.java b/tools/idegen/src/com/android/idegen/Module.java
index 7ba42a3..deb2281 100644
--- a/tools/idegen/src/com/android/idegen/Module.java
+++ b/tools/idegen/src/com/android/idegen/Module.java
@@ -34,6 +34,8 @@
 
     private static final Logger logger = Logger.getLogger(Module.class.getName());
 
+    private static final String IML_TEMPLATE_FILE_NAME = "module-template.iml";
+
     /**
      * All possible attributes for the make file.
      */
@@ -44,23 +46,35 @@
     }
 
     ModuleCache moduleCache = ModuleCache.getInstance();
+
     private File imlFile;
+
     private Set<String> allDependencies = Sets.newHashSet(); // direct + indirect
+
     private Set<File> allDependentImlFiles = Sets.newHashSet();
 
     protected abstract void build() throws IOException;
+
     protected abstract String getName();
+
     protected abstract File getDir();
+
     protected abstract boolean isAndroidModule();
+
     protected abstract List<File> getIntermediatesDirs();
+
     public abstract Set<String> getDirectDependencies();
+
     protected abstract ImmutableList<File> getSourceDirs();
+
     protected abstract ImmutableList<File> getExcludeDirs();
+
     public abstract File getRepoRoot();
 
     public void buildImlFile() throws IOException {
-        String imlTemplate = Files.toString(new File(getRepoRoot(), Constants.REL_IML_TEMPLATE),
-                Constants.CHARSET);
+        String imlTemplate = Files.toString(
+                new File(DirectorySearch.findTemplateDir(), IML_TEMPLATE_FILE_NAME),
+                IntellijProject.CHARSET);
 
         String facetXml = "";
         if (isAndroidModule()) {
@@ -100,7 +114,7 @@
 
         imlFile = new File(moduleDir, getName() + ".iml");
         logger.info("Creating " + imlFile.getAbsolutePath());
-        Files.write(imlTemplate, imlFile, Constants.CHARSET);
+        Files.write(imlTemplate, imlFile, IntellijProject.CHARSET);
     }
 
     protected String buildIntermediates() {
diff --git a/tools/idegen/src/com/android/idegen/StandardModule.java b/tools/idegen/src/com/android/idegen/StandardModule.java
index dffb95e..f7b24b0 100644
--- a/tools/idegen/src/com/android/idegen/StandardModule.java
+++ b/tools/idegen/src/com/android/idegen/StandardModule.java
@@ -17,6 +17,7 @@
 package com.android.idegen;
 
 import com.google.common.base.Objects;
+import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Iterables;
 import com.google.common.collect.Lists;
@@ -45,10 +46,18 @@
  */
 public class StandardModule extends Module {
 
+    static final String REL_OUT_APP_DIR = "out/target/common/obj/APPS";
+
     private static final Logger logger = Logger.getLogger(StandardModule.class.getName());
 
     private static final Pattern SRC_PATTERN = Pattern.compile(
             ".*\\(call all-java-files-under, (.*)\\)");
+    private static final String[] AUTO_DEPENDENCIES = new String[]{
+            IntellijProject.FRAMEWORK_MODULE, "libcore"
+    };
+    private static final String[] DIRS_WITH_AUTO_DEPENDENCIES = new String[]{
+            "packages", "vendor", "frameworks/ex", "frameworks/opt", "frameworks/support"
+    };
 
     String moduleName;
     File makeFile;
@@ -66,7 +75,8 @@
     }
 
     public StandardModule(String moduleName, String makeFile, boolean searchForSrc) {
-        this(moduleName, new File(makeFile), searchForSrc);
+        this(Preconditions.checkNotNull(moduleName), new File(Preconditions.checkNotNull(makeFile)),
+                searchForSrc);
     }
 
     public StandardModule(String moduleName, File makeFile, boolean searchForSrc) {
@@ -75,16 +85,16 @@
         this.moduleRoot = makeFile.getParentFile();
         this.repoRoot = DirectorySearch.findRepoRoot(makeFile);
         this.intermediatesDir = new File(repoRoot.getAbsolutePath() + File.separator +
-                Constants.REL_OUT_APP_DIR + File.separator + getName() + "_intermediates" +
+                REL_OUT_APP_DIR + File.separator + getName() + "_intermediates" +
                 File.separator + "src");
         this.searchForSrc = searchForSrc;
 
         // TODO: auto-detect when framework dependency is needed instead of using coded list.
-        for (String dir : Constants.DIRS_WITH_AUTO_DEPENDENCIES) {
+        for (String dir : DIRS_WITH_AUTO_DEPENDENCIES) {
             // length + 2 to account for slash
             boolean isDir = makeFile.getAbsolutePath().startsWith(repoRoot + "/" + dir);
             if (isDir) {
-                for (String dependency : Constants.AUTO_DEPENDENCIES) {
+                for (String dependency : AUTO_DEPENDENCIES) {
                     this.directDependencies.add(dependency);
                 }
             }