use of com.intellij.ide.util.projectWizard.importSources.DetectedProjectRoot in project intellij-community by JetBrains.
the class ModulesDetectionStep method calcStateHashCode.
private int calcStateHashCode() {
final String contentEntryPath = myBuilder.getBaseProjectPath();
int hash = contentEntryPath != null ? contentEntryPath.hashCode() : 1;
for (DetectedProjectRoot root : myBuilder.getProjectRoots(myDetector)) {
hash = 31 * hash + root.getDirectory().hashCode();
}
final List<LibraryDescriptor> libs = myProjectDescriptor.getLibraries();
for (LibraryDescriptor lib : libs) {
final Collection<File> files = lib.getJars();
for (File file : files) {
hash = 31 * hash + file.hashCode();
}
}
return hash;
}
use of com.intellij.ide.util.projectWizard.importSources.DetectedProjectRoot in project intellij-community by JetBrains.
the class RootDetectionProcessor method isUnderIncompatibleRoot.
private static boolean isUnderIncompatibleRoot(DetectedProjectRoot root, Map<File, DetectedRootData> rootData) {
File directory = root.getDirectory().getParentFile();
while (directory != null) {
final DetectedRootData data = rootData.get(directory);
if (data != null) {
for (DetectedProjectRoot parentRoot : data.getAllRoots()) {
if (!parentRoot.canContainRoot(root)) {
return true;
}
}
}
directory = directory.getParentFile();
}
return false;
}
use of com.intellij.ide.util.projectWizard.importSources.DetectedProjectRoot 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());
}
use of com.intellij.ide.util.projectWizard.importSources.DetectedProjectRoot in project intellij-community by JetBrains.
the class DetectedRootData method addRoot.
public DetectedProjectRoot addRoot(ProjectStructureDetector detector, DetectedProjectRoot root) {
for (Map.Entry<DetectedProjectRoot, Collection<ProjectStructureDetector>> entry : myRoots.entrySet()) {
final DetectedProjectRoot oldRoot = entry.getKey();
final DetectedProjectRoot combined = oldRoot.combineWith(root);
if (combined != null) {
myRoots.remove(oldRoot);
final Set<ProjectStructureDetector> values = new HashSet<>(entry.getValue());
values.add(detector);
myRoots.put(combined, values);
if (mySelectedRoot == oldRoot) {
mySelectedRoot = combined;
}
return combined;
}
}
myRoots.putValue(root, detector);
return root;
}
use of com.intellij.ide.util.projectWizard.importSources.DetectedProjectRoot in project intellij-community by JetBrains.
the class ImportFromSourcesTestCase method importFromSources.
protected void importFromSources(File dir) {
myRootDir = dir;
try {
myProject = doCreateProject(getIprFile());
myBuilder.setBaseProjectPath(dir.getAbsolutePath());
List<DetectedRootData> list = RootDetectionProcessor.detectRoots(dir);
MultiMap<ProjectStructureDetector, DetectedProjectRoot> map = RootDetectionProcessor.createRootsMap(list);
myBuilder.setupProjectStructure(map);
for (ProjectStructureDetector detector : map.keySet()) {
List<ModuleWizardStep> steps = detector.createWizardSteps(myBuilder, myBuilder.getProjectDescriptor(detector), EmptyIcon.ICON_16);
try {
for (ModuleWizardStep step : steps) {
if (step instanceof AbstractStepWithProgress<?>) {
performStep((AbstractStepWithProgress<?>) step);
}
}
} finally {
for (ModuleWizardStep step : steps) {
step.disposeUIResources();
}
}
}
myBuilder.commit(myProject, null, ModulesProvider.EMPTY_MODULES_PROVIDER);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Aggregations