站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > NetBeans API Javadoc (Current Development Version)

ActionUtils (Ant) - NetBeans API Javadoc (Current Development Version)

org.apache.tools.ant.module/3 3.27.0 2

org.apache.tools.ant.module.api.support
Class ActionUtils

java.lang.Object
  extended by org.apache.tools.ant.module.api.support.ActionUtils

public final class ActionUtils
extends Object

Makes it easier to implement org.netbeans.spi.project.ActionProvider in a standard way by running targets in Ant scripts.

See Also:
ActionProvider

Method Summary
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).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

runTarget

public static ExecutorTask runTarget(FileObject buildXml,
                                     String[] targetNames,
                                     Properties properties)
                              throws IOException,
                                     IllegalArgumentException
Runs an Ant target (or a sequence of them).

Parameters:
buildXml - an Ant build script
targetNames - one or more targets to run; or null for the default target
properties - any Ant properties to define, or null
Returns:
a task tracking the progress of Ant
Throws:
IOException - if there was a problem starting Ant
IllegalArgumentException - if you did not provide any targets

findSelectedFiles

public static FileObject[] findSelectedFiles(Lookup context,
                                             FileObject dir,
                                             String suffix,
                                             boolean strict)
Convenience method to find a file selection in a selection (context). All files must exist on disk (according to 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 DataNodes 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 DataObjects 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 DataObject as a cookie) 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.

Parameters:
context - a selection as provided to e.g. ActionProvider.isActionEnabled(...)
dir - a constraining parent directory, or null to not check for a parent directory
suffix - a file suffix (e.g. .java) to constrain files by, or null to not check suffixes
strict - if true, all files in the selection have to be accepted
Returns:
a nonempty selection of disk files, or null
See Also:
ActionProvider.isActionEnabled(...)

regexpMapFiles

public static FileObject[] regexpMapFiles(FileObject[] fromFiles,
                                          FileObject fromDir,
                                          Pattern fromRx,
                                          FileObject toDir,
                                          String toSubst,
                                          boolean strict)
                                   throws IllegalArgumentException
Map files of one kind in a source directory to files of another kind in a target directory. You may use regular expressions to remap file names in the process. Only files which actually exist in the target directory will be returned. (If you expect the target files to be created by Ant you do not need this method, since Ant's mappers suffice.) The file paths considered by the regular expression (if supplied) always use / as the separator.

Typical usage to map a set of Java source files to corresponding tests: regexpMapFiles(files, srcDir, Pattern.compile("/([^/]+)\\.java"), testSrcDir, "/\\1Test.java", true)

Parameters:
fromFiles - a list of source files to start with (may be empty)
fromDir - a directory in which all the source files reside
fromRx - 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 included
toDir - a target directory that results will reside in
toSubst - replacement text for fromRx (may include regexp references), or must be null if fromRx was null
strict - true to return null in case some starting files did not match any target file
Returns:
a list of corresponding target files (may be empty), or null if in strict mode and there was at least one source file which did not match a target file
Throws:
IllegalArgumentException - in case some source file is not in the source directory

antIncludesList

public static String antIncludesList(FileObject[] files,
                                     FileObject dir)
                              throws IllegalArgumentException
Create an "includes" string such as is accepted by many Ant commands as well as filesets. / is always used as the separator in the relative paths.

Parameters:
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 reside
Returns:
a comma-separated list of relative file paths suitable for use by Ant (the empty string in case there are no files)
Throws:
IllegalArgumentException - in case some file is not in the directory

antIncludesList

public static String antIncludesList(FileObject[] files,
                                     FileObject dir,
                                     boolean recursive)
                              throws IllegalArgumentException
Create an "includes" string such as is accepted by many Ant commands as well as filesets. / is always used as the separator in the relative paths.

Parameters:
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 reside
recursive - if true the include list for directory is recursive
Returns:
a comma-separated list of relative file paths suitable for use by Ant (the empty string in case there are no files)
Throws:
IllegalArgumentException - in case some file is not in the directory
Since:
org.apache.tools.ant.module/3 3.16

org.apache.tools.ant.module/3 3.27.0 2

Built on May 28 2007.  |  Portions Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.