Skip to content

Commit

Permalink
Fix #71 Load JSON schemas from classpath
Browse files Browse the repository at this point in the history
Closes #71

Signed-off-by: Andres Almiray <[email protected]>
  • Loading branch information
aalmiray committed Feb 13, 2024
1 parent dd13d25 commit 39cf879
Show file tree
Hide file tree
Showing 43 changed files with 103 additions and 361 deletions.
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

0 comments on commit 39cf879

Please sign in to comment.