Skip to content

Commit

Permalink
I think it works (but more testing needed)
Browse files Browse the repository at this point in the history
  • Loading branch information
Oshawk committed Feb 20, 2024
1 parent 4ffb1ff commit 977d6fc
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 25 deletions.
2 changes: 1 addition & 1 deletion scripts/pull.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ try {
git pull
if ($LASTEXITCODE -ne 0) {
git merge --abort
Exit 2
Exit 3
}

Exit 0
6 changes: 3 additions & 3 deletions scripts/pull.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

[ $# -eq 1 ] || exit 2

dir="$(dirname "$1")" || exit 2
dir="$(dirname "$1")" || exit 3

cd "$dir" || exit 2
cd "$dir" || exit 4

git pull || { git merge --abort; exit 2; }
git pull || { git merge --abort; exit 5; }

exit 0
10 changes: 5 additions & 5 deletions scripts/push.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@ try {

git reset
if ($LASTEXITCODE -ne 0) {
Exit 2
Exit 3
}

git add "$Repository"
if ($LASTEXITCODE -ne 0) {
Exit 2
Exit 4
}

try {
git commit -m "Update $(Split-Path "$Repository" -Leaf -ErrorAction Stop) repository"
git commit --allow-empty -m "Update $(Split-Path "$Repository" -Leaf -ErrorAction Stop) repository"
} catch {
Exit 2
Exit 5
}
if ($LASTEXITCODE -ne 0) {
Exit 2
Exit 6
}

git push
Expand Down
12 changes: 6 additions & 6 deletions scripts/push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

[ $# -eq 1 ] || exit 2

dir="$(dirname "$1")" || exit 2
file="$(basename "$1")" || exit 2
dir="$(dirname "$1")" || exit 3
file="$(basename "$1")" || exit 4

cd "$dir" || exit 2
cd "$dir" || exit 5

git reset || exit 2
git reset || exit 6

git add "$1" || exit 2
git add "$1" || exit 7

git commit -m "Update $file repository" || exit 2
git commit --allow-empty -m "Update $file repository" || exit 8

git push || { git reset --hard HEAD~1; exit 1; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fun getMainWindow(context: JadxPluginContext): JFrame {
val commonContext = commonContextField.get(context.guiContext)

val mainWindowField = Class.forName("jadx.gui.plugins.context.CommonGuiPluginsContext").getDeclaredField("mainWindow")
commonContextField.isAccessible = true
mainWindowField.isAccessible = true
val mainWindow = mainWindowField.get(commonContext) as JFrame

return mainWindow
Expand All @@ -41,7 +41,7 @@ class ConflictModal(parent: JFrame, remote: RemoteRename, local: LocalRename): J
init {
defaultCloseOperation = DISPOSE_ON_CLOSE

layout = GridLayout(1, 2)
contentPane = Box.createVerticalBox()

val boldFont = SimpleAttributeSet()
StyleConstants.setFontFamily(boldFont, "Monospaced")
Expand Down
9 changes: 9 additions & 0 deletions src/main/kotlin/uk/oshawk/jadx/collaboration/DataTypes.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package uk.oshawk.jadx.collaboration

import jadx.api.data.ICodeRename
import jadx.api.data.IJavaNodeRef
import jadx.api.data.impl.JadxCodeRename
import jadx.api.data.impl.JadxNodeRef

class NodeRef(
private val type: IJavaNodeRef.RefType,
Expand All @@ -21,6 +23,10 @@ class NodeRef(
override fun getDeclaringClass() = declaringClass
override fun getShortId() = shortId
override fun compareTo(other: IJavaNodeRef?) = COMPARATOR.compare(this, other)

fun convert(): JadxNodeRef {
return JadxNodeRef(type, declaringClass, shortId)
}
}

class ProjectRename(private val nodeRef: NodeRef, private val newName: String) : ICodeRename {
Expand All @@ -35,6 +41,9 @@ class ProjectRename(private val nodeRef: NodeRef, private val newName: String) :
override fun getNewName() = newName
override fun compareTo(other: ICodeRename?) = COMPARATOR.compare(this, other)

fun convert(): JadxCodeRename {
return JadxCodeRename(nodeRef.convert(), newName)
}
}

data class LocalRename(val nodeRef: NodeRef, val newName: String?, val lastPullNewName: String?)
Expand Down
19 changes: 11 additions & 8 deletions src/main/kotlin/uk/oshawk/jadx/collaboration/Plugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class Plugin(
LOG.info { "projectToLocalRepository: ${localRepository.renames.size} new local repository renames" }
}

private fun remoteRepositoryToLocalRepository(remoteRepository: RemoteRepository, localRepository: LocalRepository): Boolean {
private fun remoteRepositoryToLocalRepository(remoteRepository: RemoteRepository, localRepository: LocalRepository): Boolean? {
var remoteRepositoryRenamesIndex = 0
LOG.info { "remoteRepositoryToLocalRepository: ${remoteRepository.renames.size} remote repository renames" }

Expand Down Expand Up @@ -178,10 +178,13 @@ class Plugin(
} else {
// Conflict.
conflict = true
if (conflictResolver(context!!, remoteRepositoryRename, oldLocalRepositoryRename)!!) { // Use remote. TODO: Handle null return.
LocalRename(remoteRepositoryRename.nodeRef, remoteRepositoryRename.newName, remoteRepositoryRename.newName)
} else { // Use local.
LocalRename(oldLocalRepositoryRename.nodeRef, oldLocalRepositoryRename.newName, remoteRepositoryRename.newName)
when (conflictResolver(context!!, remoteRepositoryRename, oldLocalRepositoryRename)) {
true -> LocalRename(remoteRepositoryRename.nodeRef, remoteRepositoryRename.newName, remoteRepositoryRename.newName) // Use remote.
false -> LocalRename(oldLocalRepositoryRename.nodeRef, oldLocalRepositoryRename.newName, remoteRepositoryRename.newName) // Use local.
null -> {
LOG.error { "Conflict resolution failed." }
return null
}
}
}
}
Expand All @@ -199,7 +202,7 @@ class Plugin(

(this.context!!.args.codeData as JadxCodeData).renames = localRepository.renames
.filter { it.newName != null }
.map { ProjectRename(it.nodeRef, it.newName!!) }
.map { ProjectRename(it.nodeRef, it.newName!!).convert() } // The convert is needed due to interface replacement. I wish it wasn't.

LOG.info { "localRepositoryToProject: ${this.context!!.args.codeData.renames.size} new project renames" }

Expand Down Expand Up @@ -275,7 +278,7 @@ class Plugin(

val remoteRepository = readRemoteRepository() ?: return

remoteRepositoryToLocalRepository(remoteRepository, localRepository)
remoteRepositoryToLocalRepository(remoteRepository, localRepository) ?: return

writeLocalRepository(localRepository) ?: return

Expand All @@ -300,7 +303,7 @@ class Plugin(
remoteRepository = readRemoteRepository() ?: return

val conflict = remoteRepositoryToLocalRepository(remoteRepository, localRepository)
} while (conflict)
} while (conflict ?: return)

localRepositoryToRemoteRepository(localRepository, remoteRepository)

Expand Down

0 comments on commit 977d6fc

Please sign in to comment.