Skip to content

Commit

Permalink
Fix #115: Record build config and produce bean (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware authored Oct 13, 2024
1 parent fe6a575 commit e80617d
Show file tree
Hide file tree
Showing 8 changed files with 187 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,20 @@

import org.apache.commons.lang3.StringUtils;

import io.quarkiverse.jasperreports.Constants;
import io.quarkiverse.jasperreports.deployment.config.ReportConfig;
import io.quarkiverse.jasperreports.JasperReportsBeanProducer;
import io.quarkiverse.jasperreports.JasperReportsRecorder;
import io.quarkiverse.jasperreports.config.Constants;
import io.quarkiverse.jasperreports.config.ReportBuildTimeConfig;
import io.quarkiverse.jasperreports.deployment.item.CompiledReportFileBuildItem;
import io.quarkiverse.jasperreports.deployment.item.ReportFileBuildItem;
import io.quarkiverse.jasperreports.deployment.item.ReportRootBuildItem;
import io.quarkiverse.jasperreports.repository.ReadOnlyStreamingService;
import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
import io.quarkus.arc.deployment.BeanContainerBuildItem;
import io.quarkus.deployment.IsDevelopment;
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.annotations.ExecutionTime;
import io.quarkus.deployment.annotations.Record;
import io.quarkus.deployment.builditem.CombinedIndexBuildItem;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.builditem.GeneratedClassBuildItem;
Expand Down Expand Up @@ -397,7 +401,7 @@ void registerFonts(BuildProducer<NativeImageResourcePatternsBuildItem> nativeIma
* Otherwise, it returns the default source path defined in ReportConfig.
*/
@BuildStep
ReportRootBuildItem defaultReportRoot(ReportConfig config) {
ReportRootBuildItem defaultReportRoot(ReportBuildTimeConfig config) {
if (config.build().enable()) {
return new ReportRootBuildItem(config.build().source().toString());
}
Expand Down Expand Up @@ -495,7 +499,7 @@ void watchReportFiles(BuildProducer<HotDeploymentWatchedFileBuildItem> watchedPa
* @param outputTarget The OutputTargetBuildItem containing information about the build output directory.
*/
@BuildStep
void compileReports(ReportConfig config, List<ReportFileBuildItem> reportFiles,
void compileReports(ReportBuildTimeConfig config, List<ReportFileBuildItem> reportFiles,
BuildProducer<GeneratedClassBuildItem> compiledReportProducer,
BuildProducer<CompiledReportFileBuildItem> compiledReportFileProducer,
OutputTargetBuildItem outputTarget) {
Expand Down Expand Up @@ -548,9 +552,28 @@ void compileReports(ReportConfig config, List<ReportFileBuildItem> reportFiles,
}
}

/**
* Registers the JasperReportsBeanProducer as an unremovable bean.
*
* @return An AdditionalBeanBuildItem for the JasperReportsBeanProducer.
*/
@BuildStep
AdditionalBeanBuildItem registerBeanProducer() {
return AdditionalBeanBuildItem.unremovableOf(JasperReportsBeanProducer.class);
}

/**
* Initializes the JasperReports producer at runtime.
*
* @param recorder The JasperReportsRecorder to use for initialization.
* @param beanContainer The BeanContainerBuildItem containing the bean container.
* @param config The ReportBuildTimeConfig to use for initialization.
*/
@BuildStep
AdditionalBeanBuildItem additionalBeans() {
return AdditionalBeanBuildItem.unremovableOf(ReadOnlyStreamingService.class);
@Record(ExecutionTime.RUNTIME_INIT)
void initializeBeanProducer(JasperReportsRecorder recorder, BeanContainerBuildItem beanContainer,
ReportBuildTimeConfig config) {
recorder.initProducer(beanContainer.getValue(), config);
}

/**
Expand All @@ -569,4 +592,4 @@ static Path findProjectRoot(Path outputDirectory, Path startDirectory) {
return startDirectory;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package io.quarkiverse.jasperreports.deployment.item;

import static io.quarkiverse.jasperreports.Constants.EXT_COMPILED;
import static io.quarkiverse.jasperreports.Constants.EXT_DATA_ADAPTER;
import static io.quarkiverse.jasperreports.Constants.EXT_REPORT;
import static io.quarkiverse.jasperreports.Constants.EXT_STYLE;
import static io.quarkiverse.jasperreports.config.Constants.EXT_COMPILED;
import static io.quarkiverse.jasperreports.config.Constants.EXT_DATA_ADAPTER;
import static io.quarkiverse.jasperreports.config.Constants.EXT_REPORT;
import static io.quarkiverse.jasperreports.config.Constants.EXT_STYLE;

import java.nio.file.Path;
import java.util.List;
Expand Down Expand Up @@ -50,4 +50,4 @@ public String getType() {
};
}

}
}
16 changes: 8 additions & 8 deletions runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@
<groupId>org.jboss.logging</groupId>
<artifactId>commons-logging-jboss-logging</artifactId>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk18on</artifactId>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk18on</artifactId>
</dependency>

<!-- JasperReports -->
<dependency>
Expand Down Expand Up @@ -107,14 +115,6 @@
<artifactId>fop</artifactId>
<version>2.10</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk18on</artifactId>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk18on</artifactId>
</dependency>
<dependency>
<groupId>net.sf.saxon</groupId>
<artifactId>Saxon-HE</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package io.quarkiverse.jasperreports;

import java.nio.file.Path;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.context.Dependent;
import jakarta.enterprise.inject.Produces;

import io.quarkiverse.jasperreports.repository.ReadOnlyStreamingService;

/**
* A bean producer for JasperReports-related services.
* This class is responsible for initializing and producing the ReadOnlyStreamingService.
*/
@ApplicationScoped
public class JasperReportsBeanProducer {

private volatile Path destinationPath;

/**
* Initializes the bean producer with the destination path for JasperReports files.
*
* @param destinationPath The path where compiled JasperReports files are located.
*/
void initialize(Path destinationPath) {
this.destinationPath = destinationPath;
}

/**
* Produces a ReadOnlyStreamingService instance.
*
* @return A new ReadOnlyStreamingService initialized with the destination path.
*/
@Dependent
@Produces
public ReadOnlyStreamingService readOnlyStreamingService() {
return new ReadOnlyStreamingService(this.destinationPath);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package io.quarkiverse.jasperreports;

import io.quarkiverse.jasperreports.config.ReportBuildTimeConfig;
import io.quarkus.arc.runtime.BeanContainer;
import io.quarkus.runtime.annotations.Recorder;

/**
* Recorder for JasperReports initialization.
* This class is responsible for initializing the JasperReportsBeanProducer at runtime.
*/
@Recorder
public class JasperReportsRecorder {

/**
* Initializes the JasperReportsBeanProducer with the configured destination path.
*
* @param container The BeanContainer used to retrieve the JasperReportsBeanProducer instance.
* @param config The ReportBuildTimeConfig containing the build configuration.
*/
public void initProducer(BeanContainer container, ReportBuildTimeConfig config) {
JasperReportsBeanProducer producer = container.beanInstance(JasperReportsBeanProducer.class);
producer.initialize(config.build().destination());
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkiverse.jasperreports;
package io.quarkiverse.jasperreports.config;

public interface Constants {

Expand All @@ -14,4 +14,4 @@ public interface Constants {

static final String DEFAULT_DEST_PATH = "jasperreports";

}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkiverse.jasperreports.deployment.config;
package io.quarkiverse.jasperreports.config;

import java.nio.file.Path;

Expand All @@ -8,8 +8,8 @@
import io.smallrye.config.WithDefault;

@ConfigMapping(prefix = "quarkus.jasperreports")
@ConfigRoot(phase = ConfigPhase.BUILD_TIME)
public interface ReportConfig {
@ConfigRoot(phase = ConfigPhase.BUILD_AND_RUN_TIME_FIXED)
public interface ReportBuildTimeConfig {

String DEFAULT_SOURCE_PATH = "src/main/jasperreports";
String DEFAULT_DEST_PATH = "jasperreports";
Expand Down Expand Up @@ -40,4 +40,4 @@ interface BuildConfig {
Path destination();
}

}
}
Loading

0 comments on commit e80617d

Please sign in to comment.