From 59e9c28f0221b9d235793a78a8d1e7152c4dd748 Mon Sep 17 00:00:00 2001 From: Dawid Jarosz Date: Thu, 1 Nov 2018 14:31:52 +0100 Subject: [PATCH 1/2] Support for 'useMaxVersion' jgitver paramter --- .gitignore | 2 + README.md | 2 + build.gradle | 4 +- gradlew | 0 .../oss/gradle/plugins/JGitverPlugin.java | 92 +++++++++---------- .../plugins/JGitverPluginExtension.java | 11 ++- 6 files changed, 56 insertions(+), 55 deletions(-) mode change 100644 => 100755 gradlew 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..1045abc 100644 --- a/README.md +++ b/README.md @@ -96,6 +96,7 @@ jgitver { useDistance true/false useGitCommitID true/false gitCommitIDLength integer + useMaxVersion true/false nonQualifierBranches string (comma separated list of branches) policy { repeatable closure pattern string (regexp with capturing group) @@ -113,6 +114,7 @@ If you do not provide such a configuration (or fill only partial configuration) - _useGitCommitTimestamp_: `false` - _useDistance_: `true` - _useGitCommitId_: `false` +- _userMaxVersion_: `false` - _nonQualifierBranches_: `'master'` - _regexVersionTag_: `'Java regexp pattern'` - if non set or null then [jgitver](https://github.com/jgitver/jgitver) default applies 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..96b2aed 100644 --- a/src/main/java/fr/brouillard/oss/gradle/plugins/JGitverPlugin.java +++ b/src/main/java/fr/brouillard/oss/gradle/plugins/JGitverPlugin.java @@ -1,74 +1,68 @@ package fr.brouillard.oss.gradle.plugins; -import java.util.Arrays; +import fr.brouillard.oss.jgitver.BranchingPolicy; +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; - -import fr.brouillard.oss.jgitver.BranchingPolicy; -import org.gradle.api.Action; 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; - public class JGitverPlugin implements Plugin { @Override 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) + .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..87a5d67 100644 --- a/src/main/java/fr/brouillard/oss/gradle/plugins/JGitverPluginExtension.java +++ b/src/main/java/fr/brouillard/oss/gradle/plugins/JGitverPluginExtension.java @@ -1,12 +1,10 @@ package fr.brouillard.oss.gradle.plugins; import groovy.lang.Closure; -import org.gradle.api.NamedDomainObjectContainer; -import org.gradle.api.Project; - -import javax.inject.Inject; import java.util.ArrayList; import java.util.List; +import javax.inject.Inject; +import org.gradle.api.Project; public class JGitverPluginExtension { public Boolean mavenLike = Boolean.FALSE; @@ -17,6 +15,7 @@ public class JGitverPluginExtension { public Boolean useGitCommitTimestamp = Boolean.FALSE; public Boolean useGitCommitID = Boolean.FALSE; public int gitCommitIDLength = 8; + public Boolean useMaxVersion = Boolean.FALSE; public String nonQualifierBranches = "master"; public String regexVersionTag = null; public List policies; @@ -64,6 +63,10 @@ public void gitCommitIDLength(int gitCommitIDLength) { this.gitCommitIDLength = gitCommitIDLength; } + public void useMaxVersion(Boolean useMaxVersion) { + this.useMaxVersion = useMaxVersion; + } + public void nonQualifierBranches(String nonQualifierBranches) { this.nonQualifierBranches = nonQualifierBranches; } From 5ed0fe091a7f2009c01fed9801a2d1caf773e746 Mon Sep 17 00:00:00 2001 From: Dawid Jarosz Date: Thu, 1 Nov 2018 15:50:55 +0100 Subject: [PATCH 2/2] Support for 'maxVersionSearchDepth' jgitver paramter --- README.md | 6 ++++-- .../oss/gradle/plugins/JGitverPlugin.java | 8 +++++--- .../oss/gradle/plugins/JGitverPluginExtension.java | 13 ++++++++++--- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 1045abc..f34395b 100644 --- a/README.md +++ b/README.md @@ -97,6 +97,7 @@ jgitver { 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) @@ -115,6 +116,7 @@ If you do not provide such a configuration (or fill only partial configuration) - _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 @@ -198,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" @@ -210,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/src/main/java/fr/brouillard/oss/gradle/plugins/JGitverPlugin.java b/src/main/java/fr/brouillard/oss/gradle/plugins/JGitverPlugin.java index 96b2aed..9d638c7 100644 --- a/src/main/java/fr/brouillard/oss/gradle/plugins/JGitverPlugin.java +++ b/src/main/java/fr/brouillard/oss/gradle/plugins/JGitverPlugin.java @@ -3,13 +3,14 @@ import fr.brouillard.oss.jgitver.BranchingPolicy; 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; import org.gradle.api.Plugin; import org.gradle.api.Project; import org.gradle.tooling.BuildException; +import java.util.List; +import java.util.Locale; +import java.util.stream.Collectors; + public class JGitverPlugin implements Plugin { @Override public void apply(Project project) { @@ -28,6 +29,7 @@ public void apply(Project project) { .setUseGitCommitId(jgitverConfiguration.useGitCommitID) .setGitCommitIdLength(jgitverConfiguration.gitCommitIDLength) .setUseMaxVersion(jgitverConfiguration.useMaxVersion) + .setMaxVersionSearchDepth(jgitverConfiguration.maxVersionSearchDepth) .setNonQualifierBranches(jgitverConfiguration.nonQualifierBranches); if (!jgitverConfiguration.policies.isEmpty()) { 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 87a5d67..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,10 +1,11 @@ package fr.brouillard.oss.gradle.plugins; import groovy.lang.Closure; +import org.gradle.api.Project; + +import javax.inject.Inject; import java.util.ArrayList; import java.util.List; -import javax.inject.Inject; -import org.gradle.api.Project; public class JGitverPluginExtension { public Boolean mavenLike = Boolean.FALSE; @@ -16,9 +17,11 @@ public class JGitverPluginExtension { 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 @@ -38,7 +41,7 @@ public void autoIncrementPatch(boolean autoIncrementPatch) { public void useDistance(boolean useDistance) { this.useDistance = useDistance; } - + public void useDirty(boolean useDirty) { this.useDirty = useDirty; } @@ -67,6 +70,10 @@ public void useMaxVersion(Boolean useMaxVersion) { this.useMaxVersion = useMaxVersion; } + public void maxVersionSearchDepth(int maxVersionSearchDepth) { + this.maxVersionSearchDepth = maxVersionSearchDepth; + } + public void nonQualifierBranches(String nonQualifierBranches) { this.nonQualifierBranches = nonQualifierBranches; }