/** * Convenience method to copy content from one Resource to another. * No filtering is performed. * * @param source the Resource to copy from. * Must not be <code>null</code>. * @param dest the Resource to copy to. * Must not be <code>null</code>. * * @throws IOException if the copying fails. * * @since Ant 1.7 */ public static void copyResource(final Resource source, final Resource dest) throws IOException { copyResource(source, dest, null); }
/** * Tells which source files should be reprocessed based on the * last modification date of target files. * @param logTo where to send (more or less) interesting output. * @param source array of resources bearing relative path and last * modification date. * @param mapper filename mapper indicating how to find the target * files. * @param targets object able to map as a resource a relative path * at <b>destination</b>. * @return array containing the source files which need to be * copied or processed, because the targets are out of date or do * not exist. */ public static Resource[] selectOutOfDateSources(final ProjectComponent logTo, final Resource[] source, final FileNameMapper mapper, final ResourceFactory targets) { return selectOutOfDateSources(logTo, source, mapper, targets, FILE_UTILS.getFileTimestampGranularity()); }
private static void copyWithFilterChainsOrTranscoding(final Resource source, final Resource dest, final Vector<FilterChain> filterChains, final boolean append, final String inputEncoding, final String outputEncoding, final Project project) throws IOException { if (areSame(source, dest)) { // copying the "same" file to itself will corrupt the file, so we skip it log(project, "Skipping (self) copy of " + source + " to " + dest); return; } try (Reader in = filterWith(project, inputEncoding, filterChains, source.getInputStream()); BufferedWriter out = new BufferedWriter(new OutputStreamWriter( getOutputStream(dest, append, project), charsetFor(outputEncoding)))) { final char[] buffer = new char[FileUtils.BUF_SIZE]; while (true) { final int nRead = in.read(buffer, 0, buffer.length); if (nRead == -1) { break; } out.write(buffer, 0, nRead); } } }
private static void copyUsingStreams(final Resource source, final Resource dest, final boolean append, final Project project) throws IOException { if (areSame(source, dest)) { // copying the "same" file to itself will corrupt the file, so we skip it log(project, "Skipping (self) copy of " + source + " to " + dest); return; } try (InputStream in = source.getInputStream(); OutputStream out = getOutputStream(dest, append, project)) { final byte[] buffer = new byte[FileUtils.BUF_SIZE]; int count = 0; do { out.write(buffer, 0, count); count = in.read(buffer, 0, buffer.length); } while (count != -1); } }
/** * 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); } }
private Resource[] selectOutOfDateResources(final Resource[] initial, final FileNameMapper mapper) { final Resource[] rs = selectFileResources(initial); Resource[] result = ResourceUtils.selectOutOfDateSources(this, rs, mapper, getZipScanner(), ZIP_FILE_TIMESTAMP_GRANULARITY); if (!doFilesonly) { final Union u = new Union(); u.addAll(Arrays.asList(selectDirectoryResources(initial))); final ResourceCollection rc = ResourceUtils.selectSources(this, u, mapper, getZipScanner(), MISSING_DIR_PROVIDER); if (!rc.isEmpty()) { final List<Resource> newer = new ArrayList<>(); newer.addAll(Arrays.asList(((Union) rc).listResources())); newer.addAll(Arrays.asList(result)); result = newer.toArray(result); } } return result; }
return d1 ? -1 : 1; return text ? textCompare(r1, r2) : binaryCompare(r1, r2);
/** * Compare two Resources by content. * @param foo the first Resource. * @param bar the second Resource. * @return a negative integer, zero, or a positive integer as the first * argument is less than, equal to, or greater than the second. * @throws BuildException if I/O errors occur. * @see org.apache.tools.ant.util.ResourceUtils#compareContent(Resource, Resource, boolean) */ protected int resourceCompare(Resource foo, Resource bar) { try { return ResourceUtils.compareContent(foo, bar, !binary); } catch (IOException e) { throw new BuildException(e); } }
private static Reader filterWith(Project project, String encoding, Vector<FilterChain> filterChains, InputStream input) { Reader r = new InputStreamReader(input, charsetFor(encoding)); if (filterChains != null && !filterChains.isEmpty()) { final ChainReaderHelper crh = new ChainReaderHelper(); crh.setBufferSize(FileUtils.BUF_SIZE); crh.setPrimaryReader(r); crh.setFilterChains(filterChains); crh.setProject(project); r = crh.getAssembledReader(); } return new BufferedReader(r); }
for (final Resource res : rc) { final FileResource r = ResourceUtils .asFileResource(res.as(FileProvider.class)); File base = r.getBaseDir(); if (base == null) {
return compareContent(r1, r2, text) == 0;
/** * Convenience method to copy content from one Resource to another. * No filtering is performed. * * @param source the Resource to copy from. * Must not be <code>null</code>. * @param dest the Resource to copy to. * Must not be <code>null</code>. * @param project the project instance. * * @throws IOException if the copying fails. * * @since Ant 1.7 */ public static void copyResource(final Resource source, final Resource dest, final Project project) throws IOException { copyResource(source, dest, null, null, false, false, null, null, project); }
.asFileResource(r.as(FileProvider.class));
throws IOException { if (areSame(source, dest)) { log(project, "Skipping (self) copy of " + source + " to " + dest); return; try (Reader in = filterWith(project, inputEncoding, filterChains, source.getInputStream()); BufferedWriter out = new BufferedWriter(new OutputStreamWriter( getOutputStream(dest, append, project), charsetFor(outputEncoding)))) {
.of(ResourceUtils.selectOutOfDateSources(task, sourceResources, mapper, this, granularity)) .map(Resource::getName).toArray(String[]::new);
final Project project) throws IOException { copyResource(source, dest, filters, filterChains, overwrite, preserveLastModified, false, inputEncoding, outputEncoding, project);
final FileProvider fp = r.as(FileProvider.class); if (fp != null) { final FileResource fr = ResourceUtils.asFileResource(fp); baseDir = getKeyFile(fr.getBaseDir()); if (fr.getBaseDir() == null) {
toCopy = ResourceUtils.selectOutOfDateSources(this, fromResources, mapper, name -> new FileResource(toDir, name), granularity);
final Project project) throws IOException { copyResource(source, dest, filters, filterChains, overwrite, preserveLastModified, append, inputEncoding, outputEncoding, project, /* force: */ false);
FileProvider fp = res.as(FileProvider.class); if (fp != null) { FileResource fr = ResourceUtils.asFileResource(fp); base = fr.getBaseDir(); if (base == null) {