Skip to content

Commit

Permalink
Optimize report generation (#119)
Browse files Browse the repository at this point in the history
- Removes Spring and spring Boot dependencies from Flight Evaluation report
- Adds vanilla app context creation code
- Configures Thymeleaf manually
- Updates tests
- Configures logging
- Removes unused configuration

Resolves #118
{minor}

Signed-off-by: Esta Nagy <[email protected]>
  • Loading branch information
nagyesta authored Jul 29, 2022
1 parent 3a3b848 commit 060d928
Show file tree
Hide file tree
Showing 29 changed files with 434 additions and 370 deletions.
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ configure(subprojects.findAll({
"com.github.nagyesta.abortmission.testkit.vanilla.ParachuteDropTestAssets",
"com.github.nagyesta.abortmission.testkit.NoOpMatcher",
"com.github.nagyesta.abortmission.booster.junit4.support.LaunchAbortTestWatcher.1",
"com.github.nagyesta.abortmission.reporting.AbortMissionFlightEvaluationReportApp"
"com.github.nagyesta.abortmission.reporting.AbortMissionFlightEvaluationReportApp",
"org.springframework.boot.loader.JarLauncher"
]
}
}
Expand Down
15 changes: 7 additions & 8 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
[versions]
spring = "5.3.21"
springBoot = "2.7.1"
thymeleaf = "3.0.15.RELEASE"
thymeleafExtrasTime = "3.0.4.RELEASE"
logback = "1.2.11"
jsonSchemaValidator = "1.0.71"
gson = "2.9.0"
Expand All @@ -9,6 +11,7 @@ h2 = "2.1.214"
jdbi3 = "3.30.0"

lombok = "1.18.24"
findbugs = "3.0.2"

junit4 = "4.13.2"
jupiter = "5.8.2"
Expand All @@ -18,7 +21,6 @@ cucumber = "7.4.1"
testNg = "7.6.1"

lombokPlugin = "6.5.0.3"
springBootPlugin = "2.7.2"
minifyPlugin = "1.3.1"
gitVersionerPlugin = "1.6.7"
indexScanPlugin = "2.3.0"
Expand All @@ -30,15 +32,14 @@ jacoco = "0.8.2"
[libraries]
spring-core = { module = "org.springframework:spring-core", version.ref = "spring" }
spring-context = { module = "org.springframework:spring-context", version.ref = "spring" }
spring-web = { module = "org.springframework:spring-web", version.ref = "spring" }
spring-test = { module = "org.springframework:spring-test", version.ref = "spring" }

spring-boot-starter = { module = "org.springframework.boot:spring-boot-starter", version.ref = "springBoot" }
spring-boot-starter-json = { module = "org.springframework.boot:spring-boot-starter-json", version.ref = "springBoot" }
spring-boot-starter-thymeleaf = { module = "org.springframework.boot:spring-boot-starter-thymeleaf", version.ref = "springBoot" }
spring-boot-configuration-processor = { module = "org.springframework.boot:spring-boot-configuration-processor", version.ref = "springBoot" }
spring-boot-starter-test = { module = "org.springframework.boot:spring-boot-starter-test", version.ref = "springBoot" }

thymeleaf = { module = "org.thymeleaf:thymeleaf", version.ref = "thymeleaf" }
thymeleaf-extras-java8time = { module = "org.thymeleaf.extras:thymeleaf-extras-java8time", version.ref = "thymeleafExtrasTime" }

logback-classic = { module = "ch.qos.logback:logback-classic", version.ref = "logback" }
logback-core = { module = "ch.qos.logback:logback-core", version.ref = "logback" }

Expand All @@ -51,6 +52,7 @@ h2 = { module = "com.h2database:h2", version.ref = "h2" }
jdbi3-sqlobject = { module = "org.jdbi:jdbi3-sqlobject", version.ref = "jdbi3" }

lombok = { module = "org.projectlombok:lombok", version.ref = "lombok" }
findbugs-jsr305 = { module = "com.google.code.findbugs:jsr305", version.ref = "findbugs" }

junit = { module = "junit:junit", version.ref = "junit4" }

Expand All @@ -69,13 +71,10 @@ cucumber-junit = { module = "io.cucumber:cucumber-junit", version.ref = "cucumbe
cucumber-spring = { module = "io.cucumber:cucumber-spring", version.ref = "cucumber" }

[bundles]
spring-boot-report = ["spring-boot-starter", "spring-boot-starter-json", "spring-boot-starter-thymeleaf"]
spring-web = ["spring-core", "spring-context", "spring-web"]
spring-test = ["spring-core", "spring-context", "spring-test"]
logback = ["logback-classic", "logback-core"]

[plugins]
spring-boot = { id = "org.springframework.boot", version.ref = "springBootPlugin" }
lombok = { id = "io.freefair.lombok", version.ref = "lombokPlugin" }
minify = { id = "org.gradlewebtools.minify", version.ref = "minifyPlugin" }
versioner = { id = "io.toolebox.git-versioner", version.ref = "gitVersionerPlugin" }
Expand Down
180 changes: 0 additions & 180 deletions gradle/verification-metadata.xml

Large diffs are not rendered by default.

23 changes: 12 additions & 11 deletions mission-report/flight-evaluation-report/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
plugins {
alias(libs.plugins.spring.boot)
id 'java'
//noinspection SpellCheckingInspection
alias(libs.plugins.lombok)
Expand All @@ -14,17 +13,14 @@ project.ext {
}

dependencies {
implementation libs.bundles.spring.boot.report
implementation libs.json.schema.validator
implementation libs.thymeleaf
implementation libs.thymeleaf.extras.java8time
implementation libs.bundles.logback
implementation libs.findbugs.jsr305
annotationProcessor libs.lombok
annotationProcessor libs.spring.boot.configuration.processor
testImplementation libs.spring.boot.starter.test
testImplementation libs.jupiter.core
constraints {
implementation libs.bundles.spring.web
testImplementation libs.bundles.spring.test
}
testImplementation libs.mockito.core
}

minification {
Expand Down Expand Up @@ -119,11 +115,17 @@ task processTemplates {
}

jar {
enabled = false
manifest {
attributes "Main-Class": "com.github.nagyesta.abortmission.reporting.AbortMissionFlightEvaluationReportApp"
}
duplicatesStrategy = DuplicatesStrategy.INCLUDE
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
}

processResources.finalizedBy processTemplates
bootJarMainClassName.dependsOn processTemplates
jar.dependsOn processTemplates
checkstyleMain.dependsOn processTemplates
compileTestJava.dependsOn processTemplates
javadoc.dependsOn processTemplates
Expand All @@ -136,7 +138,6 @@ publishing {
publications {
mavenJava(MavenPublication) {
from components.java
artifact bootJar
artifactId = "abort.${project.name}"
pom {
name = "${project.artifactDisplayName}"
Expand Down
1 change: 1 addition & 0 deletions mission-report/flight-evaluation-report/lombok.config
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# This file is generated by the 'io.freefair.lombok' Gradle plugin
config.stopBubbling = true
lombok.addLombokGeneratedAnnotation = true
lombok.nonnull.exceptiontype=IllegalArgumentException
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.github.nagyesta.abortmission.reporting;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.nagyesta.abortmission.reporting.config.ConversionProperties;
import com.github.nagyesta.abortmission.reporting.controller.ConversionController;
import com.github.nagyesta.abortmission.reporting.html.converter.ClassJsonToHtmlConverter;
import com.github.nagyesta.abortmission.reporting.html.converter.LaunchJsonToHtmlConverter;
import com.github.nagyesta.abortmission.reporting.html.converter.StageLaunchStatsJsonToHtmlConverter;
import com.github.nagyesta.abortmission.reporting.html.converter.StatsJsonToHtmlConverter;
import org.thymeleaf.TemplateEngine;

public class AbortMissionAppContext {
private final ConversionController controller;

public AbortMissionAppContext(final ConversionProperties properties) {
final ObjectMapper objectMapper = new ObjectMapper();
final StatsJsonToHtmlConverter statsConverter = new StatsJsonToHtmlConverter();
final StageLaunchStatsJsonToHtmlConverter stageConverter = new StageLaunchStatsJsonToHtmlConverter(statsConverter);
final ClassJsonToHtmlConverter classConverter = new ClassJsonToHtmlConverter(statsConverter, stageConverter);
final LaunchJsonToHtmlConverter launchConverter = new LaunchJsonToHtmlConverter(statsConverter, classConverter);
final TemplateEngine templateEngine = new TemplateEngine();
controller = new ConversionController(properties, objectMapper, launchConverter, templateEngine);
}

/**
* Returns the controller.
*
* @return controller
*/
public ConversionController controller() {
return controller;
}

/**
* Exits with an error code (1).
*/
public void exitWithError() {
System.exit(1);
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,33 @@
package com.github.nagyesta.abortmission.reporting;

import com.github.nagyesta.abortmission.reporting.controller.ConversionController;
import com.github.nagyesta.abortmission.reporting.config.ConversionProperties;
import com.github.nagyesta.abortmission.reporting.exception.RenderException;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import lombok.extern.slf4j.Slf4j;

import java.util.Arrays;
import java.util.List;

@SpringBootApplication
@SuppressWarnings("checkstyle:HideUtilityClassConstructor")
public class AbortMissionFlightEvaluationReportApp {
@Slf4j
public final class AbortMissionFlightEvaluationReportApp {

public static void main(final String[] args) throws RenderException {
SpringApplication.run(AbortMissionFlightEvaluationReportApp.class, args)
.getBean(ConversionController.class).convert();
final AbortMissionFlightEvaluationReportApp app = new AbortMissionFlightEvaluationReportApp();
app.execute(app.bootstrap(Arrays.asList(args)));
}

AbortMissionAppContext bootstrap(final List<String> args) {
final ConversionProperties properties = new PropertiesParser(args).parseArguments();
return new AbortMissionAppContext(properties);
}

void execute(final AbortMissionAppContext context) {
try {
context.controller().convert();
} catch (final RenderException ex) {
log.error(ex.getMessage(), ex);
context.exitWithError();
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.github.nagyesta.abortmission.reporting;

import com.github.nagyesta.abortmission.reporting.config.ConversionProperties;

import java.io.File;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.regex.Pattern;

public final class PropertiesParser {

private static final String INPUT = "--report.input";
private static final String OUTPUT = "--report.output";
private static final String RELAXED = "--report.relaxed";
private static final String FAIL_ON_ERROR = "--report.failOnError";
private static final String EQUALS = "=";
private static final String EMPTY = "";

private final List<String> args;

public PropertiesParser(final List<String> args) {
this.args = List.copyOf(args);
}

public ConversionProperties parseArguments() {
final ConversionProperties.ConversionPropertiesBuilder builder = ConversionProperties.builder();
parse(INPUT, File::new, builder::input);
parse(OUTPUT, File::new, builder::output);
parse(RELAXED, Boolean::valueOf, builder::relaxed);
parse(FAIL_ON_ERROR, Boolean::valueOf, builder::failOnError);
return builder.build();
}

private <T> void parse(final String parameter, final Function<String, T> mapper, final Consumer<T> consumer) {
args.stream().filter(s -> s.startsWith(parameter)).findFirst()
.map(s -> s.replaceFirst(Pattern.quote(parameter + EQUALS), EMPTY))
.map(mapper).ifPresent(consumer);
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,61 @@
package com.github.nagyesta.abortmission.reporting.config;

import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import javax.annotation.Nonnull;
import java.io.File;

@Data
@NoArgsConstructor
@Component
@ConfigurationProperties(prefix = "report", ignoreInvalidFields = false, ignoreUnknownFields = false)
public class ConversionProperties {
@NonNull
public final class ConversionProperties {
private File input;
@NonNull
private File output;
private boolean relaxed = false;
private boolean failOnError = false;
private boolean relaxed;
private boolean failOnError;

private ConversionProperties(@NonNull final File input, @NonNull final File output, final boolean relaxed, final boolean failOnError) {
this.input = input;
this.output = output;
this.relaxed = relaxed;
this.failOnError = failOnError;
}

public static ConversionPropertiesBuilder builder() {
return new ConversionPropertiesBuilder();
}

@SuppressWarnings("checkstyle:HiddenField")
public static final class ConversionPropertiesBuilder {
private File input;
private File output;
private boolean relaxed = false;
private boolean failOnError = false;

ConversionPropertiesBuilder() {
}

public ConversionPropertiesBuilder input(@Nonnull final File input) {
this.input = input;
return this;
}

public ConversionPropertiesBuilder output(@Nonnull final File output) {
this.output = output;
return this;
}

public ConversionPropertiesBuilder relaxed(final boolean relaxed) {
this.relaxed = relaxed;
return this;
}

public ConversionPropertiesBuilder failOnError(final boolean failOnError) {
this.failOnError = failOnError;
return this;
}

public ConversionProperties build() {
return new ConversionProperties(input, output, relaxed, failOnError);
}
}
}
Loading

0 comments on commit 060d928

Please sign in to comment.