diff --git a/CHANGELOG.md b/CHANGELOG.md index 90acc62..3c9dacd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## Version 0.2.1 +_2018-11-02_ +* Fix: Address regression in file filter matching + ## Version 0.2.0 _2018-11-02_ * New: Added doc generation for configuration api diff --git a/README.md b/README.md index cef8e60..20076b8 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ [ ![JCenter](https://api.bintray.com/packages/marcoferrer/kroto-plus/protoc-gen-kroto-plus/images/download.svg) ](https://bintray.com/marcoferrer/kroto-plus/protoc-gen-kroto-plus/_latestVersion) [![Maven Central](https://img.shields.io/maven-central/v/com.github.marcoferrer.krotoplus/protoc-gen-kroto-plus.svg?label=Maven%20Central)](http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22com.github.marcoferrer.krotoplus%22%20a%3A%22protoc-gen-kroto-plus%22) -## Version 0.2.0 +## Version 0.2.1 * [CHANGELOG](https://github.com/marcoferrer/kroto-plus/blob/master/CHANGELOG.md) * Most notable changes * Update to Kotlin 1.3.0 diff --git a/build.gradle b/build.gradle index 8a996b8..a39608a 100644 --- a/build.gradle +++ b/build.gradle @@ -44,7 +44,7 @@ subprojects{ subproject -> apply plugin: 'kotlin' group = 'com.github.marcoferrer.krotoplus' - version = '0.2.0' + version = '0.2.1' compileKotlin { kotlinOptions.jvmTarget = "1.8" diff --git a/community-scripts/extendable-messages/build.gradle b/community-scripts/extendable-messages/build.gradle index 9348c6a..8947369 100644 --- a/community-scripts/extendable-messages/build.gradle +++ b/community-scripts/extendable-messages/build.gradle @@ -1,4 +1,4 @@ -def krotoPlusVersion = '0.2.0' +def krotoPlusVersion = '0.2.1' plugins { id "org.jetbrains.kotlin.jvm" version "1.3.0" diff --git a/community-scripts/var-arg-extensions/build.gradle b/community-scripts/var-arg-extensions/build.gradle index 67c2661..0298b22 100644 --- a/community-scripts/var-arg-extensions/build.gradle +++ b/community-scripts/var-arg-extensions/build.gradle @@ -1,4 +1,4 @@ -def krotoPlusVersion = '0.2.0' +def krotoPlusVersion = '0.2.1' plugins { id "org.jetbrains.kotlin.jvm" version "1.3.0" diff --git a/example-project/build.gradle b/example-project/build.gradle index d4040b8..9158f29 100644 --- a/example-project/build.gradle +++ b/example-project/build.gradle @@ -5,7 +5,7 @@ buildscript { "grpc": '1.15.1', "kotlin": '1.3.0', "coroutines": '1.0.0', - "krotoplus": '0.2.0' + "krotoplus": '0.2.1' ] } diff --git a/protoc-gen-kroto-plus/src/main/kotlin/com/github/marcoferrer/krotoplus/utils/FileFilterExts.kt b/protoc-gen-kroto-plus/src/main/kotlin/com/github/marcoferrer/krotoplus/utils/FileFilterExts.kt index cbab64f..0646307 100644 --- a/protoc-gen-kroto-plus/src/main/kotlin/com/github/marcoferrer/krotoplus/utils/FileFilterExts.kt +++ b/protoc-gen-kroto-plus/src/main/kotlin/com/github/marcoferrer/krotoplus/utils/FileFilterExts.kt @@ -6,8 +6,11 @@ data class RegexFilter(val include: List, val exclude: List) { fun isEmpty() = include.isEmpty() && exclude.isEmpty() - fun matches(value: String) = - isEmpty() || (include.any { it.matches(value) } || exclude.all { !it.matches(value) }) + fun matches(value: String) = when{ + include.isNotEmpty() -> include.any { it.matches(value) } && exclude.none { it.matches(value) } + exclude.isNotEmpty() -> exclude.none { it.matches(value) } + else -> true + } } fun globPatternToRegexString(globPattern: String): String = globPattern diff --git a/protoc-gen-kroto-plus/src/test/kotlin/FileFilterTest.kt b/protoc-gen-kroto-plus/src/test/kotlin/FileFilterTest.kt new file mode 100644 index 0000000..71886fa --- /dev/null +++ b/protoc-gen-kroto-plus/src/test/kotlin/FileFilterTest.kt @@ -0,0 +1,108 @@ +package com.github.marcoferrer.krotoplus.utils + +import com.github.marcoferrer.krotoplus.config.FileFilter +import kotlin.test.Test +import kotlin.test.assertEquals + +class FileFilterTest { + + val testPaths = listOf( + "google/protobuf", + "test/dummy/a/1", + "test/dummy/a/2", + "test/dummy/b/1", + "test/dummy/b/2", + "test/dummy/c/1", + "test/dummy/c/2" + ) + + @Test + fun `include all paths`(){ + val fileFilter = FileFilter.getDefaultInstance() + val matches = testPaths.filter { fileFilter.matches(it) } + assertEquals(7, matches.size) + } + + @Test + fun `Include single path`(){ + val fileFilter = FileFilter.newBuilder().addIncludePath("test/dummy/a/*").build() + val matches = testPaths.filter { fileFilter.matches(it) } + assertEquals(2, matches.size) + assertEquals("test/dummy/a/1",matches[0]) + assertEquals("test/dummy/a/2",matches[1]) + } + + @Test + fun `Include multiple paths`(){ + val fileFilter = FileFilter.newBuilder() + .addIncludePath("test/dummy/a/*") + .addIncludePath("google/*") + .build() + val matches = testPaths.filter { fileFilter.matches(it) } + assertEquals(3, matches.size) + assertEquals("google/protobuf",matches[0]) + assertEquals("test/dummy/a/1",matches[1]) + assertEquals("test/dummy/a/2",matches[2]) + } + + @Test + fun `Exclude single path`(){ + val fileFilter = FileFilter.newBuilder() + .addExcludePath("google/*") + .build() + + val matches = testPaths.filter { fileFilter.matches(it) } + assertEquals(6, matches.size) + assertEquals("test/dummy/a/1",matches[0]) + assertEquals("test/dummy/a/2",matches[1]) + assertEquals("test/dummy/b/1",matches[2]) + assertEquals("test/dummy/b/2",matches[3]) + assertEquals("test/dummy/c/1",matches[4]) + assertEquals("test/dummy/c/2",matches[5]) + } + + @Test + fun `Exclude multiple paths`(){ + val fileFilter = FileFilter.newBuilder() + .addExcludePath("google/*") + .addExcludePath("test/dummy/b/*") + .build() + + val matches = testPaths.filter { fileFilter.matches(it) } + assertEquals(4, matches.size) + assertEquals("test/dummy/a/1",matches[0]) + assertEquals("test/dummy/a/2",matches[1]) + assertEquals("test/dummy/c/1",matches[2]) + assertEquals("test/dummy/c/2",matches[3]) + } + + @Test + fun `Include and exclude paths`(){ + val fileFilter = FileFilter.newBuilder() + .addIncludePath("test/dummy/*") + .addExcludePath("test/dummy/*/1") + .build() + + val matches = testPaths.filter { fileFilter.matches(it) } + assertEquals(3, matches.size) + assertEquals("test/dummy/a/2",matches[0]) + assertEquals("test/dummy/b/2",matches[1]) + assertEquals("test/dummy/c/2",matches[2]) + } + + @Test + fun `Include and exclude multiple paths`(){ + val fileFilter = FileFilter.newBuilder() + .addIncludePath("google/*") + .addIncludePath("test/dummy/*/1") + .addExcludePath("test/dummy/a/*") + .addExcludePath("test/dummy/c/*") + .build() + + val matches = testPaths.filter { fileFilter.matches(it) } + assertEquals(2, matches.size) + assertEquals("google/protobuf",matches[0]) + assertEquals("test/dummy/b/1",matches[1]) + } + +} \ No newline at end of file