Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: f12ff62494ac11f517cf94d037c1f3787148ee5a (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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
/*******************************************************************************
 * Copyright (c) 2000, 2018 IBM Corporation and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.team.internal.ccvs.core;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.eclipse.core.resources.*;
import org.eclipse.core.runtime.*;
import org.eclipse.core.runtime.jobs.*;
import org.eclipse.team.core.*;
import org.eclipse.team.core.mapping.IChangeGroupingRequestor;
import org.eclipse.team.core.subscribers.Subscriber;
import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot;
import org.eclipse.team.internal.ccvs.core.syncinfo.FolderSyncInfo;
import org.eclipse.team.internal.core.TeamPlugin;
import org.eclipse.team.internal.core.subscribers.ActiveChangeSetManager;


/**
 * This class represents the CVS Provider's capabilities in the absence of a
 * particular project.
 */

public class CVSTeamProviderType extends RepositoryProviderType implements IAdaptable {
	
	private static AutoShareJob autoShareJob;
	
	public static class AutoShareJob extends Job {

		List projectsToShare = new ArrayList();
		
		AutoShareJob() {
			super(CVSMessages.CVSTeamProviderType_0);
		}

		public boolean isQueueEmpty() {
			return projectsToShare.isEmpty();
		}

		/* (non-Javadoc)
		 * @see org.eclipse.core.runtime.jobs.Job#shouldSchedule()
		 */
		public boolean shouldSchedule() {
			return !isQueueEmpty();
		}
		
		/* (non-Javadoc)
		 * @see org.eclipse.core.runtime.jobs.Job#shouldRun()
		 */
		public boolean shouldRun() {
			synchronized (projectsToShare) {
				for (Iterator iter = projectsToShare.iterator(); iter.hasNext();) {
					IProject project = (IProject) iter.next();
					if (RepositoryProvider.isShared(project)) {
						iter.remove();
					}
				}
				return !projectsToShare.isEmpty();
			}
		}
		
		public void share(IProject project) {
			if (!RepositoryProvider.isShared(project)) {
				synchronized (projectsToShare) {
					if (!projectsToShare.contains(project))
						projectsToShare.add(project);
				}
				if(getState() == Job.NONE && !isQueueEmpty())
					schedule();
			}
		}
		
		/* (non-Javadoc)
		 * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
		 */
		protected IStatus run(IProgressMonitor monitor) {
			IProject next = null;
			next = getNextProject();
			monitor.beginTask(null, IProgressMonitor.UNKNOWN);
			while (next != null) {
				autoconnectCVSProject(next, Policy.subMonitorFor(monitor, IProgressMonitor.UNKNOWN));
				next = getNextProject();
			}
			monitor.done();
			return Status.OK_STATUS;
		}

		private IProject getNextProject() {
			IProject next = null;
			synchronized (projectsToShare) {
				if (!projectsToShare.isEmpty()) {
					next = (IProject)projectsToShare.remove(0);
				}
			}
			return next;
		}
		
		/*
		 * Auto-connect to the repository using CVS/ directories
		 */
		private void autoconnectCVSProject(IProject project, IProgressMonitor monitor) {
			try {
				ICVSFolder folder = (ICVSFolder)CVSWorkspaceRoot.getCVSResourceFor(project);
				FolderSyncInfo info = folder.getFolderSyncInfo();
				if (info != null) {	
					// Set the sharing
					CVSWorkspaceRoot.setSharing(project, info, monitor);
				}
			} catch (TeamException e) {
				CVSProviderPlugin.log(IStatus.ERROR, "Could not auto-share project " + project.getName(), e); //$NON-NLS-1$
			}
		}
	}
	
	private synchronized static AutoShareJob getAutoShareJob() {
		if (autoShareJob == null) {
			autoShareJob = new AutoShareJob();
			autoShareJob.addJobChangeListener(new JobChangeAdapter() {
				public void done(IJobChangeEvent event) {
					// Reschedule the job if it has unprocessed projects
					if (!autoShareJob.isQueueEmpty()) {
						autoShareJob.schedule();
					}
				}
			});
			autoShareJob.setSystem(true);
			autoShareJob.setPriority(Job.SHORT);
			// Must run with the workspace rule to ensure that projects added while we're running
			// can be shared
			autoShareJob.setRule(ResourcesPlugin.getWorkspace().getRoot());
		}
		return autoShareJob;
	}
	
	/**
	 * @see org.eclipse.team.core.RepositoryProviderType#supportsProjectSetImportRelocation()
	 */
	public boolean supportsProjectSetImportRelocation() {
		return false;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.team.core.RepositoryProviderType#getProjectSetCapability()
	 */
	public ProjectSetCapability getProjectSetCapability() {
		return new CVSProjectSetCapability();
	}
	
	/* (non-Javadoc)
	 * @see org.eclipse.team.core.RepositoryProviderType#metaFilesDetected(org.eclipse.core.resources.IProject, org.eclipse.core.resources.IContainer[])
	 */
	public void metaFilesDetected(IProject project, IContainer[] containers) {
		for (int i = 0; i < containers.length; i++) {
			IContainer container = containers[i];
			IContainer cvsDir = null;
			if (container.getName().equals("CVS")) { //$NON-NLS-1$
				cvsDir = container;
			} else {
				IResource resource = container.findMember("CVS"); //$NON-NLS-1$
				if (resource.getType() != IResource.FILE) {
					cvsDir = (IContainer)resource;
				}
			}
			try {
				if (cvsDir != null && !cvsDir.isTeamPrivateMember())
					cvsDir.setTeamPrivateMember(true);
			} catch (CoreException e) {
				TeamPlugin.log(IStatus.ERROR, "Could not flag meta-files as team-private for " + cvsDir.getFullPath(), e); //$NON-NLS-1$
			}
		}
        if (CVSProviderPlugin.getPlugin().isAutoshareOnImport())
            getAutoShareJob().share(project);
	}
	
	/* (non-Javadoc)
	 * @see org.eclipse.team.core.RepositoryProviderType#getSubscriber()
	 */
	public Subscriber getSubscriber() {
		return CVSProviderPlugin.getPlugin().getCVSWorkspaceSubscriber();
	}

	/* (non-Javadoc)
	 * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
	 */
	public <T> T getAdapter(Class<T> adapter) {
		if (adapter == ActiveChangeSetManager.class || adapter == IChangeGroupingRequestor.class)
			return adapter.cast(CVSProviderPlugin.getPlugin().getChangeSetManager());
		return Platform.getAdapterManager().getAdapter(this, adapter);
	}
}

Back to the top