You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by bo...@apache.org on 2016/04/10 06:52:33 UTC
[1/2] ant git commit: removed anchor by accident
Repository: ant
Updated Branches:
refs/heads/master dc34b252d -> 32bf39369
removed anchor by accident
Project: http://git-wip-us.apache.org/repos/asf/ant/repo
Commit: http://git-wip-us.apache.org/repos/asf/ant/commit/bcfcb4d8
Tree: http://git-wip-us.apache.org/repos/asf/ant/tree/bcfcb4d8
Diff: http://git-wip-us.apache.org/repos/asf/ant/diff/bcfcb4d8
Branch: refs/heads/master
Commit: bcfcb4d8ea02b9def1fab9b4c119348ccd09b064
Parents: dc34b25
Author: Stefan Bodewig <bo...@apache.org>
Authored: Sun Apr 10 06:50:15 2016 +0200
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Sun Apr 10 06:50:15 2016 +0200
----------------------------------------------------------------------
manual/Types/selectors.html | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ant/blob/bcfcb4d8/manual/Types/selectors.html
----------------------------------------------------------------------
diff --git a/manual/Types/selectors.html b/manual/Types/selectors.html
index ab0a293..387d4d1 100644
--- a/manual/Types/selectors.html
+++ b/manual/Types/selectors.html
@@ -1013,7 +1013,7 @@
but the Java VM cannot detect this state, this selector will
still select the file.</p>
- <h4><a name="symlink">Writable Selector</a></h4>
+ <h4><a name="writable">Writable Selector</a></h4>
<p>The <code><writable></code> selector selects only files
that are writable. Ant only invokes
[2/2] ant git commit: ownedBy selector
Posted by bo...@apache.org.
ownedBy selector
Project: http://git-wip-us.apache.org/repos/asf/ant/repo
Commit: http://git-wip-us.apache.org/repos/asf/ant/commit/32bf3936
Tree: http://git-wip-us.apache.org/repos/asf/ant/tree/32bf3936
Diff: http://git-wip-us.apache.org/repos/asf/ant/diff/32bf3936
Branch: refs/heads/master
Commit: 32bf39369dedbe35eb7309d9056596b12435cdef
Parents: bcfcb4d
Author: Stefan Bodewig <bo...@apache.org>
Authored: Sun Apr 10 06:52:10 2016 +0200
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Sun Apr 10 06:52:10 2016 +0200
----------------------------------------------------------------------
WHATSNEW | 2 +-
manual/Types/selectors.html | 25 +++++++
.../apache/tools/ant/types/AbstractFileSet.java | 14 ++++
.../selectors/AbstractSelectorContainer.java | 13 ++++
.../types/selectors/BaseSelectorContainer.java | 13 ++++
.../ant/types/selectors/OwnedBySelector.java | 78 ++++++++++++++++++++
.../antunit/types/selectors/ownedby-test.xml | 65 ++++++++++++++++
7 files changed, 209 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ant/blob/32bf3936/WHATSNEW
----------------------------------------------------------------------
diff --git a/WHATSNEW b/WHATSNEW
index 1836653..9112353 100644
--- a/WHATSNEW
+++ b/WHATSNEW
@@ -16,7 +16,7 @@ Fixed bugs:
Other changes:
--------------
- * New file selectors <executable> and <symlink>
+ * New file selectors <executable>, <symlink> and <ownedBy>.
Changes from Ant 1.9.6 TO Ant 1.9.7
===================================
http://git-wip-us.apache.org/repos/asf/ant/blob/32bf3936/manual/Types/selectors.html
----------------------------------------------------------------------
diff --git a/manual/Types/selectors.html b/manual/Types/selectors.html
index 387d4d1..153a252 100644
--- a/manual/Types/selectors.html
+++ b/manual/Types/selectors.html
@@ -96,6 +96,8 @@
Select files if they are executable.</li>
<li><a href="#symlink"><code><symlink></code></a> -
Select files if they are symlink.</li>
+ <li><a href="#ownedBy"><code><ownedBy></code></a> -
+ Select files if they are owned by a given user.</li>
</ul>
<h4><a name="containsselect">Contains Selector</a></h4>
@@ -1041,6 +1043,29 @@
<p><em>Since Ant 1.10.0</em></p>
+ <h4><a name="ownedBy">OwnedBy Selector</a></h4>
+
+ <p>The <code><ownedBy></code> selector selects only files
+ that are owned by the given user. Ant only invokes
+ <code>java.nio.file.Files#getOwner</code> so if a file system
+ doesn't support the operation this selector will not select
+ the file.</p>
+
+ <p><em>Since Ant 1.10.0</em></p>
+
+ <table border="1" cellpadding="2" cellspacing="0">
+ <tr>
+ <td valign="top"><b>Attribute</b></td>
+ <td valign="top"><b>Description</b></td>
+ <td align="center" valign="top"><b>Required</b></td>
+ </tr>
+ <tr>
+ <td valign="top">owner</td>
+ <td valign="top">Username of the expected owner</td>
+ <td valign="top" align="center">yes</td>
+ </tr>
+ </table>
+
<h4><a name="scriptselector">Script Selector</a></h4>
<p>
http://git-wip-us.apache.org/repos/asf/ant/blob/32bf3936/src/main/org/apache/tools/ant/types/AbstractFileSet.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/AbstractFileSet.java b/src/main/org/apache/tools/ant/types/AbstractFileSet.java
index bf15607..bc3d02e 100644
--- a/src/main/org/apache/tools/ant/types/AbstractFileSet.java
+++ b/src/main/org/apache/tools/ant/types/AbstractFileSet.java
@@ -43,6 +43,7 @@ import org.apache.tools.ant.types.selectors.MajoritySelector;
import org.apache.tools.ant.types.selectors.NoneSelector;
import org.apache.tools.ant.types.selectors.NotSelector;
import org.apache.tools.ant.types.selectors.OrSelector;
+import org.apache.tools.ant.types.selectors.OwnedBySelector;
import org.apache.tools.ant.types.selectors.PresentSelector;
import org.apache.tools.ant.types.selectors.ReadableSelector;
import org.apache.tools.ant.types.selectors.SelectSelector;
@@ -799,15 +800,28 @@ public abstract class AbstractFileSet extends DataType
appendSelector(w);
}
+ /**
+ * @since 1.10.0
+ */
public void addExecutable(ExecutableSelector e) {
appendSelector(e);
}
+ /**
+ * @since 1.10.0
+ */
public void addSymlink(SymlinkSelector e) {
appendSelector(e);
}
/**
+ * @since 1.10.0
+ */
+ public void addOwnedBy(OwnedBySelector o) {
+ appendSelector(o);
+ }
+
+ /**
* Add an arbitrary selector.
* @param selector the <code>FileSelector</code> to add.
* @since Ant 1.6
http://git-wip-us.apache.org/repos/asf/ant/blob/32bf3936/src/main/org/apache/tools/ant/types/selectors/AbstractSelectorContainer.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/selectors/AbstractSelectorContainer.java b/src/main/org/apache/tools/ant/types/selectors/AbstractSelectorContainer.java
index c2f41a7..3039d48 100644
--- a/src/main/org/apache/tools/ant/types/selectors/AbstractSelectorContainer.java
+++ b/src/main/org/apache/tools/ant/types/selectors/AbstractSelectorContainer.java
@@ -312,15 +312,28 @@ public abstract class AbstractSelectorContainer extends DataType
appendSelector(w);
}
+ /**
+ * @since 1.10.0
+ */
public void addExecutable(ExecutableSelector e) {
appendSelector(e);
}
+ /**
+ * @since 1.10.0
+ */
public void addSymlink(SymlinkSelector e) {
appendSelector(e);
}
/**
+ * @since 1.10.0
+ */
+ public void addOwnedBy(OwnedBySelector o) {
+ appendSelector(o);
+ }
+
+ /**
* add an arbitrary selector
* @param selector the selector to add
* @since Ant 1.6
http://git-wip-us.apache.org/repos/asf/ant/blob/32bf3936/src/main/org/apache/tools/ant/types/selectors/BaseSelectorContainer.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/selectors/BaseSelectorContainer.java b/src/main/org/apache/tools/ant/types/selectors/BaseSelectorContainer.java
index e7aa612..3fcccd7 100644
--- a/src/main/org/apache/tools/ant/types/selectors/BaseSelectorContainer.java
+++ b/src/main/org/apache/tools/ant/types/selectors/BaseSelectorContainer.java
@@ -315,15 +315,28 @@ public abstract class BaseSelectorContainer extends BaseSelector
appendSelector(w);
}
+ /**
+ * @since 1.10.0
+ */
public void addExecutable(ExecutableSelector e) {
appendSelector(e);
}
+ /**
+ * @since 1.10.0
+ */
public void addSymlink(SymlinkSelector e) {
appendSelector(e);
}
/**
+ * @since 1.10.0
+ */
+ public void addOwnedBy(OwnedBySelector o) {
+ appendSelector(o);
+ }
+
+ /**
* add an arbitrary selector
* @param selector the selector to add
* @since Ant 1.6
http://git-wip-us.apache.org/repos/asf/ant/blob/32bf3936/src/main/org/apache/tools/ant/types/selectors/OwnedBySelector.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/selectors/OwnedBySelector.java b/src/main/org/apache/tools/ant/types/selectors/OwnedBySelector.java
new file mode 100644
index 0000000..7f34498
--- /dev/null
+++ b/src/main/org/apache/tools/ant/types/selectors/OwnedBySelector.java
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.tools.ant.types.selectors;
+
+import java.nio.file.Files;
+import java.nio.file.attribute.UserPrincipal;
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.types.Resource;
+import org.apache.tools.ant.types.resources.FileProvider;
+import org.apache.tools.ant.types.resources.selectors.ResourceSelector;
+
+/**
+ * A selector that selects files based on their owner.
+ *
+ * <p>Owner is defined in terms of {@link
+ * java.nio.file.Files#getOwner}, this means the selector will accept
+ * any file that exists and is owned by the given user. If the {@code
+ * getOwner} method throws an {@code UnsupportedOperattionException}
+ * the file in question is not included.</p>
+ *
+ * @since Ant 1.10.0
+ */
+public class OwnedBySelector implements FileSelector, ResourceSelector {
+
+ private String owner;
+
+ /**
+ * Sets the User-Name to look for.
+ * @param the user name
+ */
+ public void setOwner(String owner) {
+ this.owner = owner;
+ }
+
+ @Override
+ public boolean isSelected(File basedir, String filename, File file) {
+ if (owner == null) {
+ throw new BuildException("the owner attribute is required");
+ }
+ if (file != null) {
+ try {
+ UserPrincipal user = Files.getOwner(file.toPath());
+ return user != null && owner.equals(user.getName());
+ } catch (UnsupportedOperationException | IOException ex) {
+ // => not the expected owner
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public boolean isSelected(Resource r) {
+ FileProvider fp = r.as(FileProvider.class);
+ if (fp != null) {
+ return isSelected(null, null, fp.getFile());
+ }
+ return false;
+ }
+}
http://git-wip-us.apache.org/repos/asf/ant/blob/32bf3936/src/tests/antunit/types/selectors/ownedby-test.xml
----------------------------------------------------------------------
diff --git a/src/tests/antunit/types/selectors/ownedby-test.xml b/src/tests/antunit/types/selectors/ownedby-test.xml
new file mode 100644
index 0000000..7949c41
--- /dev/null
+++ b/src/tests/antunit/types/selectors/ownedby-test.xml
@@ -0,0 +1,65 @@
+<?xml version="1.0"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<project xmlns:au="antlib:org.apache.ant.antunit" default="antunit">
+
+ <import file="../../antunit-base.xml" />
+
+ <property name="file" value="testfile"/>
+
+ <target name="createTestdir">
+ <mkdir dir="${output}"/>
+ <touch file="${output}/${file}"/>
+ </target>
+
+ <target name="testRequiresOwner" depends="createTestdir">
+ <au:expectfailure expectedMessage="the owner attribute is required">
+ <au:assertTrue>
+ <isfileselected file="${output}/${file}">
+ <ownedBy/>
+ </isfileselected>
+ </au:assertTrue>
+ </au:expectfailure>
+ </target>
+
+ <!-- not sure whether this works on Windows, Jenkins will tell us -->
+ <target name="testOwnedBy" depends="createTestdir">
+ <au:assertTrue>
+ <resourcecount when="equal" count="1">
+ <fileset dir="${output}">
+ <ownedBy owner="${user.name}"/>
+ </fileset>
+ </resourcecount>
+ </au:assertTrue>
+ <au:assertTrue>
+ <resourcecount when="equal" count="0">
+ <fileset dir="${output}" excludes="${file}">
+ <ownedBy owner="${user.name}"/>
+ </fileset>
+ </resourcecount>
+ </au:assertTrue>
+ </target>
+
+ <target name="testAsTrueConditions" depends="createTestdir">
+ <au:assertTrue>
+ <isfileselected file="${output}/${file}">
+ <ownedBy owner="${user.name}"/>
+ </isfileselected>
+ </au:assertTrue>
+ </target>
+
+</project>