예제 #1
0
 /**
  * Resolve and transfer values from ScmArtifact to R4EFileVersion
  *
  * @param aTargetFileVer R4EFileVersion
  * @param aSourceFileVer R4EFileVersion
  */
 public static void copyFileVersionData(
     R4EFileVersion aTargetFileVer, R4EFileVersion aSourceFileVer) {
   if ((null != aTargetFileVer) && (null != aSourceFileVer)) {
     aTargetFileVer.setName(aSourceFileVer.getName());
     aTargetFileVer.setVersionID(aSourceFileVer.getVersionID());
     aTargetFileVer.setRepositoryPath(aSourceFileVer.getRepositoryPath());
     aTargetFileVer.setLocalVersionID(aSourceFileVer.getLocalVersionID());
     aTargetFileVer.setPlatformURI(aSourceFileVer.getPlatformURI());
     aTargetFileVer.setResource(aSourceFileVer.getResource());
   }
 }
예제 #2
0
  /**
   * Method copyWorkspaceFileToLocalRepository.
   *
   * @param aLocalRepository IRFSRegistry
   * @param aFile IFile
   * @return IFile
   * @throws CoreException
   * @throws ReviewsFileStorageException
   */
  public static R4EFileVersion copyWorkspaceFileToLocalRepository(
      IRFSRegistry aLocalRepository, IFile aFile)
      throws CoreException, ReviewsFileStorageException {
    R4EFileVersion tmpFileVersion = null;
    if ((null != aLocalRepository) && (null != aFile)) {
      // Create and Set value in temporary File version
      tmpFileVersion = RModelFactory.eINSTANCE.createR4EFileVersion();
      if ((null != tmpFileVersion)) {
        updateFileVersion(tmpFileVersion, aFile);

        // Push a local copy to local review repository, and obtain the local id
        tmpFileVersion.setLocalVersionID(aLocalRepository.registerReviewBlob(aFile.getContents()));
        tmpFileVersion.setVersionID(NO_SOURCE_CONTROL_ID_TEXT);
      }
    }
    return tmpFileVersion;
  }
예제 #3
0
  /**
   * Method copyRemoteFileToLocalRepository.
   *
   * @param aLocalRepository IRFSRegistry
   * @param aArtifact ScmArtifact
   * @return IFile
   * @throws CoreException
   * @throws ReviewsFileStorageException
   */
  public static R4EFileVersion copyRemoteFileToLocalRepository(
      IRFSRegistry aLocalRepository, ScmArtifact aArtifact)
      throws ReviewsFileStorageException, CoreException {

    if ((null == aArtifact)
        || (null == aArtifact.getPath())
        || aArtifact.getPath().equals(INVALID_PATH)) {
      return null; // File not found in remote repository
    }
    final IFileRevision fileRev = aArtifact.getFileRevision(null);
    if (null == fileRev) {
      return null;
    }

    // Pull file from the version control system
    InputStream iStream = null;
    final IStorage fileStore = fileRev.getStorage(null);
    if (null == fileStore) {
      return null;
    }
    try {
      iStream = fileStore.getContents();
    } catch (CoreException e) {
      R4EUIPlugin.Ftracer.traceInfo("Exception: " + e.toString() + " (" + e.getMessage() + ")");
      return null;
    }

    // Create and Set value in temporary File version
    final R4EFileVersion tmpFileVersion = RModelFactory.eINSTANCE.createR4EFileVersion();
    if ((null != tmpFileVersion) && (null != aLocalRepository)) {
      updateFileVersion(tmpFileVersion, aArtifact);

      // Push a local copy to local review repository, and obtain the local id
      tmpFileVersion.setLocalVersionID(aLocalRepository.registerReviewBlob(iStream));
      if (null != iStream) {
        try {
          iStream.close();
        } catch (IOException e) {
          R4EUIPlugin.Ftracer.traceWarning("Exception while closing stream, " + e.toString());
        }
      }
    }
    return tmpFileVersion;
  }
예제 #4
0
  /**
   * Method copyRemoteFileToLocalRepository.
   *
   * @param aLock ReentrantLock
   * @param aLocalRepository IRFSRegistry
   * @param aArtifact ScmArtifact
   * @param aMainMonitor IProgressMonitor
   * @param aSubMonitor IProgressMonitor
   * @return IFile
   * @throws CoreException
   * @throws ReviewsFileStorageException
   * @throws MainJobCancelledException
   * @throws SubJobCancelledException
   */
  public static R4EFileVersion copyRemoteFileToLocalRepository(
      ReentrantLock aLock,
      IRFSRegistry aLocalRepository,
      ScmArtifact aArtifact,
      IProgressMonitor aMainMonitor)
      throws ReviewsFileStorageException, CoreException {
    ReentrantLock lock = aLock;
    if (null == lock) {
      lock = new ReentrantLock();
    }

    // Check if Main Job or Sub Job was cancelled before fetching
    if (aMainMonitor.isCanceled()) {
      throw new CoreException(
          new Status(
              IStatus.CANCEL,
              R4EUIPlugin.PLUGIN_ID,
              IStatus.CANCEL,
              R4EUIConstants.CANCEL_EXCEPTION_MSG,
              null));
    }

    if ((null == aArtifact)
        || (null == aArtifact.getPath())
        || aArtifact.getPath().equals(INVALID_PATH)) {
      return null; // File not found in remote repository
    }

    // Tracing benchmarks
    Date fetchStart = null;
    if (Tracer.isInfo()) {
      fetchStart = new Date();
    }

    final IFileRevision fileRev = aArtifact.getFileRevision(null);
    if (null == fileRev) {
      return null;
    }

    // Pull file from the version control system
    InputStream iStream = null;
    final IStorage fileStore = fileRev.getStorage(null);
    if (null == fileStore) {
      return null;
    }
    try {
      iStream = fileStore.getContents();
    } catch (CoreException e) {
      R4EUIPlugin.Ftracer.traceInfo("Exception: " + e.toString() + " (" + e.getMessage() + ")");
      return null;
    }

    // Create and Set value in temporary File version
    final R4EFileVersion tmpFileVersion = RModelFactory.eINSTANCE.createR4EFileVersion();
    if ((null != tmpFileVersion) && (null != aLocalRepository)) {
      updateFileVersion(tmpFileVersion, aArtifact);

      // Check if Main Job or Sub Job was cancelled before pushing a local copy
      if (aMainMonitor.isCanceled()) {
        throw new CoreException(
            new Status(
                IStatus.CANCEL,
                R4EUIPlugin.PLUGIN_ID,
                IStatus.CANCEL,
                R4EUIConstants.CANCEL_EXCEPTION_MSG,
                null));
      }

      // Tracing benchmarks
      Date blobRegStart = null;
      if (fetchStart != null) {
        blobRegStart = new Date();
      }

      // Push a local copy to local review repository, and obtain the local id
      lock.lock();
      try {
        tmpFileVersion.setLocalVersionID(aLocalRepository.registerReviewBlob(iStream));
      } finally {
        lock.unlock();

        if (fetchStart != null) {
          long downloadTime = blobRegStart.getTime() - fetchStart.getTime();
          long uploadTime = (new Date()).getTime() - blobRegStart.getTime();
          R4EUIPlugin.Ftracer.traceInfo(
              "Registered blob for "
                  + fileRev.getName()
                  + " "
                  + //$NON-NLS-1$//$NON-NLS-2$
                  aArtifact.getId()
                  + ", fetch (ms): "
                  + downloadTime
                  + ", push (ms) "
                  + uploadTime); //$NON-NLS-1$ //$NON-NLS-2$
        }

        if (null != iStream) {
          try {
            iStream.close();
          } catch (IOException e) {
            R4EUIPlugin.Ftracer.traceWarning("Exception while closing stream, " + e.toString());
          }
        }
      }
    }
    return tmpFileVersion;
  }