use of org.eclipse.core.resources.mapping.ResourceMapping in project egit by eclipse.
the class GitResourceVariantTreeTest method collectResources.
private static Set<IResource> collectResources(ResourceMapping[] mappings) throws CoreException {
final Set<IResource> resources = new HashSet<IResource>();
ResourceMappingContext context = ResourceMappingContext.LOCAL_CONTEXT;
for (ResourceMapping mapping : mappings) {
ResourceTraversal[] traversals = mapping.getTraversals(context, new NullProgressMonitor());
for (ResourceTraversal traversal : traversals) {
resources.addAll(Arrays.asList(traversal.getResources()));
}
}
return resources;
}
use of org.eclipse.core.resources.mapping.ResourceMapping in project egit by eclipse.
the class GitResourceVariantTreeTest method shouldNotReturnNullOnSameResouceVariant.
@Test
public void shouldNotReturnNullOnSameResouceVariant() throws Exception {
String modifiedFileName = "changingFile." + SampleModelProvider.SAMPLE_FILE_EXTENSION;
String unchangedFileName = "notChangingFile." + SampleModelProvider.SAMPLE_FILE_EXTENSION;
String removedFileName = "toBeRemovedFile." + SampleModelProvider.SAMPLE_FILE_EXTENSION;
File modifiedFile = testRepo.createFile(iProject, modifiedFileName);
File unchangedFile = testRepo.createFile(iProject, unchangedFileName);
File removedFile = testRepo.createFile(iProject, removedFileName);
testRepo.appendFileContent(modifiedFile, "My content is changing");
testRepo.appendFileContent(unchangedFile, "My content is constant");
testRepo.appendFileContent(removedFile, "I will be removed");
IFile iModifiedFile = testRepo.getIFile(iProject, modifiedFile);
IFile iUnchangedFile = testRepo.getIFile(iProject, unchangedFile);
IFile iRemovedFile = testRepo.getIFile(iProject, removedFile);
testRepo.trackAllFiles(iProject);
RevCommit firstCommit = testRepo.commit("C1");
testRepo.appendFileContent(modifiedFile, " My content has changed");
testRepo.track(modifiedFile);
testRepo.removeFromIndex(removedFile);
RevCommit secondCommit = testRepo.commit("C2");
// @formatter:off
// History (X means has changed)
// ------------------------------------------------------------
// files C1 [HEAD] C2
// changingFile.sample |-----X----------|-------X-------|->
// notChangingFile.sample |-----X----------|---------------|->
// toBeRemovedFile.sample |-----X----------|-------X-------|->
// -------------------------------------------------------------
// @formatter:on
testRepo.checkoutBranch(firstCommit.getName());
iProject.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
// Now synchronize the two commits using our logical model provider
SampleModelProvider provider = new SampleModelProvider();
// Get the affected resources
ResourceMapping[] mappings = provider.getMappings(iModifiedFile, ResourceMappingContext.LOCAL_CONTEXT, new NullProgressMonitor());
Set<IResource> includedResource = collectResources(mappings);
Set<IResource> expectedIncludedResources = new HashSet<IResource>();
expectedIncludedResources.add(iModifiedFile);
expectedIncludedResources.add(iUnchangedFile);
expectedIncludedResources.add(iRemovedFile);
assertEquals(expectedIncludedResources, includedResource);
// Synchronize the data
final GitSynchronizeData data = new GitSynchronizeData(testRepo.getRepository(), firstCommit.getName(), secondCommit.getName(), true, includedResource);
GitSynchronizeDataSet gitSynchDataSet = new GitSynchronizeDataSet(data);
final GitResourceVariantTreeSubscriber subscriber = new GitResourceVariantTreeSubscriber(gitSynchDataSet);
subscriber.init(new NullProgressMonitor());
IResourceVariantTree sourceVariantTree = subscriber.getSourceTree();
assertNotNull(sourceVariantTree);
IResourceVariantTree remoteVariantTree = subscriber.getRemoteTree();
assertNotNull(remoteVariantTree);
// In the use case in which the file has been deleted the source variant is
// not null whereas the remote variant is null.It seems quite logic.
// However in the second use case we have the same result, the source variant is
// not null whereas the remote is null. In both cases the null value does
// not mean the same thing. In the first case, the null value means that
// the resource is no longer in the repository and in the second the
// null value means there is no change between the two versions.
// Using these values I am not able to distinguish both case.
// It is in contradiction with test #shouldReturnNullResourceVariant2()
// and test #shoulReturnSameResourceVariant(). However I haven't found
// another way to handle this case. Maybe something can be
// done with ThreeWayDiffEntry.scan(tw) to force including in the cache
// some entry even if they have not changed. For example,
// ThreeWayDiffEntry.scan(tw,includedSource) or maybe try preventing the variant
// tree to return null by walking throught the repository and looking for the file...
IResourceVariant unchangedSourceVariant = sourceVariantTree.getResourceVariant(iUnchangedFile);
IResourceVariant unchangedRemoteVariant = remoteVariantTree.getResourceVariant(iUnchangedFile);
assertNotNull(unchangedSourceVariant);
assertNotNull(unchangedRemoteVariant);
IResourceVariant removedSourceVariant = sourceVariantTree.getResourceVariant(iRemovedFile);
IResourceVariant removedRemoteVariant = remoteVariantTree.getResourceVariant(iRemovedFile);
assertNotNull(removedSourceVariant);
assertNull(removedRemoteVariant);
GitSubscriberResourceMappingContext context = new GitSubscriberResourceMappingContext(subscriber, gitSynchDataSet);
assertFalse(context.hasLocalChange(iUnchangedFile, new NullProgressMonitor()));
assertFalse(context.hasRemoteChange(iUnchangedFile, new NullProgressMonitor()));
assertFalse(context.hasLocalChange(iModifiedFile, new NullProgressMonitor()));
assertTrue(context.hasRemoteChange(iModifiedFile, new NullProgressMonitor()));
assertFalse(context.hasLocalChange(iRemovedFile, new NullProgressMonitor()));
assertTrue(context.hasRemoteChange(iRemovedFile, new NullProgressMonitor()));
}
use of org.eclipse.core.resources.mapping.ResourceMapping in project egit by eclipse.
the class GitSubscriberMergeContextTest method mergeModelWithConflict.
@Test
public void mergeModelWithConflict() throws Exception {
File file1 = testRepo.createFile(iProject, "file1." + SAMPLE_FILE_EXTENSION);
File file2 = testRepo.createFile(iProject, "file2." + SAMPLE_FILE_EXTENSION);
String initialContent1 = "some content for the first file";
String initialContent2 = "some content for the second file";
testRepo.appendContentAndCommit(iProject, file1, initialContent1, "first file - initial commit");
testRepo.appendContentAndCommit(iProject, file2, initialContent2, "second file - initial commit");
IFile iFile1 = testRepo.getIFile(iProject, file1);
IFile iFile2 = testRepo.getIFile(iProject, file2);
testRepo.createAndCheckoutBranch(MASTER, BRANCH);
final String branchChanges = "branch changes\n";
setContentsAndCommit(testRepo, iFile1, initialContent1 + branchChanges, "branch commit");
setContentsAndCommit(testRepo, iFile2, initialContent2 + branchChanges, "branch commit");
testRepo.checkoutBranch(MASTER);
final String masterChanges = "some changes\n";
setContentsAndCommit(testRepo, iFile1, initialContent1 + masterChanges, "master commit");
setContentsAndCommit(testRepo, iFile2, initialContent2 + masterChanges, "master commit");
iProject.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
// end setup
IMergeContext mergeContext = prepareModelContext(repo, iFile1, MASTER, BRANCH);
IDiff node = mergeContext.getDiffTree().getDiff(iFile1);
assertNotNull(node);
node = mergeContext.getDiffTree().getDiff(iFile2);
assertNotNull(node);
IResourceMappingMerger merger = createMerger();
IStatus mergeStatus = merger.merge(mergeContext, new NullProgressMonitor());
assertEquals(IStatus.ERROR, mergeStatus.getSeverity());
assertTrue(mergeStatus instanceof IMergeStatus);
assertEquals(2, ((IMergeStatus) mergeStatus).getConflictingMappings().length);
Set<IFile> conflictingFiles = new LinkedHashSet<IFile>();
for (ResourceMapping conflictingMapping : ((IMergeStatus) mergeStatus).getConflictingMappings()) {
assertTrue(conflictingMapping instanceof SampleResourceMapping && conflictingMapping.getModelObject() instanceof IFile);
conflictingFiles.add((IFile) conflictingMapping.getModelObject());
}
assertTrue(conflictingFiles.contains(iFile1));
assertTrue(conflictingFiles.contains(iFile2));
assertContentEquals(iFile1, initialContent1 + masterChanges);
assertContentEquals(iFile2, initialContent2 + masterChanges);
Status status = status(repo);
assertEquals(0, status.getChanged().size());
assertEquals(0, status.getModified().size());
}
use of org.eclipse.core.resources.mapping.ResourceMapping in project egit by eclipse.
the class LabelEventJob method decorateResourceMapping.
/**
* Decorates a resource mapping (i.e. a Working Set).
*
* @param element the element for which the decoration was initially called
* @param decoration the decoration
* @throws CoreException
*/
private void decorateResourceMapping(Object element, IDecoration decoration) throws CoreException {
@SuppressWarnings("restriction") ResourceMapping mapping = Utils.getResourceMapping(element);
if (mapping == null) {
return;
}
boolean isWorkingSet = mapping.getModelObject() instanceof IWorkingSet;
IDecoratableResource decoRes;
try {
if (isWorkingSet) {
decoRes = new DecoratableWorkingSet(mapping);
} else {
decoRes = new DecoratableResourceMapping(mapping);
}
} catch (IOException e) {
throw new CoreException(Activator.createErrorStatus(NLS.bind(UIText.Decorator_exceptionMessage, element), e));
}
/*
* don't render question marks on working sets. !isTracked() can have two reasons:
* 1) nothing is tracked.
* 2) no indexDiff for the contained projects ready yet.
* in both cases, don't do anything to not pollute the display of the sets.
*/
if (!decoRes.isTracked() && isWorkingSet) {
return;
}
helper.decorate(decoration, decoRes);
}
use of org.eclipse.core.resources.mapping.ResourceMapping in project egit by eclipse.
the class GitAdapterFactory method getAdapter.
@Override
public Object getAdapter(Object adaptableObject, Class adapterType) {
if (adapterType.isAssignableFrom(IHistoryPageSource.class)) {
return GitHistoryPageSource.INSTANCE;
}
if (IWorkbenchAdapter.class == adapterType) {
// property page names for git repository tree nodes
if (adaptableObject instanceof RepositoryTreeNode) {
return getRepositoryTreeNodeWorkbenchAdapter((RepositoryTreeNode) adaptableObject);
}
if (gitModelWorkbenchAdapter == null) {
gitModelWorkbenchAdapter = new GitModelWorkbenchAdapter();
}
return gitModelWorkbenchAdapter;
}
if (adaptableObject instanceof IHistoryView && IShowInSource.class == adapterType) {
IHistoryView historyView = (IHistoryView) adaptableObject;
IHistoryPage historyPage = historyView.getHistoryPage();
if (historyPage instanceof GitHistoryPage) {
return historyPage;
}
}
if (adaptableObject instanceof IURIEditorInput && adapterType == Repository.class) {
return getRepository((IURIEditorInput) adaptableObject);
}
if (adaptableObject instanceof IURIEditorInput && adapterType == File.class) {
return getFile((IURIEditorInput) adaptableObject);
}
if (adaptableObject instanceof GitModelObject && adapterType == ResourceMapping.class) {
return GitObjectMapping.create((GitModelObject) adaptableObject);
}
if (adaptableObject instanceof GitModelObject && adapterType == IResource.class) {
GitModelObject obj = (GitModelObject) adaptableObject;
if (obj instanceof GitModelBlob) {
IResource res = ResourceUtil.getFileForLocation(obj.getLocation(), false);
if (res == null) {
// Deleted resource?
res = getWorkspaceResourceFromGitPath(obj.getLocation());
}
return res;
}
if (obj instanceof GitModelTree) {
IResource res = root.getContainerForLocation(obj.getLocation());
if (res == null) {
res = root.getFolder(obj.getLocation());
}
return res;
}
}
if (adapterType == Repository.class) {
ResourceMapping m = AdapterUtils.adapt(adaptableObject, ResourceMapping.class);
if (m != null) {
return SelectionUtils.getRepository(new StructuredSelection(m));
}
}
return null;
}
Aggregations