本文整理汇总了Java中org.apache.tools.ant.types.resources.FileResource类的典型用法代码示例。如果您正苦于以下问题:Java FileResource类的具体用法?Java FileResource怎么用?Java FileResource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FileResource类属于org.apache.tools.ant.types.resources包,在下文中一共展示了FileResource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: collectClassesJarsAndResources
import org.apache.tools.ant.types.resources.FileResource; //导入依赖的package包/类
/** Also modifies resourceReferences collection */
@SuppressWarnings("unchecked")
private List<String> collectClassesJarsAndResources() {
Resources filesToProcess = new Resources();
List<String> result = new ArrayList<String> (filesToProcess.size());
filesToProcess.setProject(getProject());
if (filesets == null)
throw new BuildException("Specify files to process using nested <fileset> element");
for (FileSet fileset : filesets) {
filesToProcess.add(fileset);
}
Iterator<org.apache.tools.ant.types.Resource> iter = (Iterator<org.apache.tools.ant.types.Resource>) filesToProcess.iterator();
while (iter.hasNext()) {
appendClassOrJarOrResource(result, (FileResource) iter.next());
}
return result;
}
示例2: appendClassOrJarOrResource
import org.apache.tools.ant.types.resources.FileResource; //导入依赖的package包/类
private void appendClassOrJarOrResource(List<String> result, FileResource r) {
String relativeName = r.getName();
String fullFileName = r.getFile().getAbsolutePath();
if (!r.isExists())
throw new BuildException ("Missing input file: " + fullFileName);
boolean classOrJar = relativeName.endsWith(".class") || relativeName.endsWith(".jar") || relativeName.endsWith(".zip");
if (classOrJar) {
if (verbose)
System.out.println("\t+file: " + relativeName);
result.add(fullFileName);
} else {
if (verbose)
System.out.println("\t+resource: " + relativeName);
String resourceName = replaceNTPathChar(relativeName);
createResource().set (resourceName, fullFileName);
result.add ("-resource:" + resourceName + '=' + fullFileName);
}
}
示例3: getModuleDescriptors
import org.apache.tools.ant.types.resources.FileResource; //导入依赖的package包/类
private synchronized Map<ModuleDescriptor, File> getModuleDescriptors() {
if (md2IvyFile == null) {
md2IvyFile = new HashMap<>();
for (ResourceCollection resources : allResources) {
for (Resource resource : resources) {
File ivyFile = ((FileResource) resource).getFile();
try {
ModuleDescriptor md = ModuleDescriptorParserRegistry.getInstance()
.parseDescriptor(getParserSettings(), ivyFile.toURI().toURL(),
isValidate());
md2IvyFile.put(md, ivyFile);
Message.debug("Add " + md.getModuleRevisionId().getModuleId());
} catch (Exception ex) {
if (haltOnError) {
throw new BuildException("impossible to parse ivy file " + ivyFile
+ " exception=" + ex, ex);
} else {
Message.warn("impossible to parse ivy file " + ivyFile
+ " exception=" + ex.getMessage());
}
}
}
}
}
return md2IvyFile;
}
示例4: getStylesheet
import org.apache.tools.ant.types.resources.FileResource; //导入依赖的package包/类
/**
* access the stylesheet to be used as a resource.
* @return stylesheet as a resource
*/
protected Resource getStylesheet() {
String xslname = "junit-frames.xsl";
if (NOFRAMES.equals(format)) {
xslname = "junit-noframes.xsl";
}
if (styleDir == null) {
// If style dir is not specified we have to retrieve
// the stylesheet from the classloader
URL stylesheetURL = getClass().getClassLoader().getResource(
"org/apache/tools/ant/taskdefs/optional/junit/xsl/" + xslname);
return new URLResource(stylesheetURL);
}
// If we are here, then the style dir is here and we
// should read the stylesheet from the filesystem
return new FileResource(new File(styleDir, xslname));
}
示例5: tarFile
import org.apache.tools.ant.types.resources.FileResource; //导入依赖的package包/类
/**
* tar a file
* @param file the file to tar
* @param tOut the output stream
* @param vPath the path name of the file to tar
* @param tarFileSet the fileset that the file came from.
* @throws IOException on error
*/
protected void tarFile(final File file, final TarOutputStream tOut, final String vPath,
final TarFileSet tarFileSet)
throws IOException {
if (file.equals(tarFile)) {
// If the archive is built for the first time and it is
// matched by a resource collection, then it hasn't been
// found in check (it hasn't been there) but will be
// included now.
//
// for some strange reason the old code would simply skip
// the entry and not fail, do the same now for backwards
// compatibility reasons. Without this, the which4j build
// fails in Gump
return;
}
tarResource(new FileResource(file), tOut, vPath, tarFileSet);
}
示例6: processResources
import org.apache.tools.ant.types.resources.FileResource; //导入依赖的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: restrict
import org.apache.tools.ant.types.resources.FileResource; //导入依赖的package包/类
/**
* Restrict the given set of files to those that are newer than
* their corresponding target files.
*
* @param files the original set of files.
* @param srcDir all files are relative to this directory.
* @param destDir target files live here. If null file names
* returned by the mapper are assumed to be absolute.
* @param mapper knows how to construct a target file names from
* source file names.
* @param granularity The number of milliseconds leeway to give
* before deciding a target is out of date.
* @return an array of filenames.
*
* @since Ant 1.6.2
*/
public String[] restrict(String[] files, File srcDir, File destDir,
FileNameMapper mapper, long granularity) {
// record destdir for later use in getResource
this.destDir = destDir;
Resource[] sourceResources =
Stream.of(files).map(f -> new FileResource(srcDir, f) {
@Override
public String getName() {
return f;
}
}).toArray(Resource[]::new);
// build the list of sources which are out of date with
// respect to the target
return Stream
.of(ResourceUtils.selectOutOfDateSources(task, sourceResources,
mapper, this, granularity))
.map(Resource::getName).toArray(String[]::new);
}
示例8: executeAndCheckResults
import org.apache.tools.ant.types.resources.FileResource; //导入依赖的package包/类
private void executeAndCheckResults(String[] expected) throws BuildException, IOException {
String[] output = new String[pfs.size()];
int j = 0;
for (Iterator it = pfs.iterator(); it.hasNext(); j++) {
FileResource fileResource = (FileResource) it.next();
String path = fileResource.getFile().getAbsolutePath().replace('\\', '/');
output[j] = path;
}
Arrays.sort(output);
String wd = getWorkDir().getPath().replace('\\', '/').concat("/");
for (int i = 0; i < expected.length; i++) {
expected[i] = wd + expected[i];
}
assertArrayEquals(expected, output);
}
示例9: generateFiles
import org.apache.tools.ant.types.resources.FileResource; //导入依赖的package包/类
private void generateFiles() throws IOException, BuildException {
for (Iterator<Resource> fileIt = files.iterator(); fileIt.hasNext();) {
FileResource fr = (FileResource) fileIt.next();
File jar = fr.getFile();
if (!jar.canRead()) {
throw new BuildException("Cannot read file: " + jar);
}
try (JarFile theJar = new JarFile(jar)) {
String codenamebase = JarWithModuleAttributes.extractCodeName(theJar.getManifest().getMainAttributes());
if (codenamebase == null) {
throw new BuildException("Not a NetBeans Module: " + jar);
}
if (codenamebase.equals("org.objectweb.asm.all")
&& jar.getParentFile().getName().equals("core")
&& jar.getParentFile().getParentFile().getName().startsWith("platform")) {
continue;
}
{
int slash = codenamebase.indexOf('/');
if (slash >= 0) {
codenamebase = codenamebase.substring(0, slash);
}
}
String dashcnb = codenamebase.replace('.', '-');
File n = new File(target, dashcnb + ".ref");
try (FileWriter w = new FileWriter(n)) {
w.write(" <extension name='" + codenamebase + "' href='" + this.masterPrefix + dashcnb + ".jnlp' />\n");
}
}
}
}
示例10: testPathsDirectoryWithNestedFile
import org.apache.tools.ant.types.resources.FileResource; //导入依赖的package包/类
@Test
public final void testPathsDirectoryWithNestedFile() throws IOException {
// given
TestRootModuleChecker.reset();
final CheckstyleAntTaskLogStub antTask = new CheckstyleAntTaskLogStub();
antTask.setConfig(getPath(CUSTOM_ROOT_CONFIG_FILE));
antTask.setProject(new Project());
final FileResource fileResource = new FileResource(
antTask.getProject(), getPath(""));
final Path sourcePath = new Path(antTask.getProject());
sourcePath.add(fileResource);
antTask.addPath(sourcePath);
// when
antTask.execute();
// then
assertTrue("Checker is not processed",
TestRootModuleChecker.isProcessed());
final List<File> filesToCheck = TestRootModuleChecker.getFilesToCheck();
assertThat("There more files to check then expected",
filesToCheck.size(), is(9));
assertThat("The path of file differs from expected",
filesToCheck.get(5).getAbsolutePath(), is(getPath(FLAWLESS_INPUT)));
assertEquals("Amount of logged messages in unexpected",
9, antTask.getLoggedMessages().size());
}
示例11: generateChecksum
import org.apache.tools.ant.types.resources.FileResource; //导入依赖的package包/类
protected void generateChecksum(FileResource fr, File checksumFile)
throws IOException
{
log("Generating checksum for " + fr.getName(), Project.MSG_INFO);
String csStr = FileListUtil.generateChecksum(fr.getInputStream(),
checksumAlgorithm);
PrintWriter pr = new PrintWriter(new FileWriter(checksumFile));
pr.println(csStr);
pr.close();
}
示例12: processJars
import org.apache.tools.ant.types.resources.FileResource; //导入依赖的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);
}
示例13: resolveResources
import org.apache.tools.ant.types.resources.FileResource; //导入依赖的package包/类
private Collection<Resource> resolveResources(String id) throws BuildException {
prepareAndCheck();
try {
List<Resource> resources = new ArrayList<>();
if (id != null) {
getProject().addReference(id, this);
}
for (ArtifactDownloadReport adr : getArtifactReports()) {
resources.add(new FileResource(adr.getLocalFile()));
}
return resources;
} catch (Exception ex) {
throw new BuildException("impossible to build ivy resources: " + ex, ex);
}
}
示例14: asList
import org.apache.tools.ant.types.resources.FileResource; //导入依赖的package包/类
private List<File> asList(IvyResources ivyResources) {
List<File> resources = new ArrayList<>();
for (Object r : ivyResources) {
assertTrue(r instanceof FileResource);
resources.add(((FileResource) r).getFile());
}
return resources;
}
示例15: setFiles
import org.apache.tools.ant.types.resources.FileResource; //导入依赖的package包/类
/**
* Set the list of files to be attached.
*
* @param filenames Comma-separated list of files.
*/
public void setFiles(String filenames) {
StringTokenizer t = new StringTokenizer(filenames, ", ");
while (t.hasMoreTokens()) {
createAttachments()
.add(new FileResource(getProject().resolveFile(t.nextToken())));
}
}