use of com.intellij.ide.util.projectWizard.importSources.ProjectStructureDetector in project intellij-community by JetBrains.
the class RootDetectionProcessor method detectRoots.
private List<DetectedRootData> detectRoots() {
Map<ProjectStructureDetector, List<DetectedProjectRoot>> roots = runDetectors();
if (myProgressIndicator != null) {
myProgressIndicator.setText2("Processing " + roots.values().size() + " project roots...");
}
Map<File, DetectedRootData> rootData = new LinkedHashMap<>();
for (ProjectStructureDetector detector : roots.keySet()) {
for (DetectedProjectRoot detectedRoot : roots.get(detector)) {
if (isUnderIncompatibleRoot(detectedRoot, rootData)) {
continue;
}
final DetectedRootData data = rootData.get(detectedRoot.getDirectory());
if (data == null) {
rootData.put(detectedRoot.getDirectory(), new DetectedRootData(detector, detectedRoot));
} else {
detectedRoot = data.addRoot(detector, detectedRoot);
}
removeIncompatibleRoots(detectedRoot, rootData);
}
}
List<DetectedRootData> dataCollection = mergeContentRoots(rootData);
if (myProgressIndicator != null) {
myProgressIndicator.setText2("");
}
return dataCollection;
}
use of com.intellij.ide.util.projectWizard.importSources.ProjectStructureDetector in project intellij-community by JetBrains.
the class CreateFromSourcesMode method addSteps.
public void addSteps(WizardContext context, ModulesProvider modulesProvider, StepSequence sequence, String specific) {
final ProjectFromSourcesBuilderImpl projectBuilder = new ProjectFromSourcesBuilderImpl(context, modulesProvider);
myProjectBuilder = projectBuilder;
final Icon icon = context.getStepIcon();
if (context.isCreatingNewProject()) {
addStep(sequence, new ProjectNameStep(context, this), specific);
}
addStep(sequence, new RootsDetectionStep(projectBuilder, context, sequence, icon, "reference.dialogs.new.project.fromCode.source"), specific);
Set<String> detectorTypes = new HashSet<>();
for (ProjectStructureDetector detector : ProjectStructureDetector.EP_NAME.getExtensions()) {
detectorTypes.add(detector.getDetectorId());
for (ModuleWizardStep step : detector.createWizardSteps(projectBuilder, projectBuilder.getProjectDescriptor(detector), icon)) {
sequence.addSpecificStep(detector.getDetectorId(), step);
}
}
if (FrameworkDetectionStep.isEnabled()) {
FrameworkDetectionStep frameworkDetectionStep = new FrameworkDetectionStep(icon, projectBuilder) {
public List<ModuleDescriptor> getModuleDescriptors() {
final List<ModuleDescriptor> moduleDescriptors = new ArrayList<>();
for (ProjectDescriptor descriptor : projectBuilder.getSelectedDescriptors()) {
moduleDescriptors.addAll(descriptor.getModules());
}
return moduleDescriptors;
}
};
projectBuilder.addConfigurationUpdater(frameworkDetectionStep);
sequence.addCommonFinishingStep(frameworkDetectionStep, detectorTypes);
}
}
use of com.intellij.ide.util.projectWizard.importSources.ProjectStructureDetector in project android by JetBrains.
the class AndroidProjectStructureDetector method setupProjectStructure.
@Override
public void setupProjectStructure(@NotNull Collection<DetectedProjectRoot> roots, @NotNull ProjectDescriptor projectDescriptor, @NotNull ProjectFromSourcesBuilder builder) {
final List<File> existingRoots = new ArrayList<File>();
for (ProjectStructureDetector detector : ProjectStructureDetector.EP_NAME.getExtensions()) {
if (detector != this) {
for (DetectedProjectRoot root : builder.getProjectRoots(detector)) {
existingRoots.add(root.getDirectory());
}
}
}
final List<ModuleDescriptor> modules = new ArrayList<ModuleDescriptor>();
for (DetectedProjectRoot root : roots) {
final File dir = root.getDirectory();
boolean javaSrcRootInside = false;
for (File javaSourceRoot : existingRoots) {
if (FileUtil.isAncestor(dir, javaSourceRoot, false)) {
javaSrcRootInside = true;
}
}
if (!javaSrcRootInside) {
modules.add(new ModuleDescriptor(root.getDirectory(), JavaModuleType.getModuleType(), Collections.<DetectedSourceRoot>emptyList()));
}
}
projectDescriptor.setModules(modules);
}
use of com.intellij.ide.util.projectWizard.importSources.ProjectStructureDetector 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.ProjectStructureDetector in project intellij-community by JetBrains.
the class RootsDetectionStep method updateSelectedTypes.
private void updateSelectedTypes() {
Set<String> selectedTypes = new LinkedHashSet<>();
selectedTypes.add("Existing Sources");
for (DetectedRootData rootData : myDetectedRootsChooser.getMarkedElements()) {
for (ProjectStructureDetector detector : rootData.getSelectedDetectors()) {
selectedTypes.add(detector.getDetectorId());
}
}
mySequence.setTypes(selectedTypes);
myContext.requestWizardButtonsUpdate();
}
Aggregations