/** * convert a file to a URL; * * @param fileToConvert File * @return the file converted to a URL */ private String toURL(File fileToConvert) { //create the URL //ant equivalent of fileToConvert.toURI().toURL().toExternalForm(); return FileUtils.getFileUtils().toURI(fileToConvert.getAbsolutePath()); }
/** * Copy task constructor. */ public Copy() { fileUtils = FileUtils.getFileUtils(); granularity = fileUtils.getFileTimestampGranularity(); }
sealBase = new URL(FileUtils.getFileUtils().toURI(container.getAbsolutePath())); } catch (MalformedURLException e) {
private void createNewArgs(String txt) throws IOException { final String[] args = cmdline.getCommandline(); // Temporary file - delete on exit, create (assured unique name). final File tempFile = FileUtils.getFileUtils().createTempFile(PREFIX, SUFFIX, null, true, true); final String[] commandline = new String[args.length + 1]; ResourceGroovyMethods.write(tempFile, txt); commandline[0] = tempFile.getCanonicalPath(); System.arraycopy(args, 0, commandline, 1, args.length); super.clearArgs(); for (String arg : commandline) { final Commandline.Argument argument = super.createArg(); argument.setValue(arg); } }
/** * Finds modules in the expanded modulesourcepath entry. * @param root the project root * @param pathToModule the path to modules folder * @param pathInModule the path in module to source folder * @param collector the map to put modules into * @since 1.9.7 */ private static void findModules( final File root, final String pathToModule, final String pathInModule, final Map<String,Collection<File>> collector) { final File f = FileUtils.getFileUtils().resolveFile(root, pathToModule); if (!f.isDirectory()) { return; } for (File module : f.listFiles(File::isDirectory)) { final String moduleName = module.getName(); final File moduleSourceRoot = pathInModule == null ? module : new File(module, pathInModule); Collection<File> moduleRoots = collector.computeIfAbsent(moduleName, k -> new ArrayList<>()); moduleRoots.add(moduleSourceRoot); } }
private void writeFile() throws BuildException { // Write to RAM first, as an OOME could otherwise produce a truncated file: ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { properties.store(baos, comment); } catch (IOException x) { // should not happen throw new BuildException(x, getLocation()); } try { try (OutputStream os = Files.newOutputStream(propertyfile.toPath())) { os.write(baos.toByteArray()); } catch (IOException x) { // possibly corrupt FileUtils.getFileUtils().tryHardToDelete(propertyfile); throw x; } } catch (IOException x) { // opening, writing, or closing throw new BuildException(x, getLocation()); } }
/** * Resolve a filename with Project's help - if we know one that is. */ private static File resolveFile(Project project, String relativeName) { return FileUtils.getFileUtils().resolveFile( (project == null) ? null : project.getBaseDir(), relativeName); }
/** * get the URL of the schema * @return a URL to the schema * @throws BuildException if not */ public String getSchemaLocationURL() { boolean hasFile = file != null; boolean hasURL = isSet(url); //error if both are empty, or both are set if (!hasFile && !hasURL) { throw new BuildException(ERROR_NO_LOCATION + namespace); } if (hasFile && hasURL) { throw new BuildException(ERROR_TWO_LOCATIONS + namespace); } String schema = url; if (hasFile) { if (!file.exists()) { throw new BuildException(ERROR_NO_FILE + file); } try { schema = FileUtils.getFileUtils().getFileURL(file).toString(); } catch (MalformedURLException e) { //this is almost implausible, but required handling throw new BuildException(ERROR_NO_URL_REPRESENTATION + file, e); } } return schema; }
private static void copyUsingFileChannels(final File sourceFile, final File destFile, final Project project) throws IOException { if (FileUtils.getFileUtils().areSame(sourceFile, destFile)) { // copying the "same" file to itself will corrupt the file, so we skip it log(project, "Skipping (self) copy of " + sourceFile + " to " + destFile); return; } final File parent = destFile.getParentFile(); if (parent != null && !parent.isDirectory() && !(parent.mkdirs() || parent.isDirectory())) { throw new IOException("failed to create the parent directory" + " for " + destFile); } try (FileChannel srcChannel = FileChannel.open(sourceFile.toPath(), StandardOpenOption.READ); FileChannel destChannel = FileChannel.open(destFile.toPath(), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE)) { long position = 0; final long count = srcChannel.size(); while (position < count) { final long chunk = Math.min(MAX_IO_CHUNK_SIZE, count - position); position += destChannel.transferFrom(srcChannel, position, chunk); } } }
/** * sets the build file to which the XML context belongs * @param buildFile ant build file */ public void setBuildFile(File buildFile) { this.buildFile = buildFile; if (buildFile != null) { this.buildFileParent = new File(buildFile.getParent()); implicitTarget.setLocation(new Location(buildFile.getAbsolutePath())); try { setBuildFile(FileUtils.getFileUtils().getFileURL(buildFile)); } catch (MalformedURLException ex) { throw new BuildException(ex); } } else { this.buildFileParent = null; } }
/** * Is the archive up to date in relationship to a list of files. * @param r the files to check * @return true if the archive is up to date. * @since Ant 1.7 */ protected boolean archiveIsUpToDate(final Resource r) { return SelectorUtils.isOutOfDate(new FileResource(tarFile), r, FileUtils.getFileUtils() .getFileTimestampGranularity()); }
return FileUtils.getFileUtils().getFileURL(file); } catch (Exception ex) { message =
/** * The heart of the matter. This is where the selector gets to decide * on the inclusion of a file in a particular fileset. * * @param basedir the base directory the scan is being done from * @param filename is the name of the file to check * @param file is a java.io.File object the selector can use * @return whether the file should be selected or not */ @Override public boolean isSelected(final File basedir, final String filename, final File file) { // throw BuildException on error validate(); // Determine file whose existence is to be checked final String[] destfiles = map.mapFileName(filename); // If filename does not match the To attribute of the mapper // then filter it out of the files we are considering if (destfiles == null) { return false; } // Sanity check if (destfiles.length != 1 || destfiles[0] == null) { throw new BuildException("Invalid destination file results for " + targetdir + " with filename " + filename); } final String destname = destfiles[0]; final File destfile = FileUtils.getFileUtils().resolveFile(targetdir, destname); return destfile.exists() == destmustexist; }
String url = systemid; if (url.startsWith("file:")) { url = FileUtils.getFileUtils().fromURI(url);
final FileUtils fileUtils = FileUtils.getFileUtils(); dir = fileUtils.normalize(dir.getAbsolutePath());
private void collectFileListFromModulePath() { final FileUtils fu = FileUtils.getFileUtils(); for (String pathElement : moduleSourcepath.list()) { boolean valid = false; for (Map.Entry<String, Collection<File>> modules : resolveModuleSourcePathElement( getProject().getBaseDir(), pathElement).entrySet()) { final String moduleName = modules.getKey(); for (File srcDir : modules.getValue()) { if (srcDir.exists()) { valid = true; final DirectoryScanner ds = getDirectoryScanner(srcDir); final String[] files = ds.getIncludedFiles(); scanDir(srcDir, fu.resolveFile(destDir, moduleName), files); } } } if (!valid) { throw new BuildException("modulesourcepath \"" + pathElement + "\" does not exist!", getLocation()); } } }
BufferedWriter out = null; try { tmpFile = FileUtils.getFileUtils().createTempFile("jikes", "tmp", null, false, true); out = new BufferedWriter(new FileWriter(tmpFile));
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); final FileProvider fileResource2 = resource2.as(FileProvider.class); return fileResource1 != null && fileResource2 != null && FileUtils.getFileUtils().areSame(fileResource1.getFile(), fileResource2.getFile()); }
/** * @since Ant 1.7 */ private void expandStream(String name, InputStream stream, File dir) throws IOException { try (TarInputStream tis = new TarInputStream( compression.decompress(name, new BufferedInputStream(stream)), getEncoding())) { log("Expanding: " + name + " into " + dir, Project.MSG_INFO); boolean empty = true; FileNameMapper mapper = getMapper(); TarEntry te; while ((te = tis.getNextEntry()) != null) { empty = false; extractFile(FileUtils.getFileUtils(), null, dir, tis, te.getName(), te.getModTime(), te.isDirectory(), mapper); } if (empty && getFailOnEmptyArchive()) { throw new BuildException("archive '%s' is empty", name); } log("expand complete", Project.MSG_VERBOSE); } }
FileUtils fu = FileUtils.getFileUtils(); File tmpFile = fu.createTempFile("modified-", ".tmp", null, true, false); Resource tmpResource = new FileResource(tmpFile);