Skip to content

Commit

Permalink
a bit of 💙 for Coming (#257)
Browse files Browse the repository at this point in the history
  • Loading branch information
monperrus authored Jan 21, 2024
1 parent 470fdd7 commit ac6cb99
Show file tree
Hide file tree
Showing 44 changed files with 305 additions and 2,813 deletions.
15 changes: 11 additions & 4 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,16 @@ jobs:
java-version: '17'
distribution: 'temurin'
cache: maven
- name: Set up maven settings.xml
uses: s4u/maven-settings-action@v2.3.0
with:
servers: |
[{
"id": "brufulascam",
"username": "monperrus",
"password": "${{ secrets.GHTOKEN_READPACKAGES }}"
}]
- name: Clone test resource
run: git clone https://github.com/SpoonLabs/repogit4testv0
- name: Build with Maven
run: mvn -B package --file pom.xml

# Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive
- name: Update dependency graph
uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6
53 changes: 43 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,49 @@
[![Travis Build Status](https://travis-ci.org/SpoonLabs/coming.svg?branch=master)](https://travis-ci.org/SpoonLabs/coming)

Coming
=======
Coming is a tool for mining git repositories.
Coming is a tool for commit analysis in git repositories.

If you use Coming, please cite one of:
If you use Coming, please cite:

* [Coming: a Tool for Mining Change Pattern Instances from Git Commits](http://arxiv.org/pdf/1810.08532). M. Martinez, M. Monperrus, Proceedings of ICSE - Demo track, 2019 ([doi:10.1109/ICSE-Companion.2019.00043](https://doi.org/10.1109/ICSE-Companion.2019.00043)). [bibtex](https://www.monperrus.net/martin/bibtexbrowser.php?key=arXiv-1810.08532&bib=monperrus.bib)
* [Accurate Extraction of Bug Fix Pattern Occurrences using Abstract Syntax Tree Analysis](https://hal.archives-ouvertes.fr/hal-01075938/file/bug-fix-pattern-identification.pdf) (Matias Martinez, Laurence Duchien and Martin Monperrus), Technical report hal-01075938, Inria, 2014 [bibtex](https://www.monperrus.net/martin/bibtexbrowser.php?key=martinez%3Ahal-01075938&bib=monperrus.bib)
* [Automatically Extracting Instances of Code Change Patterns with AST Analysis](https://hal.inria.fr/hal-00861883/file/paper-short.pdf) (Martinez, M.; Duchien, L.; Monperrus, M.) IEEE International Conference on Software Maintenance (ICSM), pp.388-391, 2013, doi: 10.1109/ICSM.2013.54 [bibtex](https://www.monperrus.net/martin/bibtexbrowser.php?key=martinez%3Ahal-00861883&bib=monperrus.bib)
* [Coming: a Tool for Mining Change Pattern Instances from Git Commits](http://arxiv.org/pdf/1810.08532). M. Martinez, M. Monperrus, Proceedings of ICSE, 2019 ([doi:10.1109/ICSE-Companion.2019.00043](https://doi.org/10.1109/ICSE-Companion.2019.00043)). [bibtex](https://www.monperrus.net/martin/bibtexbrowser.php?key=1810.08532&bib=monperrus.bib)

Contact:

[Matias Martinez](http://www.martinezmatias.com/), [Martin Monperrus](http://www.monperrus.net/martin/)

## Install

Please install a JDK 1.8 and configure Maven or your IDE to use it.
Coming is deployed on Maven Central, see [past versions](https://repo1.maven.org/maven2/com/github/spoonlabs/coming/).

To build yourself, the procedure is as follows.

Add a github token in `.m2/settings.xml`.

```xml
<settings>
<servers>
<server>
<id>br.ufu.lascam</id>
<username>yourlogin</username>
<!-- your github token with scope read:packages -->
<password>FOOBAR</password>
</server>
</servers>
</settings>
```


Install a JDK 17 and configure Maven or your IDE to use it.


```
mvn install -DskipTests
$ export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64/
$ mvn -version
Apache Maven 3.6.3
Maven home: /usr/share/maven
Java version: 17.0.9, vendor: Private Build, runtime: /usr/lib/jvm/java-17-openjdk-amd64
# now installing
$ mvn install -DskipTests
```

Tests:
Expand Down Expand Up @@ -82,6 +106,8 @@ In the following command we change the value of two properties: `max_nb_hunks` a

When running Coming in mode `-mode mineinstance` the output is a file name `instances_found.json` , which shows the different instances of the pattern passed as parameter.

* [Automatically Extracting Instances of Code Change Patterns with AST Analysis](https://hal.inria.fr/hal-00861883/file/paper-short.pdf) (Martinez, M.; Duchien, L.; Monperrus, M.) IEEE International Conference on Software Maintenance (ICSM), pp.388-391, 2013, doi: 10.1109/ICSM.2013.54 [bibtex](https://www.monperrus.net/martin/bibtexbrowser.php?key=martinez%3Ahal-00861883&bib=monperrus.bib)


#### Mining Simple Changes (i.e., with exactly one change)

Expand Down Expand Up @@ -313,6 +339,11 @@ Example, the previous json file shows
which means that there are 2 changes that update binary operators inside an if condition (i.e., the parent).

### Mode Repairability

This is a mode to find commits which look like automated program repair commits, see paper ["Estimating the Potential of Program Repair Search Spaces with Commit Analysis"](http://arxiv.org/pdf/2007.06986) (Khashayar Etemadi, Niloofar Tarighat, Siddharth Yadav, Matias Martinez and Martin Monperrus, Journal of Systems and Software, 2022).

Note that the results are sensitive to the underlying diff algorithm. If you run repairibility analysis today, you'll get results that are different from the paper. For exact reproduction, use commit [1cad74323bacad65f06ddf80ab53971d38957507](https://github.com/SpoonLabs/coming/commit/1cad74323bacad65f06ddf80ab53971d38957507) and Java 8.

When running Coming in mode `-mode repairibility`, the output is a file named `all_instances_found.json` , which shows the possible tool creating the commits. You can choose tools of interest by including the option: `-repairtool All,Jkali,..`

An example of the content of such file is:
Expand Down Expand Up @@ -376,10 +407,12 @@ Last 100 commits of the repository are analyzed by default, you can change this

### Mode Code Features

Coming has an option to compute the features associated to the code changed by a commit.
Coming can be used to compute features associated to the code changed by a commit.
This functionality can be used with the argument `-mode features`.
Coming writes in the folder specified in the `-output` a JSON file for each commit.

See [Automated Classification of Overfitting Patches with Statically Extracted Code Features](http://arxiv.org/pdf/1910.12057) (He Ye, Jian Gu, Matias Martinez, Thomas Durieux and Martin Monperrus), In IEEE Transactions on Software Engineering, 2021.

## Input Types

Coming read the input from the folder indicated by the argument `-location`. The kind of input depends on the argument `-input`.
Expand Down
25 changes: 15 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,16 @@
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>


<dependency><!-- must come before gumtree-spoon -->
<!-- must come before gumtree-spoon -->

<dependency>
<groupId>br.ufu.lascam</groupId>
<artifactId>automatic-diff-dissection</artifactId>
<version>1.1-SNAPSHOT</version>
<version>1.1</version>
</dependency>

<dependency>
<groupId>fr.inria.gforge.spoon.labs </groupId>
<artifactId>gumtree-spoon-ast-diff</artifactId>
Expand Down Expand Up @@ -170,13 +173,18 @@

<dependency>
<groupId>ml.dmlc</groupId>
<artifactId>xgboost4j</artifactId>
<version>0.72</version>
<artifactId>xgboost4j_2.12</artifactId>
<version>2.0.3</version>
</dependency>

</dependencies>

<repositories>
<repository>
<id>brufulascam</id>
<url>https://maven.pkg.github.com/lascam-UFU/automatic-diff-dissection</url>
</repository>

<repository>
<id>tdurieux.github.io/maven-repository/snapshots/</id>
<name>tdurieux.github.io maven-repository</name>
Expand All @@ -189,11 +197,7 @@
<url>https://tdurieux.github.io/maven-repository/releases/</url>
</repository>

<repository>
<id>maven.inria.fr-snapshot</id>
<name>Maven Repository for Spoon Snapshots</name>
<url>http://maven.inria.fr/artifactory/spoon-public-snapshot</url>
</repository>

</repositories>

<build>
Expand Down Expand Up @@ -311,6 +315,7 @@
<id>ossrh</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>

<snapshotRepository>
<id>ossrh-snapshot</id>
<url>https://oss.sonatype.org/repositories/snapshots</url>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class MegaDiff implements Diff {
/**
* the mapping of this diff
*/
private MappingStore _mappingsComp = new MappingStore();
private MappingStore _mappingsComp;
/**
* Context of the spoon diff.
*/
Expand All @@ -37,7 +37,7 @@ public void merge(Diff anotherDiff) {
this.rootOperations.addAll(anotherDiff.getRootOperations());

for (Mapping map : anotherDiff.getMappingsComp().asSet()) {
_mappingsComp.link(map.getFirst(), map.getSecond());
_mappingsComp = new MappingStore(map.first, map.second);
}

// context.
Expand Down Expand Up @@ -101,6 +101,11 @@ public boolean containsOperations(List<Operation> operations, OperationKind kind
return false;
}

@Override
public boolean containsOperations(List<Operation> list, OperationKind operationKind, String s) {
return containsOperations(list, operationKind, s,"EMPTY");
}

@Override
public void debugInformation() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public ODSLabel getLabel(File pairFolder) throws Exception {
File tempFile = null;
try {
tempFile = File.createTempFile("test", ".txt");
System.out.println("tempFile: "+tempFile);
} catch (Exception e) {
log.error("ODS cannot create a feature file test.txt in the disk ");
return ODSLabel.UNKNOWN;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import java.util.List;
import java.util.stream.Collectors;

import com.github.gumtreediff.tree.ITree;

import com.github.gumtreediff.tree.Tree;
import fr.inria.coming.codefeatures.Cntx;
import fr.inria.coming.codefeatures.CodeElementInfo;
import fr.inria.coming.codefeatures.CodeFeatures;
Expand Down Expand Up @@ -69,7 +69,7 @@ public void writeGroupedInfo(Cntx<Object> context, String key, CodeFeatures prop
public String adjustIdentifyInJson(CtElement spoonElement) {

if (spoonElement.getAllMetadata().containsKey("gtnode")) {
ITree gumtreeObject = (ITree) spoonElement.getMetadata("gtnode");
Tree gumtreeObject = (Tree) spoonElement.getMetadata("gtnode");

return gumtreeObject.getLabel();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.util.List;
import java.util.Map;

import com.github.gumtreediff.tree.ITree;
import com.github.gumtreediff.tree.Tree;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;

Expand Down Expand Up @@ -71,7 +71,7 @@ public static JsonObject createJSonOfOperation(MapList<Operation, Operation> ope
operation.getAction().getNode());
change.add("ast_node_updated_previous", ast);

ITree dest = iDiff.getMappingsComp().getDst(operation.getAction().getNode());
Tree dest = iDiff.getMappingsComp().getDstForSrc(operation.getAction().getNode());
JsonObject ast_dst = jsongen.getJSONasJsonObject(((DiffImpl) iDiff).getContext(), dest);
change.add("ast_node_updated_post", ast_dst);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ public RepositoryPGit(String pathOfRepo, String branch) {
* The branch to analyze
*/
public RepositoryPGit(String pathOfRepo, String branch, Collection<String> filter) {
if (!new File(pathOfRepo).exists()) {
throw new RuntimeException("repository path (arg --location) does not exist");
}
FileRepositoryBuilder builder = new FileRepositoryBuilder();
this.filter = filter;
String path = pathOfRepo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ public void getInstancesOfRevision(RevisionResult revisionResult, JsonArray inst
opjson.add("concrete_change", getJSONFromOperator(op));

if (op.getNode().getPosition() != null) {
opjson.addProperty("file", op.getNode().getPosition().getFile().getAbsolutePath());
final String repoPath = new File(ComingProperties.getProperty("location")).getAbsolutePath();
final String relativePath = op.getNode().getPosition().getFile().getAbsolutePath().replace(new File(System.getProperty("user.dir")).getAbsolutePath(), "");
opjson.addProperty("file", repoPath+File.separator+ relativePath);
opjson.addProperty("line", op.getNode().getPosition().getLine());
}
ops.add(opjson);
Expand Down
8 changes: 1 addition & 7 deletions src/main/java/fr/inria/coming/main/ComingMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -238,13 +238,7 @@ private void loadFilters() {
private void loadOutput() {
String outputs = ComingProperties.getProperty("outputprocessor");
if (outputs == null) {
if (Boolean.valueOf(System.getProperty("executed_by_travis"))) {
navigatorEngine.getOutputProcessors().add(0, new NullOutput());
System.out.println("****EXECUTED_BY_TRAVIS****");
} else {
navigatorEngine.getOutputProcessors().add(0, new StdOutput());
System.out.println("**NOT_EXECUTED_BY_TRAVIS**");
}
navigatorEngine.getOutputProcessors().add(0, new NullOutput());
} else {
loadOutputProcessors(outputs);
}
Expand Down
17 changes: 10 additions & 7 deletions src/main/java/fr/inria/coming/repairability/repairtools/Arja.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

import com.github.gumtreediff.actions.model.Insert;
import com.github.gumtreediff.matchers.MappingStore;
import com.github.gumtreediff.tree.ITree;

import com.github.gumtreediff.tree.Tree;
import fr.inria.coming.changeminer.analyzer.instancedetector.ChangePatternInstance;
import fr.inria.coming.changeminer.analyzer.patternspecification.ChangePatternSpecification;
import fr.inria.coming.changeminer.entity.IRevision;
Expand Down Expand Up @@ -82,7 +82,7 @@ public boolean filter(ChangePatternInstance instance, IRevision revision, Diff d
return true;
} else if (op instanceof InsertOperation) {
MappingStore mapping = diff.getMappingsComp();
if (!mapping.hasSrc(((Insert) op.getAction()).getParent()))
if (!mapping.isSrcMapped(((Insert) op.getAction()).getParent()))
return false;

CtElement parentOfInsertedNode = ((InsertOperation) op).getParent();
Expand All @@ -102,18 +102,18 @@ public boolean filter(ChangePatternInstance instance, IRevision revision, Diff d
CtElement affectedNode, srcNode;
if (op instanceof InsertOperation) {
MappingStore mapping = diff.getMappingsComp();
if (!mapping.hasSrc(((Insert) op.getAction()).getParent()))
if (!mapping.isSrcMapped(((Insert) op.getAction()).getParent()))
return false;

affectedNode = op.getSrcNode().getParent();
srcNode = ((InsertOperation) op).getParent();
} else if (op instanceof DeleteOperation) {
MappingStore mapping = diff.getMappingsComp();

if (!mapping.hasSrc(op.getAction().getNode().getParent()))
if (!mapping.isSrcMapped(op.getAction().getNode().getParent()))
return false;

ITree dstTree = mapping.getDst(op.getAction().getNode().getParent());
Tree dstTree = mapping.getDstForSrc(op.getAction().getNode().getParent());
affectedNode = (CtElement) dstTree.getMetadata("spoon_object");
srcNode = op.getSrcNode();
} else if (op instanceof UpdateOperation) {
Expand All @@ -137,10 +137,13 @@ public boolean filter(ChangePatternInstance instance, IRevision revision, Diff d
delOp = getActionFromDelInsInstance(instance, "DEL");

MappingStore mapping = diff.getMappingsComp();
if (!mapping.hasSrc(((Insert) op.getAction()).getParent()))
if (!mapping.isSrcMapped(((Insert) op.getAction()).getParent()))
// the inserted node is a part of a parent inserted node
return false;


if (!(insOp instanceof InsertOperation)) {
return false;
}
CtElement insertedNodeParent = ((InsertOperation)insOp).getParent();

if(insertedNodeParent == null)
Expand Down
Loading

0 comments on commit ac6cb99

Please sign in to comment.