diff --git a/src/main/java/com/massivedisaster/bintraydeployautomator/model/Configuration.java b/src/main/java/com/massivedisaster/bintraydeployautomator/model/Configuration.java index e0f9f82..eda4b03 100644 --- a/src/main/java/com/massivedisaster/bintraydeployautomator/model/Configuration.java +++ b/src/main/java/com/massivedisaster/bintraydeployautomator/model/Configuration.java @@ -1,6 +1,7 @@ package com.massivedisaster.bintraydeployautomator.model; import com.google.gson.Gson; +import com.massivedisaster.bintraydeployautomator.utils.ArrayUtils; import org.gradle.internal.impldep.org.apache.commons.lang.StringUtils; @@ -107,7 +108,27 @@ public String[] getArguments() { * @return tasks to run. */ public String[] getTasks() { - return new String[]{"clean", "build", "bintrayUpload"}; + return ArrayUtils.addAll(new String[]{"clean", "build"}, getBintrayTasks()); + } + + /** + * Get the bintray tasks from modules. + * + * @return list of bintray upload tasks. + */ + private String[] getBintrayTasks() { + if (modules == null) { + throw new IllegalArgumentException("modules can't be null"); + } + + if (bintrayTasks == null) { + int size = modules.size(); + bintrayTasks = new String[size]; + for (int i = 0; i < size; i++) { + bintrayTasks[i] = modules.get(i) + ":bintrayUpload"; + } + } + return bintrayTasks; } /** diff --git a/src/main/java/com/massivedisaster/bintraydeployautomator/utils/ArrayUtils.java b/src/main/java/com/massivedisaster/bintraydeployautomator/utils/ArrayUtils.java new file mode 100644 index 0000000..37c96bf --- /dev/null +++ b/src/main/java/com/massivedisaster/bintraydeployautomator/utils/ArrayUtils.java @@ -0,0 +1,43 @@ +package com.massivedisaster.bintraydeployautomator.utils; + +/** + * Array Utils + */ +public class ArrayUtils { + + /** + * Adds all the elements of the given arrays into a new array. + * The new array contains all of the element of array1 followed by all of the elements array2. When an array + * is returned, it is always a new array. + * + * @param array1 the first array whose elements are added to the new array. + * @param array2 the second array whose elements are added to the new array. + * @return The new String[] array. + */ + public static String[] addAll(String[] array1, String[] array2) { + if (array1 == null) { + return clone(array2); + } else if (array2 == null) { + return clone(array1); + } + String[] joinedArray = new String[array1.length + array2.length]; + System.arraycopy(array1, 0, joinedArray, 0, array1.length); + System.arraycopy(array2, 0, joinedArray, array1.length, array2.length); + return joinedArray; + } + + /** + * Clones an array returning a typecast result and handling null. + * This method returns null for a null input array. + * + * @param array the array to clone, may be null + * @return the cloned array, null if null input + */ + private static String[] clone(String[] array) { + if (array == null) { + return null; + } + return array.clone(); + } + +}