/* * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.jetbrains.python.module; import com.intellij.ide.util.importProject.ProjectDescriptor; import com.intellij.ide.util.projectWizard.ModuleWizardStep; import com.intellij.ide.util.projectWizard.ProjectWizardStepFactory; import com.intellij.ide.util.projectWizard.importSources.DetectedContentRoot; import com.intellij.ide.util.projectWizard.importSources.DetectedProjectRoot; import com.intellij.ide.util.projectWizard.importSources.ProjectFromSourcesBuilder; import com.intellij.ide.util.projectWizard.importSources.ProjectStructureDetector; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.module.WebModuleType; import com.intellij.openapi.util.io.FileUtilRt; import com.jetbrains.python.PythonModuleTypeBase; import org.jetbrains.annotations.NotNull; import javax.swing.*; import java.io.File; import java.util.Collection; import java.util.Collections; import java.util.List; /** * @author yole */ public class PyProjectStructureDetector extends ProjectStructureDetector { private static final Logger LOG = Logger.getInstance("#com.jetbrains.python.module.PyProjectStructureDetector"); @NotNull @Override public DirectoryProcessingResult detectRoots(@NotNull File dir, @NotNull File[] children, @NotNull File base, @NotNull List<DetectedProjectRoot> result) { LOG.info("Detecting roots under " + dir); for (File child : children) { final String name = child.getName(); if (FileUtilRt.extensionEquals(name, "py")) { LOG.info("Found Python file " + child.getPath()); result.add(new DetectedContentRoot(dir, "Python", PythonModuleTypeBase.getInstance(), WebModuleType.getInstance())); return DirectoryProcessingResult.SKIP_CHILDREN; } if ("node_modules".equals(name)) { return DirectoryProcessingResult.SKIP_CHILDREN; } } return DirectoryProcessingResult.PROCESS_CHILDREN; } @Override public void setupProjectStructure(@NotNull Collection<DetectedProjectRoot> roots, @NotNull ProjectDescriptor projectDescriptor, @NotNull ProjectFromSourcesBuilder builder) { builder.setupModulesByContentRoots(projectDescriptor, roots); } @Override public List<ModuleWizardStep> createWizardSteps(ProjectFromSourcesBuilder builder, ProjectDescriptor projectDescriptor, Icon stepIcon) { return Collections.singletonList(ProjectWizardStepFactory.getInstance().createProjectJdkStep(builder.getContext())); } }