Skip to content

Commit cc53f75

Browse files
committed
Add basic functional test for value sources
1 parent 9b17934 commit cc53f75

File tree

11 files changed

+75
-11
lines changed

11 files changed

+75
-11
lines changed

indra-git/src/main/java/net/kyori/indra/git/MappedRepositoryValueSource.java

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@
3030
/**
3131
* A {@link RepositoryValueSource} that maps an intermediary value type to a final value type.
3232
*
33-
* @param <I> intermediary (non-serializable/config-cacheable) value type
34-
* @param <V> mapped value type
35-
* @param <P> parameters type
33+
* @param <I> the intermediary (non-serializable/config-cacheable) value type
34+
* @param <V> the mapped value type
35+
* @param <P> the parameters type
36+
* @since 4.0.0
3637
*/
3738
public abstract class MappedRepositoryValueSource<I, V, P extends RepositoryValueSource.Parameters> extends RepositoryValueSource<V, P> {
3839
@Override
@@ -44,10 +45,29 @@ public abstract class MappedRepositoryValueSource<I, V, P extends RepositoryValu
4445
return this.mapValue(repository, rawValue);
4546
}
4647

48+
/**
49+
* Obtains the raw value from the repository.
50+
*
51+
* @param repository the git repository
52+
* @return the raw value, or {@code null}
53+
*/
4754
protected abstract @Nullable I getRawValue(final @NotNull Git repository);
4855

56+
/**
57+
* Maps the raw value to the final value type.
58+
*
59+
* @param git the git repository
60+
* @param value the raw value
61+
* @return the mapped value, or {@code null}
62+
*/
4963
protected abstract @Nullable V mapValue(final @NotNull Git git, final @NotNull I value);
5064

65+
/**
66+
* A {@link MappedRepositoryValueSource} that does not require any additional parameters.
67+
*
68+
* @param <I> the intermediary (non-serializable/config-cacheable) value type
69+
* @param <V> the mapped value type
70+
*/
5171
public abstract static class Parameterless<I, V> extends MappedRepositoryValueSource<I, V, Parameters> {
5272
}
5373
}

indra-git/src/main/java/net/kyori/indra/git/QueryBranch.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
* A {@link MappedRepositoryValueSource} that obtains values from the current branch,
3737
* or {@code null} if the project is not in a git repository or is checked out to a detached {@code HEAD}.
3838
*
39-
* @param <V> value type
39+
* @param <V> the value type
4040
*/
4141
public abstract class QueryBranch<V> extends MappedRepositoryValueSource.Parameterless<Ref, V> {
4242
private static final Logger LOGGER = Logging.getLogger(QueryBranch.class);
@@ -54,6 +54,9 @@ public abstract class QueryBranch<V> extends MappedRepositoryValueSource.Paramet
5454
}
5555
}
5656

57+
/**
58+
* Queries the {@link Ref#getName() name} of the current branch ref.
59+
*/
5760
public abstract static class Name extends QueryBranch<String> {
5861
@Override
5962
protected @NotNull String mapValue(final @NotNull Git git, final @NotNull Ref ref) {

indra-git/src/main/java/net/kyori/indra/git/QueryHeadTag.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,17 @@
3333
* A {@link MappedRepositoryValueSource} that obtains values from the tag pointing to the commit checked out as {@code HEAD},
3434
* or {@code null} if the project is not in a git repository or is not checked out to a tag
3535
*
36-
* @param <V> value type
36+
* @param <V> the value type
3737
*/
3838
public abstract class QueryHeadTag<V> extends MappedRepositoryValueSource.Parameterless<Ref, V> {
3939
@Override
4040
protected @Nullable Ref getRawValue(final @NotNull Git repository) {
4141
return IndraGitExtensionImpl.headTag(repository);
4242
}
4343

44+
/**
45+
* Queries the {@link Ref#getName() name} of the head tag ref.
46+
*/
4447
public abstract static class Name extends QueryHeadTag<String> {
4548
@Override
4649
protected @NotNull String mapValue(final @NotNull Git git, final @NotNull Ref ref) {

indra-git/src/main/java/net/kyori/indra/git/QueryTags.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
* A {@link MappedRepositoryValueSource} that queries the git repository for a list of tags.
3838
* Returns an empty list if the repository is not present or if an error occurs while querying.
3939
*
40-
* @param <V> value type
40+
* @param <V> the value type
4141
*/
4242
public abstract class QueryTags<V> extends MappedRepositoryValueSource.Parameterless<List<? extends Ref>, V> {
4343
private static final Logger LOGGER = Logging.getLogger(QueryTags.class);
@@ -52,6 +52,9 @@ public abstract class QueryTags<V> extends MappedRepositoryValueSource.Parameter
5252
}
5353
}
5454

55+
/**
56+
* Queries the {@link Ref#getName() names} of the tags.
57+
*/
5558
public abstract static class Names extends QueryTags<List<String>> {
5659
@Override
5760
protected @NotNull List<String> mapValue(final @NotNull Git git, final @NotNull List<? extends Ref> value) {

indra-git/src/main/java/net/kyori/indra/git/RepositoryValueSource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
* <p>Implementations must be abstract, and only implement {@link #obtain(Git)}.</p>
4343
*
4444
* @param <V> the value type
45-
* @param <P> the parameter type
45+
* @param <P> the parameters type
4646
* @since 4.0.0
4747
*/
4848
public abstract class RepositoryValueSource<V, P extends RepositoryValueSource.Parameters> implements ValueSource<V, P> {

indra-git/src/test/java/net/kyori/indra/git/IndraGitPluginFunctionalTest.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* This file is part of indra, licensed under the MIT License.
33
*
4-
* Copyright (c) 2020-2024 KyoriPowered
4+
* Copyright (c) 2020-2025 KyoriPowered
55
*
66
* Permission is hereby granted, free of charge, to any person obtaining a copy
77
* of this software and associated documentation files (the "Software"), to deal
@@ -27,6 +27,7 @@
2727
import net.kyori.indra.test.FunctionalTestDisplayNameGenerator;
2828
import net.kyori.indra.test.IndraConfigCacheFunctionalTest;
2929
import net.kyori.mammoth.test.TestContext;
30+
import org.eclipse.jgit.api.Git;
3031
import org.eclipse.jgit.api.errors.GitAPIException;
3132
import org.gradle.testkit.runner.BuildResult;
3233
import org.junit.jupiter.api.DisplayNameGeneration;
@@ -53,6 +54,27 @@ void testGitApplication(final TestContext ctx) throws IOException, GitAPIExcepti
5354
assertTrue(second.getOutput().contains("Configuration cache entry reused"), "No config cache reuse");
5455
}
5556

57+
@IndraConfigCacheFunctionalTest
58+
void valueSources(final TestContext ctx) throws IOException, GitAPIException {
59+
try (final Git git = IndraGitPluginTest.initRepo(ctx.outputDirectory())) {
60+
git.commit()
61+
.setAllowEmpty(true)
62+
.setMessage("initial commit")
63+
.setAuthor(IndraGitPluginTest.COMMITTER)
64+
.setCommitter(IndraGitPluginTest.COMMITTER)
65+
.setSign(false)
66+
.call();
67+
}
68+
ctx.copyInput("build.gradle");
69+
ctx.copyInput("settings.gradle");
70+
71+
final BuildResult result = ctx.build("jar");
72+
assertTrue(result.getOutput().contains("Configuration cache entry stored"), "No config cache");
73+
74+
final BuildResult second = ctx.build("jar");
75+
assertTrue(second.getOutput().contains("Configuration cache entry reused"), "No config cache reuse");
76+
}
77+
5678
@IndraConfigCacheFunctionalTest
5779
void testOnSettings(final TestContext ctx) throws IOException, GitAPIException {
5880
IndraGitPluginTest.initRepo(ctx.outputDirectory());

indra-git/src/test/java/net/kyori/indra/git/IndraGitPluginTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
class IndraGitPluginTest {
5252
private static final String PLUGIN = "net.kyori.indra.git";
5353
private static final String DEFAULT_BRANCH = "trunk";
54-
private static final PersonIdent COMMITTER = new PersonIdent("CI", "[email protected]");
54+
public static final PersonIdent COMMITTER = new PersonIdent("CI", "[email protected]");
5555

5656
@TempDir
5757
private Path projectDir;

indra-git/src/test/resources/net/kyori/indra/git/gitApplication/in/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ plugins {
22
id 'net.kyori.indra.git'
33
}
44

5-
task printGitStatus(type: net.kyori.indra.git.task.RepositoryTask) {
5+
tasks.register('printGitStatus', net.kyori.indra.git.task.RepositoryTask) {
66
doLast {
77
logger.lifecycle("Git present: ${repo() != null}")
88
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
plugins {
2+
id 'net.kyori.indra.git'
3+
id 'java'
4+
}
5+
6+
println(indraGit.branchName().get())
7+
println(indraGit.commit().get().name())
8+
9+
tasks.jar {
10+
indraGit.applyVcsInformationToManifest(manifest)
11+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rootProject.name = "valueSources"

0 commit comments

Comments
 (0)