All Downloads are FREE. Search and download functionalities are using the official Maven repository.

pl.allegro.tech.build.axion.release.domain.PredefinedVersionCreator.groovy Maven / Gradle / Ivy

There is a newer version: 1.18.15
Show newest version
package pl.allegro.tech.build.axion.release.domain

import pl.allegro.tech.build.axion.release.domain.scm.ScmPosition

enum PredefinedVersionCreator {

    SIMPLE('simple', { String versionFromTag, ScmPosition position ->
        return versionFromTag.toString()
    }),

    VERSION_WITH_BRANCH('versionWithBranch', { String versionFromTag, ScmPosition position ->
        if (position.branch != 'master' && position.branch != 'HEAD') {
            return "$versionFromTag-$position.branch".toString()
        }
        return versionFromTag
    })

    private final String type

    final Closure versionCreator

    private PredefinedVersionCreator(String type, Closure c) {
        this.type = type
        this.versionCreator = c
    }

    static Closure versionCreatorFor(String type) {
        PredefinedVersionCreator creator = values().find { it.type == type }
        if (creator == null) {
            throw new IllegalArgumentException("There is no predefined version creator with $type type. " +
                    "You can choose from: ${values().collect { it.type }}");
        }
        return creator.versionCreator
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy