/** * Method useWorkspaceResource. * * @param aVersion R4EFileVersion * @return boolean */ public static boolean useWorkspaceResource(R4EFileVersion aVersion) { // Get handle to local storage repository try { if (null != R4EUIModelController.getActiveReview()) { final IRFSRegistry localRepository = RFSRegistryFactory.getRegistry(R4EUIModelController.getActiveReview().getReview()); if (null != localRepository) { // If resource is available in the workspace, use it. Otherwise use the local repo // version if ((null != aVersion) && (null != aVersion.getResource())) { final String workspaceFileId = localRepository.blobIdFor(((IFile) aVersion.getResource()).getContents()); final String repoFileId = aVersion.getLocalVersionID(); if ((null != workspaceFileId) && workspaceFileId.equals((repoFileId))) { return true; } } } } } catch (ReviewsFileStorageException e) { R4EUIPlugin.Ftracer.traceWarning("Exception: " + e.toString() + " (" + e.getMessage() + ")"); } catch (CoreException e) { R4EUIPlugin.Ftracer.traceWarning("Exception: " + e.toString() + " (" + e.getMessage() + ")"); } return false; }
/** * 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; }
/** * 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; }