/** * 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 getParticipant. * * @param aId - String * @return R4EParticipant */ protected R4EParticipant getParticipant(String aId) { // First check if the participant already exist in the participant list for (R4EParticipant tmpPart : fParticipants) { if (aId.equalsIgnoreCase(tmpPart.getId())) { return null; } } final R4EParticipant participant = RModelFactory.eINSTANCE.createR4EParticipant(); if (R4EUIModelController.isUserQueryAvailable()) { final IQueryUser query = new QueryUserFactory().getInstance(); try { final List<IUserInfo> users = query.searchByUserId(aId); // Fill info with first user returned for (IUserInfo user : users) { if (user.getUserId().toLowerCase().equals(aId)) { participant.setId(user.getUserId().toLowerCase()); participant.setEmail(user.getEmail()); fParticipantsDetailsValues.add(UIUtils.buildUserDetailsString(user)); return participant; } } } catch (NamingException e) { R4EUIPlugin.Ftracer.traceError("Exception: " + e.toString() + " (" + e.getMessage() + ")"); R4EUIPlugin.getDefault().logError("Exception: " + e.toString(), e); } catch (IOException e) { R4EUIPlugin.getDefault().logWarning("Exception: " + e.toString(), e); } } participant.setId(aId); fParticipantsDetailsValues.add(""); return participant; }
/** * 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 updateFileVersion * * @param aTargetFileVer R4EFileVersion * @param aScmArt ScmArtifact * @throws CoreException */ public static void updateFileVersion(R4EFileVersion aTargetFileVer, ScmArtifact aScmArt) throws CoreException { if ((null != aTargetFileVer) && (null != aScmArt)) { aTargetFileVer.setName(aScmArt.getFileRevision(null).getName()); aTargetFileVer.setVersionID(aScmArt.getId()); final IFileRevision fileRev = aScmArt.getFileRevision(null); if (null != fileRev) { final IStorage fileStore = fileRev.getStorage(null); if (null != fileStore) { final IPath filePath = fileStore.getFullPath(); if (null != filePath) { aTargetFileVer.setRepositoryPath(filePath.toPortableString()); } } } final String fileRelPath = aScmArt.getProjectRelativePath(); if (null == fileRelPath) { R4EUIPlugin.Ftracer.traceDebug( "Invalid relative file path in scmArtifact with path: " + aScmArt.getPath()); } final IProject project = ResourceUtils.getProject(aScmArt.getProjectName()); final IResource resource = ResourceUtils.findResource(project, fileRelPath); aTargetFileVer.setPlatformURI(ResourceUtils.toPlatformURIStr(resource)); aTargetFileVer.setResource(resource); final String projPlatformURI = ResourceUtils.toPlatformURIStr(project); if (null == projPlatformURI) { R4EUIPlugin.Ftracer.traceDebug( "Unable to resolve the project: " + aScmArt.getProjectName() + " platform's URI, in scmArtifact with path: " + aScmArt.getPath()); } } }
/** * 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; }