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

Fix #71 Load JSON schemas from classpath #76

Merged
merged 1 commit into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions generator/src/main/resources/template/event-template.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,12 @@ package dev.cdevents.events;


import dev.cdevents.constants.CDEventConstants;
import dev.cdevents.exception.CDEventsException;
import dev.cdevents.models.CDEvent;
import dev.cdevents.models.{{subject}}.{{predicate}}.*;

import java.net.URI;
import java.util.Date;
import java.util.UUID;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;


public class {{capitalizedSubject}}{{capitalizedPredicate}}CDEvent extends {{capitalizedSubject}}{{predicate}} implements CDEvent {
Expand Down Expand Up @@ -103,11 +99,7 @@ public class {{capitalizedSubject}}{{capitalizedPredicate}}CDEvent extends {{cap

@Override
public String eventSchema() {
try {
return Files.readString(Paths.get(CDEventConstants.SCHEMA_FOLDER + "/{{schemaFileName}}"));
} catch (IOException e) {
throw new CDEventsException("Exception while reading Event JsonSchema file ", e);
}
return dev.cdevents.spec.schemas.SchemaLoader.loadSchema("{{schemaFileName}}");
}


Expand Down
2 changes: 1 addition & 1 deletion sdk/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/schemas/spec/schemas</outputDirectory>
<outputDirectory>${project.build.directory}/schemas/dev/cdevents/spec/schemas</outputDirectory>
<resources>
<resource>
<directory>../spec/schemas</directory>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,12 @@


import dev.cdevents.constants.CDEventConstants;
import dev.cdevents.exception.CDEventsException;
import dev.cdevents.models.CDEvent;
import dev.cdevents.models.artifact.packaged.*;

import java.net.URI;
import java.util.Date;
import java.util.UUID;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;


public class ArtifactPackagedCDEvent extends Artifactpackaged implements CDEvent {
Expand Down Expand Up @@ -101,11 +97,7 @@ public String schemaURL() {

@Override
public String eventSchema() {
try {
return Files.readString(Paths.get(CDEventConstants.SCHEMA_FOLDER + "/artifactpackaged.json"));
} catch (IOException e) {
throw new CDEventsException("Exception while reading Event JsonSchema file ", e);
}
return dev.cdevents.spec.schemas.SchemaLoader.loadSchema("artifactpackaged.json");
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,12 @@


import dev.cdevents.constants.CDEventConstants;
import dev.cdevents.exception.CDEventsException;
import dev.cdevents.models.CDEvent;
import dev.cdevents.models.artifact.published.*;

import java.net.URI;
import java.util.Date;
import java.util.UUID;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;


public class ArtifactPublishedCDEvent extends Artifactpublished implements CDEvent {
Expand Down Expand Up @@ -100,11 +96,7 @@ public String schemaURL() {

@Override
public String eventSchema() {
try {
return Files.readString(Paths.get(CDEventConstants.SCHEMA_FOLDER + "/artifactpublished.json"));
} catch (IOException e) {
throw new CDEventsException("Exception while reading Event JsonSchema file ", e);
}
return dev.cdevents.spec.schemas.SchemaLoader.loadSchema("artifactpublished.json");
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,12 @@


import dev.cdevents.constants.CDEventConstants;
import dev.cdevents.exception.CDEventsException;
import dev.cdevents.models.CDEvent;
import dev.cdevents.models.artifact.signed.*;

import java.net.URI;
import java.util.Date;
import java.util.UUID;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;


public class ArtifactSignedCDEvent extends Artifactsigned implements CDEvent {
Expand Down Expand Up @@ -100,11 +96,7 @@ public String schemaURL() {

@Override
public String eventSchema() {
try {
return Files.readString(Paths.get(CDEventConstants.SCHEMA_FOLDER + "/artifactsigned.json"));
} catch (IOException e) {
throw new CDEventsException("Exception while reading Event JsonSchema file ", e);
}
return dev.cdevents.spec.schemas.SchemaLoader.loadSchema("artifactsigned.json");
}


Expand Down
10 changes: 1 addition & 9 deletions sdk/src/main/java/dev/cdevents/events/BranchCreatedCDEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,12 @@


import dev.cdevents.constants.CDEventConstants;
import dev.cdevents.exception.CDEventsException;
import dev.cdevents.models.CDEvent;
import dev.cdevents.models.branch.created.*;

import java.net.URI;
import java.util.Date;
import java.util.UUID;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;


public class BranchCreatedCDEvent extends Branchcreated implements CDEvent {
Expand Down Expand Up @@ -101,11 +97,7 @@ public String schemaURL() {

@Override
public String eventSchema() {
try {
return Files.readString(Paths.get(CDEventConstants.SCHEMA_FOLDER + "/branchcreated.json"));
} catch (IOException e) {
throw new CDEventsException("Exception while reading Event JsonSchema file ", e);
}
return dev.cdevents.spec.schemas.SchemaLoader.loadSchema("branchcreated.json");
}


Expand Down
10 changes: 1 addition & 9 deletions sdk/src/main/java/dev/cdevents/events/BranchDeletedCDEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,12 @@


import dev.cdevents.constants.CDEventConstants;
import dev.cdevents.exception.CDEventsException;
import dev.cdevents.models.CDEvent;
import dev.cdevents.models.branch.deleted.*;

import java.net.URI;
import java.util.Date;
import java.util.UUID;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;


public class BranchDeletedCDEvent extends Branchdeleted implements CDEvent {
Expand Down Expand Up @@ -101,11 +97,7 @@ public String schemaURL() {

@Override
public String eventSchema() {
try {
return Files.readString(Paths.get(CDEventConstants.SCHEMA_FOLDER + "/branchdeleted.json"));
} catch (IOException e) {
throw new CDEventsException("Exception while reading Event JsonSchema file ", e);
}
return dev.cdevents.spec.schemas.SchemaLoader.loadSchema("branchdeleted.json");
}


Expand Down
10 changes: 1 addition & 9 deletions sdk/src/main/java/dev/cdevents/events/BuildFinishedCDEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,12 @@


import dev.cdevents.constants.CDEventConstants;
import dev.cdevents.exception.CDEventsException;
import dev.cdevents.models.CDEvent;
import dev.cdevents.models.build.finished.*;

import java.net.URI;
import java.util.Date;
import java.util.UUID;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;


public class BuildFinishedCDEvent extends Buildfinished implements CDEvent {
Expand Down Expand Up @@ -100,11 +96,7 @@ public String schemaURL() {

@Override
public String eventSchema() {
try {
return Files.readString(Paths.get(CDEventConstants.SCHEMA_FOLDER + "/buildfinished.json"));
} catch (IOException e) {
throw new CDEventsException("Exception while reading Event JsonSchema file ", e);
}
return dev.cdevents.spec.schemas.SchemaLoader.loadSchema("buildfinished.json");
}


Expand Down
10 changes: 1 addition & 9 deletions sdk/src/main/java/dev/cdevents/events/BuildQueuedCDEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,12 @@


import dev.cdevents.constants.CDEventConstants;
import dev.cdevents.exception.CDEventsException;
import dev.cdevents.models.CDEvent;
import dev.cdevents.models.build.queued.*;

import java.net.URI;
import java.util.Date;
import java.util.UUID;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;


public class BuildQueuedCDEvent extends Buildqueued implements CDEvent {
Expand Down Expand Up @@ -100,11 +96,7 @@ public String schemaURL() {

@Override
public String eventSchema() {
try {
return Files.readString(Paths.get(CDEventConstants.SCHEMA_FOLDER + "/buildqueued.json"));
} catch (IOException e) {
throw new CDEventsException("Exception while reading Event JsonSchema file ", e);
}
return dev.cdevents.spec.schemas.SchemaLoader.loadSchema("buildqueued.json");
}


Expand Down
10 changes: 1 addition & 9 deletions sdk/src/main/java/dev/cdevents/events/BuildStartedCDEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,12 @@


import dev.cdevents.constants.CDEventConstants;
import dev.cdevents.exception.CDEventsException;
import dev.cdevents.models.CDEvent;
import dev.cdevents.models.build.started.*;

import java.net.URI;
import java.util.Date;
import java.util.UUID;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;


public class BuildStartedCDEvent extends Buildstarted implements CDEvent {
Expand Down Expand Up @@ -100,11 +96,7 @@ public String schemaURL() {

@Override
public String eventSchema() {
try {
return Files.readString(Paths.get(CDEventConstants.SCHEMA_FOLDER + "/buildstarted.json"));
} catch (IOException e) {
throw new CDEventsException("Exception while reading Event JsonSchema file ", e);
}
return dev.cdevents.spec.schemas.SchemaLoader.loadSchema("buildstarted.json");
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,12 @@


import dev.cdevents.constants.CDEventConstants;
import dev.cdevents.exception.CDEventsException;
import dev.cdevents.models.CDEvent;
import dev.cdevents.models.change.abandoned.*;

import java.net.URI;
import java.util.Date;
import java.util.UUID;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;


public class ChangeAbandonedCDEvent extends Changeabandoned implements CDEvent {
Expand Down Expand Up @@ -101,11 +97,7 @@ public String schemaURL() {

@Override
public String eventSchema() {
try {
return Files.readString(Paths.get(CDEventConstants.SCHEMA_FOLDER + "/changeabandoned.json"));
} catch (IOException e) {
throw new CDEventsException("Exception while reading Event JsonSchema file ", e);
}
return dev.cdevents.spec.schemas.SchemaLoader.loadSchema("changeabandoned.json");
}


Expand Down
10 changes: 1 addition & 9 deletions sdk/src/main/java/dev/cdevents/events/ChangeCreatedCDEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,12 @@


import dev.cdevents.constants.CDEventConstants;
import dev.cdevents.exception.CDEventsException;
import dev.cdevents.models.CDEvent;
import dev.cdevents.models.change.created.*;

import java.net.URI;
import java.util.Date;
import java.util.UUID;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;


public class ChangeCreatedCDEvent extends Changecreated implements CDEvent {
Expand Down Expand Up @@ -101,11 +97,7 @@ public String schemaURL() {

@Override
public String eventSchema() {
try {
return Files.readString(Paths.get(CDEventConstants.SCHEMA_FOLDER + "/changecreated.json"));
} catch (IOException e) {
throw new CDEventsException("Exception while reading Event JsonSchema file ", e);
}
return dev.cdevents.spec.schemas.SchemaLoader.loadSchema("changecreated.json");
}


Expand Down
10 changes: 1 addition & 9 deletions sdk/src/main/java/dev/cdevents/events/ChangeMergedCDEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,12 @@


import dev.cdevents.constants.CDEventConstants;
import dev.cdevents.exception.CDEventsException;
import dev.cdevents.models.CDEvent;
import dev.cdevents.models.change.merged.*;

import java.net.URI;
import java.util.Date;
import java.util.UUID;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;


public class ChangeMergedCDEvent extends Changemerged implements CDEvent {
Expand Down Expand Up @@ -101,11 +97,7 @@ public String schemaURL() {

@Override
public String eventSchema() {
try {
return Files.readString(Paths.get(CDEventConstants.SCHEMA_FOLDER + "/changemerged.json"));
} catch (IOException e) {
throw new CDEventsException("Exception while reading Event JsonSchema file ", e);
}
return dev.cdevents.spec.schemas.SchemaLoader.loadSchema("changemerged.json");
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,12 @@


import dev.cdevents.constants.CDEventConstants;
import dev.cdevents.exception.CDEventsException;
import dev.cdevents.models.CDEvent;
import dev.cdevents.models.change.reviewed.*;

import java.net.URI;
import java.util.Date;
import java.util.UUID;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;


public class ChangeReviewedCDEvent extends Changereviewed implements CDEvent {
Expand Down Expand Up @@ -101,11 +97,7 @@ public String schemaURL() {

@Override
public String eventSchema() {
try {
return Files.readString(Paths.get(CDEventConstants.SCHEMA_FOLDER + "/changereviewed.json"));
} catch (IOException e) {
throw new CDEventsException("Exception while reading Event JsonSchema file ", e);
}
return dev.cdevents.spec.schemas.SchemaLoader.loadSchema("changereviewed.json");
}


Expand Down
Loading
Loading