-
-
Notifications
You must be signed in to change notification settings - Fork 332
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Conflicts: # gradle.properties
- Loading branch information
Showing
31 changed files
with
484 additions
and
1,228 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 22 additions & 27 deletions
49
.../src/main/kotlin/io/mockk/proxy/common/transformation/RetransformInlineInstrumnetation.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,45 @@ | ||
package io.mockk.proxy.common.transformation | ||
|
||
import io.mockk.proxy.MockKAgentLogger | ||
import java.lang.instrument.UnmodifiableClassException | ||
|
||
abstract class RetransformInlineInstrumnetation( | ||
private val log: MockKAgentLogger, | ||
protected val log: MockKAgentLogger, | ||
private val specMap: ClassTransformationSpecMap | ||
) : InlineInstrumentation { | ||
|
||
protected abstract fun retransform(classes: Array<Class<*>>) | ||
protected abstract fun retransform(classesToTransform: Collection<Class<*>>) | ||
|
||
override fun execute(request: TransformationRequest): () -> Unit { | ||
val instrumentationRequest = specMap.applyTransformationRequest( | ||
request | ||
) | ||
|
||
val cancellation = { doCancel(request) } | ||
|
||
var cancellation: (() -> Unit)? = null | ||
try { | ||
val classes = instrumentationRequest.classes.toTypedArray() | ||
if (classes.isNotEmpty()) { | ||
log.trace("Retransforming ${specMap.transformationMap(instrumentationRequest)}") | ||
retransform(classes) | ||
specMap.applyTransformation(request) { | ||
cancellation = { doCancel(request) } | ||
|
||
retransform(it.classes) | ||
} | ||
} catch (ex: Exception) { | ||
log.warn(ex, "Failed to transform classes $instrumentationRequest") | ||
cancellation() | ||
} catch (ex: java.lang.Exception) { | ||
log.warn(ex, "Failed to transform classes ${request.classes}") | ||
cancellation?.invoke() | ||
return {} | ||
} | ||
|
||
return cancellation | ||
return cancellation ?: {} | ||
} | ||
|
||
private fun doCancel(request: TransformationRequest) { | ||
val reverseInstrumentationRequest = | ||
specMap.applyTransformationRequest( | ||
request.reverse() | ||
) | ||
|
||
try { | ||
val classes = reverseInstrumentationRequest.classes.toTypedArray() | ||
if (classes.isNotEmpty()) { | ||
log.trace("Retransforming back ${specMap.transformationMap(reverseInstrumentationRequest)}") | ||
retransform(classes) | ||
specMap.applyTransformation( | ||
request.reverse() | ||
) { | ||
val classes = it.classes | ||
if (classes.isNotEmpty()) { | ||
log.trace("Retransforming back ${it.classes}") | ||
retransform(classes) | ||
} | ||
} | ||
} catch (ex: Exception) { | ||
log.warn(ex, "Failed to revert class transformation ${reverseInstrumentationRequest.classes}") | ||
} catch (ex: UnmodifiableClassException) { | ||
log.warn(ex, "Failed to revert class transformation ${request.classes}") | ||
} | ||
} | ||
} |
Oops, something went wrong.