Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Development: Replace usage of standard streams with logger calls #7399

Merged
merged 3 commits into from
Oct 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
for (TypeElement annotation : annotations) {
Set<? extends Element> 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;
}
Expand Down Expand Up @@ -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");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
11 changes: 11 additions & 0 deletions src/test/java/de/tum/in/www1/artemis/ArchitectureTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<? super JavaAnnotation<?>> simpleNameAnnotation(String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;

Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void initRepo(String defaultBranch) {
remoteGit.close();
}
catch (IOException | GitAPIException ex) {
ex.printStackTrace();
fail(ex.getMessage(), ex);
}
}

Expand Down