From 7f1ded6c0333307bfdaed04287a52ac1ef7b83a5 Mon Sep 17 00:00:00 2001 From: Jalander Ramagiri Date: Thu, 27 Apr 2023 16:44:50 +0100 Subject: [PATCH 1/5] Update readme with example to create PipelineRunFinished CDEvent --- README.md | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1b4842d..f87c953 100644 --- a/README.md +++ b/README.md @@ -1 +1,66 @@ -# 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 modules + +``` + + dev.cdevents.sdk-java + cdevents-sdk-java + ${cdevents.version} + + + + io.cloudevents + cloudevents-core + ${cloudevents.version} + +``` + +## Create your first CDEvent + +Below is the example of creating a new [PipelineRun-finished](https://cdevents.dev/docs/core/#pipelinerun-finished) event, + +``` +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) From ef4179e531e74a1c47efdc8f088f287a85d5dbb8 Mon Sep 17 00:00:00 2001 From: Jalander Ramagiri Date: Thu, 27 Apr 2023 19:10:16 +0100 Subject: [PATCH 2/5] adding DEVELOPMENT page --- DEVELOPMENT.md | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 4 +-- 2 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 DEVELOPMENT.md diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md new file mode 100644 index 0000000..dc6d009 --- /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. + +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 clean test +``` + +To run all targets, before creating a commit: + +```shell +./mvnw clean install +``` diff --git a/README.md b/README.md index f87c953..87f8148 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ The SDK can be used to create CDEvents and render as CloudEvents to send them to ## Add dependency modules -``` +```xml dev.cdevents.sdk-java cdevents-sdk-java @@ -24,7 +24,7 @@ The SDK can be used to create CDEvents and render as CloudEvents to send them to 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[]){ From 022c52440f7ea4fbc605770a11fd406f266e88d3 Mon Sep 17 00:00:00 2001 From: Jalander Ramagiri Date: Tue, 2 May 2023 09:50:25 +0100 Subject: [PATCH 3/5] updating with review comments --- DEVELOPMENT.md | 6 +++--- pom.xml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index dc6d009..51766f7 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -16,7 +16,7 @@ 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. +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 @@ -70,11 +70,11 @@ $ docker run -e RUN_LOCAL=true -e USE_FIND_ALGORITHM=true -v /path/to/local/code To run unit tests: ```shell -$ ./mvnw clean test +$ ./mvnw test ``` To run all targets, before creating a commit: ```shell -./mvnw clean install +./mvnw verify ``` 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 From 83c4051f39df115739fa0015ffc68290a56c1683 Mon Sep 17 00:00:00 2001 From: Jalander Ramagiri Date: Tue, 2 May 2023 10:20:04 +0100 Subject: [PATCH 4/5] updating groupId in the README --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 87f8148..b8b3004 100644 --- a/README.md +++ b/README.md @@ -8,9 +8,9 @@ The SDK can be used to create CDEvents and render as CloudEvents to send them to ```xml - dev.cdevents.sdk-java + dev.cdevents cdevents-sdk-java - ${cdevents.version} + ${cdevents.version} From e82a83560e9cdaba10e19cdcc9dd78ac8affcbe8 Mon Sep 17 00:00:00 2001 From: Jalander Ramagiri Date: Tue, 2 May 2023 19:27:45 +0100 Subject: [PATCH 5/5] removing transitive dependency from README --- README.md | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/README.md b/README.md index b8b3004..e9c3442 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ 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 modules +## Add dependency module ```xml @@ -12,12 +12,6 @@ The SDK can be used to create CDEvents and render as CloudEvents to send them to cdevents-sdk-java ${cdevents.version} - - - io.cloudevents - cloudevents-core - ${cloudevents.version} - ``` ## Create your first CDEvent