Example #1
0
  /**
   * Returns the path of the locked file for the provided lock.
   *
   * <p>Examples:
   *
   * <pre>
   * default://locks@system/repo/master/some/path/to/file.txt.ulock =>
   * default://master@repo/some/path/to/file.txt
   *
   * file:\\locks@system\repo\master\some\path\to\file.txt.ulock =>
   * file:\\master@repo\some\path\to\file.txt
   * </pre>
   *
   * @param lockPath the path of a lock, must not be null.
   * @return the locked path.
   */
  public static Path fromLock(final Path lockPath) {
    checkNotNull("path", lockPath);

    final String uri =
        lockPath
            .toURI()
            .replaceFirst("locks@system(/|\\\\)([^/&^\\\\]*)(/|\\\\)([^/&^\\\\]*)", "$4@$2");

    return PathFactory.newPath(
        lockPath.getFileName().replace(LOCK_FILE_EXTENSION, ""),
        uri.replace(LOCK_FILE_EXTENSION, ""));
  }
Example #2
0
    @Override
    public boolean equals(Object o) {
      if (this == o) {
        return true;
      }
      if (!(o instanceof Path)) {
        return false;
      }

      final Path path = (Path) o;

      return uri.equals(path.toURI());
    }
Example #3
0
  /**
   * Returns a path of a lock for the provided file.
   *
   * <p>Examples:
   *
   * <pre>
   * default://master@repo/some/path/to/file.txt =>
   * default://locks@system/repo/master/some/path/to/file.txt.ulock
   *
   * file:\\master@repo\some\path\to\file.txt =>
   * file:\\locks@system\repo\master\some\path\to\file.txt.ulock
   * </pre>
   *
   * @param path the path of a file for which a lock should be created, must not be null.
   * @return the lock path
   */
  public static Path newLockPath(final Path path) {
    checkNotNull("path", path);

    final String systemUri =
        path.toURI().replaceFirst("(/|\\\\)([^/&^\\\\]*)@([^/&^\\\\]*)", "$1locks@system$1$3$1$2");

    return PathFactory.newPath("/", systemUri);
  }
Example #4
0
 public static Path newLock(final Path path) {
   Path lockPath = newLockPath(path);
   return PathFactory.newPath(
       path.getFileName() + LOCK_FILE_EXTENSION, lockPath.toURI() + LOCK_FILE_EXTENSION);
 }
Example #5
0
 @Override
 public int compareTo(final Path another) {
   return this.uri.compareTo(another.toURI());
 }