本文整理汇总了Java中org.apache.tools.ant.types.Resource.as方法的典型用法代码示例。如果您正苦于以下问题:Java Resource.as方法的具体用法?Java Resource.as怎么用?Java Resource.as使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.tools.ant.types.Resource
的用法示例。
在下文中一共展示了Resource.as方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isFilesystemOnly
import org.apache.tools.ant.types.Resource; //导入方法依赖的package包/类
/**
* Fulfill the ResourceCollection contract.
* @return whether this is a filesystem-only resource collection.
*/
public synchronized boolean isFilesystemOnly() {
if (isReference()) {
return ((BaseResourceCollectionContainer) getCheckedRef()).isFilesystemOnly();
}
dieOnCircularReference();
if (rc == null || rc.isFilesystemOnly()) {
return true;
}
/* now check each Resource in case the child only
lets through files from any children IT may have: */
for (Resource r : this) {
if (r.as(FileProvider.class) == null) {
return false;
}
}
return true;
}
示例2: compareTo
import org.apache.tools.ant.types.Resource; //导入方法依赖的package包/类
/**
* Compare this FileResource to another Resource.
* @param another the other Resource against which to compare.
* @return a negative integer, zero, or a positive integer as this FileResource
* is less than, equal to, or greater than the specified Resource.
*/
@Override
public int compareTo(Resource another) {
if (isReference()) {
return getCheckedRef().compareTo(another);
}
if (this.equals(another)) {
return 0;
}
FileProvider otherFP = another.as(FileProvider.class);
if (otherFP != null) {
File f = getFile();
if (f == null) {
return -1;
}
File of = otherFP.getFile();
if (of == null) {
return 1;
}
int compareFiles = f.compareTo(of);
return compareFiles != 0 ? compareFiles
: getName().compareTo(another.getName());
}
return super.compareTo(another);
}
示例3: getOutputStream
import org.apache.tools.ant.types.Resource; //导入方法依赖的package包/类
private static OutputStream getOutputStream(final Resource resource, final boolean append, final Project project)
throws IOException {
if (append) {
final Appendable a = resource.as(Appendable.class);
if (a != null) {
return a.getAppendOutputStream();
}
String msg = "Appendable OutputStream not available for non-appendable resource "
+ resource + "; using plain OutputStream";
if (project != null) {
project.log(msg, Project.MSG_VERBOSE);
} else {
System.out.println(msg);
}
}
return resource.getOutputStream();
}
示例4: setPermissions
import org.apache.tools.ant.types.Resource; //导入方法依赖的package包/类
/**
* Sets permissions on a {@link Resource} - doesn't do anything
* for unsupported resource types.
*
* <p>Supported types are:</p>
* <ul>
* <li>any {@link FileProvider}</li>
* <li>{@link ArchiveResource}</li>
* </ul>
*
* @param r the resource to set permissions for
* @param permissions the permissions
* @param posixNotSupportedCallback optional callback that is
* invoked for a file provider resource if the file-system holding
* the file doesn't support PosixFilePermissions. The Path
* corresponding to the file is passed to the callback.
* @throws IOException if something goes wrong
*/
public static void setPermissions(Resource r, Set<PosixFilePermission> permissions,
Consumer<Path> posixNotSupportedCallback)
throws IOException {
FileProvider f = r.as(FileProvider.class);
if (f != null) {
Path p = f.getFile().toPath();
PosixFileAttributeView view =
Files.getFileAttributeView(p, PosixFileAttributeView.class);
if (view != null) {
view.setPermissions(permissions);
} else if (posixNotSupportedCallback != null) {
posixNotSupportedCallback.accept(p);
}
} else if (r instanceof ArchiveResource) {
((ArchiveResource) r).setMode(modeFromPermissions(permissions,
FileType.of(r)));
}
}
示例5: 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;
}
示例6: processResources
import org.apache.tools.ant.types.Resource; //导入方法依赖的package包/类
/**
* Styles all existing resources.
*
* @param stylesheet style sheet to use
* @since Ant 1.7
*/
private void processResources(final Resource stylesheet) {
for (final Resource r : resources) {
if (!r.isExists()) {
continue;
}
File base = baseDir;
String name = r.getName();
final FileProvider fp = r.as(FileProvider.class);
if (fp != null) {
final FileResource f = ResourceUtils.asFileResource(fp);
base = f.getBaseDir();
if (base == null) {
name = f.getFile().getAbsolutePath();
}
}
process(base, name, destDir, stylesheet);
}
}
示例7: setOutput
import org.apache.tools.ant.types.Resource; //导入方法依赖的package包/类
/**
* Resource to write to.
* @param output the Resource to write to.
* @since Ant 1.8
*/
public void setOutput(Resource output) {
if (this.output != null) {
throw new BuildException("Cannot set > 1 output target");
}
this.output = output;
FileProvider fp = output.as(FileProvider.class);
this.file = fp != null ? fp.getFile() : null;
}
示例8: areSame
import org.apache.tools.ant.types.Resource; //导入方法依赖的package包/类
private static boolean areSame(final Resource resource1, final Resource resource2) throws IOException {
if (resource1 == null || resource2 == null) {
return false;
}
final FileProvider fileResource1 = resource1.as(FileProvider.class);
if (fileResource1 == null) {
return false;
}
final FileProvider fileResource2 = resource2.as(FileProvider.class);
if (fileResource2 == null) {
return false;
}
return FileUtils.getFileUtils().areSame(fileResource1.getFile(), fileResource2.getFile());
}
示例9: execute
import org.apache.tools.ant.types.Resource; //导入方法依赖的package包/类
public void execute() {
for (Resource r : resources) {
URLProvider up = r.as(URLProvider.class);
if (up != null) {
URL u = up.getURL();
try {
FileUtils.close(u.openConnection());
} catch (IOException ex) {
// ignore
}
}
}
}
示例10: resourceToURI
import org.apache.tools.ant.types.Resource; //导入方法依赖的package包/类
private String resourceToURI(final Resource resource) {
final FileProvider fp = resource.as(FileProvider.class);
if (fp != null) {
return FILE_UTILS.toURI(fp.getFile().getAbsolutePath());
}
final URLProvider up = resource.as(URLProvider.class);
if (up != null) {
final URL u = up.getURL();
return String.valueOf(u);
} else {
return resource.getName();
}
}
示例11: touch
import org.apache.tools.ant.types.Resource; //导入方法依赖的package包/类
/**
* Does the actual work; assumes everything has been checked by now.
* @throws BuildException if an error occurs.
*/
protected void touch() throws BuildException {
long defaultTimestamp = getTimestamp();
if (file != null) {
touch(new FileResource(file.getParentFile(), file.getName()),
defaultTimestamp);
}
if (resources == null) {
return;
}
// deal with the resource collections
for (Resource r : resources) {
Touchable t = r.as(Touchable.class);
if (t == null) {
throw new BuildException("Can't touch " + r);
}
touch(r, defaultTimestamp);
}
// deal with filesets in a special way since the task
// originally also used the directories and Union won't return
// them.
for (FileSet fs : filesets) {
DirectoryScanner ds = fs.getDirectoryScanner(getProject());
File fromDir = fs.getDir(getProject());
for (String srcDir : ds.getIncludedDirectories()) {
touch(new FileResource(fromDir, srcDir), defaultTimestamp);
}
}
}
示例12: checkAttributes
import org.apache.tools.ant.types.Resource; //导入方法依赖的package包/类
/**
* Check the attributes.
*/
private void checkAttributes() {
if (userAgent == null || userAgent.trim().length() == 0) {
throw new BuildException("userAgent may not be null or empty");
}
if (sources.size() == 0) {
throw new BuildException("at least one source is required",
getLocation());
}
for (final Resource r : sources) {
final URLProvider up = r.as(URLProvider.class);
if (up == null) {
throw new BuildException(
"Only URLProvider resources are supported", getLocation());
}
}
if (destination == null) {
throw new BuildException("dest attribute is required", getLocation());
}
if (destination.exists() && sources.size() > 1
&& !destination.isDirectory()) {
throw new BuildException(
"The specified destination is not a directory", getLocation());
}
if (destination.exists() && !destination.canWrite()) {
throw new BuildException("Can't write to "
+ destination.getAbsolutePath(),
getLocation());
}
if (sources.size() > 1 && !destination.exists()) {
destination.mkdirs();
}
}
示例13: 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;
}
示例14: 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.");
}
}
示例15: configureLiaison
import org.apache.tools.ant.types.Resource; //导入方法依赖的package包/类
/**
* Loads the stylesheet and set xsl:param parameters.
*
* @param stylesheet the resource from which to load the stylesheet.
* @exception BuildException if the stylesheet cannot be loaded.
* @since Ant 1.7
*/
protected void configureLiaison(final Resource stylesheet) throws BuildException {
if (stylesheetLoaded && reuseLoadedStylesheet) {
return;
}
stylesheetLoaded = true;
try {
log("Loading stylesheet " + stylesheet, Project.MSG_INFO);
// We call liaison.configure() and then liaison.setStylesheet()
// so that the internal variables of liaison can be set up
if (liaison instanceof XSLTLiaison2) {
((XSLTLiaison2) liaison).configure(this);
}
if (liaison instanceof XSLTLiaison3) {
// If we are here we can set the stylesheet as a
// resource
((XSLTLiaison3) liaison).setStylesheet(stylesheet);
} else {
// If we are here we cannot set the stylesheet as
// a resource, but we can set it as a file. So,
// we make an attempt to get it as a file
final FileProvider fp =
stylesheet.as(FileProvider.class);
if (fp != null) {
liaison.setStylesheet(fp.getFile());
} else {
handleError(liaison.getClass().toString()
+ " accepts the stylesheet only as a file");
return;
}
}
for (final Param p : params) {
if (p.shouldUse()) {
final Object evaluatedParam = evaluateParam(p);
if (liaison instanceof XSLTLiaison4) {
((XSLTLiaison4) liaison).addParam(p.getName(),
evaluatedParam);
} else if (evaluatedParam == null || evaluatedParam instanceof String) {
liaison.addParam(p.getName(), (String) evaluatedParam);
} else {
log("XSLTLiaison '" + liaison.getClass().getName()
+ "' supports only String parameters. Converting parameter '" + p.getName()
+ "' to its String value '" + evaluatedParam, Project.MSG_WARN);
liaison.addParam(p.getName(), String.valueOf(evaluatedParam));
}
}
}
} catch (final Exception ex) {
log("Failed to transform using stylesheet " + stylesheet, Project.MSG_INFO);
handleTransformationError(ex);
}
}