Repository: cloudslang/cloud-slang
Issue: CLI compile folders

`compile dir_with_no_sl_files` --> NPE

compile description says `--f ...` <-- should be updated to `--d`

Changed files:
cloudslang-cli/src/main/java/io/cloudslang/lang/cli/services/ConsolePrinterImpl.java
cloudslang-cli/src/test/java/io/cloudslang/lang/cli/services/ConsolePrinterImplTest.java
cloudslang-cli/src/main/java/io/cloudslang/lang/cli/SlangCli.java

diff --git a/cloudslang-cli/src/main/java/io/cloudslang/lang/cli/SlangCli.java b/cloudslang-cli/src/main/java/io/cloudslang/lang/cli/SlangCli.java
index f1eba947f..fcd1360f7 100644
--- a/cloudslang-cli/src/main/java/io/cloudslang/lang/cli/SlangCli.java
+++ b/cloudslang-cli/src/main/java/io/cloudslang/lang/cli/SlangCli.java
@@ -23,17 +23,6 @@ import io.cloudslang.lang.runtime.events.LanguageEventData;
 import io.cloudslang.score.events.EventConstants;
 import io.cloudslang.score.events.ScoreEvent;
 import io.cloudslang.score.events.ScoreEventListener;
-
-import java.io.File;
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.collections4.MapUtils;
 import org.apache.commons.lang.time.StopWatch;
@@ -46,6 +35,15 @@ import org.springframework.shell.core.annotation.CliOption;
 import org.springframework.stereotype.Component;
 
 import javax.annotation.PostConstruct;
+import java.io.File;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
 
 /**
  * @author lesant
@@ -150,9 +148,11 @@ public class SlangCli implements CommandMarker {
 
     @CliCommand(value = "compile", help = "Display compile errors for an executable")
     public String compileSource(
-            @CliOption(key = {"", "d", "directory"}, mandatory = false, help = FILE_HELP)
+            @CliOption(key = {"", "d", "directory"}, mandatory = false,
+                    help = "Path to directory. e.g. compile --d c:/.../your_directory")
             final List<String> directories,
-            @CliOption(key = {"", "f", "file"}, mandatory = false, help = FILE_HELP) final File file,
+            @CliOption(key = {"", "f", "file"}, mandatory = false,
+                    help = "Path to filename. e.g. compile --f c:/.../your_flow.sl") final File file,
             @CliOption(key = {"cp", "classpath"}, mandatory = false, help = CLASSPATH_HELP)
             final List<String> classPath
     ) {
@@ -169,17 +169,21 @@ public class SlangCli implements CommandMarker {
     }
 
     private String printAllCompileErrors(List<CompilationModellingResult> results) {
-        StringBuilder stringBuilder = new StringBuilder();
-        for (CompilationModellingResult result : results) {
-            printCompileErrors(result.getErrors(), result.getFile(), stringBuilder);
-            stringBuilder.append(System.lineSeparator());
+        if (results.size() > 0) {
+            StringBuilder stringBuilder = new StringBuilder();
+            for (CompilationModellingResult result : results) {
+                printCompileErrors(result.getErrors(), result.getFile(), stringBuilder);
+                stringBuilder.append(System.lineSeparator());
+            }
+            return stringBuilder.toString();
+        } else {
+            return "No files were found to compile.";
         }
-        return stringBuilder.toString();
     }
 
     private String printCompileErrors(List<RuntimeException> exceptions, File file, StringBuilder stringBuilder) {
         if (exceptions.size() > 0) {
-            stringBuilder.append("Following exceptions were found:" + System.lineSeparator());
+            stringBuilder.append("Following exceptions were found:").append(System.lineSeparator());
             for (RuntimeException exception : exceptions) {
                 stringBuilder.append("\\t");
                 stringBuilder.append(exception.getClass());
@@ -189,7 +193,7 @@ public class SlangCli implements CommandMarker {
             }
             throw new RuntimeException(stringBuilder.toString());
         } else {
-            stringBuilder.append("Compilation was successful for " + file.getName());
+            stringBuilder.append("Compilation was successful for ").append(file.getName());
         }
         return StringUtils.trim(stringBuilder.toString());
     }
@@ -215,7 +219,7 @@ public class SlangCli implements CommandMarker {
         if (CollectionUtils.isEmpty(systemProperties)) {
             stringBuilder.append("No system properties found.");
         } else {
-            stringBuilder.append("Following system properties were loaded:" + System.lineSeparator());
+            stringBuilder.append("Following system properties were loaded:").append(System.lineSeparator());
             for (SystemProperty systemProperty : systemProperties) {
                 stringBuilder.append("\\t");
                 stringBuilder.append(systemProperty.getFullyQualifiedName());
diff --git a/cloudslang-cli/src/main/java/io/cloudslang/lang/cli/services/ConsolePrinterImpl.java b/cloudslang-cli/src/main/java/io/cloudslang/lang/cli/services/ConsolePrinterImpl.java
index b7bd94af8..e2a02703b 100644
--- a/cloudslang-cli/src/main/java/io/cloudslang/lang/cli/services/ConsolePrinterImpl.java
+++ b/cloudslang-cli/src/main/java/io/cloudslang/lang/cli/services/ConsolePrinterImpl.java
@@ -48,7 +48,9 @@ public class ConsolePrinterImpl implements ConsolePrinter, DisposableBean {
     @Override
     public synchronized void waitForAllPrintTasksToFinish() {
         try {
-            lastTask.get(1, TimeUnit.MINUTES);
+            if (lastTask != null) {
+                lastTask.get(1, TimeUnit.MINUTES);
+            }
         } catch (InterruptedException | ExecutionException | TimeoutException ignore) {
         }
     }
diff --git a/cloudslang-cli/src/test/java/io/cloudslang/lang/cli/services/ConsolePrinterImplTest.java b/cloudslang-cli/src/test/java/io/cloudslang/lang/cli/services/ConsolePrinterImplTest.java
index f13ee6c0f..a40846279 100644
--- a/cloudslang-cli/src/test/java/io/cloudslang/lang/cli/services/ConsolePrinterImplTest.java
+++ b/cloudslang-cli/src/test/java/io/cloudslang/lang/cli/services/ConsolePrinterImplTest.java
@@ -42,6 +42,7 @@ import static org.mockito.Mockito.when;
 public class ConsolePrinterImplTest {
 
     private static final String SINGLE_THREAD_EXECUTOR = "singleThreadExecutor";
+    public static final String LAST_TASK = "lastTask";
 
     @InjectMocks
     @Spy
@@ -96,6 +97,21 @@ public class ConsolePrinterImplTest {
         verify(lastTask, times(1)).get(1, TimeUnit.MINUTES);
     }
 
+    @Test
+    public void testNullPointerExceptionNotThrown() throws NoSuchFieldException, IllegalAccessException {
+        ConsolePrinterImpl consolePrinter = new ConsolePrinterImpl();
+        consolePrinter.initialize();
+
+        Class<? extends ConsolePrinterImpl> consolePrinterClass = consolePrinter.getClass();
+        Field consolePrinterClassDeclaredField = consolePrinterClass.getDeclaredField(LAST_TASK);
+
+        consolePrinterClassDeclaredField.setAccessible(true);
+        Object lastTask = consolePrinterClassDeclaredField.get(consolePrinter);
+        assertNull(lastTask);
+
+        consolePrinter.waitForAllPrintTasksToFinish();
+    }
+
     @Test
     public void testConsolePrint() throws Exception {
         final List<Runnable> runnableList = new ArrayList<>();