Skip to content

Commit

Permalink
Merge pull request #14 from massivedisaster/feature/add_module_filter…
Browse files Browse the repository at this point in the history
…_support

Adds module filter support. #13
  • Loading branch information
Andrer757 authored Jun 12, 2017
2 parents 76fa9ab + ae02f99 commit 8430316
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}

}

0 comments on commit 8430316

Please sign in to comment.