Skip to content

Commit

Permalink
[ANCHOR-220] Refactor README (#1064)
Browse files Browse the repository at this point in the history
### Description
- Fix, clean up and improve the `How to Contribute` section 
- Add How to set up development environment
- Add Git guidelines
- Add repository directory structure
- Remove outdated contents
  • Loading branch information
lijamie98 authored Aug 25, 2023
1 parent eee0938 commit 67ceac1
Show file tree
Hide file tree
Showing 22 changed files with 368 additions and 928 deletions.
2 changes: 1 addition & 1 deletion README.md
35 changes: 0 additions & 35 deletions docs/00 - Stellar Anchor Platform.md

This file was deleted.

208 changes: 208 additions & 0 deletions docs/01 - Contributing/A - Development Environment.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
# How to set up the development environment

<!-- TOC -->

* [How to set up the development environment](#how-to-set-up-the-development-environment)
* [Install JDK 11](#install-jdk-11)
* [Checkout the Project](#checkout-the-project)
* [Set up `docker`](#set-up-docker)
* [Set up your hosts file](#set-up-your-hosts-file)
* [Build the Project with Gradle](#build-the-project-with-gradle)
* [Clean](#clean)
* [Build](#build)
* [Running Unit Tests](#running-unit-tests)
* [Set up the Git Hooks](#set-up-the-git-hooks)
* [Set up the Development Environment with IntelliJ IDEA](#set-up-the-development-environment-with-intellij-idea)
* [Configuring Gradle on IntelliJ IDEA](#configuring-gradle-on-intellij-idea)
* [Run Configurations](#run-configurations)
* [Example: Debug the Platform Server](#example-debug-the-platform-server)
* [Example: Debug the Junit or the End-to-End Tests](#example-debug-the-junit-or-the-end-to-end-tests)
* [Running the Tests From Gradle in IntelliJ](#running-the-tests-from-gradle-in-intellij)

<!-- TOC -->

## Install JDK 11

Before you start, please make sure you
have [JDK-11](https://www.oracle.com/java/technologies/javase-jdk11-downloads.html) installed on your machine.

To check if you have it installed, run:

```shell
java -version
```

## Checkout the Project

To check out the project, run:

```shell
git clone [email protected]:stellar/java-stellar-anchor-sdk.git
```

or

```shell
git clone https://github.com/stellar/java-stellar-anchor-sdk.git
```

## Set up `docker`

Please make sure you have `docker` installed on your machine. If you don't, please follow the instructions on
the [docker website](https://docs.docker.com/get-docker/).

Docker version 23.0.0 or higher is recommended. To check your docker version, run:

```shell
docker --version
```

You should see something like:

```shell
Docker version 23.0.5, build bc4487a
```

## Set up your hosts file

On macOS and Linux, you need to add the following entries to your `/etc/hosts` file. And on Windows, you need to add the
following entries to your `C:\Windows\System32\Drivers\etc\hosts` file.

These entries are needed to successfully run integration tests and end-2-end tests for the docker containers to
communicate with each other.

```shell
127.0.0.1 db
127.0.0.1 zookeeper
127.0.0.1 kafka
127.0.0.1 sep24-reference-ui
127.0.0.1 reference-server
127.0.0.1 wallet-server
127.0.0.1 platform
127.0.0.1 host.docker.internal
```

## Build the Project with Gradle

### Clean

`./gradlew clean`

### Build

Buile all projects: `./gradlew build`

Build a subproject: `./gradlew :[subproject]:build`

Build the Spring Boot application: `./gradlew bootJar`

### Running Unit Tests

Run all tests: `./gradlew test`

Run subproject tests: `./gradlew :[subproject]:test`

## Set up the Git Hooks

In order to have consistent code style, we use [Google Java Format](https://github.com/google/google-java-format) to
format the code, and [ktfmt](https://github.com/facebook/ktfmt) to format Kotlin code.
Before each commit, you should run the git hook to format the code. We have a script that will set up the git hooks for
you. To install it, run:

```shell
./gradlew updateGitHook
```

The gradle `updateGitHook` task will install the git hooks for you. You should see `spotlessCheck` and `spotlessApply`
being executed when you commit your code.

# Set up the Development Environment with IntelliJ IDEA

The project is mostly developed with IntelliJ, therefore we will only cover the project configuration for that IDE.

## Configuring Gradle on IntelliJ IDEA

1. Clone the repository:

```shell
git clone [email protected]:stellar/java-stellar-anchor-sdk.git
```
2. Install IntelliJ
3. Install and configure `google-java-format`
1. File -> Settings -> Plugins -> Marketplace -> Search for `google-java-format` -> Install
2. File -> Settings -> google-java-format -> Check `Enable google-java-format` and
choose `Default Google Java Style` -> Apply
4. Install and configure `ktfmt`
1. File -> Settings -> Plugins -> Marketplace -> Search for `ktfmt` -> Install
2. File -> Settings -> Editor -> ktfmt -> Check `Enable ktfmt` and choose `Google (internal)` -> Apply
5. Use IntelliJ to open as a Gradle project:
1. Launch IntelliJ
2. File -> Open, choose the folder `java-stellar-anchor-sdk` where you cloned the repository.
3. When asked, choose `Open as Project`.
4. IntelliJ will parse Gradle buildscript `build.gradle.kts` file and configure the project accordingly.
6. Configure Gradle to build & run using IntelliJ IDEA:
1. Go to `Preferences -> Build, Execution, Deployment -> Build Tools -> Gradle`.
2. Configure `Build and run using` to IntellliJ IDEA.
3. Configure `Run tests using` to IntellliJ IDEA.

![configure-intellij-gradle.png](/docs/resources/img/configure-intellij-gradle.png)

7. Refresh the project using Gradle's new configuration:
1. Open Gradle tool window: `View -> Tool Windows -> Gradle`
2. Click the `Reload All Gradle Projects` button.
![gradle-reload-all.png](/docs/resources/img/gradle-reload-all.png)
## Run Configurations
Several IntelliJ run configurations are provided to make it easier to run the project.
- `Docker - Run Dev Stack - Zookeeper, Kafka, DB`: runs the development stack locally, using `docker-compose`.
- `Run - All Servers - with Docker`: runs all the servers locally, using `docker-compose`.
- `Run - All Servers - no Docker`: runs all the servers locally, without running `docker-compose`.
- `Run - Sep Server - no Docker`: runs the SEP server locally, without running `docker-compose`.
- `Run - Platform Server - no Docker`: runs the Platform server locally, without running `docker-compose`.
- `Run - Event Processing Server - no Docker`: runs the Event Processing server locally, without
running `docker-compose`.
- `Run - Java Reference Server - no Docker`: runs the Java Reference server locally, without running `docker-compose`.
- `Run - Kotlin Reference Server - no Docker`: runs the Kotlin Reference server locally, without
running `docker-compose`.
The following run configurations are provided to run integration and end-2-end tests
- `Test - Kotlin Reference Server - no Docker`: runs the Kotlin Reference server locally, without
running `docker-compose`.
- `Test - End2End Test - no fullstack`: runs the end-2-end tests locally, without running `docker-compose`.
- `Test - End2End Test - with fullstack`: runs the end-2-end tests locally, with running `docker-compose`.
- `Test - Integration Test - no fullstack`: runs the integration tests locally, without running `docker-compose`.
- `Test - Integration Test - with fullstack`: runs the integration tests locally, with running `docker-compose`.
### Example: Debug the Platform Server
If you would like to debug the Platform server, you can do so by running the
- Make sure `docker` and `docker-compose` is available on your local machine.
- Run `Docker - Run Dev Stack - Zookeeper, Kafka, DB` to start the development stack.
- Run `Run - Sep Server - no Docker` to start the SEP server.
- Debug `Run - Platform Server - no Docker` to start debugging the Platform server.
### Example: Debug the Junit or the End-to-End Tests
If you would like to debug the unit tests or the end-to-end tests
- Make sure `docker` and `docker-compose` is available on your local machine.
- Run or Debug `Run - All Servers - with Docker`
- Debug `Test - End2End Test - no fullstack` or `Test - Integration Test - no fullstack`
## Running the Tests From Gradle in IntelliJ
To make sure your configuration worked, please make sure you can run all the tests successfully from the IDE:
1. Open the Gradle tool window: `View -> Tool Windows -> Gradle`.
2. Navigate to the all tests option: `Tasks -> verification -> test`.
3. Right-click it and select the `run` or `debug` option:
![running-the-tests.png](/docs/resources/img/running-the-tests.png)
__Note__: You may need to check there is no active docker containers running on your machine from the previous debug
sessions. If there are, please stop and delete them.
49 changes: 49 additions & 0 deletions docs/01 - Contributing/B - Git Guidelines.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Git Guidelines

Please follow the guidelines below when contributing to this project via Git and pull requests.

<!-- TOC -->
* [Git Guidelines](#git-guidelines)
* [Git Commit Messages](#git-commit-messages)
* [Pull Request Style](#pull-request-style)
* [Our Git workflow](#our-git-workflow)
<!-- TOC -->

## Git Commit Messages

Write your commit message in the imperative: `"Fix bug"` and not `"Fixed bug"` or `"Fixes bug."` This convention
matches up with commit messages generated by commands like git merge and git revert.

Example:

```text
Fix issue where Foo is handled as Bar.
Further paragraphs come after blank lines.
- Bullet points are okay, too
- Typically a hyphen or asterisk is used for the bullet, and bullets are wrapped by spaces before and after each bullet block.
If the commit relates to an issue, add a reference(s) to them at the bottom, like so:
Resolve: #123
```

## Pull Request Style

- Push the commits to your forked repository and create a pull request to the `develop` branch of this repository.
- When starting a pull request, it's recommended to start it as draft, so that it's clear that it's still a work in
progress.
- When the pull request is ready for review, remove the draft status and optionally post the message to
the `#ptal-anchor-eng` Slack channel.
- If possible, please prefix the pull request title with Jira ticket number, like:
- `[ANCHOR-100]: Fix the configuration issue.`
- `[ANCHOR-295]: SEP-6 deposit implementation.`
- Please make sure to fulfill the pull request templates.
- When merging the pull request, we suggest to use the squash & commit option.

## Our Git workflow

We use the [Gitflow Workflow](https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow) for this
project.

47 changes: 47 additions & 0 deletions docs/01 - Contributing/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# How to contribute

<!-- TOC -->
* [How to contribute](#how-to-contribute)
* [Set up the Development Environment](#set-up-the-development-environment)
* [Git Guidelines](#git-guidelines)
* [Logging Guidelines](#logging-guidelines)
* [Database Migration](#database-migration)
* [Publishing the SDK library to Maven Central](#publishing-the-sdk-library-to-maven-central)
* [Testing with AWS Services](#testing-with-aws-services)
<!-- TOC -->

👍🎉 First off, thanks for taking the time to contribute! 🎉👍

Check out the [Stellar Contribution Guide](https://github.com/stellar/.github/blob/master/CONTRIBUTING.md) that apply to
all Stellar projects.

## Set up the Development Environment

Check out
the [How to set up the development environment](A%20-%20Development%20Environment.md) guide.

## Git Guidelines

Check out the [Git Guidelines](B%20-%20Git%20Guidelines.md) guide.

## Logging Guidelines

When contributing code, think twice about a given log message because not every bit of information is equally important.
Therefore, the logging levels should be used consistently.

Please follow the [Logging Guidelines](C%20-%20Logging%20Guidelines.md).

## Database Migration

Please refer to [Database Migration](D%20-%20Database%20Migration.md) for information on
this topic.

## Publishing the SDK library to Maven Central

Please refer to [Publishing the SDK](E%20-%20Publishing%20the%20SDK.md) for information on
this topic.

## Testing with AWS Services

Please refer to [Testing with AWS Services](F%20-%20Testing%20with%20AWS%20Services.md) for
information on this topic.
Loading

0 comments on commit 67ceac1

Please sign in to comment.