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

Configuration for report file location #98

Conversation

nderwin
Copy link
Contributor

@nderwin nderwin commented Oct 6, 2024

  • added runtime configuration to enable / disable building the reports
  • added source (.jrxml) and destination (.jasper) paths for the reports
  • ignore another NetBeans specific file for git

Signed-off-by:Nathan Erwin [email protected]

@melloware
Copy link
Contributor

melloware commented Oct 6, 2024

in \runtime\src\main\resources\META-INF\quarkus-extension.yaml make sure to add the config line below now that we have configs.

config:
    - "quarkus.jasperreports."

Full example

name: JasperReports
description: JasperReports is an open source reporting library that can be embedded into any Java application.
artifact: ${project.groupId}:${project.artifactId}:${project.version}
metadata:
  short-name: "jasperreports"
  type: "test"
  keywords:
    - "reports"
    - "reporting"
    - "pdf"
    - "excel"
  categories:
    - "miscellaneous"
  config:
    - "quarkus.jasperreports."
  status: "preview"
  guide: "https://docs.quarkiverse.io/quarkus-jasperreports/dev/index.html"
  icon-url: "https://raw.githubusercontent.com/quarkiverse/quarkus-jasperreports/main/docs/modules/ROOT/assets/images/jasperreports.svg"

@nderwin
Copy link
Contributor Author

nderwin commented Oct 7, 2024

in \runtime\src\main\resources\META-INF\quarkus-extension.yaml make sure to add the config line below now that we have configs.

Done. Now, to figure out why it's not adding the config to the generated docs. The "Writing You Own Extension" guide makes it sound like you don't have to do anything but add the config class(es).

@nderwin nderwin force-pushed the feature/72-configuration-for-report-file-locations branch 3 times, most recently from 5a53bf0 to b81ac1f Compare October 7, 2024 03:07
@melloware
Copy link
Contributor

You should not have to do anything
run mvn clean install from the root directory?

@nderwin nderwin force-pushed the feature/72-configuration-for-report-file-locations branch from b81ac1f to 1857d89 Compare October 8, 2024 00:59
@nderwin
Copy link
Contributor Author

nderwin commented Oct 8, 2024

#99 (comment)

@gastaldi I do the same, use a Maven plugin, but the purpose of this is to roll that into the deployment, though I'm not sure I'm producing the correct build item as I'm not getting a .jasper file to show up in the target directory or the .jar file.

@gastaldi
Copy link
Member

gastaldi commented Oct 8, 2024

Perhaps we need a processor producing a CompiledReportBuildItem with the path to the compiled jasper? Just thinking out loud

@nderwin nderwin force-pushed the feature/72-configuration-for-report-file-locations branch 2 times, most recently from 1fd0fb6 to ce1e711 Compare October 8, 2024 21:27
@nderwin
Copy link
Contributor Author

nderwin commented Oct 8, 2024

@gastaldi Ok, I'm stuck. I tried writing the CompiledReportBuildItem, but then a build step has to consume it, and then do what with it? I just can't get it to output a .jasper file into the target directory someplace, or the .jar, and it's probably something really simple that I missed. Right now, I'm using a GeneratedClassBuildItem like what is being used for the native output.

@melloware
Copy link
Contributor

@nderwin i think I can help with this. I will look tomorrow.

@melloware
Copy link
Contributor

This is just pseudocode i didn't test it but to save to the output target directory the .jasper file.

@BuildStep
    void compileReports(ReportConfig config, List<ReportFileBuildItem> reportFiles,
            BuildProducer<GeneratedClassBuildItem> compiledReportProducer,
			OutputTargetBuildItem outputTarget) {

        Log.warnf("Found %s report(s) to compile? %s", reportFiles.size(), config.build().enable());
        if (config.build().enable()) {
            // TODO - only compile if the report file has changed
            for (ReportFileBuildItem item : reportFiles) {
                String outputFile = item.getFileName().replace("." + ReportFileBuildItem.EXT_REPORT,
                        "." + ReportFileBuildItem.EXT_COMPILED);
                String outputFilePath = outputTarget.getOutputDirectory().get(Path.of(config.build().destination().toString(), outputFile)).toString();
                Log.warnf("Compiling %s into %s", item.getFileName(), outputFilePath);

                try (InputStream inputStream = JRLoader.getLocationInputStream(item.getFileName())) {
                    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
                    JasperCompileManager.compileReportToStream(inputStream, outputStream);
					// might have to reset or reload the input stream if its a bytearrayStream you can call reset
					JasperDesign jasperDesign = JRXmlLoader.load(inputStream);
					JasperCompileManager.compileReportToFile(jasperDesign, outputFilePath);

                    Log.warnf("Compiled size is %s", outputStream.size());
                    compiledReportProducer
                            .produce(new GeneratedClassBuildItem(true,
                                    outputFilePath, // TODO: this is supposed to be the class name ??
                                    outputStream.toByteArray()));
                } catch (JRException ex) {
                } catch (IOException ex) {
                }
            }
        } else {
            Log.debug("Automatic report compilation disabled");
        }
    }

It uses the OutpputTargetBuildItem to get the target directory and then you have to write the Jasper compiled file to that directory.

@nderwin nderwin force-pushed the feature/72-configuration-for-report-file-locations branch 2 times, most recently from 7b1a84e to 170e0f9 Compare October 9, 2024 17:36
@nderwin
Copy link
Contributor Author

nderwin commented Oct 9, 2024

@melloware Yes, now I have generated .jasper files. Needs some more cleanup, but this should be ready late today, and then it can be iterated and improved upon.

@melloware
Copy link
Contributor

Awesome!

@nderwin nderwin force-pushed the feature/72-configuration-for-report-file-locations branch from 170e0f9 to eaaef9e Compare October 9, 2024 21:35
config.build().destination().get().toString());

if (!Files.exists(outputFilePath)) {
Files.createDirectories(outputFilePath);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to call outputFilePath.getParent() if I am not mistaken

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did try that at first, but it didn't work right. This one puts the output directory where I wanted it to be.

@nderwin nderwin force-pushed the feature/72-configuration-for-report-file-locations branch 2 times, most recently from 542d578 to 1d983cd Compare October 9, 2024 23:35
@nderwin nderwin force-pushed the feature/72-configuration-for-report-file-locations branch from 1d983cd to 153810f Compare October 9, 2024 23:59
@nderwin
Copy link
Contributor Author

nderwin commented Oct 10, 2024

@melloware This is so close... just barfing on the native tests if you could take a look?

@melloware
Copy link
Contributor

Have you merged all my latest changes from main?

@melloware
Copy link
Contributor

Oh I bet I know is it trying to compile on build? You can't compile in native mode so you have to add a LauncHMode check to your build step so it doesn't happen in Native mode.

@nderwin
Copy link
Contributor Author

nderwin commented Oct 10, 2024

Yup, has the latest; I'm not as familiar with native mode (haven't needed to use it), but I thought we'd be able to use the output of the compile step to feed into whatever native mode needs?

@melloware
Copy link
Contributor

I will take a closer look tomorrow.

// if (isRunningInContainer()) {
// result = (JasperReport) JRLoader.loadObject(JRLoader.getLocationInputStream(jasperFile + ".jasper"));
// } else {
result = compile(jasperFile);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the issue. You can't compile in Native mode that is why this check uses the .jasper file and not the compiled file. It checks if it's running on Native mode. You need to put this back.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

compile doesn't actually compile any more, it basically does what line 25 is doing - loading the previously compiled .jasper file.

@melloware
Copy link
Contributor

Found the issue. You need to put the code back the way I had it because it runs the integration tests against the native build and that absolutely cannot compile.

@gastaldi
Copy link
Member

I will take a closer look tomorrow.

Wow, your days are really short :)

@melloware
Copy link
Contributor

I am seeing errors in the log saying "src/main/resources" is invalid. Like it's not actually compiling them?

* added runtime configuration to enable / disable building the reports
* added source (.jrxml) and destination (.jasper) paths for the reports
* ignore another NetBeans specific file for git
* reworked the file watching to only watch the report files in dev mode, but we need to collect the report files always so they can be compiled
* compile the found source files

Signed-off-by:Nathan Erwin <[email protected]>
@nderwin nderwin force-pushed the feature/72-configuration-for-report-file-locations branch from 153810f to 40879ad Compare October 10, 2024 13:13
@melloware
Copy link
Contributor

@nderwin i am going to merge this and work on a fix. Its easier for me to figure it out working locally.

@melloware melloware marked this pull request as ready for review October 10, 2024 13:24
@melloware melloware requested a review from a team as a code owner October 10, 2024 13:24
@melloware melloware merged commit 8a10f7b into quarkiverse:main Oct 10, 2024
1 check failed
@nderwin
Copy link
Contributor Author

nderwin commented Oct 10, 2024

@melloware Ok, let me know if there's anything I can do to help.

@nderwin nderwin deleted the feature/72-configuration-for-report-file-locations branch October 10, 2024 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants