diff --git a/src/main/java/de/tum/www1/orion/dto/Dto.kt b/src/main/java/de/tum/www1/orion/dto/Dto.kt index 6632cfc..65911e0 100644 --- a/src/main/java/de/tum/www1/orion/dto/Dto.kt +++ b/src/main/java/de/tum/www1/orion/dto/Dto.kt @@ -19,7 +19,7 @@ data class ProgrammingExercise( private val course: Course?, val templateParticipation: ProgrammingExerciseParticipation, val solutionParticipation: ProgrammingExerciseParticipation, - val testRepositoryUrl: URL, + val testRepositoryUri: URL, val programmingLanguage: ProgrammingLanguage, val auxiliaryRepositories: List?, val exerciseGroup: ExerciseGroup?, @@ -64,7 +64,7 @@ data class Exam( */ data class ProgrammingExerciseParticipation( val id: Long, - val repositoryUrl: URL, + val repositoryUri: URL, val buildPlanId: String, var locked: Boolean ) @@ -98,7 +98,7 @@ data class AuxiliaryRepository( val id: Long, val name: String, val checkoutDirectory: String, - val repositoryUrl: URL, + val repositoryUri: URL, val description: String ) diff --git a/src/main/java/de/tum/www1/orion/exercise/OrionExerciseService.kt b/src/main/java/de/tum/www1/orion/exercise/OrionExerciseService.kt index 0cfcc22..40de13a 100644 --- a/src/main/java/de/tum/www1/orion/exercise/OrionExerciseService.kt +++ b/src/main/java/de/tum/www1/orion/exercise/OrionExerciseService.kt @@ -4,6 +4,7 @@ import com.intellij.ide.impl.ProjectUtil import com.intellij.openapi.application.* 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.openapi.util.io.FileUtil import com.intellij.openapi.vfs.LocalFileSystem @@ -12,6 +13,7 @@ import de.tum.www1.orion.connector.ide.exercise.OrionExerciseConnector import de.tum.www1.orion.dto.ProgrammingExercise import de.tum.www1.orion.enumeration.ExerciseView import de.tum.www1.orion.exercise.OrionJavaInstructorProjectCreator.prepareProjectForImport +import de.tum.www1.orion.exercise.assessment.OrionAssessmentService import de.tum.www1.orion.exercise.registry.OrionGlobalExerciseRegistryService import de.tum.www1.orion.exercise.registry.OrionTutorExerciseRegistry import de.tum.www1.orion.messaging.OrionIntellijStateNotifier @@ -31,8 +33,6 @@ import de.tum.www1.orion.util.runWithIndeterminateProgressModal import de.tum.www1.orion.util.translate import de.tum.www1.orion.vcs.OrionGitAdapter import de.tum.www1.orion.vcs.OrionGitAdapter.clone -import com.intellij.openapi.diagnostic.Logger -import de.tum.www1.orion.exercise.assessment.OrionAssessmentService import java.io.File import java.io.IOException import java.nio.file.Files @@ -83,7 +83,7 @@ class OrionExerciseService(private val project: Project) { }?.forEach { clone( project, - it.repositoryUrl.toString(), + it.repositoryUri.toString(), projectPath, "$projectPath/${it.checkoutDirectory}", true, @@ -92,16 +92,16 @@ class OrionExerciseService(private val project: Project) { } // Clone all base repositories clone( - project, exercise.templateParticipation.repositoryUrl.toString(), + project, exercise.templateParticipation.repositoryUri.toString(), projectPath, "$projectPath/exercise", true, null, ) clone( - project, exercise.testRepositoryUrl.toString(), + project, exercise.testRepositoryUri.toString(), projectPath, "$projectPath/tests", true, null ) clone( - project, exercise.solutionParticipation.repositoryUrl.toString(), + project, exercise.solutionParticipation.repositoryUri.toString(), projectPath, "$projectPath/solution", true ) { // After cloning all repos, create the necessary project files and notify the webview about the opened project @@ -140,15 +140,15 @@ 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, true, null) + clone(project, exercise.testRepositoryUri.toString(), parent, chosenPath, true, null) // clone the template to use it to highlight the student code changes. clone( - project, exercise.templateParticipation.repositoryUrl.toString(), + project, exercise.templateParticipation.repositoryUri.toString(), parent, "$chosenPath/template", true, null ) // clone the solution to use it to highlight student code changes clone( - project, exercise.templateParticipation.repositoryUrl.toString(), + project, exercise.templateParticipation.repositoryUri.toString(), parent, "$chosenPath/solution", true ) diff --git a/src/main/java/de/tum/www1/orion/settings/OrionSettingsProvider.java b/src/main/java/de/tum/www1/orion/settings/OrionSettingsProvider.java index db8c149..5340697 100644 --- a/src/main/java/de/tum/www1/orion/settings/OrionSettingsProvider.java +++ b/src/main/java/de/tum/www1/orion/settings/OrionSettingsProvider.java @@ -11,6 +11,7 @@ public interface OrionSettingsProvider { enum KEYS { ARTEMIS_URL("de.tum.www1.orion.settings.artemis.url", "https://artemis.ase.in.tum.de"), + ARTEMIS_GIT_URL("de.tum.www1.orion.settings.artemis.giturl", "http://artemis.cit.tum.de/git/"), PROJECT_BASE_DIR("de.tum.www1.orion.settings.projects.path", System.getProperty("user.home") + File.separatorChar + "ArtemisProjects"), INSTRUCTOR_BASE_DIR("de.tum.www1.orion.settings.projects.instructor.path", System.getProperty("user.home") + File.separatorChar + "ArtemisProjects" + File.separatorChar + "Instructor"), TUTOR_BASE_DIR("de.tum.www1.orion.settings.projects.tutor.path", System.getProperty("user.home") + File.separatorChar + "ArtemisProjects" + File.separatorChar + "Tutor"), diff --git a/src/main/java/de/tum/www1/orion/ui/settings/OrionPluginSettings.kt b/src/main/java/de/tum/www1/orion/ui/settings/OrionPluginSettings.kt index cf7f66e..7673d00 100644 --- a/src/main/java/de/tum/www1/orion/ui/settings/OrionPluginSettings.kt +++ b/src/main/java/de/tum/www1/orion/ui/settings/OrionPluginSettings.kt @@ -13,8 +13,6 @@ import com.intellij.ui.dsl.builder.panel import de.tum.www1.orion.settings.OrionSettingsProvider import de.tum.www1.orion.ui.browser.BrowserUIInitializationService import de.tum.www1.orion.util.translate -import org.apache.commons.lang3.StringUtils - import javax.swing.JCheckBox import javax.swing.JComponent import javax.swing.JPanel @@ -32,12 +30,14 @@ class OrionPluginSettings(private val project: Project) : SearchableConfigurable private lateinit var instructorPathField: TextFieldWithBrowseButton private lateinit var tutorPathField: TextFieldWithBrowseButton private lateinit var artemisUrlField: JTextField + private lateinit var artemisGitUrlField: JTextField private lateinit var commitMessageField: JTextField private lateinit var useDefaultBox: JCheckBox private lateinit var userAgentField: JTextField private val settings: Map get() = mapOf( - Pair(OrionSettingsProvider.KEYS.ARTEMIS_URL, StringUtils.removeEnd(artemisUrlField.text, "/")), + Pair(OrionSettingsProvider.KEYS.ARTEMIS_URL, artemisUrlField.text.removeSuffix("/")), + Pair(OrionSettingsProvider.KEYS.ARTEMIS_GIT_URL, artemisGitUrlField.text.removeSuffix("/")), Pair(OrionSettingsProvider.KEYS.PROJECT_BASE_DIR, projectPathField.text), Pair(OrionSettingsProvider.KEYS.TUTOR_BASE_DIR, tutorPathField.text), Pair(OrionSettingsProvider.KEYS.INSTRUCTOR_BASE_DIR, instructorPathField.text), @@ -63,6 +63,7 @@ class OrionPluginSettings(private val project: Project) : SearchableConfigurable override fun createComponent(): JComponent { val settings = service() val currentArtemisUrl = settings.getSetting(OrionSettingsProvider.KEYS.ARTEMIS_URL) + val currentArtemisGitUrl = settings.getSetting(OrionSettingsProvider.KEYS.ARTEMIS_GIT_URL) val currentProjectPath = settings.getSetting(OrionSettingsProvider.KEYS.PROJECT_BASE_DIR) val currentTutorPath = settings.getSetting(OrionSettingsProvider.KEYS.TUTOR_BASE_DIR) val currentInstructorPath = settings.getSetting(OrionSettingsProvider.KEYS.INSTRUCTOR_BASE_DIR) @@ -78,6 +79,12 @@ class OrionPluginSettings(private val project: Project) : SearchableConfigurable row { artemisUrlField = textField().bindText({ currentArtemisUrl }, {}).align(Align.FILL).component } + row { + label(translate("orion.settings.giturl.label")) + } + row { + artemisGitUrlField = textField().bindText({ currentArtemisGitUrl }, {}).align(Align.FILL).component + } row { label(translate("orion.settings.path.title")).bold() } @@ -144,6 +151,7 @@ class OrionPluginSettings(private val project: Project) : SearchableConfigurable } } artemisUrlField.toolTipText = translate("orion.settings.url.tooltip") + artemisGitUrlField.toolTipText = translate("orion.settings.url.tooltip") return settingsPanel } diff --git a/src/main/java/de/tum/www1/orion/vcs/OrionGitCredentialsInjectorService.kt b/src/main/java/de/tum/www1/orion/vcs/OrionGitCredentialsInjectorService.kt index c5abad1..e2bc0fa 100644 --- a/src/main/java/de/tum/www1/orion/vcs/OrionGitCredentialsInjectorService.kt +++ b/src/main/java/de/tum/www1/orion/vcs/OrionGitCredentialsInjectorService.kt @@ -4,35 +4,44 @@ import com.intellij.credentialStore.CredentialAttributes import com.intellij.credentialStore.Credentials import com.intellij.credentialStore.generateServiceName import com.intellij.ide.passwordSafe.PasswordSafe +import com.intellij.openapi.components.service +import de.tum.www1.orion.settings.OrionSettingsProvider class OrionGitCredentialsInjectorService : OrionGitCredentialsService { override fun storeGitCredentials(username: String, password: String) { - makeKeys(username) - .map { Pair(CredentialAttributes(generateServiceName("Git HTTP", it), it, OrionGitCredentialsInjectorService::class.java), - Credentials(it, password)) } - .forEach { PasswordSafe.instance.set(it.first, it.second) } + val artemisGitUrl = makeKey(username) + PasswordSafe.instance.set( + CredentialAttributes( + generateServiceName("Git HTTP", artemisGitUrl), + artemisGitUrl, + OrionGitCredentialsInjectorService::class.java + ), + Credentials(artemisGitUrl, password) + ) } override fun removeGitCredentials(username: String) { - getDefaultSafeAttributes(username).forEach { - PasswordSafe.instance.set(it, null) - } + PasswordSafe.instance.set(getDefaultSafeAttributes(username), null) } - private fun getDefaultSafeAttributes(username: String): List { - return makeKeys(username) - .map { Pair(generateServiceName("Git HTTP", it), it) } - .map { CredentialAttributes(it.first, it.second, OrionGitCredentialsInjectorService::class.java) } - .toList() + private fun getDefaultSafeAttributes(username: String): CredentialAttributes { + val artemisGitUrl = makeKey(username) + return CredentialAttributes( + generateServiceName("Git HTTP", artemisGitUrl), + artemisGitUrl, + OrionGitCredentialsInjectorService::class.java + ) } - private fun makeKeys(username: String): List { - return listOf(NEW_REPO_HOST.format(username), OLD_REPO_HOST.format(username)) + private fun makeKey(username: String): String { + var url = service().getSetting(OrionSettingsProvider.KEYS.ARTEMIS_GIT_URL) + url = if (!url.contains("://")) { + "https://$username@$url" + } else { + url.replaceFirst("://", "://$username@") + } + return url } - companion object { - private const val NEW_REPO_HOST = "http://%s@bitbucket.ase.in.tum.de" - private const val OLD_REPO_HOST = "http://%s@repobruegge.in.tum.de" - } } diff --git a/src/main/resources/i18n/OrionBundle.properties b/src/main/resources/i18n/OrionBundle.properties index c2f42de..1d7efdc 100644 --- a/src/main/resources/i18n/OrionBundle.properties +++ b/src/main/resources/i18n/OrionBundle.properties @@ -2,6 +2,7 @@ orion.settings.displayName=Orion orion.settings.url.title=Artemis base URL: orion.settings.url.label=The URL of the Artemis homepage.\nChange this to change between different versions of Artemis. orion.settings.url.tooltip=Trailing slashes will automatically be deleted +orion.settings.giturl.label=The URL of the Artemis git server. orion.settings.path.title=Artemis exercise path: orion.settings.path.label=Where to store all imported exercises and projects. orion.settings.path.browser.title=Artemis project path diff --git a/src/main/resources/i18n/OrionBundle_de.properties b/src/main/resources/i18n/OrionBundle_de.properties index a18e642..3cc1c5c 100644 --- a/src/main/resources/i18n/OrionBundle_de.properties +++ b/src/main/resources/i18n/OrionBundle_de.properties @@ -2,6 +2,7 @@ orion.settings.displayName=Orion orion.settings.url.title=Artemis URL: orion.settings.url.label=Die URL der Artemis Homepage.\nFrei wählbar, um zwischen verschiedenen Artemis Instanzen zu wechseln. orion.settings.url.tooltip=Slashes am Ende werden automatisch gelöscht +orion.settings.giturl.label=Die URL des Artemis GIT Systems. orion.settings.path.title=Artemis Aufgaben Speicherort: orion.settings.path.label=Der Ordner, in welchem alle importierten Aufgaben gespeichert werden sollen. orion.settings.path.browser.title=Artemis Projekt Pfad