Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SJSW integration #194

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
2 changes: 1 addition & 1 deletion .github/workflows/buildPeass.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
mvn -version
fi
shell: bash
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Install git-crypt
run: |
if [ "$RUNNER_OS" == "Linux" ]; then
Expand Down
11 changes: 11 additions & 0 deletions analysis/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
</build>

<dependencies>
<dependency>
<groupId>io.github.terahidro2003</groupId>
<artifactId>sfsw</artifactId>
<version>0.2.0</version>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
Expand All @@ -49,6 +54,12 @@
<groupId>de.dagere.peass</groupId>
<artifactId>measurement</artifactId>
<version>${project.version}</version>
<exclusions>
<exclusion>
<artifactId>sfsw</artifactId>
<groupId>io.github.terahidro2003</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>de.dagere.peass</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@

import org.apache.commons.io.FileUtils;

import difflib.Delta;
import difflib.DiffUtils;
import difflib.Patch;
import com.github.difflib.DiffUtils;
import com.github.difflib.patch.AbstractDelta;
import com.github.difflib.patch.Patch;


public class GuessDecider {

Expand Down Expand Up @@ -40,7 +41,7 @@ public Guess guess(Set<String> methods) throws IOException {
Patch<String> patch = getDiff(method);

for (Guesser guesser : Guesser.allGuessers) {
for (Delta<String> delta : patch.getDeltas()) {
for (AbstractDelta<String> delta : patch.getDeltas()) {
if (guesser.isGuessTrue(delta)) {
currentGuess.add(guesser);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
import java.util.LinkedList;
import java.util.List;

import com.github.difflib.patch.AbstractDelta;

import de.dagere.peass.analysis.guessing.GuessDecider.ConditionChecker;
import difflib.Delta;

public class Guesser {

Expand Down Expand Up @@ -60,12 +61,12 @@ public class Guesser {
this.direction = direction;
}

boolean isGuessTrue(Delta<String> delta) {
boolean isGuessTrue(AbstractDelta<String> delta) {
boolean fullfills = false;
if (check(delta.getOriginal().getLines(), checker) && check(delta.getRevised().getLines(), checkerOld)) {
if (check(delta.getSource().getLines(), checker) && check(delta.getTarget().getLines(), checkerOld)) {
fullfills = true;
}
if (check(delta.getOriginal().getLines(), checkerOld) && check(delta.getRevised().getLines(), checker)) {
if (check(delta.getSource().getLines(), checkerOld) && check(delta.getTarget().getLines(), checker)) {
fullfills = true;
}
return fullfills;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

import java.util.List;

import com.github.difflib.patch.AbstractDelta;

import de.dagere.peass.analysis.guessing.GuessDecider.ConditionChecker;
import difflib.Delta;

class OneSideGuesser extends Guesser {

Expand All @@ -12,9 +13,9 @@ class OneSideGuesser extends Guesser {
}

@Override
boolean isGuessTrue(Delta<String> delta) {
List<String> lines = delta.getRevised().getLines();
List<String> lines2 = delta.getOriginal().getLines();
boolean isGuessTrue(AbstractDelta<String> delta) {
List<String> lines = delta.getTarget().getLines();
List<String> lines2 = delta.getSource().getLines();
if (lines2.size() < lines.size()) {
return testOneSideCondition(checker, lines, lines2);
} else if (lines2.size() > lines.size()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
import java.util.Map.Entry;
import java.util.Set;

import com.github.difflib.DiffUtils;
import com.github.difflib.patch.AbstractDelta;
import com.github.difflib.patch.Patch;
import com.github.javaparser.ast.CompilationUnit;

import de.dagere.nodeDiffDetector.data.MethodCall;
Expand All @@ -20,9 +23,6 @@
import de.dagere.nodeDiffDetector.utils.JavaParserProvider;
import de.dagere.peass.config.ExecutionConfig;
import de.dagere.peass.folders.PeassFolders;
import difflib.Delta;
import difflib.DiffUtils;
import difflib.Patch;

public class PropertyChangeGuesser {

Expand All @@ -45,9 +45,9 @@ public Set<String> getGuesses(final PeassFolders folders, final Entry<MethodCall
final String sourceOld = cache.getMethodSource(changedEntity.getKey(), method, fileOld);
final Patch<String> changedLinesMethod = DiffUtils.diff(Arrays.asList(sourceOld.split("\n")), Arrays.asList(source.split("\n")));

for (final Delta<String> delta : changedLinesMethod.getDeltas()) {
getDeltaGuess(guessedTypes, (delta.getOriginal().getLines()));
getDeltaGuess(guessedTypes, (delta.getRevised().getLines()));
for (final AbstractDelta<String> delta : changedLinesMethod.getDeltas()) {
getDeltaGuess(guessedTypes, (delta.getSource().getLines()));
getDeltaGuess(guessedTypes, (delta.getTarget().getLines()));
}
}
}
Expand Down
8 changes: 1 addition & 7 deletions dependency/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -181,16 +181,10 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.googlecode.java-diff-utils</groupId>
<artifactId>diffutils</artifactId>
<version>1.3.0</version>
</dependency>

<dependency>
<groupId>org.apache.groovy</groupId>
<artifactId>groovy-astbuilder</artifactId>
<version>4.0.15</version>
<version>4.0.22</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@

import org.apache.commons.io.FileUtils;

import com.github.difflib.DiffUtils;
import com.github.difflib.patch.Patch;

import de.dagere.nodeDiffDetector.data.MethodCall;
import de.dagere.nodeDiffDetector.diffDetection.FileComparisonUtil;
import de.dagere.nodeDiffDetector.sourceReading.MethodReader;
import de.dagere.peass.config.ExecutionConfig;
import de.dagere.peass.dependency.traces.diff.DiffUtilJava;
import difflib.DiffUtils;
import difflib.Patch;

public class MethodChangeReader {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.github.difflib.DiffUtils;
import com.github.difflib.patch.AbstractDelta;
import com.github.difflib.patch.DeltaType;
import com.github.difflib.patch.Patch;

import de.dagere.nodeDiffDetector.data.MethodCall;
import de.dagere.nodeDiffDetector.data.Type;
import de.dagere.nodeDiffDetector.diffDetection.ClazzChangeData;
Expand All @@ -40,10 +45,6 @@
import de.dagere.peass.vcs.CommitIteratorGit;
import de.dagere.peass.vcs.GitUtils;
import de.dagere.requitur.Sequitur;
import difflib.Delta;
import difflib.Delta.TYPE;
import difflib.DiffUtils;
import difflib.Patch;

public class PropertyReadHelper {

Expand Down Expand Up @@ -263,11 +264,11 @@ public void getKeywordChanges(final ChangeProperty property, final MethodChangeR

final Map<String, Integer> vNewkeywords = new HashMap<>();
final Map<String, Integer> vOldkeywords = new HashMap<>();
for (final Delta<String> changeSet : patch.getDeltas()) {
for (final String line : changeSet.getOriginal().getLines()) {
for (final AbstractDelta<String> changeSet : patch.getDeltas()) {
for (final String line : changeSet.getSource().getLines()) {
getKeywordCount(vOldkeywords, line);
}
for (final String line : changeSet.getRevised().getLines()) {
for (final String line : changeSet.getTarget().getLines()) {
getKeywordCount(vNewkeywords, line);
}
}
Expand Down Expand Up @@ -357,12 +358,12 @@ public static void determineTraceSizeChanges(final ChangeProperty property, fina
LOG.debug(patch);

int added = 0, removed = 0;
for (final Delta<String> delta : patch.getDeltas()) {
if (delta.getType().equals(TYPE.DELETE)) {
for (final AbstractDelta<String> delta : patch.getDeltas()) {
if (delta.getType().equals(DeltaType.DELETE)) {
removed++;
} else if (delta.getType().equals(TYPE.INSERT)) {
} else if (delta.getType().equals(DeltaType.INSERT)) {
added++;
} else if (delta.getType().equals(TYPE.CHANGE)) {
} else if (delta.getType().equals(DeltaType.CHANGE)) {
added++;
removed++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.io.FileFilter;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
Expand All @@ -14,20 +13,15 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import de.dagere.nodeDiffDetector.data.MethodCall;
import de.dagere.nodeDiffDetector.data.Type;
import de.dagere.nodeDiffDetector.diffDetection.ChangeDetector;
import de.dagere.nodeDiffDetector.diffDetection.ClazzChangeData;
import de.dagere.nodeDiffDetector.diffDetection.FileComparisonUtil;
import de.dagere.nodeDiffDetector.sourceReading.MethodReader;
import de.dagere.peass.config.ExecutionConfig;
import de.dagere.peass.dependency.analysis.data.CommitDiff;
import de.dagere.peass.execution.utils.TestExecutor;
import de.dagere.peass.folders.PeassFolders;
import de.dagere.peass.vcs.CommitIterator;
import de.dagere.peass.vcs.GitUtils;
import difflib.DiffUtils;
import difflib.Patch;

/**
* Determines whether a file has a change, and whether this change is class-wide or only affecting a method.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public void executeKoPeMeKiekerRun(final TestSet testsToUpdate, final String com

executor.prepareKoPeMeExecution(new File(commitLogFolder, "clean.txt"));
for (final TestMethodCall testcase : testsToUpdate.getTestMethods()) {
executor.executeTest(testcase, commitLogFolder, testTransformer.getConfig().getTimeoutInSeconds());
executor.executeTest(testcase, commitLogFolder, testTransformer.getConfig().getTimeoutInSeconds(), "");
}
LOG.debug("KoPeMe-Kieker-Run finished");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void checkTwiceExecution(String commit, String predecessor, Set<TestMetho
truncateLastRunResults();

for (TestMethodCall testcase : tests) {
executor.executeTest(testcase, twiceRunningLogFolder, transformer.getConfig().getExecutionConfig().getTimeout());
executor.executeTest(testcase, twiceRunningLogFolder, transformer.getConfig().getExecutionConfig().getTimeout(), "");

checkTestExistance(commit, testcase);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ public String getTestPackageName() {
* @param testname Name of the test that should be run
*/
@Override
protected void runTest(final File moduleFolder, final File logFile, TestMethodCall test, final String testname, final long timeout) {
protected void runTest(final File moduleFolder, final File logFile, TestMethodCall test, final String testname, final long timeout, final String profilerAgent) {
final Process process = buildGradleProcess(moduleFolder, logFile, test);
execute(testname, timeout, process);
adbPull();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,10 @@ public void cleanLastTest(final File module) {
}

@Override
public void executeTest(final TestMethodCall test, final File logFolder, final long timeout) {
public void executeTest(final TestMethodCall test, final File logFolder, final long timeout, final String profilerAgent) {
final File module = new File(folders.getProjectFolder(), test.getModule());
cleanLastTest(module);
runMethod(logFolder, test, module, timeout);
runMethod(logFolder, test, module, timeout, "");

cleanAboveSize(logFolder, "txt");
}
Expand All @@ -153,7 +153,7 @@ public void executeTest(final TestMethodCall test, final File logFolder, final l
* @param testname Name of the test that should be run
*/
@Override
protected void runTest(final File moduleFolder, final File methodLogFile, TestMethodCall test, final String testname, final long timeout) {
protected void runTest(final File moduleFolder, final File methodLogFile, TestMethodCall test, final String testname, final long timeout, final String profilerAgent) {
try {
final Process process = buildGradleProcess(moduleFolder, methodLogFile, test, "--tests", testname);
execute(testname, timeout, process);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Optional;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand Down Expand Up @@ -124,9 +125,9 @@ private void updateJava() {
}

@Override
public void executeTest(final TestMethodCall test, final File logFolder, final long timeout) {
public void executeTest(final TestMethodCall test, final File logFolder, final long timeout, final String profilerAgent) {
final File moduleFolder = new File(folders.getProjectFolder(), test.getModule());
runMethod(logFolder, test, moduleFolder, timeout);
runMethod(logFolder, test, moduleFolder, timeout, profilerAgent);

cleanAboveSize(logFolder, "txt");
}
Expand All @@ -138,9 +139,26 @@ public void executeTest(final TestMethodCall test, final File logFolder, final l
* @param testname Name of the test that should be run
*/
@Override
protected void runTest(final File module, final File logFile, TestMethodCall test, final String testname, final long timeout) {
protected void runTest(final File module, final File logFile, TestMethodCall test, final String testname, final long timeout, final String profilerAgent) {
try {
final Process process = buildMavenProcess(logFile, test, "-Dtest=" + testname);
LOG.info("Executing test with name {}", testname);
final Process process = buildMavenProcess(logFile, test, "-Dtest=" + testname, profilerAgent);
execute(testname, timeout, process);
} catch (final InterruptedException | IOException e) {
e.printStackTrace();
}
}

private void runTest(final File module, final File logFile, TestMethodCall test, final String testname, final long timeout, Optional<String> profilerAgent) {
try {
LOG.info("Executing test with name {}", testname);
final Process process;
if (profilerAgent.isPresent()) {
process = buildMavenProcess(logFile, test, "-Dtest=" + testname, profilerAgent.get());
} else {
process = buildMavenProcess(logFile, test, "-Dtest=" + testname);
}

execute(testname, timeout, process);
} catch (final InterruptedException | IOException e) {
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ protected String getTestGoal() {
return testGoal;
}

protected abstract void runTest(File moduleFolder, final File logFile, TestMethodCall test, final String testname, final long timeout);
protected abstract void runTest(File moduleFolder, final File logFile, TestMethodCall test, final String testname, final long timeout, final String profilerAgent);

protected void runMethod(final File logFolder, final TestMethodCall test, final File moduleFolder, final long timeout) {
protected void runMethod(final File logFolder, final TestMethodCall test, final File moduleFolder, final long timeout, final String profilerAgent) {
try (final JUnitTestShortener shortener = new JUnitTestShortener(testTransformer, moduleFolder, test.toEntity(), test.getMethod())) {
if (testTransformer.getConfig().isDirectlyMeasureKieker()) {
File fileToInstrument = shortener.getCalleeClazzFile();
Expand All @@ -68,7 +68,7 @@ protected void runMethod(final File logFolder, final TestMethodCall test, final
clean(cleanFile);

final File methodLogFile = getMethodLogFile(logFolder, test);
runTest(moduleFolder, methodLogFile, test, test.getClazz(), timeout);
runTest(moduleFolder, methodLogFile, test, test.getClazz(), timeout, profilerAgent);
} catch (Exception e1) {
e1.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public int getJDKVersion() {

public abstract void prepareKoPeMeExecution(File logFile);

public abstract void executeTest(final TestMethodCall test, final File logFolder, long timeout);
public abstract void executeTest(final TestMethodCall test, final File logFolder, long timeout, String profilerAgent);

/**
* Deletes files which are bigger than sizeInMb Mb, since they pollute the disc space and will not be analyzable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void prepareKoPeMeExecution(final File logFile) {
}

@Override
public void executeTest(final TestMethodCall test, final File logFolder, final long timeout) {
public void executeTest(final TestMethodCall test, final File logFolder, final long timeout, final String profilerAgent) {
// TODO Auto-generated method stub

}
Expand Down
Loading