本文整理汇总了Java中org.apache.tools.ant.types.Resource.getName方法的典型用法代码示例。如果您正苦于以下问题:Java Resource.getName方法的具体用法?Java Resource.getName怎么用?Java Resource.getName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.tools.ant.types.Resource
的用法示例。
在下文中一共展示了Resource.getName方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: expandResource
import org.apache.tools.ant.types.Resource; //导入方法依赖的package包/类
/**
* This method is to be overridden by extending unarchival tasks.
*
* @param srcR the source resource
* @param dir the destination directory
* @since Ant 1.7
*/
@Override
protected void expandResource(Resource srcR, File dir) {
if (!srcR.isExists()) {
throw new BuildException("Unable to untar "
+ srcR.getName()
+ " as the it does not exist",
getLocation());
}
try (InputStream i = srcR.getInputStream()) {
expandStream(srcR.getName(), i, dir);
} catch (IOException ioe) {
throw new BuildException("Error while expanding " + srcR.getName(),
ioe, getLocation());
}
}
示例3: 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);
}
}
示例4: processJars
import org.apache.tools.ant.types.Resource; //导入方法依赖的package包/类
/**
* Process all JARs.
*/
private void processJars() {
log("Starting scan.", verboseLevel);
long start = System.currentTimeMillis();
@SuppressWarnings("unchecked")
Iterator<Resource> iter = (Iterator<Resource>) jarResources.iterator();
int checked = 0;
int errors = 0;
while (iter.hasNext()) {
final Resource r = iter.next();
if (!r.isExists()) {
throw new BuildException("JAR resource does not exist: " + r.getName());
}
if (!(r instanceof FileResource)) {
throw new BuildException("Only filesystem resource are supported: " + r.getName()
+ ", was: " + r.getClass().getName());
}
File jarFile = ((FileResource) r).getFile();
if (! checkJarFile(jarFile) ) {
errors++;
}
checked++;
}
log(String.format(Locale.ROOT,
"Scanned %d JAR file(s) for licenses (in %.2fs.), %d error(s).",
checked, (System.currentTimeMillis() - start) / 1000.0, errors),
errors > 0 ? Project.MSG_ERR : Project.MSG_INFO);
}
示例5: read
import org.apache.tools.ant.types.Resource; //导入方法依赖的package包/类
private ResourceCollection read(Resource r) {
try (BufferedReader reader = new BufferedReader(open(r))) {
Union streamResources = new Union();
streamResources.setCache(true);
reader.lines().map(this::parse).forEach(streamResources::add);
return streamResources;
} catch (final IOException ioe) {
throw new BuildException("Unable to read resource " + r.getName()
+ ": " + ioe, ioe, getLocation());
}
}
示例6: 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(Resource r) {
String n = r.getName();
if (matches(n)) {
return true;
}
String s = r.toString();
return s.equals(n) ? false : matches(s);
}
示例7: 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();
}
}
示例8: getProperties
import org.apache.tools.ant.types.Resource; //导入方法依赖的package包/类
/**
* Load a properties resource.
* @param propertyResource the resource to load the properties from.
* @return loaded <code>Properties</code> object.
* @throws BuildException if the resource could not be found or read.
* @since Ant 1.8.0
*/
public Properties getProperties(Resource propertyResource)
throws BuildException {
Properties props = new Properties();
try (
InputStream
in = propertyResource.getInputStream()){
props.load(in);
} catch (IOException e) {
throw new BuildException("Property resource (%s) cannot be loaded.",
propertyResource.getName());
}
return props;
}
示例9: selectSources
import org.apache.tools.ant.types.Resource; //导入方法依赖的package包/类
/**
* Tells which sources should be reprocessed because the given
* selector selects at least one target.
*
* @param logTo where to send (more or less) interesting output.
* @param source ResourceCollection.
* @param mapper filename mapper indicating how to find the target Resources.
* @param targets object able to map a relative path as a Resource.
* @param selector returns a selector that is applied to target
* files. If it selects at least one target the source will be
* added to the returned collection.
* @return ResourceCollection.
* @since Ant 1.8.0
*/
public static ResourceCollection selectSources(final ProjectComponent logTo,
ResourceCollection source,
final FileNameMapper mapper,
final ResourceFactory targets,
final ResourceSelectorProvider selector) {
if (source.isEmpty()) {
logTo.log("No sources found.", Project.MSG_VERBOSE);
return Resources.NONE;
}
source = Union.getInstance(source);
final Union result = new Union();
for (final Resource sr : source) {
String srName = sr.getName();
srName = srName == null
? srName : srName.replace('/', File.separatorChar);
String[] targetnames = null;
try {
targetnames = mapper.mapFileName(srName);
} catch (final Exception e) {
logTo.log("Caught " + e + " mapping resource " + sr,
Project.MSG_VERBOSE);
}
if (targetnames == null || targetnames.length == 0) {
logTo.log(sr + " skipped - don\'t know how to handle it",
Project.MSG_VERBOSE);
continue;
}
for (int i = 0; i < targetnames.length; i++) {
if (targetnames[i] == null) {
targetnames[i] = "(no name)";
}
}
final Union targetColl = new Union();
for (int i = 0; i < targetnames.length; i++) {
targetColl.add(targets.getResource(
targetnames[i].replace(File.separatorChar, '/')));
}
//find the out-of-date targets:
final Restrict r = new Restrict();
r.add(selector.getTargetSelectorForSource(sr));
r.add(targetColl);
if (r.size() > 0) {
result.add(sr);
final Resource t = r.iterator().next();
logTo.log(sr.getName() + " added as " + t.getName()
+ (t.isExists() ? " is outdated." : " doesn\'t exist."),
Project.MSG_VERBOSE);
continue;
}
//log uptodateness of all targets:
logTo.log(sr.getName()
+ " omitted as " + targetColl.toString()
+ (targetColl.size() == 1 ? " is" : " are ")
+ " up to date.", Project.MSG_VERBOSE);
}
return result;
}
示例10: execute
import org.apache.tools.ant.types.Resource; //导入方法依赖的package包/类
/**
* Execute the task.
*/
@Override
public void execute() throws BuildException {
log("Starting scan.", verboseLevel);
long start = System.currentTimeMillis();
setupIvy();
int numErrors = 0;
if ( ! verifySortedCoordinatesPropertiesFile(centralizedVersionsFile)) {
++numErrors;
}
if ( ! verifySortedCoordinatesPropertiesFile(ignoreConflictsFile)) {
++numErrors;
}
collectDirectDependencies();
if ( ! collectVersionConflictsToIgnore()) {
++numErrors;
}
int numChecked = 0;
@SuppressWarnings("unchecked")
Iterator<Resource> iter = (Iterator<Resource>)ivyXmlResources.iterator();
while (iter.hasNext()) {
final Resource resource = iter.next();
if ( ! resource.isExists()) {
throw new BuildException("Resource does not exist: " + resource.getName());
}
if ( ! (resource instanceof FileResource)) {
throw new BuildException("Only filesystem resources are supported: "
+ resource.getName() + ", was: " + resource.getClass().getName());
}
File ivyXmlFile = ((FileResource)resource).getFile();
try {
if ( ! checkIvyXmlFile(ivyXmlFile)) {
++numErrors;
}
if ( ! resolveTransitively(ivyXmlFile)) {
++numErrors;
}
if ( ! findLatestConflictVersions()) {
++numErrors;
}
} catch (Exception e) {
throw new BuildException("Exception reading file " + ivyXmlFile.getPath() + " - " + e.toString(), e);
}
++numChecked;
}
log("Checking for orphans in " + centralizedVersionsFile.getName(), verboseLevel);
for (Map.Entry<String,Dependency> entry : directDependencies.entrySet()) {
String coordinateKey = entry.getKey();
if ( ! entry.getValue().directlyReferenced) {
log("ORPHAN coordinate key '" + coordinateKey + "' in " + centralizedVersionsFile.getName()
+ " is not found in any " + IVY_XML_FILENAME + " file.",
Project.MSG_ERR);
++numErrors;
}
}
int numConflicts = emitConflicts();
int messageLevel = numErrors > 0 ? Project.MSG_ERR : Project.MSG_INFO;
log("Checked that " + centralizedVersionsFile.getName() + " and " + ignoreConflictsFile.getName()
+ " have lexically sorted '/org/name' keys and no duplicates or orphans.",
messageLevel);
log("Scanned " + numChecked + " " + IVY_XML_FILENAME + " files for rev=\"${/org/name}\" format.",
messageLevel);
log("Found " + numConflicts + " indirect dependency version conflicts.");
log(String.format(Locale.ROOT, "Completed in %.2fs., %d error(s).",
(System.currentTimeMillis() - start) / 1000.0, numErrors),
messageLevel);
if (numConflicts > 0 || numErrors > 0) {
throw new BuildException("Lib versions check failed. Check the logs.");
}
}
示例11: 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);
}
}
}
}
示例12: createDirectoryCollection
import org.apache.tools.ant.types.Resource; //导入方法依赖的package包/类
private List<Directory> createDirectoryCollection(final ResourceCollection rc) {
// not a fileset or contains non-file resources
if (!rc.isFilesystemOnly()) {
throw new BuildException("Only FileSystem resources are supported.");
}
List<Directory> ds = new ArrayList<>();
for (Resource r : rc) {
if (!r.isExists()) {
throw new BuildException("Could not find resource %s to scp.",
r.toLongString());
}
FileProvider fp = r.as(FileProvider.class);
if (fp == null) {
throw new BuildException("Resource %s is not a file.",
r.toLongString());
}
FileResource fr = ResourceUtils.asFileResource(fp);
File baseDir = fr.getBaseDir();
if (baseDir == null) {
throw new BuildException(
"basedir for resource %s is undefined.", r.toLongString());
}
// if the basedir is set, the name will be relative to that
String name = r.getName();
Directory root = new Directory(baseDir);
Directory current = root;
File currentParent = baseDir;
for (String element : Directory.getPath(name)) {
final File file = new File(currentParent, element);
if (file.isDirectory()) {
current.addDirectory(new Directory(file));
current = current.getChild(file);
currentParent = current.getDirectory();
} else if (file.isFile()) {
current.addFile(file);
}
}
ds.add(root);
}
return ds;
}
示例13: getLastNamePart
import org.apache.tools.ant.types.Resource; //导入方法依赖的package包/类
private String getLastNamePart(Resource r) {
String n = r.getName();
int idx = n.lastIndexOf('/');
return idx < 0 ? n : n.substring(idx + 1);
}