All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.ajoberstar.gradle.git.publish.GitCliValueSource Maven / Gradle / Ivy

There is a newer version: 4.2.2
Show newest version
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;
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy