diff --git a/src/main/injectors/GenericMergeModule.groovy b/src/main/injectors/GenericMergeModule.groovy index 327e7be23..0080f3b32 100644 --- a/src/main/injectors/GenericMergeModule.groovy +++ b/src/main/injectors/GenericMergeModule.groovy @@ -7,13 +7,8 @@ import interfaces.DataCollector import interfaces.OutputProcessor import interfaces.ProjectProcessor import services.commitFilters.MutuallyModifiedFilesCommitFilter -import services.dataCollectors.common.CompareScenarioMergeConflictsDataCollector -import services.dataCollectors.common.RunNormalizationOnScenarioFilesDataCollector +import services.dataCollectors.common.RunNormalizationOnScenarioFilesWithSporkDataCollector import services.dataCollectors.common.SyntacticallyCompareScenarioFilesDataCollector -import services.dataCollectors.mergeToolExecutors.GitMergeFileMergeToolDataCollector -import services.dataCollectors.mergeToolExecutors.JDimeMergeToolExecutorDataCollector -import services.dataCollectors.mergeToolExecutors.LastMergeMergeToolExecutorDataCollector -import services.dataCollectors.mergeToolExecutors.SporkMergeToolExecutorDataCollector import services.outputProcessors.EmptyOutputProcessor import services.projectProcessors.DummyProjectProcessor @@ -26,28 +21,39 @@ class GenericMergeModule extends AbstractModule { Multibinder dataCollectorBinder = Multibinder.newSetBinder(binder(), DataCollector.class) // Run the merge tools on the scenarios - dataCollectorBinder.addBinding().to(JDimeMergeToolExecutorDataCollector.class) - dataCollectorBinder.addBinding().to(LastMergeMergeToolExecutorDataCollector.class) - dataCollectorBinder.addBinding().to(SporkMergeToolExecutorDataCollector.class) - dataCollectorBinder.addBinding().to(GitMergeFileMergeToolDataCollector.class) +// dataCollectorBinder.addBinding().to(JDimeMergeToolExecutorDataCollector.class) +// dataCollectorBinder.addBinding().to(LastMergeMergeToolExecutorDataCollector.class) +// dataCollectorBinder.addBinding().to(SporkMergeToolExecutorDataCollector.class) +// dataCollectorBinder.addBinding().to(GitMergeFileMergeToolDataCollector.class) // Normalize the output files formatting due to jDime pretty-printing - dataCollectorBinder.addBinding().toInstance(new RunNormalizationOnScenarioFilesDataCollector(["merge.java", "merge.spork.java", "merge.last_merge.java"])) +// dataCollectorBinder.addBinding().toInstance(new RunNormalizationOnScenarioFilesDataCollector(["merge.java", "merge.spork.java", "merge.last_merge.java"])) - // Run comparisons between tools themselves - dataCollectorBinder.addBinding().toInstance(new SyntacticallyCompareScenarioFilesDataCollector("merge.last_merge.java", "merge.spork.java")) - dataCollectorBinder.addBinding().toInstance(new SyntacticallyCompareScenarioFilesDataCollector("merge.last_merge.java", "merge.jdime.java")) - dataCollectorBinder.addBinding().toInstance(new SyntacticallyCompareScenarioFilesDataCollector("merge.jdime.java", "merge.spork.java")) - // Run comparisons between tools and the original merge file - dataCollectorBinder.addBinding().toInstance(new SyntacticallyCompareScenarioFilesDataCollector("merge.jdime.java", "merge.java")) - dataCollectorBinder.addBinding().toInstance(new SyntacticallyCompareScenarioFilesDataCollector("merge.last_merge.java", "merge.java")) - dataCollectorBinder.addBinding().toInstance(new SyntacticallyCompareScenarioFilesDataCollector("merge.spork.java", "merge.java")) + // Normalize the output files formatting due to Spork pretty-printing + dataCollectorBinder.addBinding().toInstance(new RunNormalizationOnScenarioFilesWithSporkDataCollector("merge.java", "merge.spork_normalized.java")) + dataCollectorBinder.addBinding().toInstance(new RunNormalizationOnScenarioFilesWithSporkDataCollector("merge.last_merge.java", "merge.last_merge.spork_normalized.java")) + + dataCollectorBinder.addBinding().toInstance(new SyntacticallyCompareScenarioFilesDataCollector("merge.last_merge.spork_normalized.java", "merge.spork.java")) + + dataCollectorBinder.addBinding().toInstance(new SyntacticallyCompareScenarioFilesDataCollector("merge.spork.java", "merge.spork_normalized.java")) + dataCollectorBinder.addBinding().toInstance(new SyntacticallyCompareScenarioFilesDataCollector("merge.last_merge.spork_normalized.java", "merge.spork_normalized.java")) + + + // Run comparisons between tools themselves +// dataCollectorBinder.addBinding().toInstance(new SyntacticallyCompareScenarioFilesDataCollector("merge.last_merge.java", "merge.spork.java")) +// dataCollectorBinder.addBinding().toInstance(new SyntacticallyCompareScenarioFilesDataCollector("merge.last_merge.java", "merge.jdime.java")) +// dataCollectorBinder.addBinding().toInstance(new SyntacticallyCompareScenarioFilesDataCollector("merge.jdime.java", "merge.spork.java")) +// +// // Run comparisons between tools and the original merge file +// dataCollectorBinder.addBinding().toInstance(new SyntacticallyCompareScenarioFilesDataCollector("merge.jdime.java", "merge.java")) +// dataCollectorBinder.addBinding().toInstance(new SyntacticallyCompareScenarioFilesDataCollector("merge.last_merge.java", "merge.java")) +// dataCollectorBinder.addBinding().toInstance(new SyntacticallyCompareScenarioFilesDataCollector("merge.spork.java", "merge.java")) // Run comparisons between conflicts themselves - dataCollectorBinder.addBinding().toInstance(new CompareScenarioMergeConflictsDataCollector("merge.last_merge.java", "merge.spork.java")) - dataCollectorBinder.addBinding().toInstance(new CompareScenarioMergeConflictsDataCollector("merge.last_merge.java", "merge.jdime.java")) - dataCollectorBinder.addBinding().toInstance(new CompareScenarioMergeConflictsDataCollector("merge.jdime.java", "merge.spork.java")) +// dataCollectorBinder.addBinding().toInstance(new CompareScenarioMergeConflictsDataCollector("merge.last_merge.java", "merge.spork.java")) +// dataCollectorBinder.addBinding().toInstance(new CompareScenarioMergeConflictsDataCollector("merge.last_merge.java", "merge.jdime.java")) +// dataCollectorBinder.addBinding().toInstance(new CompareScenarioMergeConflictsDataCollector("merge.jdime.java", "merge.spork.java")) Multibinder outputProcessorBinder = Multibinder.newSetBinder(binder(), OutputProcessor.class) outputProcessorBinder.addBinding().to(EmptyOutputProcessor.class) diff --git a/src/main/services/dataCollectors/common/RunNormalizationOnScenarioFilesWithSporkDataCollector.groovy b/src/main/services/dataCollectors/common/RunNormalizationOnScenarioFilesWithSporkDataCollector.groovy new file mode 100644 index 000000000..9f83f8d5c --- /dev/null +++ b/src/main/services/dataCollectors/common/RunNormalizationOnScenarioFilesWithSporkDataCollector.groovy @@ -0,0 +1,59 @@ +package services.dataCollectors.common + +import interfaces.DataCollector +import org.apache.logging.log4j.LogManager +import org.apache.logging.log4j.Logger +import project.MergeCommit +import project.Project +import services.dataCollectors.S3MMergesCollector.MergeScenarioCollector +import util.ProcessRunner + +import java.nio.file.Path + +class RunNormalizationOnScenarioFilesWithSporkDataCollector implements DataCollector { + private static Logger LOG = LogManager.getLogger(RunNormalizationOnScenarioFilesWithSporkDataCollector.class) + + private static final String SPORK_JAR_PATH = "${System.getProperty("user.dir")}/dependencies/spork.jar" + + private String inputFileName + private String outputFileName + + RunNormalizationOnScenarioFilesWithSporkDataCollector(String inputFileName, String outputFileName) { + this.inputFileName = inputFileName + this.outputFileName = outputFileName + } + + @Override + void collectData(Project project, MergeCommit mergeCommit) { + def scenarioFiles = MergeScenarioCollector.collectNonFastForwardMergeScenarios(project, mergeCommit) + + LOG.trace("Starting normalization of scenario files") + scenarioFiles.parallelStream().forEach(scenarioFile -> { + normalizeFile(scenarioFile) + }) + LOG.trace("Finished normalization of scenario files") + } + + private void normalizeFile(Path scenarioDirectory) { + def processBuilder = ProcessRunner.buildProcess(System.getProperty("user.dir")) + processBuilder.command().addAll(getBuildParameters(scenarioDirectory)) + + LOG.trace("Calling spork with command \"${processBuilder.command().join(' ')}\"") + def exitCode = ProcessRunner.startProcess(processBuilder).waitFor() + if (exitCode != 0) { + LOG.warn("File normalization failed with exit code ${exitCode}") + } + } + + private List getBuildParameters(Path scenarioDirectory) { + def list = new ArrayList() + list.add("java") + list.add("-jar") + list.add(SPORK_JAR_PATH) + list.add(scenarioDirectory.resolve(inputFileName).toString()) + list.add(scenarioDirectory.resolve(inputFileName).toString()) + list.add(scenarioDirectory.resolve(inputFileName).toString()) + list.add("--output=${scenarioDirectory.resolve(outputFileName).toString()}".toString()) + return list + } +}