org.ajoberstar.gradle.git.publish.GitCliValueSource Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gradle-git-publish Show documentation
Show all versions of gradle-git-publish Show documentation
Gradle plugin for publishing to Git repositories
package org.ajoberstar.gradle.git.publish;
import java.io.ByteArrayOutputStream;
import java.nio.charset.StandardCharsets;
import javax.inject.Inject;
import org.gradle.api.provider.ListProperty;
import org.gradle.api.provider.ValueSource;
import org.gradle.api.provider.ValueSourceParameters;
import org.gradle.process.ExecOperations;
import org.jetbrains.annotations.Nullable;
public abstract class GitCliValueSource implements ValueSource {
public interface Params extends ValueSourceParameters {
ListProperty getGitArguments();
}
@Inject
protected abstract ExecOperations getExecOperations();
@Override
public @Nullable String obtain() {
try {
var output = new ByteArrayOutputStream();
getExecOperations().exec(spec -> {
spec.executable("git");
spec.setArgs(getParameters().getGitArguments().get());
spec.setStandardOutput(output);
});
return output.toString(StandardCharsets.UTF_8).trim();
} catch (Exception e) {
return null;
}
}
}