Skip to content

Commit

Permalink
Merge pull request #180 from Vinicius-resende-cin/fix-diffj-execution
Browse files Browse the repository at this point in the history
Receive diffj execution working directory from a parameter
  • Loading branch information
pauloborba authored May 2, 2024
2 parents 75a5f63 + edda7a2 commit cdb7435
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,28 @@ import services.dataCollectors.modifiedLinesCollector.ModifiedMethodsHelper
import java.util.stream.Collectors

/**
* @requires: that a diffj cli is in the dependencies folder
* @requires: that a diffj cli is in the dependencies folder, or that the path to the diffj cli is provided
* @provides: returns true if both left and right of the merge scenario have a intersection on the modified methods list
*/
class MutuallyModifiedMethodsCommitFilter implements CommitFilter {

private modifiedMethodsHelper = new ModifiedMethodsHelper("diffj.jar");
private ModifiedMethodsHelper modifiedMethodsHelper;

/**
* Default constructor.
* Assumes the path to diffj as the 'dependencies' directory in the root of the project.
*/
public MutuallyModifiedMethodsCommitFilter() {
this("dependencies");
}

/**
* Receives the path to diffj as a parameter, in cases where the class is used as a library.
* @param dependenciesPath The path to the folder containing the DiffJ executable.
*/
public MutuallyModifiedMethodsCommitFilter(String dependenciesPath) {
this.modifiedMethodsHelper = new ModifiedMethodsHelper("diffj.jar", dependenciesPath);
}

boolean applyFilter(Project project, MergeCommit mergeCommit) {
return containsMutuallyModifiedMethods(project, mergeCommit)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,27 @@ import static app.MiningFramework.arguments


/**
* @requires: that a diffj cli is in the dependencies folder and that diff (textual diff tool) is installed
* @requires: that a diffj cli is in the dependencies folder (or that the path to the diffj cli is provided)
and that diff (textual diff tool) is installed
* @provides: a [outputPath]/data/results.csv file with the following format:
* project;merge commit;className;method;left modifications;left deletions;right modifications;right deletions
*/
class ModifiedLinesCollector extends ModifiedLinesCollectorAbstract {

/**
* Default constructor.
* Assumes the path to diffj as the 'dependencies' directory in the root of the project.
*/
public ModifiedLinesCollector() {
modifiedMethodsHelper = new ModifiedMethodsHelper("diffj.jar");
this("dependencies");
}

/**
* Receives the path to diffj as a parameter, in cases where the class is used as a library.
* @param dependenciesPath The path to the folder containing the DiffJ executable.
*/
public ModifiedLinesCollector(String dependenciesPath) {
modifiedMethodsHelper = new ModifiedMethodsHelper("diffj.jar", dependenciesPath);
}

void collectData(Project project, MergeCommit mergeCommit) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,29 @@ import static app.MiningFramework.arguments


/**
* @requires: that a diffj cli is in the dependencies folder and that diff (textual diff tool) is installed
* @requires: that a diffj cli is in the dependencies folder (or that the path to the diffj cli is provided)
and that diff (textual diff tool) is installed
* @provides: a [outputPath]/data/results.csv file with the following format:
* project;merge commit;left commit;right commit;base commit;className;method;empty_diff_base_left;empty_diff_base_right;empty_diff_base_merge
*/
class ModifiedLinesCollectorDynamicSemanticStudy extends ModifiedLinesCollectorAbstract {

protected String localPathRevisions = ""

/**
* Default constructor.
* Assumes the path to diffj as the 'dependencies' directory in the root of the project.
*/
public ModifiedLinesCollectorDynamicSemanticStudy() {
modifiedMethodsHelper = new ModifiedMethodsHelper("diffj-method-return-info.jar");
this("dependencies");
}

/**
* Receives the path to diffj as a parameter, in cases where the class is used as a library.
* @param dependenciesPath The path to the folder containing the DiffJ executable.
*/
public ModifiedLinesCollectorDynamicSemanticStudy(String dependenciesPath) {
modifiedMethodsHelper = new ModifiedMethodsHelper("diffj-method-return-info.jar", dependenciesPath);
}

void collectData(Project project, MergeCommit mergeCommit) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,27 @@ import util.ProcessRunner
class ModifiedMethodsHelper {

private String diffJOption;
private String dependenciesPath; // Path to the folder containing the DiffJ executable
private TextualDiffParser textualDiffParser = new TextualDiffParser();
private DiffJParser modifiedMethodsParser = new DiffJParser();
private MethodModifiedLinesMatcher modifiedMethodsMatcher = new MethodModifiedLinesMatcher();

/**
* Assumes the path to diffj as the 'dependencies' directory in the root of the project.
* @param diffj Represents the diffJ file name.
*/
public ModifiedMethodsHelper(String diffj) {
this.diffJOption = diffj
this(diffj, "dependencies");
}

/**
* Receives the path to diffj as a parameter, in cases where the class is used as a library.
* @param diffj Represents the diffJ file name.
* @param dependenciesPath The path to the folder containing the DiffJ executable.
*/
public ModifiedMethodsHelper(String diffj, String dependenciesPath) {
this.diffJOption = diffj;
this.dependenciesPath = dependenciesPath;
}

public Set<ModifiedMethod> getModifiedMethods(Project project, String filePath, String ancestorSHA, String targetSHA) {
Expand All @@ -39,7 +54,7 @@ class ModifiedMethodsHelper {
}

private List<String> runDiffJ(File ancestorFile, File targetFile) {
Process diffJ = ProcessRunner.runProcess('dependencies', 'java', '-jar', this.diffJOption, "--brief", ancestorFile.getAbsolutePath(), targetFile.getAbsolutePath())
Process diffJ = ProcessRunner.runProcess(this.dependenciesPath, 'java', '-jar', this.diffJOption, "--brief", ancestorFile.getAbsolutePath(), targetFile.getAbsolutePath())
BufferedReader reader = new BufferedReader(new InputStreamReader(diffJ.getInputStream()))
def output = reader.readLines()
reader.close()
Expand Down

0 comments on commit cdb7435

Please sign in to comment.