Skip to content

Commit

Permalink
JAVA-8427 migrate maven plugin to sdk repo
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianPhillips2020 committed Nov 8, 2024
1 parent d94c7bc commit 5f9dd49
Show file tree
Hide file tree
Showing 49 changed files with 5,501 additions and 73 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/build-maven-plugin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: build

on: [push]

jobs:
changelog:
runs-on: ubuntu-latest
steps:
- uses: dangoslen/changelog-enforcer@v3
build:
name: Verify
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-java@v4
with:
java-version: 11
distribution: temurin

- uses: actions/setup-java@v4
with:
java-version: 17
distribution: temurin

- uses: actions/setup-java@v4
with:
java-version: 21
distribution: temurin

- name: Maven Verify
env:
CONTRAST__API__URL: ${{ secrets.CONTRAST__API__URL }}
CONTRAST__API__USER_NAME: ${{ secrets.CONTRAST__API__USER_NAME }}
CONTRAST__API__API_KEY: ${{ secrets.CONTRAST__API__API_KEY }}
CONTRAST__API__SERVICE_KEY: ${{ secrets.CONTRAST__API__SERVICE_KEY }}
CONTRAST__API__ORGANIZATION_ID: ${{ secrets.CONTRAST__API__ORGANIZATION_ID }}
run: cd maven-plugin/ && ./mvnw --batch-mode -Pend-to-end-test verify
2 changes: 1 addition & 1 deletion .github/workflows/build-sdk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: Cache Maven Wrapper
uses: actions/cache@v2
with:
path: ./.mvn/wrapper/maven-wrapper.jar
path: cd sdk/ ./.mvn/wrapper/maven-wrapper.jar
key: ${{ runner.os }}-maven-wrapper-${{ hashFiles('./.mvn/wrapper/maven-wrapper.properties') }}
restore-keys: ${{ runner.os }}-maven-wrapper

Expand Down
62 changes: 62 additions & 0 deletions .github/workflows/publish-maven-plugin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: publish

on:
workflow_dispatch:

jobs:
publish:
permissions:
contents: write
environment: Maven Central
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Set up JDK 11
uses: actions/setup-java@v2
with:
java-version: 11
distribution: temurin
server-id: ossrh
server-username: OSSRH_USERNAME
server-password: OSSRH_PASSWORD
gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }}
gpg-passphrase: GPG_PASSPHRASE

- name: Cache Maven Wrapper
uses: actions/cache@v2
with:
path: cd maven-plugin/ && ./.mvn/wrapper/maven-wrapper.jar
key: ${{ runner.os }}-maven-wrapper-${{ hashFiles('./.mvn/wrapper/maven-wrapper.properties') }}
restore-keys: ${{ runner.os }}-maven-wrapper

- name: Cache Maven Repository
uses: actions/cache@v2
with:
path: ~/.m2/repository
key: ${{ runner.os }}-m2-repository-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2-repository

# See https://github.com/actions/checkout/issues/13
- name: Configure Git User
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email '41898282+github-actions[bot]@users.noreply.github.com'
- name: Maven Release (dry-run)
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
run: |
cd maven-plugin/ && ./mvnw -DdryRun=true --batch-mode release:prepare release:perform -Dusername=$GITHUB_ACTOR -Dpassword=$GITHUB_TOKEN
- name: Maven Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
run: |
cd maven-plugin/ && ./mvnw --batch-mode release:prepare release:perform -Dusername=$GITHUB_ACTOR -Dpassword=$GITHUB_TOKEN
File renamed without changes.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Project
*.private.env.json
/.idea
*.iml

Expand Down
77 changes: 5 additions & 72 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,80 +1,13 @@
# Contrast Java SDK
# Contrast SDK Repo

[![javadoc](https://javadoc.io/badge2/com.contrastsecurity/contrast-sdk-java/javadoc.svg)](https://javadoc.io/doc/com.contrastsecurity/contrast-sdk-java)
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.contrastsecurity/contrast-sdk-java/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.contrastsecurity/contrast-sdk-java)
Root repository for the Contrast SDK, Contrast Gradle Plugin, and Contrast Maven Plugin

Each sub-project is a standalone build, with their own maven/gradle builds.

This SDK gives you a quick start for programmatically accessing the [Contrast REST API](https://api.contrastsecurity.com/) using Java.

[SDK](sdk/README.md)

## Requirements
[Maven Plugin](maven-plugin/README.md)

* JDK 1.8
* Contrast Account


## How to use this SDK

1. Add the
[contrast-sdk-java](https://search.maven.org/artifact/com.contrastsecurity/contrast-sdk-java)
dependency from Maven Central to your project.
1. At a minimum, you will need to supply four basic connection parameters ([find them here](https://docs.contrastsecurity.com/en/personal-keys.html)):
* Username
* API Key
* Service Key
* Contrast REST API URL (e.g. https://app.contrastsecurity.com/Contrast/api)


## Example

```java
ContrastSDK contrastSDK = new ContrastSDK.Builder("contrast_admin", "demo", "demo")
.withApiUrl("http://localhost:19080/Contrast/api")
.build();

String orgUuid = contrastSDK.getProfileDefaultOrganizations().getOrganization().getOrgUuid();

Applications apps = contrastSDK.getApplications(orgUuid);
for (Application app : apps.getApplications()) {
System.out.println(app.getName() + " (" + app.getCodeShorthand() + " LOC)");
}
```

Sample output:
```
Aneritx (48K LOC)
Default Web Site (0k LOC)
EnterpriseTPS (48K LOC)
Feynmann (48K LOC)
jhipster-sample (0k LOC)
JSPWiki (48K LOC)
Liferay (48K LOC)
OpenMRS (65K LOC)
OracleFS (48K LOC)
Security Test (< 1K LOC)
Ticketbook (2K LOC)
WebGoat (48K LOC)
WebGoat7 (106K LOC)
```


## Building

Requires JDK 11 to build

Use `./mvnw verify` to build and test changes to the project


### Formatting

To avoid distracting white space changes in pull requests and wasteful bickering
about format preferences, Contrast uses the google-java-format opinionated Java
code formatter to automatically format all code to a common specification.

Developers are expected to configure their editors to automatically apply this
format (plugins exist for both IDEA and Eclipse). Alternatively, developers can
apply the formatting before committing changes using the Maven plugin:

```shell
./mvnw spotless:apply
```
Loading

0 comments on commit 5f9dd49

Please sign in to comment.