Skip to content

Commit

Permalink
feat: SoraldBit runs directly from the realtime module (eclipse#1246)
Browse files Browse the repository at this point in the history
  • Loading branch information
khaes-kth committed Feb 7, 2022
1 parent af5fb95 commit 7f4cd17
Show file tree
Hide file tree
Showing 19 changed files with 355 additions and 153 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -38,3 +38,4 @@ repairnator/repairnator-pipeline/output_astor
*.java-version

.DS_Store
treatedbuild.json
6 changes: 3 additions & 3 deletions src/docker-images/pipeline-dockerimage/Dockerfile
Expand Up @@ -10,13 +10,13 @@ COPY build_repairnator.sh /root/
COPY pipeline_launcher.sh /root/
COPY ODSmodel.bin /root/

RUN apt-get update
RUN apt-get update
RUN apt-get install xmlstarlet apt-utils cloc libgomp1 -y
RUN curl -O -s https://oss.sonatype.org/content/repositories/snapshots/fr/inria/repairnator/repairnator-pipeline/maven-metadata.xml
RUN echo `xmlstarlet sel -t -v '//latest' maven-metadata.xml` > /root/version.ini
RUN chmod +x /root/*.sh
RUN echo "Europe/Paris" > /etc/timezone
RUN /root/configure_git.sh
RUN echo "Europe/Paris" > /etc/timezone
RUN /root/configure_git.sh
RUN /root/build_repairnator.sh # This script builds the latest version available on central.
#COPY repairnator-pipeline.jar /root/repairnator-pipeline.jar # If you want to bypass it, and use a built jar, uncomment this line and comment the one above.

Expand Down
4 changes: 4 additions & 0 deletions src/docker-images/pipeline-dockerimage/pipeline_launcher.sh
Expand Up @@ -34,6 +34,10 @@ if [[ "$CREATE_PR" == 1 ]]; then
args="$args --createPR"
fi

if [[ "$CREATE_FORK" == 1 ]]; then
args="$args --createFork"
fi

if [[ "$SMTP_TLS" == 1 ]]; then
args="$args --smtpTLS"
fi
Expand Down
Expand Up @@ -67,6 +67,8 @@ public static void registerCommonArgs(JSAP jsap) throws JSAPException {
jsap.registerParameter(LauncherUtils.defineArgGithubUserEmail());
// --createPR
jsap.registerParameter(LauncherUtils.defineArgCreatePR());
// --createFork
jsap.registerParameter(LauncherUtils.defineArgCreateFork());

// --z3
jsap.registerParameter(LauncherUtils.defineArgZ3());
Expand Down Expand Up @@ -194,6 +196,9 @@ public static void initCommonConfig(RepairnatorConfig config, JSAPResult argumen
config.setFork(true);
}

if(LauncherUtils.getArgCreateFork(arguments))
config.setFork(true);

config.setZ3solverPath(new File(LauncherUtils.getArgZ3(arguments)).getAbsolutePath());
config.setWorkspacePath(LauncherUtils.getArgWorkspace(arguments));
if (LauncherUtils.getArgTmpDirAsWorkSpace(arguments)) {
Expand Down Expand Up @@ -302,6 +307,18 @@ public static boolean getArgCreatePR(JSAPResult arguments) {
return arguments.getBoolean("createPR");
}

public static Switch defineArgCreateFork() {
Switch sw = new Switch("createFork");
sw.setLongFlag("createFork");
sw.setDefault("false");
sw.setHelp("Activate the creation of a Pull Request in case of patch.");
return sw;
}

public static boolean getArgCreateFork(JSAPResult arguments) {
return arguments.getBoolean("createFork");
}

public static Switch defineArgCheckstyleMode() {
Switch sw = new Switch("checkstyle");
sw.setLongFlag("checkstyle");
Expand Down
Expand Up @@ -94,6 +94,9 @@ public RunnablePipelineContainer(DockerPoolManager poolManager, String imageId,
this.envValues.add("OUTPUT="+output);
this.envValues.add("TRAVIS_ENDPOINT="+this.repairnatorConfig.getJTravisEndpoint());
this.envValues.add("TRAVIS_TOKEN="+this.repairnatorConfig.getTravisToken());
if (this.repairnatorConfig.isFork()) {
this.envValues.add("CREATE_FORK=1");
}
if (this.repairnatorConfig.isCreatePR()) {
this.envValues.add("CREATE_PR=1");
}
Expand Down
6 changes: 6 additions & 0 deletions src/repairnator-pipeline/pom.xml
Expand Up @@ -54,6 +54,12 @@
<groupId>se.kth.castor</groupId>
<artifactId>sorald</artifactId>
<version>0.3.0</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.github.spoonlabs</groupId>
Expand Down
Expand Up @@ -13,6 +13,8 @@
import fr.inria.spirals.repairnator.process.step.checkoutrepository.CheckoutType;
import fr.inria.spirals.repairnator.serializer.AbstractDataSerializer;
import fr.inria.spirals.repairnator.utils.Utils;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.internal.storage.file.FileRepository;
import org.kohsuke.github.GHRepository;
import org.kohsuke.github.GitHub;
import org.slf4j.Logger;
Expand Down Expand Up @@ -281,6 +283,10 @@ public String getRepoLocalPath() {
return repoLocalPath;
}

public Git openAndGetGitObject() throws IOException {
return new Git(new FileRepository(repoLocalPath + File.separatorChar + ".git"));
}

public String getRepoToPushLocalPath() {
return repoToPushLocalPath;
}
Expand Down
Expand Up @@ -6,6 +6,7 @@
import java.util.List;

import fr.inria.spirals.repairnator.process.inspectors.ProjectInspector;
import org.apache.commons.io.FileUtils;
import org.eclipse.jgit.api.CloneCommand;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException;
Expand All @@ -19,80 +20,82 @@
public class CloneCheckoutBranchRepository extends AbstractStep {


public CloneCheckoutBranchRepository(ProjectInspector inspector) {
public CloneCheckoutBranchRepository(ProjectInspector inspector) {
super(inspector, true);
}
@Override

@Override
protected StepStatus businessExecute() {

GitRepositoryProjectInspector githubInspector;
GitRepositoryProjectInspector githubInspector;

try {
githubInspector = (GitRepositoryProjectInspector) getInspector();
} catch (Exception ex) {
this.addStepError("CloneCheckoutBranchRepository only supports GitHub commit references");
return StepStatus.buildError(this, PipelineState.NOTCLONABLE);
}

try {
githubInspector = (GitRepositoryProjectInspector) getInspector();
}catch (Exception ex){
this.addStepError("CloneCheckoutBranchRepository only supports GitHub commit references");
return StepStatus.buildError(this, PipelineState.NOTCLONABLE);
}

String repoUrl = githubInspector.getGitRepositoryUrl() + ".git";
String branch = null;
if (githubInspector.getGitRepositoryBranch() != null) {
branch = "refs/heads/" + githubInspector.getGitRepositoryBranch();
branch = "refs/heads/" + githubInspector.getGitRepositoryBranch();
}

String repoLocalPath = githubInspector.getRepoLocalPath();
try {
this.getLogger().info("Cloning repository " + repoUrl + " in the following directory: " + repoLocalPath);

List<String> branchList = new ArrayList<String>();
branchList.add(branch);


FileUtils.deleteDirectory(new File(repoLocalPath));

CloneCommand cloneRepositoryCommand = Git.cloneRepository()
.setCloneSubmodules(true)
.setURI( repoUrl )
.setDirectory(new File(repoLocalPath));
.setCloneSubmodules(true)
.setURI(repoUrl)
.setDirectory(new File(repoLocalPath));
if (branch != null) {
cloneRepositoryCommand.setBranchesToClone(branchList).setBranch(branch);
cloneRepositoryCommand.setBranchesToClone(branchList).setBranch(branch);
}

Git git = cloneRepositoryCommand.call();
Repository repository = git.getRepository();

List<RevCommit> commits = getBranchCommits(repository, repoLocalPath);

if (getConfig().isGitRepositoryFirstCommit()) {
git.checkout().setName(commits.get(commits.size()-1).getName()).call();
git.checkout().setName(commits.get(commits.size() - 1).getName()).call();
} else if (getConfig().getGitRepositoryIdCommit() != null) {
git.checkout().setName(getConfig().getGitRepositoryIdCommit()).call();
git.checkout().setName(getConfig().getGitRepositoryIdCommit()).call();
} else {
git.checkout().setName(commits.get(0).getName()).call();
git.checkout().setName(commits.get(0).getName()).call();
}

return StepStatus.buildSuccess(this);
} catch (Exception e) {
this.addStepError("Repository " + repoUrl + " cannot be cloned.", e);
return StepStatus.buildError(this, PipelineState.NOTCLONABLE);
}
}
private List<RevCommit> getBranchCommits(Repository repository, String path) {
String treeName = null;
try {
treeName = repository.getBranch();
} catch (IOException e1) {
e1.printStackTrace();
}
List<RevCommit> commitList = new ArrayList<>();
try {
Git git = Git.open(new File(path));
git.log().add(repository.resolve(treeName)).call().forEach(commitList::add);
} catch (RevisionSyntaxException | GitAPIException | IOException e) {
e.printStackTrace();
}

return commitList;
}

private List<RevCommit> getBranchCommits(Repository repository, String path) {

String treeName = null;
try {
treeName = repository.getBranch();
} catch (IOException e1) {
e1.printStackTrace();
}
List<RevCommit> commitList = new ArrayList<>();

try {
Git git = Git.open(new File(path));
git.log().add(repository.resolve(treeName)).call().forEach(commitList::add);
} catch (RevisionSyntaxException | GitAPIException | IOException e) {
e.printStackTrace();
}

return commitList;
}
}
Expand Up @@ -30,26 +30,25 @@ public class SoraldAdapter {
private static final String PREVIOUS_COMMIT_REF = "HEAD^";
private static SoraldAdapter _instance;

private String patchPrintingMode;
private String tmpdir;

public SoraldAdapter(String tmpdir, String patchPrintingMode) {
public SoraldAdapter(String tmpdir) {
this.tmpdir = tmpdir;
this.patchPrintingMode = patchPrintingMode;
}

public static SoraldAdapter getInstance(String tmpdir, String patchPrintingMode) {
public static SoraldAdapter getInstance(String tmpdir) {
if (_instance == null)
_instance = new SoraldAdapter(tmpdir, patchPrintingMode);
_instance = new SoraldAdapter(tmpdir);
return _instance;
}

// Clones the repo in @repoPath, fixes all violations, returns violation introducing file paths.
public Set<String> repairRepoAndReturnViolationIntroducingFiles (SoraldTargetCommit commit, String rule, String repoPath)
public Set<String> repairRepoAndReturnViolationIntroducingFiles (SoraldTargetCommit commit, String rule,
String repoPath, String printingMode)
throws ParseException, GitAPIException, IOException, InterruptedException {
logger.info("repairing: " + commit.getCommitUrl());

File repoDir = cloneRepo(commit.getRepoUrl(), commit.getCommitId(), repoPath);
File repoDir = cloneRepo(commit.getRepoUrl(), commit.getCommitId(), tmpdir + File.separator + repoPath);
logger.info("repo cloned: " + commit.getRepoName());

Map<String, Set<String>> ruleToIntroducingFiles = getIntroducedViolations(repoDir);
Expand All @@ -58,7 +57,9 @@ public Set<String> repairRepoAndReturnViolationIntroducingFiles (SoraldTargetCom
if(!ruleToIntroducingFiles.containsKey(rule))
return null;

repair(rule, repoDir, patchPrintingMode);
logger.info("new violations introduced for rule: " + rule);

// repair(rule, repoDir, printingMode);

return ruleToIntroducingFiles.get(rule);
}
Expand Down Expand Up @@ -209,9 +210,9 @@ public Map<String, Set<String>> listViolationLocations(File repoDir) throws IOEx



public File cloneRepo(String repoUrl, String commitId, String dirname)
public static File cloneRepo(String repoUrl, String commitId, String dirname)
throws IOException, GitAPIException {
File repoDir = new File(tmpdir + File.separator + dirname);
File repoDir = new File(dirname);

if (repoDir.exists())
FileUtils.deleteDirectory(repoDir);
Expand Down

0 comments on commit 7f4cd17

Please sign in to comment.