本文整理汇总了Java中org.apache.tools.ant.types.Resource.isDirectory方法的典型用法代码示例。如果您正苦于以下问题:Java Resource.isDirectory方法的具体用法?Java Resource.isDirectory怎么用?Java Resource.isDirectory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.tools.ant.types.Resource
的用法示例。
在下文中一共展示了Resource.isDirectory方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkEntry
import org.apache.tools.ant.types.Resource; //导入方法依赖的package包/类
/**
* Validate settings and ensure that the represented "archive entry"
* has been established.
*/
protected final synchronized void checkEntry() throws BuildException {
dieOnCircularReference();
if (haveEntry) {
return;
}
String name = getName();
if (name == null) {
throw new BuildException("entry name not set");
}
Resource r = getArchive();
if (r == null) {
throw new BuildException("archive attribute not set");
}
if (!r.isExists()) {
throw new BuildException("%s does not exist.", r);
}
if (r.isDirectory()) {
throw new BuildException("%s denotes a directory.", r);
}
fetchEntry();
haveEntry = true;
}
示例2: grabNonFileSetResources
import org.apache.tools.ant.types.Resource; //导入方法依赖的package包/类
/**
* Fetch all included and not excluded resources from the collections.
*
* <p>Included directories will precede included files.</p>
* @param rcs an array of resource collections
* @return the resources included
* @since Ant 1.7
*/
protected Resource[][] grabNonFileSetResources(final ResourceCollection[] rcs) {
final Resource[][] result = new Resource[rcs.length][];
for (int i = 0; i < rcs.length; i++) {
final List<Resource> dirs = new ArrayList<>();
final List<Resource> files = new ArrayList<>();
for (final Resource r : rcs[i]) {
if (r.isDirectory()) {
dirs.add(r);
} else if (r.isExists()) {
files.add(r);
}
}
// make sure directories are in alpha-order - this also
// ensures parents come before their children
Collections.sort(dirs, Comparator.comparing(Resource::getName));
final List<Resource> rs = new ArrayList<>(dirs);
rs.addAll(files);
result[i] = rs.toArray(new Resource[rs.size()]);
}
return result;
}
示例3: setSrcResource
import org.apache.tools.ant.types.Resource; //导入方法依赖的package包/类
/**
* The resource to expand; required.
* @param src resource to expand
*/
public void setSrcResource(Resource src) {
if (!src.isExists()) {
throw new BuildException("the archive %s doesn't exist",
src.getName());
}
if (src.isDirectory()) {
throw new BuildException("the archive %s can't be a directory",
src.getName());
}
FileProvider fp = src.as(FileProvider.class);
if (fp != null) {
source = fp.getFile();
} else if (!supportsNonFileResources()) {
throw new BuildException(
"The source %s is not a FileSystem Only FileSystem resources are supported.",
src.getName());
}
srcResource = src;
}
示例4: compareContent
import org.apache.tools.ant.types.Resource; //导入方法依赖的package包/类
/**
* Compare the content of two Resources. A nonexistent Resource's
* content is "less than" that of an existing Resource; a directory-type
* Resource's content is "less than" that of a file-type Resource.
* @param r1 the Resource whose content is to be compared.
* @param r2 the other Resource whose content is to be compared.
* @param text true if the content is to be treated as text and
* differences in kind of line break are to be ignored.
* @return a negative integer, zero, or a positive integer as the first
* argument is less than, equal to, or greater than the second.
* @throws IOException if the Resources cannot be read.
* @since Ant 1.7
*/
public static int compareContent(final Resource r1, final Resource r2, final boolean text) throws IOException {
if (r1.equals(r2)) {
return 0;
}
final boolean e1 = r1.isExists();
final boolean e2 = r2.isExists();
if (!(e1 || e2)) {
return 0;
}
if (e1 != e2) {
return e1 ? 1 : -1;
}
final boolean d1 = r1.isDirectory();
final boolean d2 = r2.isDirectory();
if (d1 && d2) {
return 0;
}
if (d1 || d2) {
return d1 ? -1 : 1;
}
return text ? textCompare(r1, r2) : binaryCompare(r1, r2);
}
示例5: isSelected
import org.apache.tools.ant.types.Resource; //导入方法依赖的package包/类
/**
* Return true if this Resource is selected.
* @param r the Resource to check.
* @return whether the Resource was selected.
*/
public boolean isSelected(final Resource r) {
if (type == null) {
throw new BuildException("The type attribute is required.");
}
final int i = type.getIndex();
return i == 2 || (r.isDirectory() ? i == 1 : i == 0);
}
示例6: handleResources
import org.apache.tools.ant.types.Resource; //导入方法依赖的package包/类
private void handleResources(Handler h) {
for (Resource r : resources) {
if (!r.isExists()) {
log(r + " does not exist", Project.MSG_WARN);
}
if (r.isDirectory()) {
log(r + " is a directory; length may not be meaningful", Project.MSG_WARN);
}
h.handle(r);
}
h.complete();
}
示例7: setSrcResource
import org.apache.tools.ant.types.Resource; //导入方法依赖的package包/类
/**
* The resource to pack; required.
* @param src resource to expand
*/
public void setSrcResource(Resource src) {
if (src.isDirectory()) {
throw new BuildException("the source can't be a directory");
}
FileProvider fp = src.as(FileProvider.class);
if (fp != null) {
source = fp.getFile();
} else if (!supportsNonFileResources()) {
throw new BuildException("Only FileSystem resources are supported.");
}
this.src = src;
}
示例8: setSrcResource
import org.apache.tools.ant.types.Resource; //导入方法依赖的package包/类
/**
* The resource to pack; required.
* @param src resource to expand
*/
public void setSrcResource(Resource src) {
if (src.isDirectory()) {
throw new BuildException("the source can't be a directory");
}
if (src.as(FileProvider.class) != null || supportsNonFileResources()) {
this.src = src;
} else {
throw new BuildException("Only FileSystem resources are supported.");
}
}
示例9: contentEquals
import org.apache.tools.ant.types.Resource; //导入方法依赖的package包/类
/**
* Compares the contents of two Resources.
*
* @param r1 the Resource whose content is to be compared.
* @param r2 the other Resource whose content is to be compared.
* @param text true if the content is to be treated as text and
* differences in kind of line break are to be ignored.
*
* @return true if the content of the Resources is the same.
*
* @throws IOException if the Resources cannot be read.
* @since Ant 1.7
*/
public static boolean contentEquals(final Resource r1, final Resource r2, final boolean text) throws IOException {
if (r1.isExists() != r2.isExists()) {
return false;
}
if (!r1.isExists()) {
// two not existing files are equal
return true;
}
// should the following two be switched? If r1 and r2 refer to the same file,
// isn't their content equal regardless of whether that file is a directory?
if (r1.isDirectory() || r2.isDirectory()) {
// don't want to compare directory contents for now
return false;
}
if (r1.equals(r2)) {
return true;
}
if (!text) {
final long s1 = r1.getSize();
final long s2 = r2.getSize();
if (s1 != Resource.UNKNOWN_SIZE && s2 != Resource.UNKNOWN_SIZE
&& s1 != s2) {
return false;
}
}
return compareContent(r1, r2, text) == 0;
}
示例10: of
import org.apache.tools.ant.types.Resource; //导入方法依赖的package包/类
/**
* Determines the file type of a {@link Resource}.
*
* @param r Resource
* @return FileType
*/
public static FileType of(Resource r) {
if (r.isDirectory()) {
return FileType.DIR;
}
return FileType.REGULAR_FILE;
}
示例11: isSelected
import org.apache.tools.ant.types.Resource; //导入方法依赖的package包/类
/**
* The heart of the matter. This is where the selector gets to decide
* on the inclusion of a Resource.
*
* @param r the Resource to check.
* @return whether the Resource is selected.
*/
public boolean isSelected(Resource r) {
// throw BuildException on error
validate();
if (r.isDirectory() || contains.isEmpty()) {
return true;
}
String userstr = contains;
if (!casesensitive) {
userstr = contains.toLowerCase();
}
if (ignorewhitespace) {
userstr = SelectorUtils.removeWhitespace(userstr);
}
try (BufferedReader in = new BufferedReader(
new InputStreamReader(r.getInputStream(), encoding == null
? Charset.defaultCharset() : Charset.forName(encoding)))) {
try {
String teststr = in.readLine();
while (teststr != null) {
if (!casesensitive) {
teststr = teststr.toLowerCase();
}
if (ignorewhitespace) {
teststr = SelectorUtils.removeWhitespace(teststr);
}
if (teststr.indexOf(userstr) > -1) {
return true;
}
teststr = in.readLine();
}
return false;
} catch (IOException ioe) {
throw new BuildException("Could not read " + r.toLongString());
}
} catch (IOException e) {
throw new BuildException(
"Could not get InputStream from " + r.toLongString(), e);
}
}
示例12: addResources
import org.apache.tools.ant.types.Resource; //导入方法依赖的package包/类
/**
* Add the given resources.
*
* @param rc may give additional information like fullpath or
* permissions.
* @param resources the resources to add
* @param zOut the stream to write to
* @throws IOException on error
*
* @since Ant 1.7
*/
protected final void addResources(final ResourceCollection rc,
final Resource[] resources,
final ZipOutputStream zOut)
throws IOException {
if (rc instanceof FileSet) {
addResources((FileSet) rc, resources, zOut);
return;
}
for (final Resource resource : resources) {
String name = resource.getName();
if (name == null) {
continue;
}
name = name.replace(File.separatorChar, '/');
if (name.isEmpty()) {
continue;
}
if (resource.isDirectory() && doFilesonly) {
continue;
}
File base = null;
final FileProvider fp = resource.as(FileProvider.class);
if (fp != null) {
base = ResourceUtils.asFileResource(fp).getBaseDir();
}
if (resource.isDirectory()) {
addDirectoryResource(resource, name, "", base, zOut,
ArchiveFileSet.DEFAULT_DIR_MODE,
ArchiveFileSet.DEFAULT_DIR_MODE);
} else {
addParentDirs(base, name, zOut, "",
ArchiveFileSet.DEFAULT_DIR_MODE);
if (fp != null) {
final File f = (fp).getFile();
zipFile(f, zOut, name, ArchiveFileSet.DEFAULT_FILE_MODE);
} else {
addResource(resource, name, "", zOut,
ArchiveFileSet.DEFAULT_FILE_MODE,
null, null);
}
}
}
}