Return-Path: X-Original-To: apmail-ant-notifications-archive@minotaur.apache.org Delivered-To: apmail-ant-notifications-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id C4F87186CD for ; Fri, 29 Apr 2016 09:52:12 +0000 (UTC) Received: (qmail 37521 invoked by uid 500); 29 Apr 2016 09:52:12 -0000 Delivered-To: apmail-ant-notifications-archive@ant.apache.org Received: (qmail 37480 invoked by uid 500); 29 Apr 2016 09:52:12 -0000 Mailing-List: contact notifications-help@ant.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ant.apache.org Delivered-To: mailing list notifications@ant.apache.org Received: (qmail 37469 invoked by uid 99); 29 Apr 2016 09:52:12 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 29 Apr 2016 09:52:12 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 4D9DFDFE3D; Fri, 29 Apr 2016 09:52:12 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: jhm@apache.org To: notifications@ant.apache.org Date: Fri, 29 Apr 2016 09:52:13 -0000 Message-Id: In-Reply-To: <9faa134bd0774c1f91943c2644860ba0@git.apache.org> References: <9faa134bd0774c1f91943c2644860ba0@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [2/2] ant git commit: Files.setPermission may throw additional exceptions (e.g. on Win7-NTFS) 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 Authored: Fri Apr 29 11:51:04 2016 +0200 Committer: Jan Matèrne 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); + } + } }