|
3 | 3 | import org.tinylog.Logger; |
4 | 4 | import org.variantsync.diffdetective.AnalysisRunner; |
5 | 5 | import org.variantsync.diffdetective.datasets.PatchDiffParseOptions; |
| 6 | +import org.variantsync.diffdetective.datasets.Repository; |
6 | 7 | import org.variantsync.diffdetective.diff.git.DiffFilter; |
7 | 8 | import org.variantsync.diffdetective.variation.diff.parse.VariationDiffParseOptions; |
8 | 9 | import org.variantsync.vevos.extraction.gt.GroundTruth; |
9 | 10 |
|
10 | 11 | import java.io.File; |
11 | 12 | import java.io.FileInputStream; |
12 | 13 | import java.io.IOException; |
| 14 | +import java.lang.reflect.Constructor; |
| 15 | +import java.lang.reflect.InvocationTargetException; |
13 | 16 | import java.nio.file.Path; |
14 | 17 | import java.util.Properties; |
| 18 | +import java.util.function.BiConsumer; |
15 | 19 |
|
16 | 20 | import static org.variantsync.vevos.extraction.ConfigProperties.*; |
17 | 21 |
|
18 | | -public class ExecutionUtilities { |
| 22 | +public abstract class GroundTruthExtraction { |
| 23 | + protected final Properties properties; |
| 24 | + |
| 25 | + protected GroundTruthExtraction(Properties properties) { |
| 26 | + this.properties = properties; |
| 27 | + } |
| 28 | + |
| 29 | + /** |
| 30 | + * Main method to start the extraction. |
| 31 | + * |
| 32 | + * @param args Command-line options. |
| 33 | + * @throws IOException When copying the log file fails. |
| 34 | + */ |
| 35 | + public static void main(String[] args) throws IOException { |
| 36 | + checkOS(); |
| 37 | + |
| 38 | + // Load the configuration |
| 39 | + Properties properties = getProperties(getPropertiesFile(args)); |
| 40 | + // TODO: load dynamically |
| 41 | + Class<?> extractionClass; |
| 42 | + try { |
| 43 | + extractionClass = determineExtractionClass(args); |
| 44 | + } catch (ClassNotFoundException e) { |
| 45 | + Logger.error("The class " + args[1] + " provided as program argument was not found."); |
| 46 | + throw new RuntimeException(e); |
| 47 | + } |
| 48 | + GroundTruthExtraction extraction; |
| 49 | + try { |
| 50 | + extraction = initializeExtraction(extractionClass, properties); |
| 51 | + } catch (NoSuchMethodException e) { |
| 52 | + throw new RuntimeException("The required constructor does not exist for the specified class " + args[1]); |
| 53 | + } catch (InvocationTargetException | InstantiationException | IllegalAccessException e) { |
| 54 | + Logger.error("Was not able to instantiate extraction class with the propterties " + args[0] |
| 55 | + + " and the class name " + args[1]); |
| 56 | + throw new RuntimeException(e); |
| 57 | + } |
| 58 | + |
| 59 | + var options = diffdetectiveOptions(properties); |
| 60 | + Logger.info("Starting SPL history analysis."); |
| 61 | + extraction.run(options); |
| 62 | + } |
| 63 | + |
| 64 | + private static Class<?> determineExtractionClass(String... args) throws ClassNotFoundException { |
| 65 | + if (args.length > 1) { |
| 66 | + return Class.forName(args[1]); |
| 67 | + } else { |
| 68 | + Logger.error("The second program argument must specify a valid GroundTruthExtraction class."); |
| 69 | + throw new IllegalArgumentException("The second program argument must specify a valid GroundTruthExtraction class."); |
| 70 | + } |
| 71 | + } |
| 72 | + |
| 73 | + private static GroundTruthExtraction initializeExtraction(Class<?> extractionClass, Properties properties) |
| 74 | + throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException { |
| 75 | + Constructor<?> constructor = extractionClass.getDeclaredConstructor(Properties.class); |
| 76 | + constructor.setAccessible(true); // If the constructor is not public |
| 77 | + return (GroundTruthExtraction) constructor.newInstance(properties); |
| 78 | + } |
19 | 79 |
|
20 | 80 | /** |
21 | 81 | * Loads the properties in the given file. |
@@ -74,7 +134,6 @@ public static AnalysisRunner.Options diffdetectiveOptions(Properties properties) |
74 | 134 | public static void checkOS() { |
75 | 135 | boolean isWindows = System.getProperty("os.name") |
76 | 136 | .toLowerCase().startsWith("windows"); |
77 | | - Logger.info("OS NAME: " + System.getProperty("os.name")); |
78 | 137 | if (isWindows) { |
79 | 138 | Logger.error("Running the analysis under Windows is not supported as the Linux/BusyBox sources are not" + |
80 | 139 | "checked out correctly."); |
@@ -124,4 +183,16 @@ public static void print(GroundTruth groundTruth, String commitName) { |
124 | 183 | System.out.println(groundTruth.get(file)); |
125 | 184 | } |
126 | 185 | } |
| 186 | + |
| 187 | + /** |
| 188 | + * Starts the extraction. |
| 189 | + * |
| 190 | + * @param options The options for DiffDetective |
| 191 | + * @throws IOException If an IO error occurs in DiffDetective |
| 192 | + */ |
| 193 | + public void run(AnalysisRunner.Options options) throws IOException { |
| 194 | + AnalysisRunner.run(options, extractionRunner()); |
| 195 | + } |
| 196 | + |
| 197 | + protected abstract BiConsumer<Repository, Path> extractionRunner(); |
127 | 198 | } |
0 commit comments