diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md new file mode 100644 index 0000000..51766f7 --- /dev/null +++ b/DEVELOPMENT.md @@ -0,0 +1,80 @@ +# Developing + +## Setting up a development environment + +### Setup a GitHub account accessible via SSH + +GitHub is used for project Source Code Management (SCM) using the SSH protocol for authentication. + +1. Create [a GitHub account](https://github.com/join) if you do not already have one. +1. Setup +[GitHub access via SSH](https://help.github.com/articles/connecting-to-github-with-ssh/) + +### Install tools + +You must install these tools: + +1. [`git`](https://help.github.com/articles/set-up-git/): For source control + +1. [`java`](https://www.oracle.com/java/technologies/downloads/): The language this SDK is built in. Java 9 is a minimum requirement to build the project. + +1. [`docker`](https://www.docker.com/): Required If Super-Linter needs to run locally + + + +### Setup a fork + +The sdk-java project requires that you develop (commit) code changes to branches that belong to a fork of the `cdevents/sdk-java` repository in your GitHub account before submitting them as Pull Requests (PRs) to the actual project repository. + +1. [Create a fork](https://help.github.com/articles/fork-a-repo/) of the `cdevents/sdk-java` repository in your GitHub account. + +1. Create a clone of your fork on your local machine: + + ```shell + git clone git@github.com:${YOUR_GITHUB_USERNAME}/sdk-java.git + ``` + +1. Configure `git` remote repositories + + Adding `cdevents/sdk-java` as the `upstream` and your fork as the `origin` remote repositories to your `.git/config` sets you up nicely for regularly [syncing your fork](https://help.github.com/articles/syncing-a-fork/) and submitting pull requests. + + 1. Change into the project directory + + ```shell + cd sdk-java + ``` + + 1. Configure sdk-java as the `upstream` repository + + ```shell + git remote add upstream git@github.com:cdevents/sdk-java.git + + # Optional: Prevent accidental pushing of commits by changing the upstream URL to `no_push` + git remote set-url --push upstream no_push + ``` + + 1. Configure your fork as the `origin` repository + + ```shell + git remote add origin git@github.com:${YOUR_GITHUB_USERNAME}/sdk-java.git + ``` + +## Developing, building and testing + + +To [Run Super-Linter locally](https://github.com/github/super-linter/blob/main/docs/run-linter-locally.md): + +```shell +$ docker run -e RUN_LOCAL=true -e USE_FIND_ALGORITHM=true -v /path/to/local/codebase:/tmp/lint github/super-linter:v4 +``` + +To run unit tests: +```shell +$ ./mvnw test +``` + +To run all targets, before creating a commit: + +```shell +./mvnw verify +``` diff --git a/README.md b/README.md index 1b4842d..e9c3442 100644 --- a/README.md +++ b/README.md @@ -1 +1,60 @@ -# sdk-java \ No newline at end of file +# CDEvents Java SDK + +Java SDK to produce [CDEvents](https://cdevents.dev). + +The SDK can be used to create CDEvents and render as CloudEvents to send them to a specific CloudEvents broker + +## Add dependency module + +```xml + + dev.cdevents + cdevents-sdk-java + ${cdevents.version} + +``` + +## Create your first CDEvent + +Below is the example of creating a new [PipelineRun-finished](https://cdevents.dev/docs/core/#pipelinerun-finished) event, + +```java +public class CDEventsExample { + + public static void main(String args[]){ + /*when creating new object of any CDEvent type, the event will be initialized with + context.id, context.type, context.version, context.timestamp + and subject.type */ + PipelineRunFinishedCDEvent pipelineRunFinishedCDEvent = new PipelineRunFinishedCDEvent(); + + /* set the required context fields to the pipelineRunFinishedCDEvent */ + pipelineRunFinishedCDEvent.setSource(URI.create("http://dev.cdevents")); + + /* set the required subject fields to the pipelineRunFinishedCDEvent */ + pipelineRunFinishedCDEvent.setSubjectId("/dev/pipeline/run/1"); + pipelineRunFinishedCDEvent.setSubjectSource(URI.create("http://dev.pipeline.run/source")); + pipelineRunFinishedCDEvent.setSubjectUrl(URI.create("http://dev.pipeline.run/url")); + pipelineRunFinishedCDEvent.setSubjectOutcome(CDEventConstants.Outcome.SUCCESS); + pipelineRunFinishedCDEvent.setSubjectPipelineName("testPipeline"); + pipelineRunFinishedCDEvent.setSubjectErrors("pipelineErrors"); + + /* Create a CloudEvent from a pipelineRunFinishedCDEvent */ + CloudEvent ceEvent = CDEvents.cdEventAsCloudEvent(pipelineRunFinishedCDEvent); + + /* This CDEvent can be sent as CloudEvent using HTTP Protocol Binding, + Refer : https://cloudevents.github.io/sdk-java/http-basic.html + */ + + } +} +``` +Now the CDEvent can be sent as CloudEvent using [Generic HTTP Protocol Binding](https://cloudevents.github.io/sdk-java/http-basic.html) + +## Contributing + +If you would like to contribute, see our [development](DEVELOPMENT.md) guide. + +## References + +- [CDEvents](https://cdevents.dev) +- [CDFoundation SIG Events Vocabulary Draft](https://github.com/cdfoundation/sig-events/tree/main/vocabulary-draft) diff --git a/pom.xml b/pom.xml index 267f4e6..4dd92ba 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - dev.cdevents.sdk-java + dev.cdevents cdevents-sdk-java v0.1.0-draft6