You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by jh...@apache.org on 2016/04/29 11:52:12 UTC
[1/2] ant git commit: StringUtils.join: new method
Repository: ant
Updated Branches:
refs/heads/master d96c85ba4 -> a80c75af5
StringUtils.join: new method
Project: http://git-wip-us.apache.org/repos/asf/ant/repo
Commit: http://git-wip-us.apache.org/repos/asf/ant/commit/75f12374
Tree: http://git-wip-us.apache.org/repos/asf/ant/tree/75f12374
Diff: http://git-wip-us.apache.org/repos/asf/ant/diff/75f12374
Branch: refs/heads/master
Commit: 75f12374003b6e140fa7d15769a0dc8e211b57cd
Parents: d96c85b
Author: Jan Mat�rne <jh...@apache.org>
Authored: Fri Apr 29 11:49:30 2016 +0200
Committer: Jan Mat�rne <jh...@apache.org>
Committed: Fri Apr 29 11:49:30 2016 +0200
----------------------------------------------------------------------
.../org/apache/tools/ant/util/StringUtils.java | 25 ++++++++++++
.../apache/tools/ant/util/StringUtilsTest.java | 40 ++++++++++++++++----
2 files changed, 57 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ant/blob/75f12374/src/main/org/apache/tools/ant/util/StringUtils.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/util/StringUtils.java b/src/main/org/apache/tools/ant/util/StringUtils.java
index 626fb22..fc2fb46 100644
--- a/src/main/org/apache/tools/ant/util/StringUtils.java
+++ b/src/main/org/apache/tools/ant/util/StringUtils.java
@@ -19,7 +19,10 @@ package org.apache.tools.ant.util;
import java.io.PrintWriter;
import java.io.StringWriter;
+import java.util.Arrays;
+import java.util.Collection;
import java.util.Vector;
+import java.util.stream.Collectors;
import org.apache.tools.ant.BuildException;
@@ -270,4 +273,26 @@ public final class StringUtils {
return string;
}
}
+
+ /**
+ * Joins the string representation of the elements of a collection to
+ * a joined string with a given separator.
+ * @param collection Collection of the data to be joined (may be null)
+ * @param separator Separator between elements (may be null)
+ * @return the joined string
+ */
+ public static String join(Collection<?> collection, CharSequence separator) {
+ return collection.stream().map( o -> String.valueOf(o) ).collect(Collectors.joining(separator));
+ }
+
+ /**
+ * Joins the string representation of the elements of an array to
+ * a joined string with a given separator.
+ * @param array Array of the data to be joined (may be null)
+ * @param separator Separator between elements (may be null)
+ * @return the joined string
+ */
+ public static String join(Object[] array, CharSequence separator) {
+ return join(Arrays.asList(array), separator);
+ }
}
http://git-wip-us.apache.org/repos/asf/ant/blob/75f12374/src/tests/junit/org/apache/tools/ant/util/StringUtilsTest.java
----------------------------------------------------------------------
diff --git a/src/tests/junit/org/apache/tools/ant/util/StringUtilsTest.java b/src/tests/junit/org/apache/tools/ant/util/StringUtilsTest.java
index 4dc43ee..81ea3c6 100644
--- a/src/tests/junit/org/apache/tools/ant/util/StringUtilsTest.java
+++ b/src/tests/junit/org/apache/tools/ant/util/StringUtilsTest.java
@@ -17,14 +17,16 @@
*/
package org.apache.tools.ant.util;
-import java.util.Vector;
-
-import org.junit.Test;
-
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Vector;
+
+import org.junit.Test;
+
/**
* Test for StringUtils
*/
@@ -33,7 +35,7 @@ public class StringUtilsTest {
@Test
public void testSplit(){
final String data = "a,b,,";
- Vector res = StringUtils.split(data, ',');
+ Vector<String> res = StringUtils.split(data, ',');
assertEquals(4, res.size());
assertEquals("a", res.elementAt(0));
assertEquals("b", res.elementAt(1));
@@ -44,7 +46,7 @@ public class StringUtilsTest {
@Test
public void testSplitLines(){
final String data = "a\r\nb\nc\nd\ne";
- Vector res = StringUtils.lineSplit(data);
+ Vector<String> res = StringUtils.lineSplit(data);
assertEquals(5, res.size());
assertEquals("a\r", res.elementAt(0));
assertEquals("b", res.elementAt(1));
@@ -53,7 +55,8 @@ public class StringUtilsTest {
assertEquals("e", res.elementAt(4));
}
- @Test
+ @SuppressWarnings("deprecation")
+ @Test
public void testReplace() {
final String data = "abcabcabca";
String res = StringUtils.replace(data, "a", "");
@@ -166,5 +169,26 @@ public class StringUtilsTest {
prefix + name + suffix,
StringUtils.removePrefix(input, "bla")
);
- }
+ }
+
+ @Test
+ public void testJoin() {
+ assertEquals("a, b, c", StringUtils.join(Arrays.asList("a", "b", "c"), ", "));
+ }
+
+ @Test
+ public void testJoinEmptyArray() {
+ assertEquals("", StringUtils.join(new String[]{}, ", "));
+ }
+
+ @Test
+ public void testJoinNullArray() {
+ assertEquals("", StringUtils.join((Collection<String>)null, ", "));
+ }
+
+ @Test
+ public void testJoinNullSeparator() {
+ assertEquals("abc", StringUtils.join(Arrays.asList("a", "b", "c"), null));
+ }
+
}
[2/2] ant git commit: Files.setPermission may throw additional
exceptions (e.g. on Win7-NTFS)
Posted by jh...@apache.org.
Files.setPermission may throw additional exceptions (e.g. on Win7-NTFS)
Project: http://git-wip-us.apache.org/repos/asf/ant/repo
Commit: http://git-wip-us.apache.org/repos/asf/ant/commit/a80c75af
Tree: http://git-wip-us.apache.org/repos/asf/ant/tree/a80c75af
Diff: http://git-wip-us.apache.org/repos/asf/ant/diff/a80c75af
Branch: refs/heads/master
Commit: a80c75af5556ff31eac7607a0ed8715acf111ef5
Parents: 75f1237
Author: Jan Matèrne <jh...@apache.org>
Authored: Fri Apr 29 11:51:04 2016 +0200
Committer: Jan Matèrne <jh...@apache.org>
Committed: Fri Apr 29 11:51:04 2016 +0200
----------------------------------------------------------------------
.../tools/ant/taskdefs/SetPermissions.java | 38 +++++++++++++-------
1 file changed, 26 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ant/blob/a80c75af/src/main/org/apache/tools/ant/taskdefs/SetPermissions.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/SetPermissions.java b/src/main/org/apache/tools/ant/taskdefs/SetPermissions.java
index b417060..b1ccc5a 100644
--- a/src/main/org/apache/tools/ant/taskdefs/SetPermissions.java
+++ b/src/main/org/apache/tools/ant/taskdefs/SetPermissions.java
@@ -31,6 +31,7 @@ import org.apache.tools.ant.types.Resource;
import org.apache.tools.ant.types.ResourceCollection;
import org.apache.tools.ant.types.resources.Resources;
import org.apache.tools.ant.util.PermissionUtils;
+import org.apache.tools.ant.util.StringUtils;
/**
* Sets {@link PosixFilePermission}s for resources.
@@ -95,18 +96,31 @@ public class SetPermissions extends Task {
if (resources == null) {
throw new BuildException("At least one resource-collection is required");
}
- for (Resource r : resources) {
- try {
- PermissionUtils.setPermissions(r, permissions);
- } catch (IOException ioe) {
- String msg = "Failed to set permissions on " + r + " due to "
- + ioe.getMessage();
- if (failonerror) {
- throw new BuildException(msg, ioe);
- } else {
- log("Warning: " + msg, Project.MSG_ERR);
- }
- }
+ Resource currentResource = null;
+ try {
+ for (Resource r : resources) {
+ currentResource = r;
+ try {
+ PermissionUtils.setPermissions(r, permissions);
+ } catch (IOException ioe) {
+ maybeThrowException(ioe, "Failed to set permissions on '%s' due to %s", r, ioe.getMessage());
+ }
+ }
+ } catch (UnsupportedOperationException uoe) {
+ maybeThrowException(null, "the associated file system of resource '%s' does not support the PosixFileAttributeView", currentResource);
+ } catch (ClassCastException uoe) {
+ maybeThrowException(null, "some specified permissions are not of type PosixFilePermission: %s", StringUtils.join(permissions, ", "));
+ } catch (SecurityException uoe) {
+ maybeThrowException(null, "the SecurityManager denies role accessUserInformation or write access for SecurityManager.checkWrite for resource '%s'", currentResource);
}
}
+
+ private void maybeThrowException(Exception ioe, String msgFormat, Object... msgArgs) {
+ String msg = String.format(msgFormat, msgArgs);
+ if (failonerror) {
+ throw new BuildException(msg, ioe);
+ } else {
+ log("Warning: " + msg, Project.MSG_ERR);
+ }
+ }
}