Skip to content

Commit cf4f4da

Browse files
Working on implementation of parent retrieval on demand
1 parent 8e775ab commit cf4f4da

4 files changed

Lines changed: 81 additions & 25 deletions

File tree

pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,5 +118,10 @@
118118
<artifactId>kconfigreader</artifactId>
119119
<version>1.0.0</version>
120120
</dependency>
121+
<dependency>
122+
<groupId>net.lingala.zip4j</groupId>
123+
<artifactId>zip4j</artifactId>
124+
<version>2.9.0</version>
125+
</dependency>
121126
</dependencies>
122127
</project>

src/main/java/de/variantsync/evolution/io/data/VariabilityDatasetLoader.java

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
import de.variantsync.evolution.variability.SPLCommit;
88
import de.variantsync.evolution.variability.SPLCommit.*;
99
import de.variantsync.evolution.variability.VariabilityDataset;
10+
import net.lingala.zip4j.ZipFile;
11+
import net.lingala.zip4j.exception.ZipException;
1012

13+
import java.io.File;
1114
import java.io.IOException;
1215
import java.nio.file.Files;
1316
import java.nio.file.Path;
@@ -104,6 +107,7 @@ public Result<VariabilityDataset, Exception> load(final Path p) {
104107
}
105108
}
106109
Logger.info("Done.");
110+
Logger.info("Found a total of " + idToCommitMap.size() + " commits.");
107111
// Return the fully-loaded dataset
108112
return Result.Success(new VariabilityDataset(successCommits, errorCommits, partialSuccessCommits));
109113
}
@@ -154,15 +158,29 @@ private FilterCountsPath resolvePathToFilterCountsFile(final Path rootDir, final
154158

155159
private String[] loadParentIds(final Path p, final String commitId) {
156160
final Path parentsFile = resolvePathToParentsFile(p, commitId);
157-
if (parentsFile != null && Files.exists(parentsFile)) {
158-
try {
159-
return Files.readString(parentsFile).split("\\s");
160-
} catch (final IOException e) {
161-
Logger.error("Was not able to load PARENTS.txt " + parentsFile + " even though it exists:", e);
162-
return null;
161+
if (parentsFile != null) {
162+
if (!Files.exists(parentsFile)) {
163+
Logger.info("No PARENTS.txt found, checking archive....");
164+
final File zipFile = new File(parentsFile.getParent() + ".zip");
165+
Logger.info("Checking ZIP file " + zipFile);
166+
if (zipFile.exists()) {
167+
try {
168+
Logger.info("Unzipping PARENTS.txt");
169+
new ZipFile(zipFile).extractFile("PARENTS.txt", String.valueOf(parentsFile.getParent()));
170+
} catch (final ZipException e) {
171+
Logger.error("Was not able to unzip commit data.", e);
172+
}
173+
}
174+
}
175+
if (Files.exists(parentsFile)) {
176+
try {
177+
return Files.readString(parentsFile).split("\\s");
178+
} catch (final IOException e) {
179+
Logger.error("Was not able to load PARENTS.txt " + parentsFile + " even though it exists:", e);
180+
return null;
181+
}
163182
}
164-
} else {
165-
return null;
166183
}
184+
return null;
167185
}
168186
}

src/main/java/de/variantsync/evolution/util/functional/Functional.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,20 @@ public static <Nullable, B, E extends Exception> Optional<B> mapFragile(final Nu
123123
public static <A, B, E extends Exception> Lazy<Optional<B>> mapFragileLazily(final A a, final FragileFunction<A, B, E> f, final Supplier<String> errorMessage) {
124124
return Lazy.of(() -> mapFragile(a, f, errorMessage));
125125
}
126+
127+
/**
128+
* Chains two fragile functions. The chained function first applies f1 to a given input, and then applies f2 to the
129+
* output of f1 (i.e., given an input x the chained function corresponds to f2(f1(x)))
130+
* @param f1 The inner function
131+
* @param f2 The outer function
132+
* @param <Input> The input type of the inner function
133+
* @param <Intermediate> The input type of the outer function and the return type of the inner function
134+
* @param <Output> The return type of the outer function
135+
* @return A new FragileFunction f2(f1(x))
136+
*/
137+
public static <Input, Intermediate, Output> FragileFunction<Input, Output, Exception> chainFragile(
138+
final FragileFunction<Input, Intermediate, Exception> f1,
139+
final FragileFunction<Intermediate, Output, Exception> f2) {
140+
return (Input input) -> f2.run(f1.run(input));
141+
}
126142
}

src/main/java/de/variantsync/evolution/variability/SPLCommit.java

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import de.variantsync.evolution.util.io.TypedPath;
99
import de.variantsync.evolution.variability.pc.Artefact;
1010
import de.variantsync.evolution.variability.pc.EFilterOutcome;
11+
import net.lingala.zip4j.ZipFile;
12+
import net.lingala.zip4j.exception.ZipException;
1113

1214
import java.nio.file.Files;
1315
import java.nio.file.Path;
@@ -16,27 +18,18 @@
1618
import java.util.Optional;
1719

1820
public 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

Comments
 (0)