public final class ActionUtils extends Object
org.netbeans.spi.project.ActionProvider
in a standard way
by running targets in Ant scripts.ActionProvider
Modifier and Type | Method and Description |
---|---|
static String |
antIncludesList(FileObject[] files,
FileObject dir)
Create an "includes" string such as is accepted by many Ant commands
as well as filesets.
|
static String |
antIncludesList(FileObject[] files,
FileObject dir,
boolean recursive)
Create an "includes" string such as is accepted by many Ant commands
as well as filesets.
|
static FileObject[] |
findSelectedFiles(Lookup context,
FileObject dir,
String suffix,
boolean strict)
Convenience method to find a file selection in a selection (context).
|
static FileObject[] |
regexpMapFiles(FileObject[] fromFiles,
FileObject fromDir,
Pattern fromRx,
FileObject toDir,
String toSubst,
boolean strict)
Map files of one kind in a source directory to files of another kind in a target directory.
|
static ExecutorTask |
runTarget(FileObject buildXml,
String[] targetNames,
Properties properties)
Runs an Ant target (or a sequence of them).
|
static ExecutorTask |
runTarget(FileObject buildXml,
String[] targetNames,
Properties properties,
Set<String> concealedProperties)
Runs an Ant target (or a sequence of them).
|
@NonNull public static ExecutorTask runTarget(@NonNull FileObject buildXml, @NullAllowed String[] targetNames, @NullAllowed Properties properties) throws IOException, IllegalArgumentException
buildXml
- an Ant build scripttargetNames
- one or more targets to run; or null for the default targetproperties
- any Ant properties to define, or nullIOException
- if there was a problem starting AntIllegalArgumentException
- if you did not provide any targets@NonNull public static ExecutorTask runTarget(@NonNull FileObject buildXml, @NullAllowed String[] targetNames, @NullAllowed Properties properties, @NullAllowed Set<String> concealedProperties) throws IOException, IllegalArgumentException
buildXml
- an Ant build scripttargetNames
- one or more targets to run; or null for the default targetproperties
- any Ant properties to define, or nullconcealedProperties
- the names of the properties whose values should not be visible to the user or nullIOException
- if there was a problem starting AntIllegalArgumentException
- if you did not provide any targetspublic static FileObject[] findSelectedFiles(Lookup context, FileObject dir, String suffix, boolean strict)
FileUtil.toFile(org.openide.filesystems.FileObject)
).
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 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 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
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.
context
- a selection as provided to e.g. ActionProvider.isActionEnabled(...)
dir
- a constraining parent directory, or null to not check for a parent directorysuffix
- a file suffix (e.g. .java) to constrain files by,
or null to not check suffixesstrict
- if true, all files in the selection have to be acceptedActionProvider.isActionEnabled(...)
public static FileObject[] regexpMapFiles(FileObject[] fromFiles, FileObject fromDir, Pattern fromRx, FileObject toDir, String toSubst, boolean strict) throws IllegalArgumentException
Typical usage to map a set of Java source files to corresponding tests:
regexpMapFiles(files, srcDir, Pattern.compile("/([^/]+)\\.java"), testSrcDir, "/\\1Test.java", true)
fromFiles
- a list of source files to start with (may be empty)fromDir
- a directory in which all the source files residefromRx
- a regular expression to match against the source files
(or null to keep the same relative file names); only one
match (somewhere in the path) is checked for; failure to match
prevents the file from being includedtoDir
- a target directory that results will reside intoSubst
- replacement text for fromRx
(may include regexp references),
or must be null if fromRx
was nullstrict
- true to return null in case some starting files did not match any target fileIllegalArgumentException
- in case some source file is not in the source directorypublic static String antIncludesList(FileObject[] files, FileObject dir) throws IllegalArgumentException
files
- a list of files or folders to include, in the case of folder
the generated include contains recursively all files under the folder.dir
- a directory in which all the files resideIllegalArgumentException
- in case some file is not in the directorypublic static String antIncludesList(FileObject[] files, FileObject dir, boolean recursive) throws IllegalArgumentException
files
- a list of files or folders to include, in the case of folder
the generated include contains recursively all files under the folder.dir
- a directory in which all the files residerecursive
- if true the include list for directory is recursiveIllegalArgumentException
- in case some file is not in the directory