private def loadModule()

in model/src/org/jetbrains/jps/idea/IdeaProjectLoader.groovy [312:463]


  private def loadModule(String imlPath) {
    def moduleFile = new File(imlPath)
    if (!moduleFile.exists()) {
      errorReporter.error("Module file $imlPath not found")
      return
    }

    def moduleBasePath = FileUtil.toSystemIndependentName(moduleFile.getParentFile().getAbsolutePath())
    MacroExpander moduleMacroExpander = new ModuleMacroExpander(projectMacroExpander, moduleBasePath)
    def currentModuleName = moduleName(imlPath)
    project.createModule(currentModuleName) {
      Module currentModule = project.modules[currentModuleName]
      currentModule.basePath = moduleBasePath
      def root = new XmlParser(false, false).parse(moduleFile)
      def componentTag = getComponent(root, "NewModuleRootManager")
      if (componentTag != null) {
        componentTag.orderEntry.each {Node entryTag ->
          String type = entryTag.@type
          DependencyScope scope = getScopeById(entryTag.@scope)
          boolean exported = entryTag.@exported != null
          switch (type) {
            case "module":
              def moduleName = entryTag.attribute("module-name")
              def module = project.modules[moduleName]
              if (module == null) {
                errorReporter.warning("Cannot resolve module $moduleName in $currentModuleName")
              }
              else {
                dependency(module, scope, exported)
              }
              break

            case "sourceFolder":
              moduleSource()
              break

            case "module-library":
              def libraryTag = entryTag.library[0]
              def libraryName = libraryTag."@name"
              def moduleLibrary = loadLibrary(project, libraryName != null ? libraryName : "moduleLibrary#${libraryCount++}",
                                              libraryTag, moduleMacroExpander)
              dependency(moduleLibrary, scope, exported)

              if (libraryName != null) {
                currentModule.libraries[libraryName] = moduleLibrary
              }
              break;

            case "library":
              def name = entryTag.attribute("name")
              def library = null
              if (entryTag.@level == "project") {
                library = project.libraries[name]
                if (library == null) {
                  errorReporter.warning("Cannot resolve project library '$name' in module '$currentModuleName'")
                }
              } else {
                library = project.globalLibraries[name]
                if (library == null) {
                  errorReporter.warning("Cannot resolve global library '$name' in module '$currentModuleName'")
                }
              }

              if (library != null) {
                dependency(library, scope, exported)
              }
              break

            case "jdk":
              def name = entryTag.@jdkName
              def sdk = project.sdks[name]
              if (sdk == null) {
                errorReporter.warning("Cannot resolve SDK '$name' in module '$currentModuleName'. Embedded javac will be used")
              }
              else {
                currentModule.sdk = sdk
                dependency(sdk, PredefinedDependencyScopes.COMPILE, false)
              }
              break

            case "inheritedJdk":
              def sdk = project.projectSdk
              if (sdk != null) {
                currentModule.sdk = sdk
                dependency(sdk, PredefinedDependencyScopes.COMPILE, false)
              }
              break
          }
        }

        def srcFolderExists = componentTag.content.sourceFolder[0] != null;

        componentTag.content.each {Node contentTag ->
          content moduleMacroExpander.expandMacros(IdeaProjectLoadingUtil.pathFromUrl(contentTag.@url))
        }

        componentTag.content.sourceFolder.each {Node folderTag ->
          String path = moduleMacroExpander.expandMacros(IdeaProjectLoadingUtil.pathFromUrl(folderTag.@url))
          String prefix = folderTag.@packagePrefix

          if (folderTag.attribute("isTestSource") == "true") {
            testSrc path
          }
          else {
            src path
          }

          if (prefix != null && prefix != "") {
            currentModule.sourceRootPrefixes[path] = (prefix.replace('.', '/'))
          }
        }

        componentTag.content.excludeFolder.each {Node exTag ->
          String path = moduleMacroExpander.expandMacros(IdeaProjectLoadingUtil.pathFromUrl(exTag.@url))
          exclude path
        }

        def languageLevel = componentTag."@LANGUAGE_LEVEL"
        if (languageLevel == null) {
          languageLevel = projectLanguageLevel
        }
        if (languageLevel != null) {
          def ll = convertLanguageLevel(languageLevel)
          currentModule["sourceLevel"] = ll
          currentModule["targetLevel"] = ll
        }

        if (srcFolderExists) {
          if (componentTag."@inherit-compiler-output" == "true") {
            if (projectOutputPath == null) {
              errorReporter.error("Module '$currentModuleName' uses output path inherited from project but project output path is not specified")
            }
            currentModule.outputPath = FileUtil.toSystemIndependentName(new File(new File(projectOutputPath, "production"), currentModuleName).absolutePath)
            currentModule.testOutputPath = FileUtil.toSystemIndependentName(new File(new File(projectOutputPath, "test"), currentModuleName).absolutePath)
          }
          else {
            currentModule.outputPath = moduleMacroExpander.expandMacros(IdeaProjectLoadingUtil.pathFromUrl(componentTag.output[0]?.@url))
            currentModule.testOutputPath = moduleMacroExpander.expandMacros(IdeaProjectLoadingUtil.pathFromUrl(componentTag."output-test"[0]?.'@url'))
            if (currentModule.testOutputPath == null) {
              currentModule.testOutputPath = currentModule.outputPath
            }
          }
        }
      }

      def facetManagerTag = getComponent(root, "FacetManager")
      if (facetManagerTag != null) {
        def facetLoader = new FacetLoader(currentModule, moduleMacroExpander)
        facetLoader.loadFacets(facetManagerTag)
      }
    }
  }