Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ plugins {
id 'net.kyori.indra'
}

group 'com.example'
version '1.0.0-SNAPSHOT'
group = 'com.example'
version = '1.0.0-SNAPSHOT'

repositories {
sonatype.snapshots()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ plugins {
id 'net.kyori.indra'
}

group 'com.example'
version '1.0.0-SNAPSHOT'
group = 'com.example'
version = '1.0.0-SNAPSHOT'

repositories {
sonatype.snapshots()
Expand Down
33 changes: 8 additions & 25 deletions indra-git/src/main/java/net/kyori/indra/git/IndraGitExtension.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* This file is part of indra, licensed under the MIT License.
*
* Copyright (c) 2020-2024 KyoriPowered
* Copyright (c) 2020-2025 KyoriPowered
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand All @@ -25,7 +25,6 @@

import java.util.List;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Ref;
import org.gradle.api.Action;
import org.gradle.api.java.archives.Manifest;
import org.gradle.api.provider.Provider;
Expand Down Expand Up @@ -91,22 +90,6 @@ default <V, P extends RepositoryValueSource.Parameters, S extends RepositoryValu
*/
<V, P extends RepositoryValueSource.Parameters, S extends RepositoryValueSource<V, P>> Provider<V> repositoryValue(final Class<S> valueSource, final Action<? super ValueSourceSpec<P>> configureAction);

/**
* Get all tags created on this repository.
*
* @return the tags on this repository, or an empty list if this project is not in a git repository
* @since 2.0.0
*/
@NotNull Provider<? extends List<? extends Ref>> tags();

/**
* Get the tag pointing to the commit checked out as {@code HEAD}.
*
* @return the tag at {@code HEAD}, or {@code null} if the project is not in a git repository or is not checked out to a tag
* @since 2.0.0
*/
@NotNull Provider<Ref> headTag();

/**
* Get a <a href="https://git-scm.com/docs/git-describe">{@code git describe}</a> string for the project's repository.
*
Expand All @@ -118,20 +101,20 @@ default <V, P extends RepositoryValueSource.Parameters, S extends RepositoryValu
@NotNull Provider<String> describe();

/**
* Get the name of the current branch.
* Get the names of all tags in the repository.
*
* @return the name of the active branch, or {@code null} if the project is not in a git repository or is checked out to a detached {@code HEAD}.
* @since 2.0.0
* @return tag names, or an empty list if the project is not in a git repository or has no tags
* @since 4.0.0
*/
@NotNull Provider<String> branchName();
@NotNull Provider<List<String>> tagNames();

/**
* Get an object pointing to the current branch.
* Get the name of the current branch.
*
* @return the active branch, or {@code null} if the project is not in a git repository or is checked out to a detached {@code HEAD}.
* @return the name of the active branch, or {@code null} if the project is not in a git repository or is checked out to a detached {@code HEAD}.
* @since 2.0.0
*/
@NotNull Provider<Ref> branch();
@NotNull Provider<String> branchName();

/**
* Get the ID of the current commit.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* This file is part of indra, licensed under the MIT License.
*
* Copyright (c) 2025 KyoriPowered
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package net.kyori.indra.git;

import org.eclipse.jgit.api.Git;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
* A {@link RepositoryValueSource} that maps an intermediary value type to a final value type.
*
* @param <I> the intermediary (non-serializable/config-cacheable) value type
* @param <V> the mapped value type
* @param <P> the parameters type
* @since 4.0.0
*/
public abstract class MappedRepositoryValueSource<I, V, P extends RepositoryValueSource.Parameters> extends RepositoryValueSource<V, P> {
@Override
protected final @Nullable V obtain(final @NotNull Git repository) {
final I rawValue = this.getRawValue(repository);
if (rawValue == null) {
return null;
}
return this.mapValue(repository, rawValue);
}

/**
* Obtains the raw value from the repository.
*
* @param repository the git repository
* @return the raw value, or {@code null}
*/
protected abstract @Nullable I getRawValue(final @NotNull Git repository);

/**
* Maps the raw value to the final value type.
*
* @param git the git repository
* @param value the raw value
* @return the mapped value, or {@code null}
*/
protected abstract @Nullable V mapValue(final @NotNull Git git, final @NotNull I value);

/**
* A {@link MappedRepositoryValueSource} that does not require any additional parameters.
*
* @param <I> the intermediary (non-serializable/config-cacheable) value type
* @param <V> the mapped value type
*/
public abstract static class Parameterless<I, V> extends MappedRepositoryValueSource<I, V, Parameters> {
}
}
66 changes: 66 additions & 0 deletions indra-git/src/main/java/net/kyori/indra/git/QueryBranch.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* This file is part of indra, licensed under the MIT License.
*
* Copyright (c) 2025 KyoriPowered
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package net.kyori.indra.git;

import java.io.IOException;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.Ref;
import org.gradle.api.logging.Logger;
import org.gradle.api.logging.Logging;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
* A {@link MappedRepositoryValueSource} that obtains values from the current branch,
* or {@code null} if the project is not in a git repository or is checked out to a detached {@code HEAD}.
*
* @param <V> the value type
*/
public abstract class QueryBranch<V> extends MappedRepositoryValueSource.Parameterless<Ref, V> {
private static final Logger LOGGER = Logging.getLogger(QueryBranch.class);

@Override
protected @Nullable Ref getRawValue(final @NotNull Git repository) {
try {
final @Nullable Ref ref = repository.getRepository().exactRef(Constants.HEAD);
if (ref == null || !ref.isSymbolic()) return null; // no HEAD, or detached HEAD

return ref.getTarget();
} catch(final IOException ex) {
LOGGER.error("Failed to query current branch name from git:", ex);
return null;
}
}

/**
* Queries the {@link Ref#getName() name} of the current branch ref.
*/
public abstract static class Name extends QueryBranch<String> {
@Override
protected @NotNull String mapValue(final @NotNull Git git, final @NotNull Ref ref) {
return ref.getName();
}
}
}
53 changes: 53 additions & 0 deletions indra-git/src/main/java/net/kyori/indra/git/QueryHeadTag.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* This file is part of indra, licensed under the MIT License.
*
* Copyright (c) 2025 KyoriPowered
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package net.kyori.indra.git;

import net.kyori.indra.git.internal.IndraGitExtensionImpl;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.lib.Ref;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
* A {@link MappedRepositoryValueSource} that obtains values from the tag pointing to the commit checked out as {@code HEAD},
* or {@code null} if the project is not in a git repository or is not checked out to a tag
*
* @param <V> the value type
*/
public abstract class QueryHeadTag<V> extends MappedRepositoryValueSource.Parameterless<Ref, V> {
@Override
protected @Nullable Ref getRawValue(final @NotNull Git repository) {
return IndraGitExtensionImpl.headTag(repository);
}

/**
* Queries the {@link Ref#getName() name} of the head tag ref.
*/
public abstract static class Name extends QueryHeadTag<String> {
@Override
protected @NotNull String mapValue(final @NotNull Git git, final @NotNull Ref ref) {
return ref.getName();
}
}
}
66 changes: 66 additions & 0 deletions indra-git/src/main/java/net/kyori/indra/git/QueryTags.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* This file is part of indra, licensed under the MIT License.
*
* Copyright (c) 2025 KyoriPowered
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package net.kyori.indra.git;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.lib.Ref;
import org.gradle.api.logging.Logger;
import org.gradle.api.logging.Logging;
import org.jetbrains.annotations.NotNull;

/**
* A {@link MappedRepositoryValueSource} that queries the git repository for a list of tags.
* Returns an empty list if the repository is not present or if an error occurs while querying.
*
* @param <V> the value type
*/
public abstract class QueryTags<V> extends MappedRepositoryValueSource.Parameterless<List<? extends Ref>, V> {
private static final Logger LOGGER = Logging.getLogger(QueryTags.class);

@Override
protected @NotNull List<? extends Ref> getRawValue(final @NotNull Git repository) {
try {
return repository.tagList().call();
} catch (final GitAPIException ex) {
LOGGER.error("Failed to query git for a list of tags:", ex);
return Collections.emptyList();
}
}

/**
* Queries the {@link Ref#getName() names} of the tags.
*/
public abstract static class Names extends QueryTags<List<String>> {
@Override
protected @NotNull List<String> mapValue(final @NotNull Git git, final @NotNull List<? extends Ref> value) {
return value.stream()
.map(Ref::getName)
.collect(Collectors.toList());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
* <p>Implementations must be abstract, and only implement {@link #obtain(Git)}.</p>
*
* @param <V> the value type
* @param <P> the parameter type
* @param <P> the parameters type
* @since 4.0.0
*/
public abstract class RepositoryValueSource<V, P extends RepositoryValueSource.Parameters> implements ValueSource<V, P> {
Expand Down
Loading
Loading