spork

AST-based structured merge tool for Java, fully Git compatible https://doi.org/10.1109/TSE.2022.3143766

https://github.com/assert-kth/spork

Science Score: 57.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 5 DOI reference(s) in README
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (13.6%) to scientific vocabulary
Last synced: 9 months ago · JSON representation ·

Repository

AST-based structured merge tool for Java, fully Git compatible https://doi.org/10.1109/TSE.2022.3143766

Basic Info
  • Host: GitHub
  • Owner: ASSERT-KTH
  • License: mit
  • Language: Java
  • Default Branch: master
  • Homepage:
  • Size: 2.48 MB
Statistics
  • Stars: 58
  • Watchers: 4
  • Forks: 9
  • Open Issues: 27
  • Releases: 10
Created over 6 years ago · Last pushed over 1 year ago
Metadata Files
Readme License Citation

README.md

Build Status Code Coverage Supported Platforms

Spork - AST based merging for Java files

Spork is an AST based structured merge research tool for Java. This means that instead of merging Java files by raw text, it resolves the abstract syntax trees and merges based on them instead.

If you're looking for a production ready tool for AST-based GIT merge, we recommend mergiraf.

If you use Spork in an academic context, please cite the related research paper:

S. Larsen, J. -R. Falleri, B. Baudry and M. Monperrus, "Spork: Structured Merge for Java with Formatting Preservation," in IEEE Transactions on Software Engineering, doi: 10.1109/TSE.2022.3143766.

You may export a citation in various formats using the Cite this repository button to the right. See the GitHub docs for more info.

Master's thesis

Spork was created as part of a master's thesis project. If you want to learn more about Spork in terms of theory and design, the thesis is freely available.

Attribution

Spork is built on top of a few pieces of fantastic software, most notably:

The merge implementation in Spork is based on the 3DM merge algorithm by Tancred Lindholm.

Quickstart

Want to just try out Spork on a small merge scenario? Below are a few shell commands that will download Spork along with a sample merge scenario, and then run it!

```bash

Download Spork

wget https://github.com/KTH/spork/releases/download/v0.5.0/spork-0.5.0.jar -O spork.jar

Download a sample merge scenario

wget https://raw.githubusercontent.com/KTH/spork/fe906f537d1bb7205256d1fe81fda9f323849a60/src/test/resources/clean/bothmodified/moveif/Left.java wget https://raw.githubusercontent.com/KTH/spork/fe906f537d1bb7205256d1fe81fda9f323849a60/src/test/resources/clean/bothmodified/moveif/Base.java wget https://raw.githubusercontent.com/KTH/spork/fe906f537d1bb7205256d1fe81fda9f323849a60/src/test/resources/clean/bothmodified/moveif/Right.java

You should now have spork.jar, Left.java, Base.java and Right.java in your local directory

a line based-merge is not possible

diff3 Left.java Base.java Right.java -m -A

an AST-merge with Spork does

java -jar spork.jar Left.java Base.java Right.java ```

It should print the result of the merge to stdout. See Base.java for the original version, and Left.java and Right.java for the respective changes. They should all be neatly integrated into the resulting merge. For more on using Spork, see Usage.

Usage

You can find a pre-built jar-file under releases. The jar-file includes all dependencies, so all you need is a Java runtime. Download the jar and run it like so:

Important: Spork requires a Java runtime version 8 or higher to run.

java -jar path/to/spork/jar <left> <base> <right>

The left, base and right arguments are required, and represent the left, base and right revisions, respectively. The base revision should be the best common ancestor of the left and right revisions.

For a full listing of the command line options, supply the -h option. It will produce the following output.

Usage: spork [-eghlV] [-o=<out>] LEFT BASE RIGHT The Spork command line app. LEFT Path to the left revision. BASE Path to the base revision. RIGHT Path to the right revision. -e, --exit-on-error Disable line-based fallback if the structured merge encounters an error. -g, --git-mode Enable Git compatibility mode. Required to use Spork as a Git merge driver. -h, --help Show this help message and exit. -l, --logging Enable logging output. -o, --output=<out> Path to the output file. Existing files are overwritten. -V, --version Print version information and exit.

Naturally, if you want the absolute latest version, you will have to build Spork yourself.

Build

Maven can be used to build the latest version of Spork.

Note: Requires JDK8+ to build.

mvn clean compile package -DskipTests

This will produce a jar-file in the target directory called something along the lines of spork-x.x.x.jar. Run the jar with java -jar path/to/spork/jar.

Configure as a Git merge driver

When Git performs a merge and encounters a file that has been edited in both revisions under merge, it will invoke a merge driver to merge the conflicting versions. It's a very simple thing to configure Spork as a merge driver for Java files, all you need is to add a couple of lines to a couple of configuration files. First, let's create a .gitattributes file and specify to use Spork as a merge driver for Java files. Put the following content in your .gitattributes file (you may all ready have one, check your home directory):

*.java merge=spork

spork doesn't mean anything to Git yet, we need to actually define the merge driver called spork. We do that in the .gitconfig file, typically located in your home directory. You should put the following content into it:

``` [core] attributesfile = /path/to/.gitattributes

[merge "spork"] name = spork driver = java -jar /path/to/spork.jar merge --git-mode %A %O %B -o %A ```

Then replace /path/to/.gitattributes with the absolute path to the .gitattributes file you edited/created first, and replace /path/to/spork.jar with the absolute path to the Spork jar-file. With that done, Spork will be used as the merge driver for Java files!

Important: The --git-mode option is required to use Spork as a Git merge driver. If you find that Spork always reverts to line-based merge, then that option is probably missing in the driver option that invokes Spork.

License

Unless otherwise stated, files in Spork are under the MIT license.

Experimental: compile as a native image

Spork can be compiled to a native executable file using GraalVM. To do so, you need to first install GraalVM's JDK for Java 17 (Spork does not support Java 21 yet, see #479). Running mvn package -P native will then generate a native image in target/spork.

Note: the native image is known to behave differently to the .jar file, producing different conflict resolution results. Help to debug this would be welcome.

Owner

  • Name: ASSERT
  • Login: ASSERT-KTH
  • Kind: organization
  • Location: Sweden

assertEquals("Research group at KTH Royal Institute of Technology, Stockholm, Sweden", description);

Citation (CITATION.cff)

# This CITATION.cff file was generated with cffinit.
# Visit https://bit.ly/cffinit to generate yours today!

cff-version: 1.2.0
title: >-
    Spork - AST-based merge for Java
message: >-
  If you use this software in an academic context,
  please cite using this metadata.
type: software
url: https://github.com/kth/spork
authors:
  - given-names: Simon
    family-names: Larsén
    email: slarse@slar.se
preferred-citation:
  type: article
  authors:
  - given-names: Simon
    family-names: Larsén
    email: slarse@kth.se
    affiliation: KTH
  - given-names: Jean-Rémy
    family-names: Falleri
    email: jean-remy.falleri@u-bordeaux.fr
    affiliation: 'Univ. Bordeaux, Bordeaux INP, CNRS, LaBRI, IUF'
  - given-names: Benoit
    family-names: Baudry
    email: baudry@kth.se
    affiliation: KTH
  - given-names: Martin
    family-names: Monperrus
    email: monperrus@kth.se
    affiliation: KTH
  doi: "10.1109/TSE.2022.3143766"
  journal: "IEEE Transactions on Software Engineering"
  start: 1 # First page number
  end: 1 # Last page number
  title: "Spork: Structured Merge for Java with Formatting Preservation"
  year: 2022

GitHub Events

Total
  • Watch event: 11
  • Delete event: 9
  • Issue comment event: 20
  • Push event: 4
  • Pull request event: 24
  • Fork event: 1
  • Create event: 12
Last Year
  • Watch event: 11
  • Delete event: 9
  • Issue comment event: 20
  • Push event: 4
  • Pull request event: 24
  • Fork event: 1
  • Create event: 12

Issues and Pull Requests

Last synced: 10 months ago

All Time
  • Total issues: 0
  • Total pull requests: 4
  • Average time to close issues: N/A
  • Average time to close pull requests: 5 days
  • Total issue authors: 0
  • Total pull request authors: 3
  • Average comments per issue: 0
  • Average comments per pull request: 0.75
  • Merged pull requests: 2
  • Bot issues: 0
  • Bot pull requests: 2
Past Year
  • Issues: 0
  • Pull requests: 4
  • Average time to close issues: N/A
  • Average time to close pull requests: 5 days
  • Issue authors: 0
  • Pull request authors: 3
  • Average comments per issue: 0
  • Average comments per pull request: 0.75
  • Merged pull requests: 2
  • Bot issues: 0
  • Bot pull requests: 2
Top Authors
Issue Authors
  • wetneb (4)
Pull Request Authors
  • dependabot[bot] (57)
  • wetneb (6)
  • slarse (4)
  • monperrus (3)
  • jrfaller (1)
  • kjy5 (1)
  • ada4a (1)
Top Labels
Issue Labels
Pull Request Labels
dependencies (57) java (31) github_actions (26)

Dependencies

pom.xml maven
  • ch.qos.logback:logback-classic 1.2.11
  • fr.inria.gforge.spoon.labs:gumtree-spoon-ast-diff 1.46
  • fr.inria.gforge.spoon:spoon-core 10.0.0
  • info.picocli:picocli 4.6.3
  • org.eclipse.jgit:org.eclipse.jgit 6.0.0.202111291000-r
  • org.jetbrains.kotlin:kotlin-stdlib-jdk8 1.6.10
  • org.slf4j:slf4j-api 1.7.36
  • org.jetbrains.kotlin:kotlin-test 1.6.10 test
  • org.junit.jupiter:junit-jupiter 5.8.2 test
.github/workflows/tests.yml actions
  • actions/cache fd5de65bc895cf536527842281bea11763fefd77 composite
  • actions/checkout 2541b1294d2704b0964813337f33b291d3f8596b composite
  • actions/setup-java 2c7a4878f5d120bd643426d54ae1209b29cc01a3 composite
  • actions/setup-python b55428b1882923874294fa556849718a1d7f2ca5 composite
  • codecov/codecov-action 81cd2dc8148241f03f5839d295e000b8f761e378 composite