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

Programming exercises: Fix import from file not importing build values #9192

4 changes: 2 additions & 2 deletions src/main/webapp/app/entities/programming-exercise.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export class ProgrammingExerciseBuildConfig {
public checkoutPath?: string;
public timeoutSeconds?: number;
public dockerFlags?: string;
public windFile?: WindFile;
public windfile?: WindFile;
public testwiseCoverageEnabled?: boolean;

constructor() {
Expand Down Expand Up @@ -176,7 +176,7 @@ export function copyBuildConfigFromExerciseJson(exerciseJson: ProgrammingExercis
buildConfig.buildPlanConfiguration = exerciseJson.buildPlanConfiguration ?? '';
buildConfig.checkoutSolutionRepository = exerciseJson.checkoutSolutionRepository ?? false;
buildConfig.timeoutSeconds = exerciseJson.timeoutSeconds ?? 0;
buildConfig.windFile = exerciseJson.windFile ?? undefined;
buildConfig.windfile = exerciseJson.windfile ?? undefined;
buildConfig.buildScript = exerciseJson.buildScript ?? '';
buildConfig.testwiseCoverageEnabled = exerciseJson.testwiseCoverageEnabled ?? false;
buildConfig.dockerFlags = exerciseJson.dockerFlags ?? '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -456,13 +456,13 @@ export class ProgrammingExerciseDetailComponent implements OnInit, OnDestroy {
},
},
!!exercise.buildConfig?.buildScript &&
!!exercise.buildConfig?.windFile?.metadata?.docker?.image && {
!!exercise.buildConfig?.windfile?.metadata?.docker?.image && {
type: DetailType.Text,
title: 'artemisApp.programmingExercise.dockerImage',
data: { text: exercise.buildConfig?.windFile?.metadata?.docker?.image },
data: { text: exercise.buildConfig?.windfile?.metadata?.docker?.image },
},
!!exercise.buildConfig?.buildScript &&
!!exercise.buildConfig?.windFile?.metadata?.docker?.image && {
!!exercise.buildConfig?.windfile?.metadata?.docker?.image && {
type: DetailType.Markdown,
title: 'artemisApp.programmingExercise.script',
titleHelpText: 'artemisApp.programmingExercise.revertToTemplateBuildPlan',
Expand Down Expand Up @@ -752,8 +752,8 @@ export class ProgrammingExerciseDetailComponent implements OnInit, OnDestroy {
* @param exercise the programming exercise to check
*/
checkAndSetWindFile(exercise: ProgrammingExercise) {
if (exercise.buildConfig && exercise.buildConfig?.buildPlanConfiguration && !exercise.buildConfig?.windFile) {
exercise.buildConfig!.windFile = this.aeolusService.parseWindFile(exercise.buildConfig?.buildPlanConfiguration);
if (exercise.buildConfig && exercise.buildConfig?.buildPlanConfiguration && !exercise.buildConfig?.windfile) {
exercise.buildConfig!.windfile = this.aeolusService.parseWindFile(exercise.buildConfig?.buildPlanConfiguration);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ export class ProgrammingExerciseUpdateComponent implements AfterViewInit, OnDest
this.withDependenciesValue = false;
this.buildPlanLoaded = false;
if (this.programmingExercise.buildConfig) {
this.programmingExercise.buildConfig.windFile = undefined;
this.programmingExercise.buildConfig.windfile = undefined;
this.programmingExercise.buildConfig.buildPlanConfiguration = undefined;
} else {
this.programmingExercise.buildConfig = new ProgrammingExerciseBuildConfig();
Expand Down Expand Up @@ -390,7 +390,7 @@ export class ProgrammingExerciseUpdateComponent implements AfterViewInit, OnDest
this.activatedRoute.data.subscribe(({ programmingExercise }) => {
this.programmingExercise = programmingExercise;
if (this.programmingExercise.buildConfig?.buildPlanConfiguration) {
this.programmingExercise.buildConfig!.windFile = this.aeolusService.parseWindFile(this.programmingExercise.buildConfig!.buildPlanConfiguration);
this.programmingExercise.buildConfig!.windfile = this.aeolusService.parseWindFile(this.programmingExercise.buildConfig!.buildPlanConfiguration);
BBesrour marked this conversation as resolved.
Show resolved Hide resolved
}
this.backupExercise = cloneDeep(this.programmingExercise);
this.selectedProgrammingLanguageValue = this.programmingExercise.programmingLanguage!;
Expand Down Expand Up @@ -615,15 +615,15 @@ export class ProgrammingExerciseUpdateComponent implements AfterViewInit, OnDest
*/
saveExercise() {
// trim potential whitespaces that can lead to issues
if (this.programmingExercise.buildConfig!.windFile?.metadata?.docker?.image) {
this.programmingExercise.buildConfig!.windFile.metadata.docker.image = this.programmingExercise.buildConfig!.windFile.metadata.docker.image.trim();
if (this.programmingExercise.buildConfig!.windfile?.metadata?.docker?.image) {
this.programmingExercise.buildConfig!.windfile.metadata.docker.image = this.programmingExercise.buildConfig!.windfile.metadata.docker.image.trim();
BBesrour marked this conversation as resolved.
Show resolved Hide resolved
}

if (this.programmingExercise.customizeBuildPlanWithAeolus) {
this.programmingExercise.buildConfig!.buildPlanConfiguration = this.aeolusService.serializeWindFile(this.programmingExercise.buildConfig!.windFile!);
if (this.programmingExercise.customizeBuildPlanWithAeolus || this.isImportFromFile) {
this.programmingExercise.buildConfig!.buildPlanConfiguration = this.aeolusService.serializeWindFile(this.programmingExercise.buildConfig!.windfile!);
} else {
this.programmingExercise.buildConfig!.buildPlanConfiguration = undefined;
this.programmingExercise.buildConfig!.windFile = undefined;
this.programmingExercise.buildConfig!.windfile = undefined;
BBesrour marked this conversation as resolved.
Show resolved Hide resolved
}
// If the programming exercise has a submission policy with a NONE type, the policy is removed altogether
if (this.programmingExercise.submissionPolicy && this.programmingExercise.submissionPolicy.type === SubmissionPolicyType.NONE) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
</div>
@if (programmingExercise.customizeBuildPlanWithAeolus) {
<div class="row m-1">
@if (programmingExercise.buildConfig?.windFile && programmingExercise.buildConfig?.windFile?.metadata && programmingExercise.buildConfig?.windFile?.metadata?.docker) {
@if (programmingExercise.buildConfig?.windfile && programmingExercise.buildConfig?.windfile?.metadata && programmingExercise.buildConfig?.windfile?.metadata?.docker) {
<jhi-programming-exercise-docker-image
[dockerImage]="programmingExercise.buildConfig!.windFile!.metadata.docker.image"
[dockerImage]="programmingExercise.buildConfig!.windfile!.metadata.docker.image"
(dockerImageChange)="setDockerImage($event)"
/>
}
<div class="col-3 col-md-3">
<div class="d-flex flex-column h-100 justify-content-between">
<div class="list-group">
@for (action of this.programmingExercise.buildConfig?.windFile?.actions; track action) {
@for (action of this.programmingExercise.buildConfig?.windfile?.actions; track action) {
<div class="list-group-item mb-1" [ngClass]="{ active: active?.name === action.name }" (click)="changeActiveAction(action.name)">
<div class="d-flex w-100 justify-content-between">
<p class="mb-0">{{ action.name }}</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ export class ProgrammingExerciseCustomAeolusBuildPlanComponent implements OnChan
ngOnChanges(changes: SimpleChanges) {
if (changes.programmingExerciseCreationConfig || changes.programmingExercise) {
if (this.shouldReloadTemplate()) {
this.loadAeolusTemplate();
const isImportFromFile = changes.programmingExerciseCreationConfig?.currentValue?.isImportFromFile ?? false;
this.loadAeolusTemplate(isImportFromFile);
}
}
}
Expand All @@ -62,20 +63,21 @@ export class ProgrammingExerciseCustomAeolusBuildPlanComponent implements OnChan
* @private
*/
resetCustomBuildPlan() {
this.programmingExercise.buildConfig!.windFile = undefined;
this.programmingExercise.buildConfig!.windfile = undefined;
this.programmingExercise.buildConfig!.buildPlanConfiguration = undefined;
}

/**
* Loads the predefined template for the selected programming language and project type
* if there is one available.
* @param isImportFromFile whether the exercise is imported from a file
* @private
*/
loadAeolusTemplate() {
if (this.programmingExercise?.id) {
if (!this.programmingExerciseCreationConfig.buildPlanLoaded && !this.programmingExercise.buildConfig?.windFile) {
loadAeolusTemplate(isImportFromFile: boolean = false) {
BBesrour marked this conversation as resolved.
Show resolved Hide resolved
if (this.programmingExercise?.id || isImportFromFile) {
BBesrour marked this conversation as resolved.
Show resolved Hide resolved
if (!this.programmingExerciseCreationConfig.buildPlanLoaded && !this.programmingExercise.buildConfig?.windfile) {
if (this.programmingExercise.buildConfig?.buildPlanConfiguration) {
this.programmingExercise.buildConfig!.windFile = this.aeolusService.parseWindFile(this.programmingExercise.buildConfig?.buildPlanConfiguration);
this.programmingExercise.buildConfig!.windfile = this.aeolusService.parseWindFile(this.programmingExercise.buildConfig?.buildPlanConfiguration);
}
this.programmingExerciseCreationConfig.buildPlanLoaded = true;
}
Expand All @@ -90,16 +92,18 @@ export class ProgrammingExerciseCustomAeolusBuildPlanComponent implements OnChan
this.staticCodeAnalysisEnabled = this.programmingExercise.staticCodeAnalysisEnabled;
this.sequentialTestRuns = this.programmingExercise.buildConfig?.sequentialTestRuns;
this.testwiseCoverageEnabled = this.programmingExercise.buildConfig?.testwiseCoverageEnabled;
this.aeolusService
.getAeolusTemplateFile(this.programmingLanguage, this.projectType, this.staticCodeAnalysisEnabled, this.sequentialTestRuns, this.testwiseCoverageEnabled)
.subscribe({
next: (file) => {
this.programmingExercise.buildConfig!.windFile = this.aeolusService.parseWindFile(file);
},
error: () => {
this.programmingExercise.buildConfig!.windFile = undefined;
},
});
if (!isImportFromFile || !this.programmingExercise.buildConfig?.windfile) {
this.aeolusService
.getAeolusTemplateFile(this.programmingLanguage, this.projectType, this.staticCodeAnalysisEnabled, this.sequentialTestRuns, this.testwiseCoverageEnabled)
.subscribe({
next: (file) => {
this.programmingExercise.buildConfig!.windfile = this.aeolusService.parseWindFile(file);
},
error: () => {
this.programmingExercise.buildConfig!.windfile = undefined;
},
});
}
this.programmingExerciseCreationConfig.buildPlanLoaded = true;
}

Expand All @@ -110,29 +114,29 @@ export class ProgrammingExerciseCustomAeolusBuildPlanComponent implements OnChan
faQuestionCircle = faQuestionCircle;

protected getActionScript(action: string): string {
const foundAction: BuildAction | undefined = this.programmingExercise.buildConfig?.windFile?.actions.find((a) => a.name === action);
const foundAction: BuildAction | undefined = this.programmingExercise.buildConfig?.windfile?.actions.find((a) => a.name === action);
if (foundAction && foundAction instanceof ScriptAction) {
return (foundAction as ScriptAction).script;
}
return '';
}

changeActiveAction(action: string): void {
if (!this.programmingExercise.buildConfig?.windFile) {
if (!this.programmingExercise.buildConfig?.windfile) {
return;
}

this.code = this.getActionScript(action);
this.active = this.programmingExercise.buildConfig?.windFile.actions.find((a) => a.name === action);
this.active = this.programmingExercise.buildConfig?.windfile.actions.find((a) => a.name === action);
this.isScriptAction = this.active instanceof ScriptAction;
if (this.isScriptAction && this.editor) {
this.editor.setText(this.code);
}
}

deleteAction(action: string): void {
if (this.programmingExercise.buildConfig?.windFile) {
this.programmingExercise.buildConfig!.windFile.actions = this.programmingExercise.buildConfig?.windFile.actions.filter((a) => a.name !== action);
if (this.programmingExercise.buildConfig?.windfile) {
this.programmingExercise.buildConfig!.windfile.actions = this.programmingExercise.buildConfig?.windfile.actions.filter((a) => a.name !== action);
if (this.active?.name === action) {
this.active = undefined;
this.code = '';
Expand All @@ -141,12 +145,12 @@ export class ProgrammingExerciseCustomAeolusBuildPlanComponent implements OnChan
}

addAction(action: string): void {
if (this.programmingExercise.buildConfig?.windFile) {
if (this.programmingExercise.buildConfig?.windfile) {
const newAction = new ScriptAction();
newAction.script = '#!/bin/bash\n\n# Add your custom build plan action here\n\nexit 0';
newAction.name = action;
newAction.runAlways = false;
this.programmingExercise.buildConfig?.windFile.actions.push(newAction);
this.programmingExercise.buildConfig?.windfile.actions.push(newAction);
this.changeActiveAction(action);
}
}
Expand Down Expand Up @@ -194,9 +198,9 @@ export class ProgrammingExerciseCustomAeolusBuildPlanComponent implements OnChan
}

setDockerImage(dockerImage: string) {
if (!this.programmingExercise.buildConfig?.windFile || !this.programmingExercise.buildConfig?.windFile.metadata.docker) {
if (!this.programmingExercise.buildConfig?.windfile || !this.programmingExercise.buildConfig?.windfile.metadata.docker) {
return;
}
this.programmingExercise.buildConfig!.windFile.metadata.docker.image = dockerImage.trim();
this.programmingExercise.buildConfig!.windfile.metadata.docker.image = dockerImage.trim();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
</div>
@if (programmingExercise.customizeBuildPlanWithAeolus) {
<div class="row m-1">
@if (programmingExercise.buildConfig?.windFile && programmingExercise.buildConfig?.windFile?.metadata && programmingExercise.buildConfig?.windFile?.metadata?.docker) {
@if (programmingExercise.buildConfig?.windfile && programmingExercise.buildConfig?.windfile?.metadata && programmingExercise.buildConfig?.windfile?.metadata?.docker) {
<jhi-programming-exercise-docker-image
[dockerImage]="programmingExercise.buildConfig!.windFile!.metadata.docker.image"
[dockerImage]="programmingExercise.buildConfig!.windfile!.metadata.docker.image"
(dockerImageChange)="setDockerImage($event)"
/>
}
Expand Down
Loading
Loading