Skip to content

Commit da74e5a

Browse files
Fixed unzipping of SPLCommit-related variability data.
1 parent 64487ec commit da74e5a

2 files changed

Lines changed: 67 additions & 35 deletions

File tree

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

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,14 @@ private List<SPLCommit> initializeSPLCommits(final Path p, final List<String> co
116116
final List<SPLCommit> splCommits = new ArrayList<>(commitIds.size());
117117
for (final String id : commitIds) {
118118
// Initialize a SPLCommit object for each commit id by resolving all paths to files with data about the commit
119-
final SPLCommit splCommit = new SPLCommit(id, resolvePathToLogFile(p, id), resolvePathToFeatureModel(p, id), resolvePathToPresenceConditions(p, id), resolvePathToMessageFile(p, id), resolvePathToFilterCountsFile(p, id));
119+
final SPLCommit splCommit = new SPLCommit(
120+
id,
121+
resolvePathToCommitOutputDir(p, id),
122+
resolvePathToLogFile(p, id),
123+
resolvePathToFeatureModel(p, id),
124+
resolvePathToPresenceConditions(p, id),
125+
resolvePathToMessageFile(p, id),
126+
resolvePathToFilterCountsFile(p, id));
120127
splCommits.add(splCommit);
121128
}
122129
return splCommits;
@@ -128,59 +135,56 @@ private Path resolvePathToCommitOutputDir(final Path rootDir, final String commi
128135

129136
private FeatureModelPath resolvePathToFeatureModel(final Path rootDir, final String commitId) {
130137
final Path p = resolvePathToCommitOutputDir(rootDir, commitId).resolve(FEATURE_MODEL_FILE);
131-
return p.toFile().exists() ? new FeatureModelPath(p) : null;
138+
return new FeatureModelPath(p);
132139
}
133140

134141
private PresenceConditionPath resolvePathToPresenceConditions(final Path rootDir, final String commitId) {
135142
final Path p = resolvePathToCommitOutputDir(rootDir, commitId).resolve(PRESENCE_CONDITIONS_FILE);
136-
return p.toFile().exists() ? new PresenceConditionPath(p) : null;
143+
return new PresenceConditionPath(p);
137144
}
138145

139146
private Path resolvePathToParentsFile(final Path rootDir, final String commitId) {
140-
final Path p = resolvePathToCommitOutputDir(rootDir, commitId).resolve(PARENTS_FILE);
141-
return p.toFile().exists() ? p : null;
147+
return resolvePathToCommitOutputDir(rootDir, commitId).resolve(PARENTS_FILE);
142148
}
143149

144150
private CommitMessagePath resolvePathToMessageFile(final Path rootDir, final String commitId) {
145151
final Path p = resolvePathToCommitOutputDir(rootDir, commitId).resolve(MESSAGE_FILE);
146-
return p.toFile().exists() ? new CommitMessagePath(p) : null;
152+
return new CommitMessagePath(p);
147153
}
148154

149155
private KernelHavenLogPath resolvePathToLogFile(final Path rootDir, final String commitId) {
150156
final Path p = rootDir.resolve(LOG_DIR_NAME).resolve(commitId + ".log");
151-
return p.toFile().exists() ? new KernelHavenLogPath(p) : null;
157+
return new KernelHavenLogPath(p);
152158
}
153159

154160
private FilterCountsPath resolvePathToFilterCountsFile(final Path rootDir, final String commitId) {
155161
final Path p = resolvePathToCommitOutputDir(rootDir, commitId).resolve(FILTER_COUNTS_FILE);
156-
return p.toFile().exists() ? new FilterCountsPath(p) : null;
162+
return new FilterCountsPath(p);
157163
}
158164

159165
private String[] loadParentIds(final Path p, final String commitId) {
160166
final Path parentsFile = resolvePathToParentsFile(p, commitId);
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)) {
167+
if (!Files.exists(parentsFile)) {
168+
Logger.info("No PARENTS.txt found, checking archive....");
169+
final File zipFile = new File(parentsFile.getParent() + ".zip");
170+
Logger.info("Checking ZIP file " + zipFile);
171+
if (zipFile.exists()) {
176172
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;
173+
Logger.info("Unzipping PARENTS.txt");
174+
new ZipFile(zipFile).extractFile(commitId + "/PARENTS.txt", String.valueOf(resolvePathToCommitOutputDir(p, commitId).getParent()));
175+
} catch (final ZipException e) {
176+
Logger.error("Was not able to unzip commit data.", e);
181177
}
182178
}
183179
}
180+
if (Files.exists(parentsFile)) {
181+
try {
182+
return Files.readString(parentsFile).split("\\s");
183+
} catch (final IOException e) {
184+
Logger.error("Was not able to load PARENTS.txt " + parentsFile + " even though it exists:", e);
185+
return null;
186+
}
187+
}
184188
return null;
185189
}
186190
}

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

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
import de.ovgu.featureide.fm.core.base.IFeatureModel;
44
import de.variantsync.evolution.io.Resources;
55
import de.variantsync.evolution.repository.Commit;
6+
import de.variantsync.evolution.util.Logger;
67
import de.variantsync.evolution.util.functional.Functional;
78
import de.variantsync.evolution.util.functional.Lazy;
9+
import de.variantsync.evolution.util.functional.interfaces.FragileFunction;
810
import de.variantsync.evolution.util.io.TypedPath;
911
import de.variantsync.evolution.variability.pc.Artefact;
1012
import 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

Comments
 (0)