/*
 * Copyright 2018, TeamDev. All rights reserved.
 *
 * Redistribution and use in source and/or binary forms, with or without
 * modification, must retain the above copyright notice and the following
 * disclaimer.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

package io.spine.tools.gradle;

/**
 * Create Gradle Runner arguments for a task.
 */
final class TaskArguments {

    private static final String STACKTRACE_CLI_OPTION = "--stacktrace";
    private static final String DEBUG_CLI_OPTION = "--debug";

    private final boolean debug;

    static TaskArguments mode(boolean debug) {
        return new TaskArguments(debug);
    }

    private TaskArguments(boolean debug) {
        this.debug = debug;
    }

    String[] of(TaskName taskName) {
        String task = taskName.getValue();
        return debug
               ? new String[]{task, STACKTRACE_CLI_OPTION, DEBUG_CLI_OPTION}
               : new String[]{task, STACKTRACE_CLI_OPTION};
    }
}

@@ -1038,16 +1038,81 @@
 radle;%0A%0A
+import com.google.common.collect.Lists;%0A%0Aimport java.util.List;%0A%0A
 /**%0A * C
@@ -1186,16 +1186,83 @@
 ents %7B%0A%0A
+    /** Gradle command line argument to turn stacktrace output. */%0A
     priv
@@ -1329,70 +1329,341 @@
 e%22;%0A
-    private static final String DEBUG_CLI_OPTION = %22--debug%22;%0A
+%0A    /** Gradle command line argument to turn debug level of logging. */%0A    private static final String DEBUG_CLI_OPTION = %22--debug%22;%0A%0A    /** Provides type information for list-to-array conversion. */%0A    private static final String%5B%5D OF_STRING = new String%5B0%5D;%0A%0A    /** If true debug level of logging will be turned for a task. */
 %0A   
@@ -1958,80 +1958,123 @@
     
-return debug%0A               ? new String%5B%5D%7Btask, STACKTRACE_CLI_OPTION, 
+List%3CString%3E result = Lists.newArrayList(task, STACKTRACE_CLI_OPTION);%0A        if (debug) %7B%0A            result.add(
 DEBU
@@ -2085,17 +2085,18 @@
 I_OPTION
-%7D
+);
 %0A       
@@ -2100,58 +2100,50 @@
     
+%7D%0A
        
-: new String%5B%5D%7Btask, STACKTRACE_CLI_OPTION%7D
+ return result.toArray(OF_STRING)
 ;%0A  

Improve task argument composition