Skip to content

Commit

Permalink
Programming exercises: Fix template upgrade for maven exercises (#8241)
Browse files Browse the repository at this point in the history
  • Loading branch information
Strohgelaender authored Mar 24, 2024
1 parent 2d8dc0b commit c605b34
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 19 deletions.
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ spotless {
"**/build/**",
"**/src/main/generated/**",
"**/src/main/resources/templates/**",
"/docker/**"
"/docker/**",
"checked-out-repos/**"
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private void upgradeTemplateFiles(ProgrammingExercise exercise, RepositoryType r
return;
}
try {
String templatePomDir = repositoryType == RepositoryType.TESTS ? "test/projectTemplate" : repositoryType.getName();
String templatePomDir = repositoryType == RepositoryType.TESTS ? "test/maven/projectTemplate" : repositoryType.getName();
Resource[] templatePoms = getTemplateResources(exercise, templatePomDir + "/**/" + POM_FILE);
Repository repository = gitService.getOrCheckoutRepository(exercise.getRepositoryURL(repositoryType), true);
List<File> repositoryPoms = gitService.listFiles(repository).stream().filter(file -> Objects.equals(file.getName(), POM_FILE)).toList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ <h2 id="jhi-programming-exercise-heading-import" jhiTranslate="artemisApp.progra
[isExamMode]="isExamMode"
[isImport]="isImportFromExistingExercise || isImportFromFile"
[isLocal]="isLocal"
[importOptions]="importOptions"
/>
<hr class="mb-5" />
<jhi-programming-exercise-difficulty [programmingExercise]="programmingExercise" [programmingExerciseCreationConfig]="getProgrammingExerciseCreationConfig()" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ import { ProgrammingExerciseLanguageComponent } from 'app/exercises/programming/
import { ProgrammingExerciseGradingComponent } from 'app/exercises/programming/manage/update/update-components/programming-exercise-grading.component';
import { ExerciseUpdatePlagiarismComponent } from 'app/exercises/shared/plagiarism/exercise-update-plagiarism/exercise-update-plagiarism.component';

export interface ImportOptions {
recreateBuildPlans: boolean;
updateTemplate: boolean;
}

@Component({
selector: 'jhi-programming-exercise-update',
templateUrl: './programming-exercise-update.component.html',
Expand Down Expand Up @@ -139,8 +144,11 @@ export class ProgrammingExerciseUpdateComponent implements AfterViewInit, OnDest
public customBuildPlansSupported: string = '';

// Additional options for import
public recreateBuildPlans = false;
public updateTemplate = false;
// This is a wrapper to allow modifications from the other subcomponents
public readonly importOptions: ImportOptions = {
recreateBuildPlans: false,
updateTemplate: false,
};
public originalStaticCodeAnalysisEnabled: boolean | undefined;

public projectTypes: ProjectType[] = [];
Expand Down Expand Up @@ -626,7 +634,9 @@ export class ProgrammingExerciseUpdateComponent implements AfterViewInit, OnDest
if (this.isImportFromFile) {
this.subscribeToSaveResponse(this.programmingExerciseService.importFromFile(this.programmingExercise, this.courseId));
} else if (this.isImportFromExistingExercise) {
this.subscribeToSaveResponse(this.programmingExerciseService.importExercise(this.programmingExercise, this.recreateBuildPlans, this.updateTemplate));
this.subscribeToSaveResponse(
this.programmingExerciseService.importExercise(this.programmingExercise, this.importOptions.recreateBuildPlans, this.importOptions.updateTemplate),
);
} else if (this.programmingExercise.id !== undefined) {
const requestOptions = {} as any;
if (this.notificationText) {
Expand Down Expand Up @@ -742,8 +752,8 @@ export class ProgrammingExerciseUpdateComponent implements AfterViewInit, OnDest
onStaticCodeAnalysisChanged() {
// On import: If SCA mode changed, activate recreation of build plans and update of the template
if (this.isImportFromExistingExercise && this.programmingExercise.staticCodeAnalysisEnabled !== this.originalStaticCodeAnalysisEnabled) {
this.recreateBuildPlans = true;
this.updateTemplate = true;
this.importOptions.recreateBuildPlans = true;
this.importOptions.updateTemplate = true;
}

if (!this.programmingExercise.staticCodeAnalysisEnabled) {
Expand All @@ -752,7 +762,7 @@ export class ProgrammingExerciseUpdateComponent implements AfterViewInit, OnDest
}

onRecreateBuildPlanOrUpdateTemplateChange() {
if (!this.recreateBuildPlans || !this.updateTemplate) {
if (!this.importOptions.recreateBuildPlans || !this.importOptions.updateTemplate) {
this.programmingExercise.staticCodeAnalysisEnabled = this.originalStaticCodeAnalysisEnabled;
}

Expand Down Expand Up @@ -1075,9 +1085,9 @@ export class ProgrammingExerciseUpdateComponent implements AfterViewInit, OnDest
rerenderSubject: this.rerenderSubject.asObservable(),
validIdeSelection: this.validIdeSelection,
inProductionEnvironment: this.inProductionEnvironment,
recreateBuildPlans: this.recreateBuildPlans,
recreateBuildPlans: this.importOptions.recreateBuildPlans,
onRecreateBuildPlanOrUpdateTemplateChange: this.onRecreateBuildPlanOrUpdateTemplateChange,
updateTemplate: this.updateTemplate,
updateTemplate: this.importOptions.updateTemplate,
publishBuildPlanUrlAllowed: this.publishBuildPlanUrlAllowed,
recreateBuildPlanOrUpdateTemplateChange: this.onRecreateBuildPlanOrUpdateTemplateChange,
buildPlanLoaded: this.buildPlanLoaded,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@
type="checkbox"
name="recreateBuildPlans"
id="field_recreateBuildPlans"
[(ngModel)]="programmingExerciseCreationConfig.recreateBuildPlans"
[(ngModel)]="importOptions.recreateBuildPlans"
(change)="programmingExerciseCreationConfig.recreateBuildPlanOrUpdateTemplateChange()"
/>
<span jhiTranslate="artemisApp.programmingExercise.recreateBuildPlans.title"></span>
Expand All @@ -179,7 +179,7 @@
type="checkbox"
name="updateTemplateFiles"
id="field_updateTemplateFiles"
[(ngModel)]="programmingExerciseCreationConfig.updateTemplate"
[(ngModel)]="importOptions.updateTemplate"
(change)="programmingExerciseCreationConfig.recreateBuildPlanOrUpdateTemplateChange()"
/>
<span jhiTranslate="artemisApp.programmingExercise.updateTemplate.title"></span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { AfterViewInit, Component, Input, OnDestroy, QueryList, ViewChild, ViewC
import { NgModel } from '@angular/forms';
import { ProgrammingExercise, ProjectType } from 'app/entities/programming-exercise.model';
import { ProgrammingExerciseCreationConfig } from 'app/exercises/programming/manage/update/programming-exercise-creation-config';
import { ImportOptions } from 'app/exercises/programming/manage/update/programming-exercise-update.component';
import { ExerciseTitleChannelNameComponent } from 'app/exercises/shared/exercise-title-channel-name/exercise-title-channel-name.component';
import { Subject, Subscription } from 'rxjs';
import { TableEditableFieldComponent } from 'app/shared/table/table-editable-field.component';
Expand All @@ -18,11 +19,11 @@ export class ProgrammingExerciseInformationComponent implements AfterViewInit, O
@Input() programmingExercise: ProgrammingExercise;
@Input() programmingExerciseCreationConfig: ProgrammingExerciseCreationConfig;
@Input() isLocal: boolean;
@Input() importOptions: ImportOptions;

@ViewChild(ExerciseTitleChannelNameComponent) exerciseTitleChannelComponent: ExerciseTitleChannelNameComponent;
@ViewChildren(TableEditableFieldComponent) tableEditableFields?: QueryList<TableEditableFieldComponent>;
@ViewChild('shortName')
shortNameField: NgModel;
@ViewChild('shortName') shortNameField: NgModel;
@ViewChild('checkoutSolutionRepository') checkoutSolutionRepositoryField?: NgModel;
@ViewChild('recreateBuildPlans') recreateBuildPlansField?: NgModel;
@ViewChild('updateTemplateFiles') updateTemplateFilesField?: NgModel;
Expand All @@ -45,7 +46,7 @@ export class ProgrammingExerciseInformationComponent implements AfterViewInit, O
});
}

ngOnDestroy() {
ngOnDestroy(): void {
for (const subscription of this.inputFieldSubscriptions) {
subscription?.unsubscribe();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ describe('ProgrammingExerciseUpdateComponent', () => {
comp.programmingExercise.staticCodeAnalysisEnabled = !scaActivatedOriginal;
comp.onStaticCodeAnalysisChanged();

expect(comp.updateTemplate).toBeTrue();
expect(comp.importOptions.updateTemplate).toBeTrue();

comp.programmingExercise.staticCodeAnalysisEnabled = !scaActivatedOriginal;
comp.onStaticCodeAnalysisChanged();
Expand All @@ -543,10 +543,10 @@ describe('ProgrammingExerciseUpdateComponent', () => {
// Recreate build plan and template update should be automatically selected
expect(comp.programmingExercise.staticCodeAnalysisEnabled).toBe(!scaActivatedOriginal);
expect(comp.programmingExercise.maxStaticCodeAnalysisPenalty).toBe(scaActivatedOriginal ? undefined : newMaxPenalty);
expect(comp.recreateBuildPlans).toBeTrue();
expect(comp.updateTemplate).toBeTrue();
expect(comp.importOptions.recreateBuildPlans).toBeTrue();
expect(comp.importOptions.updateTemplate).toBeTrue();

comp.recreateBuildPlans = !comp.recreateBuildPlans;
comp.importOptions.recreateBuildPlans = !comp.importOptions.recreateBuildPlans;
comp.onRecreateBuildPlanOrUpdateTemplateChange();
tick();

Expand Down

0 comments on commit c605b34

Please sign in to comment.