33import de .ovgu .featureide .fm .core .base .IFeatureModel ;
44import de .variantsync .evolution .io .Resources ;
55import de .variantsync .evolution .repository .Commit ;
6+ import de .variantsync .evolution .util .Logger ;
67import de .variantsync .evolution .util .functional .Functional ;
78import de .variantsync .evolution .util .functional .Lazy ;
9+ import de .variantsync .evolution .util .functional .interfaces .FragileFunction ;
810import de .variantsync .evolution .util .io .TypedPath ;
911import de .variantsync .evolution .variability .pc .Artefact ;
1012import de .variantsync .evolution .variability .pc .EFilterOutcome ;
@@ -23,6 +25,7 @@ public class SPLCommit extends Commit {
2325 private final Lazy <Optional <Artefact >> presenceConditions ;
2426 private final Lazy <Optional <String >> message ;
2527 private final Lazy <Optional <Map <EFilterOutcome , Integer >>> filterCounts ;
28+ private final Path dataDir ;
2629 private final Path kernelHavenLogPath ;
2730 private final Path featureModelPath ;
2831 private final Path presenceConditionsPath ;
@@ -36,48 +39,52 @@ public class SPLCommit extends Commit {
3639 * @param commitId The id of the commit
3740 */
3841 public SPLCommit (final String commitId ) {
39- this (commitId , null , null , null , null , null );
42+ this (commitId , null , null , null , null , null , null );
4043 }
4144
4245 public SPLCommit (
4346 final String commitId ,
47+ final Path dataDir ,
4448 final KernelHavenLogPath kernelHavenLog ,
4549 final FeatureModelPath featureModel ,
4650 final PresenceConditionPath presenceConditions ,
4751 final CommitMessagePath commitMessage ,
4852 final FilterCountsPath filterCounts ) {
4953 super (commitId );
54+ this .dataDir = dataDir ;
5055
5156 this .kernelHavenLogPath = TypedPath .unwrapNullable (kernelHavenLog );
5257 this .featureModelPath = TypedPath .unwrapNullable (featureModel );
5358 this .presenceConditionsPath = TypedPath .unwrapNullable (presenceConditions );
5459 this .commitMessagePath = TypedPath .unwrapNullable (commitMessage );
5560 this .filterCountsPath = TypedPath .unwrapNullable (filterCounts );
5661
62+ final FragileFunction <Path , Path , ZipException > tryUnzip = SPLCommit ::tryUnzip ;
63+
5764 // Lazy loading of log file
5865 this .kernelHavenLog = Functional .mapFragileLazily (
5966 kernelHavenLogPath ,
60- Functional . chainFragile ( SPLCommit :: tryUnzip , Files ::readString ),
67+ tryUnzip . andThen ( Files ::readString ),
6168 () -> "Was not able to load KernelHaven log for commit " + commitId );
6269 // Lazy loading of feature model
6370 this .featureModel = Functional .mapFragileLazily (
6471 featureModelPath ,
65- Functional . chainFragile ( SPLCommit :: tryUnzip , path -> Resources .Instance ().load (IFeatureModel .class , path )),
72+ tryUnzip . andThen ( path -> Resources .Instance ().load (IFeatureModel .class , path )),
6673 () -> "Was not able to load feature model for id " + commitId );
6774 // Lazy loading of presence condition
6875 this .presenceConditions = Functional .mapFragileLazily (
6976 presenceConditionsPath ,
70- Functional . chainFragile ( SPLCommit :: tryUnzip , path -> Resources .Instance ().load (Artefact .class , path )),
77+ tryUnzip . andThen ( path -> Resources .Instance ().load (Artefact .class , path )),
7178 () -> "Was not able to load presence conditions for id " + commitId );
7279 // Lazy loading of commit message
7380 this .message = Functional .mapFragileLazily (
7481 commitMessagePath ,
75- Functional . chainFragile ( SPLCommit :: tryUnzip , Files ::readString ),
82+ tryUnzip . andThen ( Files ::readString ),
7683 () -> "Was not able to load commit message for id " + commitId );
7784 // Lazy loading of filter counts
7885 this .filterCounts = Functional .mapFragileLazily (
7986 filterCountsPath ,
80- Functional . chainFragile ( SPLCommit :: tryUnzip , path -> {
87+ tryUnzip . andThen ( path -> {
8188 final Map <EFilterOutcome , Integer > countsMap = new HashMap <>();
8289 Files .readAllLines (path ).stream ().map (l -> l .split (":" )).forEach (parts -> countsMap .put (EFilterOutcome .valueOf (parts [0 ]), Integer .parseInt (parts [1 ].trim ())));
8390 return countsMap ;
@@ -87,10 +94,22 @@ public SPLCommit(
8794
8895 private static Path tryUnzip (final Path path ) throws ZipException {
8996 if (!Files .exists (path )) {
90- final Path zippedParent = Path .of (path .getParent ().toString () + ".zip" );
97+ final Path zippedParent = Path .of (path .getParent () + ".zip" );
98+ Logger .debug ("Checking whether there is an archive " + zippedParent );
9199 if (Files .exists (zippedParent )) {
92- new ZipFile (zippedParent .toFile ()).extractAll (String .valueOf (path .getParent ()));
100+ Logger .debug ("Archive " + zippedParent .getFileName () + " found." );
101+ try {
102+ new ZipFile (zippedParent .toFile ()).extractAll (String .valueOf (zippedParent .getParent ()));
103+ } catch (final ZipException e ) {
104+ Logger .error ("Was not able to unzip " + zippedParent , e );
105+ throw e ;
106+ }
107+ } else {
108+ Logger .warning ("Path " + path + " does not exist and no ZIP file found." );
109+ return null ;
93110 }
111+ } else {
112+ Logger .debug ("Path " + path + " exists. No unzip required." );
94113 }
95114 return path ;
96115 }
@@ -144,6 +163,10 @@ public Lazy<Optional<Map<EFilterOutcome, Integer>>> filterCounts() {
144163 return filterCounts ;
145164 }
146165
166+ public Path getCommitDataDirectory () {
167+ return dataDir ;
168+ }
169+
147170 public Path getKernelHavenLogPath () {
148171 return kernelHavenLogPath ;
149172 }
@@ -165,17 +188,22 @@ public Path getFilterCountsPath() {
165188 }
166189
167190 public record KernelHavenLogPath (Path path ) implements TypedPath {
191+
168192 }
169193
170194 public record FeatureModelPath (Path path ) implements TypedPath {
195+
171196 }
172197
173198 public record PresenceConditionPath (Path path ) implements TypedPath {
199+
174200 }
175201
176202 public record CommitMessagePath (Path path ) implements TypedPath {
203+
177204 }
178205
179206 public record FilterCountsPath (Path path ) implements TypedPath {
207+
180208 }
181209}
0 commit comments