Added AntTargetExecutor.Env.setConcealedProperties
--- o.apache.tools.ant.module/nbproject/project.properties
+++ o.apache.tools.ant.module/nbproject/project.properties
@@ -42,7 +42,7 @@
javac.compilerargs=-Xlint:unchecked
javac.source=1.7
-spec.version.base=3.73.0
+spec.version.base=3.74.0
compile.ant.jar=${ant.core.lib}
src-bridge.cp.extra=build/classes:${compile.ant.jar}
extra.module.files=\
--- o.apache.tools.ant.module/src/org/apache/tools/ant/module/api/support/ActionUtils.java
+++ o.apache.tools.ant.module/src/org/apache/tools/ant/module/api/support/ActionUtils.java
@@ -154,6 +154,39 @@
* @see ActionProvider.isActionEnabled(...)
*/
public static FileObject[] findSelectedFiles(Lookup context, FileObject dir, String suffix, boolean strict) {
+ return findSelectedFiles(context, dir, suffix, strict, false);
+ }
+
+ /**
+ * Convenience method to find a file selection in a selection (context).
+ * All files must exist on disk (according to {@link FileUtil#toFile}).
+ * If a constraining directory is supplied, they must also be contained in it.
+ * If a constraining file suffix is supplied, the base names of the files
+ * must end with that suffix.
+ * The return value is null if there are no matching files; or if the strict
+ * parameter is true and some of the files in the selection did not match
+ * the constraints (disk files, directory, and/or suffix).
+ *
+ * Typically {@link org.openide.loaders.DataNode}s will form a node selection
+ * which will be placed in the context. This method does not directly
+ * look for nodes in the selection; but generally the lookups of the nodes in
+ * a node selection are spliced into the context as well, so the {@link FileObject}s
+ * should be available. A corollary of not checking nodes directly is that any
+ * nodes in the context which do not correspond to files at all (i.e. do not have
+ * {@link FileObject} in their lookup) are ignored, even with the strict parameter on;
+ * and that multiple nodes in the context with the same associated file are treated
+ * as a single entry.
+ *
+ * @param context a selection as provided to e.g. ActionProvider.isActionEnabled(...)
+ * @param dir a constraining parent directory, or null to not check for a parent directory
+ * @param suffix a file suffix (e.g. .java) to constrain files by,
+ * or null to not check suffixes
+ * @param strict if true, all files in the selection have to be accepted
+ * @param findInPackages if true, all files under any package in the selection will also be checked
+ * @return a nonempty selection of disk files, or null
+ * @see ActionProvider.isActionEnabled(...)
+ */
+ public static FileObject[] findSelectedFiles(Lookup context, FileObject dir, String suffix, boolean strict, boolean findInPackages) {
if (dir != null && !dir.isFolder()) {
throw new IllegalArgumentException("Not a folder: " + dir); // NOI18N
}
@@ -173,7 +206,37 @@
candidates = _candidates;
}
Collection files = new LinkedHashSet(); // #50644: remove dupes
+ Collection selectedFiles = findSelectedFiles(candidates, dir, suffix, strict, findInPackages);
+ if(selectedFiles != null) {
+ files.addAll(selectedFiles);
+ }
+
+ if (findInPackages) {
+ Collection packageCandidates = new ArrayList<>();
for (FileObject f : candidates) {
+ if (f.isFolder()) {
+ FileObject[] children = f.getChildren();
+ for (FileObject child : children) {
+ if (child.isData()) {
+ packageCandidates.add(child);
+ }
+ }
+ }
+ }
+ Collection selectedFilesInPackages = findSelectedFiles(packageCandidates, dir, suffix, strict, findInPackages);
+ if (selectedFilesInPackages != null) {
+ files.addAll(selectedFilesInPackages);
+ }
+ }
+ if (files.isEmpty()) {
+ return null;
+ }
+ return files.toArray(new FileObject[files.size()]);
+ }
+
+ private static Collection findSelectedFiles(Collection extends FileObject> candidates, FileObject dir, String suffix, boolean strict, boolean findInPackages) {
+ Collection files = new LinkedHashSet<>(); // #50644: remove dupes
+ for (FileObject f : candidates) {
if (f.hasExt("form")) {
continue; // #206309
}
@@ -190,13 +253,15 @@
if (matches) {
files.add(f);
} else if (strict) {
+ if(!findInPackages) {
return null;
}
}
+ }
if (files.isEmpty()) {
return null;
}
- return files.toArray(new FileObject[files.size()]);
+ return files;
}
/**
--- o.apache.tools.ant.module/test/unit/src/org/apache/tools/ant/module/api/support/ActionUtilsTest.java
+++ o.apache.tools.ant.module/test/unit/src/org/apache/tools/ant/module/api/support/ActionUtilsTest.java
@@ -71,8 +71,8 @@
}
private FileObject dir, f1, f1form, f2, subdir, f3, fx, subdir2, f3a, f4, subsubdir, f5, f5a;
- private DataObject d1, d2, d3, dx;
- private Node n1, n2, n3, nx;
+ private DataObject d1, d2, d3, dx, d4;
+ private Node n1, n2, n3, nx, n4;
@Override
protected void setUp() throws Exception {
@@ -95,10 +95,12 @@
d2 = DataObject.find(f2);
d3 = DataObject.find(f3);
dx = DataObject.find(fx);
+ d4 = DataObject.find(subdir2);
n1 = d1.getNodeDelegate();
n2 = d2.getNodeDelegate();
n3 = d3.getNodeDelegate();
nx = dx.getNodeDelegate();
+ n4 = d4.getNodeDelegate();
}
public void testFindSelectedFiles() throws Exception {
@@ -119,6 +121,10 @@
assertEquals("duplicates removed #2 (cf. #50644)", Arrays.asList(new FileObject[] {f1, f2}), filesFrom(new Node[] {n1, n2, n1}, null, null, true));
assertEquals("two selected files", Arrays.asList(new FileObject[] {f1, f2}), files2List(ActionUtils.findSelectedFiles(Lookups.fixed(f1, f2), null, null, true)));
assertEquals("one form, one selection", Collections.singletonList(f1), files2List(ActionUtils.findSelectedFiles(Lookups.fixed(f1, f1form), null, ".data", true)));
+ assertEquals("one selected directory", Collections.singletonList(subdir2), filesFrom(new Node[] {n4}, subdir2, null, true, false));
+ assertEquals("one selected directory, two selected files", Arrays.asList(new FileObject[] {subdir2, f5, f4}), filesFrom(new Node[] {n4}, subdir2, null, true, true));
+ assertEquals("zero selection", null, filesFrom(new Node[] {n4}, subdir2, ".data", true, false));
+ assertEquals("two selected files", Arrays.asList(new FileObject[] {f5, f4}), filesFrom(new Node[] {n4}, subdir2, "data", true, true));
}
private static Lookup context(Node[] sel) {
@@ -131,9 +137,13 @@
}
private static List filesFrom(Node[] sel, FileObject dir, String suffix, boolean strict) {
- return files2List(ActionUtils.findSelectedFiles(context(sel), dir, suffix, strict));
+ return filesFrom(sel, dir, suffix, strict, false);
}
+ private static List filesFrom(Node[] sel, FileObject dir, String suffix, boolean strict, boolean findInPackages) {
+ return files2List(ActionUtils.findSelectedFiles(context(sel), dir, suffix, strict, findInPackages));
+ }
+
public void testAntIncludesList() throws Exception {
assertEquals("2 includes", "f1.data,sub/f3.data", ActionUtils.antIncludesList(new FileObject[] {f1, f3}, dir));
assertEquals("1 include", "f1.data", ActionUtils.antIncludesList(new FileObject[] {f1}, dir));
--- projectui/src/org/netbeans/modules/project/ui/actions/Bundle.properties
+++ projectui/src/org/netbeans/modules/project/ui/actions/Bundle.properties
@@ -80,9 +80,11 @@
LBL_RunMainProjectAction_Name=&Run {0,choice,-1#Main Project|0#Project|1#Project ({1})|1<{0} Projects}
+# Name of 1-off actions
+# {0} - # of selected files
LBL_RunSingleAction_Name=Run &File
# {0,choice,0#File|1#"{1}"|1
have.tests
init,compile-test,-pre-test-run
-
+