diff --git a/.gitignore b/.gitignore index 6c65082..181fdc1 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,8 @@ build/ .gradle/ .settings/ .okhttpcache/ +.idea/ +*.iml src/test/integration/test/.git/ src/test/integration/test/build/ src/test/integration/test/.gradle/ diff --git a/README.md b/README.md index 2b967b7..f34395b 100644 --- a/README.md +++ b/README.md @@ -96,6 +96,8 @@ jgitver { useDistance true/false useGitCommitID true/false gitCommitIDLength integer + useMaxVersion true/false + maxVersionSearchDepth integer nonQualifierBranches string (comma separated list of branches) policy { repeatable closure pattern string (regexp with capturing group) @@ -113,6 +115,8 @@ If you do not provide such a configuration (or fill only partial configuration) - _useGitCommitTimestamp_: `false` - _useDistance_: `true` - _useGitCommitId_: `false` +- _userMaxVersion_: `false` +- _maxVersionSearchDepth_: 1000 - _nonQualifierBranches_: `'master'` - _regexVersionTag_: `'Java regexp pattern'` - if non set or null then [jgitver](https://github.com/jgitver/jgitver) default applies @@ -196,7 +200,7 @@ Since `0.4.1` it now possible to provide externally the branch information via a ````gradle buildscript { repositories { - mavenLocal() + mavenLocal() } dependencies { classpath "fr.brouillard.oss.gradle:gradle-jgitver-plugin:0.3.2" @@ -208,7 +212,7 @@ Since `0.4.1` it now possible to provide externally the branch information via a ````gradle buildscript { repositories { - mavenLocal() + mavenLocal() } dependencies { classpath "fr.brouillard.oss.gradle:gradle-jgitver-plugin:0.3.2" diff --git a/build.gradle b/build.gradle index b91758d..bc75dbb 100644 --- a/build.gradle +++ b/build.gradle @@ -11,7 +11,7 @@ buildscript { plugins { id "com.gradle.plugin-publish" version "0.9.7" - id "fr.brouillard.oss.gradle.jgitver" version "0.4.1" + id "fr.brouillard.oss.gradle.jgitver" version "0.5.0" } apply plugin: 'java' @@ -41,7 +41,7 @@ pluginBundle { dependencies { compile gradleApi() - compile "fr.brouillard.oss:jgitver:0.6.1" + compile "fr.brouillard.oss:jgitver:0.8.0" } task changelog(type: se.bjurr.gitchangelog.plugin.gradle.GitChangelogTask) { diff --git a/gradlew b/gradlew old mode 100644 new mode 100755 diff --git a/src/main/java/fr/brouillard/oss/gradle/plugins/JGitverPlugin.java b/src/main/java/fr/brouillard/oss/gradle/plugins/JGitverPlugin.java index 430f409..9d638c7 100644 --- a/src/main/java/fr/brouillard/oss/gradle/plugins/JGitverPlugin.java +++ b/src/main/java/fr/brouillard/oss/gradle/plugins/JGitverPlugin.java @@ -1,18 +1,15 @@ package fr.brouillard.oss.gradle.plugins; -import java.util.Arrays; -import java.util.List; -import java.util.Locale; -import java.util.stream.Collectors; - import fr.brouillard.oss.jgitver.BranchingPolicy; -import org.gradle.api.Action; +import fr.brouillard.oss.jgitver.GitVersionCalculator; +import fr.brouillard.oss.jgitver.metadata.Metadatas; import org.gradle.api.Plugin; import org.gradle.api.Project; import org.gradle.tooling.BuildException; -import fr.brouillard.oss.jgitver.GitVersionCalculator; -import fr.brouillard.oss.jgitver.metadata.Metadatas; +import java.util.List; +import java.util.Locale; +import java.util.stream.Collectors; public class JGitverPlugin implements Plugin { @Override @@ -20,55 +17,54 @@ public void apply(Project project) { project.getExtensions().create("jgitver", JGitverPluginExtension.class, project); project.getTasks().create("version", JGitverVersionTask.class); - project.afterEvaluate(new Action() { - @Override - public void execute(Project evaluatedProject) { - JGitverPluginExtension jgitverConfiguration = project.getExtensions().findByType(JGitverPluginExtension.class); + project.afterEvaluate(evaluatedProject -> { + JGitverPluginExtension jgitverConfiguration = project.getExtensions().findByType(JGitverPluginExtension.class); - GitVersionCalculator versionCalculator = GitVersionCalculator.location(project.getRootDir()) - .setMavenLike(jgitverConfiguration.mavenLike) - .setAutoIncrementPatch(jgitverConfiguration.autoIncrementPatch) - .setUseDistance(jgitverConfiguration.useDistance) - .setUseDirty(jgitverConfiguration.useDirty) - .setUseGitCommitTimestamp(jgitverConfiguration.useGitCommitTimestamp) - .setUseGitCommitId(jgitverConfiguration.useGitCommitID) - .setGitCommitIdLength(jgitverConfiguration.gitCommitIDLength) - .setNonQualifierBranches(jgitverConfiguration.nonQualifierBranches); + GitVersionCalculator versionCalculator = GitVersionCalculator.location(project.getRootDir()) + .setMavenLike(jgitverConfiguration.mavenLike) + .setAutoIncrementPatch(jgitverConfiguration.autoIncrementPatch) + .setUseDistance(jgitverConfiguration.useDistance) + .setUseDirty(jgitverConfiguration.useDirty) + .setUseGitCommitTimestamp(jgitverConfiguration.useGitCommitTimestamp) + .setUseGitCommitId(jgitverConfiguration.useGitCommitID) + .setGitCommitIdLength(jgitverConfiguration.gitCommitIDLength) + .setUseMaxVersion(jgitverConfiguration.useMaxVersion) + .setMaxVersionSearchDepth(jgitverConfiguration.maxVersionSearchDepth) + .setNonQualifierBranches(jgitverConfiguration.nonQualifierBranches); - if (!jgitverConfiguration.policies.isEmpty()) { - List branchingPolicies = jgitverConfiguration.policies.stream() - .map(JGitverPlugin::toBranchingPolicy) - .collect(Collectors.toList()); - versionCalculator.setQualifierBranchingPolicies(branchingPolicies); - } + if (!jgitverConfiguration.policies.isEmpty()) { + List branchingPolicies = jgitverConfiguration.policies.stream() + .map(JGitverPlugin::toBranchingPolicy) + .collect(Collectors.toList()); + versionCalculator.setQualifierBranchingPolicies(branchingPolicies); + } - if (jgitverConfiguration.regexVersionTag != null) { - versionCalculator = versionCalculator.setFindTagVersionPattern(jgitverConfiguration.regexVersionTag); - } + if (jgitverConfiguration.regexVersionTag != null) { + versionCalculator = versionCalculator.setFindTagVersionPattern(jgitverConfiguration.regexVersionTag); + } - String gitCalculatedVersion = versionCalculator.getVersion(); + String gitCalculatedVersion = versionCalculator.getVersion(); - boolean isDirty = versionCalculator - .meta(Metadatas.DIRTY) - .map(Boolean::parseBoolean) - .orElse(Boolean.FALSE); - - if (jgitverConfiguration.useDirty && jgitverConfiguration.failIfDirty && isDirty) { - IllegalStateException cause = new IllegalStateException("jgitver detected a dirty state, project is configured to fail"); - throw new BuildException("jgitver stopped the build for a git dirty state", cause); - } - - project.setVersion(gitCalculatedVersion); - project.getAllprojects().forEach(subproject -> subproject.setVersion(gitCalculatedVersion)); + boolean isDirty = versionCalculator + .meta(Metadatas.DIRTY) + .map(Boolean::parseBoolean) + .orElse(Boolean.FALSE); - for (Metadatas metadata: Metadatas.values()) { - versionCalculator.meta(metadata).ifPresent(metadataValue -> { - project.getExtensions().getExtraProperties().set(metadata.name().toLowerCase(Locale.ENGLISH), metadataValue); - project.getAllprojects().forEach( - subproject -> subproject.getExtensions().getExtraProperties().set(metadata.name().toLowerCase(Locale.ENGLISH), metadataValue)); - }); - }; + if (jgitverConfiguration.useDirty && jgitverConfiguration.failIfDirty && isDirty) { + IllegalStateException cause = new IllegalStateException("jgitver detected a dirty state, project is configured to fail"); + throw new BuildException("jgitver stopped the build for a git dirty state", cause); } + + project.setVersion(gitCalculatedVersion); + project.getAllprojects().forEach(subproject -> subproject.setVersion(gitCalculatedVersion)); + + for (Metadatas metadata: Metadatas.values()) { + versionCalculator.meta(metadata).ifPresent(metadataValue -> { + project.getExtensions().getExtraProperties().set(metadata.name().toLowerCase(Locale.ENGLISH), metadataValue); + project.getAllprojects().forEach( + subproject -> subproject.getExtensions().getExtraProperties().set(metadata.name().toLowerCase(Locale.ENGLISH), metadataValue)); + }); + }; }); } diff --git a/src/main/java/fr/brouillard/oss/gradle/plugins/JGitverPluginExtension.java b/src/main/java/fr/brouillard/oss/gradle/plugins/JGitverPluginExtension.java index 2422f0d..d9402b7 100644 --- a/src/main/java/fr/brouillard/oss/gradle/plugins/JGitverPluginExtension.java +++ b/src/main/java/fr/brouillard/oss/gradle/plugins/JGitverPluginExtension.java @@ -1,7 +1,6 @@ package fr.brouillard.oss.gradle.plugins; import groovy.lang.Closure; -import org.gradle.api.NamedDomainObjectContainer; import org.gradle.api.Project; import javax.inject.Inject; @@ -17,9 +16,12 @@ public class JGitverPluginExtension { public Boolean useGitCommitTimestamp = Boolean.FALSE; public Boolean useGitCommitID = Boolean.FALSE; public int gitCommitIDLength = 8; + public Boolean useMaxVersion = Boolean.FALSE; + public int maxVersionSearchDepth = 1000; public String nonQualifierBranches = "master"; public String regexVersionTag = null; public List policies; + private Project project; @Inject @@ -39,7 +41,7 @@ public void autoIncrementPatch(boolean autoIncrementPatch) { public void useDistance(boolean useDistance) { this.useDistance = useDistance; } - + public void useDirty(boolean useDirty) { this.useDirty = useDirty; } @@ -64,6 +66,14 @@ public void gitCommitIDLength(int gitCommitIDLength) { this.gitCommitIDLength = gitCommitIDLength; } + public void useMaxVersion(Boolean useMaxVersion) { + this.useMaxVersion = useMaxVersion; + } + + public void maxVersionSearchDepth(int maxVersionSearchDepth) { + this.maxVersionSearchDepth = maxVersionSearchDepth; + } + public void nonQualifierBranches(String nonQualifierBranches) { this.nonQualifierBranches = nonQualifierBranches; }