Example #1
0
 /**
  * Returns the informational message describing the cause of this exception.
  *
  * @return an informational message
  */
 public String getMessage() {
   SVNErrorMessage error = getErrorMessage();
   if (error != null) {
     return error.getFullMessage();
   }
   return super.getMessage();
 }
Example #2
0
 /**
  * Creates an exception given an error message and the cause exception.
  *
  * @param errorMessage an error message
  * @param cause the real cause of the error
  */
 public SVNException(SVNErrorMessage errorMessage, Throwable cause) {
   super(cause);
   if (cause instanceof SVNException) {
     SVNErrorMessage childMessages = ((SVNException) cause).getErrorMessage();
     SVNErrorMessage parent = errorMessage;
     while (parent.hasChildErrorMessage()) {
       parent = parent.getChildErrorMessage();
     }
     if (parent != childMessages) {
       parent.setChildErrorMessage(childMessages);
     }
   }
   myErrorMessage = errorMessage;
 }
 private boolean for17move(
     final SvnVcs vcs, final File src, final File dst, boolean undo, SVNStatus srcStatus)
     throws SVNException {
   if (srcStatus != null && srcStatus.getCopyFromURL() == null) {
     undo = false;
   }
   if (undo) {
     myUndoingMove = true;
     createRevertAction(vcs, dst, true).execute();
     copyUnversionedMembersOfDirectory(src, dst);
     if (srcStatus == null || SvnVcs.svnStatusIsUnversioned(srcStatus)) {
       FileUtil.delete(src);
     } else {
       createRevertAction(vcs, src, true).execute();
     }
     restoreFromUndoStorage(dst);
   } else {
     if (doUsualMove(vcs, src)) return true;
     // check destination directory
     final SVNStatus dstParentStatus = getFileStatus(vcs, dst.getParentFile());
     if (dstParentStatus == null || SvnVcs.svnStatusIsUnversioned(dstParentStatus)) {
       try {
         copyFileOrDir(src, dst);
       } catch (IOException e) {
         throw new SVNException(SVNErrorMessage.create(SVNErrorCode.IO_ERROR, e), e);
       }
       createDeleteAction(vcs, src, true).execute();
       return false;
     }
     moveFileWithSvn(vcs, src, dst);
   }
   return false;
 }
Example #4
0
  @Override
  protected SvnStatus run(SVNWCContext context) throws SVNException {
    File directoryPath;
    String targetName;

    SVNNodeKind kind = context.readKind(getFirstTarget(), false);
    SVNDepth depth = getOperation().getDepth();
    if (kind == SVNNodeKind.DIR) {
      directoryPath = getFirstTarget();
      targetName = "";
    } else {
      directoryPath = SVNFileUtil.getParentFile(getFirstTarget());
      targetName = SVNFileUtil.getFileName(getFirstTarget());
      if (kind == SVNNodeKind.FILE) {
        if (depth == SVNDepth.EMPTY) {
          depth = SVNDepth.FILES;
        }
      } else {
        boolean notAWc = false;
        try {
          kind = context.readKind(directoryPath, false);
          notAWc = kind != SVNNodeKind.DIR;
        } catch (SVNException e) {
          notAWc = true;
        }
        if (notAWc) {
          SVNErrorMessage err =
              SVNErrorMessage.create(
                  SVNErrorCode.WC_PATH_NOT_FOUND,
                  "The node ''{0}'' was not found",
                  getFirstTarget());
          SVNErrorManager.error(err, SVNLogType.WC);
        }
      }
    }

    String[] globalIgnores = context.getOptions().getIgnorePatterns();

    if (getOperation().isRemote()) {
      SVNURL url = context.getUrlFromPath(directoryPath);
      if (url == null) {
        SVNErrorMessage error =
            SVNErrorMessage.create(
                SVNErrorCode.ENTRY_MISSING_URL, "Entry ''{0}'' has no URL", directoryPath);
        SVNErrorManager.error(error, SVNLogType.WC);
      }
      SVNRepository repository = getRepositoryAccess().createRepository(url, null, true);
      long rev;
      if (getOperation().getRevision() == SVNRevision.HEAD) {
        rev = -1;
      } else {
        rev =
            context.getRevisionNumber(
                getOperation().getRevision(), null, repository, getFirstTarget());
      }
      kind = repository.checkPath("", rev);
      checkCancelled();
      SVNStatusEditor17 editor = null;
      SVNReporter17 reporter = null;
      if (kind == SVNNodeKind.NONE) {
        boolean added = context.isNodeAdded(directoryPath);
        if (added) {
          boolean replaced = context.isNodeReplaced(directoryPath);
          if (replaced) {
            added = false;
          }
        }
        setTargetDeletedInRepository(!added);
        editor =
            new SVNStatusEditor17(
                getFirstTarget(),
                context,
                getOperation().getOptions(),
                getOperation().isReportIgnored(),
                getOperation().isReportAll(),
                depth,
                this);
        editor.setFileListHook(getOperation().getFileListHook());
        checkCancelled();
        editor.closeEdit();
      } else {
        editor =
            new SVNRemoteStatusEditor17(
                directoryPath,
                targetName,
                context,
                getOperation().getOptions(),
                getOperation().isReportIgnored(),
                getOperation().isReportAll(),
                depth,
                this);
        editor.setFileListHook(getOperation().getFileListHook());

        SVNRepository locksRepos = getRepositoryAccess().createRepository(url, null, false);
        checkCancelled();
        boolean serverSupportsDepth = repository.hasCapability(SVNCapability.DEPTH);
        reporter =
            new SVNReporter17(
                getFirstTarget(),
                context,
                false,
                !serverSupportsDepth,
                depth,
                false,
                true,
                true,
                false,
                null);
        SVNStatusReporter17 statusReporter = new SVNStatusReporter17(locksRepos, reporter, editor);
        String target = "".equals(targetName) ? null : targetName;
        SVNDepth statusDepth = getOperation().isDepthAsSticky() ? depth : SVNDepth.UNKNOWN;
        repository.status(
            rev,
            target,
            statusDepth,
            statusReporter,
            SVNCancellableEditor.newInstance((ISVNEditor) editor, this, null));
      }
      getOperation().setRemoteRevision(editor.getTargetRevision());

      long reportedFiles = reporter != null ? reporter.getReportedFilesCount() : 0;
      long totalFiles = reporter != null ? reporter.getTotalFilesCount() : 0;
      SVNEvent event =
          SVNEventFactory.createSVNEvent(
              getFirstTarget(),
              SVNNodeKind.NONE,
              null,
              editor.getTargetRevision(),
              SVNEventAction.STATUS_COMPLETED,
              null,
              null,
              null,
              reportedFiles,
              totalFiles);

      handleEvent(event, ISVNEventHandler.UNKNOWN);
    } else {
      SVNStatusEditor17 editor =
          new SVNStatusEditor17(
              directoryPath,
              context,
              context.getOptions(),
              getOperation().isReportIgnored(),
              getOperation().isReportAll(),
              depth,
              this);
      editor.setFileListHook(getOperation().getFileListHook());
      try {
        editor.walkStatus(
            getFirstTarget(),
            depth,
            getOperation().isReportAll(),
            getOperation().isReportIgnored(),
            false,
            globalIgnores != null ? Arrays.asList(globalIgnores) : null);
      } catch (SVNException e) {
        if (e.getErrorMessage().getErrorCode() == SVNErrorCode.WC_MISSING) {
          SVNErrorMessage err =
              SVNErrorMessage.create(
                  SVNErrorCode.WC_NOT_WORKING_COPY,
                  "''{0}'' is not a working copy",
                  getFirstTarget());
          SVNErrorManager.error(err, SVNLogType.WC);
        }
        throw e;
      }
    }

    if (depth.isRecursive() && getOperation().isReportExternals()) {
      Map<File, File> externals = context.getDb().getExternalsDefinedBelow(getFirstTarget());
      doExternalStatus(externals);
    }

    return getOperation().first();
  }
Example #5
0
 /**
  * Creates an exception given an error message.
  *
  * @param errorMessage an error message
  */
 public SVNException(SVNErrorMessage errorMessage) {
   this(errorMessage, errorMessage.getCause());
 }
Example #6
0
  private void doList(
      SVNRepository repos,
      long rev,
      final ISVNDirEntryHandler handler,
      boolean fetchLocks,
      SVNDepth depth,
      int entryFields,
      SVNURL externalParentUrl,
      String externalTarget)
      throws SVNException {
    boolean includeExternals = !getOperation().isIgnoreExternals();
    Map<SVNURL, SVNPropertyValue> externals =
        includeExternals ? new HashMap<SVNURL, SVNPropertyValue>() : null;
    SVNURL url = repos.getLocation();
    SVNURL reposRoot = repos.getRepositoryRoot(false);
    SVNDirEntry entry = null;
    SVNException error = null;
    try {
      entry = repos.info("", rev);
    } catch (SVNException svne) {
      if (svne.getErrorMessage().getErrorCode() == SVNErrorCode.RA_NOT_IMPLEMENTED) {
        error = svne;
      } else {
        throw svne;
      }
    }
    if (error != null) {
      SVNNodeKind kind = repos.checkPath("", rev);
      if (kind != SVNNodeKind.NONE) {
        if (!url.equals(reposRoot)) {
          String name = SVNPathUtil.tail(repos.getLocation().getPath());
          repos.setLocation(repos.getLocation().removePathTail(), false);
          Collection<SVNDirEntry> dirEntries =
              repos.getDir("", rev, null, entryFields, (Collection) null);
          repos.setLocation(url, false);
          for (Iterator<SVNDirEntry> ents = dirEntries.iterator(); ents.hasNext(); ) {
            SVNDirEntry dirEntry = (SVNDirEntry) ents.next();
            if (name.equals(dirEntry.getName())) {
              entry = dirEntry;
              break;
            }
          }
          if (entry != null) {
            entry.setRelativePath(kind == SVNNodeKind.FILE ? name : "");
          }
        } else {
          SVNProperties props = new SVNProperties();
          repos.getDir("", rev, props, entryFields, (Collection<SVNDirEntry>) null);
          SVNProperties revProps = repos.getRevisionProperties(rev, null);
          String author = revProps.getStringValue(SVNRevisionProperty.AUTHOR);
          String dateStr = revProps.getStringValue(SVNRevisionProperty.DATE);
          Date datestamp = null;
          if (dateStr != null) {
            datestamp = SVNDate.parseDateString(dateStr);
          }
          entry =
              new SVNDirEntry(
                  url, reposRoot, "", kind, 0, !props.isEmpty(), rev, datestamp, author);
          entry.setRelativePath("");
        }
      }
    } else if (entry != null) {
      if (entry.getKind() == SVNNodeKind.DIR) {
        entry.setName("");
      }
      entry.setRelativePath(entry.getKind() == SVNNodeKind.DIR ? "" : entry.getName());
    }
    if (entry == null) {
      SVNErrorMessage err =
          SVNErrorMessage.create(
              SVNErrorCode.FS_NOT_FOUND, "URL ''{0}'' non-existent in that revision", url);
      SVNErrorManager.error(err, SVNLogType.WC);
    }
    final Map locksMap = new SVNHashMap();
    if (fetchLocks) {
      SVNLock[] locks = new SVNLock[0];
      try {
        locks = repos.getLocks("");
      } catch (SVNException e) {
        if (!(e.getErrorMessage() != null
            && e.getErrorMessage().getErrorCode() == SVNErrorCode.RA_NOT_IMPLEMENTED)) {
          throw e;
        }
      }
      if (locks != null && locks.length > 0) {
        SVNURL root = repos.getRepositoryRoot(true);
        for (int i = 0; i < locks.length; i++) {
          String repositoryPath = locks[i].getPath();
          locksMap.put(root.appendPath(repositoryPath, false), locks[i]);
        }
      }
    }
    ISVNDirEntryHandler nestedHandler =
        new ISVNDirEntryHandler() {

          public void handleDirEntry(SVNDirEntry dirEntry) throws SVNException {
            dirEntry.setLock((SVNLock) locksMap.get(dirEntry.getURL()));
            handler.handleDirEntry(dirEntry);
          }
        };
    entry.setExternalParentUrl(externalParentUrl);
    entry.setExternalTarget(externalTarget);
    nestedHandler.handleDirEntry(entry);
    if (entry.getKind() == SVNNodeKind.DIR
        && (depth == SVNDepth.FILES
            || depth == SVNDepth.IMMEDIATES
            || depth == SVNDepth.INFINITY)) {
      list(
          repos,
          "",
          rev,
          depth,
          entryFields,
          externals,
          externalParentUrl,
          externalTarget,
          nestedHandler);
    }

    if (includeExternals && externals != null && externals.size() > 0) {
      listExternals(repos, externals, depth, entryFields, fetchLocks, handler);
    }
  }
 private static void wrapAndThrow(VcsException e) throws SVNException {
   // TODO: probably we should wrap into new exception only if e.getCause is not SVNException
   throw new SVNException(SVNErrorMessage.create(SVNErrorCode.FS_GENERAL, e), e);
 }