Skip to content

Commit

Permalink
Merge pull request #278 from seart-group/enhancement/logging
Browse files Browse the repository at this point in the history
  • Loading branch information
dabico authored Jan 8, 2024
2 parents 96a050b + 1edb947 commit 5761487
Showing 1 changed file with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import ch.usi.si.seart.io.ExternalProcess;
import ch.usi.si.seart.stereotype.Connector;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanInitializationException;
import org.springframework.beans.factory.config.BeanPostProcessor;
Expand All @@ -15,16 +17,20 @@ public class ConnectorAnnotationProcessor implements BeanPostProcessor {

@Override
public Object postProcessBeforeInitialization(Object bean, @NotNull String beanName) throws BeansException {
if (bean.getClass().isAnnotationPresent(Connector.class)) {
Connector annotation = bean.getClass().getAnnotation(Connector.class);
Class<?> type = bean.getClass();
Logger log = LoggerFactory.getLogger(type);
if (type.isAnnotationPresent(Connector.class)) {
Connector annotation = type.getAnnotation(Connector.class);
String command = annotation.command();
String versionFlag = annotation.versionFlag();
try {
new ExternalProcess(command, versionFlag).execute().ifFailedThrow(() -> {
String template = "The '%s' command is not installed";
String message = String.format(template, command);
return new BeanInitializationException(message);
});
ExternalProcess.Result result = new ExternalProcess(command, versionFlag).execute()
.ifFailedThrow(() -> {
String template = "The '%s' command is not installed";
String message = String.format(template, command);
return new BeanInitializationException(message);
});
result.getStdOut().trim().lines().forEach(log::debug);
} catch (TimeoutException ex) {
String template = "Timed out checking '%s'";
String message = String.format(template, command);
Expand Down

0 comments on commit 5761487

Please sign in to comment.