Refine search
/** * 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; }
/** * 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; }
/** * Get the string representation of this Resource. * @return this Resource formatted as a String. * @since Ant 1.7 */ @Override public String toString() { if (isReference()) { return getCheckedRef().toString(); } String n = getName(); return n == null ? "(anonymous)" : n; }
/** * The exists attribute tells whether a resource exists. * @return true if this resource exists. */ public boolean isExists() { if (isReference()) { return getCheckedRef().isExists(); } //default true: return exists == null || exists; }
/** * Fulfill the ResourceCollection contract. * @return whether this Resource is a FileProvider. * @since Ant 1.7 */ @Override public boolean isFilesystemOnly() { return (isReference() && getCheckedRef().isFilesystemOnly()) || this.as(FileProvider.class) != null; }
/** * 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; }
/** * Implement the gunzipping. */ @Override protected void extract() { if (srcResource.getLastModified() > dest.lastModified()) { log("Expanding " + srcResource.getName() + " to " + dest.getAbsolutePath()); try (OutputStream out = Files.newOutputStream(dest.toPath()); GZIPInputStream zIn = new GZIPInputStream(srcResource.getInputStream())) { byte[] buffer = new byte[BUFFER_SIZE]; int count = 0; do { out.write(buffer, 0, count); count = zIn.read(buffer, 0, buffer.length); } while (count != -1); } catch (IOException ioe) { String msg = "Problem expanding gzip " + ioe.getMessage(); throw new BuildException(msg, ioe, getLocation()); } } }
/** * Returns the list of files corresponding to the resource collection * * @param resources - A list of {@link ResourceCollection} * @return the list of files corresponding to the resource collection * @throws BuildException */ private List<String> getFiles(List<ResourceCollection> resources) throws BuildException { List<String> files= Lists.newArrayList(); for (ResourceCollection rc : resources) { for (Resource o : rc) { if (o instanceof FileResource) { FileResource fr = ((FileResource) o); if (fr.isDirectory()) { throw new BuildException("Directory based FileResources are not supported."); } if (! fr.isExists()) { log("'" + fr.toLongString() + "' does not exist", Project.MSG_VERBOSE); } files.add(fr.getFile().getAbsolutePath()); } else { log("Unsupported Resource type: " + o.toString(), Project.MSG_VERBOSE); } } } return files; }
if (resource.isFilesystemOnly()) { File file = fileResource.getFile(); String filename = fileResource.getName(); File basedir = fileResource.getBaseDir(); return isSelected(basedir, filename, file); FileUtils fu = FileUtils.getFileUtils(); File tmpFile = fu.createTempFile("modified-", ".tmp", null, true, false); Resource tmpResource = new FileResource(tmpFile); ResourceUtils.copyResource(resource, tmpResource); boolean isSelected = isSelected(tmpFile.getParentFile(), tmpFile.getName(), resource.toLongString()); tmpFile.delete(); return isSelected; } catch (UnsupportedOperationException uoe) { log("The resource '" + resource.getName() + "' does not provide an InputStream, so it is not checked. " + "According to 'selres' attribute value it is " return selectResourcesWithoutInputStream; } catch (Exception e) { throw new BuildException(e);
/** * 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."); } }
while (resources.hasNext()) { Resource r = (Resource) resources.next(); if (!r.isExists()) { continue; String baseDir = fr.getBaseDir().getAbsolutePath(); String file = fr.getFile().getAbsolutePath(); file = file.substring(baseDir.length(), file.length()); String[] parts = file.split("/"); throw new BuildException("Unable to recognize the path separator for src file: " + file); File specificDestinationFile = new File(destDir, specificFilePart); if (specificFile.exists()) { fileUtils.copyFile(specificFile, specificDestinationFile); continue; File generalFile = new File(licenseDir, generalFilePart); if (generalFile.exists()) { fileUtils.copyFile(generalFile, specificDestinationFile); continue; File moreGeneralFile = new File(licenseDir, moreGeneralFilePart); if (moreGeneralFile.exists()) { fileUtils.copyFile(moreGeneralFile, specificDestinationFile); throw new BuildException(e);
url = (URL) source; } else if (source instanceof Resource) { FileProvider fp = ((Resource) source).as(FileProvider.class); if (fp != null) { buildFile = fp.getFile(); } else { URLProvider up = ((Resource) source).as(URLProvider.class); if (up != null) { url = up.getURL(); buildFile = FILE_UTILS.normalize(buildFile.getAbsolutePath()); context.setBuildFile(buildFile); buildFileName = buildFile.toString(); context.setBuildFile(url); } catch (MalformedURLException ex) { throw new BuildException(ex); throw new BuildException("Source " + source.getClass().getName() + " not supported by this plugin"); uri = FILE_UTILS.toURI(buildFile.getAbsolutePath()); inputStream = Files.newInputStream(buildFile.toPath()); } else {
/** * Return true if this Resource is selected. * @param r the Resource to check. * @return whether the Resource was selected. */ public boolean isSelected(final Resource r) { if (type == null) { throw new BuildException("The type attribute is required."); } final int i = type.getIndex(); return i == 2 || (r.isDirectory() ? i == 1 : i == 0); }
final List<Resource> v = new ArrayList<>(); for (Resource rc : fromResources) { if (mapper.mapFileName(rc.getName()) != null) { v.add(rc); } else { toCopy = ResourceUtils.selectOutOfDateSources(this, fromResources, mapper, name -> new FileResource(toDir, name), granularity); final String[] mappedFiles = mapper.mapFileName(rc.getName()); if (mappedFiles == null || mappedFiles.length == 0) { throw new BuildException("Can't copy a resource without a" + " name if the mapper doesn't" + " provide one.");
throws IOException { if (!r.isExists()) { return; if (r.isDirectory() && !vPath.endsWith("/")) { vPath += "/"; throw new BuildException("Entry: " + vPath + " longer than " + TarConstants.NAMELEN + "characters.", getLocation()); te.setModTime(r.getLastModified()); if (!r.isDirectory()) { if (r.size() > TarConstants.MAXSIZE) { throw new BuildException( "Resource: " + r + " larger than " + TarConstants.MAXSIZE + " bytes."); te.setSize(r.getSize()); tOut.putNextEntry(te); if (!r.isDirectory()) { in = r.getInputStream(); FileUtils.close(in);
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()); } }
if (resource.getSize() == 0) { return false; new InputStreamReader(resource.getInputStream()))) { String contents = FileUtils.safeReadFully(reader); String sub = substring; if (!casesensitive) { throw new BuildException("There was a problem accessing resource : " + resource);
upToDate = check(fs.getDir(getProject()), getFileNames(fs)); } else if (!rc.isFilesystemOnly() && !supportsNonFileResources()) { throw new BuildException("only filesystem resources are supported"); } else if (rc.isFilesystemOnly()) { final Set<File> basedirs = new HashSet<>(); for (final Resource res : rc) { final FileResource r = ResourceUtils .asFileResource(res.as(FileProvider.class)); File base = r.getBaseDir(); if (base == null) { base = Copy.NULL_FILE_PLACEHOLDER; List<String> files = basedirToFilesMap.computeIfAbsent(base, k -> new Vector<>()); if (base == Copy.NULL_FILE_PLACEHOLDER) { files.add(r.getFile().getAbsolutePath()); } else { files.add(r.getName());
/** * Return an InputStream for reading the contents of this Resource. * @return an InputStream object. * @throws IOException if the tar file cannot be opened, * or the entry cannot be read. */ @Override public InputStream getInputStream() throws IOException { if (isReference()) { return getCheckedRef().getInputStream(); } Resource archive = getArchive(); final TarInputStream i = new TarInputStream(archive.getInputStream()); TarEntry te; while ((te = i.getNextEntry()) != null) { if (te.getName().equals(getName())) { return i; } } FileUtils.close(i); throw new BuildException("no entry " + getName() + " in " + getArchive()); }
throw new BuildException("Source file " + srcFile + " is not a file!", getLocation()); OutputStream os = null; FileProvider fp = output.as(FileProvider.class); if (fp != null) { os = FileUtils.newOutputStream(fp.getFile().toPath(), append); } else { if (append) { Appendable a = output.as(Appendable.class); if (a != null) { os = a.getAppendOutputStream(); os = output.getOutputStream(); if (append) { log("Ignoring append=true for non-appendable" FileUtils.close(out); setErrorProperty(); if ("abort".equals(onError)) { throw new BuildException(e, getLocation()); FileUtils.close(getStatement()); } catch (SQLException ex) {