throw new InvocationTargetException(e);
}
}
}
ISVNClientAdapter svnClient = svnResource.getRepository().getSVNClient();
Set<IResource> includedResources = new HashSet<IResource>();
if ( null != resources && resources.length > 0) {
includedResources.addAll(Arrays.asList(resources));
}
//将includedResources按照project进行分组
Map<IProject, List<IResource>> projectToResources = new HashMap<IProject, List<IResource>>();
for( IResource resourceTmp : includedResources ){
IProject project = resourceTmp.getProject();
List<IResource> resources = projectToResources.get(project);
if (resources == null) {
resources = new ArrayList<IResource>();
projectToResources.put(project, resources);
}
resources.add(resourceTmp);
}
//确保所有的project都在同一个Repository Root里(否则,无法正常生成ReviewBoard能够识别的diff)
if( !RbSVNUrlUtils.isProjectWithSameSVNRepository( projectToResources.keySet() ) ){
throw new Exception( RbSubclipseMessages.getString("ERROR_PROJECT_NOTSAME_REPOSITORY") );
}
//再逐个生成resources的diff
SVNRevision toRevision = SVNRevision.WORKING;
monitor.worked(200);
for ( Iterator<Entry<IProject, List<IResource>>> iEntry = projectToResources.entrySet().iterator(); iEntry.hasNext(); ) {
monitor.worked(100);
Entry<IProject, List<IResource>> entry = (Entry<IProject, List<IResource>>) iEntry.next();
IProject project = (IProject) entry.getKey();
List<IResource> resources = (List<IResource>) entry.getValue();
String repositoryRootUrl = RbSVNUrlUtils.getRepositoryRootUrlForResource( project );
String projectSVNUrl = RbSVNUrlUtils.getSVNUrlForProject( project );
if( !repositoryRootUrl.endsWith("/") ){
repositoryRootUrl += "/";
}
if( !projectSVNUrl.endsWith("/") ){
projectSVNUrl += "/";
}
String relativeRepositoryRootUrl = projectSVNUrl.replaceFirst( repositoryRootUrl, EMPTY_STRING );
for( IResource resourceTmp : resources ){
if( ! (resourceTmp instanceof IFile) ){
continue;
}
File tempDiffFile = IOUtils.generateTmpFile( FOLDER_TMP_DIFF, DIFF_SUFFIX);
File resourceFileTmp = ((IFile)resourceTmp).getLocation().toFile();
SVNRevision compareVersionReal = compareVersion;
//修复版本号
if( compareVersionReal instanceof SVNRevision.Number ){
compareVersionReal = RbSVNUrlUtils.reviseSVNRevisionAdaptByMaxOrMin( resourceTmp, (SVNRevision.Number)compareVersion, false, null );
if( null == compareVersionReal ){
compareVersionReal = compareVersion;
}
}
svnClient.diff(resourceFileTmp, compareVersionReal, resourceFileTmp, toRevision,
tempDiffFile, false, false, false, false);
if( null == tempDiffFile || !tempDiffFile.exists() ){
continue;
}