Permalink
Browse files

Minor refactoring.

  • Loading branch information...
kelemen committed Nov 12, 2012
1 parent a68f689 commit d22d0b9c131a6a457edc47e94f2728d491adabfb
@@ -1,5 +1,6 @@
package org.netbeans.gradle.project.tasks;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@@ -95,6 +96,22 @@ public void setArguments(List<String> arguments) {
this.arguments = CollectionUtils.copyNullSafeList(arguments);
}
+ private static <T> List<T> concatNullSafeLists(
+ List<? extends T> list1,
+ List<? extends T> list2) {
+ List<T> result = new ArrayList<T>(list1.size() + list2.size());
+ result.addAll(list1);
+ result.addAll(list2);
+ for (T element: result) {
+ if (element == null) throw new NullPointerException("element");
+ }
+ return result;
+ }
+
+ public void addArguments(List<String> toAdd) {
+ this.arguments = Collections.unmodifiableList(concatNullSafeLists(this.arguments, toAdd));
+ }
+
public List<String> getJvmArguments() {
return jvmArguments;
}
@@ -103,6 +120,10 @@ public void setJvmArguments(List<String> jvmArguments) {
this.jvmArguments = CollectionUtils.copyNullSafeList(jvmArguments);
}
+ public void addJvmArguments(List<String> toAdd) {
+ this.jvmArguments = Collections.unmodifiableList(concatNullSafeLists(this.jvmArguments, toAdd));
+ }
+
public SmartOutputHandler.Visitor getStdOutListener() {
return stdOutListener;
}
@@ -11,7 +11,6 @@
import java.nio.CharBuffer;
import java.nio.charset.Charset;
import java.nio.charset.CharsetEncoder;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
@@ -240,13 +239,7 @@ public DaemonTaskDef call() throws Exception {
final GradleTaskDef newTaskDef;
if (globalJvmArgs != null && !globalJvmArgs.isEmpty()) {
GradleTaskDef.Builder builder = new GradleTaskDef.Builder(taskDef);
-
- List<String> combinedJvmArgs = new ArrayList<String>(
- taskDef.getJvmArguments().size() + globalJvmArgs.size());
- combinedJvmArgs.addAll(taskDef.getJvmArguments());
- combinedJvmArgs.addAll(globalJvmArgs);
- builder.setJvmArguments(combinedJvmArgs);
-
+ builder.addArguments(globalJvmArgs);
newTaskDef = builder.create();
}
else {

0 comments on commit d22d0b9

Please sign in to comment.