Skip to content

Commit

Permalink
feat(core): Add asdf packager to Gradle model. Relates to #825
Browse files Browse the repository at this point in the history
  • Loading branch information
aalmiray committed Jul 28, 2022
1 parent f4a3523 commit 6f890a4
Show file tree
Hide file tree
Showing 6 changed files with 169 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2020-2022 The JReleaser authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jreleaser.gradle.plugin.dsl

import groovy.transform.CompileStatic
import org.gradle.api.Action
import org.gradle.api.provider.Property

/**
*
* @author Andres Almiray
* @since 1.2.0
*/
@CompileStatic
interface Asdf extends RepositoryPackager {
Property<String> getToolCheck()

Tap getRepository()

void repository(Action<? super Tap> action)

void repository(@DelegatesTo(strategy = Closure.DELEGATE_FIRST, value = Tap) Closure<Void> action)
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import org.gradle.api.Action
*/
@CompileStatic
interface Packagers {
Asdf getAsdf()

Brew getBrew()

Chocolatey getChocolatey()
Expand All @@ -47,6 +49,8 @@ interface Packagers {

Spec getSpec()

void asdf(Action<? super Asdf> action)

void brew(Action<? super Brew> action)

void chocolatey(Action<? super Chocolatey> action)
Expand All @@ -67,6 +71,8 @@ interface Packagers {

void spec(Action<? super Spec> action)

void asdf(@DelegatesTo(strategy = Closure.DELEGATE_FIRST, value = Asdf) Closure<Void> action)

void brew(@DelegatesTo(strategy = Closure.DELEGATE_FIRST, value = Brew) Closure<Void> action)

void chocolatey(@DelegatesTo(strategy = Closure.DELEGATE_FIRST, value = Chocolatey) Closure<Void> action)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2020-2022 The JReleaser authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jreleaser.gradle.plugin.internal.dsl

import groovy.transform.CompileStatic
import org.gradle.api.Action
import org.gradle.api.internal.provider.Providers
import org.gradle.api.model.ObjectFactory
import org.gradle.api.provider.Property
import org.gradle.api.tasks.Internal
import org.jreleaser.gradle.plugin.dsl.CommitAuthor
import org.jreleaser.gradle.plugin.dsl.Asdf
import org.jreleaser.gradle.plugin.dsl.Tap
import org.kordamp.gradle.util.ConfigureUtil

import javax.inject.Inject

/**
*
* @author Andres Almiray
* @since 1.2.0
*/
@CompileStatic
class AsdfImpl extends AbstractRepositoryPackager implements Asdf {
final CommitAuthorImpl commitAuthor
final TapImpl repository
final Property<String> toolCheck

@Inject
AsdfImpl(ObjectFactory objects) {
super(objects)
repository = objects.newInstance(TapImpl, objects)
commitAuthor = objects.newInstance(CommitAuthorImpl, objects)
toolCheck = objects.property(String).convention(Providers.notDefined())
}

@Override
@Internal
boolean isSet() {
super.isSet() ||
commitAuthor.isSet() ||
repository.isSet() ||
toolCheck.present
}

@Override
void repository(Action<? super Tap> action) {
action.execute(repository)
}

@Override
void commitAuthor(Action<? super CommitAuthor> action) {
action.execute(commitAuthor)
}

@Override
void repository(@DelegatesTo(strategy = Closure.DELEGATE_FIRST, value = Tap) Closure<Void> action) {
ConfigureUtil.configure(action, repository)
}

@Override
void commitAuthor(@DelegatesTo(strategy = Closure.DELEGATE_FIRST, value = CommitAuthor) Closure<Void> action) {
ConfigureUtil.configure(action, commitAuthor)
}

org.jreleaser.model.Asdf toModel() {
org.jreleaser.model.Asdf packager = new org.jreleaser.model.Asdf()
fillPackagerProperties(packager)
fillTemplatePackagerProperties(packager)
if (repository.isSet()) packager.repository = repository.toAsdfRepository()
if (commitAuthor.isSet()) packager.commitAuthor = commitAuthor.toModel()
if (toolCheck.present) packager.toolCheck = toolCheck.get()
packager
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import org.gradle.api.provider.MapProperty
import org.gradle.api.provider.Property
import org.gradle.api.tasks.Internal
import org.jreleaser.gradle.plugin.dsl.Artifact
import org.jreleaser.gradle.plugin.dsl.Asdf
import org.jreleaser.gradle.plugin.dsl.Brew
import org.jreleaser.gradle.plugin.dsl.Chocolatey
import org.jreleaser.gradle.plugin.dsl.Distribution
Expand Down Expand Up @@ -66,6 +67,7 @@ class DistributionImpl implements Distribution {
final ExecutableImpl executable
final JavaImpl java
final PlatformImpl platform
final AsdfImpl asdf
final BrewImpl brew
final ChocolateyImpl chocolatey
final DockerImpl docker
Expand Down Expand Up @@ -100,6 +102,7 @@ class DistributionImpl implements Distribution {
executable = objects.newInstance(ExecutableImpl, objects)
java = objects.newInstance(JavaImpl, objects)
platform = objects.newInstance(PlatformImpl, objects)
asdf = objects.newInstance(AsdfImpl, objects)
brew = objects.newInstance(BrewImpl, objects)
chocolatey = objects.newInstance(ChocolateyImpl, objects)
docker = objects.newInstance(DockerImpl, objects)
Expand Down Expand Up @@ -146,6 +149,11 @@ class DistributionImpl implements Distribution {
action.execute(executable)
}

@Override
void asdf(Action<? super Asdf> action) {
action.execute(asdf)
}

@Override
void brew(Action<? super Brew> action) {
action.execute(brew)
Expand Down Expand Up @@ -223,6 +231,11 @@ class DistributionImpl implements Distribution {
ConfigureUtil.configure(action, executable)
}

@Override
void asdf(@DelegatesTo(strategy = Closure.DELEGATE_FIRST, value = Asdf) Closure<Void> action) {
ConfigureUtil.configure(action, asdf)
}

@Override
void brew(@DelegatesTo(strategy = Closure.DELEGATE_FIRST, value = Brew) Closure<Void> action) {
ConfigureUtil.configure(action, brew)
Expand Down Expand Up @@ -286,6 +299,7 @@ class DistributionImpl implements Distribution {
}
distribution.tags = (List<String>) tags.getOrElse([])
if (extraProperties.present) distribution.extraProperties.putAll(extraProperties.get())
if (asdf.isSet()) distribution.asdf = asdf.toModel()
if (brew.isSet()) distribution.brew = brew.toModel()
if (chocolatey.isSet()) distribution.chocolatey = chocolatey.toModel()
if (docker.isSet()) distribution.docker = docker.toModel()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package org.jreleaser.gradle.plugin.internal.dsl
import groovy.transform.CompileStatic
import org.gradle.api.Action
import org.gradle.api.model.ObjectFactory
import org.jreleaser.gradle.plugin.dsl.Asdf
import org.jreleaser.gradle.plugin.dsl.Brew
import org.jreleaser.gradle.plugin.dsl.Chocolatey
import org.jreleaser.gradle.plugin.dsl.Docker
Expand All @@ -42,6 +43,7 @@ import javax.inject.Inject
*/
@CompileStatic
class PackagersImpl implements Packagers {
final AsdfImpl asdf
final BrewImpl brew
final ChocolateyImpl chocolatey
final DockerImpl docker
Expand All @@ -55,6 +57,7 @@ class PackagersImpl implements Packagers {

@Inject
PackagersImpl(ObjectFactory objects) {
asdf = objects.newInstance(AsdfImpl, objects)
brew = objects.newInstance(BrewImpl, objects)
chocolatey = objects.newInstance(ChocolateyImpl, objects)
docker = objects.newInstance(DockerImpl, objects)
Expand All @@ -67,6 +70,11 @@ class PackagersImpl implements Packagers {
spec = objects.newInstance(SpecImpl, objects)
}

@Override
void asdf(Action<? super Asdf> action) {
action.execute(asdf)
}

@Override
void brew(Action<? super Brew> action) {
action.execute(brew)
Expand Down Expand Up @@ -117,6 +125,11 @@ class PackagersImpl implements Packagers {
action.execute(spec)
}

@Override
void asdf(@DelegatesTo(strategy = Closure.DELEGATE_FIRST, value = Asdf) Closure<Void> action) {
ConfigureUtil.configure(action, asdf)
}

@Override
void brew(@DelegatesTo(strategy = Closure.DELEGATE_FIRST, value = Brew) Closure<Void> action) {
ConfigureUtil.configure(action, brew)
Expand Down Expand Up @@ -169,6 +182,7 @@ class PackagersImpl implements Packagers {

org.jreleaser.model.Packagers toModel() {
org.jreleaser.model.Packagers packagers = new org.jreleaser.model.Packagers()
if (asdf.isSet()) packagers.asdf = asdf.toModel()
if (brew.isSet()) packagers.brew = brew.toModel()
if (chocolatey.isSet()) packagers.chocolatey = chocolatey.toModel()
if (docker.isSet()) packagers.docker = docker.toModel()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import org.gradle.api.provider.Property
import org.gradle.api.tasks.Internal
import org.jreleaser.gradle.plugin.dsl.Tap
import org.jreleaser.model.Active
import org.jreleaser.model.Asdf
import org.jreleaser.model.Brew
import org.jreleaser.model.Chocolatey
import org.jreleaser.model.Gofish
Expand Down Expand Up @@ -97,6 +98,12 @@ class TapImpl implements Tap {
if (commitMessage.present) into.commitMessage = commitMessage.get()
}

Asdf.AsdfRepository toAsdfRepository() {
Asdf.AsdfRepository tap = new Asdf.AsdfRepository()
convert(tap)
tap
}

Brew.HomebrewTap toHomebrewTap() {
Brew.HomebrewTap tap = new Brew.HomebrewTap()
convert(tap)
Expand Down

0 comments on commit 6f890a4

Please sign in to comment.