Skip to content

Commit

Permalink
Update CodeTFChange to include explicit DiffSide
Browse files Browse the repository at this point in the history
  • Loading branch information
drdavella authored and nahsra committed Feb 12, 2024
1 parent b8c58f3 commit f6b9740
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion framework/codemodder-base/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ dependencies {
api(libs.java.security.toolkit)
api(libs.commons.lang3)

api("io.codemodder:codetf-java:2.1.4")
api("io.codemodder:codetf-java:3.0.0")
api(libs.slf4j.api)
api(libs.javaparser.core)
api(libs.javaparser.symbolsolver.core)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.github.difflib.UnifiedDiffUtils;
import io.codemodder.codetf.CodeTFChange;
import io.codemodder.codetf.CodeTFChangesetEntry;
import io.codemodder.codetf.CodeTFDiffSide;
import io.codemodder.codetf.CodeTFPackageAction;
import io.codemodder.codetf.CodeTFResult;
import io.codemodder.javaparser.JavaParserChanger;
Expand Down Expand Up @@ -274,6 +275,7 @@ private CodeTFChange translateCodemodChangetoCodeTFChange(
codemodChange.lineNumber(),
emptyMap(),
changeDescription,
CodeTFDiffSide.LEFT,
pkgActions,
codemodChange.getParameters());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
import java.util.concurrent.*;
import java.util.stream.Collectors;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -135,6 +134,7 @@ public DependencyUpdateResult updateDependencies(
oldDeps.size() + 1,
Collections.emptyMap(),
"updated deps",
CodeTFDiffSide.LEFT,
List.of(packageAddResult),
List.of());
CodeTFChangesetEntry entry = new CodeTFChangesetEntry("deps.txt", diff, List.of(change));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.codemodder.DependencyGAV;
import io.codemodder.codetf.CodeTFChange;
import io.codemodder.codetf.CodeTFChangesetEntry;
import io.codemodder.codetf.CodeTFDiffSide;
import io.codemodder.plugins.maven.operator.POMDocument;
import java.io.File;
import java.net.URISyntaxException;
Expand Down Expand Up @@ -64,8 +65,10 @@ CodeTFChangesetEntry getChanges(

final String description = dependencyDescriptor.create(newDependency);
final Map<String, String> properties = buildPropertiesMap(description);
// Use RIGHT side as the diff side for now, as we are only adding dependencies.
final CodeTFChange change =
new CodeTFChange(position, properties, description, List.of(), List.of());
new CodeTFChange(
position, properties, description, CodeTFDiffSide.RIGHT, List.of(), List.of());

final List<String> patchDiff =
UnifiedDiffUtils.generateUnifiedDiff(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import io.codemodder.*;
import io.codemodder.codetf.CodeTFChange;
import io.codemodder.codetf.CodeTFChangesetEntry;
import io.codemodder.codetf.CodeTFDiffSide;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
Expand Down Expand Up @@ -244,18 +245,22 @@ void it_returns_expected_changeset_when_using_parent_pom() throws IOException {
// module1/pom.xml adding mars1 to dependencies
assertThat(changes.get(0).getPath()).isEqualTo("module1/pom.xml");
assertThat(changes.get(0).getChanges().get(0).getLineNumber()).isEqualTo(19);
assertThat(changes.get(0).getChanges().get(0).getDiffSide()).isEqualTo(CodeTFDiffSide.RIGHT);

// pom.xml adding mars1 to dependency management
assertThat(changes.get(1).getPath()).isEqualTo("pom.xml");
assertThat(changes.get(1).getChanges().get(0).getLineNumber()).isEqualTo(15);
assertThat(changes.get(1).getChanges().get(0).getDiffSide()).isEqualTo(CodeTFDiffSide.RIGHT);

// module1/pom.xml adding mars2 to dependencies
assertThat(changes.get(2).getPath()).isEqualTo("module1/pom.xml");
assertThat(changes.get(2).getChanges().get(0).getLineNumber()).isEqualTo(23);
assertThat(changes.get(2).getChanges().get(0).getDiffSide()).isEqualTo(CodeTFDiffSide.RIGHT);

// pom.xml adding mars2 to dependency management
assertThat(changes.get(3).getPath()).isEqualTo("pom.xml");
assertThat(changes.get(3).getChanges().get(0).getLineNumber()).isEqualTo(20);
assertThat(changes.get(3).getChanges().get(0).getDiffSide()).isEqualTo(CodeTFDiffSide.RIGHT);

// we don't have license facts for these dependencies, so we should be silent on their license!
boolean matchedLicenseFacts =
Expand Down

0 comments on commit f6b9740

Please sign in to comment.