Skip to content

Commit f2f20c3

Browse files
committed
Make abstractconfigurable ready to be used in serializable classes
1 parent d516313 commit f2f20c3

File tree

3 files changed

+14
-28
lines changed

3 files changed

+14
-28
lines changed

framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/configuration/AbstractConfigurable.java

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
/* Licensed under MIT 2022-2024. */
22
package edu.kit.kastel.mcse.ardoco.core.configuration;
33

4-
import java.io.IOException;
5-
import java.io.ObjectInputStream;
6-
import java.io.ObjectOutputStream;
7-
import java.io.Serial;
84
import java.lang.reflect.Field;
95
import java.lang.reflect.ParameterizedType;
106
import java.util.ArrayList;
@@ -14,20 +10,20 @@
1410
import java.util.SortedMap;
1511
import java.util.TreeMap;
1612

17-
import org.apache.commons.lang3.reflect.FieldUtils;
1813
import org.slf4j.Logger;
1914
import org.slf4j.LoggerFactory;
2015

2116
import edu.kit.kastel.mcse.ardoco.core.architecture.Deterministic;
2217

2318
@Deterministic
2419
public abstract class AbstractConfigurable implements IConfigurable {
25-
protected final Logger logger = LoggerFactory.getLogger(this.getClass());
26-
2720
public static final String CLASS_ATTRIBUTE_CONNECTOR = "::";
2821
public static final String KEY_VALUE_CONNECTOR = "=";
2922
public static final String LIST_SEPARATOR = ",";
3023

24+
@SuppressWarnings("java:S2065") // The logger is used in the subclasses that are serializable
25+
private transient Logger logger;
26+
3127
private SortedMap<String, String> lastAppliedConfiguration = new TreeMap<>();
3228

3329
@Override
@@ -50,7 +46,7 @@ private void applyConfiguration(SortedMap<String, String> additionalConfiguratio
5046
}
5147

5248
if (currentClassInHierarchy.getAnnotation(NoConfiguration.class) != null) {
53-
this.logger.debug("Skipping configuration for class {}", currentClassInHierarchy.getSimpleName());
49+
this.getLogger().debug("Skipping configuration for class {}", currentClassInHierarchy.getSimpleName());
5450
return;
5551
}
5652

@@ -101,7 +97,7 @@ private void setValue(Field field, String value) {
10197
field.setAccessible(true);
10298
field.set(this, parsedValue);
10399
} catch (Exception e) {
104-
this.logger.error(e.getMessage(), e);
100+
this.getLogger().error(e.getMessage(), e);
105101
}
106102
}
107103

@@ -131,20 +127,10 @@ private Object parse(Field field, Class<?> fieldsClass, String value) {
131127
throw new IllegalArgumentException("Could not find a parse method for fields of type: " + fieldsClass);
132128
}
133129

134-
@Serial
135-
private void writeObject(ObjectOutputStream objectOutputStream) throws IOException {
136-
objectOutputStream.defaultWriteObject();
137-
}
138-
139-
@Serial
140-
private void readObject(ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException {
141-
objectInputStream.defaultReadObject();
142-
try {
143-
var loggerField = Arrays.stream(FieldUtils.getAllFields(this.getClass())).filter(f -> f.getName().equals("logger")).findFirst().orElseThrow();
144-
loggerField.setAccessible(true);
145-
loggerField.set(this, LoggerFactory.getLogger(this.getClass()));
146-
} catch (IllegalAccessException e) {
147-
throw new IllegalAccessError(e.getMessage());
130+
protected final Logger getLogger() {
131+
if (this.logger == null) {
132+
this.logger = LoggerFactory.getLogger(this.getClass());
148133
}
134+
return this.logger;
149135
}
150136
}

framework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/pipeline/Pipeline.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ public boolean wasExecuted() {
7474
public void process() {
7575
this.preparePipelineSteps();
7676
for (var pipelineStep : this.pipelineSteps) {
77-
this.logger.info("Starting {} - {}", this.getId(), pipelineStep.getId());
77+
this.getLogger().info("Starting {} - {}", this.getId(), pipelineStep.getId());
7878
var start = Instant.now();
7979

8080
pipelineStep.run();
8181

82-
if (this.logger.isInfoEnabled()) {
82+
if (this.getLogger().isInfoEnabled()) {
8383
var end = Instant.now();
8484
var duration = Duration.between(start, end);
8585
long minutesPart = duration.toMinutes();
@@ -92,7 +92,7 @@ public void process() {
9292
durationString = String.format("%01d.%03d s", secondsPart, millisPart);
9393
}
9494

95-
this.logger.info("Finished {} - {} in {}", this.getId(), pipelineStep.getId(), durationString);
95+
this.getLogger().info("Finished {} - {} in {}", this.getId(), pipelineStep.getId(), durationString);
9696
}
9797
}
9898
}

pipeline-core/src/main/java/edu/kit/kastel/mcse/ardoco/core/execution/ArDoCo.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public ArDoCoResult runAndSave(File outputDir) {
6868
classLogger.info("Starting {}", this.projectName);
6969

7070
if (!this.hasPipelineSteps()) {
71-
this.logger.error("Pipeline has not been defined and initialized beforehand. Aborting!");
71+
this.getLogger().error("Pipeline has not been defined and initialized beforehand. Aborting!");
7272
return null;
7373
}
7474

@@ -79,7 +79,7 @@ public ArDoCoResult runAndSave(File outputDir) {
7979
ArDoCoResult arDoCoResult = new ArDoCoResult(this.getDataRepository());
8080
saveOutput(this.projectName, outputDir, arDoCoResult);
8181

82-
if (this.logger.isInfoEnabled()) {
82+
if (this.getLogger().isInfoEnabled()) {
8383
var duration = Duration.between(startTime, endTime);
8484
long minutesPart = duration.toMinutes();
8585
int secondsPart = duration.toSecondsPart();

0 commit comments

Comments
 (0)