Skip to content

Commit

Permalink
Merge pull request #105 from nebula-plugins/remove-jgit
Browse files Browse the repository at this point in the history
Use  providers.exec()  for git operations GitScmProvider in order to avoid jgit breaking configuration cache
  • Loading branch information
rpalcolea authored Mar 24, 2023
2 parents 94096da + 8c983b1 commit eaca2f8
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 201 deletions.
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ dependencies {
implementation 'com.perforce:p4java:2015.2.1365273'
implementation 'com.netflix.nebula:nebula-gradle-interop:latest.release'
implementation 'com.netflix.nebula:gradle-contacts-plugin:latest.release'
implementation 'org.eclipse.jgit:org.eclipse.jgit:5.13.0.202109080827-r'
implementation 'org.tmatesoft.svnkit:svnkit:1.8.12'
implementation 'net.java.dev.jna:jna-platform:5.7.0'
testImplementation 'com.github.stefanbirkner:system-rules:1.19.0'
Expand Down
16 changes: 8 additions & 8 deletions gradle.lockfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# This file is expected to be part of source control.
cglib:cglib-nodep:3.2.2=integTestRuntimeClasspath,testRuntimeClasspath
com.github.stefanbirkner:system-rules:1.19.0=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
com.googlecode.javaewah:JavaEWAH:1.1.12=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.googlecode.javaewah:JavaEWAH:1.1.12=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
com.jcraft:jsch.agentproxy.connector-factory:0.0.7=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.jcraft:jsch.agentproxy.core:0.0.7=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.jcraft:jsch.agentproxy.pageant:0.0.7=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
Expand All @@ -13,7 +13,7 @@ com.jcraft:jsch.agentproxy.usocket-jna:0.0.7=compileClasspath,integTestCompileCl
com.jcraft:jsch.agentproxy.usocket-nc:0.0.7=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.jcraft:jzlib:1.1.2=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.netflix.nebula:gradle-contacts-plugin:7.0.0=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.netflix.nebula:nebula-gradle-interop:2.0.0=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.netflix.nebula:nebula-gradle-interop:2.1.1=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.netflix.nebula:nebula-test:10.3.0=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
com.perforce:p4java:2015.2.1365273=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.trilead:trilead-ssh2:1.0.0-build220=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
Expand All @@ -27,19 +27,19 @@ org.ajoberstar.grgit:grgit-core:4.1.1=integTestCompileClasspath,integTestRuntime
org.antlr:antlr-runtime:3.4=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.apiguardian:apiguardian-api:1.1.2=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
org.codehaus.groovy:groovy:3.0.9=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
org.eclipse.jgit:org.eclipse.jgit:5.13.0.202109080827-r=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.eclipse.jgit:org.eclipse.jgit:5.13.0.202109080827-r=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
org.hamcrest:hamcrest-core:1.3=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
org.hamcrest:hamcrest:2.2=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
org.jetbrains.kotlin:kotlin-stdlib-common:1.4.21=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.4.21=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.4.21=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.jetbrains.kotlin:kotlin-stdlib:1.4.21=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.jetbrains.kotlin:kotlin-stdlib-common:1.8.0=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.8.0=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.0=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.jetbrains.kotlin:kotlin-stdlib:1.8.0=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.jetbrains:annotations:13.0=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.junit.platform:junit-platform-commons:1.8.1=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
org.junit.platform:junit-platform-engine:1.8.1=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
org.objenesis:objenesis:2.4=integTestRuntimeClasspath,testRuntimeClasspath
org.opentest4j:opentest4j:1.2.0=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
org.slf4j:slf4j-api:1.7.30=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.slf4j:slf4j-api:1.7.30=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
org.spockframework:spock-core:2.1-M2-groovy-3.0=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
org.spockframework:spock-junit4:2.1-M2-groovy-3.0=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
org.tmatesoft.sqljet:sqljet:1.1.10=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
Expand Down
42 changes: 0 additions & 42 deletions plugin.gradle

This file was deleted.

34 changes: 11 additions & 23 deletions src/main/groovy/nebula/plugin/info/scm/GitScmProvider.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,8 @@

package nebula.plugin.info.scm

import org.eclipse.jgit.lib.Config
import org.eclipse.jgit.lib.Constants
import org.eclipse.jgit.lib.Repository
import org.eclipse.jgit.lib.RepositoryBuilder
import org.gradle.api.Project
import org.gradle.api.provider.ProviderFactory
import org.slf4j.Logger
import org.slf4j.LoggerFactory

class GitScmProvider extends AbstractScmProvider {
GitScmProvider(ProviderFactory providerFactory) {
Expand All @@ -32,19 +26,12 @@ class GitScmProvider extends AbstractScmProvider {

@Override
boolean supports(Project project) {
// TODO When we can make p4java optional, we'll add a classForName check here.
return findFile(project.projectDir, '.git') != null
}

private Repository getRepository(File projectDir) {
new RepositoryBuilder().findGitDir(projectDir).build();
}

@Override
String calculateModuleOrigin(File projectDir) {
Repository repository = getRepository(projectDir)
Config storedConfig = repository.getConfig()
String remoteOriginUrl = storedConfig.getString('remote', 'origin', 'url')
def remoteOriginUrl = executeGitCommand("git", "config", "--get", "remote.origin.url")
try {
URL url = remoteOriginUrl.toURL()
if (url.getUserInfo()) {
Expand All @@ -59,9 +46,8 @@ class GitScmProvider extends AbstractScmProvider {

@Override
String calculateModuleSource(File projectDir) {
Repository repository = getRepository(projectDir)
File gitDir = repository.directory
return projectDir.absolutePath - gitDir.parentFile.absolutePath
String gitWorkDir = executeGitCommand("git", "rev-parse", "--show-toplevel")
return projectDir.absolutePath - new File(gitWorkDir).absolutePath
}

@Override
Expand All @@ -74,11 +60,7 @@ class GitScmProvider extends AbstractScmProvider {
boolean isHashPresent = providerFactory.environmentVariable('GIT_COMMIT').present
String hash
if (!isHashPresent) {
def head = getRepository(projectDir).resolve(Constants.HEAD)
if (!head) {
return null
}
hash = head.name
hash = executeGitCommand("git", "rev-parse", "HEAD")
} else {
hash = providerFactory.environmentVariable('GIT_COMMIT').get()
}
Expand All @@ -87,6 +69,12 @@ class GitScmProvider extends AbstractScmProvider {

@Override
String calculateBranch(File projectDir) {
return getRepository(projectDir).branch
return executeGitCommand("git", "rev-parse", "--abbrev-ref", "HEAD")
}

private String executeGitCommand(Object... args) {
providerFactory.exec {
it.commandLine(args)
}.standardOutput.asText.get().replaceAll("\n", "").trim()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class InfoPluginIntegrationTestKitSpec extends IntegrationTestKitSpec {
java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
vendor = JvmVendorSpec.ADOPTIUM
}
}
Expand Down Expand Up @@ -87,7 +86,6 @@ class InfoPluginIntegrationTestKitSpec extends IntegrationTestKitSpec {
java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
vendor = JvmVendorSpec.ADOPTIUM
}
}
Expand Down Expand Up @@ -143,7 +141,6 @@ class InfoPluginIntegrationTestKitSpec extends IntegrationTestKitSpec {
java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
vendor = JvmVendorSpec.ADOPTIUM
}
}
Expand Down Expand Up @@ -200,7 +197,6 @@ class InfoPluginIntegrationTestKitSpec extends IntegrationTestKitSpec {
java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
vendor = JvmVendorSpec.ADOPTIUM
}
}
Expand Down Expand Up @@ -262,7 +258,6 @@ class InfoPluginIntegrationTestKitSpec extends IntegrationTestKitSpec {
java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
vendor = JvmVendorSpec.ADOPTIUM
}
}
Expand Down
122 changes: 0 additions & 122 deletions src/test/groovy/nebula/plugin/info/scm/GitScmProviderLocalSpec.groovy

This file was deleted.

0 comments on commit eaca2f8

Please sign in to comment.