22
33import de .variantsync .subjects .extraction .util .ConfigManipulator ;
44import de .variantsync .subjects .extraction .util .ShellExecutor ;
5+ import net .lingala .zip4j .ZipFile ;
6+ import net .lingala .zip4j .exception .ZipException ;
57import net .ssehub .kernel_haven .SetUpException ;
68import net .ssehub .kernel_haven .config .Configuration ;
79import net .ssehub .kernel_haven .config .DefaultSettings ;
@@ -76,9 +78,16 @@ public void run() {
7678 return ;
7779 }
7880
81+ Path pathToTargetDir = Paths .get (parentDir .getAbsolutePath (), "output" );
82+ Set <String > processedCommits = determineProcessedCommits (pathToTargetDir );
83+
7984 int count = 1 ;
8085 // Process commits assigned to this task
8186 for (RevCommit commit : commits ) {
87+ if (processedCommits .contains (commit .getName ())) {
88+ LOGGER .logStatus ("Skipping " + commit .getName () + " as it was already processed." );
89+ continue ;
90+ }
8291 LOGGER .logStatus ("Started analysis of commit " + commit .getName () + " in task #" + taskName );
8392 LOGGER .logStatus ("Commit number " + count + " of " + commits .size ());
8493 // Make sure the directory is not blocked
@@ -105,7 +114,6 @@ public void run() {
105114 Thread .currentThread ().setName (threadName );
106115 LOGGER .logStatus ("KernelHaven execution finished." );
107116
108- Path pathToTargetDir = Paths .get (parentDir .getAbsolutePath (), "output" );
109117 synchronized (AnalysisTask .class ) {
110118 moveResultsToDirectory (workDir , pathToTargetDir , commit , prepareFail );
111119 }
@@ -144,11 +152,26 @@ private void prepareConfig(File workDir, File propertiesFile) throws SetUpExcept
144152 LOGGER .logInfo ("Saving configuration " + propertiesFile );
145153 manipulator .writeToFile ();
146154 }
155+
156+ private Set <String > determineProcessedCommits (Path pathToTargetDir ) {
157+ Set <String > processedCommits = new HashSet <>();
158+ try {
159+ Path successFile = Paths .get (pathToTargetDir .toString (), SUCCESS_COMMIT_FILE );
160+ Path errorFile = Paths .get (pathToTargetDir .toString (), ERROR_COMMIT_FILE );
161+ Path incompletePCFile = Paths .get (pathToTargetDir .toString (), INCOMPLETE_PC_COMMIT_FILE );
162+ if (Files .exists (successFile )) processedCommits .addAll (Files .readAllLines (successFile ));
163+ if (Files .exists (errorFile )) processedCommits .addAll (Files .readAllLines (errorFile ));
164+ if (Files .exists (incompletePCFile )) processedCommits .addAll (Files .readAllLines (incompletePCFile ));
165+ } catch (IOException e ) {
166+ LOGGER .logException ("Was not able to determine processed commits." , e );
167+ }
168+ return processedCommits ;
169+ }
147170
148171 private static void moveResultsToDirectory (File workDir , Path pathToTargetDir , RevCommit commit , File prepareFail ) {
149172 String commitId = commit .getName ();
150173 LOGGER .logStatus ("Moving result to common output directory." );
151- File data_collection_dir = pathToTargetDir .resolve ("data" ).resolve (commit . getName () ).toFile ();
174+ File data_collection_dir = pathToTargetDir .resolve ("data" ).resolve (commitId ).toFile ();
152175 File log_collection_dir = pathToTargetDir .resolve ("log" ).toFile ();
153176
154177 if (data_collection_dir .mkdirs ()) {
@@ -185,7 +208,7 @@ private static void moveResultsToDirectory(File workDir, Path pathToTargetDir, R
185208 moveKernelHavenLog (workDir , log_collection_dir , commitId );
186209
187210 if (hasError ) {
188- EXECUTOR .execute ("echo \" " + commitId + " \" >> " + ERROR_COMMIT_FILE , pathToTargetDir .toFile ());
211+ EXECUTOR .execute ("echo \" " + commitId + "\" >> " + ERROR_COMMIT_FILE , pathToTargetDir .toFile ());
189212 if (Objects .requireNonNull (data_collection_dir .listFiles ()).length == 0 ) {
190213 try {
191214 Files .delete (data_collection_dir .toPath ());
@@ -198,12 +221,19 @@ private static void moveResultsToDirectory(File workDir, Path pathToTargetDir, R
198221 writeToFile (data_collection_dir , COMMIT_MESSAGE_FILE , commit .getFullMessage ());
199222 if (prepareFail .exists ()) {
200223 LOGGER .logWarning ("KernelHaven was not able to correctly load the build model, the extracted file presence conditions are incomplete!" );
201- EXECUTOR .execute ("echo \" " + commitId + " \" >> " + INCOMPLETE_PC_COMMIT_FILE , pathToTargetDir .toFile ());
224+ EXECUTOR .execute ("echo \" " + commitId + "\" >> " + INCOMPLETE_PC_COMMIT_FILE , pathToTargetDir .toFile ());
202225 } else {
203- EXECUTOR .execute ("echo \" " + commitId + " \" >> " + SUCCESS_COMMIT_FILE , pathToTargetDir .toFile ());
226+ EXECUTOR .execute ("echo \" " + commitId + "\" >> " + SUCCESS_COMMIT_FILE , pathToTargetDir .toFile ());
204227 }
205228 }
206229
230+ try {
231+ new ZipFile (new File (data_collection_dir .getParentFile (), commitId + ".zip" )).addFolder (data_collection_dir );
232+ EXECUTOR .execute ("rm -rf " + commitId , data_collection_dir .getParentFile ());
233+ } catch (ZipException e ) {
234+ LOGGER .logError ("Was not able to zip variability data of commit " + commit .getName ());
235+ }
236+
207237 LOGGER .logInfo ("...done." );
208238 }
209239
0 commit comments