Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/Enhancement Fixed version control related bugs #107

Merged
merged 1 commit into from
Apr 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/main/java/de/tum/www1/orion/dto/Dto.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<AuxiliaryRepository>?,
val exerciseGroup: ExerciseGroup?,
Expand Down Expand Up @@ -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
)
Expand Down Expand Up @@ -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
)

Expand Down
18 changes: 9 additions & 9 deletions src/main/java/de/tum/www1/orion/exercise/OrionExerciseService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -83,7 +83,7 @@ class OrionExerciseService(private val project: Project) {
}?.forEach {
clone(
project,
it.repositoryUrl.toString(),
it.repositoryUri.toString(),
projectPath,
"$projectPath/${it.checkoutDirectory}",
true,
Expand All @@ -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
Expand Down Expand Up @@ -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
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
14 changes: 11 additions & 3 deletions src/main/java/de/tum/www1/orion/ui/settings/OrionPluginSettings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<OrionSettingsProvider.KEYS, String>
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),
Expand All @@ -63,6 +63,7 @@ class OrionPluginSettings(private val project: Project) : SearchableConfigurable
override fun createComponent(): JComponent {
val settings = service<OrionSettingsProvider>()
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)
Expand All @@ -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()
}
Expand Down Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<CredentialAttributes> {
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<String> {
return listOf(NEW_REPO_HOST.format(username), OLD_REPO_HOST.format(username))
private fun makeKey(username: String): String {
var url = service<OrionSettingsProvider>().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"
}
}
1 change: 1 addition & 0 deletions src/main/resources/i18n/OrionBundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/i18n/OrionBundle_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading