Skip to content

Commit

Permalink
cache windfiles on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
reschandreas committed Dec 21, 2023
1 parent 173846b commit 3c3f03c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
@Profile("aeolus | localci")
public class AeolusTemplateService {

private final Logger LOGGER = LoggerFactory.getLogger(AeolusTemplateService.class);
private final Logger logger = LoggerFactory.getLogger(AeolusTemplateService.class);

private final ProgrammingLanguageConfiguration programmingLanguageConfiguration;

Expand All @@ -44,6 +44,35 @@ public class AeolusTemplateService {
public AeolusTemplateService(ProgrammingLanguageConfiguration programmingLanguageConfiguration, ResourceLoaderService resourceLoaderService) {
this.programmingLanguageConfiguration = programmingLanguageConfiguration;
this.resourceLoaderService = resourceLoaderService;
// load all scripts into the cache
cacheOnBoot();
}

private void cacheOnBoot() {
var resources = this.resourceLoaderService.getResources(Path.of("templates", "aeolus"));
for (var resource : resources) {
try {
String filename = resource.getFilename();
if (filename == null) {
continue;
}
String directory = resource.getURL().getPath().split("templates/aeolus/")[1].split("/")[0];
String projectType = filename.split("_")[0].replace(".yaml", "");
Optional<ProjectType> optionalProjectType = Optional.empty();
if (!projectType.equals("default")) {
optionalProjectType = Optional.of(ProjectType.valueOf(projectType.toUpperCase()));
}
String uniqueKey = directory + "_" + filename;
byte[] fileContent = IOUtils.toByteArray(resource.getInputStream());
String script = new String(fileContent, StandardCharsets.UTF_8);
Windfile windfile = readWindfile(script);
this.addInstanceVariablesToWindfile(windfile, ProgrammingLanguage.valueOf(directory.toUpperCase()), optionalProjectType);
templateCache.put(uniqueKey, windfile);
}
catch (IOException | IllegalArgumentException e) {
logger.error("Failed to load windfile {}", resource.getFilename(), e);
}
}
}

/**
Expand Down Expand Up @@ -118,7 +147,7 @@ public Windfile getDefaultWindfileFor(ProgrammingExercise exercise) {
exercise.hasSequentialTestRuns(), exercise.isTestwiseCoverageEnabled());
}
catch (IOException e) {
LOGGER.info("No windfile for the settings of exercise {}", exercise.getId(), e);
logger.info("No windfile for the settings of exercise {}", exercise.getId(), e);
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,6 @@ public void onComplete() {
*/
public Path createBuildScript(ProgrammingExerciseParticipation participation, String containerName) {
ProgrammingExercise programmingExercise = participation.getProgrammingExercise();
boolean hasSequentialTestRuns = programmingExercise.hasSequentialTestRuns();
boolean hasStaticCodeAnalysis = programmingExercise.isStaticCodeAnalysisEnabled();

List<ScriptAction> actions = List.of();

Expand Down Expand Up @@ -412,19 +410,6 @@ public Path createBuildScript(ProgrammingExerciseParticipation participation, St
}
});

// Fall back to hardcoded scripts for old exercises without windfile
// *****************
// TODO: Delete once windfile templates can be used as fallbacks
if (actions.isEmpty()) {
// Windfile actions are not defined, use default build script
switch (programmingExercise.getProgrammingLanguage()) {
case JAVA, KOTLIN -> scriptForJavaKotlin(programmingExercise, buildScript, hasSequentialTestRuns, hasStaticCodeAnalysis);
case PYTHON -> scriptForPython(buildScript);
default -> throw new IllegalArgumentException("No build stage setup for programming language " + programmingExercise.getProgrammingLanguage());
}
}
// *****************

try {
FileUtils.writeStringToFile(buildScriptPath.toFile(), buildScript.toString(), StandardCharsets.UTF_8);
}
Expand Down

0 comments on commit 3c3f03c

Please sign in to comment.