Skip to content

Commit

Permalink
Merge branch 'spgroup:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
galilasmb authored Sep 23, 2024
2 parents 96d392d + d71b493 commit 9722de8
Show file tree
Hide file tree
Showing 40 changed files with 1,135 additions and 40 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,34 @@ jobs:
run: ./gradlew assemble
- name: Gradle check
run: ./gradlew check --info
docker:
runs-on: ubuntu-22.04
permissions:
contents: read
packages: write
attestations: write
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Build and push Docker image
id: push
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
results.csv
/data/
/output/
*.iml
/bin/
Expand Down
21 changes: 21 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM amazoncorretto:8 as build

WORKDIR /usr/src/miningframework

COPY . .

RUN ./gradlew installDist

FROM amazoncorretto:8

WORKDIR /usr/src/miningframework

RUN yum -y update
RUN yum -y install git

COPY --from=build /usr/src/miningframework/build /usr/local/bin/miningframework
RUN chmod +x /usr/local/bin/miningframework/install/miningframework/bin/miningframework

ENV PATH="/usr/local/bin/miningframework/install/miningframework/bin:${PATH}"

ENTRYPOINT ["miningframework"]
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ For those, the order which the they are injected will be followed by the framewo
The framework uses [Google Guice](https://github.com/google/guice) to implement dependency injection, and inject the interface implementations.
So, to select the interface implementations you want to use in your desired instantiation of the framework, you also need to write a class such as [StaticAnalysisConflictsDetectionModule](https://github.com/spgroup/miningframework/blob/master/src/main/injectors/StaticAnalysisConflictsDetectionModule.groovy) in the injectors package, which acts as the dependency injector. This one, in particular, is used as a default injector if no other is specified when invoking the framework.

## Running Mining Framework with Docker

If you have Docker available on your machine, you might find it easier to start playing with Mining Framework by using our pre-built Docker image.

The image is built upon [Amazon Corretto](https://hub.docker.com/_/amazoncorretto) with Java 8, and provides an already compiled distribution of Mining Framework. To start running it with Docker, simply run:

```
docker run -v $PWD/output:/usr/src/miningframework/output/ -v $PWD/projects.csv:/usr/src/miningframework/projects.csv --rm ghcr.io/spgroup/miningframework:master projects.csv
```

## Running a specific framework instantiation

Expand Down Expand Up @@ -94,6 +103,9 @@ the Mining Framework take an input csv file and a name for the output dir
be used in the analysis. Required for (and
only considered when) running studies with
the CSDiff tool. Default: '{ } ( ) ; ,'
-log,--log-level <log level Specify the minimum log level: (OFF, FATAL,
ERROR, WARN, INFO, DEBUG, TRACE, ALL).
Default: "INFO"
-p,--push <link> Specify a git repository to upload the
output in the end of the analysis (format
https://github.com/<owner>/<name>
Expand All @@ -112,3 +124,7 @@ One can run the framework tests by running the check task:
`./gradlew check`

* To create new tests, you have to create a git repository with a merge scenario simulating a specific situation you want to test, add it to the `test_repositories` directory, add a corresponding entry to `src/test/input.csv`, and then create the Test class.

## Building

`.\gradlew build -x test`
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,7 @@ dependencies {
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.3.1'
testCompileOnly 'junit:junit:4.12'
testRuntimeOnly 'org.junit.vintage:junit-vintage-engine:5.3.1'
implementation 'org.apache.logging.log4j:log4j-api:2.23.1'
implementation 'org.apache.logging.log4j:log4j-core:2.23.1'
implementation 'org.json:json:20210307'
}
Binary file not shown.
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
certifi==2023.7.22
certifi==2024.7.4
chardet==3.0.4
idna==3.7
requests==2.32.0
urllib3==1.26.18
urllib3==1.26.19
pandas==2.0.3
seaborn==0.12.2
fpdf==1.7.2
Expand Down
6 changes: 5 additions & 1 deletion src/main/app/Main.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,20 @@ import arguments.Arguments
import arguments.InputParser

import exception.InvalidArgsException
import org.apache.logging.log4j.LogManager
import project.Project

import util.FileManager

class Main {
private static LOG = LogManager.getLogger(Main.class)

static main(args) {
ArgsParser argsParser = new ArgsParser()
try {
Arguments appArguments = argsParser.parse(args)

LOG.trace("Successfully parsed CLI args")

if (appArguments.isHelp()) {
argsParser.printHelp()
} else {
Expand Down
6 changes: 6 additions & 0 deletions src/main/arguments/ArgsParser.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package arguments
import exception.InvalidArgsException
import groovy.cli.commons.CliBuilder
import groovy.cli.commons.OptionAccessor
import org.apache.logging.log4j.Level

import java.text.ParseException
import java.text.SimpleDateFormat
Expand Down Expand Up @@ -33,6 +34,7 @@ class ArgsParser {
this.cli.k(longOpt: 'keep-projects', argName: 'keep projects', 'Specify that cloned projects must be kept after the analysis (those are kept in clonedRepositories/ )')
this.cli.e(longOpt: 'extension', args: 1, argName: 'file extenson', 'Specify the file extension that should be used in the analysis (e.g. .rb, .ts, .java, .cpp. Default: .java)')
this.cli.l(longOpt: 'language-separators', args: 1, argName: 'language syntactic separators', 'Specify the language separators that should be used in the analysis. Required for (and only considered when) running studies with the CSDiff tool. Default: \"{ } ( ) ; ,\"')
this.cli.log(longOpt: 'log-level', args: 1, argName: 'log level', 'Specify the minimum log level: (OFF, FATAL, ERROR, WARN, INFO, DEBUG, TRACE, ALL). Default: \"INFO\"')
}

Arguments parse(args) {
Expand Down Expand Up @@ -124,6 +126,10 @@ class ArgsParser {
if(this.options.l) {
args.setLanguageSyntacticSeparators(this.options.l)
}

if(this.options.log) {
args.setLogLevel(Level.toLevel(this.options.log))
}
}

private boolean repositoryExists(String repositoryURL) {
Expand Down
22 changes: 17 additions & 5 deletions src/main/arguments/Arguments.groovy
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package arguments

import injectors.StaticAnalysisConflictsDetectionModule
import org.apache.logging.log4j.Level
import org.apache.logging.log4j.core.config.Configurator

class Arguments {

private String inputPath
private String outputPath
private String sinceDate
Expand All @@ -16,6 +18,7 @@ class Arguments {
private boolean keepProjects
private String syntacticSeparators
private String fileExtension
private Level logLevel

Arguments() { // set the default values for all parameters
isHelp = false
Expand All @@ -29,9 +32,10 @@ class Arguments {
keepProjects = false
syntacticSeparators = '{ } ( ) ; ,'
fileExtension = 'java'
logLevel = Level.INFO
}

void setNumOfThreads (int numOfThreads) {
void setNumOfThreads(int numOfThreads) {
this.numOfThreads = numOfThreads
}

Expand Down Expand Up @@ -82,7 +86,7 @@ class Arguments {
int getNumOfThreads() {
return this.numOfThreads
}

String getInputPath() {
return inputPath
}
Expand All @@ -107,7 +111,7 @@ class Arguments {
return isHelp
}

boolean getKeepProjects () {
boolean getKeepProjects() {
return keepProjects
}

Expand All @@ -130,9 +134,17 @@ class Arguments {
boolean providedAccessKey() {
return accessKey.length() > 0
}

boolean isPushCommandActive() {
return !resultsRemoteRepositoryURL.equals('')
}

Level getLogLevel() {
return logLevel
}

void setLogLevel(Level logLevel) {
this.logLevel = logLevel
Configurator.setRootLevel(logLevel)
}
}
56 changes: 56 additions & 0 deletions src/main/injectors/GenericMergeModule.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package injectors

import com.google.inject.AbstractModule
import com.google.inject.multibindings.Multibinder
import interfaces.CommitFilter
import interfaces.DataCollector
import interfaces.OutputProcessor
import interfaces.ProjectProcessor
import org.apache.logging.log4j.LogManager
import org.apache.logging.log4j.Logger
import services.commitFilters.MutuallyModifiedFilesCommitFilter
import services.dataCollectors.GenericMerge.GenericMergeConfig
import services.dataCollectors.GenericMerge.GenericMergeDataCollector
import services.dataCollectors.GenericMerge.MergeConflictsComparator
import services.dataCollectors.GenericMerge.MergeToolsComparator
import services.dataCollectors.GenericMerge.ScenarioLOCsCounter
import services.dataCollectors.GenericMerge.UnstructuredMergeCollector
import services.outputProcessors.GenericMergeDataOutputProcessor
import services.projectProcessors.DummyProjectProcessor
import services.util.ci.CIPlatform
import services.util.ci.TravisPlatform

import java.nio.file.Files
import java.nio.file.Paths

class GenericMergeModule extends AbstractModule {
private static Logger LOG = LogManager.getLogger(GenericMergeModule.class)

@Override
protected void configure() {
Multibinder<ProjectProcessor> projectProcessorBinder = Multibinder.newSetBinder(binder(), ProjectProcessor.class)
projectProcessorBinder.addBinding().to(DummyProjectProcessor.class)

Multibinder<DataCollector> dataCollectorBinder = Multibinder.newSetBinder(binder(), DataCollector.class)
dataCollectorBinder.addBinding().to(ScenarioLOCsCounter.class)
dataCollectorBinder.addBinding().to(GenericMergeDataCollector.class)
dataCollectorBinder.addBinding().to(MergeToolsComparator.class)
dataCollectorBinder.addBinding().to(MergeConflictsComparator.class)
dataCollectorBinder.addBinding().to(UnstructuredMergeCollector.class)

Multibinder<OutputProcessor> outputProcessorBinder = Multibinder.newSetBinder(binder(), OutputProcessor.class)
outputProcessorBinder.addBinding().to(GenericMergeDataOutputProcessor.class)

bind(CommitFilter.class).to(MutuallyModifiedFilesCommitFilter.class)
bind(CIPlatform.class).to(TravisPlatform.class)

createExecutionReportsFile()
}

private static void createExecutionReportsFile() {
LOG.info("Creating Generic Merge report file")
Files.createDirectories(Paths.get(GenericMergeConfig.GENERIC_MERGE_REPORT_PATH))
def reportFile = new File(GenericMergeConfig.GENERIC_MERGE_REPORT_FILE_NAME)
reportFile.createNewFile()
}
}
8 changes: 8 additions & 0 deletions src/main/resources/log4j2.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Root Logger
rootLogger=info, STDOUT

# Direct log messages to stdout
appender.console.type = Console
appender.console.name = STDOUT
appender.console.layout.type=PatternLayout
appender.console.layout.pattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
14 changes: 14 additions & 0 deletions src/main/resources/log4j2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="INFO">
<Appenders>
<Console name="console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
</Console>
</Appenders>

<Loggers>
<Root level="info">
<AppenderRef ref="console" />
</Root>
</Loggers>
</Configuration>
Loading

0 comments on commit 9722de8

Please sign in to comment.