diff options
2 files changed, 117 insertions, 25 deletions
diff --git a/org.eclipse.mylyn.subclipse.core/src/org/eclipse/mylyn/internal/subclipse/core/SubclipseArtifact.java b/org.eclipse.mylyn.subclipse.core/src/org/eclipse/mylyn/internal/subclipse/core/SubclipseArtifact.java index 73ed917..2388b8b 100644 --- a/org.eclipse.mylyn.subclipse.core/src/org/eclipse/mylyn/internal/subclipse/core/SubclipseArtifact.java +++ b/org.eclipse.mylyn.subclipse.core/src/org/eclipse/mylyn/internal/subclipse/core/SubclipseArtifact.java @@ -6,7 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Ericsson AB - Initial API and Implementation + * Alvaro Sanchez-Leon (Ericsson AB) - Initial API and Implementation + * Sebastien Dubois (Ericsson AB) - Implemented getContributors method *******************************************************************************/ package org.eclipse.mylyn.internal.subclipse.core; @@ -26,7 +27,10 @@ import org.eclipse.team.core.history.IFileRevision; import org.eclipse.team.core.history.provider.FileRevision; import org.tigris.subversion.subclipse.core.ISVNRemoteResource; import org.tigris.subversion.subclipse.core.ISVNRepositoryLocation; +import org.tigris.subversion.subclipse.core.SVNException; +import org.tigris.subversion.subclipse.core.commands.GetLogsCommand; import org.tigris.subversion.subclipse.core.commands.GetRemoteResourceCommand; +import org.tigris.subversion.subclipse.core.history.ILogEntry; import org.tigris.subversion.subclipse.core.resources.RemoteFile; import org.tigris.subversion.svnclientadapter.SVNRevision; import org.tigris.subversion.svnclientadapter.SVNUrl; @@ -39,7 +43,7 @@ public class SubclipseArtifact extends ScmArtifact { private final SubclipseRepository repository; - private static ILog logger = SubclipseCorePlugin.getDefault().getLog(); + private static final ILog logger = SubclipseCorePlugin.getDefault().getLog(); private ISVNRemoteResource svnRemResource = null; @@ -68,10 +72,18 @@ public class SubclipseArtifact extends ScmArtifact { return svnRemResource.getStorage(monitor); } - Long revisionNum = Long.decode(getId()); + final Long revisionNum = Long.decode(getId()); return resolveStorage(monitor, revisionNum, repository.getLocation(), getPath()); } + @Override + public String getContentIdentifier() { + if (null != svnRemResource) { + return svnRemResource.getLastChangedRevision().toString(); + } + return null; + } + public String getName() { return path.lastSegment(); } @@ -85,7 +97,62 @@ public class SubclipseArtifact extends ScmArtifact { @Override public IFileRevision[] getContributors(IProgressMonitor monitor) { - throw new UnsupportedOperationException(); + //NOTE: Here we cannot use the ScmResourceArtifact to retrieve the contributors because Subclipse does not + // implement IFileHistory and IFileRevision interfaces. So we will assume that the only contributor is the + // previous version of the artifact. + if (null == svnRemResource) { + return null; + } + + //First we have to get the previous revision using the previous ILogEntry. + SVNRevision firstRevision = new SVNRevision.Number(1L); + SVNRevision.Number previousRevision = new SVNRevision.Number(Long.parseLong(getId())); + GetLogsCommand logCmd = new GetLogsCommand(svnRemResource, null, previousRevision, firstRevision, false, 2L, + null, true); + try { + logCmd.run(monitor); + } catch (SVNException e) { + return null; + } + + final ILogEntry[] entries = logCmd.getLogEntries(); + if (entries.length < 2) { + //No base version found + return null; + } + + //Pick the previous revision of the artifact and return it as an IFileRevision + final ISVNRemoteResource remoteResource = entries[entries.length - 1].getRemoteResource(); + final IFileRevision[] contributors = new IFileRevision[1]; + contributors[0] = new FileRevision() { + public IFileRevision withAllProperties(IProgressMonitor monitor) throws CoreException { + return this; + } + + public boolean isPropertyMissing() { + return false; + } + + public IStorage getStorage(IProgressMonitor monitor) throws CoreException { + if (null != remoteResource) { + return remoteResource.getStorage(monitor); + } + return null; + } + + @Override + public String getContentIdentifier() { + if (null != remoteResource) { + return remoteResource.getLastChangedRevision().toString(); + } + return null; + } + + public String getName() { + return remoteResource.getName(); + } + }; + return contributors; } @Override @@ -127,29 +194,28 @@ public class SubclipseArtifact extends ScmArtifact { private ISVNRemoteResource resolveRemoteResource(IProgressMonitor monitor, ISVNRepositoryLocation location, SVNRevision revision, SVNUrl url) throws CoreException { - GetRemoteResourceCommand command = new GetRemoteResourceCommand(location, url, revision); + final GetRemoteResourceCommand command = new GetRemoteResourceCommand(location, url, revision); command.run(monitor); - ISVNRemoteResource resource = command.getRemoteResource(); + final ISVNRemoteResource resource = command.getRemoteResource(); if (resource == null) { - String msg = "Unable to resolve remote resource for: " + url.toString(); //$NON-NLS-1$ - Status status = new Status(IStatus.ERROR, SubclipseCorePlugin.PLUGIN_ID, msg); + final String msg = "Unable to resolve remote resource for: " + url.toString(); //$NON-NLS-1$ + final Status status = new Status(IStatus.ERROR, SubclipseCorePlugin.PLUGIN_ID, msg); throw new CoreException(status); } return resource; } - private IStorage resolveStorage(IProgressMonitor monitor, Long revNo, ISVNRepositoryLocation location, String path) - throws CoreException { + private IStorage resolveStorage(IProgressMonitor monitor, Long revNo, ISVNRepositoryLocation location, String path) { try { - SVNRevision revision = new SVNRevision.Number(revNo); + final SVNRevision revision = new SVNRevision.Number(revNo.longValue()); - SVNUrl url = getRepositoryURL(); + final SVNUrl url = getRepositoryURL(); - ISVNRemoteResource resource = resolveRemoteResource(monitor, location, revision, url); + final ISVNRemoteResource resource = resolveRemoteResource(monitor, location, revision, url); // check if the resource is a file if (resource.isFolder()) { diff --git a/org.eclipse.mylyn.subclipse.core/src/org/eclipse/mylyn/internal/subclipse/core/SubclipseConnector.java b/org.eclipse.mylyn.subclipse.core/src/org/eclipse/mylyn/internal/subclipse/core/SubclipseConnector.java index 36a5e31..c88bceb 100644 --- a/org.eclipse.mylyn.subclipse.core/src/org/eclipse/mylyn/internal/subclipse/core/SubclipseConnector.java +++ b/org.eclipse.mylyn.subclipse.core/src/org/eclipse/mylyn/internal/subclipse/core/SubclipseConnector.java @@ -6,7 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Ericsson AB - Initial API and Implementation + * Alvaro Sanchez-Leon (Ericsson AB) - Initial API and Implementation + * Sebastien Dubois (Ericsson AB) - Improved getArtifact method to resolve remote resources versions *******************************************************************************/ package org.eclipse.mylyn.internal.subclipse.core; @@ -33,6 +34,7 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.ILog; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Status; import org.eclipse.mylyn.versions.core.Change; @@ -49,6 +51,8 @@ import org.tigris.subversion.subclipse.core.ISVNRemoteResource; import org.tigris.subversion.subclipse.core.ISVNRepositoryLocation; import org.tigris.subversion.subclipse.core.SVNException; import org.tigris.subversion.subclipse.core.SVNProviderPlugin; +import org.tigris.subversion.subclipse.core.commands.GetLogsCommand; +import org.tigris.subversion.subclipse.core.history.ILogEntry; import org.tigris.subversion.subclipse.core.resources.SVNWorkspaceRoot; import org.tigris.subversion.svnclientadapter.ISVNClientAdapter; import org.tigris.subversion.svnclientadapter.ISVNLogMessage; @@ -77,34 +81,56 @@ public class SubclipseConnector extends ScmConnector { @Override public ScmArtifact getArtifact(IResource resource, String revision) { - ISVNRemoteResource svnResource = null; - + ISVNRemoteResource localResource = null; SubclipseRepository repo = null; + ISVNRemoteResource resolvedResource = null; + try { - svnResource = SVNWorkspaceRoot.getBaseResourceFor(resource); - if (svnResource == null) { - //not in version control + //First get local resource handle + localResource = SVNWorkspaceRoot.getBaseResourceFor(resource); + + if (null == revision) { + //We are looking for the local resource in the workspace + resolvedResource = localResource; + } else { + //We are looking for a previous version. Get it from the SVN remote repo using SVN logs. + SVNRevision svnRevision = new SVNRevision.Number(Long.parseLong(revision)); + GetLogsCommand logCmd = new GetLogsCommand(localResource, null, svnRevision, svnRevision, false, 1L, + null, true); + try { + logCmd.run(new NullProgressMonitor()); + } catch (SVNException e) { + // TODO: implement a plug-in logger besides the one in the work space + return null; + } + + final ILogEntry[] entries = logCmd.getLogEntries(); + if (entries.length < 1) { + //No version found + return null; + } + resolvedResource = entries[entries.length - 1].getRemoteResource(); + } + if (null == resolvedResource) { + //No valid resource version found return null; } repo = (SubclipseRepository) getRepository(resource, null); } catch (SVNException e) { // TODO: implement a plug-in logger besides the one in the work space - // e.printStackTrace(); return null; } catch (CoreException e) { // TODO implement a plug-in logger besides the one in the work space - // e.printStackTrace(); return null; } - SVNRevision SubCRevision = svnResource.getRevision(); - String id = String.valueOf(SubCRevision.getKind()); - SubclipseArtifact artifact = new SubclipseArtifact(id, svnResource.getRepositoryRelativePath(), repo); + String id = Long.toString(resolvedResource.getLastChangedRevision().getNumber()); + SubclipseArtifact artifact = new SubclipseArtifact(id, resolvedResource.getRepositoryRelativePath(), repo); //Assign the resource information artifact.setProjectName(resource.getProject().getName()); artifact.setProjectRelativePath(resource.getProjectRelativePath().toPortableString()); - artifact.setRemoteResource(svnResource); + artifact.setRemoteResource(resolvedResource); return artifact; } |