Search in sources :

Example 66 with DiffEntry

use of org.eclipse.jgit.diff.DiffEntry in project curiostack by curioswitch.

the class CurioGenericCiPlugin method computeAffectedFiles.

private static Set<String> computeAffectedFiles(Git git, CanonicalTreeParser oldTreeParser, CanonicalTreeParser newTreeParser, Project rootProject) {
    final List<DiffEntry> diffs;
    try {
        diffs = git.diff().setNewTree(newTreeParser).setOldTree(oldTreeParser).setShowNameAndStatusOnly(true).call();
    } catch (GitAPIException e) {
        throw new IllegalStateException(e);
    }
    Set<String> affectedRelativePaths = new HashSet<>();
    for (DiffEntry diff : diffs) {
        switch(diff.getChangeType()) {
            case ADD:
            case MODIFY:
            case COPY:
                affectedRelativePaths.add(diff.getNewPath());
                break;
            case DELETE:
                affectedRelativePaths.add(diff.getOldPath());
                break;
            case RENAME:
                affectedRelativePaths.add(diff.getNewPath());
                affectedRelativePaths.add(diff.getOldPath());
                break;
        }
    }
    var filtered = affectedRelativePaths.stream().filter(path -> !IGNORED_ROOT_FILES.contains(path)).collect(toImmutableSet());
    rootProject.getLogger().info("Found diffs: {}", filtered);
    return filtered;
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) JavaPlugin(org.gradle.api.plugins.JavaPlugin) RevWalk(org.eclipse.jgit.revwalk.RevWalk) Task(org.gradle.api.Task) UploadCodeCovCacheTask(org.curioswitch.gradle.plugins.ci.tasks.UploadCodeCovCacheTask) UnknownTaskException(org.gradle.api.UnknownTaskException) JibTask(org.curioswitch.gradle.golang.tasks.JibTask) JavaBasePlugin(org.gradle.api.plugins.JavaBasePlugin) GolangPlugin(org.curioswitch.gradle.golang.GolangPlugin) TaskProvider(org.gradle.api.tasks.TaskProvider) GoTestTask(org.curioswitch.gradle.golang.tasks.GoTestTask) Map(java.util.Map) Splitter(com.google.common.base.Splitter) Path(java.nio.file.Path) JacocoReport(org.gradle.testing.jacoco.tasks.JacocoReport) Delete(org.gradle.api.tasks.Delete) ImmutableSet(com.google.common.collect.ImmutableSet) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) Project(org.gradle.api.Project) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Set(java.util.Set) Constants(org.eclipse.jgit.lib.Constants) Collectors(java.util.stream.Collectors) RevTree(org.eclipse.jgit.revwalk.RevTree) UncheckedIOException(java.io.UncheckedIOException) List(java.util.List) Ref(org.eclipse.jgit.lib.Ref) UploadToCodeCovTask(org.curioswitch.gradle.plugins.ci.tasks.UploadToCodeCovTask) RevCommit(org.eclipse.jgit.revwalk.RevCommit) CanonicalTreeParser(org.eclipse.jgit.treewalk.CanonicalTreeParser) GolangExtension(org.curioswitch.gradle.golang.GolangExtension) BasePlugin(org.gradle.api.plugins.BasePlugin) DownloadToolUtil(org.curioswitch.gradle.tooldownloader.util.DownloadToolUtil) Function(java.util.function.Function) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LifecycleBasePlugin(org.gradle.language.base.plugins.LifecycleBasePlugin) ImmutableList(com.google.common.collect.ImmutableList) FetchCodeCovCacheTask(org.curioswitch.gradle.plugins.ci.tasks.FetchCodeCovCacheTask) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) ExtraPropertiesExtension(org.gradle.api.plugins.ExtraPropertiesExtension) Files(java.nio.file.Files) Ascii(com.google.common.base.Ascii) JacocoPlugin(org.gradle.testing.jacoco.plugins.JacocoPlugin) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) IOException(java.io.IOException) File(java.io.File) ObjectId(org.eclipse.jgit.lib.ObjectId) Paths(java.nio.file.Paths) Git(org.eclipse.jgit.api.Git) DiffEntry(org.eclipse.jgit.diff.DiffEntry) Collections(java.util.Collections) ObjectReader(org.eclipse.jgit.lib.ObjectReader) Plugin(org.gradle.api.Plugin) DiffEntry(org.eclipse.jgit.diff.DiffEntry) HashSet(java.util.HashSet)

Aggregations

DiffEntry (org.eclipse.jgit.diff.DiffEntry)66 RevCommit (org.eclipse.jgit.revwalk.RevCommit)24 RevWalk (org.eclipse.jgit.revwalk.RevWalk)23 DiffFormatter (org.eclipse.jgit.diff.DiffFormatter)22 ObjectReader (org.eclipse.jgit.lib.ObjectReader)21 CanonicalTreeParser (org.eclipse.jgit.treewalk.CanonicalTreeParser)20 IOException (java.io.IOException)19 Git (org.eclipse.jgit.api.Git)18 ObjectId (org.eclipse.jgit.lib.ObjectId)15 ArrayList (java.util.ArrayList)14 File (java.io.File)13 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)12 RevTree (org.eclipse.jgit.revwalk.RevTree)11 ByteArrayOutputStream (java.io.ByteArrayOutputStream)8 Path (java.nio.file.Path)8 Test (org.junit.Test)8 FileTreeIterator (org.eclipse.jgit.treewalk.FileTreeIterator)7 TreeWalk (org.eclipse.jgit.treewalk.TreeWalk)7 Ref (org.eclipse.jgit.lib.Ref)6 Repository (org.eclipse.jgit.lib.Repository)6