88import de .variantsync .evolution .util .io .TypedPath ;
99import de .variantsync .evolution .variability .pc .Artefact ;
1010import de .variantsync .evolution .variability .pc .EFilterOutcome ;
11+ import net .lingala .zip4j .ZipFile ;
12+ import net .lingala .zip4j .exception .ZipException ;
1113
1214import java .nio .file .Files ;
1315import java .nio .file .Path ;
1618import java .util .Optional ;
1719
1820public class SPLCommit extends Commit {
19- public record KernelHavenLogPath (Path path ) implements TypedPath {}
20- public record FeatureModelPath (Path path ) implements TypedPath {}
21- public record PresenceConditionPath (Path path ) implements TypedPath {}
22- public record CommitMessagePath (Path path ) implements TypedPath {}
23- public record FilterCountsPath (Path path ) implements TypedPath {}
24-
2521 private final Lazy <Optional <String >> kernelHavenLog ;
2622 private final Lazy <Optional <IFeatureModel >> featureModel ;
2723 private final Lazy <Optional <Artefact >> presenceConditions ;
2824 private final Lazy <Optional <String >> message ;
2925 private final Lazy <Optional <Map <EFilterOutcome , Integer >>> filterCounts ;
30-
3126 private final Path kernelHavenLogPath ;
3227 private final Path featureModelPath ;
3328 private final Path presenceConditionsPath ;
3429 private final Path commitMessagePath ;
3530 private final Path filterCountsPath ;
36-
3731 private SPLCommit [] parents ;
3832
39-
4033 /**
4134 * Constructor for commits that should only contain information about the commit id.
4235 *
@@ -52,8 +45,7 @@ public SPLCommit(
5245 final FeatureModelPath featureModel ,
5346 final PresenceConditionPath presenceConditions ,
5447 final CommitMessagePath commitMessage ,
55- final FilterCountsPath filterCounts )
56- {
48+ final FilterCountsPath filterCounts ) {
5749 super (commitId );
5850
5951 this .kernelHavenLogPath = TypedPath .unwrapNullable (kernelHavenLog );
@@ -65,34 +57,44 @@ public SPLCommit(
6557 // Lazy loading of log file
6658 this .kernelHavenLog = Functional .mapFragileLazily (
6759 kernelHavenLogPath ,
68- Files ::readString ,
60+ Functional . chainFragile ( SPLCommit :: tryUnzip , Files ::readString ) ,
6961 () -> "Was not able to load KernelHaven log for commit " + commitId );
7062 // Lazy loading of feature model
7163 this .featureModel = Functional .mapFragileLazily (
7264 featureModelPath ,
73- p -> Resources .Instance ().load (IFeatureModel .class , p ),
65+ Functional . chainFragile ( SPLCommit :: tryUnzip , path -> Resources .Instance ().load (IFeatureModel .class , path ) ),
7466 () -> "Was not able to load feature model for id " + commitId );
7567 // Lazy loading of presence condition
7668 this .presenceConditions = Functional .mapFragileLazily (
7769 presenceConditionsPath ,
78- path -> Resources .Instance ().load (Artefact .class , path ),
70+ Functional . chainFragile ( SPLCommit :: tryUnzip , path -> Resources .Instance ().load (Artefact .class , path ) ),
7971 () -> "Was not able to load presence conditions for id " + commitId );
8072 // Lazy loading of commit message
8173 this .message = Functional .mapFragileLazily (
8274 commitMessagePath ,
83- Files ::readString ,
75+ Functional . chainFragile ( SPLCommit :: tryUnzip , Files ::readString ) ,
8476 () -> "Was not able to load commit message for id " + commitId );
8577 // Lazy loading of filter counts
8678 this .filterCounts = Functional .mapFragileLazily (
8779 filterCountsPath ,
88- path -> {
80+ Functional . chainFragile ( SPLCommit :: tryUnzip , path -> {
8981 final Map <EFilterOutcome , Integer > countsMap = new HashMap <>();
9082 Files .readAllLines (path ).stream ().map (l -> l .split (":" )).forEach (parts -> countsMap .put (EFilterOutcome .valueOf (parts [0 ]), Integer .parseInt (parts [1 ].trim ())));
9183 return countsMap ;
92- },
84+ }) ,
9385 () -> "Was not able to load filter counts for id " + commitId );
9486 }
9587
88+ private static Path tryUnzip (final Path path ) throws ZipException {
89+ if (!Files .exists (path )) {
90+ final Path zippedParent = Path .of (path .getParent ().toString () + ".zip" );
91+ if (Files .exists (zippedParent )) {
92+ new ZipFile (zippedParent .toFile ()).extractAll (String .valueOf (path .getParent ()));
93+ }
94+ }
95+ return path ;
96+ }
97+
9698 /**
9799 * Return the parents of this commit. As the dataset only contains the data about non-error commits,
98100 * not all <code>SPLCommit</code> objects are associated with their parents. Therefore, an <code>Optional</code> is returned.
@@ -161,4 +163,19 @@ public Path getCommitMessagePath() {
161163 public Path getFilterCountsPath () {
162164 return filterCountsPath ;
163165 }
166+
167+ public record KernelHavenLogPath (Path path ) implements TypedPath {
168+ }
169+
170+ public record FeatureModelPath (Path path ) implements TypedPath {
171+ }
172+
173+ public record PresenceConditionPath (Path path ) implements TypedPath {
174+ }
175+
176+ public record CommitMessagePath (Path path ) implements TypedPath {
177+ }
178+
179+ public record FilterCountsPath (Path path ) implements TypedPath {
180+ }
164181}
0 commit comments