KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ccvs > core > CVSTeamProviderType


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.team.internal.ccvs.core;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.Iterator JavaDoc;
15 import java.util.List JavaDoc;
16
17 import org.eclipse.core.resources.*;
18 import org.eclipse.core.runtime.*;
19 import org.eclipse.core.runtime.jobs.*;
20 import org.eclipse.team.core.*;
21 import org.eclipse.team.core.mapping.IChangeGroupingRequestor;
22 import org.eclipse.team.core.subscribers.Subscriber;
23 import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot;
24 import org.eclipse.team.internal.ccvs.core.syncinfo.FolderSyncInfo;
25 import org.eclipse.team.internal.core.TeamPlugin;
26 import org.eclipse.team.internal.core.subscribers.ActiveChangeSetManager;
27
28
29 /**
30  * This class represents the CVS Provider's capabilities in the absence of a
31  * particular project.
32  */

33
34 public class CVSTeamProviderType extends RepositoryProviderType implements IAdaptable {
35     
36     private static AutoShareJob autoShareJob;
37     
38     public static class AutoShareJob extends Job {
39
40         List JavaDoc projectsToShare = new ArrayList JavaDoc();
41         
42         AutoShareJob() {
43             super(CVSMessages.CVSTeamProviderType_0);
44         }
45
46         public boolean isQueueEmpty() {
47             return projectsToShare.isEmpty();
48         }
49
50         /* (non-Javadoc)
51          * @see org.eclipse.core.runtime.jobs.Job#shouldSchedule()
52          */

53         public boolean shouldSchedule() {
54             return !isQueueEmpty();
55         }
56         
57         /* (non-Javadoc)
58          * @see org.eclipse.core.runtime.jobs.Job#shouldRun()
59          */

60         public boolean shouldRun() {
61             synchronized (projectsToShare) {
62                 for (Iterator JavaDoc iter = projectsToShare.iterator(); iter.hasNext();) {
63                     IProject project = (IProject) iter.next();
64                     if (RepositoryProvider.isShared(project)) {
65                         iter.remove();
66                     }
67                 }
68                 return !projectsToShare.isEmpty();
69             }
70         }
71         
72         public void share(IProject project) {
73             if (!RepositoryProvider.isShared(project)) {
74                 synchronized (projectsToShare) {
75                     if (!projectsToShare.contains(project))
76                         projectsToShare.add(project);
77                 }
78                 if(getState() == Job.NONE && !isQueueEmpty())
79                     schedule();
80             }
81         }
82         
83         /* (non-Javadoc)
84          * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
85          */

86         protected IStatus run(IProgressMonitor monitor) {
87             IProject next = null;
88             next = getNextProject();
89             monitor.beginTask(null, IProgressMonitor.UNKNOWN);
90             while (next != null) {
91                 autoconnectCVSProject(next, Policy.subMonitorFor(monitor, IProgressMonitor.UNKNOWN));
92                 next = getNextProject();
93             }
94             monitor.done();
95             return Status.OK_STATUS;
96         }
97
98         private IProject getNextProject() {
99             IProject next = null;
100             synchronized (projectsToShare) {
101                 if (!projectsToShare.isEmpty()) {
102                     next = (IProject)projectsToShare.remove(0);
103                 }
104             }
105             return next;
106         }
107         
108         /*
109          * Auto-connect to the repository using CVS/ directories
110          */

111         private void autoconnectCVSProject(IProject project, IProgressMonitor monitor) {
112             try {
113                 ICVSFolder folder = (ICVSFolder)CVSWorkspaceRoot.getCVSResourceFor(project);
114                 FolderSyncInfo info = folder.getFolderSyncInfo();
115                 if (info != null) {
116                     // Set the sharing
117
CVSWorkspaceRoot.setSharing(project, info, monitor);
118                 }
119             } catch (TeamException e) {
120                 CVSProviderPlugin.log(IStatus.ERROR, "Could not auto-share project " + project.getName(), e); //$NON-NLS-1$
121
}
122         }
123     }
124     
125     private synchronized static AutoShareJob getAutoShareJob() {
126         if (autoShareJob == null) {
127             autoShareJob = new AutoShareJob();
128             autoShareJob.addJobChangeListener(new JobChangeAdapter() {
129                 public void done(IJobChangeEvent event) {
130                     // Reschedule the job if it has unprocessed projects
131
if (!autoShareJob.isQueueEmpty()) {
132                         autoShareJob.schedule();
133                     }
134                 }
135             });
136             autoShareJob.setSystem(true);
137             autoShareJob.setPriority(Job.SHORT);
138             // Must run with the workspace rule to ensure that projects added while we're running
139
// can be shared
140
autoShareJob.setRule(ResourcesPlugin.getWorkspace().getRoot());
141         }
142         return autoShareJob;
143     }
144     
145     /**
146      * @see org.eclipse.team.core.RepositoryProviderType#supportsProjectSetImportRelocation()
147      */

148     public boolean supportsProjectSetImportRelocation() {
149         return false;
150     }
151
152     /* (non-Javadoc)
153      * @see org.eclipse.team.core.RepositoryProviderType#getProjectSetCapability()
154      */

155     public ProjectSetCapability getProjectSetCapability() {
156         return new CVSProjectSetCapability();
157     }
158     
159     /* (non-Javadoc)
160      * @see org.eclipse.team.core.RepositoryProviderType#metaFilesDetected(org.eclipse.core.resources.IProject, org.eclipse.core.resources.IContainer[])
161      */

162     public void metaFilesDetected(IProject project, IContainer[] containers) {
163         for (int i = 0; i < containers.length; i++) {
164             IContainer container = containers[i];
165             IContainer cvsDir = null;
166             if (container.getName().equals("CVS")) { //$NON-NLS-1$
167
cvsDir = container;
168             } else {
169                 IResource resource = container.findMember("CVS"); //$NON-NLS-1$
170
if (resource.getType() != IResource.FILE) {
171                     cvsDir = (IContainer)resource;
172                 }
173             }
174             try {
175                 if (cvsDir != null && !cvsDir.isTeamPrivateMember())
176                     cvsDir.setTeamPrivateMember(true);
177             } catch (CoreException e) {
178                 TeamPlugin.log(IStatus.ERROR, "Could not flag meta-files as team-private for " + cvsDir.getFullPath(), e); //$NON-NLS-1$
179
}
180         }
181         if (CVSProviderPlugin.getPlugin().isAutoshareOnImport())
182             getAutoShareJob().share(project);
183     }
184     
185     /* (non-Javadoc)
186      * @see org.eclipse.team.core.RepositoryProviderType#getSubscriber()
187      */

188     public Subscriber getSubscriber() {
189         return CVSProviderPlugin.getPlugin().getCVSWorkspaceSubscriber();
190     }
191
192     /* (non-Javadoc)
193      * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
194      */

195     public Object JavaDoc getAdapter(Class JavaDoc adapter) {
196         if (adapter == ActiveChangeSetManager.class || adapter == IChangeGroupingRequestor.class)
197             return CVSProviderPlugin.getPlugin().getChangeSetManager();
198         return Platform.getAdapterManager().getAdapter(this, adapter);
199     }
200 }
201
Popular Tags