Closed aalmiray closed 7 months ago
Here's an stacktrace that occurs when an event is created with the following code:
PipelinerunStartedCDEvent cdEvent = new PipelinerunStartedCDEvent();
cdEvent.setSource(URI.create(source));
cdEvent.setSubjectId(subjectId);
cdEvent.setSubjectSource(subjectSource);
cdEvent.setSubjectUrl(subjectUrl);
cdEvent.setSubjectPipelineName(subjectPipelineName);
sendEvent(context, CDEvents.cdEventAsCloudEvent(cdEvent));
dev.cdevents.exception.CDEventsException: Exception while reading Event JsonSchema file
at dev.cdevents.events.PipelinerunStartedCDEvent.eventSchema(PipelinerunStartedCDEvent.java:106)
at dev.cdevents.CDEvents.getJsonSchemaValidationMessages(CDEvents.java:136)
at dev.cdevents.CDEvents.validateCDEvent(CDEvents.java:82)
at dev.cdevents.CDEvents.cdEventAsCloudEvent(CDEvents.java:55)
at org.jreleaser.extensions.cdevents.CDEventsWorkflowListener.onSessionStart(CDEventsWorkflowListener.java:181)
at org.jreleaser.model.internal.JReleaserContext.fireSessionStartEvent(JReleaserContext.java:1051)
at org.jreleaser.workflow.WorkflowImpl.doExecute(WorkflowImpl.java:104)
at org.jreleaser.workflow.WorkflowImpl.execute(WorkflowImpl.java:54)
at org.jreleaser.cli.Assemble.doExecute(Assemble.java:99)
at org.jreleaser.cli.AbstractModelCommand.execute(AbstractModelCommand.java:89)
at org.jreleaser.cli.AbstractCommand.call(AbstractCommand.java:52)
at org.jreleaser.cli.AbstractModelCommand.call(AbstractModelCommand.java:53)
at org.jreleaser.cli.AbstractCommand.call(AbstractCommand.java:37)
at picocli.CommandLine.executeUserObject(CommandLine.java:2041)
at picocli.CommandLine.access$1500(CommandLine.java:148)
at picocli.CommandLine$RunLast.executeUserObjectOfLastSubcommandWithSameParent(CommandLine.java:2461)
at picocli.CommandLine$RunLast.handle(CommandLine.java:2453)
at picocli.CommandLine$RunLast.handle(CommandLine.java:2415)
at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:2273)
at picocli.CommandLine$RunLast.execute(CommandLine.java:2417)
at picocli.CommandLine.execute(CommandLine.java:2170)
at org.jreleaser.cli.Main.execute(Main.java:98)
at org.jreleaser.cli.Main.run(Main.java:81)
at org.jreleaser.cli.Main.main(Main.java:70)
Caused by: java.nio.file.NoSuchFileException: ../spec/schemas/pipelinerunstarted.json
at java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:92)
at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:106)
at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111)
at java.base/sun.nio.fs.UnixFileSystemProvider.newByteChannel(UnixFileSystemProvider.java:261)
at java.base/java.nio.file.Files.newByteChannel(Files.java:379)
at java.base/java.nio.file.Files.newByteChannel(Files.java:431)
at java.base/java.nio.file.Files.readAllBytes(Files.java:3268)
at java.base/java.nio.file.Files.readString(Files.java:3346)
at java.base/java.nio.file.Files.readString(Files.java:3305)
at dev.cdevents.events.PipelinerunStartedCDEvent.eventSchema(PipelinerunStartedCDEvent.java:104)
... 23 more
🎉 This issue has been resolved in v0.3.1
(Release Notes)
The current code foe each event loads its schema in this way
https://github.com/cdevents/sdk-java/blob/3055c23edd1e056a3b7fd9c682e24b80d1f4e862/sdk/src/main/java/dev/cdevents/events/PipelinerunStartedCDEvent.java#L102-L108
Which means it expects to find the schema as a file in the filesystem. This code fails when the
cdevents-java-sdk
is consumed as a dependency by other projects, as the schema files are no longer found in the filesystem but rather as embedded resources within thecdevents-java-sdk
JAR.This code must be updated to find the schema as a classpath resource first, falling back to filesystem if not found.