2 * Copyright 2000-2017 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.intellij.openapi.module.impl
18 import com.intellij.openapi.Disposable
19 import com.intellij.openapi.application.PathManager
20 import com.intellij.openapi.module.UnloadedModuleDescription
21 import com.intellij.openapi.vfs.pointers.VirtualFilePointer
22 import com.intellij.openapi.vfs.pointers.VirtualFilePointerManager
23 import org.jetbrains.jps.model.module.JpsModule
24 import org.jetbrains.jps.model.module.JpsModuleDependency
25 import org.jetbrains.jps.model.serialization.JpsGlobalLoader
26 import org.jetbrains.jps.model.serialization.JpsProjectLoader
27 import java.nio.file.Paths
32 class UnloadedModuleDescriptionImpl(val modulePath: ModulePath,
33 private val dependencyModuleNames: List<String>,
34 private val contentRoots: List<VirtualFilePointer>) : UnloadedModuleDescription {
35 override fun getGroupPath() = modulePath.group?.split(ModuleManagerImpl.MODULE_GROUP_SEPARATOR) ?: emptyList()
37 override fun getName() = modulePath.moduleName
39 override fun getContentRoots() = contentRoots
41 override fun getDependencyModuleNames() = dependencyModuleNames
45 fun createFromPaths(paths: List<ModulePath>, parentDisposable: Disposable): List<UnloadedModuleDescriptionImpl> {
46 val pathVariables = JpsGlobalLoader.computeAllPathVariables(PathManager.getOptionsPath())
47 val modules = JpsProjectLoader.loadModules(paths.map { Paths.get(it.path) }, null, pathVariables)
48 val pathsByName = paths.associateBy { it.moduleName }
49 return modules.map { create(pathsByName[it.name]!!, it, parentDisposable) }
52 private fun create(path: ModulePath, module: JpsModule, parentDisposable: Disposable): UnloadedModuleDescriptionImpl {
53 val dependencyModuleNames = module.dependenciesList.dependencies
54 .filterIsInstance(JpsModuleDependency::class.java)
55 .map { it.moduleReference.moduleName }
57 val pointerManager = VirtualFilePointerManager.getInstance()
58 return UnloadedModuleDescriptionImpl(path, dependencyModuleNames, module.contentRootsList.urls.map {pointerManager.create(it, parentDisposable, null)})