From 35adebc505f41a722f7902659fdfcad03a7533e4 Mon Sep 17 00:00:00 2001 From: Glade Diviney Date: Fri, 30 Oct 2020 10:30:27 -0700 Subject: [PATCH] fix #87: handle failure to find repo with warning message --- HISTORY.md | 8 ++++++-- README.md | 2 +- .../com/gladed/androidgitversion/AndroidGitVersion.groovy | 7 +++++-- .../gladed/androidgitversion/AndroidGitVersionTest.groovy | 2 +- .../groovy/com/gladed/androidgitversion/MainTest.groovy | 6 +++--- 5 files changed, 16 insertions(+), 9 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 32cae83..c7c78b3 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,9 +1,13 @@ # Changes +## 0.4.14 + +* Print warning message if git repo not found (#87). + ## 0.4.13 -* Support `%describe%` for git-describe results +* Support `%describe%` for git-describe results. ## 0.4.11 -* Support `commitHashLength` +* Support `commitHashLength`. diff --git a/README.md b/README.md index df7e619..6a6a4b2 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Add `plugins` block to the top of your `app/build.gradle` (or equivalent): ```groovy plugins { - id 'com.gladed.androidgitversion' version '0.4.13' + id 'com.gladed.androidgitversion' version '0.4.14' } ``` diff --git a/src/main/groovy/com/gladed/androidgitversion/AndroidGitVersion.groovy b/src/main/groovy/com/gladed/androidgitversion/AndroidGitVersion.groovy index 26cf128..5c3dc2d 100644 --- a/src/main/groovy/com/gladed/androidgitversion/AndroidGitVersion.groovy +++ b/src/main/groovy/com/gladed/androidgitversion/AndroidGitVersion.groovy @@ -4,6 +4,7 @@ import org.eclipse.jgit.api.Git import org.eclipse.jgit.diff.DiffEntry import org.eclipse.jgit.diff.DiffFormatter import org.eclipse.jgit.diff.RawTextComparator +import org.eclipse.jgit.errors.RepositoryNotFoundException import org.eclipse.jgit.lib.Constants import org.eclipse.jgit.lib.ObjectId import org.eclipse.jgit.lib.Repository @@ -17,6 +18,7 @@ import org.eclipse.jgit.util.io.DisabledOutputStream import org.gradle.api.GradleException import org.gradle.api.Plugin import org.gradle.api.Project +import org.slf4j.LoggerFactory class AndroidGitVersion implements Plugin { void apply(Project project) { @@ -200,8 +202,9 @@ class AndroidGitVersionExtension { .readEnvironment() .findGitDir(project.projectDir) .build() - } catch (IllegalArgumentException ignore) { - // No repo found + } catch (IllegalArgumentException | RepositoryNotFoundException ignore) { + def logger = LoggerFactory.getLogger("androidGitVersion") + logger.warn("No git repository reachable from ${project.projectDir}") return results } diff --git a/src/test/groovy/com/gladed/androidgitversion/AndroidGitVersionTest.groovy b/src/test/groovy/com/gladed/androidgitversion/AndroidGitVersionTest.groovy index 85bf85c..b8b755b 100644 --- a/src/test/groovy/com/gladed/androidgitversion/AndroidGitVersionTest.groovy +++ b/src/test/groovy/com/gladed/androidgitversion/AndroidGitVersionTest.groovy @@ -26,7 +26,7 @@ abstract class AndroidGitVersionTest extends GroovyTestCase { }() Git git = { - return Git.init().setDirectory(projectFolder.root).call(); + return Git.init().setDirectory(projectFolder.root).call() }() @Lazy diff --git a/src/test/groovy/com/gladed/androidgitversion/MainTest.groovy b/src/test/groovy/com/gladed/androidgitversion/MainTest.groovy index 0f8d5f1..47422e4 100644 --- a/src/test/groovy/com/gladed/androidgitversion/MainTest.groovy +++ b/src/test/groovy/com/gladed/androidgitversion/MainTest.groovy @@ -102,7 +102,6 @@ class MainTest extends AndroidGitVersionTest { assertEquals(1056555, plugin.code()) } - void testSubmodule() { // Set up a base repo addCommit() @@ -121,17 +120,18 @@ class MainTest extends AndroidGitVersionTest { libraryGit.tag().setName("2.0").call() // Add the library repo to the base repo as a submodule - Repository libraryRepo = git.submoduleAdd() + git.submoduleAdd() .setPath("library") .setURI(libraryGit.getRepository().getDirectory().getCanonicalPath()) .call() - libraryRepo.close() + .close() // Add the submodule as a subproject to the base project Project libraryProject = ProjectBuilder.builder() .withProjectDir(new File(projectFolder.root, "library")) .withParent(project) .build() + libraryProject.pluginManager.apply 'com.gladed.androidgitversion' AndroidGitVersionExtension libraryPlugin = (AndroidGitVersionExtension) libraryProject.getExtensions().getByName('androidGitVersion')