use of com.intellij.ide.util.projectWizard.importSources.DetectedSourceRoot in project intellij-elixir by KronicDeth.
the class ElixirProjectStructureDetector method setupProjectStructure.
/**
* This detector just for import non-organization project which not like mix-project
* So that it's no need to detect directories such as libs, deps, tests etc
*
* And mix-project will imported by the MixProjectImportBuilder.java
* */
@Override
public void setupProjectStructure(@NotNull Collection<DetectedProjectRoot> roots, @NotNull ProjectDescriptor projectDescriptor, @NotNull ProjectFromSourcesBuilder builder) {
if (!roots.isEmpty() && !builder.hasRootsFromOtherDetectors(this)) {
List<ModuleDescriptor> modules = projectDescriptor.getModules();
if (modules.isEmpty()) {
modules = new ArrayList<ModuleDescriptor>();
for (DetectedProjectRoot root : roots) {
modules.add(new ModuleDescriptor(root.getDirectory(), ElixirModuleType.getInstance(), ContainerUtil.<DetectedSourceRoot>emptyList()));
}
projectDescriptor.setModules(modules);
}
}
}
use of com.intellij.ide.util.projectWizard.importSources.DetectedSourceRoot in project intellij-community by JetBrains.
the class ModuleInsight method splitModule.
@Nullable
public ModuleDescriptor splitModule(final ModuleDescriptor descriptor, String newModuleName, final Collection<File> contentsToExtract) {
ModuleDescriptor newModule = null;
for (File root : contentsToExtract) {
final Collection<DetectedSourceRoot> sources = descriptor.removeContentRoot(root);
if (newModule == null) {
newModule = createModuleDescriptor(root, sources != null ? sources : new HashSet<>());
} else {
if (sources != null && sources.size() > 0) {
for (DetectedSourceRoot source : sources) {
newModule.addSourceRoot(root, source);
}
} else {
newModule.addContentRoot(root);
}
}
}
if (newModule != null) {
newModule.setName(newModuleName);
myModules.add(newModule);
} else {
return null;
}
final Map<File, ModuleDescriptor> contentRootToModule = new HashMap<>();
for (ModuleDescriptor module : myModules) {
final Set<File> roots = module.getContentRoots();
for (File root : roots) {
contentRootToModule.put(root, module);
}
module.clearModuleDependencies();
module.clearLibraryFiles();
}
buildModuleDependencies(contentRootToModule);
return newModule;
}
use of com.intellij.ide.util.projectWizard.importSources.DetectedSourceRoot in project intellij-community by JetBrains.
the class ModuleInsight method appendContentRoot.
private static File appendContentRoot(final ModuleDescriptor module, final File contentRoot) {
final Set<File> moduleRoots = module.getContentRoots();
for (File moduleRoot : moduleRoots) {
if (FileUtil.isAncestor(moduleRoot, contentRoot, false)) {
// no need to include a separate root
return moduleRoot;
}
if (FileUtil.isAncestor(contentRoot, moduleRoot, true)) {
final Collection<DetectedSourceRoot> currentSources = module.getSourceRoots(moduleRoot);
module.removeContentRoot(moduleRoot);
module.addContentRoot(contentRoot);
for (DetectedSourceRoot source : currentSources) {
module.addSourceRoot(contentRoot, source);
}
// no need to include a separate root
return contentRoot;
}
}
module.addContentRoot(contentRoot);
return contentRoot;
}
use of com.intellij.ide.util.projectWizard.importSources.DetectedSourceRoot in project intellij-community by JetBrains.
the class RootDetectionProcessor method mergeContentRoots.
private List<DetectedRootData> mergeContentRoots(Map<File, DetectedRootData> rootData) {
LOG.debug(rootData.size() + " roots found, merging content roots");
boolean hasSourceRoots = false;
Set<ModuleType> typesToReplace = new HashSet<>();
Set<ModuleType> moduleTypes = new HashSet<>();
for (DetectedRootData data : rootData.values()) {
for (DetectedProjectRoot root : data.getAllRoots()) {
if (root instanceof DetectedContentRoot) {
Collections.addAll(typesToReplace, ((DetectedContentRoot) root).getTypesToReplace());
moduleTypes.add(((DetectedContentRoot) root).getModuleType());
} else if (root instanceof DetectedSourceRoot) {
LOG.debug("Source root found: " + root.getDirectory() + ", content roots will be ignored");
hasSourceRoots = true;
break;
}
}
}
moduleTypes.removeAll(typesToReplace);
if (hasSourceRoots || moduleTypes.size() <= 1) {
Iterator<DetectedRootData> iterator = rootData.values().iterator();
DetectedContentRoot firstRoot = null;
ProjectStructureDetector firstDetector = null;
while (iterator.hasNext()) {
DetectedRootData data = iterator.next();
for (DetectedProjectRoot root : data.getAllRoots()) {
if (root instanceof DetectedContentRoot) {
LOG.debug("Removed detected " + root.getRootTypeName() + " content root: " + root.getDirectory());
Collection<ProjectStructureDetector> detectors = data.removeRoot(root);
if ((firstRoot == null || firstDetector == null) && moduleTypes.contains(((DetectedContentRoot) root).getModuleType())) {
firstRoot = (DetectedContentRoot) root;
firstDetector = ContainerUtil.getFirstItem(detectors);
}
}
}
if (data.isEmpty()) {
iterator.remove();
}
}
if (!hasSourceRoots && firstRoot != null && firstDetector != null) {
DetectedContentRoot baseRoot = new DetectedContentRoot(myBaseDir, firstRoot.getRootTypeName(), firstRoot.getModuleType());
DetectedRootData data = rootData.get(myBaseDir);
if (data == null) {
rootData.put(myBaseDir, new DetectedRootData(firstDetector, baseRoot));
} else {
data.addRoot(firstDetector, baseRoot);
}
LOG.debug("Added " + firstRoot.getRootTypeName() + " content root for " + myBaseDir);
}
}
return new ArrayList<>(rootData.values());
}
Aggregations