use of de.tum.in.www1.artemis.domain.enumeration.ProgrammingLanguage in project Artemis by ls1intum.
the class JenkinsService method addFeedbackToResult.
@Override
protected void addFeedbackToResult(Result result, AbstractBuildResultNotificationDTO buildResult) {
final ProgrammingExercise programmingExercise = (ProgrammingExercise) result.getParticipation().getExercise();
final ProgrammingLanguage programmingLanguage = programmingExercise.getProgrammingLanguage();
final var jobs = ((TestResultsDTO) buildResult).getResults();
// Extract test case feedback
for (final var job : jobs) {
for (final var testCase : job.getTestCases()) {
var feedbackMessages = extractMessageFromTestCase(testCase).map(List::of).orElse(List.of());
var feedback = feedbackRepository.createFeedbackFromTestCase(testCase.getName(), feedbackMessages, testCase.isSuccessful(), programmingLanguage);
result.addFeedback(feedback);
}
}
// Extract static code analysis feedback if option was enabled
var staticCodeAnalysisReports = ((TestResultsDTO) buildResult).getStaticCodeAnalysisReports();
if (Boolean.TRUE.equals(programmingExercise.isStaticCodeAnalysisEnabled()) && staticCodeAnalysisReports != null && !staticCodeAnalysisReports.isEmpty()) {
var scaFeedback = feedbackRepository.createFeedbackFromStaticCodeAnalysisReports(staticCodeAnalysisReports);
result.addFeedbacks(scaFeedback);
}
// Relevant feedback is negative, or positive with a message
result.setHasFeedback(result.getFeedbacks().stream().anyMatch(fb -> !fb.isPositive() || fb.getDetailText() != null));
}
use of de.tum.in.www1.artemis.domain.enumeration.ProgrammingLanguage in project Artemis by ls1intum.
the class JenkinsService method onBuildCompleted.
@Override
public Result onBuildCompleted(ProgrammingExerciseParticipation participation, Object requestBody) {
final var buildResult = TestResultsDTO.convert(requestBody);
var newResult = createResultFromBuildResult(buildResult, participation);
// Fetch submission or create a fallback
var latestSubmission = super.getSubmissionForBuildResult(participation.getId(), buildResult).orElseGet(() -> createAndSaveFallbackSubmission(participation, buildResult));
latestSubmission.setBuildFailed("No tests found".equals(newResult.getResultString()));
// Parse, filter, and save the build logs if they exist
if (buildResult.getLogs() != null) {
ProgrammingLanguage programmingLanguage = participation.getProgrammingExercise().getProgrammingLanguage();
List<BuildLogEntry> buildLogEntries = JenkinsBuildLogParseUtils.parseBuildLogsFromJenkinsLogs(buildResult.getLogs());
buildLogEntries = filterUnnecessaryLogs(buildLogEntries, programmingLanguage);
buildLogEntries = buildLogService.saveBuildLogs(buildLogEntries, latestSubmission);
// Set the received logs in order to avoid duplicate entries (this removes existing logs)
latestSubmission.setBuildLogEntries(buildLogEntries);
}
// Note: we only set one side of the relationship because we don't know yet whether the result will actually be saved
newResult.setSubmission(latestSubmission);
newResult.setRatedIfNotExceeded(exerciseDateService.getDueDate(participation).orElse(null), latestSubmission);
return newResult;
}
use of de.tum.in.www1.artemis.domain.enumeration.ProgrammingLanguage in project ArTEMiS by ls1intum.
the class JenkinsService method onBuildCompleted.
@Override
public Result onBuildCompleted(ProgrammingExerciseParticipation participation, Object requestBody) {
final var buildResult = TestResultsDTO.convert(requestBody);
var newResult = createResultFromBuildResult(buildResult, participation);
// Fetch submission or create a fallback
var latestSubmission = super.getSubmissionForBuildResult(participation.getId(), buildResult).orElseGet(() -> createAndSaveFallbackSubmission(participation, buildResult));
latestSubmission.setBuildFailed("No tests found".equals(newResult.getResultString()));
// Parse, filter, and save the build logs if they exist
if (buildResult.getLogs() != null) {
ProgrammingLanguage programmingLanguage = participation.getProgrammingExercise().getProgrammingLanguage();
List<BuildLogEntry> buildLogEntries = JenkinsBuildLogParseUtils.parseBuildLogsFromJenkinsLogs(buildResult.getLogs());
buildLogEntries = filterUnnecessaryLogs(buildLogEntries, programmingLanguage);
buildLogEntries = buildLogService.saveBuildLogs(buildLogEntries, latestSubmission);
// Set the received logs in order to avoid duplicate entries (this removes existing logs)
latestSubmission.setBuildLogEntries(buildLogEntries);
}
// Note: we only set one side of the relationship because we don't know yet whether the result will actually be saved
newResult.setSubmission(latestSubmission);
newResult.setRatedIfNotExceeded(exerciseDateService.getDueDate(participation).orElse(null), latestSubmission);
return newResult;
}
use of de.tum.in.www1.artemis.domain.enumeration.ProgrammingLanguage in project ArTEMiS by ls1intum.
the class JenkinsService method addFeedbackToResult.
@Override
protected void addFeedbackToResult(Result result, AbstractBuildResultNotificationDTO buildResult) {
final ProgrammingExercise programmingExercise = (ProgrammingExercise) result.getParticipation().getExercise();
final ProgrammingLanguage programmingLanguage = programmingExercise.getProgrammingLanguage();
final var jobs = ((TestResultsDTO) buildResult).getResults();
// Extract test case feedback
for (final var job : jobs) {
for (final var testCase : job.getTestCases()) {
var feedbackMessages = extractMessageFromTestCase(testCase).map(List::of).orElse(List.of());
var feedback = feedbackRepository.createFeedbackFromTestCase(testCase.getName(), feedbackMessages, testCase.isSuccessful(), programmingLanguage);
result.addFeedback(feedback);
}
}
// Extract static code analysis feedback if option was enabled
var staticCodeAnalysisReports = ((TestResultsDTO) buildResult).getStaticCodeAnalysisReports();
if (Boolean.TRUE.equals(programmingExercise.isStaticCodeAnalysisEnabled()) && staticCodeAnalysisReports != null && !staticCodeAnalysisReports.isEmpty()) {
var scaFeedback = feedbackRepository.createFeedbackFromStaticCodeAnalysisReports(staticCodeAnalysisReports);
result.addFeedbacks(scaFeedback);
}
// Relevant feedback is negative, or positive with a message
result.setHasFeedback(result.getFeedbacks().stream().anyMatch(fb -> !fb.isPositive() || fb.getDetailText() != null));
}
use of de.tum.in.www1.artemis.domain.enumeration.ProgrammingLanguage in project ArTEMiS by ls1intum.
the class JenkinsService method getLatestBuildLogs.
@Override
public List<BuildLogEntry> getLatestBuildLogs(ProgrammingSubmission programmingSubmission) {
ProgrammingExerciseParticipation programmingExerciseParticipation = (ProgrammingExerciseParticipation) programmingSubmission.getParticipation();
String projectKey = programmingExerciseParticipation.getProgrammingExercise().getProjectKey();
String buildPlanId = programmingExerciseParticipation.getBuildPlanId();
ProgrammingLanguage programmingLanguage = programmingExerciseParticipation.getProgrammingExercise().getProgrammingLanguage();
try {
final var build = jenkinsJobService.getJobInFolder(projectKey, buildPlanId).getLastBuild();
List<BuildLogEntry> buildLogEntries;
// Attempt to parse pipeline logs
final String pipelineLogs = build.details().getConsoleOutputText();
if (pipelineLogs != null && pipelineLogs.contains("[Pipeline] Start of Pipeline")) {
buildLogEntries = JenkinsBuildLogParseUtils.parseBuildLogsFromJenkinsLogs(List.of(pipelineLogs.split("\n")));
} else {
// Fallback to legacy logs
final var logHtml = Jsoup.parse(build.details().getConsoleOutputHtml()).body();
buildLogEntries = JenkinsBuildLogParseUtils.parseLogsLegacy(logHtml);
}
// Filter and save build logs
buildLogEntries = filterUnnecessaryLogs(buildLogEntries, programmingLanguage);
buildLogEntries = buildLogService.saveBuildLogs(buildLogEntries, programmingSubmission);
programmingSubmission.setBuildLogEntries(buildLogEntries);
programmingSubmissionRepository.save(programmingSubmission);
return buildLogEntries;
} catch (IOException e) {
log.error(e.getMessage(), e);
throw new JenkinsException(e.getMessage(), e);
}
}
Aggregations