final String adjustedContext = PathUtil.optionallyRemoveFollowingSlash(context); final String adjustedOther = PathUtil.optionallyRemoveFollowingSlash(other.context); if (!adjustedContext.equals(adjustedOther)) { return false;
final String adjustedContext = PathUtil.optionallyRemoveFollowingSlash(context); final String adjustedOther = PathUtil.optionallyRemoveFollowingSlash(other.context); if (!adjustedContext.equals(adjustedOther)) { return false;
/** * Obtains the parent of this Path, if exists, else null. For instance if the Path is "/my/path", the parent will be * "/my". Each call will result in a new object reference, though subsequent calls upon the same Path will be equal * by value. * * @return * * @param path * The path whose parent context we should return */ static ArchivePath getParent(final ArchivePath path) { // Precondition checks assert path != null : "Path must be specified"; // Get the last index of "/" final String resolvedContext = PathUtil.optionallyRemoveFollowingSlash(path.get()); final int lastIndex = resolvedContext.lastIndexOf(ArchivePath.SEPARATOR); // If it either doesn't occur or is the root if (lastIndex == -1 || (lastIndex == 0 && resolvedContext.length() == 1)) { // No parent present, return null return null; } // Get the parent context final String sub = resolvedContext.substring(0, lastIndex); // Return return new BasicPath(sub); }
/** * Obtains the parent of this Path, if exists, else null. For instance if the Path is "/my/path", the parent will be * "/my". Each call will result in a new object reference, though subsequent calls upon the same Path will be equal * by value. * * @return * * @param path * The path whose parent context we should return */ static ArchivePath getParent(final ArchivePath path) { // Precondition checks assert path != null : "Path must be specified"; // Get the last index of "/" final String resolvedContext = PathUtil.optionallyRemoveFollowingSlash(path.get()); final int lastIndex = resolvedContext.lastIndexOf(ArchivePath.SEPARATOR); // If it either doesn't occur or is the root if (lastIndex == -1 || (lastIndex == 0 && resolvedContext.length() == 1)) { // No parent present, return null return null; } // Get the parent context final String sub = resolvedContext.substring(0, lastIndex); // Return return new BasicPath(sub); }
/** * {@inheritDoc} * * @see org.jboss.shrinkwrap.api.Archive#addAsDirectory(org.jboss.shrinkwrap.api.ArchivePath) */ @Override public T addAsDirectory(final ArchivePath path) throws IllegalArgumentException { // Precondition check Validate.notNull(path, "path must be specified"); // Adjust the path to remove any trailing slash ArchivePath adjustedPath = new BasicPath(PathUtil.optionallyRemoveFollowingSlash(path.get())); return addAsset(adjustedPath, null); }
/** * {@inheritDoc} * * @see org.jboss.shrinkwrap.api.Archive#addAsDirectory(org.jboss.shrinkwrap.api.ArchivePath) */ @Override public T addAsDirectory(final ArchivePath path) throws IllegalArgumentException { // Precondition check Validate.notNull(path, "path must be specified"); // Adjust the path to remove any trailing slash ArchivePath adjustedPath = new BasicPath(PathUtil.optionallyRemoveFollowingSlash(path.get())); return addAsset(adjustedPath, null); }
/** * Obtains an {@link InputStream} to an entry of specified name from the specified TAR.GZ file, or null if not * found. We have to iterate through all entries for a matching name, as the instream does not support random * access. * * @param expectedZip * @param path * @return * @throws IllegalArgumentException * @throws IOException */ private InputStream getEntryFromTarFile(final File archive, final ArchivePath path) throws IllegalArgumentException, IOException { String entryPath = PathUtil.optionallyRemovePrecedingSlash(path.get()); final TarInputStream in = this.getTarInputStreamFromFile(archive); TarEntry currentEntry = null; while ((currentEntry = in.getNextEntry()) != null) { final String entryName = currentEntry.getName(); if (currentEntry.isDirectory()) { entryPath = PathUtil.optionallyAppendSlash(entryPath); } else { entryPath = PathUtil.optionallyRemoveFollowingSlash(entryPath); } if (entryName.equals(entryPath)) { return in; } } // Not found return null; }