2 * Copyright 2000-2014 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;
18 import com.intellij.openapi.project.Project;
19 import com.intellij.openapi.util.InvalidDataException;
20 import com.intellij.openapi.util.SimpleModificationTracker;
21 import com.intellij.util.graph.Graph;
22 import org.jdom.JDOMException;
23 import org.jetbrains.annotations.NonNls;
24 import org.jetbrains.annotations.NotNull;
25 import org.jetbrains.annotations.Nullable;
27 import java.io.IOException;
28 import java.util.Comparator;
29 import java.util.List;
32 * Provides services for working with the modules of a project.
34 public abstract class ModuleManager extends SimpleModificationTracker {
36 * Returns the module manager instance for the current project.
38 * @param project the project for which the module manager is requested.
39 * @return the module manager instance.
41 public static ModuleManager getInstance(@NotNull Project project) {
42 return project.getComponent(ModuleManager.class);
46 * Creates a module of the specified type at the specified path and adds it to the project
47 * to which the module manager is related.
49 * @param filePath the path at which the module is created.
50 * @param moduleTypeId the ID of the module type to create.
51 * @return the module instance.
53 @NotNull public abstract Module newModule(@NotNull @NonNls String filePath, final String moduleTypeId);
56 * Loads a module from an .iml file with the specified path and adds it to the project.
58 * @param filePath the path to load the module from.
59 * @return the module instance.
60 * @throws InvalidDataException if the data in the .iml file is semantically incorrect.
61 * @throws IOException if an I/O error occurred when loading the module file.
62 * @throws JDOMException if the file contains invalid XML data.
63 * @throws ModuleWithNameAlreadyExists if a module with such a name already exists in the project.
65 @NotNull public abstract Module loadModule(@NotNull String filePath) throws InvalidDataException, IOException, JDOMException, ModuleWithNameAlreadyExists;
68 * Disposes of the specified module and removes it from the project.
70 * @param module the module to remove.
72 public abstract void disposeModule(@NotNull Module module);
75 * Returns the list of all modules in the project.
77 * @return the array of modules.
79 @NotNull public abstract Module[] getModules();
82 * Returns the project module with the specified name.
84 * @param name the name of the module to find.
85 * @return the module instance, or null if no module with such name exists.
87 @Nullable public abstract Module findModuleByName(@NonNls @NotNull String name);
90 * Returns the list of modules sorted by dependency (the modules which do not depend
91 * on anything are in the beginning of the list, a module which depends on another module
92 * follows it in the list).
94 * @return the sorted array of modules.
96 @NotNull public abstract Module[] getSortedModules();
99 * Returns the module comparator which can be used for sorting modules by dependency
100 * (the modules which do not depend on anything are in the beginning of the list,
101 * a module which depends on another module follows it in the list).
103 * @return the module comparator instance.
105 @NotNull public abstract Comparator<Module> moduleDependencyComparator();
108 * Returns the list of modules which directly depend on the specified module.
110 * @param module the module for which the list of dependent modules is requested.
111 * @return list of <i>modules that depend on</i> given module.
113 * @see ModuleUtilCore#getAllDependentModules(Module)
115 @NotNull public abstract List<Module> getModuleDependentModules(@NotNull Module module);
118 * Checks if one of the specified modules directly depends on the other module.
120 * @param module the module to check the dependency for.
121 * @param onModule the module on which <code>module</code> may depend.
122 * @return true if <code>module</code> directly depends on <code>onModule</code>, false otherwise.
124 public abstract boolean isModuleDependent(@NotNull Module module, @NotNull Module onModule);
127 * Returns the graph of dependencies between modules in the project.
129 * @return the module dependency graph.
131 @NotNull public abstract Graph<Module> moduleGraph();
134 * Returns the graph of dependencies between modules in the project.
136 * @param includeTests whether test-only dependencies should be included
137 * @return the module dependency graph.
140 @NotNull public abstract Graph<Module> moduleGraph(boolean includeTests);
143 * Returns the model for the list of modules in the project, which can be used to add,
144 * remove or modify modules.
146 * @return the modifiable model instance.
148 @NotNull public abstract ModifiableModuleModel getModifiableModel();
152 * Returns the path to the group to which the specified module belongs, as an
153 * array of group names starting from the project root.
155 * @param module the module for which the path is requested.
156 * @return the path to the group for the module, or null if the module does not belong to any group.
158 @Nullable public abstract String[] getModuleGroupPath(@NotNull Module module);