mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-07 22:09:38 +07:00
[IFT] Extract 'markDirectoryAsSourcesRoot' method to ProjectUtils
IJ-CR-18000 GitOrigin-RevId: e895753205b6edf6e848d16afd474b2b7a8cf5f0
This commit is contained in:
committed by
intellij-monorepo-bot
parent
4693a95ce6
commit
8366c14ee9
@@ -1,16 +1,10 @@
|
||||
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.jetbrains.python.ift
|
||||
|
||||
import com.intellij.openapi.application.runWriteAction
|
||||
import com.intellij.openapi.diagnostic.thisLogger
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.roots.ModuleRootManager
|
||||
import com.intellij.openapi.vfs.LocalFileSystem
|
||||
import com.intellij.openapi.vfs.VfsUtilCore
|
||||
import com.jetbrains.python.statistics.modules
|
||||
import training.project.ProjectUtils
|
||||
import training.project.ReadMeCreator
|
||||
import training.util.getFeedbackLink
|
||||
import java.io.File
|
||||
|
||||
class PythonLangSupport : PythonBasedLangSupport() {
|
||||
override val contentRootDirectoryName = "PyCharmLearningProject"
|
||||
@@ -28,31 +22,6 @@ class PythonLangSupport : PythonBasedLangSupport() {
|
||||
override val readMeCreator = ReadMeCreator()
|
||||
|
||||
override fun applyToProjectAfterConfigure(): (Project) -> Unit = { project ->
|
||||
// mark src directory as sources root
|
||||
if (project.modules.size > 1) {
|
||||
thisLogger().error("The learning project has more than one module: ${project.modules.map { it.name }}")
|
||||
}
|
||||
val module = project.modules.first()
|
||||
val sourcesPath = project.basePath!! + '/' + sourcesDirectoryName
|
||||
val sourcesRoot = LocalFileSystem.getInstance().refreshAndFindFileByPath(sourcesPath)
|
||||
if (sourcesRoot == null) {
|
||||
val status = when {
|
||||
!File(sourcesPath).exists() -> "does not exist"
|
||||
File(sourcesPath).isDirectory -> "existed directory"
|
||||
else -> "it is regular file"
|
||||
}
|
||||
error("Failed to find directory with source files: $sourcesPath ($status)")
|
||||
}
|
||||
val rootsModel = ModuleRootManager.getInstance(module).modifiableModel
|
||||
val contentEntry = rootsModel.contentEntries.find {
|
||||
val contentEntryFile = it.file
|
||||
contentEntryFile != null && VfsUtilCore.isAncestor(contentEntryFile, sourcesRoot, false)
|
||||
} ?: error("Failed to find content entry for file: ${sourcesRoot.name}")
|
||||
|
||||
contentEntry.addSourceFolder(sourcesRoot, false)
|
||||
runWriteAction {
|
||||
rootsModel.commit()
|
||||
project.save()
|
||||
}
|
||||
ProjectUtils.markDirectoryAsSourcesRoot(project, sourcesDirectoryName)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user