org.ajoberstar.gradle.git.publish.tasks.GitPublishCommit 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.tasks;
import java.io.File;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.inject.Inject;
import org.ajoberstar.grgit.gradle.GrgitService;
import org.gradle.api.DefaultTask;
import org.gradle.api.model.ObjectFactory;
import org.gradle.api.provider.Property;
import org.gradle.api.tasks.*;
@UntrackedTask(because = "Git tracks the state")
public class GitPublishCommit extends DefaultTask {
private final Property grgitService;
private final Property message;
private final Property sign;
@Inject
public GitPublishCommit(ObjectFactory objectFactory) {
this.grgitService = objectFactory.property(GrgitService.class);
this.message = objectFactory.property(String.class);
this.sign = objectFactory.property(Boolean.class);
}
@Internal
public Property getGrgitService() {
return grgitService;
}
@Input
public Property getMessage() {
return message;
}
@Input
@Optional
public Property getSign() {
return sign;
}
@TaskAction
public void commit() {
var git = getGrgitService().get().getGrgit();
git.add(op -> {
op.setPatterns(Stream.of(".").collect(Collectors.toSet()));
});
// check if anything has changed
if (git.status().isClean()) {
setDidWork(false);
} else {
git.commit(op -> {
op.setMessage(getMessage().get());
if (getSign().isPresent()) {
op.setSign(getSign().get());
}
});
setDidWork(true);
}
}
}