Skip to content

Commit

Permalink
[misc] Update dependencies and formatting (#459)
Browse files Browse the repository at this point in the history
* Fix auto-formatting

* Bump logback to version 1.4.11

* Bump maven shade plugin to 3.5.0

* Bump various actions
  • Loading branch information
slarse authored Sep 15, 2023
1 parent 0b9e858 commit 10f2f22
Show file tree
Hide file tree
Showing 28 changed files with 169 additions and 104 deletions.
22 changes: 11 additions & 11 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ jobs:
os: [ ubuntu-latest, macos-latest ]

steps:
- uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b
- uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac
with:
fetch-depth: 2
- uses: actions/setup-java@2c7a4878f5d120bd643426d54ae1209b29cc01a3
- uses: actions/setup-java@cd89f46ac9d01407894225f350157564c9c7cee2
with:
java-version: 11
java-package: jdk
Expand All @@ -40,7 +40,7 @@ jobs:
run: echo "::set-output name=date::$(/bin/date -u "+%Y%m%d")"
shell: bash
- name: Use Maven dependency cache
uses: actions/cache@fd5de65bc895cf536527842281bea11763fefd77
uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84
with:
path: ~/.m2/repository
key: ${{ runner.os }}-${{ steps.get-date.outputs.date }}-${{ hashFiles('**/pom.xml') }}
Expand All @@ -51,7 +51,7 @@ jobs:
- name: Run tests
run: mvn test
- name: Upload coverage report to Codecov
uses: codecov/codecov-action@81cd2dc8148241f03f5839d295e000b8f761e378
uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d
with:
fail_ci_if_error: false

Expand All @@ -60,16 +60,16 @@ jobs:
if: ${{ github.ref == 'refs/heads/master' }}

steps:
- uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b
- uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac
with:
fetch-depth: 0 # fetch everything
- uses: actions/setup-java@2c7a4878f5d120bd643426d54ae1209b29cc01a3
- uses: actions/setup-java@cd89f46ac9d01407894225f350157564c9c7cee2
with:
java-version: 11
java-package: jdk
architecture: x64
distribution: ${{ env.JAVA_DISTRIBUTION }}
- uses: actions/setup-python@b55428b1882923874294fa556849718a1d7f2ca5
- uses: actions/setup-python@61a6322f88396a6271a6ee3565807d608ecaddd1
with:
python-version: 3.8

Expand All @@ -78,7 +78,7 @@ jobs:
run: echo "::set-output name=date::$(/bin/date -u "+%Y%m%d")"
shell: bash
- name: Use Maven dependency cache
uses: actions/cache@fd5de65bc895cf536527842281bea11763fefd77
uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84
with:
path: ~/.m2/repository
key: ${{ runner.os }}-${{ steps.get-date.outputs.date }}-${{ hashFiles('**/pom.xml') }}
Expand All @@ -95,10 +95,10 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b
- uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac
with:
fetch-depth: 0 # fetch everything
- uses: actions/setup-java@2c7a4878f5d120bd643426d54ae1209b29cc01a3
- uses: actions/setup-java@cd89f46ac9d01407894225f350157564c9c7cee2
with:
java-version: 11
java-package: jdk
Expand All @@ -110,7 +110,7 @@ jobs:
run: echo "::set-output name=date::$(/bin/date -u "+%Y%m%d")"
shell: bash
- name: Use Maven dependency cache
uses: actions/cache@fd5de65bc895cf536527842281bea11763fefd77
uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84
with:
path: ~/.m2/repository
key: ${{ runner.os }}-${{ steps.get-date.outputs.date }}-${{ hashFiles('**/pom.xml') }}
Expand Down
14 changes: 9 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.11</version>
<version>1.4.11</version>
</dependency>

<!-- cli -->
Expand Down Expand Up @@ -100,7 +100,7 @@
<!-- shade plugin for fat jar -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.3.0</version>
<version>3.5.0</version>
<executions>
<execution>
<phase>package</phase>
Expand Down Expand Up @@ -246,15 +246,15 @@
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>2.21.0</version>
<version>2.39.0</version>
<configuration>
<java>
<includes>
<include>src/main/java/**/*.java</include>
<include>src/test/java/**/*.java</include>
</includes>
<googleJavaFormat>
<version>1.9</version>
<version>1.17.0</version>
<style>AOSP</style>
</googleJavaFormat>
</java>
Expand All @@ -265,7 +265,11 @@
<include>src/test/kotlin/**/*.kt</include>
</includes>
<ktlint>
<version>0.37.2</version>
<version>0.48.0</version>
<editorConfigOverride>
<ij_kotlin_allow_trailing_comma>true</ij_kotlin_allow_trailing_comma>
<ij_kotlin_allow_trailing_comma_on_call_site>true</ij_kotlin_allow_trailing_comma_on_call_site>
</editorConfigOverride>
</ktlint>
</kotlin>
</configuration>
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/se/kth/spork/spoon/printer/OperatorHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ public static String getOperatorText(Object o) {
}
}

/** @return java source code representation of a pre or post unary operator. */
/**
* @return java source code representation of a pre or post unary operator.
*/
public static String getOperatorText(UnaryOperatorKind o) {
switch (o) {
case POS:
Expand All @@ -72,7 +74,9 @@ public static String getOperatorText(UnaryOperatorKind o) {
}
}

/** @return java source code representation of a binary operator. */
/**
* @return java source code representation of a binary operator.
*/
public static String getOperatorText(BinaryOperatorKind o) {
switch (o) {
case OR:
Expand Down
4 changes: 3 additions & 1 deletion src/main/kotlin/se/kth/spork/base3dm/TdmMerge.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ private val LOGGER: LazyLogger = LazyLogger(Object::class.java)
*/
fun <T : ListNode, V> resolveRawMerge(base: ChangeSet<T, V>, delta: ChangeSet<T, V>) {
for (pcs in delta.pcsSet) {
if (!delta.contains(pcs)) // was removed as otherPcs
if (!delta.contains(pcs)) {
// was removed as otherPcs
continue
}

// We need to merge the content of the predecessor and successor, but we can skip the parent.
// The reason is that a parent node that never appears as a predecessor or successor will never be
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ private fun getContent(elem: CtElement): RoledValues {
if (elem is CtComment) {
val rawContent = elem.rawContent
val content = RoledValue(
CtRole.COMMENT_CONTENT, elem.getValueByRole<Any>(CtRole.COMMENT_CONTENT)
CtRole.COMMENT_CONTENT,
elem.getValueByRole<Any>(CtRole.COMMENT_CONTENT),
)
content.putMetadata(RoledValue.Key.RAW_CONTENT, rawContent)
rvs.add(content)
Expand Down
56 changes: 40 additions & 16 deletions src/main/kotlin/se/kth/spork/spoon/Spoon3dmMerge.kt
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ object Spoon3dmMerge {
left: T,
right: T,
baseMatcher: (ITree, ITree) -> Matcher,
leftRightMatcher: (ITree, ITree) -> Matcher
leftRightMatcher: (ITree, ITree) -> Matcher,
): Pair<T, Int> {
val start = System.nanoTime()

Expand All @@ -106,18 +106,29 @@ object Spoon3dmMerge {
// 3DM PHASE
LOGGER.info { "Mapping nodes to class representatives" }
var classRepMap = createClassRepresentativesMapping(
base, left, right, baseLeft, baseRight, leftRight
base,
left,
right,
baseLeft,
baseRight,
leftRight,
)
LOGGER.info { "Converting Spoon trees to PCS triples" }
val t0 = PcsBuilder.fromSpoon(base, Revision.BASE)
val t1 = PcsBuilder.fromSpoon(left, Revision.LEFT)
val t2 = PcsBuilder.fromSpoon(right, Revision.RIGHT)
LOGGER.info { "Computing raw PCS merge" }
var delta = ChangeSet(
classRepMap, ::getContent, t0, t1, t2
classRepMap,
::getContent,
t0,
t1,
t2,
)
val t0Star = ChangeSet(
classRepMap, ::getContent, t0
classRepMap,
::getContent,
t0,
)
LOGGER.info { "Resolving final PCS merge" }
resolveRawMerge(t0Star, delta)
Expand All @@ -126,11 +137,19 @@ object Spoon3dmMerge {
LOGGER.info { "Root conflicts detected, restarting merge" }
LOGGER.info { "Removing root conflicting nodes from tree matchings" }
removeFromMappings(
rootConflictingNodes, baseLeft, baseRight, leftRight
rootConflictingNodes,
baseLeft,
baseRight,
leftRight,
)
LOGGER.info { "Mapping nodes to class representatives" }
classRepMap = createClassRepresentativesMapping(
base, left, right, baseLeft, baseRight, leftRight
base,
left,
right,
baseLeft,
baseRight,
leftRight,
)
LOGGER.info { "Computing raw PCS merge" }
delta = ChangeSet(classRepMap, ::getContent, t0, t1, t2)
Expand All @@ -141,31 +160,35 @@ object Spoon3dmMerge {
// INTERPRETER PHASE
LOGGER.info { "Interpreting resolved PCS merge" }
val structuralConflictHandlers = Arrays.asList(
MethodOrderingConflictHandler(), OptimisticInsertInsertHandler()
MethodOrderingConflictHandler(),
OptimisticInsertInsertHandler(),
)
val contentConflictHandlers = Arrays.asList(
IsImplicitHandler(),
ModifierHandler(),
IsUpperHandler(),
CommentContentHandler()
CommentContentHandler(),
)
val merge = fromMergedPcs(
delta,
baseLeft,
baseRight,
structuralConflictHandlers,
contentConflictHandlers
contentConflictHandlers,
)

// we can be certain that the merge tree has the same root type as the three constituents,
// so this cast is safe
@Suppress("UNCHECKED_CAST") val mergeTree = merge.first as T
@Suppress("UNCHECKED_CAST")
val mergeTree = merge.first as T
val numConflicts = merge.second
val metadataElementConflicts = mergeMetadataElements(mergeTree, base, left, right)
LOGGER.info { "Checking for duplicated members" }
val duplicateMemberConflicts = eliminateDuplicateMembers(mergeTree)
LOGGER.info { "Merged in " + (System.nanoTime() - start).toDouble() / 1e9 + " seconds" }
return Pair(
mergeTree, numConflicts + metadataElementConflicts + duplicateMemberConflicts
mergeTree,
numConflicts + metadataElementConflicts + duplicateMemberConflicts,
)
}

Expand All @@ -190,7 +213,7 @@ object Spoon3dmMerge {
mergeTree: CtElement,
base: CtElement,
left: CtElement,
right: CtElement
right: CtElement,
): Int {
var numConflicts = 0
if (base.getMetadata(Parser.IMPORT_STATEMENTS) != null) {
Expand Down Expand Up @@ -261,7 +284,7 @@ object Spoon3dmMerge {
left,
right,
::matchTrees,
::matchTrees
::matchTrees,
)
numConflicts += mergePair.second
val mergedMember = mergePair.first
Expand All @@ -271,7 +294,8 @@ object Spoon3dmMerge {
// badness in the Spoon API: addTypeMember returns a generic type that depends only on the
// static type of the returned expression. So we must store the returned expression and declare
// the type, or Kotlin gets grumpy.
@Suppress("UNUSED_VARIABLE") val dontcare: CtType<*> = type.addTypeMember(mergedMember)
@Suppress("UNUSED_VARIABLE")
val dontcare: CtType<*> = type.addTypeMember(mergedMember)
}

return numConflicts
Expand All @@ -285,7 +309,7 @@ object Spoon3dmMerge {
private fun mergeCuComments(
base: CtElement,
left: CtElement,
right: CtElement
right: CtElement,
): Pair<String, Int> {
val baseComment = getCuComment(base)
val leftComment = getCuComment(left)
Expand All @@ -312,7 +336,7 @@ object Spoon3dmMerge {
private fun mergeImportStatements(
base: CtElement,
left: CtElement,
right: CtElement
right: CtElement,
): List<CtImport> {
val baseImports = HashSet(base.getMetadata(Parser.IMPORT_STATEMENTS) as Collection<CtImport>)
val leftImports = HashSet(left.getMetadata(Parser.IMPORT_STATEMENTS) as Collection<CtImport>)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@ class CommentContentHandler : ContentConflictHandler {
rightVal: Any,
baseElem: CtElement?,
leftElem: CtElement,
rightElem: CtElement
rightElem: CtElement,
): Pair<Any?, Boolean> {
return Pair(mergeComments(baseVal ?: "", leftVal, rightVal), false)
}

private fun mergeComments(base: Any, left: Any, right: Any): Any? {
val merge = lineBasedMerge(base.toString(), left.toString(), right.toString())
return if (merge.second > 0) null
else merge.first
return if (merge.second > 0) {
null
} else {
merge.first
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class ContentConflict(
val role: CtRole,
val base: RoledValue?,
val left: RoledValue,
val right: RoledValue
val right: RoledValue,
) {

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ interface ContentConflictHandler {
rightVal: Any,
baseElem: CtElement?,
leftElem: CtElement,
rightElem: CtElement
rightElem: CtElement,
): Pair<Any?, Boolean>

/** @return The role that this conflict handler deals with.
Expand Down
Loading

0 comments on commit 10f2f22

Please sign in to comment.