From e8eb3d476f0b36dfc77ad22202fc732ee55cc6b8 Mon Sep 17 00:00:00 2001 From: Maria Tigina Date: Fri, 1 Dec 2023 21:19:11 +0100 Subject: [PATCH] Add intellij plugin --- build.gradle.kts | 37 +++++++++++- .../courseFrameworkLesson/lesson-info.yaml | 6 -- .../academy/kotlin/template/InvisibleFile.kt | 6 -- .../jetbrains/academy/kotlin/template/Main.kt | 13 ----- .../programmingTask/task-info.yaml | 12 ---- .../programmingTask/task.md | 3 - .../test/InvokeSayByeFunction.kt | 11 ---- .../programmingTask/test/MainClass.kt | 8 --- .../programmingTask/test/Tests.kt | 58 ------------------- .../academy/kotlin/template/InvisibleFile.kt | 6 -- .../jetbrains/academy/kotlin/template/Main.kt | 6 -- .../theoryTask/task-info.yaml | 6 -- .../courseFrameworkLesson/theoryTask/task.md | 18 ------ .../Find Number of Classes/src/Task.kt | 12 ---- .../Find Number of Classes/test/Tests.kt | 21 ------- .../courseLesson/PsiTreeUtil/src/Main.kt | 3 - .../courseLesson/PsiTreeUtil/task-info.yaml | 16 ----- .../courseLesson/PsiTreeUtil/task.md | 1 - .../findNumberOfClassesTask/src/Task.kt | 7 +++ .../task-info.yaml | 0 .../task.md | 0 .../findNumberOfClassesTask/test/Tests.kt | 16 +++++ .../src/Main.kt | 0 .../task-info.yaml | 0 .../task.md | 0 courseSection/courseLesson/lesson-info.yaml | 5 +- courseSection/section-info.yaml | 1 - settings.gradle.kts | 4 +- 28 files changed, 63 insertions(+), 213 deletions(-) delete mode 100644 courseSection/courseFrameworkLesson/lesson-info.yaml delete mode 100644 courseSection/courseFrameworkLesson/programmingTask/src/org/jetbrains/academy/kotlin/template/InvisibleFile.kt delete mode 100644 courseSection/courseFrameworkLesson/programmingTask/src/org/jetbrains/academy/kotlin/template/Main.kt delete mode 100644 courseSection/courseFrameworkLesson/programmingTask/task-info.yaml delete mode 100644 courseSection/courseFrameworkLesson/programmingTask/task.md delete mode 100644 courseSection/courseFrameworkLesson/programmingTask/test/InvokeSayByeFunction.kt delete mode 100644 courseSection/courseFrameworkLesson/programmingTask/test/MainClass.kt delete mode 100644 courseSection/courseFrameworkLesson/programmingTask/test/Tests.kt delete mode 100644 courseSection/courseFrameworkLesson/theoryTask/src/org/jetbrains/academy/kotlin/template/InvisibleFile.kt delete mode 100644 courseSection/courseFrameworkLesson/theoryTask/src/org/jetbrains/academy/kotlin/template/Main.kt delete mode 100644 courseSection/courseFrameworkLesson/theoryTask/task-info.yaml delete mode 100644 courseSection/courseFrameworkLesson/theoryTask/task.md delete mode 100644 courseSection/courseLesson/Find Number of Classes/src/Task.kt delete mode 100644 courseSection/courseLesson/Find Number of Classes/test/Tests.kt delete mode 100644 courseSection/courseLesson/PsiTreeUtil/src/Main.kt delete mode 100644 courseSection/courseLesson/PsiTreeUtil/task-info.yaml delete mode 100644 courseSection/courseLesson/PsiTreeUtil/task.md create mode 100644 courseSection/courseLesson/findNumberOfClassesTask/src/Task.kt rename courseSection/courseLesson/{Find Number of Classes => findNumberOfClassesTask}/task-info.yaml (100%) rename courseSection/courseLesson/{Find Number of Classes => findNumberOfClassesTask}/task.md (100%) create mode 100644 courseSection/courseLesson/findNumberOfClassesTask/test/Tests.kt rename courseSection/courseLesson/{Intro to Psi => introductionToPsiTask}/src/Main.kt (100%) rename courseSection/courseLesson/{Intro to Psi => introductionToPsiTask}/task-info.yaml (100%) rename courseSection/courseLesson/{Intro to Psi => introductionToPsiTask}/task.md (100%) diff --git a/build.gradle.kts b/build.gradle.kts index 3ae9789..4f9b668 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -13,7 +13,13 @@ plugins { id("org.jetbrains.intellij") version "1.16.1" } - +intellij { + version.set("2023.1.2") + type.set("IC") + plugins.set(listOf("com.intellij.java", "org.jetbrains.kotlin")) + downloadSources.set(true) + updateSinceUntilBuild.set(true) +} val detektReportMerge by tasks.registering(io.gitlab.arturbosch.detekt.report.ReportMergeTask::class) { output.set(rootProject.buildDir.resolve("reports/detekt/merge.sarif")) @@ -117,6 +123,35 @@ configure(subprojects) { // We have to store tests inside test folder directly configure(subprojects.filter { it.name != "common" }) { + apply { + plugin("org.jetbrains.intellij") + } + + intellij { + version.set("2023.1.2") + type.set("IC") + plugins.set(listOf("com.intellij.java", "org.jetbrains.kotlin")) + downloadSources.set(true) + updateSinceUntilBuild.set(true) + } + + val jvmVersion = gradleProperties("jvmVersion").get() + tasks { + withType { + kotlinOptions { + jvmTarget = jvmVersion + } + } + + withType { + sourceCompatibility = jvmVersion + targetCompatibility = jvmVersion + } + + withType() + .forEach { it.enabled = false } + } + sourceSets { getByName("main").java.srcDirs("src") getByName("test").java.srcDirs("test") diff --git a/courseSection/courseFrameworkLesson/lesson-info.yaml b/courseSection/courseFrameworkLesson/lesson-info.yaml deleted file mode 100644 index 3bfc725..0000000 --- a/courseSection/courseFrameworkLesson/lesson-info.yaml +++ /dev/null @@ -1,6 +0,0 @@ -type: framework -custom_name: Course framework lesson -content: - - theoryTask - - programmingTask -is_template_based: false diff --git a/courseSection/courseFrameworkLesson/programmingTask/src/org/jetbrains/academy/kotlin/template/InvisibleFile.kt b/courseSection/courseFrameworkLesson/programmingTask/src/org/jetbrains/academy/kotlin/template/InvisibleFile.kt deleted file mode 100644 index cd63678..0000000 --- a/courseSection/courseFrameworkLesson/programmingTask/src/org/jetbrains/academy/kotlin/template/InvisibleFile.kt +++ /dev/null @@ -1,6 +0,0 @@ -package org.jetbrains.academy.kotlin.template - -// This file will be hidden in the student mode -// Since this file is invisible, it can be changed between tasks -@Suppress("FunctionOnlyReturningConstant") -fun sayBye() = "Bye" diff --git a/courseSection/courseFrameworkLesson/programmingTask/src/org/jetbrains/academy/kotlin/template/Main.kt b/courseSection/courseFrameworkLesson/programmingTask/src/org/jetbrains/academy/kotlin/template/Main.kt deleted file mode 100644 index 1596b0f..0000000 --- a/courseSection/courseFrameworkLesson/programmingTask/src/org/jetbrains/academy/kotlin/template/Main.kt +++ /dev/null @@ -1,13 +0,0 @@ -package org.jetbrains.academy.kotlin.template - -// Since the file from the first lesson will be propagated, -// you can put the solution here -fun invokeSayBye(howManyTimes: Int): String { - return List(howManyTimes) { sayBye() }.joinToString(System.lineSeparator()) -} - -fun main() { - println("How many times should I print Bye?") - val howManyTimes = readln().toInt() - println(invokeSayBye(howManyTimes)) -} diff --git a/courseSection/courseFrameworkLesson/programmingTask/task-info.yaml b/courseSection/courseFrameworkLesson/programmingTask/task-info.yaml deleted file mode 100644 index 98134f0..0000000 --- a/courseSection/courseFrameworkLesson/programmingTask/task-info.yaml +++ /dev/null @@ -1,12 +0,0 @@ -type: edu -files: - - name: src/org/jetbrains/academy/kotlin/template/Main.kt - visible: true - - name: src/org/jetbrains/academy/kotlin/template/InvisibleFile.kt - visible: false - - name: test/InvokeSayByeFunction.kt - visible: false - - name: test/MainClass.kt - visible: false - - name: test/Tests.kt - visible: false diff --git a/courseSection/courseFrameworkLesson/programmingTask/task.md b/courseSection/courseFrameworkLesson/programmingTask/task.md deleted file mode 100644 index 6397aa8..0000000 --- a/courseSection/courseFrameworkLesson/programmingTask/task.md +++ /dev/null @@ -1,3 +0,0 @@ -In this task the user needs to implement some functions. -You can check the user mode - the content of the `Main.kt` file will be propagated from the previous step, -however the `InvisibleFile.kt` will be changed. \ No newline at end of file diff --git a/courseSection/courseFrameworkLesson/programmingTask/test/InvokeSayByeFunction.kt b/courseSection/courseFrameworkLesson/programmingTask/test/InvokeSayByeFunction.kt deleted file mode 100644 index 483bfea..0000000 --- a/courseSection/courseFrameworkLesson/programmingTask/test/InvokeSayByeFunction.kt +++ /dev/null @@ -1,11 +0,0 @@ -import org.jetbrains.academy.test.system.core.models.TestKotlinType -import org.jetbrains.academy.test.system.core.models.method.TestMethod -import org.jetbrains.academy.test.system.core.models.variable.TestVariable - -internal val invokeSayByeFunction = TestMethod( - "invokeSayBye", - TestKotlinType("String"), - arguments = listOf( - TestVariable("howManyTimes", "Int"), - ), -) diff --git a/courseSection/courseFrameworkLesson/programmingTask/test/MainClass.kt b/courseSection/courseFrameworkLesson/programmingTask/test/MainClass.kt deleted file mode 100644 index ec121fd..0000000 --- a/courseSection/courseFrameworkLesson/programmingTask/test/MainClass.kt +++ /dev/null @@ -1,8 +0,0 @@ -import org.jetbrains.academy.test.system.core.models.classes.TestClass - -internal val mainClass = TestClass( - classPackage = "org.jetbrains.academy.kotlin.template", - customMethods = listOf( - invokeSayByeFunction, - ), -) diff --git a/courseSection/courseFrameworkLesson/programmingTask/test/Tests.kt b/courseSection/courseFrameworkLesson/programmingTask/test/Tests.kt deleted file mode 100644 index 9344d6d..0000000 --- a/courseSection/courseFrameworkLesson/programmingTask/test/Tests.kt +++ /dev/null @@ -1,58 +0,0 @@ -import org.jetbrains.academy.kotlin.template.main -import org.jetbrains.academy.kotlin.template.newLineSeparator -import org.jetbrains.academy.kotlin.template.runMainFunction -import org.jetbrains.academy.kotlin.template.throwInternalCourseError -import org.jetbrains.academy.test.system.core.invokeWithArgs -import org.jetbrains.academy.test.system.core.models.classes.findClassSafe -import org.junit.jupiter.api.Assertions -import org.junit.jupiter.api.BeforeAll -import org.junit.jupiter.api.Test -import org.junit.jupiter.params.ParameterizedTest -import org.junit.jupiter.params.provider.Arguments -import org.junit.jupiter.params.provider.MethodSource - -class Test { - companion object { - private lateinit var mainClazz: Class<*> - - @JvmStatic - @BeforeAll - fun beforeAll() { - mainClazz = mainClass.findClassSafe() ?: throwInternalCourseError() - } - - private const val BYE = "Bye" - - @JvmStatic - fun invokeSayByeArguments() = listOf( - Arguments.of(1, List(1) { BYE }.joinToString(System.lineSeparator())), - Arguments.of(2, List(2) { BYE }.joinToString(System.lineSeparator())), - Arguments.of(3, List(3) { BYE }.joinToString(System.lineSeparator())) - ) - } - @Test - fun invokeSayByeFunction() { - mainClass.checkMethod(mainClazz, invokeSayByeFunction) - } - - @ParameterizedTest - @MethodSource("invokeSayByeArguments") - fun invokeSayByeImplementation( - howManyTimes: Int, - output: String, - ) { - val userMethod = mainClass.findMethod(mainClazz, invokeSayByeFunction) - Assertions.assertEquals( - output, - userMethod.invokeWithArgs(howManyTimes, clazz = mainClazz)?.toString()?.trimIndent(), - "For howManyTimes = $howManyTimes the function ${invokeSayByeFunction.name} should return $output" - ) - } - @Test - fun testSolution() { - Assertions.assertEquals( - "How many times should I print $BYE?${newLineSeparator}$BYE${newLineSeparator}$BYE".trimIndent(), - runMainFunction(::main, "2").trimIndent() - ) - } -} \ No newline at end of file diff --git a/courseSection/courseFrameworkLesson/theoryTask/src/org/jetbrains/academy/kotlin/template/InvisibleFile.kt b/courseSection/courseFrameworkLesson/theoryTask/src/org/jetbrains/academy/kotlin/template/InvisibleFile.kt deleted file mode 100644 index 415bdcf..0000000 --- a/courseSection/courseFrameworkLesson/theoryTask/src/org/jetbrains/academy/kotlin/template/InvisibleFile.kt +++ /dev/null @@ -1,6 +0,0 @@ -package org.jetbrains.academy.kotlin.template - -// This file will be hidden in the student mode -// Since this file is invisible, it can be changed between tasks -@Suppress("FunctionOnlyReturningConstant") -fun sayHello() = "Hello" diff --git a/courseSection/courseFrameworkLesson/theoryTask/src/org/jetbrains/academy/kotlin/template/Main.kt b/courseSection/courseFrameworkLesson/theoryTask/src/org/jetbrains/academy/kotlin/template/Main.kt deleted file mode 100644 index a81bd1c..0000000 --- a/courseSection/courseFrameworkLesson/theoryTask/src/org/jetbrains/academy/kotlin/template/Main.kt +++ /dev/null @@ -1,6 +0,0 @@ -package org.jetbrains.academy.kotlin.template - -// This file will be visible for the student -fun main() { - // Write your solution here -} diff --git a/courseSection/courseFrameworkLesson/theoryTask/task-info.yaml b/courseSection/courseFrameworkLesson/theoryTask/task-info.yaml deleted file mode 100644 index d577bb8..0000000 --- a/courseSection/courseFrameworkLesson/theoryTask/task-info.yaml +++ /dev/null @@ -1,6 +0,0 @@ -type: theory -files: - - name: src/org/jetbrains/academy/kotlin/template/Main.kt - visible: true - - name: src/org/jetbrains/academy/kotlin/template/InvisibleFile.kt - visible: false diff --git a/courseSection/courseFrameworkLesson/theoryTask/task.md b/courseSection/courseFrameworkLesson/theoryTask/task.md deleted file mode 100644 index fe0801a..0000000 --- a/courseSection/courseFrameworkLesson/theoryTask/task.md +++ /dev/null @@ -1,18 +0,0 @@ -It is an example of framework lessons. -If you create this type of lesson, the user can solve tasks step-by-step. -Initially the user see all visible files from the first task in the lesson. -Next, all changes which were made by the user in the visible files, -will be propagated to the next tasks. - -Beginning from the second lesson you can modify the visible files to be able to provide -students with the correct solution from the course author. -Invisible files can be modified between tasks. - -**Note, you need to have the same set of the files between all tasks.** -So, it is the same for the resources folder, to avoid double-storing of images, -you can put them into the `common` module: - -

- Logo -

- diff --git a/courseSection/courseLesson/Find Number of Classes/src/Task.kt b/courseSection/courseLesson/Find Number of Classes/src/Task.kt deleted file mode 100644 index 3247374..0000000 --- a/courseSection/courseLesson/Find Number of Classes/src/Task.kt +++ /dev/null @@ -1,12 +0,0 @@ -import com.intellij.openapi.vfs.VirtualFile - -class FileAnalyzer(val project: Project) { - - private val psiManager = PsiManager.getInstance(project) - - fun classCounter(file: VirtualFile): Int { - // get psiFile from virtualFile - val classes = // get classes from psiFile - return classes - } -} \ No newline at end of file diff --git a/courseSection/courseLesson/Find Number of Classes/test/Tests.kt b/courseSection/courseLesson/Find Number of Classes/test/Tests.kt deleted file mode 100644 index ec5ce87..0000000 --- a/courseSection/courseLesson/Find Number of Classes/test/Tests.kt +++ /dev/null @@ -1,21 +0,0 @@ -import org.junit.Assert -import org.junit.Test -import com.intellij.testFramework.fixtures.BasePlatformTestCase -import org.junit.jupiter.api.Assertions.assertEquals - -class Test { - @Test fun testSolution() { - val file = myFixture.configureByText("MyClass.java", """ - public class MyClass1 { - public void method1() {} - } - - class MyClass2 { - public void method2() {} - } - """.trimIndent()) - - val stats = FileAnalyzer(myFixture.project).classCounter(file.virtualFile) - assertEquals(2, stats) - } -} \ No newline at end of file diff --git a/courseSection/courseLesson/PsiTreeUtil/src/Main.kt b/courseSection/courseLesson/PsiTreeUtil/src/Main.kt deleted file mode 100644 index 2d5aa02..0000000 --- a/courseSection/courseLesson/PsiTreeUtil/src/Main.kt +++ /dev/null @@ -1,3 +0,0 @@ -fun main() { - // Write your solution here -} diff --git a/courseSection/courseLesson/PsiTreeUtil/task-info.yaml b/courseSection/courseLesson/PsiTreeUtil/task-info.yaml deleted file mode 100644 index 09c497f..0000000 --- a/courseSection/courseLesson/PsiTreeUtil/task-info.yaml +++ /dev/null @@ -1,16 +0,0 @@ -type: choice -is_multiple_choice: false -options: - - text: PsiFile - is_correct: false - - text: PsiMethod - is_correct: true - - text: PsiVariable - is_correct: false - - text: PsiClass - is_correct: false -message_incorrect: Almost there! The key is to match the element type you're searching for with the corresponding PSI class. In PsiTreeUtil.findChildrenOfType, the class type parameter determines what kind of PSI elements you'll find. -files: - - name: src/Main.kt - visible: true - diff --git a/courseSection/courseLesson/PsiTreeUtil/task.md b/courseSection/courseLesson/PsiTreeUtil/task.md deleted file mode 100644 index 2659345..0000000 --- a/courseSection/courseLesson/PsiTreeUtil/task.md +++ /dev/null @@ -1 +0,0 @@ -If you want to find all method declarations within a class using PsiTreeUtil, which class type should you specify in the findChildrenOfType method? \ No newline at end of file diff --git a/courseSection/courseLesson/findNumberOfClassesTask/src/Task.kt b/courseSection/courseLesson/findNumberOfClassesTask/src/Task.kt new file mode 100644 index 0000000..d2357ec --- /dev/null +++ b/courseSection/courseLesson/findNumberOfClassesTask/src/Task.kt @@ -0,0 +1,7 @@ +import com.intellij.psi.PsiClass +import com.intellij.psi.PsiFile +import com.intellij.psi.util.PsiTreeUtil + +fun countPsiClasses(psiFile: PsiFile): Int { + return PsiTreeUtil.findChildrenOfType(psiFile, PsiClass::class.java).toList().size +} diff --git a/courseSection/courseLesson/Find Number of Classes/task-info.yaml b/courseSection/courseLesson/findNumberOfClassesTask/task-info.yaml similarity index 100% rename from courseSection/courseLesson/Find Number of Classes/task-info.yaml rename to courseSection/courseLesson/findNumberOfClassesTask/task-info.yaml diff --git a/courseSection/courseLesson/Find Number of Classes/task.md b/courseSection/courseLesson/findNumberOfClassesTask/task.md similarity index 100% rename from courseSection/courseLesson/Find Number of Classes/task.md rename to courseSection/courseLesson/findNumberOfClassesTask/task.md diff --git a/courseSection/courseLesson/findNumberOfClassesTask/test/Tests.kt b/courseSection/courseLesson/findNumberOfClassesTask/test/Tests.kt new file mode 100644 index 0000000..6958605 --- /dev/null +++ b/courseSection/courseLesson/findNumberOfClassesTask/test/Tests.kt @@ -0,0 +1,16 @@ +import com.intellij.testFramework.fixtures.BasePlatformTestCase + +class Test : BasePlatformTestCase() { + fun testSolution() { + val file = myFixture.configureByText("MyClass.kt", """ + class MyFirstClass { + } + + class MySecondClass { + } + """.trimIndent()) + + val psiClassesCount = countPsiClasses(file) + assertEquals(2, psiClassesCount) + } +} diff --git a/courseSection/courseLesson/Intro to Psi/src/Main.kt b/courseSection/courseLesson/introductionToPsiTask/src/Main.kt similarity index 100% rename from courseSection/courseLesson/Intro to Psi/src/Main.kt rename to courseSection/courseLesson/introductionToPsiTask/src/Main.kt diff --git a/courseSection/courseLesson/Intro to Psi/task-info.yaml b/courseSection/courseLesson/introductionToPsiTask/task-info.yaml similarity index 100% rename from courseSection/courseLesson/Intro to Psi/task-info.yaml rename to courseSection/courseLesson/introductionToPsiTask/task-info.yaml diff --git a/courseSection/courseLesson/Intro to Psi/task.md b/courseSection/courseLesson/introductionToPsiTask/task.md similarity index 100% rename from courseSection/courseLesson/Intro to Psi/task.md rename to courseSection/courseLesson/introductionToPsiTask/task.md diff --git a/courseSection/courseLesson/lesson-info.yaml b/courseSection/courseLesson/lesson-info.yaml index eb83467..7244454 100644 --- a/courseSection/courseLesson/lesson-info.yaml +++ b/courseSection/courseLesson/lesson-info.yaml @@ -3,6 +3,5 @@ content: - theoryTask - quizTask - programmingTask - - Intro to Psi - - PsiTreeUtil - - Find Number of Classes + - introductionToPsiTask + - findNumberOfClassesTask diff --git a/courseSection/section-info.yaml b/courseSection/section-info.yaml index daa299c..358ed2a 100644 --- a/courseSection/section-info.yaml +++ b/courseSection/section-info.yaml @@ -1,4 +1,3 @@ custom_name: Course section content: - courseLesson - - courseFrameworkLesson diff --git a/settings.gradle.kts b/settings.gradle.kts index 77c7bb2..841d8f8 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,4 +1,4 @@ -rootProject.name = "JetBrains Academy Kotlin course template" +rootProject.name = "JetBrains Academy IntelliJ IDEA Plugin Development Course" pluginManagement { repositories { @@ -7,7 +7,7 @@ pluginManagement { mavenCentral() // To be able to use the Kotlin test framework for the tests - https://github.com/jetbrains-academy/kotlin-test-framework - maven(url = "https://packages.jetbrains.team/maven/p/kotlin-test-framework/kotlin-test-framework") +// maven(url = "https://packages.jetbrains.team/maven/p/kotlin-test-framework/kotlin-test-framework") } }