mirror of
https://github.com/corda/corda.git
synced 2025-06-14 05:08:18 +00:00
[EG-3461] removed dependency from tools.jar (#6631)
* removed dependency from tools.jar I removed the log line in /node/src/main/kotlin/net/corda/node/internal/NodeStartup.kt because I felt it was not so important and I modified the checkpoint agent detection simply using a static field (I tested both with and without the checkpoint agent running and detection works correctly) * move method to node-api to address review comments Co-authored-by: Walter Oggioni <walter.oggioni@r3.com>
This commit is contained in:
@ -0,0 +1,26 @@
|
||||
package net.corda.nodeapi.internal
|
||||
|
||||
import net.corda.core.internal.VisibleForTesting
|
||||
|
||||
class JVMAgentUtilities {
|
||||
|
||||
companion object {
|
||||
@VisibleForTesting
|
||||
@Suppress("NestedBlockDepth")
|
||||
fun parseDebugPort(args: Iterable<String>): Short? {
|
||||
val debugArgumentPrefix = "-agentlib:jdwp="
|
||||
for (arg in args) {
|
||||
if (arg.startsWith(debugArgumentPrefix)) {
|
||||
for (keyValuePair in arg.substring(debugArgumentPrefix.length + 1).split(",")) {
|
||||
val equal = keyValuePair.indexOf('=')
|
||||
if (equal >= 0 && keyValuePair.startsWith("address")) {
|
||||
val portBegin = (keyValuePair.lastIndexOf(':').takeUnless { it < 0 } ?: equal) + 1
|
||||
return keyValuePair.substring(portBegin).toShort()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package net.corda.nodeapi.internal
|
||||
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.junit.runners.Parameterized
|
||||
|
||||
@RunWith(Parameterized::class)
|
||||
class ParseDebugPortTest(private val args: Iterable<String>,
|
||||
private val expectedPort: Short?,
|
||||
@Suppress("unused_parameter") description : String) {
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
@Parameterized.Parameters(name = "{2}")
|
||||
fun load() = arrayOf(
|
||||
arrayOf(emptyList<String>(), null, "No arguments"),
|
||||
arrayOf(listOf("-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=1234"), 1234.toShort(), "Debug argument"),
|
||||
arrayOf(listOf("-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=0.0.0.0:7777"), 7777.toShort(), "Debug argument with bind address"),
|
||||
arrayOf(listOf("-agentlib:jdwp=transport=dt_socket,server=y,suspend=y"), null, "Debug argument without port"),
|
||||
arrayOf(listOf("-version", "-Dmy.jvm.property=someValue"), null, "Unrelated arguments"),
|
||||
arrayOf(listOf("-Dcapsule.jvm.args=\"-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=4321",
|
||||
"-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=1234"), 1234.toShort(), "Debug argument and capsule arguments")
|
||||
)
|
||||
}
|
||||
|
||||
@Test(timeout = 10_000)
|
||||
fun test() {
|
||||
val port = JVMAgentUtilities.parseDebugPort(args)
|
||||
Assert.assertEquals(expectedPort, port)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user