This repository has been archived by the owner on Nov 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
220 additions
and
121 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
22 changes: 0 additions & 22 deletions
22
src/main/java/com/bridgecrew/util/ApplicationServiceUtil.java
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.bridgecrew.commons | ||
|
||
import com.bridgecrew.commons.models.Request | ||
import com.bridgecrew.commons.models.Response | ||
import com.bridgecrew.utils.GlobalMapper | ||
import com.fasterxml.jackson.core.JsonProcessingException | ||
import com.intellij.openapi.components.Service | ||
import com.sun.jna.Native | ||
import org.eclipse.sisu.Nullable | ||
import org.slf4j.Logger | ||
import org.slf4j.LoggerFactory | ||
|
||
@Service | ||
class CommonsClient { | ||
|
||
private val logger: Logger = LoggerFactory.getLogger(javaClass) | ||
|
||
@Nullable | ||
private var commons: CommonsLibrary? = null | ||
|
||
init { | ||
try { | ||
val file = Native.extractFromResourcePath( | ||
"/lib/${System.mapLibraryName("commons-${getArch()}")}", | ||
javaClass.classLoader | ||
) | ||
logger.info("Loading commons lib from ${file.absolutePath}") | ||
commons = Native.load(file.absolutePath, CommonsLibrary::class.java) | ||
logger.info("Successfully loaded commons from ${file.absolutePath}") | ||
} catch (e: Exception) { | ||
logger.error("Failed to load commons lib", e) | ||
} | ||
} | ||
|
||
fun helloWorld() { | ||
commons?.HelloWorld() | ||
} | ||
|
||
fun add(a: Int, b: Int): Int { | ||
return commons?.Add(a, b) ?: 0 | ||
} | ||
|
||
fun handleRequest(request: Request?): Response { | ||
try { | ||
val requestJson = GlobalMapper.i().writeValueAsString(request) | ||
val response = commons?.HandleRequest(requestJson) | ||
return GlobalMapper.i().readValue(response, Response::class.java) | ||
} catch (e: JsonProcessingException) { | ||
logger.error("Failed to handle request", e) | ||
return Response(e.message) | ||
} | ||
} | ||
|
||
@Throws(Exception::class) | ||
private fun getArch(): String { | ||
return when (val arch = System.getProperty("os.arch").lowercase()) { | ||
"x86_64", "amd64" -> "x64" | ||
"arm", "arm64", "aarch64" -> "arm" | ||
else -> throw Exception("Unsupported architecture: $arch") | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.bridgecrew.commons | ||
|
||
import com.sun.jna.Library | ||
|
||
interface CommonsLibrary : Library { | ||
|
||
fun HelloWorld() | ||
|
||
fun Add(a: Int, b: Int): Int | ||
|
||
fun HandleRequest(request: String?): String? | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/kotlin/com/bridgecrew/commons/models/PluginCommonsResponse.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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.bridgecrew.commons.models | ||
|
||
open class PluginCommonsResponse( | ||
|
||
var error: String? | ||
) |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.bridgecrew.commons.models | ||
|
||
data class Request( | ||
var strings: List<String>, | ||
var anotherString: String, | ||
var number: Int | ||
) |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.bridgecrew.commons.models | ||
|
||
data class Response( | ||
var strings: List<String>?, | ||
var result: Boolean? | ||
) : PluginCommonsResponse(null) { | ||
|
||
constructor(error: String?) : this(null, null) { | ||
this.error = error | ||
} | ||
} |
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
Oops, something went wrong.