Skip to content

Commit

Permalink
Merge branch 'main' into Enhancement-Save-Logins-everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
GunniBusch authored Dec 29, 2023
2 parents 6279048 + e7eb059 commit 78ba98f
Show file tree
Hide file tree
Showing 24 changed files with 233 additions and 29 deletions.
4 changes: 3 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,12 @@ tasks {
version.set(properties("pluginVersion").get())
changeNotes.set(
"""<p>
<h1>Added Todos for Tutors</h1>
<h1>Added Todos for Tutors and easy Setup for Local Testing</h1>
<h2>Improvements</h2>
<ul>
<li>Updated dependencies for IntelliJ 2023.2.4</li>
<li>Local Tests for Students</li>
<li>Todos for Tutors</li>
</ul>
</p>"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.intellij.execution.testframework.ui.BaseTestsOutputConsoleView
import com.intellij.execution.ui.ConsoleView
import com.intellij.openapi.components.service
import com.intellij.openapi.project.Project
import de.tum.www1.orion.build.util.OrionRunConfiguration
import de.tum.www1.orion.exercise.registry.OrionStudentExerciseRegistry
import de.tum.www1.orion.messaging.OrionIntellijStateNotifier

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package de.tum.www1.orion.build
import com.intellij.execution.configurations.ConfigurationFactory
import com.intellij.execution.configurations.RunConfiguration
import com.intellij.openapi.project.Project
import de.tum.www1.orion.build.util.OrionRunConfiguration
import de.tum.www1.orion.build.util.OrionSubmitRunConfigurationType

class OrionConfigurationFactory(type: OrionSubmitRunConfigurationType) : ConfigurationFactory(type) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package de.tum.www1.orion.build
import com.intellij.execution.RunnerAndConfigurationSettings
import com.intellij.openapi.application.ApplicationInfo
import com.intellij.openapi.project.Project
import de.tum.www1.orion.build.instructor.JavaRunConfigurationProvider
import de.tum.www1.orion.build.instructor.OrionInstructorBuildUtil
import de.tum.www1.orion.build.util.JavaRunConfigurationProvider
import de.tum.www1.orion.enumeration.ProgrammingLanguage
import de.tum.www1.orion.util.selectedProgrammingLanguage
import java.io.File.separatorChar
Expand Down Expand Up @@ -36,6 +36,24 @@ object OrionLocalRunConfigurationSettingsFactory {
}
}

/**
* @param project project to generate the configuration for
* @return the configuration
*/
fun runConfigurationForLocalTesting(project: Project): RunnerAndConfigurationSettings? {
return when (project.selectedProgrammingLanguage()) {
ProgrammingLanguage.JAVA, ProgrammingLanguage.KOTLIN -> {
val applicationInfo = ApplicationInfo.getInstance().fullApplicationName
if (!applicationInfo.contains("IntelliJ")) {
return null
}
JavaRunConfigurationProvider(project).provideBuildAndTestRunConfiguration("${project.basePath!!}${separatorChar}artemis-tests")

}
else -> null
}
}

/**
* Creates a run configuration working in the base directory
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.intellij.execution.runners.ProgramRunner
import com.intellij.execution.runners.RunContentBuilder
import com.intellij.execution.ui.RunContentDescriptor
import com.intellij.openapi.fileEditor.FileDocumentManager
import de.tum.www1.orion.build.util.OrionRunConfiguration

class OrionProgramRunner : GenericProgramRunner<RunnerSettings>() {
override fun canRun(executorId: String, profile: RunProfile): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package de.tum.www1.orion.build

import com.intellij.openapi.options.SettingsEditor
import com.intellij.ui.dsl.builder.panel
import de.tum.www1.orion.build.util.OrionRunConfiguration
import javax.swing.JComponent
import javax.swing.JPanel

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package de.tum.www1.orion.build.student

import com.intellij.notification.NotificationType
import com.intellij.openapi.application.ApplicationInfo
import com.intellij.openapi.application.runInEdt
import com.intellij.openapi.application.runWriteAction
import com.intellij.openapi.components.Service
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.io.FileUtil
import de.tum.www1.orion.ui.util.notify
import de.tum.www1.orion.util.OrionProjectUtil
import de.tum.www1.orion.vcs.OrionGitAdapter
import java.io.File


@Service(Service.Level.PROJECT)
class OrionStudentTestUtilService(val project: Project) {

/**
* Initializes the test repository for a programming exercise
*/
fun initializeTestRepo(testRepositoryUrl: String) {
// clone repo
val currentDirectory = project.basePath
if (currentDirectory == null) {
project.notify("Error initializing the project!!! [REPLACE THIS]")
return
}
// Clone Module this can be done for any project
OrionGitAdapter.clone(
project, testRepositoryUrl, currentDirectory, "./artemis-tests/", false
) {
// followup setups for different programming languages/types of projects
copyAssignmentFolder(project)
initializeModule(project)
project.notify("Successfully initialized test setup!", NotificationType.IDE_UPDATE)
}

}

/**
* Copies the assignment folder (src)
* @param project the currently opened project
*/
private fun copyAssignmentFolder(project: Project) {
runInEdt {
runWriteAction {
val srcPath = File("${project.basePath}${File.separatorChar}src")
val assignemntSrcPath =
File("${project.basePath}${File.separatorChar}artemis-tests${File.separatorChar}assignment${File.separatorChar}src")
FileUtil.createDirectory(assignemntSrcPath)
if (srcPath.isDirectory) {
FileUtil.copyFileOrDir(srcPath, assignemntSrcPath)
}
}
}
}


/**
* Initializes a new module with tests for the project
* @param project the currently opened project
*
*/
private fun initializeModule(project: Project) {
// check if its IntelliJ else stop the configuration
val applicationInfo = ApplicationInfo.getInstance().fullApplicationName
if (!applicationInfo.contains("IntelliJ")) {
return
}
// is gradle project
if (File("${project.basePath}${File.separatorChar}artemis-tests${File.separatorChar}build.gradle").isFile) {
OrionProjectUtil.newModule(project, "artemis-tests", OrionProjectUtil.ModuleType.GRADLE_MODULE)
}
// is maven project
if (File("${project.basePath}${File.separatorChar}artemis-tests${File.separatorChar}pom.xml").isFile) {
OrionProjectUtil.newModule(project, "artemis-tests", OrionProjectUtil.ModuleType.MAVEN_MODULE)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.tum.www1.orion.build.instructor
package de.tum.www1.orion.build.util

import com.intellij.execution.RunManager
import com.intellij.execution.RunnerAndConfigurationSettings
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.tum.www1.orion.build
package de.tum.www1.orion.build.util

import com.intellij.execution.Executor
import com.intellij.execution.configurations.RunConfiguration
Expand All @@ -8,6 +8,9 @@ import com.intellij.execution.runners.ExecutionEnvironment
import com.intellij.execution.runners.RunConfigurationWithSuppressedDefaultRunAction
import com.intellij.openapi.options.SettingsEditor
import com.intellij.openapi.project.Project
import de.tum.www1.orion.build.OrionCommandLineState
import de.tum.www1.orion.build.OrionConfigurationFactory
import de.tum.www1.orion.build.OrionSettingsEditor

class OrionRunConfiguration(project: Project, factory: OrionConfigurationFactory, name: String)
: RunConfigurationBase<OrionCommandLineState>(project, factory, name), RunConfigurationWithSuppressedDefaultRunAction {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.tum.www1.orion.build.instructor
package de.tum.www1.orion.build.util

import com.intellij.execution.RunnerAndConfigurationSettings

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package de.tum.www1.orion.build
package de.tum.www1.orion.build.util

import com.intellij.execution.configurations.ConfigurationFactory
import com.intellij.execution.configurations.ConfigurationType
import com.intellij.icons.AllIcons
import de.tum.www1.orion.build.OrionConfigurationFactory
import javax.swing.Icon

class OrionSubmitRunConfigurationType : ConfigurationType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class ArtemisClientConnector(private val project: Project) : JavaScriptConnector
project.messageBus.connect().subscribe(INTELLIJ_STATE_TOPIC, object : OrionIntellijStateNotifier {
override fun openedExercise(opened: Long, currentView: ExerciseView) {
executeJSFunction(JavaScriptFunction.ON_EXERCISE_OPENED, opened, currentView)
executeJSFunction(JavaScriptFunction.INITIALIZEFEEDBACK)
}

override fun startedBuild(courseId: Long, exerciseId: Long) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ interface JavaScriptConnector {
IS_CLONING("isCloning", Boolean::class),
IS_BUILDING("isBuilding", Boolean::class),
TRIGGER_BUILD_FROM_IDE("startedBuildInOrion", Long::class, Long::class),
UPDATE_ASSESSMENT("updateAssessment", Long::class, String::class);
UPDATE_ASSESSMENT("updateAssessment", Long::class, String::class),
INITIALIZEFEEDBACK("initializeFeedback");

private val argTypes: List<KClass<*>> = argTypes.asList()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import com.intellij.openapi.components.Service
import com.intellij.openapi.components.service
import com.intellij.openapi.project.Project
import com.intellij.ui.jcef.JBCefJSQuery
import de.tum.www1.orion.build.OrionRunConfiguration
import de.tum.www1.orion.build.OrionSubmitRunConfigurationType
import de.tum.www1.orion.build.util.OrionRunConfiguration
import de.tum.www1.orion.build.util.OrionSubmitRunConfigurationType
import de.tum.www1.orion.build.OrionTestParser
import de.tum.www1.orion.build.instructor.OrionInstructorBuildUtil
import de.tum.www1.orion.connector.ide.OrionConnector
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ interface IOrionExerciseConnector {
*/
fun initializeAssessment(submissionId: Long, feedback: String)

/**
* Initializes the project with a test repository.
*
* @param testRepository the url or the test repository
*/
fun initializeTestRepository(testRepository: String)

/**
* Initializes the [OrionFeedbackService]
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.intellij.openapi.components.Service
import com.intellij.openapi.components.service
import com.intellij.openapi.project.Project
import com.intellij.ui.jcef.JBCefJSQuery
import de.tum.www1.orion.build.student.OrionStudentTestUtilService
import de.tum.www1.orion.connector.ide.OrionConnector
import de.tum.www1.orion.dto.Feedback
import de.tum.www1.orion.dto.ProgrammingExercise
Expand Down Expand Up @@ -51,6 +52,10 @@ class OrionExerciseConnector(val project: Project) : OrionConnector(), IOrionExe
project.service<OrionAssessmentService>().initializeFeedback(submissionId, feedbackArray)
}

override fun initializeTestRepository(testRepository: String) {
project.service<OrionStudentTestUtilService>().initializeTestRepo(testRepository)
}

override fun initializeFeedback(feedback: String) {
val feedbackArray = gson().fromJson(feedback, Array<Feedback>::class.java)
initializeFeedbackForParticipations(feedbackArray)
Expand Down Expand Up @@ -86,7 +91,9 @@ class OrionExerciseConnector(val project: Project) : OrionConnector(), IOrionExe
"initializeAssessment" to { scanner ->
initializeAssessment(scanner.nextLine().toLong(), scanner.nextAll())
},
"initializeFeedback" to { scanner -> initializeFeedback(scanner.nextAll()) })
"initializeTestRepository" to { scanner -> initializeTestRepository(scanner.nextAll()) },
"initializeFeedback" to { scanner -> initializeFeedback(scanner.nextAll()) }
)
addJavaHandler(browser, reactions)

val parameterNames = mapOf(
Expand All @@ -98,6 +105,7 @@ class OrionExerciseConnector(val project: Project) : OrionConnector(), IOrionExe
"downloadURL"
),
"initializeAssessment" to listOf("submissionId", "feedback"),
"initializeTestRepository" to listOf("testRepository"),
"initializeFeedback" to listOf("feedback")
)
addLoadHandler(browser, queryInjector, parameterNames)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package de.tum.www1.orion.connector.ide.shared

import com.intellij.openapi.components.Service
import com.intellij.openapi.components.service
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.project.Project
import com.intellij.ui.jcef.JBCefJSQuery
import de.tum.www1.orion.connector.ide.OrionConnector
import de.tum.www1.orion.ui.browser.IBrowser
import de.tum.www1.orion.util.nextAll
import de.tum.www1.orion.vcs.OrionGitCredentialsService
import com.intellij.openapi.diagnostic.Logger
import java.util.*

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import de.tum.www1.orion.exercise.registry.OrionInstructorExerciseRegistry
import de.tum.www1.orion.ui.browser.IBrowser
import java.util.*


@Service(Service.Level.PROJECT)
class OrionVCSConnector(val project: Project) : OrionConnector(), IOrionVCSConnector {
@Deprecated("Replaced with onBuildStarted")
Expand Down
18 changes: 10 additions & 8 deletions src/main/java/de/tum/www1/orion/exercise/OrionExerciseService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -86,21 +86,23 @@ class OrionExerciseService(private val project: Project) {
it.repositoryUrl.toString(),
projectPath,
"$projectPath/${it.checkoutDirectory}",
true,
null
)
}
// Clone all base repositories
clone(
project, exercise.templateParticipation.repositoryUrl.toString(),
projectPath, "$projectPath/exercise", null
)
projectPath, "$projectPath/exercise", true, null,

)
clone(
project, exercise.testRepositoryUrl.toString(),
projectPath, "$projectPath/tests", null
projectPath, "$projectPath/tests", true, null
)
clone(
project, exercise.solutionParticipation.repositoryUrl.toString(),
projectPath, "$projectPath/solution"
projectPath, "$projectPath/solution", true
) {
// After cloning all repos, create the necessary project files and notify the webview about the opened project
prepareProjectForImport(File(projectPath))
Expand All @@ -123,7 +125,7 @@ class OrionExerciseService(private val project: Project) {
fun importParticipation(repositoryUrl: String, exercise: ProgrammingExercise) {
createProject(exercise, ExerciseView.STUDENT) { chosenPath, registry ->
val parent = LocalFileSystem.getInstance().refreshAndFindFileByPath(chosenPath)!!.parent.path
clone(project, repositoryUrl, parent, chosenPath) {
clone(project, repositoryUrl, parent, chosenPath, true) {
registry.registerExercise(exercise, ExerciseView.STUDENT, chosenPath)
ProjectUtil.openOrImport(chosenPath, project, false)
}
Expand All @@ -138,16 +140,16 @@ class OrionExerciseService(private val project: Project) {
fun assessExercise(exercise: ProgrammingExercise) {
createProject(exercise, ExerciseView.TUTOR) { chosenPath, registry ->
val parent = LocalFileSystem.getInstance().refreshAndFindFileByPath(chosenPath)!!.parent.path
clone(project, exercise.testRepositoryUrl.toString(), parent, chosenPath, null)
clone(project, exercise.testRepositoryUrl.toString(), parent, chosenPath, true, null)
// clone the template to use it to highlight the student code changes.
clone(
project, exercise.templateParticipation.repositoryUrl.toString(),
parent, "$chosenPath/template", null
parent, "$chosenPath/template", true, null
)
// clone the solution to use it to highlight student code changes
clone(
project, exercise.templateParticipation.repositoryUrl.toString(),
parent, "$chosenPath/solution"
parent, "$chosenPath/solution", true
)

{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
//@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
package de.tum.www1.orion.ui.assessment

import com.intellij.diff.DiffRequestFactory
import com.intellij.diff.editor.DiffEditorProvider
import com.intellij.diff.editor.DiffRequestProcessorEditor
import com.intellij.diff.editor.DiffVirtualFile
import com.intellij.diff.editor.SimpleDiffVirtualFile
import com.intellij.openapi.fileEditor.FileEditor
import com.intellij.openapi.fileEditor.FileEditorPolicy
Expand Down Expand Up @@ -36,8 +37,9 @@ class OrionTemplateDiffEditorProvider : OrionEditorProvider() {

val request = DiffRequestFactory.getInstance().createFromFiles(project, studentFile, templateFile)
val diffFile = SimpleDiffVirtualFile(request)

return DiffEditorProvider().createEditor(project, diffFile)
// Copy from DiffEditorProvider
val processor = (diffFile as DiffVirtualFile).createProcessor(project)
return DiffRequestProcessorEditor(diffFile, processor)
}

override fun getEditorTypeId(): String = "ORION TEMPLATE DIFF EDITOR"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ class BrowserService(val project: Project) : IBrowser, Disposable {
* Loads a specific url in the browser.
*/
override fun loadUrl(url: String) {
//todo do override on specific domain
if (isInitialized) {
jbCefBrowser.cefBrowser.executeJavaScript("window.location.href = '$url';", null, 0)
// Reloading clears the webclient's data, reinitialize exercise information
Expand Down
Loading

0 comments on commit 78ba98f

Please sign in to comment.