Skip to content

Commit 9c9bf4f

Browse files
Merge pull request #48 from Tinder/fix_bug_amin
GitQuery 3.0.4
2 parents ed30555 + 90c6b1d commit 9c9bf4f

File tree

20 files changed

+175
-59
lines changed

20 files changed

+175
-59
lines changed

CHANGELOG.md

+11
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@ All notable changes to this library will be documented in this file.
33

44
Version in this change log adheres to [Semantic Versioning](http://semver.org/).
55

6+
### 3.0.4 (2020-12-01) [#48](https://github.com/Tinder/GitQuery/pull/48) Fix cli bug prefixing / to path ([tinder-aminghadersohi](https://github.com/tinder-aminghadersohi)
7+
8+
### 3.0.3 (2020-12-01) [#48](https://github.com/Tinder/GitQuery/pull/48) Allow init-config to use includeGlobs in config ([tinder-aminghadersohi](https://github.com/tinder-aminghadersohi)
9+
10+
### 3.0.2 (2020-12-01) [#48](https://github.com/Tinder/GitQuery/pull/48) Bug Fix - Snakeyaml constructor call ([tinder-aminghadersohi](https://github.com/tinder-aminghadersohi)
11+
- Upgrade to Snakeyaml 1.27
12+
- Simplify constructor call for Yaml to avoid this error: `org.yaml.snakeyaml.representer.Representer.<init>(Lorg/yaml/snakeyaml/DumperOptions;)V`
13+
14+
### 3.0.1 (2020-12-01) [#48](https://github.com/Tinder/GitQuery/pull/48) Bug Fix - init config ([tinder-aminghadersohi](https://github.com/tinder-aminghadersohi)
15+
- Fix a bug related to the gradle plugin init config writing absolute path where relative is desired.
16+
617
### 3.0.0 (2020-11-14) [#45](https://github.com/Tinder/GitQuery/pull/45) GitQuery 3 ([tinder-aminghadersohi](https://github.com/tinder-aminghadersohi)
718
- New `init-config` command line parameter
819
- New Gradle extension `gitQueryInit`

buildSrc/src/main/kotlin/Libs.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ object Libs {
1313
const val kotlin = "1.4.10"
1414
const val ktlint = "0.39.0"
1515
const val ktlintGradlePlugin = "9.4.1"
16-
const val snakeyaml = "1.26"
16+
const val snakeyaml = "1.27"
1717
const val vanniktechMavenPublish = "0.13.0"
1818
}
1919

core/src/main/kotlin/com/tinder/gitquery/core/GitQueryInit.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,12 @@ object GitQueryInit {
3434
configFile: String,
3535
config: GitQueryConfig,
3636
verbose: Boolean = false,
37+
buildDir: String = System.getProperty("user.dir") + "/build"
3738
) {
3839
this.verbose = verbose
3940
config.validate()
4041

41-
val actualRepoDirectory = config.getActualRepoPath()
42+
val actualRepoDirectory = config.getActualRepoPath(buildDir)
4243

4344
prepareRepo(config.remote, config.branch, actualRepoDirectory, verbose = verbose)
4445

core/src/main/kotlin/com/tinder/gitquery/core/GitQuerySync.kt

+7-2
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,17 @@ object GitQuerySync {
2727
fun sync(
2828
config: GitQueryConfig,
2929
verbose: Boolean = false,
30+
projectDir: String = System.getProperty("user.dir"),
31+
buildDir: String = System.getProperty("user.dir") + "/build"
3032
) {
3133
config.validate()
3234

33-
val outputPath = toAbsolutePath(config.outputDir)
35+
val outputPath = toAbsolutePath(
36+
path = config.outputDir,
37+
prefixPath = projectDir
38+
)
3439

35-
val actualRepoPath = config.getActualRepoPath()
40+
val actualRepoPath = config.getActualRepoPath(buildDir)
3641

3742
prepareRepo(config.remote, config.branch, actualRepoPath, verbose = verbose)
3843

core/src/main/kotlin/com/tinder/gitquery/core/GitQueryVersion.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ package com.tinder.gitquery.core
44
* This file was generated by ./build-support/bin/write-version-class
55
*/
66

7-
const val GIT_QUERY_VERSION = "3.0.0"
7+
const val GIT_QUERY_VERSION = "3.0.4"

core/src/main/kotlin/com/tinder/gitquery/core/config/GitQueryConfig.kt

+3-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import com.tinder.gitquery.core.utils.toAbsolutePath
88
import org.yaml.snakeyaml.DumperOptions
99
import org.yaml.snakeyaml.Yaml
1010
import org.yaml.snakeyaml.constructor.Constructor
11-
import org.yaml.snakeyaml.representer.Representer
1211
import java.io.FileWriter
1312
import java.nio.file.Files
1413
import java.nio.file.Paths
@@ -78,16 +77,16 @@ data class GitQueryConfig(
7877
val writer = FileWriter(filename)
7978
val options = DumperOptions()
8079
options.defaultFlowStyle = DumperOptions.FlowStyle.BLOCK
81-
val yaml = Yaml(Constructor(GitQueryConfig::class.java), Representer(options), options)
80+
val yaml = Yaml(options)
8281
yaml.dump(this, writer)
8382
writer.flush()
8483
}
8584

8685
/**
8786
* using the repoDir and remote config attributes, return where the repo should be cloned.
8887
*/
89-
fun getActualRepoPath(): String {
90-
val repoPath = toAbsolutePath(this.repoDir)
88+
fun getActualRepoPath(pathPrefix: String): String {
89+
val repoPath = toAbsolutePath(path = this.repoDir, prefixPath = pathPrefix)
9190
val repoFullname = remote.substringAfter("[email protected]:")
9291
.substringBefore(".git")
9392
return "$repoPath/$repoFullname"

core/src/main/kotlin/com/tinder/gitquery/core/utils/PathUtils.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ fun toAbsolutePath(
1313
path.isBlank() -> {
1414
""
1515
}
16-
path[0] == '/' -> {
16+
path[0] == '/' || prefixPath.isBlank() -> {
1717
path
1818
}
1919
else -> {

core/src/test/kotlin/com/tinder/gitquery/core/GitQuerySyncTest.kt

+12-4
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ class GitQuerySyncTest {
4242
),
4343
repoDir = "${testProjectDir.root}/tmp/remote",
4444
outputDir = "${testProjectDir.root}/gitquery-output"
45-
)
45+
),
46+
projectDir = testProjectDir.root.path,
47+
buildDir = testProjectDir.root.path
4648
)
4749

4850
// Then
@@ -63,7 +65,9 @@ class GitQuerySyncTest {
6365
),
6466
repoDir = "${testProjectDir.root}/tmp/remote",
6567
outputDir = "${testProjectDir.root}/gitquery-output"
66-
)
68+
),
69+
projectDir = testProjectDir.root.path,
70+
buildDir = testProjectDir.root.path
6771
)
6872
}.exceptionOrNull()
6973

@@ -89,7 +93,9 @@ class GitQuerySyncTest {
8993
),
9094
repoDir = "${testProjectDir.root}/tmp/remote",
9195
outputDir = "${testProjectDir.root}/gitquery-output"
92-
)
96+
),
97+
projectDir = testProjectDir.root.path,
98+
buildDir = testProjectDir.root.path
9399
)
94100
}.exceptionOrNull()
95101

@@ -115,7 +121,9 @@ class GitQuerySyncTest {
115121
),
116122
repoDir = "${testProjectDir.root}/tmp/remote",
117123
outputDir = "${testProjectDir.root}/gitquery-output"
118-
)
124+
),
125+
projectDir = testProjectDir.root.path,
126+
buildDir = testProjectDir.root.path
119127
)
120128
}.exceptionOrNull()
121129

gradle-plugin/src/main/kotlin/com/tinder/gitquery/GitQueryInitTask.kt

+5-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
package com.tinder.gitquery
66

77
import com.tinder.gitquery.core.GitQueryInit.initConfig
8-
import org.gradle.api.logging.LogLevel
98
import org.gradle.api.tasks.Input
109
import org.gradle.api.tasks.TaskAction
1110
import javax.inject.Inject
@@ -52,14 +51,12 @@ open class GitQueryInitTask @Inject constructor(
5251

5352
@TaskAction
5453
override fun taskAction() {
55-
if (includeGlobs.isEmpty()) {
56-
logger.log(LogLevel.WARN, "GitQueryInit skipped - includeGlobs is empty.")
57-
return
58-
}
5954
initConfig(
6055
configFile = configFileName(),
6156
config = readConfig(createIfNotExists = true).apply {
62-
initConfig.includeGlobs = includeGlobs
57+
if (includeGlobs.isNotEmpty()) {
58+
initConfig.includeGlobs = includeGlobs
59+
}
6360
if (excludeGlobs.isNotEmpty()) {
6461
initConfig.excludeGlobs = excludeGlobs
6562
}
@@ -68,7 +65,8 @@ open class GitQueryInitTask @Inject constructor(
6865
}
6966
initConfig.flatFiles = flatFiles
7067
},
71-
verbose = verbose
68+
verbose = verbose,
69+
buildDir = project.buildDir.path
7270
)
7371
}
7472
}

gradle-plugin/src/main/kotlin/com/tinder/gitquery/GitQuerySyncTask.kt

+9-17
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ open class GitQuerySyncTask @Inject constructor(
6767
open fun taskAction() {
6868
GitQuerySync.sync(
6969
config = readConfig(createIfNotExists = false),
70-
verbose = verbose
70+
verbose = verbose,
71+
projectDir = project.projectDir.path,
72+
buildDir = project.buildDir.path
7173
)
7274
}
7375

@@ -82,22 +84,12 @@ open class GitQuerySyncTask @Inject constructor(
8284
if (branch.isNotBlank()) {
8385
it.branch = branch
8486
}
85-
it.repoDir = toAbsolutePath(
86-
path = if (repoDir.isNotBlank()) {
87-
repoDir
88-
} else {
89-
it.repoDir
90-
},
91-
prefixPath = "${project.buildDir}"
92-
)
93-
it.outputDir = toAbsolutePath(
94-
path = if (outputDir.isNotBlank()) {
95-
outputDir
96-
} else {
97-
it.outputDir
98-
},
99-
prefixPath = "${project.projectDir}"
100-
)
87+
if (repoDir.isNotBlank()) {
88+
it.repoDir = repoDir
89+
}
90+
if (outputDir.isNotBlank()) {
91+
it.outputDir = outputDir
92+
}
10193
it.cleanOutput = cleanOutput
10294
}
10395
}

gradle-plugin/src/test/kotlin/com/tinder/gitquery/GitQuerySyncTaskTest.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ plugins {
9191
}
9292
9393
gitQuery {
94-
configFile = "gitquery.yml"
95-
outputDir = "gitquery-output"
94+
configFile = "gitquery.yml"
95+
outputDir = "gitquery-output"
9696
repoDir = "tmp/remote"
9797
}
9898
""".trimIndent()

gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ org.gradle.daemon=true
77
org.gradle.parallel=true
88

99
GROUP=com.tinder.gitquery
10-
VERSION_NAME=3.0.0
10+
VERSION_NAME=3.0.4
1111

1212
POM_DESCRIPTION=A library for querying and syncing files in a remote git repo.
1313
POM_URL=https://github.com/Tinder/GitQuery

samples/protobuf-sync-code-gen/README.md

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
## Gradle Proto to Kotlin Code Gen
1+
## Sync Protobuf and generate Java from it
22

3-
Taken from the the [streem/pbandk](https://github.com/streem/pbandk), this example uses git query to sync the address
4-
book example in the [protobuf repository](https://github.com/google/protobuf) and use [streem/pbandk](https://github.com/streem/pbandk)
5-
to generate Kotlin.
3+
This example uses GitQuery to sync the addressbook example in the [protobuf repository](https://github.com/google/protobuf) and use [streem/pbandk](https://github.com/streem/pbandk)
4+
to generate Java.
65

76
For this example the synced proto and generated code has been committed to show what it looks like.
87

samples/protobuf-sync-code-gen/build.gradle.kts

+2-11
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,17 @@ import com.google.protobuf.gradle.protoc
99
plugins {
1010
application
1111
id("com.google.protobuf") version "0.8.13"
12-
id("com.tinder.gitquery") version "3.0.0"
12+
id("com.tinder.gitquery") version "3.0.4"
1313
java
1414
}
1515

1616
val protoDir = "src/main/proto"
1717

1818
gitQuery {
1919
autoSync = true
20-
cleanOutput = true
2120
configFile = "gitquery.yml"
2221
outputDir = protoDir
23-
repoDir = "${project.buildDir}/tmp/.gitquery"
24-
}
25-
26-
// This will init/update the config file every time the gitQuery task runs.
27-
gitQueryInit {
28-
flatFiles = false
29-
includeGlobs = listOf("**/examples/addressbook.proto")
30-
excludeGlobs = listOf("**/generated/**/*.proto")
31-
revision = "v3.14.0"
22+
repoDir = "tmp/.gitquery"
3223
}
3324

3425
sourceSets {

samples/protobuf-sync-code-gen/gitquery.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
!!com.tinder.gitquery.core.GitQueryConfig
1+
!!com.tinder.gitquery.core.config.GitQueryConfig
22
branch: master
33
cleanOutput: true
44
commits: &id001 {}
@@ -13,8 +13,8 @@ initConfig:
1313
includeGlobs:
1414
- '**/examples/addressbook.proto'
1515
revision: v3.14.0
16-
outputDir: /Users/aming/github/Tinder/GitQuery/samples/protobuf-sync-code-gen/src/main/proto
16+
outputDir: src/main/proto
1717
remote: [email protected]:protocolbuffers/protobuf.git
18-
repoDir: /Users/aming/github/Tinder/GitQuery/samples/protobuf-sync-code-gen/build/tmp/.gitquery
18+
repoDir: tmp/.gitquery
1919
schema:
2020
version: '1'
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
## Gradle Proto to Kotlin Code Gen
2+
3+
This examples shows how to generate a gitquery config, and use it to sync the files.
4+
5+
### Building
6+
7+
To build the code simply run:
8+
9+
path/to/gradle gitQueryInit build
10+
11+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
plugins {
2+
id("java")
3+
id("com.tinder.gitquery") version "3.0.4"
4+
}
5+
6+
def protoDir = "src/main/proto"
7+
8+
gitQuery {
9+
autoSync = true
10+
configFile = "gitquery.yml"
11+
outputDir = protoDir
12+
repoDir = "tmp/.gitquery"
13+
}
14+
15+
repositories {
16+
jcenter()
17+
if (System.getenv("CI") == "true") {
18+
mavenLocal()
19+
}
20+
mavenCentral()
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
!!com.tinder.gitquery.core.config.GitQueryConfig
2+
branch: master
3+
cleanOutput: true
4+
commits: &id001 {}
5+
extra: *id001
6+
files:
7+
examples:
8+
addressbook.proto: v3.14.0
9+
initConfig:
10+
excludeGlobs:
11+
- '**/generated/**/*.proto'
12+
flatFiles: false
13+
includeGlobs:
14+
- '**/examples/addressbook.proto'
15+
revision: v3.14.0
16+
outputDir: src/main/proto
17+
remote: [email protected]:protocolbuffers/protobuf.git
18+
repoDir: tmp/.gitquery
19+
schema:
20+
version: '1'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
pluginManagement {
2+
repositories {
3+
if (System.getenv("CI") == "true") {
4+
mavenLocal()
5+
}
6+
// for GA versions
7+
gradlePluginPortal()
8+
}
9+
}

0 commit comments

Comments
 (0)