/** * Synchronize access. * @return the name/value of this StringResource. */ @Override public synchronized String getName() { return super.getName(); }
/** * Compare two Resources. * @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. */ protected int resourceCompare(Resource foo, Resource bar) { return foo.getName().compareTo(bar.getName()); }
private String getLastNamePart(Resource r) { String n = r.getName(); int idx = n.lastIndexOf('/'); return idx < 0 ? n : n.substring(idx + 1); } }
/** * Get the name of the resource. * @return the name of the wrapped resource. */ @Override public String getName() { return getResource().getName(); }
/** * 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; }
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()); } }
/** * Get the name of this URLResource * (its file component minus the leading separator). * @return the name of this resource. */ public synchronized String getName() { if (isReference()) { return getCheckedRef().getName(); } String name = getURL().getFile(); return name.isEmpty() ? name : name.substring(1); }
/** * For file-based archivefilesets, return the same as for normal filesets; * else just return the path of the zip. * @return for file based archivefilesets, included files as a list * of semicolon-separated filenames. else just the name of the zip. */ @Override public String toString() { if (hasDir && getProject() != null) { return super.toString(); } return src == null ? null : src.getName(); }
/** * 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()); } }
/** * 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()); } } }
/** * 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) && matches(s); }
/** * Name attribute will contain the path of a file relative to the * root directory of its fileset or the recorded path of a zip * entry. * * <p>example for a file with fullpath /var/opt/adm/resource.txt * in a file set with root dir /var/opt it will be * adm/resource.txt.</p> * * <p>"/" will be used as the directory separator.</p> * @return the name of this resource. */ public String getName() { return isReference() ? getCheckedRef().getName() : name; }
private Collection<Resource> getCollection() { FileNameMapper m = mapper == null ? new IdentityMapper() : mapper.getImplementation(); Stream<MappedResource> stream; if (enableMultipleMappings) { stream = nested.stream() .flatMap(r -> Stream.of(m.mapFileName(r.getName())) .filter(Objects::nonNull) .map(MergingMapper::new) .map(mm -> new MappedResource(r, mm))); } else { stream = nested.stream().map(r -> new MappedResource(r, m)); } return stream.collect(Collectors.toList()); }
/** * Get the hash code for this Resource. * @return hash code as int. * @since Ant 1.7 */ @Override public int hashCode() { if (isReference()) { return getCheckedRef().hashCode(); } String name = getName(); return MAGIC * (name == null ? NULL_NAME : name.hashCode()); }
/** * Maps the name. */ @Override public String getName() { String name = getResource().getName(); if (isReference()) { return name; } String[] mapped = mapper.mapFileName(name); return mapped != null && mapped.length > 0 ? mapped[0] : null; }
/** * 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; }
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(); } }
/** * Determine a Resource's Unix mode or return the given default * value if not available. */ private int getUnixMode(final Resource r, final ZipFile zf, final int defaultMode) { int unixMode = defaultMode; if (zf != null) { final ZipEntry ze = zf.getEntry(r.getName()); unixMode = ze.getUnixMode(); if ((unixMode == 0 || unixMode == UnixStat.DIR_FLAG) && !preserve0Permissions) { unixMode = defaultMode; } } else if (r instanceof ArchiveResource) { unixMode = ((ArchiveResource) r).getMode(); } return unixMode; }
/** * Log which Resources (if any) have been modified in the future. * @param logTo the ProjectComponent to do the logging. * @param rc the collection of Resources to check. * @param granularity the timestamp granularity to use. * @since Ant 1.7 */ private static void logFuture(final ProjectComponent logTo, final ResourceCollection rc, final long granularity) { final long now = System.currentTimeMillis() + granularity; final Date sel = new Date(); sel.setMillis(now); sel.setWhen(TimeComparison.AFTER); final Restrict future = new Restrict(); future.add(sel); future.add(rc); for (final Resource r : future) { logTo.log("Warning: " + r.getName() + " modified in the future.", Project.MSG_WARN); } }
private void touch(Resource r, long defaultTimestamp) { if (fileNameMapper == null) { FileProvider fp = r.as(FileProvider.class); if (fp != null) { // use this to create file and deal with non-writable files touch(fp.getFile(), defaultTimestamp); } else { r.as(Touchable.class).touch(defaultTimestamp); } } else { String[] mapped = fileNameMapper.mapFileName(r.getName()); if (mapped != null && mapped.length > 0) { long modTime = defaultTimestamp; if (millis < 0 && r.isExists()) { modTime = r.getLastModified(); } for (String fileName : mapped) { touch(getProject().resolveFile(fileName), modTime); } } } }