Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: e08d1a1011be5fc1e1f49b1b54a306cb40fbef19 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*******************************************************************************
 * Copyright (c) 2013 Atos
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Arthur Daussy - initial implementation
 *******************************************************************************/
package org.eclipse.papyrus.team.collaborative.connector.svn.locker;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.papyrus.team.collaborative.IExtendedURI;
import org.eclipse.papyrus.team.collaborative.connector.svn.tracing.ITracingConstant;
import org.eclipse.papyrus.team.collaborative.connector.svn.tracing.Tracer;
import org.eclipse.papyrus.team.collaborative.connector.svn.utils.SVNUtils;
import org.eclipse.papyrus.team.collaborative.participants.locker.ILocker;
import org.eclipse.papyrus.team.collaborative.reports.CollabStatus;
import org.eclipse.team.svn.core.operation.CompositeOperation;
import org.eclipse.team.svn.core.operation.IActionOperation;
import org.eclipse.team.svn.core.operation.local.LockOperation;
import org.eclipse.team.svn.core.operation.local.RefreshResourcesOperation;
import org.eclipse.team.svn.ui.utility.ICancellableOperationWrapper;
import org.eclipse.team.svn.ui.utility.UIMonitorUtility;


/**
 * SVN implementation of {@link ILocker}
 * 
 * @author adaussy
 * 
 */
public class SVNLocker extends AbstractSVNCollab implements ILocker {


	public SVNLocker(Set<IExtendedURI> uris, ResourceSet resourceSet) {
		super(uris, resourceSet);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.papyrus.team.collaborative.participants.locker.ILocker#lock()
	 */
	public IStatus lock() {
		IResource[] resourcesToProcess = getTargetFiles(getTargetResources());
		//Check that every file is on repository
		List<IResource> fileToAddToRepo = new ArrayList<IResource>();
		for(int i = 0; i < resourcesToProcess.length; i++) {
			IResource currentResource = resourcesToProcess[i];
			if(!SVNUtils.isAddedToRepository(currentResource)) {
				return CollabStatus.createErrorStatus(currentResource.getFullPath() + "is not in the repository");
			}
		}
		//Add resource to repository
		IStatus addStatus = SVNUtils.addToRepository("Adding new resource to repository", fileToAddToRepo);
		if(!addStatus.isOK()) {
			return addStatus;
		}
		if(ITracingConstant.LOCK_TRACING) {
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.append("Locking: ").append("\n");
			for(IResource r : resourcesToProcess) {
				stringBuilder.append(r.getFullPath()).append("\n");
			}
			Tracer.logInfo(stringBuilder.toString());
		}
		//Lock operation
		LockOperation mainOp = new LockOperation(resourcesToProcess, "Lock taken", false);
		CompositeOperation op = new CompositeOperation(mainOp.getId(), mainOp.getMessagesClass());
		op.add(mainOp);
		op.add(new RefreshResourcesOperation(resourcesToProcess));
		ICancellableOperationWrapper runnable = UIMonitorUtility.doTaskNowDefault(op, false);
		IActionOperation resultStatus = runnable.getOperation();
		return resultStatus.getStatus();
	}



	@Override
	protected Set<IExtendedURI> doBuild() {
		for(IExtendedURI extendedURI : getUris()) {
			IExtendedURI resourceURI = getResourceURI(extendedURI);
			if(resourceURI != null) {
				if(!isLocked(resourceURI).isOK()) {
					getExtendedSet().add(resourceURI);
				}
			}
		}
		return getExtendedSet();
	}





}

Back to the top