Skip to content

Commit

Permalink
fix import from file not importing build values
Browse files Browse the repository at this point in the history
  • Loading branch information
BBesrour committed Aug 5, 2024
1 parent fc8aa37 commit 87a7554
Show file tree
Hide file tree
Showing 10 changed files with 114 additions and 104 deletions.
2 changes: 1 addition & 1 deletion src/main/webapp/app/entities/programming-exercise.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export class ProgrammingExercise extends Exercise {
public testCasesChanged?: boolean;

public projectType?: ProjectType;
public windFile?: WindFile;
public windfile?: WindFile;
public buildScript?: string;
public buildPlanConfiguration?: string;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,13 +453,13 @@ export class ProgrammingExerciseDetailComponent implements OnInit, OnDestroy {
},
},
!!exercise.buildScript &&
!!exercise.windFile?.metadata?.docker?.image && {
!!exercise.windfile?.metadata?.docker?.image && {
type: DetailType.Text,
title: 'artemisApp.programmingExercise.dockerImage',
data: { text: exercise.windFile?.metadata?.docker?.image },
data: { text: exercise.windfile?.metadata?.docker?.image },
},
!!exercise.buildScript &&
!!exercise.windFile?.metadata?.docker?.image && {
!!exercise.windfile?.metadata?.docker?.image && {
type: DetailType.Markdown,
title: 'artemisApp.programmingExercise.script',
titleHelpText: 'artemisApp.programmingExercise.revertToTemplateBuildPlan',
Expand Down Expand Up @@ -749,8 +749,8 @@ export class ProgrammingExerciseDetailComponent implements OnInit, OnDestroy {
* @param exercise the programming exercise to check
*/
checkAndSetWindFile(exercise: ProgrammingExercise) {
if (exercise.buildPlanConfiguration && !exercise.windFile) {
exercise.windFile = this.aeolusService.parseWindFile(exercise.buildPlanConfiguration);
if (exercise.buildPlanConfiguration && !exercise.windfile) {
exercise.windfile = this.aeolusService.parseWindFile(exercise.buildPlanConfiguration);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ export class ProgrammingExerciseUpdateComponent implements AfterViewInit, OnDest
this.selectedProjectTypeValue = this.projectTypes?.[0];
this.withDependenciesValue = false;
this.buildPlanLoaded = false;
this.programmingExercise.windFile = undefined;
this.programmingExercise.windfile = undefined;
this.programmingExercise.buildPlanConfiguration = undefined;
}

Expand Down Expand Up @@ -386,7 +386,7 @@ export class ProgrammingExerciseUpdateComponent implements AfterViewInit, OnDest
this.activatedRoute.data.subscribe(({ programmingExercise }) => {
this.programmingExercise = programmingExercise;
if (this.programmingExercise.buildPlanConfiguration) {
this.programmingExercise.windFile = this.aeolusService.parseWindFile(this.programmingExercise.buildPlanConfiguration);
this.programmingExercise.windfile = this.aeolusService.parseWindFile(this.programmingExercise.buildPlanConfiguration);
}
this.backupExercise = cloneDeep(this.programmingExercise);
this.selectedProgrammingLanguageValue = this.programmingExercise.programmingLanguage!;
Expand Down Expand Up @@ -611,15 +611,15 @@ export class ProgrammingExerciseUpdateComponent implements AfterViewInit, OnDest
*/
saveExercise() {
// trim potential whitespaces that can lead to issues
if (this.programmingExercise.windFile?.metadata?.docker?.image) {
this.programmingExercise.windFile.metadata.docker.image = this.programmingExercise.windFile.metadata.docker.image.trim();
if (this.programmingExercise.windfile?.metadata?.docker?.image) {
this.programmingExercise.windfile.metadata.docker.image = this.programmingExercise.windfile.metadata.docker.image.trim();
}

if (this.programmingExercise.customizeBuildPlanWithAeolus) {
this.programmingExercise.buildPlanConfiguration = this.aeolusService.serializeWindFile(this.programmingExercise.windFile!);
this.programmingExercise.buildPlanConfiguration = this.aeolusService.serializeWindFile(this.programmingExercise.windfile!);
} else {
this.programmingExercise.buildPlanConfiguration = undefined;
this.programmingExercise.windFile = undefined;
this.programmingExercise.windfile = undefined;
}
// 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,13 +6,13 @@
</div>
@if (programmingExercise.customizeBuildPlanWithAeolus) {
<div class="row m-1">
@if (programmingExercise.windFile && programmingExercise.windFile.metadata && programmingExercise.windFile.metadata.docker) {
<jhi-programming-exercise-docker-image [dockerImage]="programmingExercise.windFile.metadata.docker.image" (dockerImageChange)="setDockerImage($event)" />
@if (programmingExercise.windfile && programmingExercise.windfile.metadata && programmingExercise.windfile.metadata.docker) {
<jhi-programming-exercise-docker-image [dockerImage]="programmingExercise.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.windFile?.actions; track action) {
@for (action of this.programmingExercise.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 @@ -22,6 +22,7 @@ export class ProgrammingExerciseCustomAeolusBuildPlanComponent implements OnChan
staticCodeAnalysisEnabled?: boolean;
sequentialTestRuns?: boolean;
testwiseCoverageEnabled?: boolean;
isImportFromFile: boolean = false;

constructor(private aeolusService: AeolusService) {}

Expand All @@ -42,7 +43,7 @@ export class ProgrammingExerciseCustomAeolusBuildPlanComponent implements OnChan
ngOnChanges(changes: SimpleChanges) {
if (changes.programmingExerciseCreationConfig || changes.programmingExercise) {
if (this.shouldReloadTemplate()) {
this.loadAeolusTemplate();
this.loadAeolusTemplate(changes.programmingExerciseCreationConfig.currentValue.isImportFromFile);
}
}
}
Expand All @@ -62,7 +63,7 @@ export class ProgrammingExerciseCustomAeolusBuildPlanComponent implements OnChan
* @private
*/
resetCustomBuildPlan() {
this.programmingExercise.windFile = undefined;
this.programmingExercise.windfile = undefined;
this.programmingExercise.buildPlanConfiguration = undefined;
}

Expand All @@ -71,11 +72,11 @@ export class ProgrammingExerciseCustomAeolusBuildPlanComponent implements OnChan
* if there is one available.
* @private
*/
loadAeolusTemplate() {
loadAeolusTemplate(isImportFromFile: boolean = false) {
if (this.programmingExercise?.id) {
if (!this.programmingExerciseCreationConfig.buildPlanLoaded && !this.programmingExercise.windFile) {
if (!this.programmingExerciseCreationConfig.buildPlanLoaded && !this.programmingExercise.windfile) {
if (this.programmingExercise.buildPlanConfiguration) {
this.programmingExercise.windFile = this.aeolusService.parseWindFile(this.programmingExercise.buildPlanConfiguration);
this.programmingExercise.windfile = this.aeolusService.parseWindFile(this.programmingExercise.buildPlanConfiguration);
}
this.programmingExerciseCreationConfig.buildPlanLoaded = true;
}
Expand All @@ -90,16 +91,19 @@ export class ProgrammingExerciseCustomAeolusBuildPlanComponent implements OnChan
this.staticCodeAnalysisEnabled = this.programmingExercise.staticCodeAnalysisEnabled;
this.sequentialTestRuns = this.programmingExercise.sequentialTestRuns;
this.testwiseCoverageEnabled = this.programmingExercise.testwiseCoverageEnabled;
this.aeolusService
.getAeolusTemplateFile(this.programmingLanguage, this.projectType, this.staticCodeAnalysisEnabled, this.sequentialTestRuns, this.testwiseCoverageEnabled)
.subscribe({
next: (file) => {
this.programmingExercise.windFile = this.aeolusService.parseWindFile(file);
},
error: () => {
this.programmingExercise.windFile = undefined;
},
});
this.isImportFromFile = isImportFromFile;
if (!isImportFromFile || !this.programmingExercise.windfile) {
this.aeolusService
.getAeolusTemplateFile(this.programmingLanguage, this.projectType, this.staticCodeAnalysisEnabled, this.sequentialTestRuns, this.testwiseCoverageEnabled)
.subscribe({
next: (file) => {
this.programmingExercise.windfile = this.aeolusService.parseWindFile(file);
},
error: () => {
this.programmingExercise.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.windFile?.actions.find((a) => a.name === action);
const foundAction: BuildAction | undefined = this.programmingExercise.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.windFile) {
if (!this.programmingExercise.windfile) {
return;
}

this.code = this.getActionScript(action);
this.active = this.programmingExercise.windFile.actions.find((a) => a.name === action);
this.active = this.programmingExercise.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.windFile) {
this.programmingExercise.windFile.actions = this.programmingExercise.windFile.actions.filter((a) => a.name !== action);
if (this.programmingExercise.windfile) {
this.programmingExercise.windfile.actions = this.programmingExercise.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.windFile) {
if (this.programmingExercise.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.windFile.actions.push(newAction);
this.programmingExercise.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.windFile || !this.programmingExercise.windFile.metadata.docker) {
if (!this.programmingExercise.windfile || !this.programmingExercise.windfile.metadata.docker) {
return;
}
this.programmingExercise.windFile.metadata.docker.image = dockerImage.trim();
this.programmingExercise.windfile.metadata.docker.image = dockerImage.trim();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
</div>
@if (programmingExercise.customizeBuildPlanWithAeolus) {
<div class="row m-1">
@if (programmingExercise.windFile && programmingExercise.windFile.metadata && programmingExercise.windFile.metadata.docker) {
<jhi-programming-exercise-docker-image [dockerImage]="programmingExercise.windFile.metadata.docker.image" (dockerImageChange)="setDockerImage($event)" />
@if (programmingExercise.windfile && programmingExercise.windfile.metadata && programmingExercise.windfile.metadata.docker) {
<jhi-programming-exercise-docker-image [dockerImage]="programmingExercise.windfile.metadata.docker.image" (dockerImageChange)="setDockerImage($event)" />
}
<label jhiTranslate="artemisApp.programmingExercise.script" class="mb-2"></label>
<div class="ms-1 p-0 card col-12 col-md-12">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export class ProgrammingExerciseCustomBuildPlanComponent implements OnChanges {
staticCodeAnalysisEnabled?: boolean;
sequentialTestRuns?: boolean;
testwiseCoverageEnabled?: boolean;
isImportFromFile: boolean = false;

constructor(private aeolusService: AeolusService) {}

Expand All @@ -32,7 +33,7 @@ export class ProgrammingExerciseCustomBuildPlanComponent implements OnChanges {
this._editor = value;
if (this._editor) {
this.setupEditor();
if (this.programmingExercise.id) {
if (this.programmingExercise.id || this.isImportFromFile) {
this.code = this.programmingExercise.buildScript || '';
}
this._editor.setText(this.code);
Expand All @@ -42,7 +43,7 @@ export class ProgrammingExerciseCustomBuildPlanComponent implements OnChanges {
ngOnChanges(changes: SimpleChanges) {
if (changes.programmingExerciseCreationConfig || changes.programmingExercise) {
if (this.shouldReloadTemplate()) {
this.loadAeolusTemplate();
this.loadAeolusTemplate(changes.programmingExerciseCreationConfig.currentValue.isImportFromFile);
}
}
}
Expand All @@ -63,7 +64,7 @@ export class ProgrammingExerciseCustomBuildPlanComponent implements OnChanges {
* @private
*/
resetCustomBuildPlan() {
this.programmingExercise.windFile = undefined;
this.programmingExercise.windfile = undefined;
this.programmingExercise.buildPlanConfiguration = undefined;
this.programmingExercise.buildScript = undefined;
}
Expand All @@ -73,7 +74,7 @@ export class ProgrammingExerciseCustomBuildPlanComponent implements OnChanges {
* if there is one available.
* @private
*/
loadAeolusTemplate() {
loadAeolusTemplate(isImportFromFile: boolean = false) {
if (!this.programmingExercise.programmingLanguage) {
return;
}
Expand All @@ -82,31 +83,36 @@ export class ProgrammingExerciseCustomBuildPlanComponent implements OnChanges {
this.staticCodeAnalysisEnabled = this.programmingExercise.staticCodeAnalysisEnabled;
this.sequentialTestRuns = this.programmingExercise.sequentialTestRuns;
this.testwiseCoverageEnabled = this.programmingExercise.testwiseCoverageEnabled;
this.aeolusService
.getAeolusTemplateFile(this.programmingLanguage, this.projectType, this.staticCodeAnalysisEnabled, this.sequentialTestRuns, this.testwiseCoverageEnabled)
.subscribe({
next: (file) => {
this.programmingExercise.windFile = this.aeolusService.parseWindFile(file);
},
error: () => {
this.programmingExercise.windFile = undefined;
},
});
this.isImportFromFile = isImportFromFile;
if (!isImportFromFile || !this.programmingExercise.windfile) {
this.aeolusService
.getAeolusTemplateFile(this.programmingLanguage, this.projectType, this.staticCodeAnalysisEnabled, this.sequentialTestRuns, this.testwiseCoverageEnabled)
.subscribe({
next: (file) => {
this.programmingExercise.windfile = this.aeolusService.parseWindFile(file);
},
error: () => {
this.programmingExercise.windfile = undefined;
},
});
}
this.programmingExerciseCreationConfig.buildPlanLoaded = true;
if (!this.programmingExercise.windFile) {
if (!this.programmingExercise.windfile) {
this.resetCustomBuildPlan();
}
this.aeolusService
.getAeolusTemplateScript(this.programmingLanguage, this.projectType, this.staticCodeAnalysisEnabled, this.sequentialTestRuns, this.testwiseCoverageEnabled)
.subscribe({
next: (file: string) => {
this.codeChanged(file);
this.editor?.setText(file);
},
error: () => {
this.programmingExercise.buildScript = undefined;
},
});
if (!isImportFromFile || !this.programmingExercise.buildScript) {
this.aeolusService
.getAeolusTemplateScript(this.programmingLanguage, this.projectType, this.staticCodeAnalysisEnabled, this.sequentialTestRuns, this.testwiseCoverageEnabled)
.subscribe({
next: (file: string) => {
this.codeChanged(file);
this.editor?.setText(file);
},
error: () => {
this.programmingExercise.buildScript = undefined;
},
});
}
if (!this.programmingExercise.buildScript) {
this.resetCustomBuildPlan();
}
Expand Down Expand Up @@ -134,9 +140,9 @@ export class ProgrammingExerciseCustomBuildPlanComponent implements OnChanges {
}

setDockerImage(dockerImage: string) {
if (!this.programmingExercise.windFile || !this.programmingExercise.windFile.metadata.docker) {
if (!this.programmingExercise.windfile || !this.programmingExercise.windfile.metadata.docker) {
return;
}
this.programmingExercise.windFile.metadata.docker.image = dockerImage.trim();
this.programmingExercise.windfile.metadata.docker.image = dockerImage.trim();
}
}
Loading

0 comments on commit 87a7554

Please sign in to comment.