Skip to content

Commit

Permalink
Remove timer (#807)
Browse files Browse the repository at this point in the history
  • Loading branch information
pkoenig10 authored Jun 5, 2024
1 parent 245280d commit 6aa597c
Show file tree
Hide file tree
Showing 12 changed files with 7 additions and 397 deletions.
5 changes: 0 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,10 @@ dependencies {

testImplementation gradleTestKit()
testImplementation 'org.junit.jupiter:junit-jupiter'
testImplementation 'junit:junit'
testRuntimeOnly("org.junit.vintage:junit-vintage-engine") {
because 'allows JUnit 3 and JUnit 4 tests to run'
}
testImplementation 'org.assertj:assertj-core'
testImplementation('org.spockframework:spock-core') {
exclude module: 'groovy-all'
}
testImplementation 'com.fasterxml.jackson.core:jackson-databind'
}

java {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,17 @@
import org.gradle.api.provider.Provider;
import org.gradle.api.services.BuildService;
import org.gradle.api.services.BuildServiceParameters;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public abstract class GitVersionCacheService implements BuildService<BuildServiceParameters.None> {

private static final Logger log = LoggerFactory.getLogger(GitVersionCacheService.class);

private final Timer timer = new Timer();
private final ConcurrentMap<String, VersionDetails> versionDetailsMap = new ConcurrentHashMap<>();

public final String getGitVersion(File project, Object args) {
File gitDir = getRootGitDir(project);
GitVersionArgs gitVersionArgs = GitVersionArgs.fromGroovyClosure(args);
String key = gitDir.toPath() + "|" + gitVersionArgs.getPrefix();
String gitVersion = versionDetailsMap
.computeIfAbsent(key, _k -> createVersionDetails(gitDir, gitVersionArgs))
.computeIfAbsent(key, _k -> new VersionDetailsImpl(gitDir, gitVersionArgs))
.getVersion();
return gitVersion;
}
Expand All @@ -47,18 +42,10 @@ public final VersionDetails getVersionDetails(File project, Object args) {
GitVersionArgs gitVersionArgs = GitVersionArgs.fromGroovyClosure(args);
String key = gitDir.toPath() + "|" + gitVersionArgs.getPrefix();
VersionDetails versionDetails =
versionDetailsMap.computeIfAbsent(key, _k -> createVersionDetails(gitDir, gitVersionArgs));
versionDetailsMap.computeIfAbsent(key, _k -> new VersionDetailsImpl(gitDir, gitVersionArgs));
return versionDetails;
}

private VersionDetails createVersionDetails(File gitDir, GitVersionArgs args) {
return TimingVersionDetails.wrap(timer, new VersionDetailsImpl(gitDir, args));
}

public final Timer timer() {
return timer;
}

private static File getRootGitDir(File currentRoot) {
File gitDir = scanForRootGitDir(currentRoot);
if (!gitDir.exists()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@

package com.palantir.gradle.gitversion;

import com.google.common.collect.ImmutableMap;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.provider.Provider;

final class GitVersionRootPlugin implements Plugin<Project> {
@Override
Expand All @@ -28,22 +26,5 @@ public void apply(Project project) {
throw new IllegalStateException(String.format(
"The %s plugin must be applied to the root project", GitVersionRootPlugin.class.getSimpleName()));
}

Provider<GitVersionCacheService> serviceProvider =
GitVersionCacheService.getSharedGitVersionCacheService(project);

BuildScanPluginInterop.addBuildScanCustomValues(project, () -> {
Timer timer = serviceProvider.get().timer();

String timerJson = timer.toJson();

long totalTime = timer.totalMillis();

return ImmutableMap.of(
"com.palantir.git-version.timings",
timerJson,
"com.palantir.git-version.timings.total",
Long.toString(totalTime));
});
}
}
35 changes: 0 additions & 35 deletions src/main/java/com/palantir/gradle/gitversion/JsonUtils.java

This file was deleted.

55 changes: 0 additions & 55 deletions src/main/java/com/palantir/gradle/gitversion/Timer.java

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -700,82 +700,6 @@ class GitVersionPluginTests extends Specification {
buildResult.output.contains(":printVersion\n1.0.0-${depth}-g${latestCommit.substring(0, 7)}\n")
}

def 'does not crash when setting build scan custom values when Gradle 6 enterprise plugin 3.2 is applied'() {
when:
settingsFile.text = '''
plugins {
id "com.gradle.enterprise" version "3.2"
}
'''.stripIndent() + settingsFile.text

buildFile << '''
plugins {
id 'com.palantir.git-version'
}
version gitVersion()
'''.stripIndent()
gitIgnoreFile << 'build'
Git git = new Git(projectDir, true)
git.runGitCommand("init", projectDir.toString())
git.runGitCommand("add", ".")
git.runGitCommand("commit", "-m", "'initial commit'")
git.runGitCommand("tag", "-a", "1.0.0", "-m", "1.0.0")

then:
with('printVersion').build()
}


def 'does not crash when setting build scan custom values when Gradle 7 build scan plugin is applied'() {
when:
settingsFile.text = '''
plugins {
id "com.gradle.enterprise" version "3.2"
}
'''.stripIndent() + settingsFile.text

buildFile << '''
plugins {
id 'com.palantir.git-version'
}
version gitVersion()
'''.stripIndent()
gitIgnoreFile << 'build'
Git git = new Git(projectDir, true)
git.runGitCommand("init", projectDir.toString())
git.runGitCommand("add", ".")
git.runGitCommand("commit", "-m", "'initial commit'")
git.runGitCommand("tag", "-a", "1.0.0", "-m", "1.0.0")

then:
with(Optional.of('7.4.2'), 'printVersion').build()
}

def 'does not crash when setting build scan custom values when Gradle 6 enterprise plugin 3.1 is applied'() {
when:
settingsFile.text = '''
plugins {
id "com.gradle.enterprise" version "3.1"
}
'''.stripIndent() + settingsFile.text

buildFile << '''
plugins {
id 'com.palantir.git-version'
}
version gitVersion()
'''.stripIndent()
gitIgnoreFile << 'build'
Git git = new Git(projectDir, true)
git.runGitCommand("init", projectDir.toString())
git.runGitCommand("add", ".")
git.runGitCommand("commit", "-m", "'initial commit'")
git.runGitCommand("tag", "-a", "1.0.0", "-m", "1.0.0")

then:
with('printVersion').build()
}

private GradleRunner with(String... tasks) {
return with(Optional.empty(), tasks)
}
Expand Down
Loading

0 comments on commit 6aa597c

Please sign in to comment.