-
Notifications
You must be signed in to change notification settings - Fork 61
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
1 parent
d9023a2
commit 3c1d96d
Showing
4 changed files
with
181 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
apply plugin: 'java-library' | ||
apply plugin: 'kotlin' | ||
apply plugin: 'maven-publish' | ||
|
||
compileJava { | ||
sourceCompatibility = JavaVersion.VERSION_11 | ||
} | ||
|
||
dependencies { | ||
implementation project(':core:imposter-api') | ||
implementation project(':core:config') | ||
implementation project(':core:config-kryo') | ||
|
||
implementation project(':core:config-dynamic') | ||
implementation project (':mock:mock-openapi') | ||
implementation project (':mock:mock-rest') | ||
implementation project (':mock:mock-soap') | ||
|
||
// logging | ||
implementation "org.apache.logging.log4j:log4j-core:$version_log4j" | ||
implementation "org.apache.logging.log4j:log4j-slf4j-impl:$version_log4j" | ||
} | ||
|
||
task sourcesJar(type: Jar, dependsOn: classes) { | ||
archiveClassifier = 'sources' | ||
from sourceSets.main.allSource | ||
} | ||
|
||
artifacts { | ||
archives sourcesJar | ||
} | ||
|
||
publishing { | ||
publications { | ||
maven(MavenPublication) { | ||
from components.java | ||
artifact sourcesJar | ||
|
||
repositories { | ||
maven { | ||
url = version.endsWith('SNAPSHOT') ? mavenSnapshotRepository : mavenReleaseRepository | ||
credentials(AwsCredentials) { | ||
accessKey awsAccessKey | ||
secretKey awsSecretKey | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
compileKotlin { | ||
kotlinOptions { | ||
jvmTarget = JavaVersion.VERSION_11 | ||
|
||
// see https://kotlinlang.org/docs/java-to-kotlin-interop.html#default-methods-in-interfaces | ||
freeCompilerArgs = ["-Xjvm-default=all"] | ||
} | ||
} | ||
|
||
compileTestKotlin { | ||
kotlinOptions { | ||
jvmTarget = JavaVersion.VERSION_11 | ||
|
||
// see https://kotlinlang.org/docs/java-to-kotlin-interop.html#default-methods-in-interfaces | ||
freeCompilerArgs = ["-Xjvm-default=all"] | ||
} | ||
} |
96 changes: 96 additions & 0 deletions
96
tools/kryo-util/src/main/java/io/gatehill/imposter/config/loader/kryo/Snapshotter.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,96 @@ | ||
/* | ||
* Copyright (c) 2024. | ||
* | ||
* This file is part of Imposter. | ||
* | ||
* "Commons Clause" License Condition v1.0 | ||
* | ||
* The Software is provided to you by the Licensor under the License, as | ||
* defined below, subject to the following condition. | ||
* | ||
* Without limiting other conditions in the License, the grant of rights | ||
* under the License will not include, and the License does not grant to | ||
* you, the right to Sell the Software. | ||
* | ||
* For purposes of the foregoing, "Sell" means practicing any or all of | ||
* the rights granted to you under the License to provide to third parties, | ||
* for a fee or other consideration (including without limitation fees for | ||
* hosting or consulting/support services related to the Software), a | ||
* product or service whose value derives, entirely or substantially, from | ||
* the functionality of the Software. Any license notice or attribution | ||
* required by the License must also include this Commons Clause License | ||
* Condition notice. | ||
* | ||
* Software: Imposter | ||
* | ||
* License: GNU Lesser General Public License version 3 | ||
* | ||
* Licensor: Peter Cornish | ||
* | ||
* Imposter is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Imposter is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with Imposter. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package io.gatehill.imposter.config.loader.kryo | ||
|
||
import io.gatehill.imposter.ImposterConfig | ||
import io.gatehill.imposter.config.util.ConfigUtil | ||
import io.gatehill.imposter.plugin.DynamicPluginDiscoveryStrategyImpl | ||
import io.gatehill.imposter.plugin.PluginManagerImpl | ||
import io.gatehill.imposter.plugin.config.BasicPluginConfig | ||
import io.gatehill.imposter.plugin.openapi.config.OpenApiPluginConfig | ||
import io.gatehill.imposter.plugin.rest.config.RestPluginConfig | ||
import io.gatehill.imposter.plugin.soap.config.SoapPluginConfig | ||
import org.apache.logging.log4j.LogManager | ||
|
||
/** | ||
* Loads YAML/JSON config and snapshots as binary. | ||
* | ||
* @author pete | ||
*/ | ||
object Snapshotter { | ||
private val logger = LogManager.getLogger() | ||
|
||
@JvmStatic | ||
fun main(args: Array<String>) { | ||
val configDir = arrayOf(args[0]) | ||
logger.info("Config dir: {}", configDir) | ||
|
||
val configFiles = ConfigUtil.discoverConfigFiles(configDir, ConfigUtil.scanRecursiveConfig) | ||
logger.info("Config files: {}", configFiles) | ||
|
||
val discoveryStrategy = DynamicPluginDiscoveryStrategyImpl() | ||
val pluginManager = PluginManagerImpl(discoveryStrategy) | ||
val pluginConfigs = ConfigUtil.readPluginConfigs(pluginManager, configFiles) | ||
logger.info("Read {} configs", pluginConfigs.size) | ||
|
||
val imposterConfig = ImposterConfig() | ||
for (pluginConfig in pluginConfigs.values.flatten()) { | ||
val configClass = determineConfigClass(pluginConfig.plugin) | ||
logger.info("Parsing {}", configClass.canonicalName) | ||
val config = ConfigUtil.loadPluginConfig(imposterConfig, pluginConfig, configClass) | ||
|
||
val kryoFile = BinarySerialiser.buildKryoPath(pluginConfig.ref.file) | ||
BinarySerialiser.serialise(config, kryoFile) | ||
} | ||
} | ||
|
||
private fun determineConfigClass(plugin: String): Class<out BasicPluginConfig> { | ||
return when (plugin) { | ||
"openapi" -> OpenApiPluginConfig::class.java | ||
"rest" -> RestPluginConfig::class.java | ||
"soap" -> SoapPluginConfig::class.java | ||
else -> throw IllegalStateException("Unsupported plugin: $plugin") | ||
} | ||
} | ||
} |
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,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Configuration status="WARN"> | ||
<Appenders> | ||
<Console name="Console" target="SYSTEM_OUT"> | ||
<PatternLayout pattern="%d{HH:mm:ss} %-5level %logger{1.} - %msg%n"/> | ||
</Console> | ||
</Appenders> | ||
<Loggers> | ||
<Logger name="io.gatehill.imposter" level="trace" /> | ||
<Root level="warn"> | ||
<AppenderRef ref="Console"/> | ||
</Root> | ||
<Logger name="io.netty" level="warn" /> | ||
<Logger name="httpclient.wire" level="warn" /> | ||
<Logger name="org.apache" level="warn" /> | ||
</Loggers> | ||
</Configuration> |