From 90e024d07dd660e73c2731ffc9380fc73ce301bc Mon Sep 17 00:00:00 2001
From: Brian Wyka <46069296+brianwyka@users.noreply.github.com>
Date: Mon, 24 Jan 2022 17:12:17 -0500
Subject: [PATCH] Remote repository scanning improvements (#60)
* Remote repository scanning improvements progress
* remote-repository: Remote repository file reading improvements for Bitbucket
* remote-repository: Fix maven version
* remote-repository: Update groovy to 3.0.9 for JDK 17 support
* remote-repository: Fix maven version in test
* remote-repository: Fix more tests for JDK 17
* remote-repository: Fix Dockerfile ci images references
* remote-repository: Fix java8 graalvm version
* remote-repository: Vulnerability fixes, Fixes #38, Fixes #59, update ci with docker login and graalvm github actions
* remote-repository: Login to GHCR with correct creds
* remote-repository: Update static native imate to be -H:+StaticExecutableWithDynamicLibC
* remote-repository: Update busybox
* remote-repository: Static native image builds on musl, scratch Docker image, disabling Bintray publish
* remote-repository: Update github workflows
* remote-repository: Fix native image builder and push to ghcr
* remote-repository: Fix docker image builder for native image musl, and use github actions for docker layer caching
* remote-repository: Push docker builders
* remote-repository: Push docker builders
* remote-repository: 0.7.0
* remote-repository: Skip native image build for java 8
* remote-repository: Skip native image build for java 8
* remote-repository: Fix java8 build and workflow dependencies
* remote-repository: Fix needs syntax
* remote-repository: 1.8 reference to identigy java 8 in mvn profile
* remote-repository: Skip failsafe integration tests for java8
* remote-repository: Only build dist when not java 8
* remote-repository: Fix dist pom
* remote-repository: Don't cache docker builders
* remote-repository: Only build dist for java 11, use 20.3.0 for windows native image
* Revert to Test Report
* remote-repository: Remove git-commitid-plugin, fixes #68
* remote-repository: Fix git scripts format
* remote-repository: Archive completion script without 'bash'
* remote-repository: Update workflow names and archive linux native image
* Fix Linux native image archive path
---
.../build-and-push-docker-builders.yml | 81 +++-
.github/workflows/maven-ci.yml | 91 ++---
.github/workflows/release.yml | 177 +++++----
.gitignore | 1 +
.mvn/wrapper/maven-wrapper.properties | 2 +-
NOTICE.txt | 2 +-
attribution.txt | 8 +-
bom/pom.xml | 2 +-
cli/pom.xml | 20 +-
cli/scripts/update-picocli.sh | 22 +-
.../cli/AbstractRemoteScanCommand.java | 21 +-
.../sourcehawk/cli/BitbucketScanCommand.java | 37 +-
.../optum/sourcehawk/cli/CommandOptions.java | 11 +-
.../sourcehawk/cli/GithubScanCommand.java | 37 +-
.../com/optum/sourcehawk/cli/Sourcehawk.java | 2 +-
cli/src/main/java/picocli/CommandLine.java | 167 +++++---
.../sourcehawk-cli/native-image.properties | 3 +-
.../cli/BitbucketScanCommandSpec.groovy | 14 +-
.../cli/BitbucketScanSubCommandSpec.groovy | 18 +-
.../cli/CliBaseSpecification.groovy | 2 +-
.../cli/GithubScanCommandSpec.groovy | 10 +-
.../cli/NativeImageConfigSpec.groovy | 1 -
.../flattened/sourcehawk-flattened-base.yml | 2 +-
.../sourcehawk-flattened-override.yml | 2 +-
cli/src/test/resources/sourcehawk-simple.yml | 22 --
core/pom.xml | 2 +-
.../optum/sourcehawk/core/data/RemoteRef.java | 49 +--
.../BitbucketRepositoryFileReader.java | 52 ---
.../GithubRepositoryFileReader.java | 54 ---
.../repository/LocalRepositoryFileReader.java | 6 +
.../RemoteRepositoryFileReader.java | 81 ++--
.../core/repository/RepositoryFileReader.java | 8 +
.../sourcehawk/core/data/RemoteRefSpec.groovy | 28 +-
.../BitbucketRepositoryFileReaderSpec.groovy | 184 ---------
.../GithubRepositoryFileReaderSpec.groovy | 239 ------------
.../RemoteRepositoryFileReaderSpec.groovy | 165 ++++++--
distributions/debian/pom.xml | 219 ++++++-----
.../docker-builders/Dockerfile-nativeimage | 22 +-
distributions/docker/Dockerfile | 22 +-
distributions/docker/README.md | 6 +-
distributions/docker/etc/group | 1 +
distributions/docker/etc/passwd | 1 +
distributions/docker/pom.xml | 79 +++-
...-to-docker-hub.sh => push-docker-image.sh} | 0
.../linux/native-image-builder/Dockerfile | 5 +-
distributions/linux/pom.xml | 70 +++-
distributions/pom.xml | 13 +-
distributions/rpm/Dockerfile | 2 +-
distributions/rpm/pom.xml | 357 ++++++++----------
.../scripts/build-and-push-docker-builders.sh | 46 ---
.../extract-file-from-docker-container.sh | 3 +-
enforcer/core/pom.xml | 2 +-
enforcer/file/aot/pom.xml | 2 +-
...wkFileEnforcerRegistryProcessorSpec.groovy | 4 +-
enforcer/file/common/pom.xml | 2 +-
enforcer/file/core/pom.xml | 2 +-
enforcer/file/docker/pom.xml | 2 +-
enforcer/file/maven/pom.xml | 4 +-
enforcer/file/pom.xml | 2 +-
enforcer/file/registry/pom.xml | 4 +-
enforcer/pom.xml | 2 +-
exec/pom.xml | 4 +-
.../sourcehawk/exec/scan/ScanExecutor.java | 45 ++-
.../exec/scan/ScanResultFactory.java | 38 +-
.../exec/ConfigurationReaderSpec.groovy | 5 +-
.../sourcehawk/exec/ExecOptionsSpec.groovy | 11 +-
.../resources/sourcehawk-flattened-base.yml | 2 +-
pom.xml | 15 +-
68 files changed, 1176 insertions(+), 1439 deletions(-)
delete mode 100644 core/src/main/java/com/optum/sourcehawk/core/repository/BitbucketRepositoryFileReader.java
delete mode 100644 core/src/main/java/com/optum/sourcehawk/core/repository/GithubRepositoryFileReader.java
delete mode 100644 core/src/test/groovy/com/optum/sourcehawk/core/repository/BitbucketRepositoryFileReaderSpec.groovy
delete mode 100644 core/src/test/groovy/com/optum/sourcehawk/core/repository/GithubRepositoryFileReaderSpec.groovy
create mode 100644 distributions/docker/etc/group
create mode 100644 distributions/docker/etc/passwd
rename distributions/docker/scripts/{push-docker-image-to-docker-hub.sh => push-docker-image.sh} (100%)
delete mode 100755 distributions/scripts/build-and-push-docker-builders.sh
diff --git a/.github/workflows/build-and-push-docker-builders.yml b/.github/workflows/build-and-push-docker-builders.yml
index 2793019..c9b2543 100644
--- a/.github/workflows/build-and-push-docker-builders.yml
+++ b/.github/workflows/build-and-push-docker-builders.yml
@@ -10,12 +10,79 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- - uses: actions/checkout@v2
+ - name: Git Checkout
+ uses: actions/checkout@v2
with:
ref: ${{ github.event.inputs.ref }}
- - name: Build and Push Docker Images to Github Container Registry
- shell: bash
- run: ./distributions/scripts/build-and-push-docker-builders.sh
- env:
- DOCKER_USERNAME: ${{ secrets.GIT_USERNAME }}
- DOCKER_PASSWORD: ${{ secrets.GIT_PACKAGE_TOKEN }}
+ - name: Set up Docker Buildx
+ id: buildx
+ uses: docker/setup-buildx-action@v1
+ - name: Login to Github Container Registry
+ uses: docker/login-action@v1
+ with:
+ registry: ghcr.io
+ username: ${{ secrets.GIT_USERNAME }}
+ password: ${{ secrets.GIT_PACKAGE_TOKEN }}
+ - name: Build and Push graalvm-ce-21.3.0-java11
+ uses: docker/build-push-action@v2
+ with:
+ builder: ${{ steps.buildx.outputs.name }}
+ context: .
+ file: distributions/docker-builders/Dockerfile-nativeimage
+ build-args: FROM_VERSION=java11-21.3.0
+ tags: ghcr.io/optum/ci/nativeimage:graalvm-ce-21.3.0-java11
+ push: true
+ - name: Build and Push graalvm-ce-21.3.0-java17
+ uses: docker/build-push-action@v2
+ with:
+ builder: ${{ steps.buildx.outputs.name }}
+ context: .
+ file: distributions/docker-builders/Dockerfile-nativeimage
+ build-args: FROM_VERSION=java17-21.3.0
+ tags: ghcr.io/optum/ci/nativeimage:graalvm-ce-21.3.0-java17
+ push: true
+ - name: Build and Push rpmbuild centos7
+ uses: docker/build-push-action@v2
+ with:
+ builder: ${{ steps.buildx.outputs.name }}
+ context: .
+ file: distributions/docker-builders/Dockerfile-rpmbuild
+ build-args: FROM=centos:7
+ tags: ghcr.io/optum/ci/rpmbuild:centos7
+ push: true
+ - name: Build and Push rpmbuild centos8
+ uses: docker/build-push-action@v2
+ with:
+ builder: ${{ steps.buildx.outputs.name }}
+ context: .
+ file: distributions/docker-builders/Dockerfile-rpmbuild
+ build-args: FROM=centos:8
+ tags: ghcr.io/optum/ci/rpmbuild:centos8
+ push: true
+ - name: Build and Push rpmbuild fedora33
+ uses: docker/build-push-action@v2
+ with:
+ builder: ${{ steps.buildx.outputs.name }}
+ context: .
+ file: distributions/docker-builders/Dockerfile-rpmbuild
+ build-args: FROM=fedora:33
+ tags: ghcr.io/optum/ci/rpmbuild:fedora33
+ push: true
+ - name: Build and Push rpmbuild fedora34
+ uses: docker/build-push-action@v2
+ with:
+ builder: ${{ steps.buildx.outputs.name }}
+ context: .
+ file: distributions/docker-builders/Dockerfile-rpmbuild
+ build-args: FROM=fedora:34
+ tags: ghcr.io/optum/ci/rpmbuild:fedora34
+ push: true
+ - name: Build and Push rpmbuild fedora35
+ uses: docker/build-push-action@v2
+ with:
+ builder: ${{ steps.buildx.outputs.name }}
+ context: .
+ file: distributions/docker-builders/Dockerfile-rpmbuild
+ build-args: FROM=fedora:35
+ tags: ghcr.io/optum/ci/rpmbuild:fedora35
+ push: true
diff --git a/.github/workflows/maven-ci.yml b/.github/workflows/maven-ci.yml
index aae2c26..b7fab70 100644
--- a/.github/workflows/maven-ci.yml
+++ b/.github/workflows/maven-ci.yml
@@ -41,13 +41,16 @@ jobs:
matrix:
java: ['8', '11', '17']
steps:
- - uses: actions/checkout@v2
- - uses: actions/cache@v1
+ - name: Checkout Source Code
+ uses: actions/checkout@v2
+ - name: Setup Maven Cache
+ uses: actions/cache@v1
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- - uses: actions/cache@v1
+ - name: Setup Sonar Cache
+ uses: actions/cache@v1
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
@@ -78,27 +81,33 @@ jobs:
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
SONATYPE_GPG_PASSPHRASE: ${{ secrets.SONATYPE_GPG_PASSPHRASE }}
+ - name: Archive Linux Native Image
+ if: success() && (matrix.java == '11')
+ uses: actions/upload-artifact@v2
+ with:
+ name: linux-native-image
+ path: distributions/linux/target/sourcehawk
- name: Archive Native Image JAR
- if: success()
+ if: success() && (matrix.java == '11')
uses: actions/upload-artifact@v2
with:
- name: native-image-${{ matrix.java }}
+ name: native-image-jar
path: cli/target/*-native-image.jar
- - name: Archive Bash Completion Script
- if: success()
+ - name: Archive Completion Script
+ if: success() && (matrix.java == '11')
uses: actions/upload-artifact@v2
with:
- name: bash-completion-script-${{ matrix.java }}
- path: cli/target/sourcehawk-bash-completion.sh
+ name: completion-script
+ path: cli/target/sourcehawk-completion.sh
- name: Archive Manpages
- if: success()
+ if: success() && (matrix.java == '11')
uses: actions/upload-artifact@v2
with:
- name: manpages-${{ matrix.java }}
+ name: manpages
path: gh-pages/manpages/sourcehawk*.1
- name: Aggregate Coverage Reports
id: aggregate_coverage_reports
- if: success()
+ if: success() && (matrix.java == '11')
run: echo ::set-output name=JACOCO_XML_REPORT_PATHS::$(find . -name "jacoco.xml" -printf '%P\n' | tr '\r\n' ',')
- name: Analyze with SonarCloud
if: success() && (github.event_name == 'push' && matrix.java == '11')
@@ -118,31 +127,31 @@ jobs:
runs-on: macos-latest
needs: build
steps:
- - uses: actions/download-artifact@v2
+ - name: Download Native Image JAR
+ uses: actions/download-artifact@v2
with:
- name: native-image-8
+ name: native-image-jar
path: build
- - uses: actions/download-artifact@v2
+ - name: Download Completion Script
+ uses: actions/download-artifact@v2
with:
- name: bash-completion-script-8
+ name: completion-script
path: build
- - uses: actions/download-artifact@v2
+ - name: Download Manpages
+ uses: actions/download-artifact@v2
with:
- name: manpages-8
+ name: manpages
path: build
- name: Rename Native Image JAR
working-directory: build
run: mv *.jar native-image.jar
- - name: Setup Java
- uses: actions/setup-java@v1
- with:
- java-version: 8
- name: Setup GraalVM
- uses: DeLaGuardo/setup-graalvm@master
+ uses: graalvm/setup-graalvm@v1
with:
- graalvm-version: 21.2.0.java8
- - name: Setup GraalVM Native Image Tool
- run: gu install native-image
+ version: '21.3.0'
+ java-version: '11'
+ components: 'native-image'
+ github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Build Mac Native Image
if: success()
working-directory: build
@@ -150,7 +159,7 @@ jobs:
- name: Create Homebrew Tap Formula Archive
if: success()
working-directory: build
- run: gzip sourcehawk*.1 && tar -czvf sourcehawk-homebrew-tap-formula.tar.gz sourcehawk sourcehawk-bash-completion.sh sourcehawk*.1.gz
+ run: gzip sourcehawk*.1 && tar -czvf sourcehawk-homebrew-tap-formula.tar.gz sourcehawk sourcehawk-completion.sh sourcehawk*.1.gz
- name: Archive Mac Native Image
if: success()
continue-on-error: true
@@ -172,28 +181,26 @@ jobs:
build-windows-native-image:
runs-on: windows-latest
needs: build
+ continue-on-error: true
steps:
- - uses: actions/download-artifact@v2
+ - name: Download Native Image JAR
+ uses: actions/download-artifact@v2
with:
- name: native-image-11
+ name: native-image-jar
path: build
- name: Rename Native Image JAR
working-directory: build
run: ren *.jar native-image.jar
- - name: Setup GraalVM Native Image and Visual C Build Tools
- run: |
- Invoke-RestMethod -Uri https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-21.3.0/graalvm-ce-java11-windows-amd64-21.3.0.zip -OutFile 'graal.zip'
- Expand-Archive -path 'graal.zip' -destinationpath '.'
- graalvm-ce-java11-21.3.0\bin\gu.cmd install native-image
- choco install visualstudio2017-workload-vctools
+ - name: Setup GraalVM
+ uses: graalvm/setup-graalvm@v1
+ with:
+ version: '20.3.0'
+ java-version: '11'
+ components: 'native-image'
+ github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Build Windows Native Image
if: success()
- shell: cmd
- run: |
- call "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliary\Build\vcvars64.bat"
- graalvm-ce-java11-21.3.0\bin\native-image -cp .\build\native-image.jar -H:+ReportExceptionStackTraces --report-unsupported-elements-at-runtime
- env:
- JAVA_HOME: ./graalvm-ce-java11-21.3.0
+ run: native-image.cmd -cp .\build\native-image.jar -H:+ReportExceptionStackTraces --report-unsupported-elements-at-runtime
- name: Archive Windows Native Image
if: success()
continue-on-error: true
@@ -204,4 +211,4 @@ jobs:
- name: Smoke Test
if: success()
shell: cmd
- run: sourcehawk.exe help
\ No newline at end of file
+ run: sourcehawk.exe help
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 519f563..2d29d58 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -23,7 +23,8 @@ jobs:
RELEASE_VERSION: ${{ steps.set_maven_project_version.outputs.RELEASE_VERSION }}
RELEASE_ASSET_UPLOAD_URL: ${{ steps.create_release.outputs.upload_url }}
steps:
- - uses: actions/checkout@v2
+ - name: Checkout Source Code
+ uses: actions/checkout@v2
with:
ref: ${{ github.event.inputs.ref }}
token: ${{ secrets.GITHUB_TOKEN }}
@@ -56,18 +57,41 @@ jobs:
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
SONATYPE_GPG_PASSPHRASE: ${{ secrets.SONATYPE_GPG_PASSPHRASE }}
+ build-java11:
+ runs-on: ubuntu-latest
+ env:
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ steps:
+ - name: Checkout Source Code
+ uses: actions/checkout@v2
+ with:
+ ref: ${{ github.event.inputs.ref }}
+ - name: Setup Java and Maven
+ uses: actions/setup-java@v1
+ with:
+ java-version: 11
+ - name: Set Maven Project Version
+ shell: bash
+ run: |
+ RELEASE_VERSION=$(./mvnw help:evaluate -Dexpression=project.version -q -DforceStdout | tail -1 | tr -d '\r\n')
+ [[ "$RELEASE_VERSION" == *"-SNAPSHOT" ]] && RELEASE_VERSION="${RELEASE_VERSION%"-SNAPSHOT"}" && ./mvnw --batch-mode versions:set -D removeSnapshot || true
+ [[ "$(git tag -l $RELEASE_VERSION)" == "$RELEASE_VERSION" ]] && echo "Tag $RELEASE_VERSION already exists" && exit 1
+ echo ::set-output name=RELEASE_VERSION::$RELEASE_VERSION
+ - name: Build Maven Project
+ if: success()
+ run: ./mvnw --batch-mode install -D ci.build -D ci.release
- name: Archive Native Image JAR
if: success()
uses: actions/upload-artifact@v2
with:
- name: native-image
+ name: native-image-jar
path: cli/target/*-native-image.jar
- - name: Archive Bash Completion Script
+ - name: Archive Completion Script
if: success()
uses: actions/upload-artifact@v2
with:
- name: bash-completion-script
- path: cli/target/sourcehawk-bash-completion.sh
+ name: completion-script
+ path: cli/target/sourcehawk-completion.sh
- name: Archive Manpages
if: success()
uses: actions/upload-artifact@v2
@@ -106,10 +130,19 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ format('v{0}', steps.set_maven_project_version.outputs.RELEASE_VERSION) }}
- release_name: ${{ format('{0} {1}', github.event.repository.name, steps.set_maven_project_version.outputs.RELEASE_VERSION) }}
+ release_name: ${{ format('{0} {1}', github.event.repository.name, needs.build.outputs.RELEASE_VERSION) }}
body_path: CHANGELOG.md
draft: ${{ github.event.inputs.draft }}
prerelease: ${{ github.event.inputs.prerelease }}
+ - name: Publish Github Pages
+ if: success()
+ continue-on-error: true
+ uses: jamesives/github-pages-deploy-action@3.7.1
+ with:
+ COMMIT_MESSAGE: ${{ format('Publishing github pages for release version {0}', needs.build.outputs.RELEASE_VERSION) }}
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ BRANCH: gh-pages
+ FOLDER: gh-pages
- name: Upload Sourcehawk Linux Executable
if: success()
continue-on-error: true
@@ -119,7 +152,7 @@ jobs:
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./distributions/linux/target/sourcehawk
- asset_name: sourcehawk-${{ steps.set_maven_project_version.outputs.RELEASE_VERSION }}-linux-x86_64
+ asset_name: sourcehawk-${{ needs.build.outputs.RELEASE_VERSION }}-linux-x86_64
asset_content_type: application/octet-stream
- name: Upload Sourcehawk Debian Buster Package
if: success()
@@ -130,7 +163,7 @@ jobs:
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./distributions/debian/target/sourcehawk-debian-buster.deb
- asset_name: sourcehawk-${{ steps.set_maven_project_version.outputs.RELEASE_VERSION }}-debian-buster-amd64.deb
+ asset_name: sourcehawk-${{ needs.build.outputs.RELEASE_VERSION }}-debian-buster-amd64.deb
asset_content_type: application/octet-stream
- name: Upload Sourcehawk Ubuntu Focal Package
if: success()
@@ -141,7 +174,18 @@ jobs:
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./distributions/debian/target/sourcehawk-ubuntu-focal.deb
- asset_name: sourcehawk-${{ steps.set_maven_project_version.outputs.RELEASE_VERSION }}-ubuntu-focal-amd64.deb
+ asset_name: sourcehawk-${{ needs.build.outputs.RELEASE_VERSION }}-ubuntu-focal-amd64.deb
+ asset_content_type: application/octet-stream
+ - name: Upload Sourcehawk Centos 7 RPM Package
+ if: success()
+ continue-on-error: true
+ uses: actions/upload-release-asset@v1
+ env:
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ with:
+ upload_url: ${{ steps.create_release.outputs.upload_url }}
+ asset_path: ./distributions/rpm/target/sourcehawk-centos-7.rpm
+ asset_name: sourcehawk-${{ needs.build.outputs.RELEASE_VERSION }}-1.el7.x86_64.rpm
asset_content_type: application/octet-stream
- name: Upload Sourcehawk Centos 8 RPM Package
if: success()
@@ -152,9 +196,9 @@ jobs:
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./distributions/rpm/target/sourcehawk-centos-8.rpm
- asset_name: sourcehawk-${{ steps.set_maven_project_version.outputs.RELEASE_VERSION }}-1.el8.x86_64.rpm
+ asset_name: sourcehawk-${{ needs.build.outputs.RELEASE_VERSION }}-1.el8.x86_64.rpm
asset_content_type: application/octet-stream
- - name: Upload Sourcehawk Fedora 35 RPM Package
+ - name: Upload Sourcehawk Fedora 33 RPM Package
if: success()
continue-on-error: true
uses: actions/upload-release-asset@v1
@@ -162,59 +206,47 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
- asset_path: ./distributions/rpm/target/sourcehawk-fedora-35.rpm
- asset_name: sourcehawk-${{ steps.set_maven_project_version.outputs.RELEASE_VERSION }}-1.fc35.x86_64.rpm
+ asset_path: ./distributions/rpm/target/sourcehawk-fedora-33.rpm
+ asset_name: sourcehawk-${{ needs.build.outputs.RELEASE_VERSION }}-1.fc33.x86_64.rpm
asset_content_type: application/octet-stream
- - name: Publish Github Pages
+ - name: Upload Sourcehawk Fedora 34 RPM Package
if: success()
continue-on-error: true
- uses: jamesives/github-pages-deploy-action@3.7.1
- with:
- COMMIT_MESSAGE: ${{ format('Publishing github pages for release version {0}', steps.set_maven_project_version.outputs.RELEASE_VERSION) }}
+ uses: actions/upload-release-asset@v1
+ env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- BRANCH: gh-pages
- FOLDER: gh-pages
- build-java11:
- runs-on: ubuntu-latest
- env:
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- steps:
- - uses: actions/checkout@v2
- with:
- ref: ${{ github.event.inputs.ref }}
- - name: Setup Java and Maven
- uses: actions/setup-java@v1
with:
- java-version: 11
- - name: Set Maven Project Version
- shell: bash
- run: |
- RELEASE_VERSION=$(./mvnw help:evaluate -Dexpression=project.version -q -DforceStdout | tail -1 | tr -d '\r\n')
- [[ "$RELEASE_VERSION" == *"-SNAPSHOT" ]] && RELEASE_VERSION="${RELEASE_VERSION%"-SNAPSHOT"}" && ./mvnw --batch-mode versions:set -D removeSnapshot || true
- [[ "$(git tag -l $RELEASE_VERSION)" == "$RELEASE_VERSION" ]] && echo "Tag $RELEASE_VERSION already exists" && exit 1
- echo ::set-output name=RELEASE_VERSION::$RELEASE_VERSION
- - name: Build Maven Project
- if: success()
- run: ./mvnw --batch-mode install -D ci.build -D ci.release
- - name: Archive Native Image JAR
+ upload_url: ${{ steps.create_release.outputs.upload_url }}
+ asset_path: ./distributions/rpm/target/sourcehawk-fedora-34.rpm
+ asset_name: sourcehawk-${{ needs.build.outputs.RELEASE_VERSION }}-1.fc34.x86_64.rpm
+ asset_content_type: application/octet-stream
+ - name: Upload Sourcehawk Fedora 35 RPM Package
if: success()
- uses: actions/upload-artifact@v2
+ continue-on-error: true
+ uses: actions/upload-release-asset@v1
+ env:
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
- name: native-image-java11
- path: cli/target/*-native-image.jar
+ upload_url: ${{ steps.create_release.outputs.upload_url }}
+ asset_path: ./distributions/rpm/target/sourcehawk-fedora-35.rpm
+ asset_name: sourcehawk-${{ needs.build.outputs.RELEASE_VERSION }}-1.fc35.x86_64.rpm
+ asset_content_type: application/octet-stream
build-mac-native-image:
runs-on: macos-latest
- needs: build
+ needs: build-java11
steps:
- - uses: actions/download-artifact@v2
+ - name: Download Native Image JAR
+ uses: actions/download-artifact@v2
with:
- name: native-image
+ name: native-image-jar
path: build
- - uses: actions/download-artifact@v2
+ - name: Download Completion Script
+ uses: actions/download-artifact@v2
with:
- name: bash-completion-script
+ name: completion-script
path: build
- - uses: actions/download-artifact@v2
+ - name: Download Manpages
+ uses: actions/download-artifact@v2
with:
name: manpages
path: build
@@ -224,13 +256,14 @@ jobs:
- name: Setup Java
uses: actions/setup-java@v1
with:
- java-version: 8
+ java-version: 11
- name: Setup GraalVM
- uses: DeLaGuardo/setup-graalvm@master
+ uses: graalvm/setup-graalvm@v1
with:
- graalvm-version: 21.2.0.java8
- - name: Setup GraalVM Native Image Tool
- run: gu install native-image
+ version: '21.3.0'
+ java-version: '11'
+ components: 'native-image'
+ github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Build Mac Native Image
if: success()
working-directory: build
@@ -242,7 +275,7 @@ jobs:
- name: Create Homebrew Tap Formula Archive
if: success()
working-directory: build
- run: gzip sourcehawk*.1 && tar -czvf sourcehawk-homebrew-tap-formula.tar.gz sourcehawk sourcehawk-bash-completion.sh sourcehawk*.1.gz
+ run: gzip sourcehawk*.1 && tar -czvf sourcehawk-homebrew-tap-formula.tar.gz sourcehawk sourcehawk-completion.sh sourcehawk*.1.gz
- name: Upload Sourcehawk Mac Executable
if: success()
continue-on-error: true
@@ -275,34 +308,34 @@ jobs:
homebrew-tap: optum/homebrew-tap
base-branch: main
download-url: ${{ steps.upload_homebrew_tap_formula_archive.outputs.browser_download_url }}
- commit-message: Updating sourcehawk formula to latest release version ${{ needs.build.outputs.RELEASE_VERSION }}
+ commit-message: |
+ Sourcehawk ${{ needs.build.outputs.RELEASE_VERSION }}
+
+ Updating sourcehawk formula to latest release version
env:
COMMITTER_TOKEN: ${{ secrets.GIT_COMMITTER_TOKEN }}
build-windows-native-image:
runs-on: windows-latest
- needs: [build, build-java11]
+ needs: build-java11
steps:
- - uses: actions/download-artifact@v2
+ - name: Download Native Image JAR
+ uses: actions/download-artifact@v2
with:
- name: native-image-java11
+ name: native-image-jar
path: build
- name: Rename Native Image JAR
working-directory: build
run: ren *.jar native-image.jar
- - name: Setup GraalVM Native Image and Visual C Build Tools
- run: |
- Invoke-RestMethod -Uri https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-21.3.0/graalvm-ce-java11-windows-amd64-21.3.0.zip -OutFile 'graal.zip'
- Expand-Archive -path 'graal.zip' -destinationpath '.'
- graalvm-ce-java11-21.3.0\bin\gu.cmd install native-image
- choco install visualstudio2017-workload-vctools
+ - name: Setup GraalVM
+ uses: graalvm/setup-graalvm@v1
+ with:
+ version: '20.3.0'
+ java-version: '11'
+ components: 'native-image'
+ github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Build Windows Native Image
if: success()
- shell: cmd
- run: |
- call "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliary\Build\vcvars64.bat"
- graalvm-ce-java11-21.3.0\bin\native-image -cp .\build\native-image.jar -H:+ReportExceptionStackTraces --report-unsupported-elements-at-runtime
- env:
- JAVA_HOME: ./graalvm-ce-java11-21.3.0
+ run: native-image.cmd -cp .\build\native-image.jar -H:+ReportExceptionStackTraces --report-unsupported-elements-at-runtime
- name: Smoke Test
if: success()
shell: cmd
diff --git a/.gitignore b/.gitignore
index 0e332c5..6028a98 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,6 +5,7 @@ target/
*.log
log
logs
+*.bak
### STS ###
.apt_generated
diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties
index e404372..f8b5614 100644
--- a/.mvn/wrapper/maven-wrapper.properties
+++ b/.mvn/wrapper/maven-wrapper.properties
@@ -1 +1 @@
-distributionUrl = https://apache.claz.org/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.zip
\ No newline at end of file
+distributionUrl = https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.8.4/apache-maven-3.8.4-bin.zip
\ No newline at end of file
diff --git a/NOTICE.txt b/NOTICE.txt
index 15afa52..4fc5b89 100644
--- a/NOTICE.txt
+++ b/NOTICE.txt
@@ -1,6 +1,6 @@
sourcehawk
-Copyright 2021 Optum
+Copyright 2022 Optum
Project Description:
====================
diff --git a/attribution.txt b/attribution.txt
index e9b35ea..fc3dc30 100644
--- a/attribution.txt
+++ b/attribution.txt
@@ -390,7 +390,7 @@ https://opensource.org/licenses/BSD-2-Clause
-------------------------------------------------------------------------------------------------------------------------------
-Package: org.spockframework:spock-core:2.0-M3-groovy-3.0
+Package: org.spockframework:spock-core:2.0-groovy-3.0
License: Apache-2.0
@@ -1847,7 +1847,7 @@ limitations under the License.
-------------------------------------------------------------------------------------------------------------------------------
-Package: org.codehaus.groovy:groovy:3.0.4
+Package: org.codehaus.groovy:groovy:3.0.9
License: Apache-2.0
@@ -1955,7 +1955,7 @@ limitations under the License.
-------------------------------------------------------------------------------------------------------------------------------
-Package: org.apache.maven:maven-model:3.6.3
+Package: org.apache.maven:maven-model:3.8.4
License: Apache-2.0
@@ -2230,7 +2230,7 @@ http://www.apache.org/licenses/LICENSE-2.0
-------------------------------------------------------------------------------------------------------------------------------
-Package: info.picocli:4.6.1
+Package: info.picocli:4.6.2
License: Apache-2.0
diff --git a/bom/pom.xml b/bom/pom.xml
index 35dbd3b..febfdc6 100644
--- a/bom/pom.xml
+++ b/bom/pom.xml
@@ -8,7 +8,7 @@
com.optum.sourcehawk
sourcehawk
- 0.6.0-SNAPSHOT
+ 0.7.0-SNAPSHOT
sourcehawk-bom
diff --git a/cli/pom.xml b/cli/pom.xml
index 441e361..a73a1ea 100644
--- a/cli/pom.xml
+++ b/cli/pom.xml
@@ -8,7 +8,7 @@
sourcehawk
com.optum.sourcehawk
- 0.6.0-SNAPSHOT
+ 0.7.0-SNAPSHOT
sourcehawk-cli
@@ -23,7 +23,7 @@
com.optum.sourcehawk.cli.Sourcehawk
- 0.94
+ 0.91
**/picocli/**/*.*
@@ -31,7 +31,7 @@
**/picocli/**/*.*
- 4.6.1
+ 4.6.2
@@ -190,7 +190,7 @@
- generate-bash-completion-script
+ generate-completion-script
process-classes
java
@@ -207,7 +207,7 @@
--force
--completionScript
- ${project.build.directory}/${cli.name}-bash-completion.sh
+ ${project.build.directory}/${cli.name}-completion.sh
${cli.class}
@@ -235,7 +235,7 @@
build-helper-maven-plugin
- attach-bash-completion-script-artifact
+ attach-completion-script
attach-artifact
@@ -243,8 +243,8 @@
- ${project.build.directory}/${cli.name}-bash-completion.sh
- bash-completion
+ ${project.build.directory}/${cli.name}-completion.sh
+ completion
sh
@@ -389,11 +389,13 @@
- ${project.build.directory}/${cli.name}-bash-completion.sh
+ ${project.build.directory}/${cli.name}-completion.sh
${project.parent.basedir}/gh-pages/index.html
${project.parent.basedir}/gh-pages/stylesheets/sourcehawk.css
${project.parent.basedir}/gh-pages/manpages/sourcehawk.1
${project.parent.basedir}/gh-pages/manpages/scan.1
+ ${project.parent.basedir}/gh-pages/manpages/scan-bitbucket.1
+ ${project.parent.basedir}/gh-pages/manpages/scan-github.1
${project.parent.basedir}/gh-pages/manpages/validate-config.1
${project.parent.basedir}/gh-pages/manpages/fix.1
${project.parent.basedir}/gh-pages/manpages/flatten-config.1
diff --git a/cli/scripts/update-picocli.sh b/cli/scripts/update-picocli.sh
index f4619ee..84011f5 100755
--- a/cli/scripts/update-picocli.sh
+++ b/cli/scripts/update-picocli.sh
@@ -11,11 +11,11 @@ set -e
#########################################################################
# Retrieve Latest Version
-VERSION=$(curl -sI https://github.com/remkop/picocli/releases/latest | grep -i location: | awk -F"/" '{ printf "%s", $NF }' | tr -d 'v' | tr -d '\r\n')
+VERSION=$(curl -ksI https://github.com/remkop/picocli/releases/latest | grep -i location: | awk -F"/" '{ printf "%s", $NF }' | tr -d 'v' | tr -d '\r\n')
# Global Variables
-DIR="$( cd "$( dirname "$( dirname "${BASH_SOURCE[0]}" )")" && pwd )"
-ROOT_DIR="$( cd "$( dirname "$( dirname "$( dirname "${BASH_SOURCE[0]}" )")")" && pwd )"
+DIR="$(dirname "$(cd -- "$(dirname "$0")"; pwd -P)")"
+ROOT_DIR="$(dirname "$(dirname "$(cd -- "$(dirname "$0")"; pwd -P)")")"
BASE_URL="https://raw.githubusercontent.com/remkop/picocli"
LICENSE_URL="$BASE_URL/v$VERSION/LICENSE"
LICENSE_FILE_PATH="$DIR/src/main/resources/META-INF/licenses/picocli.txt"
@@ -28,15 +28,19 @@ curl -ksf "$LICENSE_URL" > "$LICENSE_FILE_PATH"
curl -ksf "$SOURCE_URL" > "$SOURCE_FILE_PATH"
# Add some warning suppression to the java source file
-sed -i 's/public\sclass\sCommandLine/@SuppressWarnings({"rawtypes", "deprecation" })\npublic class CommandLine/g' "$SOURCE_FILE_PATH"
+sed -i.bak -e 's/public class CommandLine/@SuppressWarnings({"rawtypes", "deprecation" })\npublic class CommandLine/g' \
+ -e 's/TODO/TIDO/g' "$SOURCE_FILE_PATH" \
+ && rm -rf "$SOURCE_FILE_PATH.bak"
+
+# Remove TODOs so not highlighted in editor
+sed -i.bak 's/TODO/TIDO/g' "$SOURCE_FILE_PATH"
# Replace the version in pom.xml file for plugin references
-sed -i "s/[-[:alnum:]./]\{1,\}<\/picocli.version>/$VERSION<\/picocli.version>/" "$DIR/pom.xml"
+sed -i.bak "s/[-[:alnum:]./]\{1,\}<\/picocli.version>/$VERSION<\/picocli.version>/" "$DIR/pom.xml" \
+ && rm -rf "$DIR/pom.xml.bak"
# Replace the version in attribution.txt file
-sed -i "s/Package: info.picocli:[-[:alnum:]./]\{1,\}/Package: info.picocli:$VERSION/" "$ROOT_DIR/attribution.txt"
-
-# Remove TODOs so not highlighted in editor
-sed -i 's/TODO/TIDO/g' "$SOURCE_FILE_PATH"
+sed -i.bak "s/Package: info.picocli:[-[:alnum:]./]\{1,\}/Package: info.picocli:$VERSION/" "$ROOT_DIR/attribution.txt" \
+ && rm -rf "$ROOT_DIR/attribution.txt.bak"
echo "Picocli updated to version: $VERSION"
\ No newline at end of file
diff --git a/cli/src/main/java/com/optum/sourcehawk/cli/AbstractRemoteScanCommand.java b/cli/src/main/java/com/optum/sourcehawk/cli/AbstractRemoteScanCommand.java
index daa1855..fffff82 100644
--- a/cli/src/main/java/com/optum/sourcehawk/cli/AbstractRemoteScanCommand.java
+++ b/cli/src/main/java/com/optum/sourcehawk/cli/AbstractRemoteScanCommand.java
@@ -43,7 +43,7 @@ abstract class AbstractRemoteScanCommand implements Callable {
*/
@Override
public Integer call() {
- val parentExecOptions = parentCommand.buildExecOptions();
+ val parentExecOptions = parentCommand.buildExecOptions(); // TODO: NPE ??
val execOptionsBuilder = parentExecOptions.toBuilder();
val configFileProvided = Optional.ofNullable(parentCommand.spec)
.map(CommandLine.Model.CommandSpec::commandLine)
@@ -52,21 +52,14 @@ public Integer call() {
.isPresent();
val remoteRef = validateAndParseRemoteRef();
execOptionsBuilder.remoteRef(remoteRef);
+ val repositoryFileReader = createRepositoryFileReader(remoteRef);
+ execOptionsBuilder.repositoryFileReader(repositoryFileReader);
if (StringUtils.equals(SourcehawkConstants.DEFAULT_CONFIG_FILE_NAME, parentExecOptions.getConfigurationFileLocation()) && !configFileProvided) {
- execOptionsBuilder.configurationFileLocation(constructRemoteConfigFileLocation(remoteRef));
+ execOptionsBuilder.configurationFileLocation(repositoryFileReader.getAbsoluteLocation(SourcehawkConstants.DEFAULT_CONFIG_FILE_NAME));
}
- execOptionsBuilder.repositoryFileReader(createRepositoryFileReader(remoteRef)).build();
return parentCommand.call(execOptionsBuilder.build());
}
- /**
- * Construct the remote config file location
- *
- * @param remoteRef the remote reference
- * @return the config file remote location
- */
- protected abstract String constructRemoteConfigFileLocation(final RemoteRef remoteRef);
-
/**
* Create the repository file reader based off the remote reference
*
@@ -76,11 +69,11 @@ public Integer call() {
protected abstract RepositoryFileReader createRepositoryFileReader(final RemoteRef remoteRef);
/**
- * Get the remote reference descriptor
+ * Get the raw remote reference
*
- * @return the raw remote reference descriptor
+ * @return the raw remote reference
*/
- protected abstract Pair getRawRemoteReference();
+ protected abstract Pair getRawRemoteReference();
/**
* Parse the coordinates to github options
diff --git a/cli/src/main/java/com/optum/sourcehawk/cli/BitbucketScanCommand.java b/cli/src/main/java/com/optum/sourcehawk/cli/BitbucketScanCommand.java
index 30c254b..c4caf44 100644
--- a/cli/src/main/java/com/optum/sourcehawk/cli/BitbucketScanCommand.java
+++ b/cli/src/main/java/com/optum/sourcehawk/cli/BitbucketScanCommand.java
@@ -1,14 +1,15 @@
package com.optum.sourcehawk.cli;
-import com.optum.sourcehawk.core.constants.SourcehawkConstants;
import com.optum.sourcehawk.core.data.Pair;
import com.optum.sourcehawk.core.data.RemoteRef;
-import com.optum.sourcehawk.core.repository.BitbucketRepositoryFileReader;
+import com.optum.sourcehawk.core.repository.RemoteRepositoryFileReader;
import com.optum.sourcehawk.core.repository.RepositoryFileReader;
import lombok.val;
import picocli.CommandLine;
-import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.util.Base64;
+import java.util.HashMap;
import java.util.Optional;
/**
@@ -25,6 +26,9 @@
)
public class BitbucketScanCommand extends AbstractRemoteScanCommand {
+ private static final String DEFAULT_BASE_URL = "https://bitbucket.org";
+ private static final String DEFAULT_REF = "main";
+
/**
* The Bitbucket options
*/
@@ -44,25 +48,24 @@ public static void main(final String... args) {
/** {@inheritDoc} */
@Override
protected RepositoryFileReader createRepositoryFileReader(final RemoteRef remoteRef) {
- if (bitbucket.serverUrl != null) {
- return new BitbucketRepositoryFileReader(bitbucket.token, bitbucket.serverUrl.toString(), remoteRef);
+ val rawFileUrlTemplate = Optional.ofNullable(bitbucket.serverUrl)
+ .map(bitbucketServerUrl -> String.format("%s/rest/api/1.0/projects/%s/repos/%s/raw/%%s?at=%s",
+ bitbucketServerUrl, remoteRef.getNamespace(), remoteRef.getRepository(), remoteRef.getRef()))
+ .orElseGet(() -> String.format("%s/api/2.0/repositories/%s/%s/src/%s/%%s", DEFAULT_BASE_URL, remoteRef.getNamespace(), remoteRef.getRepository(), remoteRef.getRef()));
+ val requestProperties = new HashMap();
+ requestProperties.put("Accept", "text/plain");
+ if (bitbucket.token != null) {
+ val authScheme = Optional.ofNullable(bitbucket.authScheme)
+ .orElse(CommandOptions.Bitbucket.DEFAULT_AUTH_SCHEME);
+ requestProperties.put("Authorization", String.format("%s %s", authScheme, bitbucket.token));
}
- return new BitbucketRepositoryFileReader(bitbucket.token, remoteRef);
- }
-
- /** {@inheritDoc} */
- @Override
- protected Pair getRawRemoteReference() {
- return Pair.of(RemoteRef.Type.BITBUCKET, bitbucket.remoteReference);
+ return new RemoteRepositoryFileReader(rawFileUrlTemplate, requestProperties);
}
/** {@inheritDoc} */
@Override
- protected String constructRemoteConfigFileLocation(final RemoteRef remoteRef) {
- val bitbucketBaseUrl = Optional.ofNullable(bitbucket.serverUrl)
- .map(URL::toString)
- .orElseGet(RemoteRef.Type.BITBUCKET::getBaseUrl);
- return BitbucketRepositoryFileReader.constructBaseUrl(remoteRef, bitbucketBaseUrl) + SourcehawkConstants.DEFAULT_CONFIG_FILE_NAME;
+ protected Pair getRawRemoteReference() {
+ return Pair.of(bitbucket.remoteReference, DEFAULT_REF);
}
}
diff --git a/cli/src/main/java/com/optum/sourcehawk/cli/CommandOptions.java b/cli/src/main/java/com/optum/sourcehawk/cli/CommandOptions.java
index ceba6c5..d25f175 100644
--- a/cli/src/main/java/com/optum/sourcehawk/cli/CommandOptions.java
+++ b/cli/src/main/java/com/optum/sourcehawk/cli/CommandOptions.java
@@ -152,6 +152,15 @@ static class Bitbucket {
)
String token;
+ @CommandLine.Option(
+ names = {"-a", "--auth-scheme"},
+ paramLabel = "auth-scheme",
+ defaultValue = DEFAULT_AUTH_SCHEME,
+ description = "The authorization scheme to use (either Bearer or Basic). If Basic, the provided token must be base64 encoded."
+ )
+ String authScheme;
+ static final String DEFAULT_AUTH_SCHEME = "Bearer";
+
@CommandLine.Option(
names = {"-S", "--server-url"},
paramLabel = "bitbucket-server-url",
@@ -162,7 +171,7 @@ static class Bitbucket {
@CommandLine.Parameters(
paramLabel = REMOTE_REFERENCE_LABEL,
description = "The Bitbucket remote reference - project/repo@ref combination, "
- + "i.e - project/repo, project/repo@master, project/repo@v1.4, or project/repo@a6de43fa51c",
+ + "i.e - project/repo, project/repo@main, project/repo@v1.4, or project/repo@a6de43fa51c",
arity = "1"
)
String remoteReference;
diff --git a/cli/src/main/java/com/optum/sourcehawk/cli/GithubScanCommand.java b/cli/src/main/java/com/optum/sourcehawk/cli/GithubScanCommand.java
index 784cf1f..b233902 100644
--- a/cli/src/main/java/com/optum/sourcehawk/cli/GithubScanCommand.java
+++ b/cli/src/main/java/com/optum/sourcehawk/cli/GithubScanCommand.java
@@ -1,14 +1,13 @@
package com.optum.sourcehawk.cli;
-import com.optum.sourcehawk.core.constants.SourcehawkConstants;
import com.optum.sourcehawk.core.data.Pair;
import com.optum.sourcehawk.core.data.RemoteRef;
-import com.optum.sourcehawk.core.repository.GithubRepositoryFileReader;
+import com.optum.sourcehawk.core.repository.RemoteRepositoryFileReader;
import com.optum.sourcehawk.core.repository.RepositoryFileReader;
import lombok.val;
import picocli.CommandLine;
-import java.net.URL;
+import java.util.HashMap;
import java.util.Optional;
/**
@@ -25,6 +24,10 @@
)
public class GithubScanCommand extends AbstractRemoteScanCommand {
+ private static final String DEFAULT_BASE_URL = "raw.githubusercontent.com";
+ private static final String DEFAULT_REF = "main";
+ private static final String AUTHORIZATION_TOKEN_PREFIX = "Bearer";
+
/**
* The github options
*/
@@ -44,28 +47,22 @@ public static void main(final String... args) {
/** {@inheritDoc} */
@Override
protected RepositoryFileReader createRepositoryFileReader(final RemoteRef remoteRef) {
- if (github.enterpriseUrl != null) {
- return new GithubRepositoryFileReader(github.token, github.enterpriseUrl.toString(), remoteRef);
+ val baseUrl = Optional.ofNullable(github.enterpriseUrl)
+ .map(githubEnterpriseUrl -> String.format("%s/raw", github.enterpriseUrl))
+ .orElse(DEFAULT_BASE_URL);
+ val rawFileUrlTemplate = String.format("%s/%s/%s/%s/%%s", baseUrl, remoteRef.getNamespace(), remoteRef.getRepository(), remoteRef.getRef());
+ val requestProperties = new HashMap();
+ requestProperties.put("Accept", "text/plain");
+ if (github.token != null) {
+ requestProperties.put("Authorization", String.format("%s %s", AUTHORIZATION_TOKEN_PREFIX, github.token));
}
- return new GithubRepositoryFileReader(github.token, remoteRef);
- }
-
- /** {@inheritDoc} */
- @Override
- protected Pair getRawRemoteReference() {
- return Pair.of(RemoteRef.Type.GITHUB, github.remoteReference);
+ return new RemoteRepositoryFileReader(rawFileUrlTemplate, requestProperties);
}
/** {@inheritDoc} */
@Override
- protected String constructRemoteConfigFileLocation(final RemoteRef remoteRef) {
- val githubEnterpriseUrl = Optional.ofNullable(github.enterpriseUrl).map(URL::toString);
- val githubRepoBaseUrl = GithubRepositoryFileReader.constructBaseUrl(
- githubEnterpriseUrl.orElseGet(RemoteRef.Type.GITHUB::getBaseUrl),
- githubEnterpriseUrl.isPresent(),
- remoteRef
- );
- return githubRepoBaseUrl + SourcehawkConstants.DEFAULT_CONFIG_FILE_NAME;
+ protected Pair getRawRemoteReference() {
+ return Pair.of(github.remoteReference, DEFAULT_REF);
}
}
diff --git a/cli/src/main/java/com/optum/sourcehawk/cli/Sourcehawk.java b/cli/src/main/java/com/optum/sourcehawk/cli/Sourcehawk.java
index 28f1e86..8840dab 100644
--- a/cli/src/main/java/com/optum/sourcehawk/cli/Sourcehawk.java
+++ b/cli/src/main/java/com/optum/sourcehawk/cli/Sourcehawk.java
@@ -22,7 +22,7 @@
headerHeading = "@|fg(magenta) >_ S O U R C E H A W K|@",
synopsisHeading = "%n",
commandListHeading ="%nCommands:%n",
- footer = "Copyright (c) 2020 Optum",
+ footer = "Copyright (c) 2022 Optum",
versionProvider = Sourcehawk.VersionProvider.class,
subcommands = {
CommandLine.HelpCommand.class,
diff --git a/cli/src/main/java/picocli/CommandLine.java b/cli/src/main/java/picocli/CommandLine.java
index 636662b..07a29c9 100644
--- a/cli/src/main/java/picocli/CommandLine.java
+++ b/cli/src/main/java/picocli/CommandLine.java
@@ -72,7 +72,7 @@
*
* // CheckSum implements Callable, so parsing, error handling and handling user
* // requests for usage help or version help can be done with one line of code.
- * public static void main(String[] args) throws Exception {
+ * public static void main(String[] args) {
* int exitCode = new CommandLine(new CheckSum()).execute(args);
* System.exit(exitCode);
* }
@@ -146,7 +146,7 @@
public class CommandLine {
/** This is picocli version {@value}. */
- public static final String VERSION = "4.6.1";
+ public static final String VERSION = "4.6.2";
private final Tracer tracer = new Tracer();
private CommandSpec commandSpec;
@@ -1207,7 +1207,7 @@ public CommandLine setColorScheme(Help.ColorScheme colorScheme) {
* help with a {@code --help} or similar option, the usage help message is printed to the standard output stream so that it can be easily searched and paged.
* @since 4.0 */
public PrintWriter getOut() {
- if (out == null) { setOut(new PrintWriter(System.out, true)); }
+ if (out == null) { setOut(newPrintWriter(System.out, getStdoutEncoding())); }
return out;
}
@@ -1234,7 +1234,7 @@ public CommandLine setOut(PrintWriter out) {
* should use this writer to print error messages (which may include a usage help message) when an unexpected error occurs.
* @since 4.0 */
public PrintWriter getErr() {
- if (err == null) { setErr(new PrintWriter(System.err, true)); }
+ if (err == null) { setErr(newPrintWriter(System.err, getStderrEncoding())); }
return err;
}
@@ -1808,7 +1808,7 @@ protected R throwOrExit(ExecutionException ex) {
* @since 2.0 */
@Deprecated public static class DefaultExceptionHandler extends AbstractHandler> implements IExceptionHandler, IExceptionHandler2 {
public List