From c3e36629c746f9bfd0f673a8e3594bfc06a196e6 Mon Sep 17 00:00:00 2001 From: Lucas Welscher Date: Sat, 21 Oct 2023 11:19:54 +0200 Subject: [PATCH] Development: Replace usage of standard streams with logger calls (#7399) --- .../in/www1/artemis/config/BeanInfoProcessor.java | 9 +++++++-- .../config/localvcci/LocalCIConfiguration.java | 4 ++-- .../migration/entries/BambooMigrationService.java | 14 +++++++------- .../entries/GitLabJenkinsMigrationService.java | 2 +- .../entries/MigrationEntry20230808_203400.java | 2 +- .../entries/MigrationEntry20230920_181600.java | 2 +- .../www1/artemis/domain/ProgrammingExercise.java | 4 ++-- .../ProgrammingExerciseParticipation.java | 2 +- .../connectors/gitlabci/GitLabCIService.java | 2 +- .../ldap/LdapAuthenticationProvider.java | 2 +- .../localci/LocalCIBuildJobExecutionService.java | 4 ++-- .../localci/LocalCIConnectorService.java | 2 +- .../ExerciseWithSubmissionsExportService.java | 2 +- .../PushNotificationService.java | 2 +- .../ProgrammingExerciseExportImportResource.java | 2 +- .../open/PublicProgrammingSubmissionResource.java | 2 +- .../de/tum/in/www1/artemis/ArchitectureTest.java | 11 +++++++++++ .../connector/BitbucketRequestMockProvider.java | 6 +++++- .../ModelingExerciseUtilService.java | 3 ++- ...ProgrammingExerciseTemplateIntegrationTest.java | 2 +- .../SubmissionExportIntegrationTest.java | 4 ++-- .../tum/in/www1/artemis/util/GitUtilService.java | 2 +- 22 files changed, 53 insertions(+), 32 deletions(-) diff --git a/src/main/java/de/tum/in/www1/artemis/config/BeanInfoProcessor.java b/src/main/java/de/tum/in/www1/artemis/config/BeanInfoProcessor.java index 83d7759072cd..f7f4c26182dd 100644 --- a/src/main/java/de/tum/in/www1/artemis/config/BeanInfoProcessor.java +++ b/src/main/java/de/tum/in/www1/artemis/config/BeanInfoProcessor.java @@ -17,6 +17,9 @@ import javax.tools.Diagnostic.Kind; import javax.tools.JavaFileObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import com.google.auto.service.AutoService; // TODO this is not working yet @@ -25,12 +28,14 @@ @SupportedSourceVersion(SourceVersion.RELEASE_17) public class BeanInfoProcessor extends AbstractProcessor { + private final Logger log = LoggerFactory.getLogger(BeanInfoProcessor.class); + @Override public boolean process(Set annotations, RoundEnvironment roundEnv) { for (TypeElement annotation : annotations) { Set annotatedElements = new HashSet<>(roundEnv.getElementsAnnotatedWith(annotation)); annotatedElements.stream().filter(ele -> ele.getKind().isClass()).map(ele -> (TypeElement) ele).flatMap(ele -> findSupers(ele).stream()) - .forEach(ele -> generateBeanInfo((TypeElement) ele)); + .forEach(ele -> generateBeanInfo(ele)); } return false; } @@ -69,7 +74,7 @@ private void generateBeanInfo(TypeElement typeElement) { processingEnv.getMessager().printMessage(Kind.WARNING, "Cannot create " + beanInfoFQN + ", maybe it already exists?"); } catch (IOException e) { - e.printStackTrace(); + log.error("Error while generating bean info", e); processingEnv.getMessager().printMessage(Kind.ERROR, "IO exception"); } } diff --git a/src/main/java/de/tum/in/www1/artemis/config/localvcci/LocalCIConfiguration.java b/src/main/java/de/tum/in/www1/artemis/config/localvcci/LocalCIConfiguration.java index 673b53da087f..1881a9d25d37 100644 --- a/src/main/java/de/tum/in/www1/artemis/config/localvcci/LocalCIConfiguration.java +++ b/src/main/java/de/tum/in/www1/artemis/config/localvcci/LocalCIConfiguration.java @@ -71,7 +71,7 @@ public ExecutorService localCIBuildExecutorService() { log.info("Using ExecutorService with thread pool size {} and a queue size limit of {}.", threadPoolSize, queueSizeLimit); ThreadFactory customThreadFactory = new ThreadFactoryBuilder().setNameFormat("local-ci-build-%d") - .setUncaughtExceptionHandler((thread, exception) -> log.error("Uncaught exception in thread " + thread.getName(), exception)).build(); + .setUncaughtExceptionHandler((thread, exception) -> log.error("Uncaught exception in thread {}", thread.getName(), exception)).build(); RejectedExecutionHandler customRejectedExecutionHandler = (runnable, executor) -> { throw new RejectedExecutionException("Task " + runnable.toString() + " rejected from " + executor.toString()); @@ -120,7 +120,7 @@ public DockerClient dockerClient() { DockerHttpClient httpClient = new ApacheDockerHttpClient.Builder().dockerHost(config.getDockerHost()).sslConfig(config.getSSLConfig()).build(); DockerClient dockerClient = DockerClientImpl.getInstance(config, httpClient); - log.info("Docker client created with connection URI: " + dockerConnectionUri); + log.info("Docker client created with connection URI: {}", dockerConnectionUri); return dockerClient; } diff --git a/src/main/java/de/tum/in/www1/artemis/config/migration/entries/BambooMigrationService.java b/src/main/java/de/tum/in/www1/artemis/config/migration/entries/BambooMigrationService.java index bb44f546c6c3..9164c7d5ac7d 100644 --- a/src/main/java/de/tum/in/www1/artemis/config/migration/entries/BambooMigrationService.java +++ b/src/main/java/de/tum/in/www1/artemis/config/migration/entries/BambooMigrationService.java @@ -133,7 +133,7 @@ public void overrideBuildPlanNotification(String projectKey, String buildPlanKey deleteBuildPlanServerNotificationId(buildPlanKey, id); } catch (RestClientException e) { - log.error("Could not delete notification with id " + id + " for build plan " + buildPlanKey, e); + log.error("Could not delete notification with id {} for build plan {}", id, buildPlanKey, e); } }); @@ -158,7 +158,7 @@ public void deleteBuildTriggers(String projectKey, String buildPlanKey, VcsRepos } for (var id : triggerIds) { deleteBuildPlanTriggerId(buildPlanKey, id); - log.debug("Deleted trigger with id " + id + " for build plan " + buildPlanKey); + log.debug("Deleted trigger with id {} for build plan {}", id, buildPlanKey); } } @@ -171,7 +171,7 @@ public void deleteBuildTriggers(String projectKey, String buildPlanKey, VcsRepos public void checkPrerequisites() throws ContinuousIntegrationException { Optional credentialsId = getSharedCredential(); if (credentialsId.isEmpty()) { - log.error("No shared credentials found on Bamboo for git user " + gitUser + ". Migration will fail."); + log.error("No shared credentials found on Bamboo for git user {}. Migration will fail.", gitUser); throw new ContinuousIntegrationException("No shared credential found for git user " + gitUser + " in Bamboo. Migration will fail. Please create a shared username and password credential for this user and run the migration again."); } @@ -183,7 +183,7 @@ public void overrideBuildPlanRepository(String buildPlanId, String name, String if (this.sharedCredentialId.isEmpty()) { Optional credentialsId = getSharedCredential(); if (credentialsId.isEmpty()) { - log.error("No shared credential found for git user " + gitUser + ". Migration will fail."); + log.error("No shared credential found for git user {}. Migration will fail.", gitUser); throw new ContinuousIntegrationException("No shared credential found for git user " + gitUser + " in Bamboo. Migration will fail. Please create a shared username and password credential for this user and run the migration again."); } @@ -196,13 +196,13 @@ public void overrideBuildPlanRepository(String buildPlanId, String name, String // if we do not find the edge case "solution" repository in the build plan, we simply continue return; } - log.info("Repository " + name + " not found for build plan " + buildPlanId + ", will be added now"); + log.info("Repository {} not found for build plan {}, will be added now", name, buildPlanId); } else { - log.debug("Deleting repository " + name + " for build plan " + buildPlanId); + log.debug("Deleting repository {} for build plan {}", name, buildPlanId); deleteLinkedRepository(buildPlanId, repositoryId.get()); } - log.debug("Adding repository " + name + " for build plan " + buildPlanId); + log.debug("Adding repository {} for build plan {}", name, buildPlanId); addGitRepository(buildPlanId, bambooInternalUrlService.toInternalVcsUrl(repositoryUrl), name, this.sharedCredentialId.orElseThrow(), defaultBranch); } diff --git a/src/main/java/de/tum/in/www1/artemis/config/migration/entries/GitLabJenkinsMigrationService.java b/src/main/java/de/tum/in/www1/artemis/config/migration/entries/GitLabJenkinsMigrationService.java index b64bd3951907..4f221ef9a1dd 100644 --- a/src/main/java/de/tum/in/www1/artemis/config/migration/entries/GitLabJenkinsMigrationService.java +++ b/src/main/java/de/tum/in/www1/artemis/config/migration/entries/GitLabJenkinsMigrationService.java @@ -74,7 +74,7 @@ public void overrideBuildPlanNotification(String projectKey, String buildPlanKey jenkinsJobService.updateJob(projectKey, buildPlanKey, newConfig); } catch (IOException | TransformerException e) { - log.error("Could not fix build plan notification for build plan " + buildPlanKey + " in project " + projectKey, e); + log.error("Could not fix build plan notification for build plan {} in project {}", buildPlanKey, projectKey, e); throw new JenkinsException(e); } } diff --git a/src/main/java/de/tum/in/www1/artemis/config/migration/entries/MigrationEntry20230808_203400.java b/src/main/java/de/tum/in/www1/artemis/config/migration/entries/MigrationEntry20230808_203400.java index b4abc7498f84..56d71f3e7560 100644 --- a/src/main/java/de/tum/in/www1/artemis/config/migration/entries/MigrationEntry20230808_203400.java +++ b/src/main/java/de/tum/in/www1/artemis/config/migration/entries/MigrationEntry20230808_203400.java @@ -606,7 +606,7 @@ private void evaluateErrorList() { log.error("Failed to migrate students participations: {}", failedStudentParticipations); log.warn("Please check the logs for more information. If the issues are related to the external VCS/CI system, fix the issues and rerun the migration. or " + "fix the build plans yourself and mark the migration as run. The migration can be rerun by deleting the migration entry in the database table containing " - + "the migration with author: " + author() + " and date_string: " + date() + " and then restarting Artemis."); + + "the migration with author: {} and date_string: {} and then restarting Artemis.", author(), date()); } @Override diff --git a/src/main/java/de/tum/in/www1/artemis/config/migration/entries/MigrationEntry20230920_181600.java b/src/main/java/de/tum/in/www1/artemis/config/migration/entries/MigrationEntry20230920_181600.java index e9fbdf8dc135..33820bd5f583 100644 --- a/src/main/java/de/tum/in/www1/artemis/config/migration/entries/MigrationEntry20230920_181600.java +++ b/src/main/java/de/tum/in/www1/artemis/config/migration/entries/MigrationEntry20230920_181600.java @@ -341,7 +341,7 @@ private void evaluateErrorList() { log.error("Failed to migrate students participations: {}", failedStudentParticipations); log.warn("Please check the logs for more information. If the issues are related to the external VCS/CI system, fix the issues and rerun the migration. or " + "fix the build plans yourself and mark the migration as run. The migration can be rerun by deleting the migration entry in the database table containing " - + "the migration with author: " + author() + " and date_string: " + date() + " and then restarting Artemis."); + + "the migration with author: {} and date_string: {} and then restarting Artemis.", author(), date()); } @Override diff --git a/src/main/java/de/tum/in/www1/artemis/domain/ProgrammingExercise.java b/src/main/java/de/tum/in/www1/artemis/domain/ProgrammingExercise.java index 134a39ed56d1..72ea15054e85 100644 --- a/src/main/java/de/tum/in/www1/artemis/domain/ProgrammingExercise.java +++ b/src/main/java/de/tum/in/www1/artemis/domain/ProgrammingExercise.java @@ -478,7 +478,7 @@ public VcsRepositoryUrl getVcsTemplateRepositoryUrl() { return new VcsRepositoryUrl(templateRepositoryUrl); } catch (URISyntaxException e) { - e.printStackTrace(); + log.warn("Cannot create URI for templateRepositoryUrl: {} due to the following error: {}", templateRepositoryUrl, e.getMessage()); } return null; } @@ -499,7 +499,7 @@ public VcsRepositoryUrl getVcsSolutionRepositoryUrl() { return new VcsRepositoryUrl(solutionRepositoryUrl); } catch (URISyntaxException e) { - e.printStackTrace(); + log.warn("Cannot create URI for solutionRepositoryUrl: {} due to the following error: {}", solutionRepositoryUrl, e.getMessage()); } return null; } diff --git a/src/main/java/de/tum/in/www1/artemis/domain/participation/ProgrammingExerciseParticipation.java b/src/main/java/de/tum/in/www1/artemis/domain/participation/ProgrammingExerciseParticipation.java index c2f5862d752c..cbf03dfcffe3 100644 --- a/src/main/java/de/tum/in/www1/artemis/domain/participation/ProgrammingExerciseParticipation.java +++ b/src/main/java/de/tum/in/www1/artemis/domain/participation/ProgrammingExerciseParticipation.java @@ -70,7 +70,7 @@ default VcsRepositoryUrl getVcsRepositoryUrl() { return new VcsRepositoryUrl(repoUrl); } catch (URISyntaxException e) { - e.printStackTrace(); + log.warn("Cannot create URI for repositoryUrl: {} due to the following error: {}", repoUrl, e.getMessage()); } return null; } diff --git a/src/main/java/de/tum/in/www1/artemis/service/connectors/gitlabci/GitLabCIService.java b/src/main/java/de/tum/in/www1/artemis/service/connectors/gitlabci/GitLabCIService.java index a1c1b43eae5e..fd29e9282fc0 100644 --- a/src/main/java/de/tum/in/www1/artemis/service/connectors/gitlabci/GitLabCIService.java +++ b/src/main/java/de/tum/in/www1/artemis/service/connectors/gitlabci/GitLabCIService.java @@ -156,7 +156,7 @@ private void setupGitLabCIConfiguration(VcsRepositoryUrl repositoryURL, Programm updateVariable(repositoryPath, VARIABLE_TEST_RESULTS_DIR_NAME, "target/surefire-reports"); } catch (GitLabApiException e) { - log.error("Error creating variable for " + repositoryURL.toString() + " The variables may already have been created.", e); + log.error("Error creating variable for {} The variables may already have been created.", repositoryURL, e); } } diff --git a/src/main/java/de/tum/in/www1/artemis/service/connectors/ldap/LdapAuthenticationProvider.java b/src/main/java/de/tum/in/www1/artemis/service/connectors/ldap/LdapAuthenticationProvider.java index 32b88f0449ce..603f5f848579 100644 --- a/src/main/java/de/tum/in/www1/artemis/service/connectors/ldap/LdapAuthenticationProvider.java +++ b/src/main/java/de/tum/in/www1/artemis/service/connectors/ldap/LdapAuthenticationProvider.java @@ -85,7 +85,7 @@ private User getOrCreateUser(Authentication authentication) { // We create our own authorization and use the credentials of the user. byte[] passwordBytes = Utf8.encode(password); boolean passwordCorrect = ldapTemplate.compare(ldapUserDto.getUid().toString(), "userPassword", passwordBytes); - log.debug("Compare password with LDAP entry for user " + username + " to validate login"); + log.debug("Compare password with LDAP entry for user {} to validate login", username); // this is the normal case, where the password is validated if (!passwordCorrect) { throw new BadCredentialsException("Wrong credentials"); diff --git a/src/main/java/de/tum/in/www1/artemis/service/connectors/localci/LocalCIBuildJobExecutionService.java b/src/main/java/de/tum/in/www1/artemis/service/connectors/localci/LocalCIBuildJobExecutionService.java index dec7453e8f85..d7c7effa48e2 100644 --- a/src/main/java/de/tum/in/www1/artemis/service/connectors/localci/LocalCIBuildJobExecutionService.java +++ b/src/main/java/de/tum/in/www1/artemis/service/connectors/localci/LocalCIBuildJobExecutionService.java @@ -197,14 +197,14 @@ private LocalCIBuildResult runScriptAndParseResults(ProgrammingExerciseParticipa localCIContainerService.startContainer(containerId); - log.info("Started container for build job " + containerName); + log.info("Started container for build job {}", containerName); localCIContainerService.populateBuildJobContainer(containerId, assignmentRepositoryPath, testsRepositoryPath, auxiliaryRepositoriesPaths, auxiliaryRepositoryNames, buildScriptPath); localCIContainerService.runScriptInContainer(containerId); - log.info("Finished running the build script in container " + containerName); + log.info("Finished running the build script in container {}", containerName); ZonedDateTime buildCompletedDate = ZonedDateTime.now(); diff --git a/src/main/java/de/tum/in/www1/artemis/service/connectors/localci/LocalCIConnectorService.java b/src/main/java/de/tum/in/www1/artemis/service/connectors/localci/LocalCIConnectorService.java index 46dc42e0a823..b3144fa4d092 100644 --- a/src/main/java/de/tum/in/www1/artemis/service/connectors/localci/LocalCIConnectorService.java +++ b/src/main/java/de/tum/in/www1/artemis/service/connectors/localci/LocalCIConnectorService.java @@ -213,7 +213,7 @@ private void processNewPushToTestRepository(ProgrammingExercise exercise, String // Something went wrong while retrieving the template participation. // At this point, programmingMessagingService.notifyUserAboutSubmissionError() does not work, because the template participation is not available. // The instructor will see in the UI that no build of the template repository was conducted and will receive an error message when triggering the build manually. - log.error("Something went wrong while triggering the template build for exercise " + exercise.getId() + " after the solution build was finished.", e); + log.error("Something went wrong while triggering the template build for exercise {} after the solution build was finished.", exercise.getId(), e); } }); } diff --git a/src/main/java/de/tum/in/www1/artemis/service/export/ExerciseWithSubmissionsExportService.java b/src/main/java/de/tum/in/www1/artemis/service/export/ExerciseWithSubmissionsExportService.java index b57dcda0b5b9..7c677e772c33 100644 --- a/src/main/java/de/tum/in/www1/artemis/service/export/ExerciseWithSubmissionsExportService.java +++ b/src/main/java/de/tum/in/www1/artemis/service/export/ExerciseWithSubmissionsExportService.java @@ -189,7 +189,7 @@ private Path checkForMatchesInProblemStatementAndCreateDirectoryForFiles(Path ou } catch (IOException e) { exportErrors.add("Could not create directory for embedded files: " + e.getMessage()); - log.warn("Could not create directory for embedded files. Won't include embedded files: " + e.getMessage()); + log.warn("Could not create directory for embedded files. Won't include embedded files.", e); return null; } } diff --git a/src/main/java/de/tum/in/www1/artemis/service/notifications/push_notifications/PushNotificationService.java b/src/main/java/de/tum/in/www1/artemis/service/notifications/push_notifications/PushNotificationService.java index dcad944e9101..62de76ccb13b 100644 --- a/src/main/java/de/tum/in/www1/artemis/service/notifications/push_notifications/PushNotificationService.java +++ b/src/main/java/de/tum/in/www1/artemis/service/notifications/push_notifications/PushNotificationService.java @@ -100,7 +100,7 @@ void sendRelayRequest(String body, String relayServerBaseUrl) { }); } catch (RestClientException e) { - log.error("Could not send " + getDeviceType().toString() + " notifications"); + log.error("Could not send {} notifications", getDeviceType().toString()); } } diff --git a/src/main/java/de/tum/in/www1/artemis/web/rest/ProgrammingExerciseExportImportResource.java b/src/main/java/de/tum/in/www1/artemis/web/rest/ProgrammingExerciseExportImportResource.java index 32436e1aa646..d2d749f044e1 100644 --- a/src/main/java/de/tum/in/www1/artemis/web/rest/ProgrammingExerciseExportImportResource.java +++ b/src/main/java/de/tum/in/www1/artemis/web/rest/ProgrammingExerciseExportImportResource.java @@ -271,7 +271,7 @@ public ResponseEntity exportInstructorExercise(@PathVariable long exer path = programmingExerciseExportService.exportProgrammingExerciseForDownload(programmingExercise, Collections.synchronizedList(new ArrayList<>())); } catch (Exception e) { - log.error("Error while exporting programming exercise with id " + exerciseId + " for instructor", e); + log.error("Error while exporting programming exercise with id {} for instructor", exerciseId, e); throw new InternalServerErrorException("Error while exporting programming exercise with id " + exerciseId + " for instructor"); } var finalZipFile = path.toFile(); diff --git a/src/main/java/de/tum/in/www1/artemis/web/rest/open/PublicProgrammingSubmissionResource.java b/src/main/java/de/tum/in/www1/artemis/web/rest/open/PublicProgrammingSubmissionResource.java index 2a41f0202336..43f47ed95b31 100644 --- a/src/main/java/de/tum/in/www1/artemis/web/rest/open/PublicProgrammingSubmissionResource.java +++ b/src/main/java/de/tum/in/www1/artemis/web/rest/open/PublicProgrammingSubmissionResource.java @@ -115,7 +115,7 @@ public ResponseEntity processNewProgrammingSubmission(@PathVariable("parti throw ex; } catch (VersionControlException ex) { - log.warn("User committed to the wrong branch for participation + " + participationId); + log.warn("User committed to the wrong branch for participation {}", participationId); return ResponseEntity.status(HttpStatus.OK).build(); } diff --git a/src/test/java/de/tum/in/www1/artemis/ArchitectureTest.java b/src/test/java/de/tum/in/www1/artemis/ArchitectureTest.java index 3a7aded9442a..67157ec29ac6 100644 --- a/src/test/java/de/tum/in/www1/artemis/ArchitectureTest.java +++ b/src/test/java/de/tum/in/www1/artemis/ArchitectureTest.java @@ -20,6 +20,7 @@ import com.tngtech.archunit.base.DescribedPredicate; import com.tngtech.archunit.core.domain.*; import com.tngtech.archunit.lang.*; +import com.tngtech.archunit.library.GeneralCodingRules; import de.tum.in.www1.artemis.service.WebsocketMessagingService; @@ -96,6 +97,16 @@ void testFileWriteUsage() { usage.check(allClasses); } + @Test + void testLogging() { + GeneralCodingRules.NO_CLASSES_SHOULD_USE_JAVA_UTIL_LOGGING.check(allClasses); + + // We currently need to access standard streams in readTestReports() to use the SurefireReportParser + // The ParallelConsoleAppender is used to print test logs to the console (necessary due to parallel test execution) + var classes = allClasses.that(not(simpleName("ProgrammingExerciseTemplateIntegrationTest").or(simpleName("ParallelConsoleAppender")))); + GeneralCodingRules.NO_CLASSES_SHOULD_ACCESS_STANDARD_STREAMS.check(classes); + } + // Custom Predicates for JavaAnnotations since ArchUnit only defines them for classes private DescribedPredicate> simpleNameAnnotation(String name) { diff --git a/src/test/java/de/tum/in/www1/artemis/connector/BitbucketRequestMockProvider.java b/src/test/java/de/tum/in/www1/artemis/connector/BitbucketRequestMockProvider.java index b25704598df9..8ce1bc8e9881 100644 --- a/src/test/java/de/tum/in/www1/artemis/connector/BitbucketRequestMockProvider.java +++ b/src/test/java/de/tum/in/www1/artemis/connector/BitbucketRequestMockProvider.java @@ -15,6 +15,8 @@ import org.hamcrest.BaseMatcher; import org.hamcrest.Description; import org.hamcrest.Matchers; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Value; @@ -47,6 +49,8 @@ @Profile("bitbucket") public class BitbucketRequestMockProvider { + private final Logger log = LoggerFactory.getLogger(BitbucketRequestMockProvider.class); + @Value("${artemis.version-control.url}") private URL bitbucketServerUrl; @@ -301,7 +305,7 @@ public boolean matches(Object actual) { return actual.equals(mapper.writeValueAsString(body)); } catch (JsonProcessingException e) { - e.printStackTrace(); + log.warn("Error while parsing", e); return false; } } diff --git a/src/test/java/de/tum/in/www1/artemis/exercise/modelingexercise/ModelingExerciseUtilService.java b/src/test/java/de/tum/in/www1/artemis/exercise/modelingexercise/ModelingExerciseUtilService.java index dd6713c12373..7441ab315862 100644 --- a/src/test/java/de/tum/in/www1/artemis/exercise/modelingexercise/ModelingExerciseUtilService.java +++ b/src/test/java/de/tum/in/www1/artemis/exercise/modelingexercise/ModelingExerciseUtilService.java @@ -3,6 +3,7 @@ import static com.google.gson.JsonParser.parseString; import static org.assertj.core.api.Assertions.assertThat; +import java.io.IOException; import java.time.ZonedDateTime; import java.util.*; @@ -269,7 +270,7 @@ public Submission addModelingSubmissionWithFinishedResultAndAssessor(ModelingExe return participationUtilService.addSubmissionWithFinishedResultsWithAssessor(participation, submission, assessorLogin); } - public ModelingSubmission addModelingSubmissionFromResources(ModelingExercise exercise, String path, String login) throws Exception { + public ModelingSubmission addModelingSubmissionFromResources(ModelingExercise exercise, String path, String login) throws IOException { String model = FileUtils.loadFileFromResources(path); ModelingSubmission submission = ParticipationFactory.generateModelingSubmission(model, true); submission = addModelingSubmission(exercise, submission, login); diff --git a/src/test/java/de/tum/in/www1/artemis/exercise/programmingexercise/ProgrammingExerciseTemplateIntegrationTest.java b/src/test/java/de/tum/in/www1/artemis/exercise/programmingexercise/ProgrammingExerciseTemplateIntegrationTest.java index 4d7302e4ce97..af0c0fc12fbd 100644 --- a/src/test/java/de/tum/in/www1/artemis/exercise/programmingexercise/ProgrammingExerciseTemplateIntegrationTest.java +++ b/src/test/java/de/tum/in/www1/artemis/exercise/programmingexercise/ProgrammingExerciseTemplateIntegrationTest.java @@ -254,7 +254,7 @@ private int invokeGradle(boolean recordTestwiseCoverage) { } catch (Exception e) { // printing the cause because this contains the relevant error message (and not a generic one from the connector) - log.error("Error occurred while executing Gradle build: " + e.getCause()); + log.error("Error occurred while executing Gradle build.", e.getCause()); return -1; } return 0; diff --git a/src/test/java/de/tum/in/www1/artemis/participation/SubmissionExportIntegrationTest.java b/src/test/java/de/tum/in/www1/artemis/participation/SubmissionExportIntegrationTest.java index aed64f17d927..40e99d2a9e4d 100644 --- a/src/test/java/de/tum/in/www1/artemis/participation/SubmissionExportIntegrationTest.java +++ b/src/test/java/de/tum/in/www1/artemis/participation/SubmissionExportIntegrationTest.java @@ -96,8 +96,8 @@ void initTestCase() { modelingSubmission3 = modelingExerciseUtilService.addModelingSubmissionFromResources(modelingExercise, "test-data/model-submission/model.54745.json", TEST_PREFIX + "student3"); } - catch (Exception e) { - e.printStackTrace(); + catch (IOException e) { + fail(e.getMessage(), e); } } else if (exercise instanceof TextExercise) { diff --git a/src/test/java/de/tum/in/www1/artemis/util/GitUtilService.java b/src/test/java/de/tum/in/www1/artemis/util/GitUtilService.java index 8c60a99967be..7c50534707b6 100644 --- a/src/test/java/de/tum/in/www1/artemis/util/GitUtilService.java +++ b/src/test/java/de/tum/in/www1/artemis/util/GitUtilService.java @@ -83,7 +83,7 @@ public void initRepo(String defaultBranch) { remoteGit.close(); } catch (IOException | GitAPIException ex) { - ex.printStackTrace(); + fail(ex.getMessage(), ex); } }