diff --git a/springboot/README.md b/springboot/README.md index ff66cde..be35e81 100644 --- a/springboot/README.md +++ b/springboot/README.md @@ -137,12 +137,12 @@ The Spring Boot rule supports other attributes for use in the BUILD file: ### Debugging the Rule Execution -If the environment variable `DEBUG_SPRINGBOOT_RULE` is set, the rule writes debug output to `$TMPDIR/bazel/debug/springboot`. +If the environment variable `debug_springboot_rule` is set, the rule writes debug output to `$TMPDIR/bazel/debug/springboot`. If `$TMPDIR` is not defined, it defaults to `/tmp`. In order to pass this environment variable to Bazel, use the `--action_env` argument: ```bash -bazel build //... --action_env=DEBUG_SPRINGBOOT_RULE=1 +bazel build //... --action_env=debug_springboot_rule=1 ``` ### Writing Tests for your Spring Boot Application diff --git a/springboot/springboot_pkg.sh b/springboot/springboot_pkg.sh index a8a6216..85436cf 100755 --- a/springboot/springboot_pkg.sh +++ b/springboot/springboot_pkg.sh @@ -65,8 +65,8 @@ if [ -z "${debug_springboot_rule}" ]; then else debugdir=$springboot_rule_tmpdir/debug/springboot mkdir -p $debugdir - debugfileNAME=$packagename-$packagesha - debugfile=$debugdir/$debugfileNAME.log + debugfileName=$packagename-$packagesha + debugfile=$debugdir/${debugfileName}.log echo "SPRING BOOT DEBUG LOG: $debugfile" fi >$debugfile diff --git a/springboot/src/main/java/com/salesforce/rulesspring/cli/SpringBootInspector.java b/springboot/src/main/java/com/salesforce/rulesspring/cli/SpringBootInspector.java index 41aeb63..2f3a40d 100644 --- a/springboot/src/main/java/com/salesforce/rulesspring/cli/SpringBootInspector.java +++ b/springboot/src/main/java/com/salesforce/rulesspring/cli/SpringBootInspector.java @@ -12,11 +12,16 @@ public class SpringBootInspector { public static void main(String[] args) throws Exception { if (args.length < 3) { + System.out.println("ERROR: this tool needs at least 3 arguments"); usage(); return; } Command cmd = parseArgs(args); + if (cmd == null) { + // command line was invalid, and reason was already logged, just exit + return; + } if ("inspector".equals(cmd.mode)) { File jarFile = new File(cmd.jarFilepath); @@ -37,14 +42,14 @@ public static void main(String[] args) throws Exception { SpringBootJarIndexer indexer = new SpringBootJarIndexer(jarFile); IndexOfFiles index = indexer.indexJar(cmd.recursive); - + SpringBootIndexReporter reporter = new SpringBootIndexReporter(); String report = reporter.generateReport(index, cmd.reportOptions); - + BufferedWriter writer = new BufferedWriter(new FileWriter(indexFile)); writer.write(report); writer.close(); - + System.out.println("Wrote index file as "+cmd.outputPath); } else { System.err.println("Operation "+cmd.operation+" is not implemented."); @@ -56,10 +61,10 @@ protected static void usage() { System.out.println("Spring Boot Jar Inspector"); System.out.println("Usage:"); System.out.println(" java -jar springboot-cli.jar MODE OPERATION [operation specific args]"); - System.out.println(" MODE: 'inspector' for running operations on a single Spring Boot jar; 'comparator' when running operations with multiple Spring Boot jars"); + System.out.println(" MODE: 'inspector' for running operations on a single Spring Boot jar; 'comparator' when running operations with multiple Spring Boot jars"); System.out.println(" OPERATION: a keyword that activates a particular operation; operations are documented below"); System.out.println("\n"); - + System.out.println("INSPECTOR OPERATIONS:"); System.out.println("\n"); System.out.println(" index: generates an index of files within the Spring Boot jar."); @@ -72,16 +77,21 @@ protected static void usage() { protected static Command parseArgs(String[] args) { // TODO this is pretty awkward but keeping it simple for now - + Command cmd = new Command(); cmd.mode = args[0]; cmd.operation = args[1]; System.out.println("Mode: "+cmd.mode); System.out.println("Operation: "+cmd.operation); - + int optionalArgIndex = 2; if ("inspector".equals(cmd.mode)) { if ("index".equals(cmd.operation)) { + if (args.length < 4) { + System.out.println("ERROR: Not enough arguments for the index command."); + usage(); + return null; + } cmd.jarFilepath = args[2]; cmd.outputPath = args[3]; System.out.println("Spring Boot Jar: "+cmd.jarFilepath); @@ -92,7 +102,7 @@ protected static Command parseArgs(String[] args) { parseOptionalArgs(args, optionalArgIndex, cmd); return cmd; } - + protected static void parseOptionalArgs(String[] args, int index, Command cmd) { for (int i = index; i