Skip to content

Commit

Permalink
Merge pull request #212 from paketo-buildpacks/maven-4
Browse files Browse the repository at this point in the history
Add Maven 4
  • Loading branch information
dmikusa authored Nov 18, 2022
2 parents bb30a96 + 862ffa9 commit aae8b22
Show file tree
Hide file tree
Showing 8 changed files with 264 additions and 52 deletions.
28 changes: 21 additions & 7 deletions .github/pipeline-descriptor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,28 @@ docker_credentials:
password: ${{ secrets.JAVA_GCLOUD_SERVICE_ACCOUNT_KEY }}

dependencies:
- id: maven
uses: docker://ghcr.io/paketo-buildpacks/actions/maven-dependency:main
- name: Maven 3
id: maven
uses: docker://ghcr.io/paketo-buildpacks/actions/maven-dependency:main
version_pattern: "^3\\.[\\d]+\\.[\\d]+"
with:
uri: https://repo1.maven.org/maven2
group_id: org.apache.maven
artifact_id: apache-maven
classifier: bin
packaging: tar.gz
uri: https://repo1.maven.org/maven2
group_id: org.apache.maven
artifact_id: apache-maven
classifier: bin
packaging: tar.gz
version_regex: ^3\\.[\\d]+\\.[\\d]+$
- name: Maven 4
id: maven
uses: docker://ghcr.io/paketo-buildpacks/actions/maven-dependency:main
version_pattern: "^4\\.[\\d]+\\.[\\d]+"
with:
uri: https://repo1.maven.org/maven2
group_id: org.apache.maven
artifact_id: apache-maven
classifier: bin
packaging: tar.gz
version_regex: ^4\\.[\\d]+\\.[\\d]+-.*$
- id: mvnd
uses: docker://ghcr.io/paketo-buildpacks/actions/github-release-dependency:main
with:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Update maven
name: Update Maven 3
"on":
schedule:
- cron: 0 5 * * 1-5
Expand Down Expand Up @@ -49,6 +49,7 @@ jobs:
group_id: org.apache.maven
packaging: tar.gz
uri: https://repo1.maven.org/maven2
version_regex: ^3\\.[\\d]+\\.[\\d]+$
- name: Update Buildpack Dependency
id: buildpack
run: |-
Expand Down Expand Up @@ -97,18 +98,18 @@ jobs:
SHA256: ${{ steps.dependency.outputs.sha256 }}
URI: ${{ steps.dependency.outputs.uri }}
VERSION: ${{ steps.dependency.outputs.version }}
VERSION_PATTERN: '[\d]+\.[\d]+\.[\d]+'
VERSION_PATTERN: ^3\.[\d]+\.[\d]+
- uses: peter-evans/create-pull-request@v4
with:
author: ${{ secrets.JAVA_GITHUB_USERNAME }} <${{ secrets.JAVA_GITHUB_USERNAME }}@users.noreply.github.com>
body: Bumps `maven` from `${{ steps.buildpack.outputs.old-version }}` to `${{ steps.buildpack.outputs.new-version }}`.
branch: update/buildpack/maven
body: Bumps `Maven 3` from `${{ steps.buildpack.outputs.old-version }}` to `${{ steps.buildpack.outputs.new-version }}`.
branch: update/buildpack/maven-3
commit-message: |-
Bump maven from ${{ steps.buildpack.outputs.old-version }} to ${{ steps.buildpack.outputs.new-version }}
Bump Maven 3 from ${{ steps.buildpack.outputs.old-version }} to ${{ steps.buildpack.outputs.new-version }}
Bumps maven from ${{ steps.buildpack.outputs.old-version }} to ${{ steps.buildpack.outputs.new-version }}.
Bumps Maven 3 from ${{ steps.buildpack.outputs.old-version }} to ${{ steps.buildpack.outputs.new-version }}.
delete-branch: true
labels: ${{ steps.buildpack.outputs.version-label }}, type:dependency-upgrade
signoff: true
title: Bump maven from ${{ steps.buildpack.outputs.old-version }} to ${{ steps.buildpack.outputs.new-version }}
title: Bump Maven 3 from ${{ steps.buildpack.outputs.old-version }} to ${{ steps.buildpack.outputs.new-version }}
token: ${{ secrets.JAVA_GITHUB_TOKEN }}
115 changes: 115 additions & 0 deletions .github/workflows/pb-update-maven-4.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
name: Update Maven 4
"on":
schedule:
- cron: 0 5 * * 1-5
workflow_dispatch: {}
jobs:
update:
name: Update Buildpack Dependency
runs-on:
- ubuntu-latest
steps:
- uses: actions/setup-go@v3
with:
go-version: "1.18"
- name: Install update-buildpack-dependency
run: |
#!/usr/bin/env bash
set -euo pipefail
go install -ldflags="-s -w" github.com/paketo-buildpacks/libpak/cmd/update-buildpack-dependency@latest
- name: Install yj
run: |
#!/usr/bin/env bash
set -euo pipefail
echo "Installing yj ${YJ_VERSION}"
mkdir -p "${HOME}"/bin
echo "${HOME}/bin" >> "${GITHUB_PATH}"
curl \
--location \
--show-error \
--silent \
--output "${HOME}"/bin/yj \
"https://github.com/sclevine/yj/releases/download/v${YJ_VERSION}/yj-linux"
chmod +x "${HOME}"/bin/yj
env:
YJ_VERSION: 5.0.0
- uses: actions/checkout@v3
- id: dependency
uses: docker://ghcr.io/paketo-buildpacks/actions/maven-dependency:main
with:
artifact_id: apache-maven
classifier: bin
group_id: org.apache.maven
packaging: tar.gz
uri: https://repo1.maven.org/maven2
version_regex: ^4\\.[\\d]+\\.[\\d]+-.*$
- name: Update Buildpack Dependency
id: buildpack
run: |-
#!/usr/bin/env bash
set -euo pipefail
OLD_VERSION=$(yj -tj < buildpack.toml | jq -r "
.metadata.dependencies[] |
select( .id == env.ID ) |
select( .version | test( env.VERSION_PATTERN ) ) |
.version")
update-buildpack-dependency \
--buildpack-toml buildpack.toml \
--id "${ID}" \
--version-pattern "${VERSION_PATTERN}" \
--version "${VERSION}" \
--cpe-pattern "${CPE_PATTERN:-}" \
--cpe "${CPE:-}" \
--purl-pattern "${PURL_PATTERN:-}" \
--purl "${PURL:-}" \
--uri "${URI}" \
--sha256 "${SHA256}"
git add buildpack.toml
git checkout -- .
if [ "$(echo "$OLD_VERSION" | awk -F '.' '{print $1}')" != "$(echo "$VERSION" | awk -F '.' '{print $1}')" ]; then
LABEL="semver:major"
elif [ "$(echo "$OLD_VERSION" | awk -F '.' '{print $2}')" != "$(echo "$VERSION" | awk -F '.' '{print $2}')" ]; then
LABEL="semver:minor"
else
LABEL="semver:patch"
fi
echo "::set-output name=old-version::${OLD_VERSION}"
echo "::set-output name=new-version::${VERSION}"
echo "::set-output name=version-label::${LABEL}"
env:
CPE: ${{ steps.dependency.outputs.cpe }}
CPE_PATTERN: ""
ID: maven
PURL: ${{ steps.dependency.outputs.purl }}
PURL_PATTERN: ""
SHA256: ${{ steps.dependency.outputs.sha256 }}
URI: ${{ steps.dependency.outputs.uri }}
VERSION: ${{ steps.dependency.outputs.version }}
VERSION_PATTERN: ^4\.[\d]+\.[\d]+
- uses: peter-evans/create-pull-request@v4
with:
author: ${{ secrets.JAVA_GITHUB_USERNAME }} <${{ secrets.JAVA_GITHUB_USERNAME }}@users.noreply.github.com>
body: Bumps `Maven 4` from `${{ steps.buildpack.outputs.old-version }}` to `${{ steps.buildpack.outputs.new-version }}`.
branch: update/buildpack/maven-4
commit-message: |-
Bump Maven 4 from ${{ steps.buildpack.outputs.old-version }} to ${{ steps.buildpack.outputs.new-version }}
Bumps Maven 4 from ${{ steps.buildpack.outputs.old-version }} to ${{ steps.buildpack.outputs.new-version }}.
delete-branch: true
labels: ${{ steps.buildpack.outputs.version-label }}, type:dependency-upgrade
signoff: true
title: Bump Maven 4 from ${{ steps.buildpack.outputs.old-version }} to ${{ steps.buildpack.outputs.new-version }}
token: ${{ secrets.JAVA_GITHUB_TOKEN }}
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,17 @@ The buildpack will do the following:

## Configuration

| Environment Variable | Description |
| --------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `$BP_MAVEN_BUILD_ARGUMENTS` | Configure the arguments to pass to Maven. Defaults to `-Dmaven.test.skip=true --no-transfer-progress package`. `--batch-mode` will be prepended to the argument list in environments without a TTY. |
| `$BP_MAVEN_BUILT_MODULE` | Configure the module to find application artifact in. Defaults to the root module (empty). |
| `$BP_MAVEN_BUILT_ARTIFACT` | Configure the built application artifact explicitly. Supersedes `$BP_MAVEN_BUILT_MODULE` Defaults to `target/*.[ejw]ar`. Can match a single file, multiple files or a directory. Can be one or more space separated patterns. |
| `$BP_MAVEN_POM_FILE` | Specifies a custom location to the project's `pom.xml` file. It should be a full path to the file under the `/workspace` directory or it should be relative to the root of the project (i.e. `/workspace'). Defaults to `pom.xml`. |
| `$BP_MAVEN_DAEMON_ENABLED` | Triggers apache maven-mvnd to be installed and configured for use instead of Maven. The default value is `false`. Set to `true` to use the Maven Daemon. |
| `$BP_MAVEN_SETTINGS_PATH` | Specifies a custom location to Maven's `settings.xml` file. If `$BP_MAVEN_SETTINGS_PATH` is set and a Maven binding is provided, the binding takes the higher precedence. |
| `$BP_INCLUDE_FILES` | Colon separated list of glob patterns to match source files. Any matched file will be retained in the final image. Defaults to `` (i.e. nothing). |
| `$BP_EXCLUDE_FILES` | Colon separated list of glob patterns to match source files. Any matched file will be specifically removed from the final image. If include patterns are also specified, then they are applied first and exclude patterns can be used to further reduce the fileset. |
| Environment Variable | Description |
| --------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `$BP_MAVEN_VERSION` | Configure the major Maven version (e.g. `3`, `4`). Since the buildpack only ships a single version of each supported line, updates to the buildpack can change the exact version of Maven installed. If you require a specific minor/patch version of Maven, use the Maven wrapper instead. |
| `$BP_MAVEN_BUILD_ARGUMENTS` | Configure the arguments to pass to Maven. Defaults to `-Dmaven.test.skip=true --no-transfer-progress package`. `--batch-mode` will be prepended to the argument list in environments without a TTY. |
| `$BP_MAVEN_BUILT_MODULE` | Configure the module to find application artifact in. Defaults to the root module (empty). |
| `$BP_MAVEN_BUILT_ARTIFACT` | Configure the built application artifact explicitly. Supersedes `$BP_MAVEN_BUILT_MODULE` Defaults to `target/*.[ejw]ar`. Can match a single file, multiple files or a directory. Can be one or more space separated patterns. |
| `$BP_MAVEN_POM_FILE` | Specifies a custom location to the project's `pom.xml` file. It should be a full path to the file under the `/workspace` directory or it should be relative to the root of the project (i.e. `/workspace'). Defaults to `pom.xml`. |
| `$BP_MAVEN_DAEMON_ENABLED` | Triggers apache maven-mvnd to be installed and configured for use instead of Maven. The default value is `false`. Set to `true` to use the Maven Daemon. |
| `$BP_MAVEN_SETTINGS_PATH` | Specifies a custom location to Maven's `settings.xml` file. If `$BP_MAVEN_SETTINGS_PATH` is set and a Maven binding is provided, the binding takes the higher precedence. |
| `$BP_INCLUDE_FILES` | Colon separated list of glob patterns to match source files. Any matched file will be retained in the final image. Defaults to `` (i.e. nothing). |
| `$BP_EXCLUDE_FILES` | Colon separated list of glob patterns to match source files. Any matched file will be specifically removed from the final image. If include patterns are also specified, then they are applied first and exclude patterns can be used to further reduce the fileset. |

## Bindings

Expand Down
20 changes: 20 additions & 0 deletions buildpack.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ api = "0.7"
description = "the path to a Maven settings file"
name = "BP_MAVEN_SETTINGS_PATH"

[[metadata.configurations]]
build = true
default = "3"
description = "the Maven version"
name = "BP_MAVEN_VERSION"

[[metadata.configurations]]
build = true
default = ""
Expand All @@ -92,6 +98,20 @@ api = "0.7"
type = "Apache-2.0"
uri = "https://www.apache.org/licenses/"

[[metadata.dependencies]]
cpes = ["cpe:2.3:a:apache:maven:4.0.0:*:*:*:*:*:*:*"]
id = "maven"
name = "Apache Maven"
purl = "pkg:generic/[email protected]"
sha256 = "4b133c01af2559501c13e6366149c65db87178d0ac354fd1f3204463b6bac7b2"
stacks = ["io.buildpacks.stacks.bionic", "io.paketo.stacks.tiny", "*"]
uri = "https://repo1.maven.org/maven2/org/apache/maven/apache-maven/4.0.0-alpha-2/apache-maven-4.0.0-alpha-2-bin.tar.gz"
version = "4.0.0"

[[metadata.dependencies.licenses]]
type = "Apache-2.0"
uri = "https://www.apache.org/licenses/"

[[metadata.dependencies]]
cpes = ["cpe:2.3:a:apache:mvnd:0.8.2:*:*:*:*:*:*:*"]
id = "mvnd"
Expand Down
10 changes: 5 additions & 5 deletions maven/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (b Build) Build(context libcnb.BuildContext) (libcnb.BuildResult, error) {
result.BOM.Entries = append(result.BOM.Entries, *be)
}
} else {
command, _, _, err = NewNoopMavenManager().Install()
command, _, _, err = NewNoopMavenManager(b.Logger).Install()
if err != nil {
return libcnb.BuildResult{}, fmt.Errorf("unable pick Maven command\n%w", err)
}
Expand Down Expand Up @@ -146,10 +146,10 @@ func (b Build) Build(context libcnb.BuildContext) (libcnb.BuildResult, error) {
func (b Build) installMaven(context libcnb.BuildContext) (string, libcnb.LayerContributor, *libcnb.BOMEntry, error) {
// be careful changing this, the order does matter to a degree
managers := []MavenManager{
NewDaemonMavenManager(b.configResolver, b.depResolver, b.depCache, context.Layers.Path),
NewStandardMavenManager(context.Application.Path, b.configResolver, b.depResolver, b.depCache, context.Layers.Path),
NewWrapperMavenManager(context.Application.Path, b.configResolver, b.depResolver, b.depCache),
NewNoopMavenManager(),
NewDaemonMavenManager(b.configResolver, b.depResolver, b.depCache, context.Layers.Path, b.Logger),
NewStandardMavenManager(context.Application.Path, b.configResolver, b.depResolver, b.depCache, context.Layers.Path, b.Logger),
NewWrapperMavenManager(context.Application.Path, b.Logger),
NewNoopMavenManager(b.Logger),
}

for _, manager := range managers {
Expand Down
28 changes: 18 additions & 10 deletions maven/maven_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ type DaemonMavenManager struct {
logger bard.Logger
}

func NewDaemonMavenManager(configResolver libpak.ConfigurationResolver, depResolver libpak.DependencyResolver, depCache libpak.DependencyCache, layersPath string) DaemonMavenManager {
func NewDaemonMavenManager(configResolver libpak.ConfigurationResolver, depResolver libpak.DependencyResolver, depCache libpak.DependencyCache, layersPath string, logger bard.Logger) DaemonMavenManager {
return DaemonMavenManager{
configResolver: configResolver,
depResolver: depResolver,
depCache: depCache,
layersPath: layersPath,
logger: logger,
}
}

Expand Down Expand Up @@ -66,12 +67,14 @@ type StandardMavenManager struct {
logger bard.Logger
}

func NewStandardMavenManager(appPath string, configResolver libpak.ConfigurationResolver, depResolver libpak.DependencyResolver, depCache libpak.DependencyCache, layersPath string) StandardMavenManager {
func NewStandardMavenManager(appPath string, configResolver libpak.ConfigurationResolver, depResolver libpak.DependencyResolver, depCache libpak.DependencyCache, layersPath string, logger bard.Logger) StandardMavenManager {
return StandardMavenManager{
appPath: appPath,
depResolver: depResolver,
depCache: depCache,
layersPath: layersPath,
appPath: appPath,
configResolver: configResolver,
depResolver: depResolver,
depCache: depCache,
layersPath: layersPath,
logger: logger,
}
}

Expand All @@ -89,7 +92,9 @@ func (s StandardMavenManager) ShouldInstall() bool {

// Install the standard JVM-based Maven distribution
func (s StandardMavenManager) Install() (string, libcnb.LayerContributor, *libcnb.BOMEntry, error) {
dep, err := s.depResolver.Resolve("maven", "")
version, _ := s.configResolver.Resolve("BP_MAVEN_VERSION")

dep, err := s.depResolver.Resolve("maven", version)
if err != nil {
return "", nil, nil, fmt.Errorf("unable to find dependency\n%w", err)
}
Expand All @@ -108,9 +113,10 @@ type WrapperMavenManager struct {
logger bard.Logger
}

func NewWrapperMavenManager(appPath string, configResolver libpak.ConfigurationResolver, depResolver libpak.DependencyResolver, depCache libpak.DependencyCache) WrapperMavenManager {
func NewWrapperMavenManager(appPath string, logger bard.Logger) WrapperMavenManager {
return WrapperMavenManager{
appPath: appPath,
logger: logger,
}
}

Expand Down Expand Up @@ -163,8 +169,10 @@ type NoopMavenManager struct {
logger bard.Logger
}

func NewNoopMavenManager() NoopMavenManager {
return NoopMavenManager{}
func NewNoopMavenManager(logger bard.Logger) NoopMavenManager {
return NoopMavenManager{
logger: logger,
}
}

// ShouldInstall determines if Maven is on the $PATH
Expand Down
Loading

0 comments on commit aae8b22

Please sign in to comment.