1 /*******************************************************************************
2 * Copyright (C) 2010, 2013 Dariusz Luksza <dariusz@luksza.org> and others.
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License 2.0
6 * which accompanies this distribution, and is available at
7 * https://www.eclipse.org/legal/epl-2.0/
9 * SPDX-License-Identifier: EPL-2.0
10 *******************************************************************************/
11 package org
.eclipse
.egit
.ui
.internal
.synchronize
.mapping
;
13 import static org
.eclipse
.core
.resources
.IResource
.ALLOW_MISSING_LOCAL
;
14 import static org
.eclipse
.core
.resources
.IResource
.DEPTH_ONE
;
16 import java
.util
.LinkedHashSet
;
19 import org
.eclipse
.core
.resources
.IFile
;
20 import org
.eclipse
.core
.resources
.IResource
;
21 import org
.eclipse
.core
.resources
.IWorkspaceRoot
;
22 import org
.eclipse
.core
.resources
.ResourcesPlugin
;
23 import org
.eclipse
.core
.resources
.mapping
.ResourceMappingContext
;
24 import org
.eclipse
.core
.resources
.mapping
.ResourceTraversal
;
25 import org
.eclipse
.core
.runtime
.CoreException
;
26 import org
.eclipse
.core
.runtime
.IPath
;
27 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
28 import org
.eclipse
.egit
.core
.synchronize
.GitSubscriberResourceMappingContext
;
29 import org
.eclipse
.egit
.core
.synchronize
.dto
.GitSynchronizeDataSet
;
30 import org
.eclipse
.egit
.ui
.internal
.synchronize
.model
.GitModelObject
;
31 import org
.eclipse
.egit
.ui
.internal
.synchronize
.model
.GitModelObjectContainer
;
33 class GitContainerMapping
extends GitObjectMapping
{
35 private static final IWorkspaceRoot ROOT
= ResourcesPlugin
.getWorkspace().getRoot();
37 public GitContainerMapping(GitModelObjectContainer gitCommit
) {
42 public ResourceTraversal
[] getTraversals(ResourceMappingContext context
,
43 IProgressMonitor monitor
) throws CoreException
{
44 GitModelObject
[] children
= ((GitModelObjectContainer
) getModelObject())
46 Set
<ResourceTraversal
> result
= new LinkedHashSet
<>();
48 final GitSynchronizeDataSet dataSet
;
49 if (context
instanceof GitSubscriberResourceMappingContext
)
50 dataSet
= ((GitSubscriberResourceMappingContext
) context
)
55 for (GitModelObject child
: children
) {
56 if (child
.isContainer())
57 result
.addAll(createTraversalForContainer(child
, dataSet
));
59 result
.add(createTraversalForFile(child
, dataSet
));
62 return result
.toArray(new ResourceTraversal
[0]);
65 private Set
<ResourceTraversal
> createTraversalForContainer(
66 GitModelObject child
, GitSynchronizeDataSet dataSet
) {
67 GitModelObject
[] containerChildren
= child
.getChildren();
68 Set
<ResourceTraversal
> result
= new LinkedHashSet
<>();
69 for (GitModelObject aChild
: containerChildren
) {
70 if(aChild
.isContainer())
71 result
.addAll(createTraversalForContainer(aChild
, dataSet
));
73 ResourceTraversal traversal
= createTraversalForFile(aChild
,
75 if (traversal
!= null)
76 result
.add(traversal
);
82 private ResourceTraversal
createTraversalForFile(GitModelObject aChild
, GitSynchronizeDataSet dataSet
) {
83 IPath childLocation
= aChild
.getLocation();
84 IFile file
= ROOT
.getFileForLocation(childLocation
);
87 file
= ROOT
.getFile(childLocation
);
90 ResourceTraversal traversal
= null;
92 traversal
= new ResourceTraversal(new IResource
[] { file
},
93 DEPTH_ONE
, ALLOW_MISSING_LOCAL
);
94 else if (file
!= null && dataSet
.shouldBeIncluded(file
))
95 traversal
= new ResourceTraversal(new IResource
[] { file
},
96 DEPTH_ONE
, ALLOW_MISSING_LOCAL
);