Add new config defaults
This PR adds config defaults for source, sarif and config. The command line mode is also started if no mode was specified.
MODIFY
README.md
README.md
@@ -26,21 +26,19 @@ This will provide you with an executable Codyze installation under `build/instal
To start Codyze, change to the directory and run Codyze.
Codyze has three execution modes:
-* commando line interface mode (`-c`)
+* commando line interface mode (`-c`, default)
* language server protocol mode (`-l`)
* interactive console mode (`-t`).
-One of these modes has to be specified as command line option when running Codyze.
-
An exemplary call to start the commando line interface mode would be
```shell
$ cd build/install/codyze
-$ ./bin/codyze -c -m ./mark -s <sourcepath>
+$ ./bin/codyze -m ./mark -s <sourcepath>
```
where `<sourcepath>` denotes the path to the source directory or file which should be analyzed.
-Codyze can be further configured with more command line arguments or a YAML configuration file.
+Codyze can be further configured with additional command line arguments or a YAML configuration file.
For more information about the usage and configurations, please refer to https://www.codyze.io and the corresponding [wiki page](https://github.com/Fraunhofer-AISEC/codyze/wiki/Usage).

MODIFY
src/main/java/de/fraunhofer/aisec/codyze/Main.java
src/main/java/de/fraunhofer/aisec/codyze/Main.java
@@ -49,6 +49,7 @@ public class Main {
*/
public static void main(String... args) throws Exception {
ConfigFilePath firstPass = new ConfigFilePath();
+ firstPass.configFile = null;
CommandLine cmd = new CommandLine(firstPass);
cmd.parseArgs(args); // first pass to get potential config file path
if (cmd.isUsageHelpRequested()) {
@@ -93,7 +94,7 @@ public class Main {
server.start();
log.info("Analysis server started in {} in ms.", Duration.between(start, Instant.now()).toMillis());
- if (!configuration.getExecutionMode().isLsp() && configuration.getSource() != null) {
+ if (!configuration.getExecutionMode().isLsp()) {
log.info("Analyzing {}", configuration.getSource());
AnalysisContext ctx = server
.analyze(configuration.getSource().getAbsolutePath())
@@ -133,9 +134,9 @@ public class Main {
// Stores path to config file given as cli option
@Command(mixinStandardHelpOptions = true)
- static class ConfigFilePath {
- @Option(names = { "--config" }, paramLabel = "<path>", description = "Parse configuration settings from this file.")
- File configFile;
+ public static class ConfigFilePath {
+ @Option(names = { "--config" }, paramLabel = "<path>", description = "Parse configuration settings from this file.\n\t(Default: ${DEFAULT-VALUE})")
+ public File configFile = new File("codyze.yaml");
@Unmatched
List<String> remainder;

MODIFY
src/main/java/de/fraunhofer/aisec/codyze/config/Configuration.kt
src/main/java/de/fraunhofer/aisec/codyze/config/Configuration.kt
@@ -9,6 +9,7 @@ import com.fasterxml.jackson.databind.DeserializationFeature
import com.fasterxml.jackson.databind.MapperFeature
import com.fasterxml.jackson.databind.PropertyNamingStrategies
import com.fasterxml.jackson.dataformat.yaml.YAMLMapper
+import de.fraunhofer.aisec.codyze.Main.ConfigFilePath
import de.fraunhofer.aisec.codyze.analysis.ServerConfiguration
import de.fraunhofer.aisec.cpg.TranslationConfiguration
import de.fraunhofer.aisec.cpg.frontends.LanguageFrontend
@@ -22,15 +23,15 @@ import picocli.CommandLine
class Configuration {
@JsonIgnore
- @CommandLine.ArgGroup(exclusive = true, multiplicity = "1", heading = "Execution Mode\n")
+ @CommandLine.ArgGroup(exclusive = true, heading = "Execution Mode\n")
val executionMode: ExecutionMode = ExecutionMode()
@CommandLine.Option(
names = ["-s", "--source"],
paramLabel = "<path>",
- description = ["Source file or folder to analyze."]
+ description = ["Source file or folder to analyze.\n\t(Default: \${DEFAULT-VALUE})"]
)
- var source: File? = null
+ var source = File("./")
private set
// TODO output standard stdout?
@@ -53,10 +54,13 @@ class Configuration {
@JsonProperty("sarif")
@CommandLine.Option(
names = ["--sarif"],
- description = ["Enables the SARIF output."],
+ negatable = true,
+ description =
+ [
+ "Controls whether the output is written in the SARIF format.\n\t(Default: \${DEFAULT-VALUE})"],
fallbackValue = "true"
)
- var sarifOutput: Boolean = false
+ var sarifOutput = true
private set
private var codyze = CodyzeConfiguration()
@@ -193,6 +197,10 @@ class Configuration {
// we don't want the parser to print to the terminal when in LSP mode
cpg.debugParser = false
}
+
+ if (!executionMode.isCli && !executionMode.isLsp && !executionMode.isTui) {
+ executionMode.isCli = true
+ }
}
// Parse CLI arguments into config class
@@ -228,7 +236,16 @@ class Configuration {
@JvmStatic
fun initConfig(configFile: File?, vararg args: String?): Configuration {
val config: Configuration =
- if (configFile != null) parseFile(configFile) else Configuration()
+ if (configFile != null) {
+ parseFile(configFile)
+ } else {
+ val defaultConfigFile = ConfigFilePath().configFile
+ if (defaultConfigFile.isFile) {
+ parseFile(defaultConfigFile)
+ } else {
+ Configuration()
+ }
+ }
config.parseCLI(*args)
return config
}
@@ -283,7 +300,7 @@ class ExecutionMode {
@CommandLine.Option(
names = ["-c"],
required = true,
- description = ["Start in command line mode."]
+ description = ["Start in command line mode (default)."]
)
var isCli = false

MODIFY
src/test/java/de/fraunhofer/aisec/codyze/analysis/markevaluation/ExpressionEvaluatorTest.kt
src/test/java/de/fraunhofer/aisec/codyze/analysis/markevaluation/ExpressionEvaluatorTest.kt
@@ -183,8 +183,7 @@ class ExpressionEvaluatorTest : AbstractTest() {
var myEntity: EntityDeclaration? = null
var myRule: RuleDeclaration? = null
- model =
- mark {
+ model = mark {
myEntity =
entity("MyClass") {
variable("field")

MODIFY
src/test/java/de/fraunhofer/aisec/codyze/crymlin/CLILoadTest.kt
src/test/java/de/fraunhofer/aisec/codyze/crymlin/CLILoadTest.kt
@@ -12,14 +12,6 @@ import picocli.CommandLine
internal class CLILoadTest {
- @Test
- @Throws(Exception::class)
- fun noArgsTest() {
- Assertions.assertThrows(CommandLine.MissingParameterException::class.java) {
- Configuration.initConfig(null, *emptyArray())
- }
- }
-
@Test
@Throws(Exception::class)
fun exclusiveOptionTest() {
@@ -39,10 +31,10 @@ internal class CLILoadTest {
assertTrue(config.executionMode.isCli)
assertFalse(config.executionMode.isLsp)
assertFalse(config.executionMode.isTui)
- assertNull(config.source)
+ assertEquals(File(".").absolutePath, config.source.absolutePath)
assertEquals(120L, config.timeout)
assertEquals("findings.sarif", config.output)
- assertFalse(config.sarifOutput)
+ assertTrue(config.sarifOutput)
assertContentEquals(
arrayOf("./").map { s -> File(s).absolutePath }.toTypedArray(),

MODIFY
src/test/java/de/fraunhofer/aisec/codyze/crymlin/ConfigLoadTest.kt
src/test/java/de/fraunhofer/aisec/codyze/crymlin/ConfigLoadTest.kt
@@ -70,7 +70,7 @@ internal class ConfigLoadTest {
assertEquals("source.java", config.source.toString())
assertEquals(120L, config.timeout)
assertEquals("result.out", config.output)
- assertFalse(config.sarifOutput)
+ assertTrue(config.sarifOutput)
assertContentEquals(
arrayOf("./").map { s -> File(s).absolutePath }.toTypedArray(),

Add new config defaults (#448)

This PR adds config defaults for source, sarif and config. The command line mode is also started if no mode was specified.

Co-authored-by: Florian Wendland <florian.wendland@aisec.fraunhofer.de>