Skip to content

Commit

Permalink
Merge pull request #158 from salesforce/plaird/small
Browse files Browse the repository at this point in the history
minor updates
  • Loading branch information
plaird authored Oct 1, 2022
2 parents fa0b281 + 961d08e commit ec5ca65
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
4 changes: 2 additions & 2 deletions springboot/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions springboot/springboot_pkg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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.");
Expand All @@ -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.");
Expand All @@ -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);
Expand All @@ -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<args.length; i++) {
if ("--recursive".equals(args[i])) {
Expand All @@ -106,16 +116,16 @@ protected static void parseOptionalArgs(String[] args, int index, Command cmd) {
System.err.println("Unrecognized parameter "+args[i]+ ". Ignoring.");
}
}

}

public static class Command {
// General args
public String mode;
public String operation;
public String jarFilepath;
public String outputPath;

// inspector:index args
public boolean recursive = false;
public String reportOptions = null;
Expand Down

0 comments on commit ec5ca65

Please sign in to comment.