Search in sources :

Example 26 with ProjectRootManager

use of com.intellij.openapi.roots.ProjectRootManager in project liferay-ide by liferay.

the class DeployGradleModuleAction method getWorkingDirectory.

@Override
protected String getWorkingDirectory(AnActionEvent event) {
    VirtualFile virtualFile = getVirtualFile(event);
    ProjectRootManager projectRootManager = ProjectRootManager.getInstance(event.getProject());
    ProjectFileIndex projectFileIndex = projectRootManager.getFileIndex();
    Module module = projectFileIndex.getModuleForFile(virtualFile);
    ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);
    ModifiableRootModel modifiableRootModel = moduleRootManager.getModifiableModel();
    VirtualFile[] roots = modifiableRootModel.getContentRoots();
    assert roots != null && roots[0] != null;
    return roots[0].getCanonicalPath();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) Module(com.intellij.openapi.module.Module) ProjectRootManager(com.intellij.openapi.roots.ProjectRootManager)

Example 27 with ProjectRootManager

use of com.intellij.openapi.roots.ProjectRootManager in project checkstyle-idea by jshiell.

the class ScanProject method update.

@Override
public void update(final AnActionEvent event) {
    super.update(event);
    try {
        final Presentation presentation = event.getPresentation();
        final Project project = DataKeys.PROJECT.getData(event.getDataContext());
        if (project == null) {
            // check if we're loading...
            presentation.setEnabled(false);
            return;
        }
        final CheckStylePlugin checkStylePlugin = project.getComponent(CheckStylePlugin.class);
        if (checkStylePlugin == null) {
            throw new IllegalStateException("Couldn't get checkstyle plugin");
        }
        final ScanScope scope = checkStylePlugin.configurationManager().getCurrent().getScanScope();
        VirtualFile[] sourceRoots = null;
        if (scope == ScanScope.Everything) {
            sourceRoots = new VirtualFile[] { project.getBaseDir() };
        } else {
            final ProjectRootManager projectRootManager = ProjectRootManager.getInstance(project);
            sourceRoots = projectRootManager.getContentSourceRoots();
        }
        // disable if no files are selected or scan in progress
        if (containsAtLeastOneFile(sourceRoots)) {
            presentation.setEnabled(!checkStylePlugin.isScanInProgress());
        } else {
            presentation.setEnabled(false);
        }
    } catch (Throwable e) {
        CheckStylePlugin.processErrorAndLog("Project button update", e);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) ScanScope(org.infernus.idea.checkstyle.model.ScanScope) Presentation(com.intellij.openapi.actionSystem.Presentation) ProjectRootManager(com.intellij.openapi.roots.ProjectRootManager) CheckStylePlugin(org.infernus.idea.checkstyle.CheckStylePlugin)

Example 28 with ProjectRootManager

use of com.intellij.openapi.roots.ProjectRootManager in project moe-ide-integration by multi-os-engine.

the class MOEModuleBuilder method setupRootModel.

@Override
public void setupRootModel(final ModifiableRootModel rootModel) throws ConfigurationException {
    Project project = rootModel.getProject();
    Module module = rootModel.getModule();
    myJdk = MOESdkType.getJDK();
    ProjectRootManager.getInstance(project).setProjectSdk(myJdk);
    rootModel.getModuleExtension(LanguageLevelModuleExtension.class).setLanguageLevel(MOESdkType.REQUIRED_JAVA_LANGUAGE_LEVEL);
    super.setupRootModel(rootModel);
    ProjectRootManager projectRootManager = ProjectRootManager.getInstance(project);
    String projectPath = rootModel.getProject().getBasePath();
    String contentEntryPath = getContentEntryPath();
    if (contentEntryPath == null || contentEntryPath.isEmpty()) {
        throw new RuntimeException("Can't get content entry path.");
    }
    VirtualFile contentRoot = LocalFileSystem.getInstance().findFileByIoFile(new File(contentEntryPath));
    try {
        createModule(contentRoot, project);
    } catch (MOEProjectComposer.MOEProjectComposerException e) {
        throw new ConfigurationException(e.getMessage());
    }
    VirtualFile[] contentFiles = new VirtualFile[] { contentRoot };
    VfsUtil.markDirtyAndRefresh(false, true, true, contentFiles);
    new ReformatCodeProcessor(project, module, false).run();
    String resourcePath = "src/main/" + MOESdkPlugin.getResourcesFolderName();
    String sourcePath = "src/main/java";
    for (ContentEntry entry : rootModel.getContentEntries()) {
        for (SourceFolder srcFolder : entry.getSourceFolders()) {
            entry.removeSourceFolder(srcFolder);
        }
        VirtualFile sourceFile = null;
        if (contentRoot != null) {
            sourceFile = contentRoot.findFileByRelativePath(sourcePath);
        }
        if (sourceFile != null) {
            entry.addSourceFolder(sourceFile, false);
        }
        VirtualFile resourceFolder = null;
        if (contentRoot != null) {
            resourceFolder = contentRoot.findFileByRelativePath(resourcePath);
        }
        if (resourceFolder != null && resourceFolder.exists()) {
            SourceFolder sourceFolder = entry.addSourceFolder(resourceFolder, JavaResourceRootType.RESOURCE);
            JavaSourceRootProperties properties = sourceFolder.getJpsElement().getProperties(JavaModuleSourceRootTypes.SOURCES);
            if (properties != null) {
                properties.setForGeneratedSources(true);
            }
        }
    }
    try {
        configureGradle(rootModel);
    } catch (IOException e) {
        MOEToolWindow.getInstance(project).error("Error occurred during gradle configuration: " + e.getMessage());
    }
    if (!isNewProject) {
        File settingsGradle = new File(projectPath, "settings.gradle");
        try {
            if (!settingsGradle.exists()) {
                if (!settingsGradle.createNewFile()) {
                    MOEToolWindow.getInstance(project).error("Error occurred during gradle settings file.");
                }
            }
            modifyGradleSettings(settingsGradle, new Module[] { rootModel.getModule() });
        } catch (IOException e) {
            MOEToolWindow.getInstance(project).error("Error occurred during gradle configuration: " + e.getMessage());
        }
    }
    if (contentRoot != null) {
        contentRoot.refresh(false, true);
    }
    Sdk sdk = MOESdkType.getMOESdk(rootModel.getModule());
    if (sdk != null) {
        rootModel.setSdk(sdk);
    } else {
        MOEToolWindow.getInstance(project).error("Error, unable set Sdk.");
    }
    rootModel.getModuleExtension(LanguageLevelModuleExtension.class).setLanguageLevel(MOESdkType.REQUIRED_JAVA_LANGUAGE_LEVEL);
    StartupManager.getInstance(project).runWhenProjectIsInitialized(new Runnable() {

        @Override
        public void run() {
            configureRun(rootModel);
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) MOEProjectComposer(org.moe.generator.project.MOEProjectComposer) ReformatCodeProcessor(com.intellij.codeInsight.actions.ReformatCodeProcessor) IOException(java.io.IOException) JavaSourceRootProperties(org.jetbrains.jps.model.java.JavaSourceRootProperties) Project(com.intellij.openapi.project.Project) SourceFolder(com.intellij.openapi.roots.SourceFolder) ConfigurationException(com.intellij.openapi.options.ConfigurationException) ContentEntry(com.intellij.openapi.roots.ContentEntry) Sdk(com.intellij.openapi.projectRoots.Sdk) Module(com.intellij.openapi.module.Module) LanguageLevelModuleExtension(com.intellij.openapi.roots.LanguageLevelModuleExtension) ProjectRootManager(com.intellij.openapi.roots.ProjectRootManager) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 29 with ProjectRootManager

use of com.intellij.openapi.roots.ProjectRootManager in project qi4j-sdk by Qi4j.

the class GlobalSearchScopeUtil method determineSearchScope.

/**
 * Determine search scope given a psi element.
 *
 * @param psiElement context.
 * @return Search scope given psi class.
 * @since 0.1
 */
@Nullable
public static GlobalSearchScope determineSearchScope(@NotNull PsiElement psiElement) {
    VirtualFile classVirtualFile = getVirtualFile(psiElement);
    if (classVirtualFile == null) {
        return null;
    }
    Module module = findModuleForPsiElement(psiElement);
    if (module == null) {
        return null;
    }
    Project project = psiElement.getProject();
    ProjectRootManager projectRootManager = ProjectRootManager.getInstance(project);
    boolean includeTestClasses = projectRootManager.getFileIndex().isInTestSourceContent(classVirtualFile);
    return module.getModuleWithDependenciesAndLibrariesScope(includeTestClasses);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VirtualFileUtil.getVirtualFile(org.qi4j.ide.plugin.idea.common.vfs.VirtualFileUtil.getVirtualFile) Project(com.intellij.openapi.project.Project) Module(com.intellij.openapi.module.Module) ProjectRootManager(com.intellij.openapi.roots.ProjectRootManager) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

ProjectRootManager (com.intellij.openapi.roots.ProjectRootManager)29 VirtualFile (com.intellij.openapi.vfs.VirtualFile)22 Project (com.intellij.openapi.project.Project)8 Module (com.intellij.openapi.module.Module)7 Sdk (com.intellij.openapi.projectRoots.Sdk)6 NotNull (org.jetbrains.annotations.NotNull)6 Nullable (org.jetbrains.annotations.Nullable)6 ModuleRootManager (com.intellij.openapi.roots.ModuleRootManager)4 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)4 File (java.io.File)4 IncorrectOperationException (com.intellij.util.IncorrectOperationException)3 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)2 NullableComputable (com.intellij.openapi.util.NullableComputable)2 PsiDirectory (com.intellij.psi.PsiDirectory)2 PsiManager (com.intellij.psi.PsiManager)2 PackageWrapper (com.intellij.refactoring.PackageWrapper)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 CheckStylePlugin (org.infernus.idea.checkstyle.CheckStylePlugin)2 ScanScope (org.infernus.idea.checkstyle.model.ScanScope)2