com.intellij.openapi.roots.ModuleRootManager Java Examples

The following examples show how to use com.intellij.openapi.roots.ModuleRootManager. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PsiPackageSupportProviders.java    From consulo with Apache License 2.0 6 votes vote down vote up
@RequiredReadAction
public static boolean isPackageSupported(@Nonnull Project project) {
  return CachedValuesManager.getManager(project).getCachedValue(project, () -> {
    boolean result = false;
    PsiPackageSupportProvider[] extensions = PsiPackageSupportProvider.EP_NAME.getExtensions();
    ModuleManager moduleManager = ModuleManager.getInstance(project);
    loop:
    for (Module module : moduleManager.getModules()) {
      ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
      for (ModuleExtension moduleExtension : rootManager.getExtensions()) {
        for (PsiPackageSupportProvider extension : extensions) {
          if (extension.isSupported(moduleExtension)) {
            result = true;
            break loop;
          }
        }
      }
    }
    return CachedValueProvider.Result.create(result, ProjectRootManager.getInstance(project));
  });
}
 
Example #2
Source File: LibraryUsageCollector.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
public Set<UsageDescriptor> getProjectUsages(@Nonnull Project project) {
  final Set<LibraryKind> usedKinds = new HashSet<LibraryKind>();
  final Processor<Library> processor = new Processor<Library>() {
    @Override
    public boolean process(Library library) {
      usedKinds.addAll(LibraryPresentationManagerImpl.getLibraryKinds(library, null));
      return true;
    }
  };
  for (Module module : ModuleManager.getInstance(project).getModules()) {
    ModuleRootManager.getInstance(module).orderEntries().librariesOnly().forEachLibrary(processor);
  }

  final HashSet<UsageDescriptor> usageDescriptors = new HashSet<UsageDescriptor>();
  for (LibraryKind kind : usedKinds) {
    usageDescriptors.add(new UsageDescriptor(kind.getKindId(), 1));
  }
  return usageDescriptors;
}
 
Example #3
Source File: GradleToolDelegate.java    From intellij-quarkus with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void processImport(Module module) {
    Project project = module.getProject();
    File gradleFile = null;

    for(VirtualFile virtualFile : ModuleRootManager.getInstance(module).getContentRoots()) {
        File baseDir = VfsUtilCore.virtualToIoFile(virtualFile);
        File file = new File(baseDir, "build.gradle");
        if (file.exists()) {
            gradleFile = file;
            break;
        }
    }

    if (gradleFile != null) {
        ProjectImportProvider gradleProjectImportProvider = getGradleProjectImportProvider();
        ProjectImportBuilder gradleProjectImportBuilder = gradleProjectImportProvider.getBuilder();
        AddModuleWizard wizard = new AddModuleWizard(project, gradleFile.getPath(), new ProjectImportProvider[]{gradleProjectImportProvider});
        if (wizard.getStepCount() == 0 || wizard.showAndGet()) {
            gradleProjectImportBuilder.commit(project, (ModifiableModuleModel)null, (ModulesProvider)null);
        }
    }
}
 
Example #4
Source File: MavenToolDelegate.java    From intellij-quarkus with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void processImport(Module module) {
    Project project = module.getProject();
    VirtualFile pomFile = null;
    VirtualFile[] contentRoots = ModuleRootManager.getInstance(module).getContentRoots();
    for(VirtualFile contentRoot : contentRoots) {
        VirtualFile child = contentRoot.findChild("pom.xml");
        if (child != null) {
            pomFile = child;
            break;
        }
    }

    if (pomFile != null) {
        MavenProjectsManager mavenProjectsManager = MavenProjectsManager.getInstance(project);
        mavenProjectsManager.addManagedFiles(Collections.singletonList(pomFile));
    }
}
 
Example #5
Source File: AbstractConfigSource.java    From intellij-quarkus with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Returns the target/classes/$configFile and null otherwise.
 * 
 * <p>
 * Using this file instead of using src/main/resources/$configFile gives the
 * capability to get the filtered value.
 * </p>
 * 
 * @return the target/classes/$configFile and null otherwise.
 */
private VirtualFile getConfigFile() {
	if (configFile != null && configFile.exists()) {
		return configFile;
	}
	if (javaProject.isLoaded()) {
		VirtualFile[] sourceRoots = ModuleRootManager.getInstance(javaProject).getSourceRoots();
		for (VirtualFile sourceRoot : sourceRoots) {
			VirtualFile file = sourceRoot.findFileByRelativePath(configFileName);
			if (file != null && file.exists()) {
				return file;
			}
		}
		return null;
	}
	return null;
}
 
Example #6
Source File: ModuleLayerWidget.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
private ListWithSelection<String> getLayers() {
  VirtualFile file = getSelectedFile();
  Project project = getProject();

  Module moduleForFile = file == null ? null : ModuleUtilCore.findModuleForFile(file, project);
  if (moduleForFile == null) {
    return null;
  }

  ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(moduleForFile);
  Map<String, ModuleRootLayer> layers = moduleRootManager.getLayers();
  if (layers.size() == 1) {
    return null;
  }
  String currentLayerName = moduleRootManager.getCurrentLayerName();

  return new ListWithSelection<>(layers.keySet(), currentLayerName);
}
 
Example #7
Source File: PubRoot.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Returns true if the project has a module for the "android" directory.
 */
public boolean hasAndroidModule(Project project) {
  final VirtualFile androidDir = getAndroidDir();
  if (androidDir == null) {
    return false;
  }

  for (Module module : ModuleManager.getInstance(project).getModules()) {
    for (VirtualFile contentRoot : ModuleRootManager.getInstance(module).getContentRoots()) {
      if (contentRoot.equals(androidDir)) {
        return true;
      }
    }
  }
  return false;
}
 
Example #8
Source File: UnmarkRootAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
public boolean canUnmark(AnActionEvent e) {
  Module module = e.getData(LangDataKeys.MODULE);
  VirtualFile[] vFiles = e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY);
  if (module == null || vFiles == null) {
    return false;
  }
  ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);
  final ContentEntry[] contentEntries = moduleRootManager.getContentEntries();

  for (VirtualFile vFile : vFiles) {
    if (!vFile.isDirectory()) {
      continue;
    }

    for (ContentEntry contentEntry : contentEntries) {
      for (ContentFolder contentFolder : contentEntry.getFolders(ContentFolderScopes.all())) {
        if (Comparing.equal(contentFolder.getFile(), vFile)) {
          return true;
        }
      }
    }
  }
  return false;
}
 
Example #9
Source File: AbstractLibraryManager.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
protected static void removeFlutterLibraryDependency(@NotNull Module module, @NotNull Library library) {
  final ModifiableRootModel modifiableModel = ModuleRootManager.getInstance(module).getModifiableModel();

  try {
    boolean wasFound = false;

    for (final OrderEntry orderEntry : modifiableModel.getOrderEntries()) {
      if (orderEntry instanceof LibraryOrderEntry &&
          LibraryTablesRegistrar.PROJECT_LEVEL.equals(((LibraryOrderEntry)orderEntry).getLibraryLevel()) &&
          StringUtil.equals(library.getName(), ((LibraryOrderEntry)orderEntry).getLibraryName())) {
        wasFound = true;
        modifiableModel.removeOrderEntry(orderEntry);
      }
    }

    if (wasFound) {
      ApplicationManager.getApplication().invokeAndWait(() -> WriteAction.run(modifiableModel::commit));
    }
  }
  finally {
    if (!modifiableModel.isDisposed()) {
      modifiableModel.dispose();
    }
  }
}
 
Example #10
Source File: ProjectHelper.java    From r2m-plugin-android with Apache License 2.0 6 votes vote down vote up
private static List<String> getLibrariesName(Project project) {
    Module[] modules = ModuleManager.getInstance(project).getModules();
    final List<String> libraryNames = new ArrayList<String>();


    for (Module module : modules) {
        ModuleRootManager.getInstance(module).orderEntries().forEachLibrary(new Processor<Library>() {
            @Override
            public boolean process(Library library) {
                libraryNames.add(library.getName());
                return true;
            }
        });
    }
    return libraryNames;
}
 
Example #11
Source File: AbstractFileProcessor.java    From consulo with Apache License 2.0 6 votes vote down vote up
protected static void findFiles(final Module module, final List<PsiFile> files) {
  final ModuleFileIndex idx = ModuleRootManager.getInstance(module).getFileIndex();

  final VirtualFile[] roots = ModuleRootManager.getInstance(module).getContentRoots();

  for (VirtualFile root : roots) {
    idx.iterateContentUnderDirectory(root, new ContentIterator() {
      public boolean processFile(final VirtualFile dir) {
        if (dir.isDirectory()) {
          final PsiDirectory psiDir = PsiManager.getInstance(module.getProject()).findDirectory(dir);
          if (psiDir != null) {
            findFiles(files, psiDir, false);
          }
        }
        return true;
      }
    });
  }
}
 
Example #12
Source File: HaxeModuleUtil.java    From intellij-haxe with Apache License 2.0 6 votes vote down vote up
/**
 * Attempt to locate a file in the module directories that may not be a direct source
 * file (like the .hxml files).  If the given file is absolute, then module (.iml) directory,
 * source and classpaths will not be searched.
 *
 * @param module
 * @param haxeProjectPath
 * @return
 */

@Nullable
private VirtualFile locateModuleFile(Module module, String haxeProjectPath) {
  // Try to find the file.  If it's absolute, we either get it the first time or give up.
  VirtualFile projectFile = HaxeFileUtil.locateFile(haxeProjectPath);
  if ( ! HaxeFileUtil.isAbsolutePath(haxeProjectPath)) {
    if (null == projectFile) {
      ModuleRootManager rootMgr = ModuleRootManager.getInstance(module);
      projectFile = HaxeFileUtil.locateFile(haxeProjectPath, rootMgr.getSourceRootUrls());
    }
    if (null == projectFile) {
      projectFile = HaxeFileUtil.locateFile(haxeProjectPath, module.getModuleFilePath());
    }
  }
  return projectFile;
}
 
Example #13
Source File: ResourceFileUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
public static VirtualFile findResourceFile(final String name, final Module inModule) {
  final VirtualFile[] sourceRoots = ModuleRootManager.getInstance(inModule).getContentFolderFiles(ContentFolderScopes.productionAndTest());
  final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(inModule.getProject()).getFileIndex();
  for (final VirtualFile sourceRoot : sourceRoots) {
    final String packagePrefix = fileIndex.getPackageNameByDirectory(sourceRoot);
    final String prefix = packagePrefix == null || packagePrefix.isEmpty() ? null : packagePrefix.replace('.', '/') + "/";
    final String relPath = prefix != null && name.startsWith(prefix) && name.length() > prefix.length() ? name.substring(prefix.length()) : name;
    final String fullPath = sourceRoot.getPath() + "/" + relPath;
    final VirtualFile fileByPath = LocalFileSystem.getInstance().findFileByPath(fullPath);
    if (fileByPath != null) {
      return fileByPath;
    }
  }
  return null;
}
 
Example #14
Source File: XQueryRunProfileState.java    From intellij-xquery with Apache License 2.0 6 votes vote down vote up
private Sdk getJdkToRunModule(Module module) {
    final Sdk moduleSdk = ModuleRootManager.getInstance(module).getSdk();
    if (moduleSdk == null) {
        return null;
    }

    final Set<Sdk> sdksFromDependencies = new LinkedHashSet<>();
    OrderEnumerator enumerator = OrderEnumerator.orderEntries(module).runtimeOnly().recursively();
    enumerator = enumerator.productionOnly();
    enumerator.forEachModule(module1 -> {
        Sdk sdk = ModuleRootManager.getInstance(module1).getSdk();
        if (sdk != null && sdk.getSdkType().equals(moduleSdk.getSdkType())) {
            sdksFromDependencies.add(sdk);
        }
        return true;
    });
    return findLatestVersion(moduleSdk, sdksFromDependencies);
}
 
Example #15
Source File: AbstractLibraryManager.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
protected static void addFlutterLibraryDependency(@NotNull Module module, @NotNull Library library) {
  final ModifiableRootModel modifiableModel = ModuleRootManager.getInstance(module).getModifiableModel();

  try {
    for (final OrderEntry orderEntry : modifiableModel.getOrderEntries()) {
      if (orderEntry instanceof LibraryOrderEntry &&
          LibraryTablesRegistrar.PROJECT_LEVEL.equals(((LibraryOrderEntry)orderEntry).getLibraryLevel()) &&
          StringUtil.equals(library.getName(), ((LibraryOrderEntry)orderEntry).getLibraryName())) {
        return; // dependency already exists
      }
    }

    modifiableModel.addLibraryEntry(library);

    ApplicationManager.getApplication().invokeAndWait(() -> WriteAction.run(modifiableModel::commit));
  }
  finally {
    if (!modifiableModel.isDisposed()) {
      modifiableModel.dispose();
    }
  }
}
 
Example #16
Source File: AbstractLibraryManager.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
protected static void removeFlutterLibraryDependency(@NotNull Module module, @NotNull Library library) {
  final ModifiableRootModel modifiableModel = ModuleRootManager.getInstance(module).getModifiableModel();

  try {
    boolean wasFound = false;

    for (final OrderEntry orderEntry : modifiableModel.getOrderEntries()) {
      if (orderEntry instanceof LibraryOrderEntry &&
          LibraryTablesRegistrar.PROJECT_LEVEL.equals(((LibraryOrderEntry)orderEntry).getLibraryLevel()) &&
          StringUtil.equals(library.getName(), ((LibraryOrderEntry)orderEntry).getLibraryName())) {
        wasFound = true;
        modifiableModel.removeOrderEntry(orderEntry);
      }
    }

    if (wasFound) {
      ApplicationManager.getApplication().invokeAndWait(() -> WriteAction.run(modifiableModel::commit));
    }
  }
  finally {
    if (!modifiableModel.isDisposed()) {
      modifiableModel.dispose();
    }
  }
}
 
Example #17
Source File: DirectoryPathMatcher.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
private static List<Pair<VirtualFile, String>> getProjectRoots(GotoFileModel model) {
  Set<VirtualFile> roots = new HashSet<>();
  for (Module module : ModuleManager.getInstance(model.getProject()).getModules()) {
    Collections.addAll(roots, ModuleRootManager.getInstance(module).getContentRoots());
    for (OrderEntry entry : ModuleRootManager.getInstance(module).getOrderEntries()) {
      if (entry instanceof OrderEntryWithTracking) {
        Collections.addAll(roots, entry.getFiles(OrderRootType.CLASSES));
        Collections.addAll(roots, entry.getFiles(OrderRootType.SOURCES));
      }
    }
  }
  return roots.stream().map(root -> {
    VirtualFile top = model.getTopLevelRoot(root);
    return top != null ? top : root;
  }).distinct().map(r -> Pair.create(r, StringUtil.notNullize(model.getFullName(r)))).collect(Collectors.toList());
}
 
Example #18
Source File: ProtostuffPluginController.java    From protobuf-jetbrains-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * Add global protobuf library to given module. Visible for testing.
 */
public void addLibrary(Module module) {
    ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);
    ModifiableRootModel modifiableRootModel = moduleRootManager.getModifiableModel();
    AtomicBoolean found = new AtomicBoolean(false);
    OrderEnumerator.orderEntries(module).forEachLibrary(library1 -> {
        if (LIB_NAME.equals(library1.getName())) {
            found.set(true);
            return false;
        }
        return true;
    });
    if (!found.get()) {
        ApplicationManager.getApplication().runWriteAction(() -> {
            modifiableRootModel.addLibraryEntry(globalLibrary);
            modifiableRootModel.commit();
        });
    }
}
 
Example #19
Source File: FieldReferenceProviderImpl.java    From protobuf-jetbrains-plugin with Apache License 2.0 6 votes vote down vote up
@Nullable
private PsiFile loadInMemoryDescriptorProto() {
    if (inm == null) {
        for (Module module : ModuleManager.getInstance(project).getModules()) {
            ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);
            VirtualFile[] allSourceRoots = moduleRootManager.orderEntries().getAllSourceRoots();
            for (VirtualFile allSourceRoot : allSourceRoots) {
                PsiDirectory directory = PsiManager.getInstance(project).findDirectory(allSourceRoot);
                if (directory != null && directory.isValid()) {
                    String relPath = "google/protobuf/descriptor.proto";
                    VirtualFile file = directory.getVirtualFile().findFileByRelativePath(relPath);
                    if (file != null) {
                        PsiManager psiManager = PsiManager.getInstance(project);
                        PsiFile psiFile = psiManager.findFile(file);
                        if (psiFile instanceof ProtoPsiFileRoot) {
                            inm = psiFile;
                            return (ProtoPsiFileRoot) psiFile;
                        }
                    }
                }
            }
        }
    }
    return inm;
}
 
Example #20
Source File: PubRootCache.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@NotNull
public List<PubRoot> getRoots(Module module) {
  final List<PubRoot> result = new ArrayList<>();

  for (VirtualFile dir : ModuleRootManager.getInstance(module).getContentRoots()) {
    PubRoot root = cache.get(dir);

    if (root == null) {
      cache.put(dir, PubRoot.forDirectory(dir));
      root = cache.get(dir);
    }

    if (root != null) {
      result.add(root);
    }
  }

  return result;
}
 
Example #21
Source File: AddUsingAction.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@RequiredUIAccess
private void execute0(final NamespaceReference namespaceReference)
{
	PsiDocumentManager.getInstance(myProject).commitAllDocuments();

	WriteCommandAction.runWriteCommandAction(myProject, () ->
	{
		addUsing(namespaceReference.getNamespace());

		String libraryName = namespaceReference.getLibraryName();
		if(libraryName != null)
		{
			Module moduleForFile = ModuleUtilCore.findModuleForPsiElement(myFile);
			if(moduleForFile != null)
			{
				ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(moduleForFile);

				final ModifiableRootModel modifiableModel = moduleRootManager.getModifiableModel();

				modifiableModel.addOrderEntry(new DotNetLibraryOrderEntryImpl((ModuleRootLayerImpl) moduleRootManager.getCurrentLayer(), libraryName));

				WriteAction.run(modifiableModel::commit);
			}
		}
	});
}
 
Example #22
Source File: RunAnythingContext.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
private static String calcDescription(Module module) {
  String basePath = module.getProject().getBasePath();
  if (basePath != null) {
    String modulePath = module.getModuleDirPath();
    if (modulePath == null) {
      VirtualFile[] contentRoots = ModuleRootManager.getInstance(module).getContentRoots();
      if (contentRoots.length == 1) {
        modulePath = contentRoots[0].getPath();
      }
    }

    if (modulePath != null) {
      String relativePath = FileUtil.getRelativePath(basePath, modulePath, '/');
      if (relativePath != null) {
        return relativePath;
      }
    }
  }
  return "undefined";
}
 
Example #23
Source File: RoboVmPlugin.java    From robovm-idea with GNU General Public License v2.0 6 votes vote down vote up
public static boolean isRoboVmModule(Module module) {
    // HACK! to identify if the module uses a robovm sdk
    if (ModuleRootManager.getInstance(module).getSdk() != null) {
        if (ModuleRootManager.getInstance(module).getSdk().getSdkType().getName().toLowerCase().contains("robovm")) {
            return true;
        }
    }

    // check if there's any RoboVM RT libs in the classpath
    OrderEnumerator classes = ModuleRootManager.getInstance(module).orderEntries().recursively().withoutSdk().compileOnly();
    for (String path : classes.getPathsList().getPathList()) {
        if (isSdkLibrary(path)) {
            return true;
        }
    }

    // check if there's a robovm.xml file in the root of the module
    for(VirtualFile file: ModuleRootManager.getInstance(module).getContentRoots()) {
        if(file.findChild("robovm.xml") != null) {
            return true;
        }
    }

    return false;
}
 
Example #24
Source File: GradleToolDelegate.java    From intellij-quarkus with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public List<VirtualFile>[] getDeploymentFiles(Module module) {
    List<VirtualFile>[] result = ToolDelegate.initDeploymentFiles();
    ModuleRootManager manager = ModuleRootManager.getInstance(module);
    Set<String> deploymentIds = new HashSet<>();
    try {
        manager.orderEntries().forEachLibrary(library -> {
            processLibrary(library, manager, deploymentIds);
            return true;
        });
        if (!deploymentIds.isEmpty()) {
            processDownload(module, deploymentIds, result);
        }
    } catch (IOException e) {
        LOGGER.error(e.getLocalizedMessage(), e);
    }
    return result;
}
 
Example #25
Source File: FlutterConsoleFilter.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@VisibleForTesting
@Nullable
public VirtualFile fileAtPath(@NotNull String pathPart) {
  // "lib/main.dart:6"
  pathPart = pathPart.split(":")[0];

  // We require the pathPart reference to be a file reference, otherwise we'd match things like
  // "Build: Running build completed, took 191ms".
  if (pathPart.indexOf('.') == -1) {
    return null;
  }

  final VirtualFile[] roots = ModuleRootManager.getInstance(module).getContentRoots();
  for (VirtualFile root : roots) {
    if (!pathPart.isEmpty()) {
      final String baseDirPath = root.getPath();
      final String path = baseDirPath + "/" + pathPart;
      VirtualFile file = findFile(path);
      if (file == null) {
        // check example dir too
        // TODO(pq): remove when `example` is a content root: https://github.com/flutter/flutter-intellij/issues/2519
        final String exampleDirRelativePath = baseDirPath + "/example/" + pathPart;
        file = findFile(exampleDirRelativePath);
      }
      if (file != null) {
        return file;
      }
    }
  }

  return null;
}
 
Example #26
Source File: HaxelibClasspathUtils.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
/**
 * Get the classpath for the given module.  This does not include any
 * paths from projects or SDKs.
 *
 * @param module to look up haxelib for.
 * @return a (possibly empty) collection of classpaths.  These are NOT
 *         necessarily properly ordered, but they are unique.
 */
@NotNull
public static HaxeClasspath getModuleClasspath(@NotNull Module module) {
  ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
  if (null == rootManager) return HaxeClasspath.EMPTY_CLASSPATH;

  ModifiableRootModel rootModel = rootManager.getModifiableModel();
  LibraryTable libraryTable = rootModel.getModuleLibraryTable();
  HaxeClasspath moduleClasspath = loadClasspathFrom(libraryTable);
  rootModel.dispose();    // MUST dispose of the model.
  return moduleClasspath;
}
 
Example #27
Source File: ModuleVcsDetector.java    From consulo with Apache License 2.0 5 votes vote down vote up
private List<Pair<String, VcsDirectoryMapping>> getMappings(final Module module) {
  List<Pair<String, VcsDirectoryMapping>> result = new ArrayList<Pair<String, VcsDirectoryMapping>>();
  final VirtualFile[] files = ModuleRootManager.getInstance(module).getContentRoots();
  final String moduleName = module.getName();
  for(final VirtualFile file: files) {
    for(final VcsDirectoryMapping mapping: myVcsManager.getDirectoryMappings()) {
      if (FileUtil.toSystemIndependentName(mapping.getDirectory()).equals(file.getPath())) {
        result.add(new Pair<String, VcsDirectoryMapping>(moduleName, mapping));
        break;
      }
    }
  }
  return result;
}
 
Example #28
Source File: ArtifactsTestCase.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
@Nonnull
public ModifiableRootModel getOrCreateModifiableRootModel(@Nonnull Module module) {
  ModifiableRootModel model = myModifiableRootModels.get(module);
  if (model == null) {
    model = ModuleRootManager.getInstance(module).getModifiableModel();
    myModifiableRootModels.put(module, model);
  }
  return model;
}
 
Example #29
Source File: BlazeSyncIntegrationTestCase.java    From intellij with Apache License 2.0 5 votes vote down vote up
/** The workspace content entries created during sync */
protected ImmutableList<ContentEntry> getWorkspaceContentEntries() {
  if (moduleMocker != null) {
    return moduleMocker.getWorkspaceContentEntries();
  }

  ModuleManager moduleManager = ModuleManager.getInstance(getProject());
  Module workspaceModule = moduleManager.findModuleByName(BlazeDataStorage.WORKSPACE_MODULE_NAME);
  assertThat(workspaceModule).isNotNull();

  ContentEntry[] entries = ModuleRootManager.getInstance(workspaceModule).getContentEntries();
  return ImmutableList.copyOf(entries);
}
 
Example #30
Source File: ModuleVcsDetector.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void autoDetectModuleVcsMapping(final Module module) {
  boolean mappingsUpdated = false;
  final VirtualFile[] files = ModuleRootManager.getInstance(module).getContentRoots();
  for(VirtualFile file: files) {
    AbstractVcs vcs = myVcsManager.findVersioningVcs(file);
    if (vcs != null && vcs != myVcsManager.getVcsFor(file)) {
      myVcsManager.setAutoDirectoryMapping(file.getPath(), vcs.getName());
      mappingsUpdated = true;
    }
  }
  if (mappingsUpdated) {
    myVcsManager.cleanupMappings();
  }
}