diff --git a/src/main/groovy/org/ajoberstar/gradle/git/release/base/DefaultVersionStrategy.groovy b/src/main/groovy/org/ajoberstar/gradle/git/release/base/DefaultVersionStrategy.groovy new file mode 100644 index 0000000..a8f6a59 --- /dev/null +++ b/src/main/groovy/org/ajoberstar/gradle/git/release/base/DefaultVersionStrategy.groovy @@ -0,0 +1,39 @@ +/* + * Copyright 2012-2015 the original author or 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 + * + * http://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.ajoberstar.gradle.git.release.base + +import org.ajoberstar.grgit.Grgit + +import org.gradle.api.Project + +/** + * Strategy to infer a version from the project's and Git repository's state. This + * also supports being selected as a default strategy. This is a temporary interface + * and should be replaced in some other way in gradle-git 2.0.0. + * @see org.ajoberstar.gradle.git.release.semver.SemVerStrategy + * @see org.ajoberstar.gradle.git.release.opinion.Strategies + */ +interface DefaultVersionStrategy extends VersionStrategy { + /** + * Determines if the strategy can be used as a default strategy for inferring + * the project's version. A return of {@code false} does not mean that the + * strategy cannot be used as the default. + * @param project the project the version should be inferred for + * @param grgit the repository the version should be inferred from + * @return {@code true} if the strategy can be used to infer the version + */ + boolean defaultSelector(Project project, Grgit grgit) +} diff --git a/src/main/groovy/org/ajoberstar/gradle/git/release/base/ReleasePluginExtension.groovy b/src/main/groovy/org/ajoberstar/gradle/git/release/base/ReleasePluginExtension.groovy index 135878d..23084c9 100644 --- a/src/main/groovy/org/ajoberstar/gradle/git/release/base/ReleasePluginExtension.groovy +++ b/src/main/groovy/org/ajoberstar/gradle/git/release/base/ReleasePluginExtension.groovy @@ -17,6 +17,7 @@ package org.ajoberstar.gradle.git.release.base import org.ajoberstar.gradle.git.release.base.ReleaseVersion import org.ajoberstar.gradle.git.release.base.TagStrategy +import org.ajoberstar.gradle.git.release.base.DefaultVersionStrategy import org.ajoberstar.gradle.git.release.base.VersionStrategy import org.ajoberstar.grgit.Grgit import org.ajoberstar.grgit.util.ConfigureUtil @@ -53,11 +54,7 @@ class ReleasePluginExtension { * The strategy to use if all of the ones in {@code versionStrategies} return * false from their {@code selector()} methods. This strategy can be, but is * not required to be, one from {@code versionStrategies}. - * - * This is deprecated as of 1.5.0, as version strategies that return false often - * will fail when their {@code infer()} method is called. */ - @Deprecated VersionStrategy defaultVersionStrategy /** @@ -110,9 +107,15 @@ class ReleasePluginExtension { } if (!selectedStrategy) { - if (defaultVersionStrategy?.selector(project, grgit)) { + boolean useDefault + if (defaultVersionStrategy instanceof DefaultVersionStrategy) { + useDefault = defaultVersionStrategy.defaultSelector(project, grgit) + } else { + useDefault = defaultVersionStrategy?.selector(project, grgit) + } + + if (useDefault) { logger.info('Falling back to default strategy: {}', defaultVersionStrategy.name) - logger.warn('Use of a default version strategy is deprecated and will be removed in gradle-git 2.0.0') selectedStrategy = defaultVersionStrategy } else { throw new GradleException('No version strategies were selected. Run build with --info for more detail.') diff --git a/src/main/groovy/org/ajoberstar/gradle/git/release/semver/SemVerStrategy.groovy b/src/main/groovy/org/ajoberstar/gradle/git/release/semver/SemVerStrategy.groovy index a5e4c29..35feaa6 100644 --- a/src/main/groovy/org/ajoberstar/gradle/git/release/semver/SemVerStrategy.groovy +++ b/src/main/groovy/org/ajoberstar/gradle/git/release/semver/SemVerStrategy.groovy @@ -21,6 +21,7 @@ import groovy.transform.PackageScope import com.github.zafarkhaja.semver.Version import org.ajoberstar.gradle.git.release.base.ReleasePluginExtension import org.ajoberstar.gradle.git.release.base.ReleaseVersion +import org.ajoberstar.gradle.git.release.base.DefaultVersionStrategy import org.ajoberstar.gradle.git.release.base.VersionStrategy import org.ajoberstar.grgit.Grgit @@ -37,7 +38,7 @@ import org.slf4j.LoggerFactory * @see Wiki Doc */ @Immutable(copyWith=true, knownImmutableClasses=[PartialSemVerStrategy]) -final class SemVerStrategy implements VersionStrategy { +final class SemVerStrategy implements DefaultVersionStrategy { private static final Logger logger = LoggerFactory.getLogger(SemVerStrategy) static final String SCOPE_PROP = 'release.scope' static final String STAGE_PROP = 'release.stage' @@ -86,6 +87,28 @@ final class SemVerStrategy implements VersionStrategy { */ boolean enforcePrecedence + /** + * Determines whether this strategy can be used to infer the version as a default. + *